Synch to No Gnus 200510111141.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
9 ;; Keywords: mail, news, MIME
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
27
28 ;;; Commentary:
29
30 ;;; Code:
31
32 (eval-when-compile
33   (require 'cl)
34   (defvar tool-bar-map))
35
36 (require 'gnus)
37 (require 'gnus-group)
38 (require 'gnus-spec)
39 (require 'gnus-range)
40 (require 'gnus-int)
41 (require 'gnus-undo)
42 (require 'gnus-util)
43 (require 'nnoo)
44
45 (eval-when-compile
46   (require 'mime-play)
47   (require 'static))
48
49 (eval-and-compile
50   (autoload 'pgg-decrypt-region "pgg" nil t)
51   (autoload 'pgg-verify-region "pgg" nil t))
52
53 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
54 (autoload 'gnus-cache-write-active "gnus-cache")
55 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
56 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
57 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
58 (autoload 'mm-uu-dissect "mm-uu")
59 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
60   "Deuglify broken Outlook (Express) articles and redisplay."
61   t)
62 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
63 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
64 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
65
66 (defcustom gnus-kill-summary-on-exit t
67   "*If non-nil, kill the summary buffer when you exit from it.
68 If nil, the summary will become a \"*Dead Summary*\" buffer, and
69 it will be killed sometime later."
70   :group 'gnus-summary-exit
71   :type 'boolean)
72
73 (defcustom gnus-fetch-old-headers nil
74   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
75 If an unread article in the group refers to an older, already read (or
76 just marked as read) article, the old article will not normally be
77 displayed in the Summary buffer.  If this variable is t, Gnus
78 will attempt to grab the headers to the old articles, and thereby
79 build complete threads.  If it has the value `some', only enough
80 headers to connect otherwise loose threads will be displayed.  This
81 variable can also be a number.  In that case, no more than that number
82 of old headers will be fetched.  If it has the value `invisible', all
83 old headers will be fetched, but none will be displayed.
84
85 The server has to support NOV for any of this to work."
86   :group 'gnus-thread
87   :type '(choice (const :tag "off" nil)
88                  (const :tag "on" t)
89                  (const some)
90                  (const invisible)
91                  number
92                  (sexp :menu-tag "other" t)))
93
94 (defcustom gnus-refer-thread-limit 200
95   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
96 If t, fetch all the available old headers."
97   :group 'gnus-thread
98   :type '(choice number
99                  (sexp :menu-tag "other" t)))
100
101 (defcustom gnus-summary-make-false-root 'adopt
102   "*nil means that Gnus won't gather loose threads.
103 If the root of a thread has expired or been read in a previous
104 session, the information necessary to build a complete thread has been
105 lost.  Instead of having many small sub-threads from this original thread
106 scattered all over the summary buffer, Gnus can gather them.
107
108 If non-nil, Gnus will try to gather all loose sub-threads from an
109 original thread into one large thread.
110
111 If this variable is non-nil, it should be one of `none', `adopt',
112 `dummy' or `empty'.
113
114 If this variable is `none', Gnus will not make a false root, but just
115 present the sub-threads after another.
116 If this variable is `dummy', Gnus will create a dummy root that will
117 have all the sub-threads as children.
118 If this variable is `adopt', Gnus will make one of the \"children\"
119 the parent and mark all the step-children as such.
120 If this variable is `empty', the \"children\" are printed with empty
121 subject fields.  (Or rather, they will be printed with a string
122 given by the `gnus-summary-same-subject' variable.)"
123   :group 'gnus-thread
124   :type '(choice (const :tag "off" nil)
125                  (const none)
126                  (const dummy)
127                  (const adopt)
128                  (const empty)))
129
130 (defcustom gnus-summary-make-false-root-always nil
131   "Always make a false dummy root."
132   :version "22.1"
133   :group 'gnus-thread
134   :type 'boolean)
135
136 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
137   "*A regexp to match subjects to be excluded from loose thread gathering.
138 As loose thread gathering is done on subjects only, that means that
139 there can be many false gatherings performed.  By rooting out certain
140 common subjects, gathering might become saner."
141   :group 'gnus-thread
142   :type 'regexp)
143
144 (defcustom gnus-summary-gather-subject-limit nil
145   "*Maximum length of subject comparisons when gathering loose threads.
146 Use nil to compare full subjects.  Setting this variable to a low
147 number will help gather threads that have been corrupted by
148 newsreaders chopping off subject lines, but it might also mean that
149 unrelated articles that have subject that happen to begin with the
150 same few characters will be incorrectly gathered.
151
152 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
153 comparing subjects."
154   :group 'gnus-thread
155   :type '(choice (const :tag "off" nil)
156                  (const fuzzy)
157                  (sexp :menu-tag "on" t)))
158
159 (defcustom gnus-simplify-subject-functions nil
160   "List of functions taking a string argument that simplify subjects.
161 The functions are applied recursively.
162
163 Useful functions to put in this list include:
164 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
165 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
166   :group 'gnus-thread
167   :type '(repeat function))
168
169 (defcustom gnus-simplify-ignored-prefixes nil
170   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
171   :group 'gnus-thread
172   :type '(choice (const :tag "off" nil)
173                  regexp))
174
175 (defcustom gnus-build-sparse-threads nil
176   "*If non-nil, fill in the gaps in threads.
177 If `some', only fill in the gaps that are needed to tie loose threads
178 together.  If `more', fill in all leaf nodes that Gnus can find.  If
179 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
180   :group 'gnus-thread
181   :type '(choice (const :tag "off" nil)
182                  (const some)
183                  (const more)
184                  (sexp :menu-tag "all" t)))
185
186 (defcustom gnus-summary-thread-gathering-function
187   'gnus-gather-threads-by-subject
188   "*Function used for gathering loose threads.
189 There are two pre-defined functions: `gnus-gather-threads-by-subject',
190 which only takes Subjects into consideration; and
191 `gnus-gather-threads-by-references', which compared the References
192 headers of the articles to find matches."
193   :group 'gnus-thread
194   :type '(radio (function-item gnus-gather-threads-by-subject)
195                 (function-item gnus-gather-threads-by-references)
196                 (function :tag "other")))
197
198 (defcustom gnus-summary-same-subject ""
199   "*String indicating that the current article has the same subject as the previous.
200 This variable will only be used if the value of
201 `gnus-summary-make-false-root' is `empty'."
202   :group 'gnus-summary-format
203   :type 'string)
204
205 (defcustom gnus-summary-goto-unread t
206   "*If t, many commands will go to the next unread article.
207 This applies to marking commands as well as other commands that
208 \"naturally\" select the next article, like, for instance, `SPC' at
209 the end of an article.
210
211 If nil, the marking commands do NOT go to the next unread article
212 \(they go to the next article instead).  If `never', commands that
213 usually go to the next unread article, will go to the next article,
214 whether it is read or not."
215   :group 'gnus-summary-marks
216   :link '(custom-manual "(gnus)Setting Marks")
217   :type '(choice (const :tag "off" nil)
218                  (const never)
219                  (sexp :menu-tag "on" t)))
220
221 (defcustom gnus-summary-default-score 0
222   "*Default article score level.
223 All scores generated by the score files will be added to this score.
224 If this variable is nil, scoring will be disabled."
225   :group 'gnus-score-default
226   :type '(choice (const :tag "disable")
227                  integer))
228
229 (defcustom gnus-summary-default-high-score 0
230   "*Default threshold for a high scored article.
231 An article will be highlighted as high scored if its score is greater
232 than this score."
233   :version "22.1"
234   :group 'gnus-score-default
235   :type 'integer)
236
237 (defcustom gnus-summary-default-low-score 0
238   "*Default threshold for a low scored article.
239 An article will be highlighted as low scored if its score is smaller
240 than this score."
241   :version "22.1"
242   :group 'gnus-score-default
243   :type 'integer)
244
245 (defcustom gnus-summary-zcore-fuzz 0
246   "*Fuzziness factor for the zcore in the summary buffer.
247 Articles with scores closer than this to `gnus-summary-default-score'
248 will not be marked."
249   :group 'gnus-summary-format
250   :type 'integer)
251
252 (defcustom gnus-simplify-subject-fuzzy-regexp nil
253   "*Strings to be removed when doing fuzzy matches.
254 This can either be a regular expression or list of regular expressions
255 that will be removed from subject strings if fuzzy subject
256 simplification is selected."
257   :group 'gnus-thread
258   :type '(repeat regexp))
259
260 (defcustom gnus-show-threads t
261   "*If non-nil, display threads in summary mode."
262   :group 'gnus-thread
263   :type 'boolean)
264
265 (defcustom gnus-thread-hide-subtree nil
266   "*If non-nil, hide all threads initially.
267 This can be a predicate specifier which says which threads to hide.
268 If threads are hidden, you have to run the command
269 `gnus-summary-show-thread' by hand or or select an article."
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-recipient'
808 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
809 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
810 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
811 and `gnus-thread-sort-by-total-score' (see
812 `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-recipient)
822                    (function-item gnus-thread-sort-by-subject)
823                    (function-item gnus-thread-sort-by-date)
824                    (function-item gnus-thread-sort-by-score)
825                    (function-item gnus-thread-sort-by-most-recent-number)
826                    (function-item gnus-thread-sort-by-most-recent-date)
827                    (function-item gnus-thread-sort-by-random)
828                    (function-item gnus-thread-sort-by-total-score)
829                    (function :tag "other"))
830            (boolean :tag "Reverse order"))))
831
832 (defcustom gnus-thread-score-function '+
833   "*Function used for calculating the total score of a thread.
834
835 The function is called with the scores of the article and each
836 subthread and should then return the score of the thread.
837
838 Some functions you can use are `+', `max', or `min'."
839   :group 'gnus-summary-sort
840   :type 'function)
841
842 (defcustom gnus-summary-expunge-below nil
843   "All articles that have a score less than this variable will be expunged.
844 This variable is local to the summary buffers."
845   :group 'gnus-score-default
846   :type '(choice (const :tag "off" nil)
847                  integer))
848
849 (defcustom gnus-thread-expunge-below nil
850   "All threads that have a total score less than this variable will be expunged.
851 See `gnus-thread-score-function' for en explanation of what a
852 \"thread score\" is.
853
854 This variable is local to the summary buffers."
855   :group 'gnus-threading
856   :group 'gnus-score-default
857   :type '(choice (const :tag "off" nil)
858                  integer))
859
860 (defcustom gnus-summary-mode-hook nil
861   "*A hook for Gnus summary mode.
862 This hook is run before any variables are set in the summary buffer."
863   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
864   :group 'gnus-summary-various
865   :type 'hook)
866
867 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
868 (when (featurep 'xemacs)
869   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
870   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
871   (add-hook 'gnus-summary-mode-hook
872             'gnus-xmas-switch-horizontal-scrollbar-off))
873
874 (defcustom gnus-summary-menu-hook nil
875   "*Hook run after the creation of the summary mode menu."
876   :group 'gnus-summary-visual
877   :type 'hook)
878
879 (defcustom gnus-summary-exit-hook nil
880   "*A hook called on exit from the summary buffer.
881 It will be called with point in the group buffer."
882   :group 'gnus-summary-exit
883   :type 'hook)
884
885 (defcustom gnus-summary-prepare-hook nil
886   "*A hook called after the summary buffer has been generated.
887 If you want to modify the summary buffer, you can use this hook."
888   :group 'gnus-summary-various
889   :type 'hook)
890
891 (defcustom gnus-summary-prepared-hook nil
892   "*A hook called as the last thing after the summary buffer has been generated."
893   :group 'gnus-summary-various
894   :type 'hook)
895
896 (defcustom gnus-summary-generate-hook nil
897   "*A hook run just before generating the summary buffer.
898 This hook is commonly used to customize threading variables and the
899 like."
900   :group 'gnus-summary-various
901   :type 'hook)
902
903 (defcustom gnus-select-group-hook nil
904   "*A hook called when a newsgroup is selected.
905
906 If you'd like to simplify subjects like the
907 `gnus-summary-next-same-subject' command does, you can use the
908 following hook:
909
910  (add-hook gnus-select-group-hook
911            (lambda ()
912              (mapcar (lambda (header)
913                        (mail-header-set-subject
914                         header
915                         (gnus-simplify-subject
916                          (mail-header-subject header) 're-only)))
917                      gnus-newsgroup-headers)))"
918   :group 'gnus-group-select
919   :type 'hook)
920
921 (defcustom gnus-select-article-hook nil
922   "*A hook called when an article is selected."
923   :group 'gnus-summary-choose
924   :options '(gnus-agent-fetch-selected-article)
925   :type 'hook)
926
927 (defcustom gnus-visual-mark-article-hook
928   (list 'gnus-highlight-selected-summary)
929   "*Hook run after selecting an article in the summary buffer.
930 It is meant to be used for highlighting the article in some way.  It
931 is not run if `gnus-visual' is nil."
932   :group 'gnus-summary-visual
933   :type 'hook)
934
935 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
936   "*A hook called before parsing the headers."
937   :group 'gnus-various
938   :type 'hook)
939
940 (defcustom gnus-exit-group-hook nil
941   "*A hook called when exiting summary mode.
942 This hook is not called from the non-updating exit commands like `Q'."
943   :group 'gnus-various
944   :type 'hook)
945
946 (defcustom gnus-summary-update-hook
947   (list 'gnus-summary-highlight-line)
948   "*A hook called when a summary line is changed.
949 The hook will not be called if `gnus-visual' is nil.
950
951 The default function `gnus-summary-highlight-line' will
952 highlight the line according to the `gnus-summary-highlight'
953 variable."
954   :group 'gnus-summary-visual
955   :type 'hook)
956
957 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
958   "*A hook called when an article is selected for the first time.
959 The hook is intended to mark an article as read (or unread)
960 automatically when it is selected."
961   :group 'gnus-summary-choose
962   :type 'hook)
963
964 (defcustom gnus-group-no-more-groups-hook nil
965   "*A hook run when returning to group mode having no more (unread) groups."
966   :group 'gnus-group-select
967   :type 'hook)
968
969 (defcustom gnus-ps-print-hook nil
970   "*A hook run before ps-printing something from Gnus."
971   :group 'gnus-summary
972   :type 'hook)
973
974 (defcustom gnus-summary-article-move-hook nil
975   "*A hook called after an article is moved, copied, respooled, or crossposted."
976   :version "22.1"
977   :group 'gnus-summary
978   :type 'hook)
979
980 (defcustom gnus-summary-article-delete-hook nil
981   "*A hook called after an article is deleted."
982   :version "22.1"
983   :group 'gnus-summary
984   :type 'hook)
985
986 (defcustom gnus-summary-article-expire-hook nil
987   "*A hook called after an article is expired."
988   :version "22.1"
989   :group 'gnus-summary
990   :type 'hook)
991
992 (defcustom gnus-summary-display-arrow
993   (and (fboundp 'display-graphic-p)
994        (display-graphic-p))
995   "*If non-nil, display an arrow highlighting the current article."
996   :version "22.1"
997   :group 'gnus-summary
998   :type 'boolean)
999
1000 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1001   "Face used for highlighting the current article in the summary buffer."
1002   :group 'gnus-summary-visual
1003   :type 'face)
1004
1005 (defvar gnus-tmp-downloaded nil)
1006
1007 (defcustom gnus-summary-highlight
1008   '(((eq mark gnus-canceled-mark)
1009      . gnus-summary-cancelled)
1010     ((and uncached (> score default-high))
1011      . gnus-summary-high-undownloaded)
1012     ((and uncached (< score default-low))
1013      . gnus-summary-low-undownloaded)
1014     (uncached
1015      . gnus-summary-normal-undownloaded)
1016     ((and (> score default-high)
1017           (or (eq mark gnus-dormant-mark)
1018               (eq mark gnus-ticked-mark)))
1019      . gnus-summary-high-ticked)
1020     ((and (< score default-low)
1021           (or (eq mark gnus-dormant-mark)
1022               (eq mark gnus-ticked-mark)))
1023      . gnus-summary-low-ticked)
1024     ((or (eq mark gnus-dormant-mark)
1025          (eq mark gnus-ticked-mark))
1026      . gnus-summary-normal-ticked)
1027     ((and (> score default-high) (eq mark gnus-ancient-mark))
1028      . gnus-summary-high-ancient)
1029     ((and (< score default-low) (eq mark gnus-ancient-mark))
1030      . gnus-summary-low-ancient)
1031     ((eq mark gnus-ancient-mark)
1032      . gnus-summary-normal-ancient)
1033     ((and (> score default-high) (eq mark gnus-unread-mark))
1034      . gnus-summary-high-unread)
1035     ((and (< score default-low) (eq mark gnus-unread-mark))
1036      . gnus-summary-low-unread)
1037     ((eq mark gnus-unread-mark)
1038      . gnus-summary-normal-unread)
1039     ((> score default-high)
1040      . gnus-summary-high-read)
1041     ((< score default-low)
1042      . gnus-summary-low-read)
1043     (t
1044      . gnus-summary-normal-read))
1045   "*Controls the highlighting of summary buffer lines.
1046
1047 A list of (FORM . FACE) pairs.  When deciding how a a particular
1048 summary line should be displayed, each form is evaluated.  The content
1049 of the face field after the first true form is used.  You can change
1050 how those summary lines are displayed, by editing the face field.
1051
1052 You can use the following variables in the FORM field.
1053
1054 score:        The article's score
1055 default:      The default article score.
1056 default-high: The default score for high scored articles.
1057 default-low:  The default score for low scored articles.
1058 below:        The score below which articles are automatically marked as read.
1059 mark:         The article's mark.
1060 uncached:     Non-nil if the article is uncached."
1061   :group 'gnus-summary-visual
1062   :type '(repeat (cons (sexp :tag "Form" nil)
1063                        face)))
1064
1065 (defcustom gnus-alter-header-function nil
1066   "Function called to allow alteration of article header structures.
1067 The function is called with one parameter, the article header vector,
1068 which it may alter in any way."
1069   :type '(choice (const :tag "None" nil)
1070                  function)
1071   :group 'gnus-summary)
1072
1073 (defvar gnus-decode-encoded-word-function
1074   (mime-find-field-decoder 'From 'nov)
1075   "Variable that says which function should be used to decode a string with encoded words.")
1076
1077 (defcustom gnus-extra-headers '(To Newsgroups)
1078   "*Extra headers to parse."
1079   :version "21.1"
1080   :group 'gnus-summary
1081   :type '(repeat symbol))
1082
1083 (defcustom gnus-ignored-from-addresses
1084   (and user-mail-address (regexp-quote user-mail-address))
1085   "*Regexp of From headers that may be suppressed in favor of To headers."
1086   :version "21.1"
1087   :group 'gnus-summary
1088   :type 'regexp)
1089
1090 (defcustom gnus-summary-to-prefix "-> "
1091   "*String prefixed to the To field in the summary line when
1092 using `gnus-ignored-from-addresses'."
1093   :version "22.1"
1094   :group 'gnus-summary
1095   :type 'string)
1096
1097 (defcustom gnus-summary-newsgroup-prefix "=> "
1098   "*String prefixed to the Newsgroup field in the summary
1099 line when using `gnus-ignored-from-addresses'."
1100   :version "22.1"
1101   :group 'gnus-summary
1102   :type 'string)
1103
1104 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1105   "List of charsets that should be ignored.
1106 When these charsets are used in the \"charset\" parameter, the
1107 default charset will be used instead."
1108   :version "21.1"
1109   :type '(repeat symbol)
1110   :group 'gnus-charset)
1111
1112 (gnus-define-group-parameter
1113  ignored-charsets
1114  :type list
1115  :function-document
1116  "Return the ignored charsets of GROUP."
1117  :variable gnus-group-ignored-charsets-alist
1118  :variable-default
1119  '(("alt\\.chinese\\.text" iso-8859-1))
1120  :variable-document
1121  "Alist of regexps (to match group names) and charsets that should be ignored.
1122 When these charsets are used in the \"charset\" parameter, the
1123 default charset will be used instead."
1124  :variable-group gnus-charset
1125  :variable-type '(repeat (cons (regexp :tag "Group")
1126                                (repeat symbol)))
1127  :parameter-type '(choice :tag "Ignored charsets"
1128                           :value nil
1129                           (repeat (symbol)))
1130  :parameter-document       "\
1131 List of charsets that should be ignored.
1132
1133 When these charsets are used in the \"charset\" parameter, the
1134 default charset will be used instead.")
1135
1136 (defcustom gnus-group-highlight-words-alist nil
1137   "Alist of group regexps and highlight regexps.
1138 This variable uses the same syntax as `gnus-emphasis-alist'."
1139   :version "21.1"
1140   :type '(repeat (cons (regexp :tag "Group")
1141                        (repeat (list (regexp :tag "Highlight regexp")
1142                                      (number :tag "Group for entire word" 0)
1143                                      (number :tag "Group for displayed part" 0)
1144                                      (symbol :tag "Face"
1145                                              gnus-emphasis-highlight-words)))))
1146   :group 'gnus-summary-visual)
1147
1148 (defcustom gnus-use-wheel nil
1149   "Use Intelli-mouse on summary movement"
1150   :type 'boolean
1151   :group 'gnus-summary-maneuvering)
1152
1153 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1154   "Amount to scroll messages by spinning the mouse wheel.
1155 This is actually a cons cell, where the first item is the amount to scroll
1156 on a normal wheel event, and the second is the amount to scroll when the
1157 wheel is moved with the shift key depressed."
1158   :type '(cons (integer :tag "Shift") integer)
1159   :group 'gnus-summary-maneuvering)
1160
1161 (defcustom gnus-wheel-edge-resistance 2
1162   "How hard it should be to change the current article
1163 by moving the mouse over the edge of the article window."
1164   :type 'integer
1165   :group 'gnus-summary-maneuvering)
1166
1167 (defcustom gnus-summary-show-article-charset-alist
1168   nil
1169   "Alist of number and charset.
1170 The article will be shown with the charset corresponding to the
1171 numbered argument.
1172 For example: ((1 . cn-gb-2312) (2 . big5))."
1173   :version "21.1"
1174   :type '(repeat (cons (number :tag "Argument" 1)
1175                        (symbol :tag "Charset")))
1176   :group 'gnus-charset)
1177
1178 (defcustom gnus-preserve-marks t
1179   "Whether marks are preserved when moving, copying and respooling messages."
1180   :version "21.1"
1181   :type 'boolean
1182   :group 'gnus-summary-marks)
1183
1184 (defcustom gnus-alter-articles-to-read-function nil
1185   "Function to be called to alter the list of articles to be selected."
1186   :type '(choice (const nil) function)
1187   :group 'gnus-summary)
1188
1189 (defcustom gnus-orphan-score nil
1190   "*All orphans get this score added.  Set in the score file."
1191   :group 'gnus-score-default
1192   :type '(choice (const nil)
1193                  integer))
1194
1195 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1196   "*A regexp to match MIME parts when saving multiple parts of a
1197 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1198 This regexp will be used by default when prompting the user for which
1199 type of files to save."
1200   :group 'gnus-summary
1201   :type 'regexp)
1202
1203 (defcustom gnus-read-all-available-headers nil
1204   "Whether Gnus should parse all headers made available to it.
1205 This is mostly relevant for slow back ends where the user may
1206 wish to widen the summary buffer to include all headers
1207 that were fetched.  Say, for nnultimate groups."
1208   :version "22.1"
1209   :group 'gnus-summary
1210   :type '(choice boolean regexp))
1211
1212 (defcustom gnus-summary-muttprint-program "muttprint"
1213   "Command (and optional arguments) used to run Muttprint."
1214   :version "22.1"
1215   :group 'gnus-summary
1216   :type 'string)
1217
1218 (defcustom gnus-article-loose-mime t
1219   "If non-nil, don't require MIME-Version header.
1220 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1221 supply the MIME-Version header or deliberately strip it from the mail.
1222 If non-nil (the default), Gnus will treat some articles as MIME
1223 even if the MIME-Version header is missing."
1224   :version "22.1"
1225   :type 'boolean
1226   :group 'gnus-article-mime)
1227
1228 (defcustom gnus-article-emulate-mime t
1229   "If non-nil, use MIME emulation for uuencode and the like.
1230 This means that Gnus will search message bodies for text that look
1231 like uuencoded bits, yEncoded bits, and so on, and present that using
1232 the normal Gnus MIME machinery."
1233   :version "22.1"
1234   :type 'boolean
1235   :group 'gnus-article-mime)
1236
1237 ;;; Internal variables
1238
1239 (defvar gnus-summary-display-cache nil)
1240 (defvar gnus-article-mime-handles nil)
1241 (defvar gnus-article-decoded-p nil)
1242 (defvar gnus-article-charset nil)
1243 (defvar gnus-article-ignored-charsets nil)
1244 (defvar gnus-scores-exclude-files nil)
1245 (defvar gnus-page-broken nil)
1246
1247 (defvar gnus-original-article nil)
1248 (defvar gnus-article-internal-prepare-hook nil)
1249 (defvar gnus-newsgroup-process-stack nil)
1250
1251 (defvar gnus-thread-indent-array nil)
1252 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1253 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1254   "Function called to sort the articles within a thread after it has been gathered together.")
1255
1256 (defvar gnus-summary-save-parts-type-history nil)
1257 (defvar gnus-summary-save-parts-last-directory nil)
1258
1259 ;; Avoid highlighting in kill files.
1260 (defvar gnus-summary-inhibit-highlight nil)
1261 (defvar gnus-newsgroup-selected-overlay nil)
1262 (defvar gnus-inhibit-limiting nil)
1263 (defvar gnus-newsgroup-adaptive-score-file nil)
1264 (defvar gnus-current-score-file nil)
1265 (defvar gnus-current-move-group nil)
1266 (defvar gnus-current-copy-group nil)
1267 (defvar gnus-current-crosspost-group nil)
1268 (defvar gnus-newsgroup-display nil)
1269
1270 (defvar gnus-newsgroup-dependencies nil)
1271 (defvar gnus-newsgroup-adaptive nil)
1272 (defvar gnus-summary-display-article-function nil)
1273 (defvar gnus-summary-highlight-line-function nil
1274   "Function called after highlighting a summary line.")
1275
1276 (defvar gnus-summary-line-format-alist
1277   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1278     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1279     (?s gnus-tmp-subject-or-nil ?s)
1280     (?n gnus-tmp-name ?s)
1281     (?A (std11-address-string
1282          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1283     (?a (or (std11-full-name-string
1284              (car (mime-entity-read-field gnus-tmp-header 'From)))
1285             gnus-tmp-from) ?s)
1286     (?F gnus-tmp-from ?s)
1287     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1288     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1289     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1290     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1291     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1292     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1293     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1294     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1295     (?L gnus-tmp-lines ?s)
1296     (?O gnus-tmp-downloaded ?c)
1297     (?I gnus-tmp-indentation ?s)
1298     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1299     (?R gnus-tmp-replied ?c)
1300     (?\[ gnus-tmp-opening-bracket ?c)
1301     (?\] gnus-tmp-closing-bracket ?c)
1302     (?\> (make-string gnus-tmp-level ? ) ?s)
1303     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1304     (?i gnus-tmp-score ?d)
1305     (?z gnus-tmp-score-char ?c)
1306     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1307     (?U gnus-tmp-unread ?c)
1308     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1309         ?s)
1310     (?t (gnus-summary-number-of-articles-in-thread
1311          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1312         ?d)
1313     (?e (gnus-summary-number-of-articles-in-thread
1314          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1315         ?c)
1316     (?u gnus-tmp-user-defined ?s)
1317     (?P (gnus-pick-line-number) ?d)
1318     (?B gnus-tmp-thread-tree-header-string ?s)
1319     (user-date (gnus-user-date
1320                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1321   "An alist of format specifications that can appear in summary lines.
1322 These are paired with what variables they correspond with, along with
1323 the type of the variable (string, integer, character, etc).")
1324
1325 (defvar gnus-summary-dummy-line-format-alist
1326   `((?S gnus-tmp-subject ?s)
1327     (?N gnus-tmp-number ?d)
1328     (?u gnus-tmp-user-defined ?s)))
1329
1330 (defvar gnus-summary-mode-line-format-alist
1331   `((?G gnus-tmp-group-name ?s)
1332     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1333     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1334     (?A gnus-tmp-article-number ?d)
1335     (?Z gnus-tmp-unread-and-unselected ?s)
1336     (?V gnus-version ?s)
1337     (?U gnus-tmp-unread-and-unticked ?d)
1338     (?S gnus-tmp-subject ?s)
1339     (?e gnus-tmp-unselected ?d)
1340     (?u gnus-tmp-user-defined ?s)
1341     (?d (length gnus-newsgroup-dormant) ?d)
1342     (?t (length gnus-newsgroup-marked) ?d)
1343     (?h (length gnus-newsgroup-spam-marked) ?d)
1344     (?r (length gnus-newsgroup-reads) ?d)
1345     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1346     (?E gnus-newsgroup-expunged-tally ?d)
1347     (?s (gnus-current-score-file-nondirectory) ?s)))
1348
1349 (defvar gnus-last-search-regexp nil
1350   "Default regexp for article search command.")
1351
1352 (defvar gnus-summary-search-article-matched-data nil
1353   "Last matched data of article search command.  It is the local variable
1354 in `gnus-article-buffer' which consists of the list of start position,
1355 end position and text.")
1356
1357 (defvar gnus-last-shell-command nil
1358   "Default shell command on article.")
1359
1360 (defvar gnus-newsgroup-agentized nil
1361   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1362 (defvar gnus-newsgroup-begin nil)
1363 (defvar gnus-newsgroup-end nil)
1364 (defvar gnus-newsgroup-last-rmail nil)
1365 (defvar gnus-newsgroup-last-mail nil)
1366 (defvar gnus-newsgroup-last-folder nil)
1367 (defvar gnus-newsgroup-last-file nil)
1368 (defvar gnus-newsgroup-auto-expire nil)
1369 (defvar gnus-newsgroup-active nil)
1370
1371 (defvar gnus-newsgroup-data nil)
1372 (defvar gnus-newsgroup-data-reverse nil)
1373 (defvar gnus-newsgroup-limit nil)
1374 (defvar gnus-newsgroup-limits nil)
1375 (defvar gnus-summary-use-undownloaded-faces nil)
1376
1377 (defvar gnus-newsgroup-unreads nil
1378   "Sorted list of unread articles in the current newsgroup.")
1379
1380 (defvar gnus-newsgroup-unselected nil
1381   "Sorted list of unselected unread articles in the current newsgroup.")
1382
1383 (defvar gnus-newsgroup-reads nil
1384   "Alist of read articles and article marks in the current newsgroup.")
1385
1386 (defvar gnus-newsgroup-expunged-tally nil)
1387
1388 (defvar gnus-newsgroup-marked nil
1389   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1390
1391 (defvar gnus-newsgroup-spam-marked nil
1392   "List of ranges of articles that have been marked as spam.")
1393
1394 (defvar gnus-newsgroup-killed nil
1395   "List of ranges of articles that have been through the scoring process.")
1396
1397 (defvar gnus-newsgroup-cached nil
1398   "Sorted list of articles that come from the article cache.")
1399
1400 (defvar gnus-newsgroup-saved nil
1401   "List of articles that have been saved.")
1402
1403 (defvar gnus-newsgroup-kill-headers nil)
1404
1405 (defvar gnus-newsgroup-replied nil
1406   "List of articles that have been replied to in the current newsgroup.")
1407
1408 (defvar gnus-newsgroup-forwarded nil
1409   "List of articles that have been forwarded in the current newsgroup.")
1410
1411 (defvar gnus-newsgroup-recent nil
1412   "List of articles that have are recent in the current newsgroup.")
1413
1414 (defvar gnus-newsgroup-expirable nil
1415   "Sorted list of articles in the current newsgroup that can be expired.")
1416
1417 (defvar gnus-newsgroup-processable nil
1418   "List of articles in the current newsgroup that can be processed.")
1419
1420 (defvar gnus-newsgroup-downloadable nil
1421   "Sorted list of articles in the current newsgroup that can be processed.")
1422
1423 (defvar gnus-newsgroup-unfetched nil
1424   "Sorted list of articles in the current newsgroup whose headers have
1425 not been fetched into the agent.
1426
1427 This list will always be a subset of gnus-newsgroup-undownloaded.")
1428
1429 (defvar gnus-newsgroup-undownloaded nil
1430   "List of articles in the current newsgroup that haven't been downloaded.")
1431
1432 (defvar gnus-newsgroup-unsendable nil
1433   "List of articles in the current newsgroup that won't be sent.")
1434
1435 (defvar gnus-newsgroup-bookmarks nil
1436   "List of articles in the current newsgroup that have bookmarks.")
1437
1438 (defvar gnus-newsgroup-dormant nil
1439   "Sorted list of dormant articles in the current newsgroup.")
1440
1441 (defvar gnus-newsgroup-unseen nil
1442   "List of unseen articles in the current newsgroup.")
1443
1444 (defvar gnus-newsgroup-seen nil
1445   "Range of seen articles in the current newsgroup.")
1446
1447 (defvar gnus-newsgroup-articles nil
1448   "List of articles in the current newsgroup.")
1449
1450 (defvar gnus-newsgroup-scored nil
1451   "List of scored articles in the current newsgroup.")
1452
1453 (defvar gnus-newsgroup-incorporated nil
1454   "List of incorporated articles in the current newsgroup.")
1455
1456 (defvar gnus-newsgroup-headers nil
1457   "List of article headers in the current newsgroup.")
1458
1459 (defvar gnus-newsgroup-threads nil)
1460
1461 (defvar gnus-newsgroup-prepared nil
1462   "Whether the current group has been prepared properly.")
1463
1464 (defvar gnus-newsgroup-ancient nil
1465   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1466
1467 (defvar gnus-newsgroup-sparse nil)
1468
1469 (defvar gnus-current-article nil)
1470 (defvar gnus-article-current nil)
1471 (defvar gnus-current-headers nil)
1472 (defvar gnus-have-all-headers nil)
1473 (defvar gnus-last-article nil)
1474 (defvar gnus-newsgroup-history nil)
1475 (defvar gnus-newsgroup-charset nil)
1476 (defvar gnus-newsgroup-ephemeral-charset nil)
1477 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1478
1479 (defvar gnus-article-before-search nil)
1480
1481 (defvar gnus-summary-local-variables
1482   '(gnus-newsgroup-name
1483     gnus-newsgroup-begin gnus-newsgroup-end
1484     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1485     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1486     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1487     gnus-newsgroup-unselected gnus-newsgroup-marked
1488     gnus-newsgroup-spam-marked
1489     gnus-newsgroup-reads gnus-newsgroup-saved
1490     gnus-newsgroup-replied gnus-newsgroup-forwarded
1491     gnus-newsgroup-recent
1492     gnus-newsgroup-expirable
1493     gnus-newsgroup-processable gnus-newsgroup-killed
1494     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1495     gnus-newsgroup-unfetched
1496     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1497     gnus-newsgroup-seen gnus-newsgroup-articles
1498     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1499     gnus-newsgroup-headers gnus-newsgroup-threads
1500     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1501     gnus-current-article gnus-current-headers gnus-have-all-headers
1502     gnus-last-article gnus-article-internal-prepare-hook
1503     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1504     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1505     gnus-thread-expunge-below
1506     gnus-score-alist gnus-current-score-file
1507     (gnus-summary-expunge-below . global)
1508     (gnus-summary-mark-below . global)
1509     (gnus-orphan-score . global)
1510     gnus-newsgroup-active gnus-scores-exclude-files
1511     gnus-newsgroup-history gnus-newsgroup-ancient
1512     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1513     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1514     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1515     (gnus-newsgroup-expunged-tally . 0)
1516     gnus-cache-removable-articles gnus-newsgroup-cached
1517     gnus-newsgroup-data gnus-newsgroup-data-reverse
1518     gnus-newsgroup-limit gnus-newsgroup-limits
1519     gnus-newsgroup-charset gnus-newsgroup-display
1520     gnus-summary-use-undownloaded-faces
1521     gnus-newsgroup-incorporated)
1522   "Variables that are buffer-local to the summary buffers.")
1523
1524 (defvar gnus-newsgroup-variables nil
1525   "A list of variables that have separate values in different newsgroups.
1526 A list of newsgroup (summary buffer) local variables, or cons of
1527 variables and their default expressions to be evalled (when the default
1528 values are not nil), that should be made global while the summary buffer
1529 is active.
1530
1531 Note: The default expressions will be evaluated (using function `eval')
1532 before assignment to the local variable rather than just assigned to it.
1533 If the default expression is the symbol `global', that symbol will not
1534 be evaluated but the global value of the local variable will be used
1535 instead.
1536
1537 These variables can be used to set variables in the group parameters
1538 while still allowing them to affect operations done in other buffers.
1539 For example:
1540
1541 \(setq gnus-newsgroup-variables
1542      '(message-use-followup-to
1543        (gnus-visible-headers .
1544          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1545 ")
1546
1547 ;; Byte-compiler warning.
1548 (eval-when-compile
1549   ;; Bind features so that require will believe that gnus-sum has
1550   ;; already been loaded (avoids infinite recursion)
1551   (let ((features (cons 'gnus-sum features)))
1552     ;; Several of the declarations in gnus-sum are needed to load the
1553     ;; following files. Right now, these definitions have been
1554     ;; compiled but not defined (evaluated).  We could either do a
1555     ;; eval-and-compile about all of the declarations or evaluate the
1556     ;; source file.
1557     (if (boundp 'gnus-newsgroup-variables)
1558         nil
1559       (load "gnus-sum.el" t t t))
1560     (require 'gnus)
1561     (require 'gnus-art)))
1562
1563 ;; Subject simplification.
1564
1565 (defun gnus-simplify-whitespace (str)
1566   "Remove excessive whitespace from STR."
1567   ;; Multiple spaces.
1568   (while (string-match "[ \t][ \t]+" str)
1569     (setq str (concat (substring str 0 (match-beginning 0))
1570                         " "
1571                         (substring str (match-end 0)))))
1572   ;; Leading spaces.
1573   (when (string-match "^[ \t]+" str)
1574     (setq str (substring str (match-end 0))))
1575   ;; Trailing spaces.
1576   (when (string-match "[ \t]+$" str)
1577     (setq str (substring str 0 (match-beginning 0))))
1578   str)
1579
1580 (defun gnus-simplify-all-whitespace (str)
1581   "Remove all whitespace from STR."
1582   (while (string-match "[ \t\n]+" str)
1583     (setq str (replace-match "" nil nil str)))
1584   str)
1585
1586 (defsubst gnus-simplify-subject-re (subject)
1587   "Remove \"Re:\" from subject lines."
1588   (if (string-match message-subject-re-regexp subject)
1589       (substring subject (match-end 0))
1590     subject))
1591
1592 (defun gnus-simplify-subject (subject &optional re-only)
1593   "Remove `Re:' and words in parentheses.
1594 If RE-ONLY is non-nil, strip leading `Re:'s only."
1595   (let ((case-fold-search t))           ;Ignore case.
1596     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1597     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1598       (setq subject (substring subject (match-end 0))))
1599     ;; Remove uninteresting prefixes.
1600     (when (and (not re-only)
1601                gnus-simplify-ignored-prefixes
1602                (string-match gnus-simplify-ignored-prefixes subject))
1603       (setq subject (substring subject (match-end 0))))
1604     ;; Remove words in parentheses from end.
1605     (unless re-only
1606       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1607         (setq subject (substring subject 0 (match-beginning 0)))))
1608     ;; Return subject string.
1609     subject))
1610
1611 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1612 ;; all whitespace.
1613 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1614   (goto-char (point-min))
1615   (while (re-search-forward regexp nil t)
1616     (replace-match (or newtext ""))))
1617
1618 (defun gnus-simplify-buffer-fuzzy ()
1619   "Simplify string in the buffer fuzzily.
1620 The string in the accessible portion of the current buffer is simplified.
1621 It is assumed to be a single-line subject.
1622 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1623 matter is removed.  Additional things can be deleted by setting
1624 `gnus-simplify-subject-fuzzy-regexp'."
1625   (let ((case-fold-search t)
1626         (modified-tick))
1627     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1628
1629     (while (not (eq modified-tick (buffer-modified-tick)))
1630       (setq modified-tick (buffer-modified-tick))
1631       (cond
1632        ((listp gnus-simplify-subject-fuzzy-regexp)
1633         (mapcar 'gnus-simplify-buffer-fuzzy-step
1634                 gnus-simplify-subject-fuzzy-regexp))
1635        (gnus-simplify-subject-fuzzy-regexp
1636         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1637       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1638       (gnus-simplify-buffer-fuzzy-step
1639        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1640       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1641
1642     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1643     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1644     (gnus-simplify-buffer-fuzzy-step " $")
1645     (gnus-simplify-buffer-fuzzy-step "^ +")))
1646
1647 (defun gnus-simplify-subject-fuzzy (subject)
1648   "Simplify a subject string fuzzily.
1649 See `gnus-simplify-buffer-fuzzy' for details."
1650   (save-excursion
1651     (gnus-set-work-buffer)
1652     (let ((case-fold-search t))
1653       ;; Remove uninteresting prefixes.
1654       (when (and gnus-simplify-ignored-prefixes
1655                  (string-match gnus-simplify-ignored-prefixes subject))
1656         (setq subject (substring subject (match-end 0))))
1657       (insert subject)
1658       (inline (gnus-simplify-buffer-fuzzy))
1659       (buffer-string))))
1660
1661 (defsubst gnus-simplify-subject-fully (subject)
1662   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1663   (cond
1664    (gnus-simplify-subject-functions
1665     (gnus-map-function gnus-simplify-subject-functions subject))
1666    ((null gnus-summary-gather-subject-limit)
1667     (gnus-simplify-subject-re subject))
1668    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1669     (gnus-simplify-subject-fuzzy subject))
1670    ((numberp gnus-summary-gather-subject-limit)
1671     (gnus-limit-string (gnus-simplify-subject-re subject)
1672                        gnus-summary-gather-subject-limit))
1673    (t
1674     subject)))
1675
1676 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1677   "Check whether two subjects are equal.
1678 If optional argument SIMPLE-FIRST is t, first argument is already
1679 simplified."
1680   (cond
1681    ((null simple-first)
1682     (equal (gnus-simplify-subject-fully s1)
1683            (gnus-simplify-subject-fully s2)))
1684    (t
1685     (equal s1
1686            (gnus-simplify-subject-fully s2)))))
1687
1688 (defun gnus-summary-bubble-group ()
1689   "Increase the score of the current group.
1690 This is a handy function to add to `gnus-summary-exit-hook' to
1691 increase the score of each group you read."
1692   (gnus-group-add-score gnus-newsgroup-name))
1693
1694 \f
1695 ;;;
1696 ;;; Gnus summary mode
1697 ;;;
1698
1699 (put 'gnus-summary-mode 'mode-class 'special)
1700
1701 (defvar gnus-article-commands-menu)
1702
1703 ;; Non-orthogonal keys
1704
1705 (gnus-define-keys gnus-summary-mode-map
1706   " " gnus-summary-next-page
1707   "\177" gnus-summary-prev-page
1708   [delete] gnus-summary-prev-page
1709   [backspace] gnus-summary-prev-page
1710   "\r" gnus-summary-scroll-up
1711   "\M-\r" gnus-summary-scroll-down
1712   "n" gnus-summary-next-unread-article
1713   "p" gnus-summary-prev-unread-article
1714   "N" gnus-summary-next-article
1715   "P" gnus-summary-prev-article
1716   "\M-\C-n" gnus-summary-next-same-subject
1717   "\M-\C-p" gnus-summary-prev-same-subject
1718   "\M-n" gnus-summary-next-unread-subject
1719   "\M-p" gnus-summary-prev-unread-subject
1720   "." gnus-summary-first-unread-article
1721   "," gnus-summary-best-unread-article
1722   "\M-s" gnus-summary-search-article-forward
1723   "\M-r" gnus-summary-search-article-backward
1724   "<" gnus-summary-beginning-of-article
1725   ">" gnus-summary-end-of-article
1726   "j" gnus-summary-goto-article
1727   "^" gnus-summary-refer-parent-article
1728   "\M-^" gnus-summary-refer-article
1729   "u" gnus-summary-tick-article-forward
1730   "!" gnus-summary-tick-article-forward
1731   "U" gnus-summary-tick-article-backward
1732   "d" gnus-summary-mark-as-read-forward
1733   "D" gnus-summary-mark-as-read-backward
1734   "E" gnus-summary-mark-as-expirable
1735   "\M-u" gnus-summary-clear-mark-forward
1736   "\M-U" gnus-summary-clear-mark-backward
1737   "k" gnus-summary-kill-same-subject-and-select
1738   "\C-k" gnus-summary-kill-same-subject
1739   "\M-\C-k" gnus-summary-kill-thread
1740   "\M-\C-l" gnus-summary-lower-thread
1741   "e" gnus-summary-edit-article
1742   "#" gnus-summary-mark-as-processable
1743   "\M-#" gnus-summary-unmark-as-processable
1744   "\M-\C-t" gnus-summary-toggle-threads
1745   "\M-\C-s" gnus-summary-show-thread
1746   "\M-\C-h" gnus-summary-hide-thread
1747   "\M-\C-f" gnus-summary-next-thread
1748   "\M-\C-b" gnus-summary-prev-thread
1749   [(meta down)] gnus-summary-next-thread
1750   [(meta up)] gnus-summary-prev-thread
1751   "\M-\C-u" gnus-summary-up-thread
1752   "\M-\C-d" gnus-summary-down-thread
1753   "&" gnus-summary-execute-command
1754   "c" gnus-summary-catchup-and-exit
1755   "\C-w" gnus-summary-mark-region-as-read
1756   "\C-t" gnus-summary-toggle-truncation
1757   "?" gnus-summary-mark-as-dormant
1758   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1759   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1760   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1761   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1762   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1763   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1764   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1765   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1766   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1767   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1768   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1769   "=" gnus-summary-expand-window
1770   "\C-x\C-s" gnus-summary-reselect-current-group
1771   "\M-g" gnus-summary-rescan-group
1772   "w" gnus-summary-stop-page-breaking
1773   "\C-c\C-r" gnus-summary-caesar-message
1774   "\M-t" gnus-summary-toggle-mime
1775   "f" gnus-summary-followup
1776   "F" gnus-summary-followup-with-original
1777   "C" gnus-summary-cancel-article
1778   "r" gnus-summary-reply
1779   "R" gnus-summary-reply-with-original
1780   "\C-c\C-f" gnus-summary-mail-forward
1781   "o" gnus-summary-save-article
1782   "\C-o" gnus-summary-save-article-mail
1783   "|" gnus-summary-pipe-output
1784   "\M-k" gnus-summary-edit-local-kill
1785   "\M-K" gnus-summary-edit-global-kill
1786   ;; "V" gnus-version
1787   "\C-c\C-d" gnus-summary-describe-group
1788   "q" gnus-summary-exit
1789   "Q" gnus-summary-exit-no-update
1790   "\C-c\C-i" gnus-info-find-node
1791   gnus-mouse-2 gnus-mouse-pick-article
1792   [follow-link] mouse-face
1793   "m" gnus-summary-mail-other-window
1794   "a" gnus-summary-post-news
1795   "i" gnus-summary-news-other-window
1796   "x" gnus-summary-limit-to-unread
1797   "s" gnus-summary-isearch-article
1798   "t" gnus-summary-toggle-header
1799   "g" gnus-summary-show-article
1800   "l" gnus-summary-goto-last-article
1801   "v" gnus-summary-preview-mime-message
1802   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1803   "\C-d" gnus-summary-enter-digest-group
1804   "\M-\C-d" gnus-summary-read-document
1805   "\M-\C-e" gnus-summary-edit-parameters
1806   "\M-\C-a" gnus-summary-customize-parameters
1807   "\C-c\C-b" gnus-bug
1808   "\C-c\C-n" gnus-namazu-search
1809   "*" gnus-cache-enter-article
1810   "\M-*" gnus-cache-remove-article
1811   "\M-&" gnus-summary-universal-argument
1812   "\C-l" gnus-recenter
1813   "I" gnus-summary-increase-score
1814   "L" gnus-summary-lower-score
1815   "\M-i" gnus-symbolic-argument
1816   "h" gnus-summary-select-article-buffer
1817
1818   "V" gnus-summary-score-map
1819   "X" gnus-uu-extract-map
1820   "S" gnus-summary-send-map)
1821
1822   ;; Sort of orthogonal keymap
1823 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1824   "t" gnus-summary-tick-article-forward
1825   "!" gnus-summary-tick-article-forward
1826   "d" gnus-summary-mark-as-read-forward
1827   "r" gnus-summary-mark-as-read-forward
1828   "c" gnus-summary-clear-mark-forward
1829   " " gnus-summary-clear-mark-forward
1830   "e" gnus-summary-mark-as-expirable
1831   "x" gnus-summary-mark-as-expirable
1832   "?" gnus-summary-mark-as-dormant
1833   "b" gnus-summary-set-bookmark
1834   "B" gnus-summary-remove-bookmark
1835   "#" gnus-summary-mark-as-processable
1836   "\M-#" gnus-summary-unmark-as-processable
1837   "S" gnus-summary-limit-include-expunged
1838   "C" gnus-summary-catchup
1839   "H" gnus-summary-catchup-to-here
1840   "h" gnus-summary-catchup-from-here
1841   "\C-c" gnus-summary-catchup-all
1842   "k" gnus-summary-kill-same-subject-and-select
1843   "K" gnus-summary-kill-same-subject
1844   "P" gnus-uu-mark-map)
1845
1846 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1847   "c" gnus-summary-clear-above
1848   "u" gnus-summary-tick-above
1849   "m" gnus-summary-mark-above
1850   "k" gnus-summary-kill-below)
1851
1852 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1853   "/" gnus-summary-limit-to-subject
1854   "n" gnus-summary-limit-to-articles
1855   "w" gnus-summary-pop-limit
1856   "s" gnus-summary-limit-to-subject
1857   "a" gnus-summary-limit-to-author
1858   "u" gnus-summary-limit-to-unread
1859   "m" gnus-summary-limit-to-marks
1860   "M" gnus-summary-limit-exclude-marks
1861   "v" gnus-summary-limit-to-score
1862   "*" gnus-summary-limit-include-cached
1863   "D" gnus-summary-limit-include-dormant
1864   "T" gnus-summary-limit-include-thread
1865   "d" gnus-summary-limit-exclude-dormant
1866   "t" gnus-summary-limit-to-age
1867   "." gnus-summary-limit-to-unseen
1868   "x" gnus-summary-limit-to-extra
1869   "p" gnus-summary-limit-to-display-predicate
1870   "E" gnus-summary-limit-include-expunged
1871   "c" gnus-summary-limit-exclude-childless-dormant
1872   "C" gnus-summary-limit-mark-excluded-as-read
1873   "o" gnus-summary-insert-old-articles
1874   "N" gnus-summary-insert-new-articles
1875   "r" gnus-summary-limit-to-replied
1876   "R" gnus-summary-limit-to-recipient)
1877
1878 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1879   "n" gnus-summary-next-unread-article
1880   "p" gnus-summary-prev-unread-article
1881   "N" gnus-summary-next-article
1882   "P" gnus-summary-prev-article
1883   "\C-n" gnus-summary-next-same-subject
1884   "\C-p" gnus-summary-prev-same-subject
1885   "\M-n" gnus-summary-next-unread-subject
1886   "\M-p" gnus-summary-prev-unread-subject
1887   "f" gnus-summary-first-unread-article
1888   "b" gnus-summary-best-unread-article
1889   "j" gnus-summary-goto-article
1890   "g" gnus-summary-goto-subject
1891   "l" gnus-summary-goto-last-article
1892   "o" gnus-summary-pop-article)
1893
1894 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1895   "k" gnus-summary-kill-thread
1896   "l" gnus-summary-lower-thread
1897   "i" gnus-summary-raise-thread
1898   "T" gnus-summary-toggle-threads
1899   "t" gnus-summary-rethread-current
1900   "^" gnus-summary-reparent-thread
1901   "s" gnus-summary-show-thread
1902   "S" gnus-summary-show-all-threads
1903   "h" gnus-summary-hide-thread
1904   "H" gnus-summary-hide-all-threads
1905   "n" gnus-summary-next-thread
1906   "p" gnus-summary-prev-thread
1907   "u" gnus-summary-up-thread
1908   "o" gnus-summary-top-thread
1909   "d" gnus-summary-down-thread
1910   "#" gnus-uu-mark-thread
1911   "\M-#" gnus-uu-unmark-thread)
1912
1913 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1914   "g" gnus-summary-prepare
1915   "c" gnus-summary-insert-cached-articles
1916   "d" gnus-summary-insert-dormant-articles)
1917
1918 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1919   "c" gnus-summary-catchup-and-exit
1920   "C" gnus-summary-catchup-all-and-exit
1921   "E" gnus-summary-exit-no-update
1922   "J" gnus-summary-jump-to-other-group
1923   "Q" gnus-summary-exit
1924   "Z" gnus-summary-exit
1925   "n" gnus-summary-catchup-and-goto-next-group
1926   "R" gnus-summary-reselect-current-group
1927   "G" gnus-summary-rescan-group
1928   "N" gnus-summary-next-group
1929   "s" gnus-summary-save-newsrc
1930   "P" gnus-summary-prev-group)
1931
1932 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1933   " " gnus-summary-next-page
1934   "n" gnus-summary-next-page
1935   "\177" gnus-summary-prev-page
1936   [delete] gnus-summary-prev-page
1937   "p" gnus-summary-prev-page
1938   "\r" gnus-summary-scroll-up
1939   "\M-\r" gnus-summary-scroll-down
1940   "<" gnus-summary-beginning-of-article
1941   ">" gnus-summary-end-of-article
1942   "b" gnus-summary-beginning-of-article
1943   "e" gnus-summary-end-of-article
1944   "^" gnus-summary-refer-parent-article
1945   "r" gnus-summary-refer-parent-article
1946   "D" gnus-summary-enter-digest-group
1947   "R" gnus-summary-refer-references
1948   "T" gnus-summary-refer-thread
1949   "g" gnus-summary-show-article
1950   "s" gnus-summary-isearch-article
1951   "P" gnus-summary-print-article
1952   "M" gnus-mailing-list-insinuate
1953   "t" gnus-article-babel)
1954
1955 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1956   "b" gnus-article-add-buttons
1957   "B" gnus-article-add-buttons-to-head
1958   "o" gnus-article-treat-overstrike
1959   "e" gnus-article-emphasize
1960   "w" gnus-article-fill-cited-article
1961   "Q" gnus-article-fill-long-lines
1962   "C" gnus-article-capitalize-sentences
1963   "c" gnus-article-remove-cr
1964   "Z" gnus-article-decode-HZ
1965   "A" gnus-article-treat-ansi-sequences
1966   "h" gnus-article-wash-html
1967   "u" gnus-article-unsplit-urls
1968   "f" gnus-article-display-x-face
1969   "l" gnus-summary-stop-page-breaking
1970   "r" gnus-summary-caesar-message
1971   "m" gnus-summary-morse-message
1972   "t" gnus-summary-toggle-header
1973   "g" gnus-treat-smiley
1974   "v" gnus-summary-verbose-headers
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   "O" gnus-article-save-part-and-strip
2084   "r" gnus-article-replace-part
2085   "d" gnus-article-delete-part
2086   "j" gnus-article-jump-to-part
2087   "c" gnus-article-copy-part
2088   "C" gnus-article-view-part-as-charset
2089   "e" gnus-article-view-part-externally
2090   "E" gnus-article-encrypt-body
2091   "i" gnus-article-inline-part
2092   "|" gnus-article-pipe-part)
2093
2094 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2095   "p" gnus-summary-mark-as-processable
2096   "u" gnus-summary-unmark-as-processable
2097   "U" gnus-summary-unmark-all-processable
2098   "v" gnus-uu-mark-over
2099   "s" gnus-uu-mark-series
2100   "r" gnus-uu-mark-region
2101   "g" gnus-uu-unmark-region
2102   "R" gnus-uu-mark-by-regexp
2103   "G" gnus-uu-unmark-by-regexp
2104   "t" gnus-uu-mark-thread
2105   "T" gnus-uu-unmark-thread
2106   "a" gnus-uu-mark-all
2107   "b" gnus-uu-mark-buffer
2108   "S" gnus-uu-mark-sparse
2109   "k" gnus-summary-kill-process-mark
2110   "y" gnus-summary-yank-process-mark
2111   "w" gnus-summary-save-process-mark
2112   "i" gnus-uu-invert-processable)
2113
2114 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2115   ;;"x" gnus-uu-extract-any
2116   "m" gnus-summary-save-parts
2117   "u" gnus-uu-decode-uu
2118   "U" gnus-uu-decode-uu-and-save
2119   "s" gnus-uu-decode-unshar
2120   "S" gnus-uu-decode-unshar-and-save
2121   "o" gnus-uu-decode-save
2122   "O" gnus-uu-decode-save
2123   "b" gnus-uu-decode-binhex
2124   "B" gnus-uu-decode-binhex
2125   "p" gnus-uu-decode-postscript
2126   "P" gnus-uu-decode-postscript-and-save)
2127
2128 (gnus-define-keys
2129     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2130   "u" gnus-uu-decode-uu-view
2131   "U" gnus-uu-decode-uu-and-save-view
2132   "s" gnus-uu-decode-unshar-view
2133   "S" gnus-uu-decode-unshar-and-save-view
2134   "o" gnus-uu-decode-save-view
2135   "O" gnus-uu-decode-save-view
2136   "b" gnus-uu-decode-binhex-view
2137   "B" gnus-uu-decode-binhex-view
2138   "p" gnus-uu-decode-postscript-view
2139   "P" gnus-uu-decode-postscript-and-save-view)
2140
2141 (defvar gnus-article-post-menu nil)
2142
2143 (defconst gnus-summary-menu-maxlen 20)
2144
2145 (defun gnus-summary-menu-split (menu)
2146   ;; If we have lots of elements, divide them into groups of 20
2147   ;; and make a pane (or submenu) for each one.
2148   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2149       (let ((menu menu) sublists next
2150             (i 1))
2151         (while menu
2152           ;; Pull off the next gnus-summary-menu-maxlen elements
2153           ;; and make them the next element of sublist.
2154           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2155           (if next
2156               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2157                       nil))
2158           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2159                                              (aref (car (last menu)) 0)) menu)
2160                                sublists))
2161           (setq i (1+ i))
2162           (setq menu next))
2163         (nreverse sublists))
2164     ;; Few elements--put them all in one pane.
2165     menu))
2166
2167 (defun gnus-summary-make-menu-bar ()
2168   (gnus-turn-off-edit-menu 'summary)
2169
2170   (unless (boundp 'gnus-summary-misc-menu)
2171
2172     (easy-menu-define
2173       gnus-summary-kill-menu gnus-summary-mode-map ""
2174       (cons
2175        "Score"
2176        (nconc
2177         (list
2178          ["Customize" gnus-score-customize t])
2179         (gnus-make-score-map 'increase)
2180         (gnus-make-score-map 'lower)
2181         '(("Mark"
2182            ["Kill below" gnus-summary-kill-below t]
2183            ["Mark above" gnus-summary-mark-above t]
2184            ["Tick above" gnus-summary-tick-above t]
2185            ["Clear above" gnus-summary-clear-above t])
2186           ["Current score" gnus-summary-current-score t]
2187           ["Set score" gnus-summary-set-score t]
2188           ["Switch current score file..." gnus-score-change-score-file t]
2189           ["Set mark below..." gnus-score-set-mark-below t]
2190           ["Set expunge below..." gnus-score-set-expunge-below t]
2191           ["Edit current score file" gnus-score-edit-current-scores t]
2192           ["Edit score file" gnus-score-edit-file t]
2193           ["Trace score" gnus-score-find-trace t]
2194           ["Find words" gnus-score-find-favourite-words t]
2195           ["Rescore buffer" gnus-summary-rescore t]
2196           ["Increase score..." gnus-summary-increase-score t]
2197           ["Lower score..." gnus-summary-lower-score t]))))
2198
2199     ;; Define both the Article menu in the summary buffer and the
2200     ;; equivalent Commands menu in the article buffer here for
2201     ;; consistency.
2202     (let ((innards
2203            `(("Hide"
2204               ["All" gnus-article-hide t]
2205               ["Headers" gnus-article-hide-headers t]
2206               ["Signature" gnus-article-hide-signature t]
2207               ["Citation" gnus-article-hide-citation t]
2208               ["List identifiers" gnus-article-hide-list-identifiers t]
2209               ["Banner" gnus-article-strip-banner t]
2210               ["Boring headers" gnus-article-hide-boring-headers t])
2211              ("Highlight"
2212               ["All" gnus-article-highlight t]
2213               ["Headers" gnus-article-highlight-headers t]
2214               ["Signature" gnus-article-highlight-signature t]
2215               ["Citation" gnus-article-highlight-citation t])
2216              ("Date"
2217               ["Local" gnus-article-date-local t]
2218               ["ISO8601" gnus-article-date-iso8601 t]
2219               ["UT" gnus-article-date-ut t]
2220               ["Original" gnus-article-date-original t]
2221               ["Lapsed" gnus-article-date-lapsed t]
2222               ["User-defined" gnus-article-date-user t])
2223              ("Display"
2224               ["Remove images" gnus-article-remove-images t]
2225               ["Toggle smiley" gnus-treat-smiley t]
2226               ["Show X-Face" gnus-article-display-x-face t]
2227               ["Show picons in From" gnus-treat-from-picon t]
2228               ["Show picons in mail headers" gnus-treat-mail-picon t]
2229               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2230               ("View as different encoding"
2231                ,@(gnus-summary-menu-split
2232                   (mapcar
2233                    (lambda (cs)
2234                      ;; Since easymenu under Emacs doesn't allow
2235                      ;; lambda forms for menu commands, we should
2236                      ;; provide intern'ed function symbols.
2237                      (let ((command (intern (format "\
2238 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2239                        (fset command
2240                              `(lambda ()
2241                                 (interactive)
2242                                 (let ((gnus-summary-show-article-charset-alist
2243                                        '((1 . ,cs))))
2244                                   (gnus-summary-show-article 1))))
2245                        `[,(symbol-name cs) ,command t]))
2246                    (sort (if (fboundp 'coding-system-list)
2247                              (coding-system-list)
2248                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2249                            )
2250                          'string<)))))
2251              ("Washing"
2252               ("Remove Blanks"
2253                ["Leading" gnus-article-strip-leading-blank-lines t]
2254                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2255                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2256                ["All of the above" gnus-article-strip-blank-lines t]
2257                ["All" gnus-article-strip-all-blank-lines t]
2258                ["Leading space" gnus-article-strip-leading-space t]
2259                ["Trailing space" gnus-article-strip-trailing-space t]
2260                ["Leading space in headers"
2261                 gnus-article-remove-leading-whitespace t])
2262               ["Overstrike" gnus-article-treat-overstrike t]
2263               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2264               ["Emphasis" gnus-article-emphasize t]
2265               ["Word wrap" gnus-article-fill-cited-article t]
2266               ["Fill long lines" gnus-article-fill-long-lines t]
2267               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2268               ["Remove CR" gnus-article-remove-cr t]
2269               ["Rot 13" gnus-summary-caesar-message
2270                ,@(if (featurep 'xemacs) '(t)
2271                    '(:help "\"Caesar rotate\" article by 13"))]
2272               ["De-IDNA" gnus-summary-idna-message t]
2273               ["Morse decode" gnus-summary-morse-message t]
2274               ["Unix pipe..." gnus-summary-pipe-message t]
2275               ["Add buttons" gnus-article-add-buttons t]
2276               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2277               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2278               ["Toggle MIME" gnus-summary-toggle-mime t]
2279               ["Verbose header" gnus-summary-verbose-headers t]
2280               ["Toggle header" gnus-summary-toggle-header t]
2281               ["Unfold headers" gnus-article-treat-unfold-headers t]
2282               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2283               ["Html" gnus-article-wash-html t]
2284               ["Unsplit URLs" gnus-article-unsplit-urls t]
2285               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2286               ["Decode HZ" gnus-article-decode-HZ t]
2287               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2288               ("(Outlook) Deuglify"
2289                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2290                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2291                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2292                ["Full (Outlook) deuglify"
2293                 gnus-article-outlook-deuglify-article t])
2294               )
2295              ("Output"
2296               ["Save in default format..." gnus-summary-save-article
2297                ,@(if (featurep 'xemacs) '(t)
2298                    '(:help "Save article using default method"))]
2299               ["Save in file..." gnus-summary-save-article-file
2300                ,@(if (featurep 'xemacs) '(t)
2301                    '(:help "Save article in file"))]
2302               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2303               ["Save in MH folder..." gnus-summary-save-article-folder t]
2304               ["Save in VM folder..." gnus-summary-save-article-vm t]
2305               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2306               ["Save body in file..." gnus-summary-save-article-body-file t]
2307               ["Pipe through a filter..." gnus-summary-pipe-output t]
2308               ["Add to SOUP packet" gnus-soup-add-article t]
2309               ["Print with Muttprint..." gnus-summary-muttprint t]
2310               ["Print" gnus-summary-print-article
2311                ,@(if (featurep 'xemacs) '(t)
2312                    '(:help "Generate and print a PostScript image"))])
2313              ("Copy, move,... (Backend)"
2314               ,@(if (featurep 'xemacs) nil
2315                   '(:help "Copying, moving, expiring articles..."))
2316               ["Respool article..." gnus-summary-respool-article t]
2317               ["Move article..." gnus-summary-move-article
2318                (gnus-check-backend-function
2319                 'request-move-article gnus-newsgroup-name)]
2320               ["Copy article..." gnus-summary-copy-article t]
2321               ["Crosspost article..." gnus-summary-crosspost-article
2322                (gnus-check-backend-function
2323                 'request-replace-article gnus-newsgroup-name)]
2324               ["Import file..." gnus-summary-import-article
2325                (gnus-check-backend-function
2326                 'request-accept-article gnus-newsgroup-name)]
2327               ["Create article..." gnus-summary-create-article
2328                (gnus-check-backend-function
2329                 'request-accept-article gnus-newsgroup-name)]
2330               ["Check if posted" gnus-summary-article-posted-p t]
2331               ["Edit article" gnus-summary-edit-article
2332                (not (gnus-group-read-only-p))]
2333               ["Delete article" gnus-summary-delete-article
2334                (gnus-check-backend-function
2335                 'request-expire-articles gnus-newsgroup-name)]
2336               ["Query respool" gnus-summary-respool-query t]
2337               ["Trace respool" gnus-summary-respool-trace t]
2338               ["Delete expirable articles" gnus-summary-expire-articles-now
2339                (gnus-check-backend-function
2340                 'request-expire-articles gnus-newsgroup-name)])
2341              ("Extract"
2342               ["Uudecode" gnus-uu-decode-uu
2343                ,@(if (featurep 'xemacs) '(t)
2344                    '(:help "Decode uuencoded article(s)"))]
2345               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2346               ["Unshar" gnus-uu-decode-unshar t]
2347               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2348               ["Save" gnus-uu-decode-save t]
2349               ["Binhex" gnus-uu-decode-binhex t]
2350               ["Postscript" gnus-uu-decode-postscript t])
2351              ("Cache"
2352               ["Enter article" gnus-cache-enter-article t]
2353               ["Remove article" gnus-cache-remove-article t])
2354              ["Translate" gnus-article-babel t]
2355              ["Select article buffer" gnus-summary-select-article-buffer t]
2356              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2357              ["Isearch article..." gnus-summary-isearch-article t]
2358              ["Beginning of the article" gnus-summary-beginning-of-article t]
2359              ["End of the article" gnus-summary-end-of-article t]
2360              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2361              ["Fetch referenced articles" gnus-summary-refer-references t]
2362              ["Fetch current thread" gnus-summary-refer-thread t]
2363              ["Fetch article with id..." gnus-summary-refer-article t]
2364              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2365              ["Redisplay" gnus-summary-show-article t]
2366              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2367       (easy-menu-define
2368         gnus-summary-article-menu gnus-summary-mode-map ""
2369         (cons "Article" innards))
2370
2371       (if (not (keymapp gnus-summary-article-menu))
2372           (easy-menu-define
2373             gnus-article-commands-menu gnus-article-mode-map ""
2374             (cons "Commands" innards))
2375         ;; in Emacs, don't share menu.
2376         (setq gnus-article-commands-menu
2377               (copy-keymap gnus-summary-article-menu))
2378         (define-key gnus-article-mode-map [menu-bar commands]
2379           (cons "Commands" gnus-article-commands-menu))))
2380
2381     (easy-menu-define
2382       gnus-summary-thread-menu gnus-summary-mode-map ""
2383       '("Threads"
2384         ["Find all messages in thread" gnus-summary-refer-thread t]
2385         ["Toggle threading" gnus-summary-toggle-threads t]
2386         ["Hide threads" gnus-summary-hide-all-threads t]
2387         ["Show threads" gnus-summary-show-all-threads t]
2388         ["Hide thread" gnus-summary-hide-thread t]
2389         ["Show thread" gnus-summary-show-thread t]
2390         ["Go to next thread" gnus-summary-next-thread t]
2391         ["Go to previous thread" gnus-summary-prev-thread t]
2392         ["Go down thread" gnus-summary-down-thread t]
2393         ["Go up thread" gnus-summary-up-thread t]
2394         ["Top of thread" gnus-summary-top-thread t]
2395         ["Mark thread as read" gnus-summary-kill-thread t]
2396         ["Lower thread score" gnus-summary-lower-thread t]
2397         ["Raise thread score" gnus-summary-raise-thread t]
2398         ["Rethread current" gnus-summary-rethread-current t]))
2399
2400     (easy-menu-define
2401       gnus-summary-post-menu gnus-summary-mode-map ""
2402       `("Post"
2403         ["Send a message (mail or news)" gnus-summary-post-news
2404          ,@(if (featurep 'xemacs) '(t)
2405              '(:help "Compose a new message (mail or news)"))]
2406         ["Followup" gnus-summary-followup
2407          ,@(if (featurep 'xemacs) '(t)
2408              '(:help "Post followup to this article"))]
2409         ["Followup and yank" gnus-summary-followup-with-original
2410          ,@(if (featurep 'xemacs) '(t)
2411              '(:help "Post followup to this article, quoting its contents"))]
2412         ["Supersede article" gnus-summary-supersede-article t]
2413         ["Cancel article" gnus-summary-cancel-article
2414          ,@(if (featurep 'xemacs) '(t)
2415              '(:help "Cancel an article you posted"))]
2416         ["Reply" gnus-summary-reply t]
2417         ["Reply and yank" gnus-summary-reply-with-original t]
2418         ["Wide reply" gnus-summary-wide-reply t]
2419         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2420          ,@(if (featurep 'xemacs) '(t)
2421              '(:help "Mail a reply, quoting this article"))]
2422         ["Very wide reply" gnus-summary-very-wide-reply t]
2423         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2424          ,@(if (featurep 'xemacs) '(t)
2425              '(:help "Mail a very wide reply, quoting this article"))]
2426         ["Mail forward" gnus-summary-mail-forward t]
2427         ["Post forward" gnus-summary-post-forward t]
2428         ["Digest and mail" gnus-summary-digest-mail-forward t]
2429         ["Digest and post" gnus-summary-digest-post-forward t]
2430         ["Resend message" gnus-summary-resend-message t]
2431         ["Resend message edit" gnus-summary-resend-message-edit t]
2432         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2433         ["Send a mail" gnus-summary-mail-other-window t]
2434         ["Create a local message" gnus-summary-news-other-window t]
2435         ["Uuencode and post" gnus-uu-post-news
2436          ,@(if (featurep 'xemacs) '(t)
2437              '(:help "Post a uuencoded article"))]
2438         ["Followup via news" gnus-summary-followup-to-mail t]
2439         ["Followup via news and yank"
2440          gnus-summary-followup-to-mail-with-original t]
2441         ;;("Draft"
2442         ;;["Send" gnus-summary-send-draft t]
2443         ;;["Send bounced" gnus-resend-bounced-mail t])
2444         ))
2445
2446     (cond
2447      ((not (keymapp gnus-summary-post-menu))
2448       (setq gnus-article-post-menu gnus-summary-post-menu))
2449      ((not gnus-article-post-menu)
2450       ;; Don't share post menu.
2451       (setq gnus-article-post-menu
2452             (copy-keymap gnus-summary-post-menu))))
2453     (define-key gnus-article-mode-map [menu-bar post]
2454       (cons "Post" gnus-article-post-menu))
2455
2456     (easy-menu-define
2457       gnus-summary-misc-menu gnus-summary-mode-map ""
2458       `("Gnus"
2459         ("Mark Read"
2460          ["Mark as read" gnus-summary-mark-as-read-forward t]
2461          ["Mark same subject and select"
2462           gnus-summary-kill-same-subject-and-select t]
2463          ["Mark same subject" gnus-summary-kill-same-subject t]
2464          ["Catchup" gnus-summary-catchup
2465           ,@(if (featurep 'xemacs) '(t)
2466               '(:help "Mark unread articles in this group as read"))]
2467          ["Catchup all" gnus-summary-catchup-all t]
2468          ["Catchup to here" gnus-summary-catchup-to-here t]
2469          ["Catchup from here" gnus-summary-catchup-from-here t]
2470          ["Catchup region" gnus-summary-mark-region-as-read
2471           (gnus-mark-active-p)]
2472          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2473         ("Mark Various"
2474          ["Tick" gnus-summary-tick-article-forward t]
2475          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2476          ["Remove marks" gnus-summary-clear-mark-forward t]
2477          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2478          ["Set bookmark" gnus-summary-set-bookmark t]
2479          ["Remove bookmark" gnus-summary-remove-bookmark t])
2480         ("Limit to"
2481          ["Marks..." gnus-summary-limit-to-marks t]
2482          ["Subject..." gnus-summary-limit-to-subject t]
2483          ["Author..." gnus-summary-limit-to-author t]
2484          ["Recipient..." gnus-summary-limit-to-recipient t]
2485          ["Age..." gnus-summary-limit-to-age t]
2486          ["Extra..." gnus-summary-limit-to-extra t]
2487          ["Score..." gnus-summary-limit-to-score t]
2488          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2489          ["Unread" gnus-summary-limit-to-unread t]
2490          ["Unseen" gnus-summary-limit-to-unseen t]
2491          ["Replied" gnus-summary-limit-to-replied t]
2492          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2493          ["Next articles" gnus-summary-limit-to-articles t]
2494          ["Pop limit" gnus-summary-pop-limit t]
2495          ["Show dormant" gnus-summary-limit-include-dormant t]
2496          ["Hide childless dormant"
2497           gnus-summary-limit-exclude-childless-dormant t]
2498          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2499          ["Hide marked" gnus-summary-limit-exclude-marks t]
2500          ["Show expunged" gnus-summary-limit-include-expunged t])
2501         ("Process Mark"
2502          ["Set mark" gnus-summary-mark-as-processable t]
2503          ["Remove mark" gnus-summary-unmark-as-processable t]
2504          ["Remove all marks" gnus-summary-unmark-all-processable t]
2505          ["Invert marks" gnus-uu-invert-processable t]
2506          ["Mark above" gnus-uu-mark-over t]
2507          ["Mark series" gnus-uu-mark-series t]
2508          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2509          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2510          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2511          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2512          ["Mark all" gnus-uu-mark-all t]
2513          ["Mark buffer" gnus-uu-mark-buffer t]
2514          ["Mark sparse" gnus-uu-mark-sparse t]
2515          ["Mark thread" gnus-uu-mark-thread t]
2516          ["Unmark thread" gnus-uu-unmark-thread t]
2517          ("Process Mark Sets"
2518           ["Kill" gnus-summary-kill-process-mark t]
2519           ["Yank" gnus-summary-yank-process-mark
2520            gnus-newsgroup-process-stack]
2521           ["Save" gnus-summary-save-process-mark t]
2522           ["Run command on marked..." gnus-summary-universal-argument t]))
2523         ("Scroll article"
2524          ["Page forward" gnus-summary-next-page
2525           ,@(if (featurep 'xemacs) '(t)
2526               '(:help "Show next page of article"))]
2527          ["Page backward" gnus-summary-prev-page
2528           ,@(if (featurep 'xemacs) '(t)
2529               '(:help "Show previous page of article"))]
2530          ["Line forward" gnus-summary-scroll-up t])
2531         ("Move"
2532          ["Next unread article" gnus-summary-next-unread-article t]
2533          ["Previous unread article" gnus-summary-prev-unread-article t]
2534          ["Next article" gnus-summary-next-article t]
2535          ["Previous article" gnus-summary-prev-article t]
2536          ["Next unread subject" gnus-summary-next-unread-subject t]
2537          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2538          ["Next article same subject" gnus-summary-next-same-subject t]
2539          ["Previous article same subject" gnus-summary-prev-same-subject t]
2540          ["First unread article" gnus-summary-first-unread-article t]
2541          ["Best unread article" gnus-summary-best-unread-article t]
2542          ["Go to subject number..." gnus-summary-goto-subject t]
2543          ["Go to article number..." gnus-summary-goto-article t]
2544          ["Go to the last article" gnus-summary-goto-last-article t]
2545          ["Pop article off history" gnus-summary-pop-article t])
2546         ("Sort"
2547          ["Sort by number" gnus-summary-sort-by-number t]
2548          ["Sort by author" gnus-summary-sort-by-author t]
2549          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2550          ["Sort by subject" gnus-summary-sort-by-subject t]
2551          ["Sort by date" gnus-summary-sort-by-date t]
2552          ["Sort by score" gnus-summary-sort-by-score t]
2553          ["Sort by lines" gnus-summary-sort-by-lines t]
2554          ["Sort by characters" gnus-summary-sort-by-chars t]
2555          ["Randomize" gnus-summary-sort-by-random t]
2556          ["Original sort" gnus-summary-sort-by-original t])
2557         ("Help"
2558          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2559          ["Describe group" gnus-summary-describe-group t]
2560          ["Fetch charter" gnus-group-fetch-charter
2561           ,@(if (featurep 'xemacs) nil
2562               '(:help "Display the charter of the current group"))]
2563          ["Fetch control message" gnus-group-fetch-control
2564           ,@(if (featurep 'xemacs) nil
2565               '(:help "Display the archived control message for the current group"))]
2566          ["Read manual" gnus-info-find-node t])
2567         ("Modes"
2568          ["Pick and read" gnus-pick-mode t]
2569          ["Binary" gnus-binary-mode t])
2570         ("Regeneration"
2571          ["Regenerate" gnus-summary-prepare t]
2572          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2573          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2574          ["Toggle threading" gnus-summary-toggle-threads t])
2575         ["See old articles" gnus-summary-insert-old-articles t]
2576         ["See new articles" gnus-summary-insert-new-articles t]
2577         ["Filter articles..." gnus-summary-execute-command t]
2578         ["Run command on articles..." gnus-summary-universal-argument t]
2579         ["Search articles forward..." gnus-summary-search-article-forward t]
2580         ["Search articles backward..." gnus-summary-search-article-backward t]
2581         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2582         ["Expand window" gnus-summary-expand-window t]
2583         ["Expire expirable articles" gnus-summary-expire-articles
2584          (gnus-check-backend-function
2585           'request-expire-articles gnus-newsgroup-name)]
2586         ["Edit local kill file" gnus-summary-edit-local-kill t]
2587         ["Edit main kill file" gnus-summary-edit-global-kill t]
2588         ["Edit group parameters" gnus-summary-edit-parameters t]
2589         ["Customize group parameters" gnus-summary-customize-parameters t]
2590         ["Send a bug report" gnus-bug t]
2591         ("Exit"
2592          ["Catchup and exit" gnus-summary-catchup-and-exit
2593           ,@(if (featurep 'xemacs) '(t)
2594               '(:help "Mark unread articles in this group as read, then exit"))]
2595          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2596          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2597          ["Exit group" gnus-summary-exit
2598           ,@(if (featurep 'xemacs) '(t)
2599               '(:help "Exit current group, return to group selection mode"))]
2600          ["Exit group without updating" gnus-summary-exit-no-update t]
2601          ["Exit and goto next group" gnus-summary-next-group t]
2602          ["Exit and goto prev group" gnus-summary-prev-group t]
2603          ["Reselect group" gnus-summary-reselect-current-group t]
2604          ["Rescan group" gnus-summary-rescan-group t]
2605          ["Update dribble" gnus-summary-save-newsrc t])))
2606
2607     (gnus-run-hooks 'gnus-summary-menu-hook)))
2608
2609 (defvar gnus-summary-tool-bar-map nil)
2610
2611 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2612 (defun gnus-summary-make-tool-bar ()
2613   (if (and (fboundp 'tool-bar-add-item-from-menu)
2614            (default-value 'tool-bar-mode)
2615            (not gnus-summary-tool-bar-map))
2616       (setq gnus-summary-tool-bar-map
2617             (let ((tool-bar-map (make-sparse-keymap))
2618                   (load-path (mm-image-load-path)))
2619               (tool-bar-add-item-from-menu
2620                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2621               (tool-bar-add-item-from-menu
2622                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2623               (tool-bar-add-item-from-menu
2624                'gnus-summary-post-news "post" gnus-summary-mode-map)
2625               (tool-bar-add-item-from-menu
2626                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2627               (tool-bar-add-item-from-menu
2628                'gnus-summary-followup "followup" gnus-summary-mode-map)
2629               (tool-bar-add-item-from-menu
2630                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2631               (tool-bar-add-item-from-menu
2632                'gnus-summary-reply "reply" gnus-summary-mode-map)
2633               (tool-bar-add-item-from-menu
2634                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2635               (tool-bar-add-item-from-menu
2636                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2637               (tool-bar-add-item-from-menu
2638                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2639               (tool-bar-add-item-from-menu
2640                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2641               (tool-bar-add-item-from-menu
2642                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2643               (tool-bar-add-item-from-menu
2644                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2645               (tool-bar-add-item-from-menu
2646                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2647               (tool-bar-add-item-from-menu
2648                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2649               (tool-bar-add-item-from-menu
2650                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2651               tool-bar-map)))
2652   (if gnus-summary-tool-bar-map
2653       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2654
2655 (defun gnus-score-set-default (var value)
2656   "A version of set that updates the GNU Emacs menu-bar."
2657   (set var value)
2658   ;; It is the message that forces the active status to be updated.
2659   (message ""))
2660
2661 (defun gnus-make-score-map (type)
2662   "Make a summary score map of type TYPE."
2663   (if t
2664       nil
2665     (let ((headers '(("author" "from" string)
2666                      ("subject" "subject" string)
2667                      ("article body" "body" string)
2668                      ("article head" "head" string)
2669                      ("xref" "xref" string)
2670                      ("extra header" "extra" string)
2671                      ("lines" "lines" number)
2672                      ("followups to author" "followup" string)))
2673           (types '((number ("less than" <)
2674                            ("greater than" >)
2675                            ("equal" =))
2676                    (string ("substring" s)
2677                            ("exact string" e)
2678                            ("fuzzy string" f)
2679                            ("regexp" r))))
2680           (perms '(("temporary" (current-time-string))
2681                    ("permanent" nil)
2682                    ("immediate" now)))
2683           header)
2684       (list
2685        (apply
2686         'nconc
2687         (list
2688          (if (eq type 'lower)
2689              "Lower score"
2690            "Increase score"))
2691         (let (outh)
2692           (while headers
2693             (setq header (car headers))
2694             (setq outh
2695                   (cons
2696                    (apply
2697                     'nconc
2698                     (list (car header))
2699                     (let ((ts (cdr (assoc (nth 2 header) types)))
2700                           outt)
2701                       (while ts
2702                         (setq outt
2703                               (cons
2704                                (apply
2705                                 'nconc
2706                                 (list (caar ts))
2707                                 (let ((ps perms)
2708                                       outp)
2709                                   (while ps
2710                                     (setq outp
2711                                           (cons
2712                                            (vector
2713                                             (caar ps)
2714                                             (list
2715                                              'gnus-summary-score-entry
2716                                              (nth 1 header)
2717                                              (if (or (string= (nth 1 header)
2718                                                               "head")
2719                                                      (string= (nth 1 header)
2720                                                               "body"))
2721                                                  ""
2722                                                (list 'gnus-summary-header
2723                                                      (nth 1 header)))
2724                                              (list 'quote (nth 1 (car ts)))
2725                                              (list 'gnus-score-delta-default
2726                                                    nil)
2727                                              (nth 1 (car ps))
2728                                              t)
2729                                             t)
2730                                            outp))
2731                                     (setq ps (cdr ps)))
2732                                   (list (nreverse outp))))
2733                                outt))
2734                         (setq ts (cdr ts)))
2735                       (list (nreverse outt))))
2736                    outh))
2737             (setq headers (cdr headers)))
2738           (list (nreverse outh))))))))
2739
2740 \f
2741
2742 (defun gnus-summary-mode (&optional group)
2743   "Major mode for reading articles.
2744
2745 All normal editing commands are switched off.
2746 \\<gnus-summary-mode-map>
2747 Each line in this buffer represents one article.  To read an
2748 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2749 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2750 respectively.
2751
2752 You can also post articles and send mail from this buffer.  To
2753 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2754 of an article, type `\\[gnus-summary-reply]'.
2755
2756 There are approx. one gazillion commands you can execute in this
2757 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2758
2759 The following commands are available:
2760
2761 \\{gnus-summary-mode-map}"
2762   (interactive)
2763   (kill-all-local-variables)
2764   (when (gnus-visual-p 'summary-menu 'menu)
2765     (gnus-summary-make-menu-bar)
2766     (gnus-summary-make-tool-bar))
2767   (gnus-summary-make-local-variables)
2768   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2769     (gnus-summary-make-local-variables))
2770   (gnus-make-thread-indent-array)
2771   (gnus-simplify-mode-line)
2772   (setq major-mode 'gnus-summary-mode)
2773   (setq mode-name "Summary")
2774   (make-local-variable 'minor-mode-alist)
2775   (use-local-map gnus-summary-mode-map)
2776   (buffer-disable-undo)
2777   (setq buffer-read-only t              ;Disable modification
2778         show-trailing-whitespace nil)
2779   (setq truncate-lines t)
2780   (setq selective-display t)
2781   (setq selective-display-ellipses t)   ;Display `...'
2782   (gnus-summary-set-display-table)
2783   (gnus-set-default-directory)
2784   (setq gnus-newsgroup-name group)
2785   (unless (gnus-news-group-p group)
2786     (setq gnus-newsgroup-incorporated
2787           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2788   (make-local-variable 'gnus-summary-line-format)
2789   (make-local-variable 'gnus-summary-line-format-spec)
2790   (make-local-variable 'gnus-summary-dummy-line-format)
2791   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2792   (make-local-variable 'gnus-summary-mark-positions)
2793   (gnus-make-local-hook 'pre-command-hook)
2794   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2795   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2796   (turn-on-gnus-mailing-list-mode)
2797   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2798   (gnus-update-summary-mark-positions))
2799
2800 (defun gnus-summary-make-local-variables ()
2801   "Make all the local summary buffer variables."
2802   (let (global)
2803     (dolist (local gnus-summary-local-variables)
2804       (if (consp local)
2805           (progn
2806             (if (eq (cdr local) 'global)
2807                 ;; Copy the global value of the variable.
2808                 (setq global (symbol-value (car local)))
2809               ;; Use the value from the list.
2810               (setq global (eval (cdr local))))
2811             (set (make-local-variable (car local)) global))
2812         ;; Simple nil-valued local variable.
2813         (set (make-local-variable local) nil)))))
2814
2815 (defun gnus-summary-clear-local-variables ()
2816   (let ((locals gnus-summary-local-variables))
2817     (while locals
2818       (if (consp (car locals))
2819           (and (symbolp (caar locals))
2820                (set (caar locals) nil))
2821         (and (symbolp (car locals))
2822              (set (car locals) nil)))
2823       (setq locals (cdr locals)))))
2824
2825 ;; Summary data functions.
2826
2827 (defmacro gnus-data-number (data)
2828   `(car ,data))
2829
2830 (defmacro gnus-data-set-number (data number)
2831   `(setcar ,data ,number))
2832
2833 (defmacro gnus-data-mark (data)
2834   `(nth 1 ,data))
2835
2836 (defmacro gnus-data-set-mark (data mark)
2837   `(setcar (nthcdr 1 ,data) ,mark))
2838
2839 (defmacro gnus-data-pos (data)
2840   `(nth 2 ,data))
2841
2842 (defmacro gnus-data-set-pos (data pos)
2843   `(setcar (nthcdr 2 ,data) ,pos))
2844
2845 (defmacro gnus-data-header (data)
2846   `(nth 3 ,data))
2847
2848 (defmacro gnus-data-set-header (data header)
2849   `(setcar (nthcdr 3 ,data) ,header))
2850
2851 (defmacro gnus-data-level (data)
2852   `(nth 4 ,data))
2853
2854 (defmacro gnus-data-unread-p (data)
2855   `(= (nth 1 ,data) gnus-unread-mark))
2856
2857 (defmacro gnus-data-read-p (data)
2858   `(/= (nth 1 ,data) gnus-unread-mark))
2859
2860 (defmacro gnus-data-pseudo-p (data)
2861   `(consp (nth 3 ,data)))
2862
2863 (defmacro gnus-data-find (number)
2864   `(assq ,number gnus-newsgroup-data))
2865
2866 (defmacro gnus-data-find-list (number &optional data)
2867   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2868      (memq (assq ,number bdata)
2869            bdata)))
2870
2871 (defmacro gnus-data-make (number mark pos header level)
2872   `(list ,number ,mark ,pos ,header ,level))
2873
2874 (defun gnus-data-enter (after-article number mark pos header level offset)
2875   (let ((data (gnus-data-find-list after-article)))
2876     (unless data
2877       (error "No such article: %d" after-article))
2878     (setcdr data (cons (gnus-data-make number mark pos header level)
2879                        (cdr data)))
2880     (setq gnus-newsgroup-data-reverse nil)
2881     (gnus-data-update-list (cddr data) offset)))
2882
2883 (defun gnus-data-enter-list (after-article list &optional offset)
2884   (when list
2885     (let ((data (and after-article (gnus-data-find-list after-article)))
2886           (ilist list))
2887       (if (not (or data
2888                    after-article))
2889           (let ((odata gnus-newsgroup-data))
2890             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2891             (when offset
2892               (gnus-data-update-list odata offset)))
2893         ;; Find the last element in the list to be spliced into the main
2894         ;; list.
2895         (setq list (last list))
2896         (if (not data)
2897             (progn
2898               (setcdr list gnus-newsgroup-data)
2899               (setq gnus-newsgroup-data ilist)
2900               (when offset
2901                 (gnus-data-update-list (cdr list) offset)))
2902           (setcdr list (cdr data))
2903           (setcdr data ilist)
2904           (when offset
2905             (gnus-data-update-list (cdr list) offset))))
2906       (setq gnus-newsgroup-data-reverse nil))))
2907
2908 (defun gnus-data-remove (article &optional offset)
2909   (let ((data gnus-newsgroup-data))
2910     (if (= (gnus-data-number (car data)) article)
2911         (progn
2912           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2913                 gnus-newsgroup-data-reverse nil)
2914           (when offset
2915             (gnus-data-update-list gnus-newsgroup-data offset)))
2916       (while (cdr data)
2917         (when (= (gnus-data-number (cadr data)) article)
2918           (setcdr data (cddr data))
2919           (when offset
2920             (gnus-data-update-list (cdr data) offset))
2921           (setq data nil
2922                 gnus-newsgroup-data-reverse nil))
2923         (setq data (cdr data))))))
2924
2925 (defmacro gnus-data-list (backward)
2926   `(if ,backward
2927        (or gnus-newsgroup-data-reverse
2928            (setq gnus-newsgroup-data-reverse
2929                  (reverse gnus-newsgroup-data)))
2930      gnus-newsgroup-data))
2931
2932 (defun gnus-data-update-list (data offset)
2933   "Add OFFSET to the POS of all data entries in DATA."
2934   (setq gnus-newsgroup-data-reverse nil)
2935   (while data
2936     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2937     (setq data (cdr data))))
2938
2939 (defun gnus-summary-article-pseudo-p (article)
2940   "Say whether this article is a pseudo article or not."
2941   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2942
2943 (defmacro gnus-summary-article-sparse-p (article)
2944   "Say whether this article is a sparse article or not."
2945   `(memq ,article gnus-newsgroup-sparse))
2946
2947 (defmacro gnus-summary-article-ancient-p (article)
2948   "Say whether this article is a sparse article or not."
2949   `(memq ,article gnus-newsgroup-ancient))
2950
2951 (defun gnus-article-parent-p (number)
2952   "Say whether this article is a parent or not."
2953   (let ((data (gnus-data-find-list number)))
2954     (and (cdr data)                     ; There has to be an article after...
2955          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2956             (gnus-data-level (nth 1 data))))))
2957
2958 (defun gnus-article-children (number)
2959   "Return a list of all children to NUMBER."
2960   (let* ((data (gnus-data-find-list number))
2961          (level (gnus-data-level (car data)))
2962          children)
2963     (setq data (cdr data))
2964     (while (and data
2965                 (= (gnus-data-level (car data)) (1+ level)))
2966       (push (gnus-data-number (car data)) children)
2967       (setq data (cdr data)))
2968     children))
2969
2970 (defmacro gnus-summary-skip-intangible ()
2971   "If the current article is intangible, then jump to a different article."
2972   '(let ((to (get-text-property (point) 'gnus-intangible)))
2973      (and to (gnus-summary-goto-subject to))))
2974
2975 (defmacro gnus-summary-article-intangible-p ()
2976   "Say whether this article is intangible or not."
2977   '(get-text-property (point) 'gnus-intangible))
2978
2979 (defun gnus-article-read-p (article)
2980   "Say whether ARTICLE is read or not."
2981   (not (or (memq article gnus-newsgroup-marked)
2982            (memq article gnus-newsgroup-spam-marked)
2983            (memq article gnus-newsgroup-unreads)
2984            (memq article gnus-newsgroup-unselected)
2985            (memq article gnus-newsgroup-dormant))))
2986
2987 ;; Some summary mode macros.
2988
2989 (defmacro gnus-summary-article-number ()
2990   "The article number of the article on the current line.
2991 If there isn't an article number here, then we return the current
2992 article number."
2993   '(progn
2994      (gnus-summary-skip-intangible)
2995      (or (get-text-property (point) 'gnus-number)
2996          (gnus-summary-last-subject))))
2997
2998 (defmacro gnus-summary-article-header (&optional number)
2999   "Return the header of article NUMBER."
3000   `(gnus-data-header (gnus-data-find
3001                       ,(or number '(gnus-summary-article-number)))))
3002
3003 (defmacro gnus-summary-thread-level (&optional number)
3004   "Return the level of thread that starts with article NUMBER."
3005   `(if (and (eq gnus-summary-make-false-root 'dummy)
3006             (get-text-property (point) 'gnus-intangible))
3007        0
3008      (gnus-data-level (gnus-data-find
3009                        ,(or number '(gnus-summary-article-number))))))
3010
3011 (defmacro gnus-summary-article-mark (&optional number)
3012   "Return the mark of article NUMBER."
3013   `(gnus-data-mark (gnus-data-find
3014                     ,(or number '(gnus-summary-article-number)))))
3015
3016 (defmacro gnus-summary-article-pos (&optional number)
3017   "Return the position of the line of article NUMBER."
3018   `(gnus-data-pos (gnus-data-find
3019                    ,(or number '(gnus-summary-article-number)))))
3020
3021 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3022 (defmacro gnus-summary-article-subject (&optional number)
3023   "Return current subject string or nil if nothing."
3024   `(let ((headers
3025           ,(if number
3026                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3027              '(gnus-data-header (assq (gnus-summary-article-number)
3028                                       gnus-newsgroup-data)))))
3029      (and headers
3030           (vectorp headers)
3031           (mail-header-subject headers))))
3032
3033 (defmacro gnus-summary-article-score (&optional number)
3034   "Return current article score."
3035   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3036                   gnus-newsgroup-scored))
3037        gnus-summary-default-score 0))
3038
3039 (defun gnus-summary-article-children (&optional number)
3040   "Return a list of article numbers that are children of article NUMBER."
3041   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3042          (level (gnus-data-level (car data)))
3043          l children)
3044     (while (and (setq data (cdr data))
3045                 (> (setq l (gnus-data-level (car data))) level))
3046       (and (= (1+ level) l)
3047            (push (gnus-data-number (car data))
3048                  children)))
3049     (nreverse children)))
3050
3051 (defun gnus-summary-article-parent (&optional number)
3052   "Return the article number of the parent of article NUMBER."
3053   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3054                                     (gnus-data-list t)))
3055          (level (gnus-data-level (car data))))
3056     (if (zerop level)
3057         ()                              ; This is a root.
3058       ;; We search until we find an article with a level less than
3059       ;; this one.  That function has to be the parent.
3060       (while (and (setq data (cdr data))
3061                   (not (< (gnus-data-level (car data)) level))))
3062       (and data (gnus-data-number (car data))))))
3063
3064 (defun gnus-unread-mark-p (mark)
3065   "Say whether MARK is the unread mark."
3066   (= mark gnus-unread-mark))
3067
3068 (defun gnus-read-mark-p (mark)
3069   "Say whether MARK is one of the marks that mark as read.
3070 This is all marks except unread, ticked, dormant, and expirable."
3071   (not (or (= mark gnus-unread-mark)
3072            (= mark gnus-ticked-mark)
3073            (= mark gnus-spam-mark)
3074            (= mark gnus-dormant-mark)
3075            (= mark gnus-expirable-mark))))
3076
3077 (defmacro gnus-article-mark (number)
3078   "Return the MARK of article NUMBER.
3079 This macro should only be used when computing the mark the \"first\"
3080 time; i.e., when generating the summary lines.  After that,
3081 `gnus-summary-article-mark' should be used to examine the
3082 marks of articles."
3083   `(cond
3084     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3085     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3086     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3087     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3088     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3089     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3090     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3091     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3092            gnus-ancient-mark))))
3093
3094 ;; Saving hidden threads.
3095
3096 (defmacro gnus-save-hidden-threads (&rest forms)
3097   "Save hidden threads, eval FORMS, and restore the hidden threads."
3098   (let ((config (make-symbol "config")))
3099     `(let ((,config (gnus-hidden-threads-configuration)))
3100        (unwind-protect
3101            (save-excursion
3102              ,@forms)
3103          (gnus-restore-hidden-threads-configuration ,config)))))
3104 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3105 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3106
3107 (defun gnus-data-compute-positions ()
3108   "Compute the positions of all articles."
3109   (setq gnus-newsgroup-data-reverse nil)
3110   (let ((data gnus-newsgroup-data))
3111     (save-excursion
3112       (gnus-save-hidden-threads
3113         (gnus-summary-show-all-threads)
3114         (goto-char (point-min))
3115         (while data
3116           (while (get-text-property (point) 'gnus-intangible)
3117             (forward-line 1))
3118           (gnus-data-set-pos (car data) (+ (point) 3))
3119           (setq data (cdr data))
3120           (forward-line 1))))))
3121
3122 (defun gnus-hidden-threads-configuration ()
3123   "Return the current hidden threads configuration."
3124   (save-excursion
3125     (let (config)
3126       (goto-char (point-min))
3127       (while (search-forward "\r" nil t)
3128         (push (1- (point)) config))
3129       config)))
3130
3131 (defun gnus-restore-hidden-threads-configuration (config)
3132   "Restore hidden threads configuration from CONFIG."
3133   (save-excursion
3134     (let (point buffer-read-only)
3135       (while (setq point (pop config))
3136         (when (and (< point (point-max))
3137                    (goto-char point)
3138                    (eq (char-after) ?\n))
3139           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3140
3141 ;; Various summary mode internalish functions.
3142
3143 (defun gnus-mouse-pick-article (e)
3144   (interactive "e")
3145   (mouse-set-point e)
3146   (gnus-summary-next-page nil t))
3147
3148 (defun gnus-summary-set-display-table ()
3149   "Change the display table.
3150 Odd characters have a tendency to mess
3151 up nicely formatted displays - we make all possible glyphs
3152 display only a single character."
3153
3154   ;; We start from the standard display table, if any.
3155   (let ((table (or (copy-sequence standard-display-table)
3156                    (make-display-table)))
3157         (i 32))
3158     ;; Nix out all the control chars...
3159     (while (>= (setq i (1- i)) 0)
3160       (aset table i [??]))
3161     ;; ... but not newline and cr, of course.  (cr is necessary for the
3162     ;; selective display).
3163     (aset table ?\n nil)
3164     (aset table ?\r nil)
3165     ;; We keep TAB as well.
3166     (aset table ?\t nil)
3167     ;; We nix out any glyphs over 126 that are not set already.
3168     (let ((i 256))
3169       (while (>= (setq i (1- i)) 127)
3170         ;; Only modify if the entry is nil.
3171         (unless (aref table i)
3172           (aset table i [??]))))
3173     (setq buffer-display-table table)))
3174
3175 (defun gnus-summary-set-article-display-arrow (pos)
3176   "Update the overlay arrow to point to line at position POS."
3177   (when (and gnus-summary-display-arrow
3178              (boundp 'overlay-arrow-position)
3179              (boundp 'overlay-arrow-string))
3180     (save-excursion
3181       (goto-char pos)
3182       (beginning-of-line)
3183       (unless overlay-arrow-position
3184         (setq overlay-arrow-position (make-marker)))
3185       (setq overlay-arrow-string "=>"
3186             overlay-arrow-position (set-marker overlay-arrow-position
3187                                                (point)
3188                                                (current-buffer))))))
3189
3190 (defun gnus-summary-setup-buffer (group)
3191   "Initialize summary buffer."
3192   (let ((buffer (gnus-summary-buffer-name group))
3193         (dead-name (concat "*Dead Summary "
3194                            (gnus-group-decoded-name group) "*")))
3195     ;; If a dead summary buffer exists, we kill it.
3196     (when (gnus-buffer-live-p dead-name)
3197       (gnus-kill-buffer dead-name))
3198     (if (get-buffer buffer)
3199         (progn
3200           (set-buffer buffer)
3201           (setq gnus-summary-buffer (current-buffer))
3202           (not gnus-newsgroup-prepared))
3203       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3204       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3205       (gnus-summary-mode group)
3206       (when gnus-carpal
3207         (gnus-carpal-setup-buffer 'summary))
3208       (unless gnus-single-article-buffer
3209         (make-local-variable 'gnus-article-buffer)
3210         (make-local-variable 'gnus-article-current)
3211         (make-local-variable 'gnus-original-article-buffer))
3212       (setq gnus-newsgroup-name group)
3213       ;; Set any local variables in the group parameters.
3214       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3215       t)))
3216
3217 (defun gnus-set-global-variables ()
3218   "Set the global equivalents of the buffer-local variables.
3219 They are set to the latest values they had.  These reflect the summary
3220 buffer that was in action when the last article was fetched."
3221   (when (eq major-mode 'gnus-summary-mode)
3222     (setq gnus-summary-buffer (current-buffer))
3223     (let ((name gnus-newsgroup-name)
3224           (marked gnus-newsgroup-marked)
3225           (spam gnus-newsgroup-spam-marked)
3226           (unread gnus-newsgroup-unreads)
3227           (headers gnus-current-headers)
3228           (data gnus-newsgroup-data)
3229           (summary gnus-summary-buffer)
3230           (article-buffer gnus-article-buffer)
3231           (original gnus-original-article-buffer)
3232           (gac gnus-article-current)
3233           (reffed gnus-reffed-article-number)
3234           (score-file gnus-current-score-file)
3235           (default-charset gnus-newsgroup-charset)
3236           vlist)
3237       (let ((locals gnus-newsgroup-variables))
3238         (while locals
3239           (if (consp (car locals))
3240               (push (eval (caar locals)) vlist)
3241             (push (eval (car locals)) vlist))
3242           (setq locals (cdr locals)))
3243         (setq vlist (nreverse vlist)))
3244       (with-current-buffer gnus-group-buffer
3245         (setq gnus-newsgroup-name name
3246               gnus-newsgroup-marked marked
3247               gnus-newsgroup-spam-marked spam
3248               gnus-newsgroup-unreads unread
3249               gnus-current-headers headers
3250               gnus-newsgroup-data data
3251               gnus-article-current gac
3252               gnus-summary-buffer summary
3253               gnus-article-buffer article-buffer
3254               gnus-original-article-buffer original
3255               gnus-reffed-article-number reffed
3256               gnus-current-score-file score-file
3257               gnus-newsgroup-charset default-charset)
3258         (let ((locals gnus-newsgroup-variables))
3259           (while locals
3260             (if (consp (car locals))
3261                 (set (caar locals) (pop vlist))
3262               (set (car locals) (pop vlist)))
3263             (setq locals (cdr locals))))
3264         ;; The article buffer also has local variables.
3265         (when (gnus-buffer-live-p gnus-article-buffer)
3266           (set-buffer gnus-article-buffer)
3267           (setq gnus-summary-buffer summary))))))
3268
3269 (defun gnus-summary-article-unread-p (article)
3270   "Say whether ARTICLE is unread or not."
3271   (memq article gnus-newsgroup-unreads))
3272
3273 (defun gnus-summary-first-article-p (&optional article)
3274   "Return whether ARTICLE is the first article in the buffer."
3275   (if (not (setq article (or article (gnus-summary-article-number))))
3276       nil
3277     (eq article (caar gnus-newsgroup-data))))
3278
3279 (defun gnus-summary-last-article-p (&optional article)
3280   "Return whether ARTICLE is the last article in the buffer."
3281   (if (not (setq article (or article (gnus-summary-article-number))))
3282       ;; All non-existent numbers are the last article.  :-)
3283       t
3284     (not (cdr (gnus-data-find-list article)))))
3285
3286 (defun gnus-make-thread-indent-array ()
3287   (let ((n 200))
3288     (unless (and gnus-thread-indent-array
3289                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3290       (setq gnus-thread-indent-array (make-vector 201 "")
3291             gnus-thread-indent-array-level gnus-thread-indent-level)
3292       (while (>= n 0)
3293         (aset gnus-thread-indent-array n
3294               (make-string (* n gnus-thread-indent-level) ? ))
3295         (setq n (1- n))))))
3296
3297 (defun gnus-update-summary-mark-positions ()
3298   "Compute where the summary marks are to go."
3299   (save-excursion
3300     (when (gnus-buffer-exists-p gnus-summary-buffer)
3301       (set-buffer gnus-summary-buffer))
3302     (let ((spec gnus-summary-line-format-spec)
3303           pos)
3304       (save-excursion
3305         (gnus-set-work-buffer)
3306         (let ((gnus-tmp-unread ?Z)
3307               (gnus-replied-mark ?Z)
3308               (gnus-score-below-mark ?Z)
3309               (gnus-score-over-mark ?Z)
3310               (gnus-undownloaded-mark ?Z)
3311               (gnus-summary-line-format-spec spec)
3312               (gnus-newsgroup-downloadable '(0))
3313               (header
3314                (make-full-mail-header
3315                 0 "" "nobody" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil))
3316               case-fold-search ignores)
3317           ;; Here, all marks are bound to Z.
3318           (gnus-summary-insert-line header
3319                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3320           (goto-char (point-min))
3321           ;; Memorize the positions of the same characters as dummy marks.
3322           (while (re-search-forward "[A-D]" nil t)
3323             (push (point) ignores))
3324           (erase-buffer)
3325           ;; We use A-D as dummy marks in order to know column positions
3326           ;; where marks should be inserted.
3327           (setq gnus-tmp-unread ?A
3328                 gnus-replied-mark ?B
3329                 gnus-score-below-mark ?C
3330                 gnus-score-over-mark ?C
3331                 gnus-undownloaded-mark ?D)
3332           (gnus-summary-insert-line header
3333                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3334           ;; Ignore characters which aren't dummy marks.
3335           (dolist (p ignores)
3336             (delete-region (goto-char (1- p)) p)
3337             (insert ?Z))
3338           (goto-char (point-min))
3339           (setq pos (list (cons 'unread
3340                                 (and (search-forward "A" nil t)
3341                                      (- (point) (point-min) 1)))))
3342           (goto-char (point-min))
3343           (push (cons 'replied (and (search-forward "B" nil t)
3344                                     (- (point) (point-min) 1)))
3345                 pos)
3346           (goto-char (point-min))
3347           (push (cons 'score (and (search-forward "C" nil t)
3348                                   (- (point) (point-min) 1)))
3349                 pos)
3350           (goto-char (point-min))
3351           (push (cons 'download (and (search-forward "D" nil t)
3352                                      (- (point) (point-min) 1)))
3353                 pos)))
3354       (setq gnus-summary-mark-positions pos))))
3355
3356 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3357   "Insert a dummy root in the summary buffer."
3358   (beginning-of-line)
3359   (gnus-add-text-properties
3360    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3361    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3362
3363 (defun gnus-summary-extract-address-component (from)
3364   (or (car (funcall gnus-extract-address-components from))
3365       from))
3366
3367 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3368   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3369                                 default-mime-charset)))
3370     ;; Is it really necessary to do this next part for each summary line?
3371     ;; Luckily, doesn't seem to slow things down much.
3372     (or
3373      (and gnus-ignored-from-addresses
3374           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3375           (let ((extra-headers (mail-header-extra header))
3376                 to
3377                 newsgroups)
3378             (cond
3379              ((setq to (cdr (assq 'To extra-headers)))
3380               (concat gnus-summary-to-prefix
3381                       (inline
3382                         (gnus-summary-extract-address-component
3383                          (funcall gnus-decode-encoded-word-function to)))))
3384              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3385               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3386      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3387
3388 (defun gnus-summary-insert-line (gnus-tmp-header
3389                                  gnus-tmp-level gnus-tmp-current
3390                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3391                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3392                                  &optional gnus-tmp-dummy gnus-tmp-score
3393                                  gnus-tmp-process)
3394   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3395          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3396          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3397          (gnus-tmp-score-char
3398           (if (or (null gnus-summary-default-score)
3399                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3400                       gnus-summary-zcore-fuzz))
3401               ?\ ;;;Whitespace
3402             (if (< gnus-tmp-score gnus-summary-default-score)
3403                 gnus-score-below-mark gnus-score-over-mark)))
3404          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3405          (gnus-tmp-replied
3406           (cond (gnus-tmp-process gnus-process-mark)
3407                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3408                  gnus-cached-mark)
3409                 (gnus-tmp-replied gnus-replied-mark)
3410                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3411                  gnus-forwarded-mark)
3412                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3413                  gnus-saved-mark)
3414                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3415                  gnus-recent-mark)
3416                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3417                  gnus-unseen-mark)
3418                 (t gnus-no-mark)))
3419          (gnus-tmp-downloaded
3420           (cond (undownloaded
3421                  gnus-undownloaded-mark)
3422                 (gnus-newsgroup-agentized
3423                  gnus-downloaded-mark)
3424                 (t
3425                  gnus-no-mark)))
3426          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3427          (gnus-tmp-name
3428           (cond
3429            ((string-match "<[^>]+> *$" gnus-tmp-from)
3430             (let ((beg (match-beginning 0)))
3431               (or (and (string-match "^\".+\"" gnus-tmp-from)
3432                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3433                   (substring gnus-tmp-from 0 beg))))
3434            ((string-match "(.+)" gnus-tmp-from)
3435             (substring gnus-tmp-from
3436                        (1+ (match-beginning 0)) (1- (match-end 0))))
3437            (t gnus-tmp-from)))
3438          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3439          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3440          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3441          (buffer-read-only nil))
3442     (when (string= gnus-tmp-name "")
3443       (setq gnus-tmp-name gnus-tmp-from))
3444     (unless (numberp gnus-tmp-lines)
3445       (setq gnus-tmp-lines -1))
3446     (if (= gnus-tmp-lines -1)
3447         (setq gnus-tmp-lines "?")
3448       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3449     (gnus-put-text-property-excluding-characters-with-faces
3450      (point)
3451      (progn (eval gnus-summary-line-format-spec) (point))
3452      'gnus-number gnus-tmp-number)
3453     (when (gnus-visual-p 'summary-highlight 'highlight)
3454       (forward-line -1)
3455       (gnus-run-hooks 'gnus-summary-update-hook)
3456       (forward-line 1))))
3457
3458 (defun gnus-summary-update-line (&optional dont-update)
3459   "Update summary line after change."
3460   (when (and gnus-summary-default-score
3461              (not gnus-summary-inhibit-highlight))
3462     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3463            (article (gnus-summary-article-number))
3464            (score (gnus-summary-article-score article)))
3465       (unless dont-update
3466         (if (and gnus-summary-mark-below
3467                  (< (gnus-summary-article-score)
3468                     gnus-summary-mark-below))
3469             ;; This article has a low score, so we mark it as read.
3470             (when (memq article gnus-newsgroup-unreads)
3471               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3472           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3473             ;; This article was previously marked as read on account
3474             ;; of a low score, but now it has risen, so we mark it as
3475             ;; unread.
3476             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3477         (gnus-summary-update-mark
3478          (if (or (null gnus-summary-default-score)
3479                  (<= (abs (- score gnus-summary-default-score))
3480                      gnus-summary-zcore-fuzz))
3481              ?\ ;;;Whitespace
3482            (if (< score gnus-summary-default-score)
3483                gnus-score-below-mark gnus-score-over-mark))
3484          'score))
3485       ;; Do visual highlighting.
3486       (when (gnus-visual-p 'summary-highlight 'highlight)
3487         (gnus-run-hooks 'gnus-summary-update-hook)))))
3488
3489 (defvar gnus-tmp-new-adopts nil)
3490
3491 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3492   "Return the number of articles in THREAD.
3493 This may be 0 in some cases -- if none of the articles in
3494 the thread are to be displayed."
3495   (let* ((number
3496           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3497           (cond
3498            ((not (listp thread))
3499             1)
3500            ((and (consp thread) (cdr thread))
3501             (apply
3502              '+ 1 (mapcar
3503                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3504            ((null thread)
3505             1)
3506            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3507             1)
3508            (t 0))))
3509     (when (and level (zerop level) gnus-tmp-new-adopts)
3510       (incf number
3511             (apply '+ (mapcar
3512                        'gnus-summary-number-of-articles-in-thread
3513                        gnus-tmp-new-adopts))))
3514     (if char
3515         (if (> number 1) gnus-not-empty-thread-mark
3516           gnus-empty-thread-mark)
3517       number)))
3518
3519 (defsubst gnus-summary-line-message-size (head)
3520   "Return pretty-printed version of message size.
3521 This function is intended to be used in
3522 `gnus-summary-line-format-alist'."
3523   (let ((c (or (mail-header-chars head) -1)))
3524     (cond ((< c 0) "n/a")               ; chars not available
3525           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3526           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3527           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3528           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3529
3530
3531 (defun gnus-summary-set-local-parameters (group)
3532   "Go through the local params of GROUP and set all variable specs in that list."
3533   (let ((vars '(quit-config)))          ; Ignore quit-config.
3534     (dolist (elem (gnus-group-find-parameter group))
3535       (and (consp elem)                 ; Has to be a cons.
3536            (consp (cdr elem))           ; The cdr has to be a list.
3537            (symbolp (car elem))         ; Has to be a symbol in there.
3538            (not (memq (car elem) vars))
3539            (ignore-errors               ; So we set it.
3540              (push (car elem) vars)
3541              (make-local-variable (car elem))
3542              (set (car elem) (eval (nth 1 elem))))))))
3543
3544 (defun gnus-summary-read-group (group &optional show-all no-article
3545                                       kill-buffer no-display backward
3546                                       select-articles)
3547   "Start reading news in newsgroup GROUP.
3548 If SHOW-ALL is non-nil, already read articles are also listed.
3549 If NO-ARTICLE is non-nil, no article is selected initially.
3550 If NO-DISPLAY, don't generate a summary buffer."
3551   (let (result)
3552     (while (and group
3553                 (null (setq result
3554                             (let ((gnus-auto-select-next nil))
3555                               (or (gnus-summary-read-group-1
3556                                    group show-all no-article
3557                                    kill-buffer no-display
3558                                    select-articles)
3559                                   (setq show-all nil
3560                                         select-articles nil)))))
3561                 (eq gnus-auto-select-next 'quietly))
3562       (set-buffer gnus-group-buffer)
3563       ;; The entry function called above goes to the next
3564       ;; group automatically, so we go two groups back
3565       ;; if we are searching for the previous group.
3566       (when backward
3567         (gnus-group-prev-unread-group 2))
3568       (if (not (equal group (gnus-group-group-name)))
3569           (setq group (gnus-group-group-name))
3570         (setq group nil)))
3571     result))
3572
3573 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3574   "Directly jump to the other GROUP from summary buffer.
3575 If SHOW-ALL is non-nil, already read articles are also listed."
3576   (interactive
3577    (if (eq gnus-summary-buffer (current-buffer))
3578        (list (completing-read
3579               "Group: " gnus-active-hashtb nil t
3580               (when (and gnus-newsgroup-name
3581                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3582                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3583               'gnus-group-history)
3584              current-prefix-arg)
3585      (error "%s must be invoked from a gnus summary buffer." this-command)))
3586   (unless (or (zerop (length group))
3587               (and gnus-newsgroup-name
3588                    (string-equal gnus-newsgroup-name group)))
3589     (gnus-summary-exit)
3590     (gnus-summary-read-group group show-all
3591                              gnus-dont-select-after-jump-to-other-group)))
3592
3593 (defun gnus-summary-read-group-1 (group show-all no-article
3594                                         kill-buffer no-display
3595                                         &optional select-articles)
3596   ;; Killed foreign groups can't be entered.
3597   ;;  (when (and (not (gnus-group-native-p group))
3598   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3599   ;;    (error "Dead non-native groups can't be entered"))
3600   (gnus-message 5 "Retrieving newsgroup: %s..."
3601                 (gnus-group-decoded-name group))
3602   (let* ((new-group (gnus-summary-setup-buffer group))
3603          (quit-config (gnus-group-quit-config group))
3604          (did-select (and new-group (gnus-select-newsgroup
3605                                      group show-all select-articles))))
3606     (cond
3607      ;; This summary buffer exists already, so we just select it.
3608      ((not new-group)
3609       (gnus-set-global-variables)
3610       (when kill-buffer
3611         (gnus-kill-or-deaden-summary kill-buffer))
3612       (gnus-configure-windows 'summary 'force)
3613       (gnus-set-mode-line 'summary)
3614       (gnus-summary-position-point)
3615       (message "")
3616       t)
3617      ;; We couldn't select this group.
3618      ((null did-select)
3619       (when (and (eq major-mode 'gnus-summary-mode)
3620                  (not (equal (current-buffer) kill-buffer)))
3621         (kill-buffer (current-buffer))
3622         (if (not quit-config)
3623             (progn
3624               ;; Update the info -- marks might need to be removed,
3625               ;; for instance.
3626               (gnus-summary-update-info)
3627               (set-buffer gnus-group-buffer)
3628               (gnus-group-jump-to-group group)
3629               (gnus-group-next-unread-group 1))
3630           (gnus-handle-ephemeral-exit quit-config)))
3631       (let ((grpinfo (gnus-get-info group)))
3632         (if (null (gnus-info-read grpinfo))
3633             (gnus-message 3 "Group %s contains no messages"
3634                           (gnus-group-decoded-name group))
3635           (gnus-message 3 "Can't select group")))
3636       nil)
3637      ;; The user did a `C-g' while prompting for number of articles,
3638      ;; so we exit this group.
3639      ((eq did-select 'quit)
3640       (and (eq major-mode 'gnus-summary-mode)
3641            (not (equal (current-buffer) kill-buffer))
3642            (kill-buffer (current-buffer)))
3643       (when kill-buffer
3644         (gnus-kill-or-deaden-summary kill-buffer))
3645       (if (not quit-config)
3646           (progn
3647             (set-buffer gnus-group-buffer)
3648             (gnus-group-jump-to-group group)
3649             (gnus-group-next-unread-group 1)
3650             (gnus-configure-windows 'group 'force))
3651         (gnus-handle-ephemeral-exit quit-config))
3652       ;; Finally signal the quit.
3653       (signal 'quit nil))
3654      ;; The group was successfully selected.
3655      (t
3656       (gnus-set-global-variables)
3657       ;; Save the active value in effect when the group was entered.
3658       (setq gnus-newsgroup-active
3659             (gnus-copy-sequence
3660              (gnus-active gnus-newsgroup-name)))
3661       ;; You can change the summary buffer in some way with this hook.
3662       (gnus-run-hooks 'gnus-select-group-hook)
3663       (when (memq 'summary (gnus-update-format-specifications
3664                             nil 'summary 'summary-mode 'summary-dummy))
3665         ;; The format specification for the summary line was updated,
3666         ;; so we need to update the mark positions as well.
3667         (gnus-update-summary-mark-positions))
3668       ;; Do score processing.
3669       (when gnus-use-scoring
3670         (gnus-possibly-score-headers))
3671       ;; Check whether to fill in the gaps in the threads.
3672       (when gnus-build-sparse-threads
3673         (gnus-build-sparse-threads))
3674       ;; Find the initial limit.
3675       (if show-all
3676           (let ((gnus-newsgroup-dormant nil))
3677             (gnus-summary-initial-limit show-all))
3678         (gnus-summary-initial-limit show-all))
3679       ;; Generate the summary buffer.
3680       (unless no-display
3681         (gnus-summary-prepare))
3682       (when gnus-use-trees
3683         (gnus-tree-open group)
3684         (setq gnus-summary-highlight-line-function
3685               'gnus-tree-highlight-article))
3686       ;; If the summary buffer is empty, but there are some low-scored
3687       ;; articles or some excluded dormants, we include these in the
3688       ;; buffer.
3689       (when (and (zerop (buffer-size))
3690                  (not no-display))
3691         (cond (gnus-newsgroup-dormant
3692                (gnus-summary-limit-include-dormant))
3693               ((and gnus-newsgroup-scored show-all)
3694                (gnus-summary-limit-include-expunged t))))
3695       ;; Function `gnus-apply-kill-file' must be called in this hook.
3696       (gnus-run-hooks 'gnus-apply-kill-hook)
3697       (if (and (zerop (buffer-size))
3698                (not no-display))
3699           (progn
3700             ;; This newsgroup is empty.
3701             (gnus-summary-catchup-and-exit nil t)
3702             (gnus-message 6 "No unread news")
3703             (when kill-buffer
3704               (gnus-kill-or-deaden-summary kill-buffer))
3705             ;; Return nil from this function.
3706             nil)
3707         ;; Hide conversation thread subtrees.  We cannot do this in
3708         ;; gnus-summary-prepare-hook since kill processing may not
3709         ;; work with hidden articles.
3710         (gnus-summary-maybe-hide-threads)
3711         (when kill-buffer
3712           (gnus-kill-or-deaden-summary kill-buffer))
3713         (gnus-summary-auto-select-subject)
3714         ;; Show first unread article if requested.
3715         (if (and (not no-article)
3716                  (not no-display)
3717                  gnus-newsgroup-unreads
3718                  gnus-auto-select-first)
3719             (progn
3720               (gnus-configure-windows 'summary)
3721               (let ((art (gnus-summary-article-number)))
3722                 (unless (and (not gnus-plugged)
3723                              (or (memq art gnus-newsgroup-undownloaded)
3724                                  (memq art gnus-newsgroup-downloadable)))
3725                   (gnus-summary-goto-article art))))
3726           ;; Don't select any articles.
3727           (gnus-summary-position-point)
3728           (gnus-configure-windows 'summary 'force)
3729           (gnus-set-mode-line 'summary))
3730         (when (and gnus-auto-center-group
3731                    (get-buffer-window gnus-group-buffer t))
3732           ;; Gotta use windows, because recenter does weird stuff if
3733           ;; the current buffer ain't the displayed window.
3734           (let ((owin (selected-window)))
3735             (select-window (get-buffer-window gnus-group-buffer t))
3736             (when (gnus-group-goto-group group)
3737               (recenter))
3738             (select-window owin)))
3739         ;; Mark this buffer as "prepared".
3740         (setq gnus-newsgroup-prepared t)
3741         (gnus-run-hooks 'gnus-summary-prepared-hook)
3742         (unless (gnus-ephemeral-group-p group)
3743           (gnus-group-update-group group))
3744         t)))))
3745
3746 (defun gnus-summary-auto-select-subject ()
3747   "Select the subject line on initial group entry."
3748   (goto-char (point-min))
3749   (cond
3750    ((eq gnus-auto-select-subject 'best)
3751     (gnus-summary-best-unread-subject))
3752    ((eq gnus-auto-select-subject 'unread)
3753     (gnus-summary-first-unread-subject))
3754    ((eq gnus-auto-select-subject 'unseen)
3755     (gnus-summary-first-unseen-subject))
3756    ((eq gnus-auto-select-subject 'unseen-or-unread)
3757     (gnus-summary-first-unseen-or-unread-subject))
3758    ((eq gnus-auto-select-subject 'first)
3759     ;; Do nothing.
3760     )
3761    ((functionp gnus-auto-select-subject)
3762     (funcall gnus-auto-select-subject))))
3763
3764 (defun gnus-summary-prepare ()
3765   "Generate the summary buffer."
3766   (interactive)
3767   (let ((buffer-read-only nil))
3768     (erase-buffer)
3769     (setq gnus-newsgroup-data nil
3770           gnus-newsgroup-data-reverse nil)
3771     (gnus-run-hooks 'gnus-summary-generate-hook)
3772     ;; Generate the buffer, either with threads or without.
3773     (when gnus-newsgroup-headers
3774       (gnus-summary-prepare-threads
3775        (if gnus-show-threads
3776            (gnus-sort-gathered-threads
3777             (funcall gnus-summary-thread-gathering-function
3778                      (gnus-sort-threads
3779                       (gnus-cut-threads (gnus-make-threads)))))
3780          ;; Unthreaded display.
3781          (gnus-sort-articles gnus-newsgroup-headers))))
3782     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3783     ;; Call hooks for modifying summary buffer.
3784     (goto-char (point-min))
3785     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3786
3787 (defsubst gnus-general-simplify-subject (subject)
3788   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3789   (setq subject
3790         (cond
3791          ;; Truncate the subject.
3792          (gnus-simplify-subject-functions
3793           (gnus-map-function gnus-simplify-subject-functions subject))
3794          ((numberp gnus-summary-gather-subject-limit)
3795           (setq subject (gnus-simplify-subject-re subject))
3796           (if (> (length subject) gnus-summary-gather-subject-limit)
3797               (substring subject 0 gnus-summary-gather-subject-limit)
3798             subject))
3799          ;; Fuzzily simplify it.
3800          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3801           (gnus-simplify-subject-fuzzy subject))
3802          ;; Just remove the leading "Re:".
3803          (t
3804           (gnus-simplify-subject-re subject))))
3805
3806   (if (and gnus-summary-gather-exclude-subject
3807            (string-match gnus-summary-gather-exclude-subject subject))
3808       nil                               ; This article shouldn't be gathered
3809     subject))
3810
3811 (defun gnus-summary-simplify-subject-query ()
3812   "Query where the respool algorithm would put this article."
3813   (interactive)
3814   (gnus-summary-select-article)
3815   (message "%s"
3816            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3817
3818 (defun gnus-gather-threads-by-subject (threads)
3819   "Gather threads by looking at Subject headers."
3820   (if (not gnus-summary-make-false-root)
3821       threads
3822     (let ((hashtb (gnus-make-hashtable 1024))
3823           (prev threads)
3824           (result threads)
3825           subject hthread whole-subject)
3826       (while threads
3827         (setq subject (gnus-general-simplify-subject
3828                        (setq whole-subject (mail-header-subject
3829                                             (caar threads)))))
3830         (when subject
3831           (if (setq hthread (gnus-gethash subject hashtb))
3832               (progn
3833                 ;; We enter a dummy root into the thread, if we
3834                 ;; haven't done that already.
3835                 (unless (stringp (caar hthread))
3836                   (setcar hthread (list whole-subject (car hthread))))
3837                 ;; We add this new gathered thread to this gathered
3838                 ;; thread.
3839                 (setcdr (car hthread)
3840                         (nconc (cdar hthread) (list (car threads))))
3841                 ;; Remove it from the list of threads.
3842                 (setcdr prev (cdr threads))
3843                 (setq threads prev))
3844             ;; Enter this thread into the hash table.
3845             (gnus-sethash subject
3846                           (if gnus-summary-make-false-root-always
3847                               (progn
3848                                 ;; If you want a dummy root above all
3849                                 ;; threads...
3850                                 (setcar threads (list whole-subject
3851                                                       (car threads)))
3852                                 threads)
3853                             threads)
3854                           hashtb)))
3855         (setq prev threads)
3856         (setq threads (cdr threads)))
3857       result)))
3858
3859 (defun gnus-gather-threads-by-references (threads)
3860   "Gather threads by looking at References headers."
3861   (let ((idhashtb (gnus-make-hashtable 1024))
3862         (thhashtb (gnus-make-hashtable 1024))
3863         (prev threads)
3864         (result threads)
3865         ids references id gthread gid entered ref)
3866     (while threads
3867       (when (setq references (mail-header-references (caar threads)))
3868         (setq id (mail-header-id (caar threads))
3869               ids (inline (gnus-split-references references))
3870               entered nil)
3871         (while (setq ref (pop ids))
3872           (setq ids (delete ref ids))
3873           (if (not (setq gid (gnus-gethash ref idhashtb)))
3874               (progn
3875                 (gnus-sethash ref id idhashtb)
3876                 (gnus-sethash id threads thhashtb))
3877             (setq gthread (gnus-gethash gid thhashtb))
3878             (unless entered
3879               ;; We enter a dummy root into the thread, if we
3880               ;; haven't done that already.
3881               (unless (stringp (caar gthread))
3882                 (setcar gthread (list (mail-header-subject (caar gthread))
3883                                       (car gthread))))
3884               ;; We add this new gathered thread to this gathered
3885               ;; thread.
3886               (setcdr (car gthread)
3887                       (nconc (cdar gthread) (list (car threads)))))
3888             ;; Add it into the thread hash table.
3889             (gnus-sethash id gthread thhashtb)
3890             (setq entered t)
3891             ;; Remove it from the list of threads.
3892             (setcdr prev (cdr threads))
3893             (setq threads prev))))
3894       (setq prev threads)
3895       (setq threads (cdr threads)))
3896     result))
3897
3898 (defun gnus-sort-gathered-threads (threads)
3899   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3900   (let ((result threads))
3901     (while threads
3902       (when (stringp (caar threads))
3903         (setcdr (car threads)
3904                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3905       (setq threads (cdr threads)))
3906     result))
3907
3908 (defun gnus-thread-loop-p (root thread)
3909   "Say whether ROOT is in THREAD."
3910   (let ((stack (list thread))
3911         (infloop 0)
3912         th)
3913     (while (setq thread (pop stack))
3914       (setq th (cdr thread))
3915       (while (and th
3916                   (not (eq (caar th) root)))
3917         (pop th))
3918       (if th
3919           ;; We have found a loop.
3920           (let (ref-dep)
3921             (setcdr thread (delq (car th) (cdr thread)))
3922             (if (boundp (setq ref-dep (intern "none"
3923                                               gnus-newsgroup-dependencies)))
3924                 (setcdr (symbol-value ref-dep)
3925                         (nconc (cdr (symbol-value ref-dep))
3926                                (list (car th))))
3927               (set ref-dep (list nil (car th))))
3928             (setq infloop 1
3929                   stack nil))
3930         ;; Push all the subthreads onto the stack.
3931         (push (cdr thread) stack)))
3932     infloop))
3933
3934 (defun gnus-make-threads ()
3935   "Go through the dependency hashtb and find the roots.  Return all threads."
3936   (let (threads)
3937     (while (catch 'infloop
3938              (mapatoms
3939               (lambda (refs)
3940                 ;; Deal with self-referencing References loops.
3941                 (when (and (car (symbol-value refs))
3942                            (not (zerop
3943                                  (apply
3944                                   '+
3945                                   (mapcar
3946                                    (lambda (thread)
3947                                      (gnus-thread-loop-p
3948                                       (car (symbol-value refs)) thread))
3949                                    (cdr (symbol-value refs)))))))
3950                   (setq threads nil)
3951                   (throw 'infloop t))
3952                 (unless (car (symbol-value refs))
3953                   ;; These threads do not refer back to any other articles,
3954                   ;; so they're roots.
3955                   (setq threads (append (cdr (symbol-value refs)) threads))))
3956               gnus-newsgroup-dependencies)))
3957     threads))
3958
3959 ;; Build the thread tree.
3960 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3961   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3962
3963 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3964 if it was already present.
3965
3966 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3967 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3968 Message-IDs will be renamed to a unique Message-ID before being
3969 entered.
3970
3971 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3972   (let* ((id (mail-header-id header))
3973          (id-dep (and id (intern id dependencies)))
3974          parent-id ref ref-dep ref-header replaced)
3975     ;; Enter this `header' in the `dependencies' table.
3976     (cond
3977      ((not id-dep)
3978       (setq header nil))
3979      ;; The first two cases do the normal part: enter a new `header'
3980      ;; in the `dependencies' table.
3981      ((not (boundp id-dep))
3982       (set id-dep (list header)))
3983      ((null (car (symbol-value id-dep)))
3984       (setcar (symbol-value id-dep) header))
3985
3986      ;; From here the `header' was already present in the
3987      ;; `dependencies' table.
3988      (force-new
3989       ;; Overrides an existing entry;
3990       ;; just set the header part of the entry.
3991       (setcar (symbol-value id-dep) header)
3992       (setq replaced t))
3993
3994      ;; Renames the existing `header' to a unique Message-ID.
3995      ((not gnus-summary-ignore-duplicates)
3996       ;; An article with this Message-ID has already been seen.
3997       ;; We rename the Message-ID.
3998       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3999            (list header))
4000       (mail-header-set-id header id))
4001
4002      ;; The last case ignores an existing entry, except it adds any
4003      ;; additional Xrefs (in case the two articles came from different
4004      ;; servers.
4005      ;; Also sets `header' to `nil' meaning that the `dependencies'
4006      ;; table was *not* modified.
4007      (t
4008       (mail-header-set-xref
4009        (car (symbol-value id-dep))
4010        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4011                    "")
4012                (or (mail-header-xref header) "")))
4013       (setq header nil)))
4014
4015     (when (and header (not replaced))
4016       ;; First check that we are not creating a References loop.
4017       (setq parent-id (gnus-parent-id (mail-header-references header)))
4018       (setq ref parent-id)
4019       (while (and ref
4020                   (setq ref-dep (intern-soft ref dependencies))
4021                   (boundp ref-dep)
4022                   (setq ref-header (car (symbol-value ref-dep))))
4023         (if (string= id ref)
4024             ;; Yuk!  This is a reference loop.  Make the article be a
4025             ;; root article.
4026             (progn
4027               (mail-header-set-references (car (symbol-value id-dep)) "none")
4028               (setq ref nil)
4029               (setq parent-id nil))
4030           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4031       (setq ref-dep (intern (or parent-id "none") dependencies))
4032       (if (boundp ref-dep)
4033           (setcdr (symbol-value ref-dep)
4034                   (nconc (cdr (symbol-value ref-dep))
4035                          (list (symbol-value id-dep))))
4036         (set ref-dep (list nil (symbol-value id-dep)))))
4037     header))
4038
4039 (defun gnus-extract-message-id-from-in-reply-to (string)
4040   (if (string-match "<[^>]+>" string)
4041       (substring string (match-beginning 0) (match-end 0))
4042     nil))
4043
4044 (defun gnus-build-sparse-threads ()
4045   (let ((headers gnus-newsgroup-headers)
4046         (mail-parse-charset gnus-newsgroup-charset)
4047         (gnus-summary-ignore-duplicates t)
4048         header references generation relations
4049         subject child end new-child date)
4050     ;; First we create an alist of generations/relations, where
4051     ;; generations is how much we trust the relation, and the relation
4052     ;; is parent/child.
4053     (gnus-message 7 "Making sparse threads...")
4054     (save-excursion
4055       (nnheader-set-temp-buffer " *gnus sparse threads*")
4056       (while (setq header (pop headers))
4057         (when (and (setq references (mail-header-references header))
4058                    (not (string= references "")))
4059           (insert references)
4060           (setq child (mail-header-id header)
4061                 subject (mail-header-subject header)
4062                 date (mail-header-date header)
4063                 generation 0)
4064           (while (search-backward ">" nil t)
4065             (setq end (1+ (point)))
4066             (when (search-backward "<" nil t)
4067               (setq new-child (buffer-substring (point) end))
4068               (push (list (incf generation)
4069                           child (setq child new-child)
4070                           subject date)
4071                     relations)))
4072           (when child
4073             (push (list (1+ generation) child nil subject) relations))
4074           (erase-buffer)))
4075       (kill-buffer (current-buffer)))
4076     ;; Sort over trustworthiness.
4077     (mapcar
4078      (lambda (relation)
4079        (when (gnus-dependencies-add-header
4080               (make-full-mail-header-from-decoded-header
4081                gnus-reffed-article-number
4082                (nth 3 relation) "" (or (nth 4 relation) "")
4083                (nth 1 relation)
4084                (or (nth 2 relation) "") 0 0 "")
4085               gnus-newsgroup-dependencies nil)
4086          (push gnus-reffed-article-number gnus-newsgroup-limit)
4087          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4088          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4089                gnus-newsgroup-reads)
4090          (decf gnus-reffed-article-number)))
4091      (sort relations 'car-less-than-car))
4092     (gnus-message 7 "Making sparse threads...done")))
4093
4094 (defun gnus-build-old-threads ()
4095   ;; Look at all the articles that refer back to old articles, and
4096   ;; fetch the headers for the articles that aren't there.  This will
4097   ;; build complete threads - if the roots haven't been expired by the
4098   ;; server, that is.
4099   (let ((mail-parse-charset gnus-newsgroup-charset)
4100         id heads)
4101     (mapatoms
4102      (lambda (refs)
4103        (when (not (car (symbol-value refs)))
4104          (setq heads (cdr (symbol-value refs)))
4105          (while heads
4106            (if (memq (mail-header-number (caar heads))
4107                      gnus-newsgroup-dormant)
4108                (setq heads (cdr heads))
4109              (setq id (symbol-name refs))
4110              (while (and (setq id (gnus-build-get-header id))
4111                          (not (car (gnus-id-to-thread id)))))
4112              (setq heads nil)))))
4113      gnus-newsgroup-dependencies)))
4114
4115 (defsubst gnus-remove-odd-characters (string)
4116   "Translate STRING into something that doesn't contain weird characters."
4117   (mm-subst-char-in-string
4118    ?\r ?\-
4119    (mm-subst-char-in-string ?\n ?\- string t) t))
4120
4121 ;; This function has to be called with point after the article number
4122 ;; on the beginning of the line.
4123 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4124   (let ((eol (point-at-eol))
4125         (buffer (current-buffer))
4126         header references in-reply-to)
4127
4128     ;; overview: [num subject from date id refs chars lines misc]
4129     (unwind-protect
4130         (progn
4131           (narrow-to-region (point) eol)
4132           (unless (eobp)
4133             (forward-char))
4134
4135           (setq header
4136                 (make-full-mail-header
4137                  number                         ; number
4138                  (nnheader-nov-field)           ; subject
4139                  (nnheader-nov-field)           ; from
4140                  (nnheader-nov-field)           ; date
4141                  (nnheader-nov-read-message-id number)  ; id
4142                  (setq references (nnheader-nov-field)) ; refs
4143                  (nnheader-nov-read-integer)    ; chars
4144                  (nnheader-nov-read-integer)    ; lines
4145                  (unless (eobp)
4146                    (if (looking-at "Xref: ")
4147                        (goto-char (match-end 0)))
4148                    (nnheader-nov-field))        ; Xref
4149                  (nnheader-nov-parse-extra))))  ; extra
4150
4151       (widen))
4152
4153     (when (and (string= references "")
4154                (setq in-reply-to (mail-header-extra header))
4155                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4156       (mail-header-set-references
4157        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4158
4159     (when gnus-alter-header-function
4160       (funcall gnus-alter-header-function header))
4161     (gnus-dependencies-add-header header dependencies force-new)))
4162
4163 (defun gnus-build-get-header (id)
4164   "Look through the buffer of NOV lines and find the header to ID.
4165 Enter this line into the dependencies hash table, and return
4166 the id of the parent article (if any)."
4167   (let ((deps gnus-newsgroup-dependencies)
4168         found header)
4169     (prog1
4170         (save-excursion
4171           (set-buffer nntp-server-buffer)
4172           (let ((case-fold-search nil))
4173             (goto-char (point-min))
4174             (while (and (not found)
4175                         (search-forward id nil t))
4176               (beginning-of-line)
4177               (setq found (looking-at
4178                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4179                                    (regexp-quote id))))
4180               (or found (beginning-of-line 2)))
4181             (when found
4182               (beginning-of-line)
4183               (and
4184                (setq header (gnus-nov-parse-line
4185                              (read (current-buffer)) deps))
4186                (gnus-parent-id (mail-header-references header))))))
4187       (when header
4188         (let ((number (mail-header-number header)))
4189           (push number gnus-newsgroup-limit)
4190           (push header gnus-newsgroup-headers)
4191           (if (memq number gnus-newsgroup-unselected)
4192               (progn
4193                 (setq gnus-newsgroup-unreads
4194                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4195                                                number))
4196                 (setq gnus-newsgroup-unselected
4197                       (delq number gnus-newsgroup-unselected)))
4198             (push number gnus-newsgroup-ancient)))))))
4199
4200 (defun gnus-build-all-threads ()
4201   "Read all the headers."
4202   (let ((gnus-summary-ignore-duplicates t)
4203         (mail-parse-charset gnus-newsgroup-charset)
4204         (dependencies gnus-newsgroup-dependencies)
4205         header article)
4206     (save-excursion
4207       (set-buffer nntp-server-buffer)
4208       (let ((case-fold-search nil))
4209         (goto-char (point-min))
4210         (while (not (eobp))
4211           (ignore-errors
4212             (setq article (read (current-buffer))
4213                   header (gnus-nov-parse-line article dependencies)))
4214           (when header
4215             (with-current-buffer gnus-summary-buffer
4216               (push header gnus-newsgroup-headers)
4217               (if (memq (setq article (mail-header-number header))
4218                         gnus-newsgroup-unselected)
4219                   (progn
4220                     (setq gnus-newsgroup-unreads
4221                           (gnus-add-to-sorted-list
4222                            gnus-newsgroup-unreads article))
4223                     (setq gnus-newsgroup-unselected
4224                           (delq article gnus-newsgroup-unselected)))
4225                 (push article gnus-newsgroup-ancient)))
4226             (forward-line 1)))))))
4227
4228 (defun gnus-summary-update-article-line (article header)
4229   "Update the line for ARTICLE using HEADER."
4230   (let* ((id (mail-header-id header))
4231          (thread (gnus-id-to-thread id)))
4232     (unless thread
4233       (error "Article in no thread"))
4234     ;; Update the thread.
4235     (setcar thread header)
4236     (gnus-summary-goto-subject article)
4237     (let* ((datal (gnus-data-find-list article))
4238            (data (car datal))
4239            (buffer-read-only nil)
4240            (level (gnus-summary-thread-level)))
4241       (gnus-delete-line)
4242       (let ((inserted (- (point)
4243                          (progn
4244                            (gnus-summary-insert-line
4245                             header level nil
4246                             (memq article gnus-newsgroup-undownloaded)
4247                             (gnus-article-mark article)
4248                             (memq article gnus-newsgroup-replied)
4249                             (memq article gnus-newsgroup-expirable)
4250                             ;; Only insert the Subject string when it's different
4251                             ;; from the previous Subject string.
4252                             (if (and
4253                                  gnus-show-threads
4254                                  (gnus-subject-equal
4255                                   (condition-case ()
4256                                       (mail-header-subject
4257                                        (gnus-data-header
4258                                         (cadr
4259                                          (gnus-data-find-list
4260                                           article
4261                                           (gnus-data-list t)))))
4262                                     ;; Error on the side of excessive subjects.
4263                                     (error ""))
4264                                   (mail-header-subject header)))
4265                                 ""
4266                               (mail-header-subject header))
4267                             nil (cdr (assq article gnus-newsgroup-scored))
4268                             (memq article gnus-newsgroup-processable))
4269                            (point)))))
4270         (when (cdr datal)
4271           (gnus-data-update-list
4272            (cdr datal)
4273            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4274
4275 (defun gnus-summary-update-article (article &optional iheader)
4276   "Update ARTICLE in the summary buffer."
4277   (set-buffer gnus-summary-buffer)
4278   (let* ((header (gnus-summary-article-header article))
4279          (id (mail-header-id header))
4280          (data (gnus-data-find article))
4281          (thread (gnus-id-to-thread id))
4282          (references (mail-header-references header))
4283          (parent
4284           (gnus-id-to-thread
4285            (or (gnus-parent-id
4286                 (when (and references
4287                            (not (equal "" references)))
4288                   references))
4289                "none")))
4290          (buffer-read-only nil)
4291          (old (car thread)))
4292     (when thread
4293       (unless iheader
4294         (setcar thread nil)
4295         (when parent
4296           (delq thread parent)))
4297       (if (gnus-summary-insert-subject id header)
4298           ;; Set the (possibly) new article number in the data structure.
4299           (gnus-data-set-number data (gnus-id-to-article id))
4300         (setcar thread old)
4301         nil))))
4302
4303 (defun gnus-rebuild-thread (id &optional line)
4304   "Rebuild the thread containing ID.
4305 If LINE, insert the rebuilt thread starting on line LINE."
4306   (let ((buffer-read-only nil)
4307         old-pos current thread data)
4308     (if (not gnus-show-threads)
4309         (setq thread (list (car (gnus-id-to-thread id))))
4310       ;; Get the thread this article is part of.
4311       (setq thread (gnus-remove-thread id)))
4312     (setq old-pos (point-at-bol))
4313     (setq current (save-excursion
4314                     (and (re-search-backward "[\r\n]" nil t)
4315                          (gnus-summary-article-number))))
4316     ;; If this is a gathered thread, we have to go some re-gathering.
4317     (when (stringp (car thread))
4318       (let ((subject (car thread))
4319             roots thr)
4320         (setq thread (cdr thread))
4321         (while thread
4322           (unless (memq (setq thr (gnus-id-to-thread
4323                                    (gnus-root-id
4324                                     (mail-header-id (caar thread)))))
4325                         roots)
4326             (push thr roots))
4327           (setq thread (cdr thread)))
4328         ;; We now have all (unique) roots.
4329         (if (= (length roots) 1)
4330             ;; All the loose roots are now one solid root.
4331             (setq thread (car roots))
4332           (setq thread (cons subject (gnus-sort-threads roots))))))
4333     (let (threads)
4334       ;; We then insert this thread into the summary buffer.
4335       (when line
4336         (goto-char (point-min))
4337         (forward-line (1- line)))
4338       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4339         (if gnus-show-threads
4340             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4341           (gnus-summary-prepare-unthreaded thread))
4342         (setq data (nreverse gnus-newsgroup-data))
4343         (setq threads gnus-newsgroup-threads))
4344       ;; We splice the new data into the data structure.
4345       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4346       ;;!!! then we want to insert at the beginning of the buffer.
4347       ;;!!! That happens to be true with Gnus now, but that may
4348       ;;!!! change in the future.  Perhaps.
4349       (gnus-data-enter-list
4350        (if line nil current) data (- (point) old-pos))
4351       (setq gnus-newsgroup-threads
4352             (nconc threads gnus-newsgroup-threads))
4353       (gnus-data-compute-positions))))
4354
4355 (defun gnus-number-to-header (number)
4356   "Return the header for article NUMBER."
4357   (let ((headers gnus-newsgroup-headers))
4358     (while (and headers
4359                 (not (= number (mail-header-number (car headers)))))
4360       (pop headers))
4361     (when headers
4362       (car headers))))
4363
4364 (defun gnus-parent-headers (in-headers &optional generation)
4365   "Return the headers of the GENERATIONeth parent of HEADERS."
4366   (unless generation
4367     (setq generation 1))
4368   (let ((parent t)
4369         (headers in-headers)
4370         references)
4371     (while (and parent
4372                 (not (zerop generation))
4373                 (setq references (mail-header-references headers)))
4374       (setq headers (if (and references
4375                              (setq parent (gnus-parent-id references)))
4376                         (car (gnus-id-to-thread parent))
4377                       nil))
4378       (decf generation))
4379     (and (not (eq headers in-headers))
4380          headers)))
4381
4382 (defun gnus-id-to-thread (id)
4383   "Return the (sub-)thread where ID appears."
4384   (gnus-gethash id gnus-newsgroup-dependencies))
4385
4386 (defun gnus-id-to-article (id)
4387   "Return the article number of ID."
4388   (let ((thread (gnus-id-to-thread id)))
4389     (when (and thread
4390                (car thread))
4391       (mail-header-number (car thread)))))
4392
4393 (defun gnus-id-to-header (id)
4394   "Return the article headers of ID."
4395   (car (gnus-id-to-thread id)))
4396
4397 (defun gnus-article-displayed-root-p (article)
4398   "Say whether ARTICLE is a root(ish) article."
4399   (let ((level (gnus-summary-thread-level article))
4400         (refs (mail-header-references  (gnus-summary-article-header article)))
4401         particle)
4402     (cond
4403      ((null level) nil)
4404      ((zerop level) t)
4405      ((null refs) t)
4406      ((null (gnus-parent-id refs)) t)
4407      ((and (= 1 level)
4408            (null (setq particle (gnus-id-to-article
4409                                  (gnus-parent-id refs))))
4410            (null (gnus-summary-thread-level particle)))))))
4411
4412 (defun gnus-root-id (id)
4413   "Return the id of the root of the thread where ID appears."
4414   (let (last-id prev)
4415     (while (and id (setq prev (car (gnus-id-to-thread id))))
4416       (setq last-id id
4417             id (gnus-parent-id (mail-header-references prev))))
4418     last-id))
4419
4420 (defun gnus-articles-in-thread (thread)
4421   "Return the list of articles in THREAD."
4422   (cons (mail-header-number (car thread))
4423         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4424
4425 (defun gnus-remove-thread (id &optional dont-remove)
4426   "Remove the thread that has ID in it."
4427   (let (headers thread last-id)
4428     ;; First go up in this thread until we find the root.
4429     (setq last-id (gnus-root-id id)
4430           headers (message-flatten-list (gnus-id-to-thread last-id)))
4431     ;; We have now found the real root of this thread.  It might have
4432     ;; been gathered into some loose thread, so we have to search
4433     ;; through the threads to find the thread we wanted.
4434     (let ((threads gnus-newsgroup-threads)
4435           sub)
4436       (while threads
4437         (setq sub (car threads))
4438         (if (stringp (car sub))
4439             ;; This is a gathered thread, so we look at the roots
4440             ;; below it to find whether this article is in this
4441             ;; gathered root.
4442             (progn
4443               (setq sub (cdr sub))
4444               (while sub
4445                 (when (member (caar sub) headers)
4446                   (setq thread (car threads)
4447                         threads nil
4448                         sub nil))
4449                 (setq sub (cdr sub))))
4450           ;; It's an ordinary thread, so we check it.
4451           (when (eq (car sub) (car headers))
4452             (setq thread sub
4453                   threads nil)))
4454         (setq threads (cdr threads)))
4455       ;; If this article is in no thread, then it's a root.
4456       (if thread
4457           (unless dont-remove
4458             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4459         (setq thread (gnus-id-to-thread last-id)))
4460       (when thread
4461         (prog1
4462             thread                      ; We return this thread.
4463           (unless dont-remove
4464             (if (stringp (car thread))
4465                 (progn
4466                   ;; If we use dummy roots, then we have to remove the
4467                   ;; dummy root as well.
4468                   (when (eq gnus-summary-make-false-root 'dummy)
4469                     ;; We go to the dummy root by going to
4470                     ;; the first sub-"thread", and then one line up.
4471                     (gnus-summary-goto-article
4472                      (mail-header-number (caadr thread)))
4473                     (forward-line -1)
4474                     (gnus-delete-line)
4475                     (gnus-data-compute-positions))
4476                   (setq thread (cdr thread))
4477                   (while thread
4478                     (gnus-remove-thread-1 (car thread))
4479                     (setq thread (cdr thread))))
4480               (gnus-remove-thread-1 thread))))))))
4481
4482 (defun gnus-remove-thread-1 (thread)
4483   "Remove the thread THREAD recursively."
4484   (let ((number (mail-header-number (pop thread)))
4485         d)
4486     (setq thread (reverse thread))
4487     (while thread
4488       (gnus-remove-thread-1 (pop thread)))
4489     (when (setq d (gnus-data-find number))
4490       (goto-char (gnus-data-pos d))
4491       (gnus-summary-show-thread)
4492       (gnus-data-remove
4493        number
4494        (- (point-at-bol)
4495           (prog1
4496               (1+ (point-at-eol))
4497             (gnus-delete-line)))))))
4498
4499 (defun gnus-sort-threads-1 (threads func)
4500   (sort (mapcar (lambda (thread)
4501                   (cons (car thread)
4502                         (and (cdr thread)
4503                              (gnus-sort-threads-1 (cdr thread) func))))
4504                 threads) func))
4505
4506 (defun gnus-sort-threads (threads)
4507   "Sort THREADS."
4508   (if (not gnus-thread-sort-functions)
4509       threads
4510     (gnus-message 8 "Sorting threads...")
4511     (let ((max-lisp-eval-depth 5000))
4512       (prog1 (gnus-sort-threads-1
4513          threads
4514          (gnus-make-sort-function gnus-thread-sort-functions))
4515         (gnus-message 8 "Sorting threads...done")))))
4516
4517 (defun gnus-sort-articles (articles)
4518   "Sort ARTICLES."
4519   (when gnus-article-sort-functions
4520     (gnus-message 7 "Sorting articles...")
4521     (prog1
4522         (setq gnus-newsgroup-headers
4523               (sort articles (gnus-make-sort-function
4524                               gnus-article-sort-functions)))
4525       (gnus-message 7 "Sorting articles...done"))))
4526
4527 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4528 (defmacro gnus-thread-header (thread)
4529   "Return header of first article in THREAD.
4530 Note that THREAD must never, ever be anything else than a variable -
4531 using some other form will lead to serious barfage."
4532   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4533   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4534   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4535         (vector thread) 2))
4536
4537 (defsubst gnus-article-sort-by-number (h1 h2)
4538   "Sort articles by article number."
4539   (< (mail-header-number h1)
4540      (mail-header-number h2)))
4541
4542 (defun gnus-thread-sort-by-number (h1 h2)
4543   "Sort threads by root article number."
4544   (gnus-article-sort-by-number
4545    (gnus-thread-header h1) (gnus-thread-header h2)))
4546
4547 (defsubst gnus-article-sort-by-random (h1 h2)
4548   "Sort articles by article number."
4549   (zerop (random 2)))
4550
4551 (defun gnus-thread-sort-by-random (h1 h2)
4552   "Sort threads by root article number."
4553   (gnus-article-sort-by-random
4554    (gnus-thread-header h1) (gnus-thread-header h2)))
4555
4556 (defsubst gnus-article-sort-by-lines (h1 h2)
4557   "Sort articles by article Lines header."
4558   (< (mail-header-lines h1)
4559      (mail-header-lines h2)))
4560
4561 (defun gnus-thread-sort-by-lines (h1 h2)
4562   "Sort threads by root article Lines header."
4563   (gnus-article-sort-by-lines
4564    (gnus-thread-header h1) (gnus-thread-header h2)))
4565
4566 (defsubst gnus-article-sort-by-chars (h1 h2)
4567   "Sort articles by octet length."
4568   (< (mail-header-chars h1)
4569      (mail-header-chars h2)))
4570
4571 (defun gnus-thread-sort-by-chars (h1 h2)
4572   "Sort threads by root article octet length."
4573   (gnus-article-sort-by-chars
4574    (gnus-thread-header h1) (gnus-thread-header h2)))
4575
4576 (defsubst gnus-article-sort-by-author (h1 h2)
4577   "Sort articles by root author."
4578   (string-lessp
4579    (let ((addr (car (mime-entity-read-field h1 'From))))
4580      (or (std11-full-name-string addr)
4581          (std11-address-string addr)
4582          ""))
4583    (let ((addr (car (mime-entity-read-field h2 'From))))
4584      (or (std11-full-name-string addr)
4585          (std11-address-string addr)
4586          ""))
4587    ))
4588
4589 (defun gnus-thread-sort-by-author (h1 h2)
4590   "Sort threads by root author."
4591   (gnus-article-sort-by-author
4592    (gnus-thread-header h1)  (gnus-thread-header h2)))
4593
4594 (defsubst gnus-article-sort-by-recipient (h1 h2)
4595   "Sort articles by recipient."
4596   (string-lessp
4597    (let ((extract (funcall
4598                    gnus-extract-address-components
4599                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4600      (or (car extract) (cadr extract)))
4601    (let ((extract (funcall
4602                    gnus-extract-address-components
4603                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4604      (or (car extract) (cadr extract)))))
4605
4606 (defun gnus-thread-sort-by-recipient (h1 h2)
4607   "Sort threads by root recipient."
4608   (gnus-article-sort-by-recipient
4609    (gnus-thread-header h1) (gnus-thread-header h2)))
4610
4611 (defsubst gnus-article-sort-by-subject (h1 h2)
4612   "Sort articles by root subject."
4613   (string-lessp
4614    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4615    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4616
4617 (defun gnus-thread-sort-by-subject (h1 h2)
4618   "Sort threads by root subject."
4619   (gnus-article-sort-by-subject
4620    (gnus-thread-header h1) (gnus-thread-header h2)))
4621
4622 (defsubst gnus-article-sort-by-date (h1 h2)
4623   "Sort articles by root article date."
4624   (time-less-p
4625    (gnus-date-get-time (mail-header-date h1))
4626    (gnus-date-get-time (mail-header-date h2))))
4627
4628 (defun gnus-thread-sort-by-date (h1 h2)
4629   "Sort threads by root article date."
4630   (gnus-article-sort-by-date
4631    (gnus-thread-header h1) (gnus-thread-header h2)))
4632
4633 (defsubst gnus-article-sort-by-score (h1 h2)
4634   "Sort articles by root article score.
4635 Unscored articles will be counted as having a score of zero."
4636   (> (or (cdr (assq (mail-header-number h1)
4637                     gnus-newsgroup-scored))
4638          gnus-summary-default-score 0)
4639      (or (cdr (assq (mail-header-number h2)
4640                     gnus-newsgroup-scored))
4641          gnus-summary-default-score 0)))
4642
4643 (defun gnus-thread-sort-by-score (h1 h2)
4644   "Sort threads by root article score."
4645   (gnus-article-sort-by-score
4646    (gnus-thread-header h1) (gnus-thread-header h2)))
4647
4648 (defun gnus-thread-sort-by-total-score (h1 h2)
4649   "Sort threads by the sum of all scores in the thread.
4650 Unscored articles will be counted as having a score of zero."
4651   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4652
4653 (defun gnus-thread-total-score (thread)
4654   ;; This function find the total score of THREAD.
4655   (cond
4656    ((null thread)
4657     0)
4658    ((consp thread)
4659     (if (stringp (car thread))
4660         (apply gnus-thread-score-function 0
4661                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4662       (gnus-thread-total-score-1 thread)))
4663    (t
4664     (gnus-thread-total-score-1 (list thread)))))
4665
4666 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4667   "Sort threads such that the thread with the most recently arrived article comes first."
4668   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4669
4670 (defun gnus-thread-highest-number (thread)
4671   "Return the highest article number in THREAD."
4672   (apply 'max (mapcar (lambda (header)
4673                         (mail-header-number header))
4674                       (message-flatten-list thread))))
4675
4676 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4677   "Sort threads such that the thread with the most recently dated article comes first."
4678   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4679
4680 (defun gnus-thread-latest-date (thread)
4681   "Return the highest article date in THREAD."
4682   (let ((previous-time 0))
4683     (apply 'max
4684            (mapcar
4685             (lambda (header)
4686               (setq previous-time
4687                     (condition-case ()
4688                         (time-to-seconds (mail-header-parse-date
4689                                           (mail-header-date header)))
4690                       (error previous-time))))
4691             (sort
4692              (message-flatten-list thread)
4693              (lambda (h1 h2)
4694                (< (mail-header-number h1)
4695                   (mail-header-number h2))))))))
4696
4697 (defun gnus-thread-total-score-1 (root)
4698   ;; This function find the total score of the thread below ROOT.
4699   (setq root (car root))
4700   (apply gnus-thread-score-function
4701          (or (append
4702               (mapcar 'gnus-thread-total-score
4703                       (cdr (gnus-id-to-thread (mail-header-id root))))
4704               (when (> (mail-header-number root) 0)
4705                 (list (or (cdr (assq (mail-header-number root)
4706                                      gnus-newsgroup-scored))
4707                           gnus-summary-default-score 0))))
4708              (list gnus-summary-default-score)
4709              '(0))))
4710
4711 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4712 (defvar gnus-tmp-prev-subject nil)
4713 (defvar gnus-tmp-false-parent nil)
4714 (defvar gnus-tmp-root-expunged nil)
4715 (defvar gnus-tmp-dummy-line nil)
4716
4717 (eval-when-compile (defvar gnus-tmp-header))
4718 (defun gnus-extra-header (type &optional header)
4719   "Return the extra header of TYPE."
4720   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4721       ""))
4722
4723 (defvar gnus-tmp-thread-tree-header-string "")
4724
4725 (defcustom gnus-sum-thread-tree-root "> "
4726   "With %B spec, used for the root of a thread.
4727 If nil, use subject instead."
4728   :version "22.1"
4729   :type '(radio (const :format "%v  " nil) string)
4730   :group 'gnus-thread)
4731
4732 (defcustom gnus-sum-thread-tree-false-root "> "
4733   "With %B spec, used for a false root of a thread.
4734 If nil, use subject instead."
4735   :version "22.1"
4736   :type '(radio (const :format "%v  " nil) string)
4737   :group 'gnus-thread)
4738
4739 (defcustom gnus-sum-thread-tree-single-indent ""
4740   "With %B spec, used for a thread with just one message.
4741 If nil, use subject instead."
4742   :version "22.1"
4743   :type '(radio (const :format "%v  " nil) string)
4744   :group 'gnus-thread)
4745
4746 (defcustom gnus-sum-thread-tree-vertical "| "
4747   "With %B spec, used for drawing a vertical line."
4748   :version "22.1"
4749   :type 'string
4750   :group 'gnus-thread)
4751
4752 (defcustom gnus-sum-thread-tree-indent "  "
4753   "With %B spec, used for indenting."
4754   :version "22.1"
4755   :type 'string
4756   :group 'gnus-thread)
4757
4758 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4759   "With %B spec, used for a leaf with brothers."
4760   :version "22.1"
4761   :type 'string
4762   :group 'gnus-thread)
4763
4764 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4765   "With %B spec, used for a leaf without brothers."
4766   :version "22.1"
4767   :type 'string
4768   :group 'gnus-thread)
4769
4770 (defun gnus-summary-prepare-threads (threads)
4771   "Prepare summary buffer from THREADS and indentation LEVEL.
4772 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4773 or a straight list of headers."
4774   (gnus-message 7 "Generating summary...")
4775
4776   (setq gnus-newsgroup-threads threads)
4777   (beginning-of-line)
4778
4779   (let ((gnus-tmp-level 0)
4780         (default-score (or gnus-summary-default-score 0))
4781         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4782         (building-line-count gnus-summary-display-while-building)
4783         (building-count (integerp gnus-summary-display-while-building))
4784         thread number subject stack state gnus-tmp-gathered beg-match
4785         new-roots gnus-tmp-new-adopts thread-end simp-subject
4786         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4787         gnus-tmp-replied gnus-tmp-subject-or-nil
4788         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4789         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4790         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4791         tree-stack)
4792
4793     (setq gnus-tmp-prev-subject nil
4794           gnus-tmp-thread-tree-header-string "")
4795
4796     (if (vectorp (car threads))
4797         ;; If this is a straight (sic) list of headers, then a
4798         ;; threaded summary display isn't required, so we just create
4799         ;; an unthreaded one.
4800         (gnus-summary-prepare-unthreaded threads)
4801
4802       ;; Do the threaded display.
4803
4804       (if gnus-summary-display-while-building
4805           (switch-to-buffer (buffer-name)))
4806       (while (or threads stack gnus-tmp-new-adopts new-roots)
4807
4808         (if (and (= gnus-tmp-level 0)
4809                  (or (not stack)
4810                      (= (caar stack) 0))
4811                  (not gnus-tmp-false-parent)
4812                  (or gnus-tmp-new-adopts new-roots))
4813             (if gnus-tmp-new-adopts
4814                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4815                       thread (list (car gnus-tmp-new-adopts))
4816                       gnus-tmp-header (caar thread)
4817                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4818               (when new-roots
4819                 (setq thread (list (car new-roots))
4820                       gnus-tmp-header (caar thread)
4821                       new-roots (cdr new-roots))))
4822
4823           (if threads
4824               ;; If there are some threads, we do them before the
4825               ;; threads on the stack.
4826               (setq thread threads
4827                     gnus-tmp-header (caar thread))
4828             ;; There were no current threads, so we pop something off
4829             ;; the stack.
4830             (setq state (car stack)
4831                   gnus-tmp-level (car state)
4832                   tree-stack (cadr state)
4833                   thread (caddr state)
4834                   stack (cdr stack)
4835                   gnus-tmp-header (caar thread))))
4836
4837         (setq gnus-tmp-false-parent nil)
4838         (setq gnus-tmp-root-expunged nil)
4839         (setq thread-end nil)
4840
4841         (if (stringp gnus-tmp-header)
4842             ;; The header is a dummy root.
4843             (cond
4844              ((eq gnus-summary-make-false-root 'adopt)
4845               ;; We let the first article adopt the rest.
4846               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4847                                                (cddar thread)))
4848               (setq gnus-tmp-gathered
4849                     (nconc (mapcar
4850                             (lambda (h) (mail-header-number (car h)))
4851                             (cddar thread))
4852                            gnus-tmp-gathered))
4853               (setq thread (cons (list (caar thread)
4854                                        (cadar thread))
4855                                  (cdr thread)))
4856               (setq gnus-tmp-level -1
4857                     gnus-tmp-false-parent t))
4858              ((eq gnus-summary-make-false-root 'empty)
4859               ;; We print adopted articles with empty subject fields.
4860               (setq gnus-tmp-gathered
4861                     (nconc (mapcar
4862                             (lambda (h) (mail-header-number (car h)))
4863                             (cddar thread))
4864                            gnus-tmp-gathered))
4865               (setq gnus-tmp-level -1))
4866              ((eq gnus-summary-make-false-root 'dummy)
4867               ;; We remember that we probably want to output a dummy
4868               ;; root.
4869               (setq gnus-tmp-dummy-line gnus-tmp-header)
4870               (setq gnus-tmp-prev-subject gnus-tmp-header))
4871              (t
4872               ;; We do not make a root for the gathered
4873               ;; sub-threads at all.
4874               (setq gnus-tmp-level -1)))
4875
4876           (setq number (mail-header-number gnus-tmp-header)
4877                 subject (mail-header-subject gnus-tmp-header)
4878                 simp-subject (gnus-simplify-subject-fully subject))
4879
4880           (cond
4881            ;; If the thread has changed subject, we might want to make
4882            ;; this subthread into a root.
4883            ((and (null gnus-thread-ignore-subject)
4884                  (not (zerop gnus-tmp-level))
4885                  gnus-tmp-prev-subject
4886                  (not (string= gnus-tmp-prev-subject simp-subject)))
4887             (setq new-roots (nconc new-roots (list (car thread)))
4888                   thread-end t
4889                   gnus-tmp-header nil))
4890            ;; If the article lies outside the current limit,
4891            ;; then we do not display it.
4892            ((not (memq number gnus-newsgroup-limit))
4893             (setq gnus-tmp-gathered
4894                   (nconc (mapcar
4895                           (lambda (h) (mail-header-number (car h)))
4896                           (cdar thread))
4897                          gnus-tmp-gathered))
4898             (setq gnus-tmp-new-adopts (if (cdar thread)
4899                                           (append gnus-tmp-new-adopts
4900                                                   (cdar thread))
4901                                         gnus-tmp-new-adopts)
4902                   thread-end t
4903                   gnus-tmp-header nil)
4904             (when (zerop gnus-tmp-level)
4905               (setq gnus-tmp-root-expunged t)))
4906            ;; Perhaps this article is to be marked as read?
4907            ((and gnus-summary-mark-below
4908                  (< (or (cdr (assq number gnus-newsgroup-scored))
4909                         default-score)
4910                     gnus-summary-mark-below)
4911                  ;; Don't touch sparse articles.
4912                  (not (gnus-summary-article-sparse-p number))
4913                  (not (gnus-summary-article-ancient-p number)))
4914             (setq gnus-newsgroup-unreads
4915                   (delq number gnus-newsgroup-unreads))
4916             (if gnus-newsgroup-auto-expire
4917                 (setq gnus-newsgroup-expirable
4918                       (gnus-add-to-sorted-list
4919                        gnus-newsgroup-expirable number))
4920               (push (cons number gnus-low-score-mark)
4921                     gnus-newsgroup-reads))))
4922
4923           (when gnus-tmp-header
4924             ;; We may have an old dummy line to output before this
4925             ;; article.
4926             (when (and gnus-tmp-dummy-line
4927                        (gnus-subject-equal
4928                         gnus-tmp-dummy-line
4929                         (mail-header-subject gnus-tmp-header)))
4930               (gnus-summary-insert-dummy-line
4931                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4932               (setq gnus-tmp-dummy-line nil))
4933
4934             ;; Compute the mark.
4935             (setq gnus-tmp-unread (gnus-article-mark number))
4936
4937             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4938                                   gnus-tmp-header gnus-tmp-level)
4939                   gnus-newsgroup-data)
4940
4941             ;; Actually insert the line.
4942             (setq
4943              gnus-tmp-subject-or-nil
4944              (cond
4945               ((and gnus-thread-ignore-subject
4946                     gnus-tmp-prev-subject
4947                     (not (string= gnus-tmp-prev-subject simp-subject)))
4948                subject)
4949               ((zerop gnus-tmp-level)
4950                (if (and (eq gnus-summary-make-false-root 'empty)
4951                         (memq number gnus-tmp-gathered)
4952                         gnus-tmp-prev-subject
4953                         (string= gnus-tmp-prev-subject simp-subject))
4954                    gnus-summary-same-subject
4955                  subject))
4956               (t gnus-summary-same-subject)))
4957             (if (and (eq gnus-summary-make-false-root 'adopt)
4958                      (= gnus-tmp-level 1)
4959                      (memq number gnus-tmp-gathered))
4960                 (setq gnus-tmp-opening-bracket ?\<
4961                       gnus-tmp-closing-bracket ?\>)
4962               (setq gnus-tmp-opening-bracket ?\[
4963                     gnus-tmp-closing-bracket ?\]))
4964             (setq
4965              gnus-tmp-indentation
4966              (aref gnus-thread-indent-array gnus-tmp-level)
4967              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4968              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4969                                 gnus-summary-default-score 0)
4970              gnus-tmp-score-char
4971              (if (or (null gnus-summary-default-score)
4972                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4973                          gnus-summary-zcore-fuzz))
4974                  ?\ ;;;Whitespace
4975                (if (< gnus-tmp-score gnus-summary-default-score)
4976                    gnus-score-below-mark gnus-score-over-mark))
4977              gnus-tmp-replied
4978              (cond ((memq number gnus-newsgroup-processable)
4979                     gnus-process-mark)
4980                    ((memq number gnus-newsgroup-cached)
4981                     gnus-cached-mark)
4982                    ((memq number gnus-newsgroup-replied)
4983                     gnus-replied-mark)
4984                    ((memq number gnus-newsgroup-forwarded)
4985                     gnus-forwarded-mark)
4986                    ((memq number gnus-newsgroup-saved)
4987                     gnus-saved-mark)
4988                    ((memq number gnus-newsgroup-recent)
4989                     gnus-recent-mark)
4990                    ((memq number gnus-newsgroup-unseen)
4991                     gnus-unseen-mark)
4992                    (t gnus-no-mark))
4993              gnus-tmp-downloaded
4994              (cond ((memq number gnus-newsgroup-undownloaded)
4995                     gnus-undownloaded-mark)
4996                    (gnus-newsgroup-agentized
4997                     gnus-downloaded-mark)
4998                    (t
4999                     gnus-no-mark))
5000              gnus-tmp-from (mail-header-from gnus-tmp-header)
5001              gnus-tmp-name
5002              (cond
5003               ((string-match "<[^>]+> *$" gnus-tmp-from)
5004                (setq beg-match (match-beginning 0))
5005                (or (and (string-match "^\".+\"" gnus-tmp-from)
5006                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5007                    (substring gnus-tmp-from 0 beg-match)))
5008               ((string-match "(.+)" gnus-tmp-from)
5009                (substring gnus-tmp-from
5010                           (1+ (match-beginning 0)) (1- (match-end 0))))
5011               (t gnus-tmp-from))
5012
5013              ;; Do the %B string
5014              gnus-tmp-thread-tree-header-string
5015              (cond
5016               ((not gnus-show-threads) "")
5017               ((zerop gnus-tmp-level)
5018                (cond ((cdar thread)
5019                       (or gnus-sum-thread-tree-root subject))
5020                      (gnus-tmp-new-adopts
5021                       (or gnus-sum-thread-tree-false-root subject))
5022                      (t
5023                       (or gnus-sum-thread-tree-single-indent subject))))
5024               (t
5025                (concat (apply 'concat
5026                               (mapcar (lambda (item)
5027                                         (if (= item 1)
5028                                             gnus-sum-thread-tree-vertical
5029                                           gnus-sum-thread-tree-indent))
5030                                       (cdr (reverse tree-stack))))
5031                        (if (nth 1 thread)
5032                            gnus-sum-thread-tree-leaf-with-other
5033                          gnus-sum-thread-tree-single-leaf)))))
5034             (when (string= gnus-tmp-name "")
5035               (setq gnus-tmp-name gnus-tmp-from))
5036             (unless (numberp gnus-tmp-lines)
5037               (setq gnus-tmp-lines -1))
5038             (if (= gnus-tmp-lines -1)
5039                 (setq gnus-tmp-lines "?")
5040               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5041               (gnus-put-text-property
5042              (point)
5043              (progn (eval gnus-summary-line-format-spec) (point))
5044                'gnus-number number)
5045             (when gnus-visual-p
5046               (forward-line -1)
5047               (gnus-run-hooks 'gnus-summary-update-hook)
5048               (forward-line 1))
5049
5050             (setq gnus-tmp-prev-subject simp-subject)))
5051
5052         (when (nth 1 thread)
5053           (push (list (max 0 gnus-tmp-level)
5054                       (copy-sequence tree-stack)
5055                       (nthcdr 1 thread))
5056                 stack))
5057         (push (if (nth 1 thread) 1 0) tree-stack)
5058         (incf gnus-tmp-level)
5059         (setq threads (if thread-end nil (cdar thread)))
5060         (if gnus-summary-display-while-building
5061             (if building-count
5062                 (progn
5063                   ;; use a set frequency
5064                   (setq building-line-count (1- building-line-count))
5065                   (when (= building-line-count 0)
5066                     (sit-for 0)
5067                     (setq building-line-count
5068                           gnus-summary-display-while-building)))
5069               ;; always
5070               (sit-for 0)))
5071         (unless threads
5072           (setq gnus-tmp-level 0)))))
5073   (gnus-message 7 "Generating summary...done"))
5074
5075 (defun gnus-summary-prepare-unthreaded (headers)
5076   "Generate an unthreaded summary buffer based on HEADERS."
5077   (let (header number mark)
5078
5079     (beginning-of-line)
5080
5081     (while headers
5082       ;; We may have to root out some bad articles...
5083       (when (memq (setq number (mail-header-number
5084                                 (setq header (pop headers))))
5085                   gnus-newsgroup-limit)
5086         ;; Mark article as read when it has a low score.
5087         (when (and gnus-summary-mark-below
5088                    (< (or (cdr (assq number gnus-newsgroup-scored))
5089                           gnus-summary-default-score 0)
5090                       gnus-summary-mark-below)
5091                    (not (gnus-summary-article-ancient-p number)))
5092           (setq gnus-newsgroup-unreads
5093                 (delq number gnus-newsgroup-unreads))
5094           (if gnus-newsgroup-auto-expire
5095               (push number gnus-newsgroup-expirable)
5096             (push (cons number gnus-low-score-mark)
5097                   gnus-newsgroup-reads)))
5098
5099         (setq mark (gnus-article-mark number))
5100         (push (gnus-data-make number mark (1+ (point)) header 0)
5101               gnus-newsgroup-data)
5102         (gnus-summary-insert-line
5103          header 0 number
5104          (memq number gnus-newsgroup-undownloaded)
5105          mark (memq number gnus-newsgroup-replied)
5106          (memq number gnus-newsgroup-expirable)
5107          (mail-header-subject header) nil
5108          (cdr (assq number gnus-newsgroup-scored))
5109          (memq number gnus-newsgroup-processable))))))
5110
5111 (defun gnus-summary-remove-list-identifiers ()
5112   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5113   (let ((regexp (if (consp gnus-list-identifiers)
5114                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5115                   gnus-list-identifiers))
5116         changed subject)
5117     (when regexp
5118       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5119       (dolist (header gnus-newsgroup-headers)
5120         (setq subject (mail-header-subject header)
5121               changed nil)
5122         (while (string-match regexp subject)
5123           (setq subject
5124                 (concat (substring subject 0 (match-beginning 1))
5125                         (substring subject (match-end 0)))
5126                 changed t))
5127         (when changed
5128           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5129             (setq subject
5130                   (concat (substring subject 0 (match-beginning 1))
5131                           (substring subject (match-end 1)))))
5132           (mail-header-set-subject header subject))))))
5133
5134 (defun gnus-fetch-headers (articles)
5135   "Fetch headers of ARTICLES."
5136   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5137     (gnus-message 5 "Fetching headers for %s..." name)
5138     (prog1
5139         (if (eq 'nov
5140                 (setq gnus-headers-retrieved-by
5141                       (gnus-retrieve-headers
5142                        articles gnus-newsgroup-name
5143                        ;; We might want to fetch old headers, but
5144                        ;; not if there is only 1 article.
5145                        (and (or (and
5146                                  (not (eq gnus-fetch-old-headers 'some))
5147                                  (not (numberp gnus-fetch-old-headers)))
5148                                 (> (length articles) 1))
5149                             gnus-fetch-old-headers))))
5150             (gnus-get-newsgroup-headers-xover
5151              articles nil nil gnus-newsgroup-name t)
5152           (gnus-get-newsgroup-headers))
5153       (gnus-message 5 "Fetching headers for %s...done" name))))
5154
5155 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5156   "Select newsgroup GROUP.
5157 If READ-ALL is non-nil, all articles in the group are selected.
5158 If SELECT-ARTICLES, only select those articles from GROUP."
5159   (let* ((entry (gnus-group-entry group))
5160          ;;!!! Dirty hack; should be removed.
5161          (gnus-summary-ignore-duplicates
5162           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5163               t
5164             gnus-summary-ignore-duplicates))
5165          (info (nth 2 entry))
5166          articles fetched-articles cached)
5167
5168     (unless (gnus-check-server
5169              (set (make-local-variable 'gnus-current-select-method)
5170                   (gnus-find-method-for-group group)))
5171       (error "Couldn't open server"))
5172
5173     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5174         (gnus-activate-group group)     ; Or we can activate it...
5175         (progn                          ; Or we bug out.
5176           (when (equal major-mode 'gnus-summary-mode)
5177             (gnus-kill-buffer (current-buffer)))
5178           (error "Couldn't activate group %s: %s"
5179                  group (gnus-status-message group))))
5180
5181     (unless (gnus-request-group group t)
5182       (when (equal major-mode 'gnus-summary-mode)
5183         (gnus-kill-buffer (current-buffer)))
5184       (error "Couldn't request group %s: %s"
5185              group (gnus-status-message group)))
5186
5187     (when gnus-agent
5188       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5189
5190       (setq gnus-summary-use-undownloaded-faces
5191             (gnus-agent-find-parameter
5192              group
5193              'agent-enable-undownloaded-faces)))
5194
5195     (setq gnus-newsgroup-name group
5196           gnus-newsgroup-unselected nil
5197           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5198
5199     (let ((display (gnus-group-find-parameter group 'display)))
5200       (setq gnus-newsgroup-display
5201             (cond
5202              ((not (zerop (or (car-safe read-all) 0)))
5203               ;; The user entered the group with C-u SPC/RET, let's show
5204               ;; all articles.
5205               'gnus-not-ignore)
5206              ((eq display 'all)
5207               'gnus-not-ignore)
5208              ((arrayp display)
5209               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5210              ((numberp display)
5211               ;; The following is probably the "correct" solution, but
5212               ;; it makes Gnus fetch all headers and then limit the
5213               ;; articles (which is slow), so instead we hack the
5214               ;; select-articles parameter instead. -- Simon Josefsson
5215               ;; <jas@kth.se>
5216               ;;
5217               ;; (gnus-byte-compile
5218               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5219               ;;                         display)))))
5220               (setq select-articles
5221                     (gnus-uncompress-range
5222                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5223                              (if (> tmp 0)
5224                                  tmp
5225                                1))
5226                            (cdr (gnus-active group)))))
5227               nil)
5228              (t
5229               nil))))
5230
5231     (gnus-summary-setup-default-charset)
5232
5233     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5234     (when (gnus-virtual-group-p group)
5235       (setq cached gnus-newsgroup-cached))
5236
5237     (setq gnus-newsgroup-unreads
5238           (gnus-sorted-ndifference
5239            (gnus-sorted-ndifference gnus-newsgroup-unreads
5240                                     gnus-newsgroup-marked)
5241            gnus-newsgroup-dormant))
5242
5243     (setq gnus-newsgroup-processable nil)
5244
5245     (gnus-update-read-articles group gnus-newsgroup-unreads)
5246
5247     ;; Adjust and set lists of article marks.
5248     (when info
5249       (gnus-adjust-marked-articles info))
5250     (if (setq articles select-articles)
5251         (setq gnus-newsgroup-unselected
5252               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5253       (setq articles (gnus-articles-to-read group read-all)))
5254
5255     (cond
5256      ((null articles)
5257       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5258       'quit)
5259      ((eq articles 0) nil)
5260      (t
5261       ;; Init the dependencies hash table.
5262       (setq gnus-newsgroup-dependencies
5263             (gnus-make-hashtable (length articles)))
5264       (gnus-set-global-variables)
5265       ;; Retrieve the headers and read them in.
5266
5267       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5268
5269       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5270       (when cached
5271         (setq gnus-newsgroup-cached cached))
5272
5273       ;; Suppress duplicates?
5274       (when gnus-suppress-duplicates
5275         (gnus-dup-suppress-articles))
5276
5277       ;; Set the initial limit.
5278       (setq gnus-newsgroup-limit (copy-sequence articles))
5279       ;; Remove canceled articles from the list of unread articles.
5280       (setq fetched-articles
5281             (mapcar (lambda (headers) (mail-header-number headers))
5282                     gnus-newsgroup-headers))
5283       (setq gnus-newsgroup-articles fetched-articles)
5284       (setq gnus-newsgroup-unreads
5285             (gnus-sorted-nintersection
5286              gnus-newsgroup-unreads fetched-articles))
5287       (gnus-compute-unseen-list)
5288
5289       ;; Removed marked articles that do not exist.
5290       (gnus-update-missing-marks
5291        (gnus-sorted-difference articles fetched-articles))
5292       ;; We might want to build some more threads first.
5293       (when (and gnus-fetch-old-headers
5294                  (eq gnus-headers-retrieved-by 'nov))
5295         (if (eq gnus-fetch-old-headers 'invisible)
5296             (gnus-build-all-threads)
5297           (gnus-build-old-threads)))
5298       ;; Let the Gnus agent mark articles as read.
5299       (when gnus-agent
5300         (gnus-agent-get-undownloaded-list))
5301       ;; Remove list identifiers from subject
5302       (when gnus-list-identifiers
5303         (gnus-summary-remove-list-identifiers))
5304       ;; Check whether auto-expire is to be done in this group.
5305       (setq gnus-newsgroup-auto-expire
5306             (gnus-group-auto-expirable-p group))
5307       ;; Set up the article buffer now, if necessary.
5308       (unless gnus-single-article-buffer
5309         (gnus-article-setup-buffer))
5310       ;; First and last article in this newsgroup.
5311       (when gnus-newsgroup-headers
5312         (setq gnus-newsgroup-begin
5313               (mail-header-number (car gnus-newsgroup-headers))
5314               gnus-newsgroup-end
5315               (mail-header-number
5316                (gnus-last-element gnus-newsgroup-headers))))
5317       ;; GROUP is successfully selected.
5318       (or gnus-newsgroup-headers t)))))
5319
5320 (defun gnus-compute-unseen-list ()
5321   ;; The `seen' marks are treated specially.
5322   (if (not gnus-newsgroup-seen)
5323       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5324     (setq gnus-newsgroup-unseen
5325           (gnus-inverse-list-range-intersection
5326            gnus-newsgroup-articles gnus-newsgroup-seen))))
5327
5328 (defun gnus-summary-display-make-predicate (display)
5329   (require 'gnus-agent)
5330   (when (= (length display) 1)
5331     (setq display (car display)))
5332   (unless gnus-summary-display-cache
5333     (dolist (elem (append '((unread . unread)
5334                             (read . read)
5335                             (unseen . unseen))
5336                           gnus-article-mark-lists))
5337       (push (cons (cdr elem)
5338                   (gnus-byte-compile
5339                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5340             gnus-summary-display-cache)))
5341   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5342         (gnus-category-predicate-cache gnus-summary-display-cache))
5343     (gnus-get-predicate display)))
5344
5345 ;; Uses the dynamically bound `number' variable.
5346 (eval-when-compile
5347   (defvar number))
5348 (defun gnus-article-marked-p (type &optional article)
5349   (let ((article (or article number)))
5350     (cond
5351      ((eq type 'tick)
5352       (memq article gnus-newsgroup-marked))
5353      ((eq type 'spam)
5354       (memq article gnus-newsgroup-spam-marked))
5355      ((eq type 'unsend)
5356       (memq article gnus-newsgroup-unsendable))
5357      ((eq type 'undownload)
5358       (memq article gnus-newsgroup-undownloaded))
5359      ((eq type 'download)
5360       (memq article gnus-newsgroup-downloadable))
5361      ((eq type 'unread)
5362       (memq article gnus-newsgroup-unreads))
5363      ((eq type 'read)
5364       (memq article gnus-newsgroup-reads))
5365      ((eq type 'dormant)
5366       (memq article gnus-newsgroup-dormant) )
5367      ((eq type 'expire)
5368       (memq article gnus-newsgroup-expirable))
5369      ((eq type 'reply)
5370       (memq article gnus-newsgroup-replied))
5371      ((eq type 'killed)
5372       (memq article gnus-newsgroup-killed))
5373      ((eq type 'bookmark)
5374       (assq article gnus-newsgroup-bookmarks))
5375      ((eq type 'score)
5376       (assq article gnus-newsgroup-scored))
5377      ((eq type 'save)
5378       (memq article gnus-newsgroup-saved))
5379      ((eq type 'cache)
5380       (memq article gnus-newsgroup-cached))
5381      ((eq type 'forward)
5382       (memq article gnus-newsgroup-forwarded))
5383      ((eq type 'seen)
5384       (not (memq article gnus-newsgroup-unseen)))
5385      ((eq type 'recent)
5386       (memq article gnus-newsgroup-recent))
5387      (t t))))
5388
5389 (defun gnus-articles-to-read (group &optional read-all)
5390   "Find out what articles the user wants to read."
5391   (let* ((articles
5392           ;; Select all articles if `read-all' is non-nil, or if there
5393           ;; are no unread articles.
5394           (if (or read-all
5395                   (and (zerop (length gnus-newsgroup-marked))
5396                        (zerop (length gnus-newsgroup-unreads)))
5397                   ;; Fetch all if the predicate is non-nil.
5398                   gnus-newsgroup-display)
5399               ;; We want to select the headers for all the articles in
5400               ;; the group, so we select either all the active
5401               ;; articles in the group, or (if that's nil), the
5402               ;; articles in the cache.
5403               (or
5404                (gnus-uncompress-range (gnus-active group))
5405                (gnus-cache-articles-in-group group))
5406             ;; Select only the "normal" subset of articles.
5407             (gnus-sorted-nunion
5408              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5409              gnus-newsgroup-unreads)))
5410          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5411          (scored (length scored-list))
5412          (number (length articles))
5413          (marked (+ (length gnus-newsgroup-marked)
5414                     (length gnus-newsgroup-dormant)))
5415          (select
5416           (cond
5417            ((numberp read-all)
5418             read-all)
5419            ((numberp gnus-newsgroup-display)
5420             gnus-newsgroup-display)
5421            (t
5422             (condition-case ()
5423                 (cond
5424                  ((and (or (<= scored marked) (= scored number))
5425                        (numberp gnus-large-newsgroup)
5426                        (> number gnus-large-newsgroup))
5427                   (let* ((cursor-in-echo-area nil)
5428                          (initial (gnus-parameter-large-newsgroup-initial
5429                                    gnus-newsgroup-name))
5430                          (input
5431                           (read-string
5432                            (format
5433                             "How many articles from %s (%s %d): "
5434                             (gnus-limit-string
5435                              (gnus-group-decoded-name gnus-newsgroup-name)
5436                              35)
5437                             (if initial "max" "default")
5438                             number)
5439                            (if initial
5440                                (cons (number-to-string initial)
5441                                      0)))))
5442                     (if (string-match "^[ \t]*$" input) number input)))
5443                  ((and (> scored marked) (< scored number)
5444                        (> (- scored number) 20))
5445                   (let ((input
5446                          (read-string
5447                           (format "%s %s (%d scored, %d total): "
5448                                   "How many articles from"
5449                                   (gnus-group-decoded-name group)
5450                                   scored number))))
5451                     (if (string-match "^[ \t]*$" input)
5452                         number input)))
5453                  (t number))
5454               (quit
5455                (message "Quit getting the articles to read")
5456                nil))))))
5457     (setq select (if (stringp select) (string-to-number select) select))
5458     (if (or (null select) (zerop select))
5459         select
5460       (if (and (not (zerop scored)) (<= (abs select) scored))
5461           (progn
5462             (setq articles (sort scored-list '<))
5463             (setq number (length articles)))
5464         (setq articles (copy-sequence articles)))
5465
5466       (when (< (abs select) number)
5467         (if (< select 0)
5468             ;; Select the N oldest articles.
5469             (setcdr (nthcdr (1- (abs select)) articles) nil)
5470           ;; Select the N most recent articles.
5471           (setq articles (nthcdr (- number select) articles))))
5472       (setq gnus-newsgroup-unselected
5473             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5474       (when gnus-alter-articles-to-read-function
5475         (setq articles
5476               (sort
5477                (funcall gnus-alter-articles-to-read-function
5478                         gnus-newsgroup-name articles)
5479                '<)))
5480       articles)))
5481
5482 (defun gnus-killed-articles (killed articles)
5483   (let (out)
5484     (while articles
5485       (when (inline (gnus-member-of-range (car articles) killed))
5486         (push (car articles) out))
5487       (setq articles (cdr articles)))
5488     out))
5489
5490 (defun gnus-uncompress-marks (marks)
5491   "Uncompress the mark ranges in MARKS."
5492   (let ((uncompressed '(score bookmark))
5493         out)
5494     (while marks
5495       (if (memq (caar marks) uncompressed)
5496           (push (car marks) out)
5497         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5498       (setq marks (cdr marks)))
5499     out))
5500
5501 (defun gnus-article-mark-to-type (mark)
5502   "Return the type of MARK."
5503   (or (cadr (assq mark gnus-article-special-mark-lists))
5504       'list))
5505
5506 (defun gnus-article-unpropagatable-p (mark)
5507   "Return whether MARK should be propagated to back end."
5508   (memq mark gnus-article-unpropagated-mark-lists))
5509
5510 (defun gnus-adjust-marked-articles (info)
5511   "Set all article lists and remove all marks that are no longer valid."
5512   (let* ((marked-lists (gnus-info-marks info))
5513          (active (gnus-active (gnus-info-group info)))
5514          (min (car active))
5515          (max (cdr active))
5516          (types gnus-article-mark-lists)
5517          marks var articles article mark mark-type
5518          bgn end)
5519
5520     (dolist (marks marked-lists)
5521       (setq mark (car marks)
5522             mark-type (gnus-article-mark-to-type mark)
5523             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5524
5525       ;; We set the variable according to the type of the marks list,
5526       ;; and then adjust the marks to a subset of the active articles.
5527       (cond
5528        ;; Adjust "simple" lists - compressed yet unsorted
5529        ((eq mark-type 'list)
5530         ;; Simultaneously uncompress and clip to active range
5531         ;; See gnus-uncompress-range for a description of possible marks
5532         (let (l lh)
5533           (if (not (cadr marks))
5534               (set var nil)
5535             (setq articles (if (numberp (cddr marks))
5536                                (list (cdr marks))
5537                              (cdr marks))
5538                   lh (cons nil nil)
5539                   l lh)
5540
5541             (while (setq article (pop articles))
5542               (cond ((consp article)
5543                      (setq bgn (max (car article) min)
5544                            end (min (cdr article) max))
5545                      (while (<= bgn end)
5546                        (setq l (setcdr l (cons bgn nil))
5547                              bgn (1+ bgn))))
5548                     ((and (<= min article)
5549                           (>= max article))
5550                      (setq l (setcdr l (cons article nil))))))
5551             (set var (cdr lh)))))
5552        ;; Adjust assocs.
5553        ((eq mark-type 'tuple)
5554         (set var (setq articles (cdr marks)))
5555         (when (not (listp (cdr (symbol-value var))))
5556           (set var (list (symbol-value var))))
5557         (when (not (listp (cdr articles)))
5558           (setq articles (list articles)))
5559         (while articles
5560           (when (or (not (consp (setq article (pop articles))))
5561                     (< (car article) min)
5562                     (> (car article) max))
5563             (set var (delq article (symbol-value var))))))
5564        ;; Adjust ranges (sloppily).
5565        ((eq mark-type 'range)
5566         (cond
5567          ((eq mark 'seen)
5568           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5569           ;; It should be (seen (NUM1 . NUM2)).
5570           (when (numberp (cddr marks))
5571             (setcdr marks (list (cdr marks))))
5572           (setq articles (cdr marks))
5573           (while (and articles
5574                       (or (and (consp (car articles))
5575                                (> min (cdar articles)))
5576                           (and (numberp (car articles))
5577                                (> min (car articles)))))
5578             (pop articles))
5579           (set var articles))))))))
5580
5581 (defun gnus-update-missing-marks (missing)
5582   "Go through the list of MISSING articles and remove them from the mark lists."
5583   (when missing
5584     (let (var m)
5585       ;; Go through all types.
5586       (dolist (elem gnus-article-mark-lists)
5587         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5588           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5589           (when (symbol-value var)
5590             ;; This list has articles.  So we delete all missing
5591             ;; articles from it.
5592             (setq m missing)
5593             (while m
5594               (set var (delq (pop m) (symbol-value var))))))))))
5595
5596 (defun gnus-update-marks ()
5597   "Enter the various lists of marked articles into the newsgroup info list."
5598   (let ((types gnus-article-mark-lists)
5599         (info (gnus-get-info gnus-newsgroup-name))
5600         type list newmarked symbol delta-marks)
5601     (when info
5602       ;; Add all marks lists to the list of marks lists.
5603       (while (setq type (pop types))
5604         (setq list (symbol-value
5605                     (setq symbol
5606                           (intern (format "gnus-newsgroup-%s" (car type))))))
5607
5608         (when list
5609           ;; Get rid of the entries of the articles that have the
5610           ;; default score.
5611           (when (and (eq (cdr type) 'score)
5612                      gnus-save-score
5613                      list)
5614             (let* ((arts list)
5615                    (prev (cons nil list))
5616                    (all prev))
5617               (while arts
5618                 (if (or (not (consp (car arts)))
5619                         (= (cdar arts) gnus-summary-default-score))
5620                     (setcdr prev (cdr arts))
5621                   (setq prev arts))
5622                 (setq arts (cdr arts)))
5623               (setq list (cdr all)))))
5624
5625         (when (eq (cdr type) 'seen)
5626           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5627
5628         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5629           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5630
5631         (when (and (gnus-check-backend-function
5632                     'request-set-mark gnus-newsgroup-name)
5633                    (not (gnus-article-unpropagatable-p (cdr type))))
5634           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5635                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5636                  (add (gnus-remove-from-range
5637                        (gnus-copy-sequence list) old)))
5638             (when add
5639               (push (list add 'add (list (cdr type))) delta-marks))
5640             (when del
5641               (push (list del 'del (list (cdr type))) delta-marks))))
5642
5643         (when list
5644           (push (cons (cdr type) list) newmarked)))
5645
5646       (when delta-marks
5647         (unless (gnus-check-group gnus-newsgroup-name)
5648           (error "Can't open server for %s" gnus-newsgroup-name))
5649         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5650
5651       ;; Enter these new marks into the info of the group.
5652       (if (nthcdr 3 info)
5653           (setcar (nthcdr 3 info) newmarked)
5654         ;; Add the marks lists to the end of the info.
5655         (when newmarked
5656           (setcdr (nthcdr 2 info) (list newmarked))))
5657
5658       ;; Cut off the end of the info if there's nothing else there.
5659       (let ((i 5))
5660         (while (and (> i 2)
5661                     (not (nth i info)))
5662           (when (nthcdr (decf i) info)
5663             (setcdr (nthcdr i info) nil)))))))
5664
5665 (defun gnus-set-mode-line (where)
5666   "Set the mode line of the article or summary buffers.
5667 If WHERE is `summary', the summary mode line format will be used."
5668   ;; Is this mode line one we keep updated?
5669   (when (and (memq where gnus-updated-mode-lines)
5670              (symbol-value
5671               (intern (format "gnus-%s-mode-line-format-spec" where))))
5672     (let (mode-string)
5673       (save-excursion
5674         ;; We evaluate this in the summary buffer since these
5675         ;; variables are buffer-local to that buffer.
5676         (set-buffer gnus-summary-buffer)
5677         ;; We bind all these variables that are used in the `eval' form
5678         ;; below.
5679         (let* ((mformat (symbol-value
5680                          (intern
5681                           (format "gnus-%s-mode-line-format-spec" where))))
5682                (gnus-tmp-group-name (gnus-group-decoded-name
5683                                      gnus-newsgroup-name))
5684                (gnus-tmp-article-number (or gnus-current-article 0))
5685                (gnus-tmp-unread gnus-newsgroup-unreads)
5686                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5687                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5688                (gnus-tmp-unread-and-unselected
5689                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5690                             (zerop gnus-tmp-unselected))
5691                        "")
5692                       ((zerop gnus-tmp-unselected)
5693                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5694                       (t (format "{%d(+%d) more}"
5695                                  gnus-tmp-unread-and-unticked
5696                                  gnus-tmp-unselected))))
5697                (gnus-tmp-subject
5698                 (if (and gnus-current-headers
5699                          (vectorp gnus-current-headers))
5700                     (gnus-mode-string-quote
5701                      (mail-header-subject gnus-current-headers))
5702                   ""))
5703                bufname-length max-len
5704                gnus-tmp-header);; passed as argument to any user-format-funcs
5705           (setq mode-string (eval mformat))
5706           (setq bufname-length (if (string-match "%b" mode-string)
5707                                    (- (length
5708                                        (buffer-name
5709                                         (if (eq where 'summary)
5710                                             nil
5711                                           (get-buffer gnus-article-buffer))))
5712                                       2)
5713                                  0))
5714           (setq max-len (max 4 (if gnus-mode-non-string-length
5715                                    (- (window-width)
5716                                       gnus-mode-non-string-length
5717                                       bufname-length)
5718                                  (length mode-string))))
5719           ;; We might have to chop a bit of the string off...
5720           (when (> (length mode-string) max-len)
5721             (setq mode-string
5722                   (concat (gnus-truncate-string mode-string (- max-len 3))
5723                           "...")))
5724           ;; Pad the mode string a bit.
5725           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5726       ;; Update the mode line.
5727       (setq mode-line-buffer-identification
5728             (gnus-mode-line-buffer-identification (list mode-string)))
5729       (set-buffer-modified-p t))))
5730
5731 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5732   "Go through the HEADERS list and add all Xrefs to a hash table.
5733 The resulting hash table is returned, or nil if no Xrefs were found."
5734   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5735          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5736          (xref-hashtb (gnus-make-hashtable))
5737          start group entry number xrefs header)
5738     (while headers
5739       (setq header (pop headers))
5740       (when (and (setq xrefs (mail-header-xref header))
5741                  (not (memq (setq number (mail-header-number header))
5742                             unreads)))
5743         (setq start 0)
5744         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5745           (setq start (match-end 0))
5746           (setq group (if prefix
5747                           (concat prefix (substring xrefs (match-beginning 1)
5748                                                     (match-end 1)))
5749                         (substring xrefs (match-beginning 1) (match-end 1))))
5750           (setq number
5751                 (string-to-number (substring xrefs (match-beginning 2)
5752                                           (match-end 2))))
5753           (if (setq entry (gnus-gethash group xref-hashtb))
5754               (setcdr entry (cons number (cdr entry)))
5755             (gnus-sethash group (cons number nil) xref-hashtb)))))
5756     (and start xref-hashtb)))
5757
5758 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5759   "Look through all the headers and mark the Xrefs as read."
5760   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5761         name info xref-hashtb idlist method nth4)
5762     (save-excursion
5763       (set-buffer gnus-group-buffer)
5764       (when (setq xref-hashtb
5765                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5766         (mapatoms
5767          (lambda (group)
5768            (unless (string= from-newsgroup (setq name (symbol-name group)))
5769              (setq idlist (symbol-value group))
5770              ;; Dead groups are not updated.
5771              (and (prog1
5772                       (setq info (gnus-get-info name))
5773                     (when (stringp (setq nth4 (gnus-info-method info)))
5774                       (setq nth4 (gnus-server-to-method nth4))))
5775                   ;; Only do the xrefs if the group has the same
5776                   ;; select method as the group we have just read.
5777                   (or (gnus-methods-equal-p
5778                        nth4 (gnus-find-method-for-group from-newsgroup))
5779                       virtual
5780                       (equal nth4 (setq method (gnus-find-method-for-group
5781                                                 from-newsgroup)))
5782                       (and (equal (car nth4) (car method))
5783                            (equal (nth 1 nth4) (nth 1 method))))
5784                   gnus-use-cross-reference
5785                   (or (not (eq gnus-use-cross-reference t))
5786                       virtual
5787                       ;; Only do cross-references on subscribed
5788                       ;; groups, if that is what is wanted.
5789                       (<= (gnus-info-level info) gnus-level-subscribed))
5790                   (gnus-group-make-articles-read name idlist))))
5791          xref-hashtb)))))
5792
5793 (defun gnus-compute-read-articles (group articles)
5794   (let* ((entry (gnus-group-entry group))
5795          (info (nth 2 entry))
5796          (active (gnus-active group))
5797          ninfo)
5798     (when entry
5799       ;; First peel off all invalid article numbers.
5800       (when active
5801         (let ((ids articles)
5802               id first)
5803           (while (setq id (pop ids))
5804             (when (and first (> id (cdr active)))
5805               ;; We'll end up in this situation in one particular
5806               ;; obscure situation.  If you re-scan a group and get
5807               ;; a new article that is cross-posted to a different
5808               ;; group that has not been re-scanned, you might get
5809               ;; crossposted article that has a higher number than
5810               ;; Gnus believes possible.  So we re-activate this
5811               ;; group as well.  This might mean doing the
5812               ;; crossposting thingy will *increase* the number
5813               ;; of articles in some groups.  Tsk, tsk.
5814               (setq active (or (gnus-activate-group group) active)))
5815             (when (or (> id (cdr active))
5816                       (< id (car active)))
5817               (setq articles (delq id articles))))))
5818       ;; If the read list is nil, we init it.
5819       (if (and active
5820                (null (gnus-info-read info))
5821                (> (car active) 1))
5822           (setq ninfo (cons 1 (1- (car active))))
5823         (setq ninfo (gnus-info-read info)))
5824       ;; Then we add the read articles to the range.
5825       (gnus-add-to-range
5826        ninfo (setq articles (sort articles '<))))))
5827
5828 (defun gnus-group-make-articles-read (group articles)
5829   "Update the info of GROUP to say that ARTICLES are read."
5830   (let* ((num 0)
5831          (entry (gnus-group-entry group))
5832          (info (nth 2 entry))
5833          (active (gnus-active group))
5834          range)
5835     (when entry
5836       (setq range (gnus-compute-read-articles group articles))
5837       (with-current-buffer gnus-group-buffer
5838         (gnus-undo-register
5839           `(progn
5840              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5841              (gnus-info-set-read ',info ',(gnus-info-read info))
5842              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5843              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5844              (gnus-group-update-group ,group t))))
5845       ;; Add the read articles to the range.
5846       (gnus-info-set-read info range)
5847       (gnus-request-set-mark group (list (list range 'add '(read))))
5848       ;; Then we have to re-compute how many unread
5849       ;; articles there are in this group.
5850       (when active
5851         (cond
5852          ((not range)
5853           (setq num (- (1+ (cdr active)) (car active))))
5854          ((not (listp (cdr range)))
5855           (setq num (- (cdr active) (- (1+ (cdr range))
5856                                        (car range)))))
5857          (t
5858           (while range
5859             (if (numberp (car range))
5860                 (setq num (1+ num))
5861               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5862             (setq range (cdr range)))
5863           (setq num (- (cdr active) num))))
5864         ;; Update the number of unread articles.
5865         (setcar entry num)
5866         ;; Update the group buffer.
5867         (unless (gnus-ephemeral-group-p group)
5868           (gnus-group-update-group group t))))))
5869
5870 (defvar gnus-newsgroup-none-id 0)
5871
5872 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5873   (let ((cur nntp-server-buffer)
5874         (dependencies
5875          (or dependencies
5876              (with-current-buffer gnus-summary-buffer
5877                gnus-newsgroup-dependencies)))
5878         headers id end ref number
5879         (mail-parse-charset gnus-newsgroup-charset)
5880         (mail-parse-ignored-charsets
5881          (save-excursion (condition-case nil
5882                              (set-buffer gnus-summary-buffer)
5883                            (error))
5884                          gnus-newsgroup-ignored-charsets)))
5885     (save-excursion
5886       (set-buffer nntp-server-buffer)
5887       ;; Translate all TAB characters into SPACE characters.
5888       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5889       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5890       (ietf-drums-unfold-fws)
5891       (gnus-run-hooks 'gnus-parse-headers-hook)
5892       (let ((case-fold-search t)
5893             in-reply-to header p lines chars ctype)
5894         (goto-char (point-min))
5895         ;; Search to the beginning of the next header.  Error messages
5896         ;; do not begin with 2 or 3.
5897         (while (re-search-forward "^[23][0-9]+ " nil t)
5898           (setq id nil
5899                 ref nil)
5900           ;; This implementation of this function, with nine
5901           ;; search-forwards instead of the one re-search-forward and
5902           ;; a case (which basically was the old function) is actually
5903           ;; about twice as fast, even though it looks messier.  You
5904           ;; can't have everything, I guess.  Speed and elegance
5905           ;; doesn't always go hand in hand.
5906           (setq
5907            header
5908            (make-full-mail-header
5909             ;; Number.
5910             (prog1
5911                 (setq number (read cur))
5912               (end-of-line)
5913               (setq p (point))
5914               (narrow-to-region (point)
5915                                 (or (and (search-forward "\n.\n" nil t)
5916                                          (- (point) 2))
5917                                     (point))))
5918             ;; Subject.
5919             (progn
5920               (goto-char p)
5921               (if (search-forward "\nsubject:" nil t)
5922                   (nnheader-header-value)
5923                 "(none)"))
5924             ;; From.
5925             (progn
5926               (goto-char p)
5927               (if (search-forward "\nfrom:" nil t)
5928                   (nnheader-header-value)
5929                 "(nobody)"))
5930             ;; Date.
5931             (progn
5932               (goto-char p)
5933               (if (search-forward "\ndate:" nil t)
5934                   (nnheader-header-value) ""))
5935             ;; Message-ID.
5936             (progn
5937               (goto-char p)
5938               (setq id (if (re-search-forward
5939                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5940                            ;; We do it this way to make sure the Message-ID
5941                            ;; is (somewhat) syntactically valid.
5942                            (buffer-substring (match-beginning 1)
5943                                              (match-end 1))
5944                          ;; If there was no message-id, we just fake one
5945                          ;; to make subsequent routines simpler.
5946                          (nnheader-generate-fake-message-id number))))
5947             ;; References.
5948             (progn
5949               (goto-char p)
5950               (if (search-forward "\nreferences:" nil t)
5951                   (progn
5952                     (setq end (point))
5953                     (prog1
5954                         (nnheader-header-value)
5955                       (setq ref
5956                             (buffer-substring
5957                              (progn
5958                                ;; (end-of-line)
5959                                (search-backward ">" end t)
5960                                (1+ (point)))
5961                              (progn
5962                                (search-backward "<" end t)
5963                                (point))))))
5964                 ;; Get the references from the in-reply-to header if there
5965                 ;; were no references and the in-reply-to header looks
5966                 ;; promising.
5967                 (if (and (search-forward "\nin-reply-to:" nil t)
5968                          (setq in-reply-to (nnheader-header-value))
5969                          (string-match "<[^>]+>" in-reply-to))
5970                     (let (ref2)
5971                       (setq ref (substring in-reply-to (match-beginning 0)
5972                                            (match-end 0)))
5973                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5974                         (setq ref2 (substring in-reply-to (match-beginning 0)
5975                                               (match-end 0)))
5976                         (when (> (length ref2) (length ref))
5977                           (setq ref ref2)))
5978                       ref)
5979                   (setq ref nil))))
5980             ;; Chars.
5981             (progn
5982               (goto-char p)
5983               (if (search-forward "\nchars: " nil t)
5984                   (if (numberp (setq chars (ignore-errors (read cur))))
5985                       chars -1)
5986                 -1))
5987             ;; Lines.
5988             (progn
5989               (goto-char p)
5990               (if (search-forward "\nlines: " nil t)
5991                   (if (numberp (setq lines (ignore-errors (read cur))))
5992                       lines -1)
5993                 -1))
5994             ;; Xref.
5995             (progn
5996               (goto-char p)
5997               (and (search-forward "\nxref:" nil t)
5998                    (nnheader-header-value)))
5999             ;; Extra.
6000             (when gnus-extra-headers
6001               (let ((extra gnus-extra-headers)
6002                     out)
6003                 (while extra
6004                   (goto-char p)
6005                   (when (search-forward
6006                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6007                     (push (cons (car extra) (nnheader-header-value)) out))
6008                   (pop extra))
6009                 out))))
6010           (goto-char p)
6011           (if (and (search-forward "\ncontent-type: " nil t)
6012                    (setq ctype (nnheader-header-value)))
6013               (mime-entity-set-content-type-internal
6014                header (mime-parse-Content-Type ctype)))
6015           (when (equal id ref)
6016             (setq ref nil))
6017
6018           (when gnus-alter-header-function
6019             (funcall gnus-alter-header-function header)
6020             (setq id (mail-header-id header)
6021                   ref (gnus-parent-id (mail-header-references header))))
6022
6023           (when (setq header
6024                       (gnus-dependencies-add-header
6025                        header dependencies force-new))
6026             (push header headers))
6027           (goto-char (point-max))
6028           (widen))
6029         (nreverse headers)))))
6030
6031 ;; Goes through the xover lines and returns a list of vectors
6032 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6033                                                   force-new dependencies
6034                                                   group also-fetch-heads)
6035   "Parse the news overview data in the server buffer.
6036 Return a list of headers that match SEQUENCE (see
6037 `nntp-retrieve-headers')."
6038   ;; Get the Xref when the users reads the articles since most/some
6039   ;; NNTP servers do not include Xrefs when using XOVER.
6040   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6041   (let ((mail-parse-charset gnus-newsgroup-charset)
6042         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6043         (cur nntp-server-buffer)
6044         (dependencies (or dependencies gnus-newsgroup-dependencies))
6045         (allp (cond
6046                ((eq gnus-read-all-available-headers t)
6047                 t)
6048                ((stringp gnus-read-all-available-headers)
6049                 (string-match gnus-read-all-available-headers group))
6050                (t
6051                 nil)))
6052         number headers header)
6053     (save-excursion
6054       (set-buffer nntp-server-buffer)
6055       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6056       ;; Allow the user to mangle the headers before parsing them.
6057       (gnus-run-hooks 'gnus-parse-headers-hook)
6058       (goto-char (point-min))
6059       (gnus-parse-without-error
6060         (while (and (or sequence allp)
6061                     (not (eobp)))
6062           (setq number (read cur))
6063           (when (not allp)
6064             (while (and sequence
6065                         (< (car sequence) number))
6066               (setq sequence (cdr sequence))))
6067           (when (and (or allp
6068                          (and sequence
6069                               (eq number (car sequence))))
6070                      (progn
6071                        (setq sequence (cdr sequence))
6072                        (setq header (inline
6073                                       (gnus-nov-parse-line
6074                                        number dependencies force-new)))))
6075             (push header headers))
6076           (forward-line 1)))
6077       ;; A common bug in inn is that if you have posted an article and
6078       ;; then retrieves the active file, it will answer correctly --
6079       ;; the new article is included.  However, a NOV entry for the
6080       ;; article may not have been generated yet, so this may fail.
6081       ;; We work around this problem by retrieving the last few
6082       ;; headers using HEAD.
6083       (if (or (not also-fetch-heads)
6084               (not sequence))
6085           ;; We (probably) got all the headers.
6086           (nreverse headers)
6087         (let ((gnus-nov-is-evil t))
6088           (nconc
6089            (nreverse headers)
6090            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6091              (gnus-get-newsgroup-headers))))))))
6092
6093 (defun gnus-article-get-xrefs ()
6094   "Fill in the Xref value in `gnus-current-headers', if necessary.
6095 This is meant to be called in `gnus-article-internal-prepare-hook'."
6096   (let ((headers (with-current-buffer gnus-summary-buffer
6097                    gnus-current-headers)))
6098     (or (not gnus-use-cross-reference)
6099         (not headers)
6100         (and (mail-header-xref headers)
6101              (not (string= (mail-header-xref headers) "")))
6102         (let ((case-fold-search t)
6103               xref)
6104           (save-restriction
6105             (nnheader-narrow-to-headers)
6106             (goto-char (point-min))
6107             (when (or (and (not (eobp))
6108                            (eq (downcase (char-after)) ?x)
6109                            (looking-at "Xref:"))
6110                       (search-forward "\nXref:" nil t))
6111               (goto-char (1+ (match-end 0)))
6112               (setq xref (buffer-substring (point) (point-at-eol)))
6113               (mail-header-set-xref headers xref)))))))
6114
6115 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6116   "Find article ID and insert the summary line for that article.
6117 OLD-HEADER can either be a header or a line number to insert
6118 the subject line on."
6119   (let* ((line (and (numberp old-header) old-header))
6120          (old-header (and (vectorp old-header) old-header))
6121          (header (cond ((and old-header use-old-header)
6122                         old-header)
6123                        ((and (numberp id)
6124                              (gnus-number-to-header id))
6125                         (gnus-number-to-header id))
6126                        (t
6127                         (gnus-read-header id))))
6128          (number (and (numberp id) id))
6129          d)
6130     (when header
6131       ;; Rebuild the thread that this article is part of and go to the
6132       ;; article we have fetched.
6133       (when (and (not gnus-show-threads)
6134                  old-header)
6135         (when (and number
6136                    (setq d (gnus-data-find (mail-header-number old-header))))
6137           (goto-char (gnus-data-pos d))
6138           (gnus-data-remove
6139            number
6140            (- (point-at-bol)
6141               (prog1
6142                   (1+ (point-at-eol))
6143                 (gnus-delete-line))))))
6144       ;; Remove list identifiers from subject.
6145       (when gnus-list-identifiers
6146         (let ((gnus-newsgroup-headers (list header)))
6147           (gnus-summary-remove-list-identifiers)))
6148       (when old-header
6149         (mail-header-set-number header (mail-header-number old-header)))
6150       (setq gnus-newsgroup-sparse
6151             (delq (setq number (mail-header-number header))
6152                   gnus-newsgroup-sparse))
6153       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6154       (push number gnus-newsgroup-limit)
6155       (gnus-rebuild-thread (mail-header-id header) line)
6156       (gnus-summary-goto-subject number nil t))
6157     (when (and (numberp number)
6158                (> number 0))
6159       ;; We have to update the boundaries even if we can't fetch the
6160       ;; article if ID is a number -- so that the next `P' or `N'
6161       ;; command will fetch the previous (or next) article even
6162       ;; if the one we tried to fetch this time has been canceled.
6163       (when (> number gnus-newsgroup-end)
6164         (setq gnus-newsgroup-end number))
6165       (when (< number gnus-newsgroup-begin)
6166         (setq gnus-newsgroup-begin number))
6167       (setq gnus-newsgroup-unselected
6168             (delq number gnus-newsgroup-unselected)))
6169     ;; Report back a success?
6170     (and header (mail-header-number header))))
6171
6172 ;;; Process/prefix in the summary buffer
6173
6174 (defun gnus-summary-work-articles (n)
6175   "Return a list of articles to be worked upon.
6176 The prefix argument, the list of process marked articles, and the
6177 current article will be taken into consideration."
6178   (save-excursion
6179     (set-buffer gnus-summary-buffer)
6180     (cond
6181      (n
6182       ;; A numerical prefix has been given.
6183       (setq n (prefix-numeric-value n))
6184       (let ((backward (< n 0))
6185             (n (abs (prefix-numeric-value n)))
6186             articles article)
6187         (save-excursion
6188           (while
6189               (and (> n 0)
6190                    (push (setq article (gnus-summary-article-number))
6191                          articles)
6192                    (if backward
6193                        (gnus-summary-find-prev nil article)
6194                      (gnus-summary-find-next nil article)))
6195             (decf n)))
6196         (nreverse articles)))
6197      ((and (gnus-region-active-p) (mark))
6198       (message "region active")
6199       ;; Work on the region between point and mark.
6200       (let ((max (max (point) (mark)))
6201             articles article)
6202         (save-excursion
6203           (goto-char (min (point) (mark)))
6204           (while
6205               (and
6206                (push (setq article (gnus-summary-article-number)) articles)
6207                (gnus-summary-find-next nil article)
6208                (< (point) max)))
6209           (nreverse articles))))
6210      (gnus-newsgroup-processable
6211       ;; There are process-marked articles present.
6212       ;; Save current state.
6213       (gnus-summary-save-process-mark)
6214       ;; Return the list.
6215       (reverse gnus-newsgroup-processable))
6216      (t
6217       ;; Just return the current article.
6218       (list (gnus-summary-article-number))))))
6219
6220 (defmacro gnus-summary-iterate (arg &rest forms)
6221   "Iterate over the process/prefixed articles and do FORMS.
6222 ARG is the interactive prefix given to the command.  FORMS will be
6223 executed with point over the summary line of the articles."
6224   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6225     `(let ((,articles (gnus-summary-work-articles ,arg)))
6226        (while ,articles
6227          (gnus-summary-goto-subject (car ,articles))
6228          ,@forms
6229          (pop ,articles)))))
6230
6231 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6232 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6233
6234 (defun gnus-summary-save-process-mark ()
6235   "Push the current set of process marked articles on the stack."
6236   (interactive)
6237   (push (copy-sequence gnus-newsgroup-processable)
6238         gnus-newsgroup-process-stack))
6239
6240 (defun gnus-summary-kill-process-mark ()
6241   "Push the current set of process marked articles on the stack and unmark."
6242   (interactive)
6243   (gnus-summary-save-process-mark)
6244   (gnus-summary-unmark-all-processable))
6245
6246 (defun gnus-summary-yank-process-mark ()
6247   "Pop the last process mark state off the stack and restore it."
6248   (interactive)
6249   (unless gnus-newsgroup-process-stack
6250     (error "Empty mark stack"))
6251   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6252
6253 (defun gnus-summary-process-mark-set (set)
6254   "Make SET into the current process marked articles."
6255   (gnus-summary-unmark-all-processable)
6256   (mapc 'gnus-summary-set-process-mark set))
6257
6258 ;;; Searching and stuff
6259
6260 (defun gnus-summary-search-group (&optional backward use-level)
6261   "Search for next unread newsgroup.
6262 If optional argument BACKWARD is non-nil, search backward instead."
6263   (save-excursion
6264     (set-buffer gnus-group-buffer)
6265     (when (gnus-group-search-forward
6266            backward nil (if use-level (gnus-group-group-level) nil))
6267       (gnus-group-group-name))))
6268
6269 (defun gnus-summary-best-group (&optional exclude-group)
6270   "Find the name of the best unread group.
6271 If EXCLUDE-GROUP, do not go to this group."
6272   (with-current-buffer gnus-group-buffer
6273     (save-excursion
6274       (gnus-group-best-unread-group exclude-group))))
6275
6276 (defun gnus-summary-find-next (&optional unread article backward)
6277   (if backward
6278       (gnus-summary-find-prev unread article)
6279     (let* ((dummy (gnus-summary-article-intangible-p))
6280            (article (or article (gnus-summary-article-number)))
6281            (data (gnus-data-find-list article))
6282            result)
6283       (when (and (not dummy)
6284                  (or (not gnus-summary-check-current)
6285                      (not unread)
6286                      (not (gnus-data-unread-p (car data)))))
6287         (setq data (cdr data)))
6288       (when (setq result
6289                   (if unread
6290                       (progn
6291                         (while data
6292                           (unless (memq (gnus-data-number (car data))
6293                                         (cond
6294                                          ((eq gnus-auto-goto-ignores
6295                                               'always-undownloaded)
6296                                           gnus-newsgroup-undownloaded)
6297                                          (gnus-plugged
6298                                           nil)
6299                                          ((eq gnus-auto-goto-ignores
6300                                               'unfetched)
6301                                           gnus-newsgroup-unfetched)
6302                                          ((eq gnus-auto-goto-ignores
6303                                               'undownloaded)
6304                                           gnus-newsgroup-undownloaded)))
6305                             (when (gnus-data-unread-p (car data))
6306                               (setq result (car data)
6307                                     data nil)))
6308                           (setq data (cdr data)))
6309                         result)
6310                     (car data)))
6311         (goto-char (gnus-data-pos result))
6312         (gnus-data-number result)))))
6313
6314 (defun gnus-summary-find-prev (&optional unread article)
6315   (let* ((eobp (eobp))
6316          (article (or article (gnus-summary-article-number)))
6317          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6318          result)
6319     (when (and (not eobp)
6320                (or (not gnus-summary-check-current)
6321                    (not unread)
6322                    (not (gnus-data-unread-p (car data)))))
6323       (setq data (cdr data)))
6324     (when (setq result
6325                 (if unread
6326                     (progn
6327                       (while data
6328                         (unless (memq (gnus-data-number (car data))
6329                                       (cond
6330                                        ((eq gnus-auto-goto-ignores
6331                                             'always-undownloaded)
6332                                         gnus-newsgroup-undownloaded)
6333                                        (gnus-plugged
6334                                         nil)
6335                                        ((eq gnus-auto-goto-ignores
6336                                             'unfetched)
6337                                         gnus-newsgroup-unfetched)
6338                                        ((eq gnus-auto-goto-ignores
6339                                             'undownloaded)
6340                                         gnus-newsgroup-undownloaded)))
6341                           (when (gnus-data-unread-p (car data))
6342                             (setq result (car data)
6343                                   data nil)))
6344                         (setq data (cdr data)))
6345                       result)
6346                   (car data)))
6347       (goto-char (gnus-data-pos result))
6348       (gnus-data-number result))))
6349
6350 (defun gnus-summary-find-subject (subject &optional unread backward article)
6351   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6352          (article (or article (gnus-summary-article-number)))
6353          (articles (gnus-data-list backward))
6354          (arts (gnus-data-find-list article articles))
6355          result)
6356     (when (or (not gnus-summary-check-current)
6357               (not unread)
6358               (not (gnus-data-unread-p (car arts))))
6359       (setq arts (cdr arts)))
6360     (while arts
6361       (and (or (not unread)
6362                (gnus-data-unread-p (car arts)))
6363            (vectorp (gnus-data-header (car arts)))
6364            (gnus-subject-equal
6365             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6366            (setq result (car arts)
6367                  arts nil))
6368       (setq arts (cdr arts)))
6369     (and result
6370          (goto-char (gnus-data-pos result))
6371          (gnus-data-number result))))
6372
6373 (defun gnus-summary-search-forward (&optional unread subject backward)
6374   "Search forward for an article.
6375 If UNREAD, look for unread articles.  If SUBJECT, look for
6376 articles with that subject.  If BACKWARD, search backward instead."
6377   (cond (subject (gnus-summary-find-subject subject unread backward))
6378         (backward (gnus-summary-find-prev unread))
6379         (t (gnus-summary-find-next unread))))
6380
6381 (defun gnus-recenter (&optional n)
6382   "Center point in window and redisplay frame.
6383 Also do horizontal recentering."
6384   (interactive "P")
6385   (when (and gnus-auto-center-summary
6386              (not (eq gnus-auto-center-summary 'vertical)))
6387     (gnus-horizontal-recenter))
6388   (recenter n))
6389
6390 (defun gnus-summary-recenter ()
6391   "Center point in the summary window.
6392 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6393 displayed, no centering will be performed."
6394   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6395   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6396   (interactive)
6397   ;; The user has to want it.
6398   (when gnus-auto-center-summary
6399     (let* ((top (cond ((< (window-height) 4) 0)
6400                       ((< (window-height) 7) 1)
6401                       (t (if (numberp gnus-auto-center-summary)
6402                              gnus-auto-center-summary
6403                            (/ (1- (window-height)) 2)))))
6404            (height (1- (window-height)))
6405            (bottom (save-excursion (goto-char (point-max))
6406                                    (forward-line (- height))
6407                                    (point)))
6408            (window (get-buffer-window (current-buffer))))
6409       (when (get-buffer-window gnus-article-buffer)
6410         ;; Only do recentering when the article buffer is displayed,
6411         ;; Set the window start to either `bottom', which is the biggest
6412         ;; possible valid number, or the second line from the top,
6413         ;; whichever is the least.
6414         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6415           (if (> bottom top-pos)
6416               ;; Keep the second line from the top visible
6417               (set-window-start window top-pos t)
6418             ;; Try to keep the bottom line visible; if it's partially
6419             ;; obscured, either scroll one more line to make it fully
6420             ;; visible, or revert to using TOP-POS.
6421             (save-excursion
6422               (goto-char (point-max))
6423               (forward-line -1)
6424               (let ((last-line-start (point)))
6425                 (goto-char bottom)
6426                 (set-window-start window (point) t)
6427                 (when (not (pos-visible-in-window-p last-line-start window))
6428                   (forward-line 1)
6429                   (set-window-start window (min (point) top-pos) t)))))))
6430       ;; Do horizontal recentering while we're at it.
6431       (when (and (get-buffer-window (current-buffer) t)
6432                  (not (eq gnus-auto-center-summary 'vertical)))
6433         (let ((selected (selected-window)))
6434           (select-window (get-buffer-window (current-buffer) t))
6435           (gnus-summary-position-point)
6436           (gnus-horizontal-recenter)
6437           (select-window selected))))))
6438
6439 (defun gnus-summary-jump-to-group (newsgroup)
6440   "Move point to NEWSGROUP in group mode buffer."
6441   ;; Keep update point of group mode buffer if visible.
6442   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6443       (save-window-excursion
6444         ;; Take care of tree window mode.
6445         (when (get-buffer-window gnus-group-buffer)
6446           (pop-to-buffer gnus-group-buffer))
6447         (gnus-group-jump-to-group newsgroup))
6448     (save-excursion
6449       ;; Take care of tree window mode.
6450       (if (get-buffer-window gnus-group-buffer)
6451           (pop-to-buffer gnus-group-buffer)
6452         (set-buffer gnus-group-buffer))
6453       (gnus-group-jump-to-group newsgroup))))
6454
6455 ;; This function returns a list of article numbers based on the
6456 ;; difference between the ranges of read articles in this group and
6457 ;; the range of active articles.
6458 (defun gnus-list-of-unread-articles (group)
6459   (let* ((read (gnus-info-read (gnus-get-info group)))
6460          (active (or (gnus-active group) (gnus-activate-group group)))
6461          (last (or (cdr active)
6462                    (error "Group %s couldn't be activated " group)))
6463          first nlast unread)
6464     ;; If none are read, then all are unread.
6465     (if (not read)
6466         (setq first (car active))
6467       ;; If the range of read articles is a single range, then the
6468       ;; first unread article is the article after the last read
6469       ;; article.  Sounds logical, doesn't it?
6470       (if (and (not (listp (cdr read)))
6471                (or (< (car read) (car active))
6472                    (progn (setq read (list read))
6473                           nil)))
6474           (setq first (max (car active) (1+ (cdr read))))
6475         ;; `read' is a list of ranges.
6476         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6477                                   (caar read)))
6478                   1)
6479           (setq first (car active)))
6480         (while read
6481           (when first
6482             (while (< first nlast)
6483               (setq unread (cons first unread)
6484                     first (1+ first))))
6485           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6486           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6487           (setq read (cdr read)))))
6488     ;; And add the last unread articles.
6489     (while (<= first last)
6490       (setq unread (cons first unread)
6491             first (1+ first)))
6492     ;; Return the list of unread articles.
6493     (delq 0 (nreverse unread))))
6494
6495 (defun gnus-list-of-read-articles (group)
6496   "Return a list of unread, unticked and non-dormant articles."
6497   (let* ((info (gnus-get-info group))
6498          (marked (gnus-info-marks info))
6499          (active (gnus-active group)))
6500     (and info active
6501          (gnus-list-range-difference
6502           (gnus-list-range-difference
6503            (gnus-sorted-complement
6504             (gnus-uncompress-range active)
6505             (gnus-list-of-unread-articles group))
6506            (cdr (assq 'dormant marked)))
6507           (cdr (assq 'tick marked))))))
6508
6509 ;; This function returns a sequence of article numbers based on the
6510 ;; difference between the ranges of read articles in this group and
6511 ;; the range of active articles.
6512 (defun gnus-sequence-of-unread-articles (group)
6513   (let* ((read (gnus-info-read (gnus-get-info group)))
6514          (active (or (gnus-active group) (gnus-activate-group group)))
6515          (last (cdr active))
6516          first nlast unread)
6517     ;; If none are read, then all are unread.
6518     (if (not read)
6519         (setq first (car active))
6520       ;; If the range of read articles is a single range, then the
6521       ;; first unread article is the article after the last read
6522       ;; article.  Sounds logical, doesn't it?
6523       (if (and (not (listp (cdr read)))
6524                (or (< (car read) (car active))
6525                    (progn (setq read (list read))
6526                           nil)))
6527           (setq first (max (car active) (1+ (cdr read))))
6528         ;; `read' is a list of ranges.
6529         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6530                                   (caar read)))
6531                   1)
6532           (setq first (car active)))
6533         (while read
6534           (when first
6535             (push (cons first nlast) unread))
6536           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6537           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6538           (setq read (cdr read)))))
6539     ;; And add the last unread articles.
6540     (cond ((< first last)
6541            (push (cons first last) unread))
6542           ((= first last)
6543            (push first unread)))
6544     ;; Return the sequence of unread articles.
6545     (delq 0 (nreverse unread))))
6546
6547 ;; Various summary commands
6548
6549 (defun gnus-summary-select-article-buffer ()
6550   "Reconfigure windows to show article buffer."
6551   (interactive)
6552   (if (not (gnus-buffer-live-p gnus-article-buffer))
6553       (error "There is no article buffer for this summary buffer")
6554     (gnus-configure-windows 'article)
6555     (select-window (get-buffer-window gnus-article-buffer))))
6556
6557 (defun gnus-summary-universal-argument (arg)
6558   "Perform any operation on all articles that are process/prefixed."
6559   (interactive "P")
6560   (let ((articles (gnus-summary-work-articles arg))
6561         func article)
6562     (if (eq
6563          (setq
6564           func
6565           (key-binding
6566            (read-key-sequence
6567             (substitute-command-keys
6568              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6569          'undefined)
6570         (gnus-error 1 "Undefined key")
6571       (save-excursion
6572         (while articles
6573           (gnus-summary-goto-subject (setq article (pop articles)))
6574           (let (gnus-newsgroup-processable)
6575             (command-execute func))
6576           (gnus-summary-remove-process-mark article)))))
6577   (gnus-summary-position-point))
6578
6579 (defun gnus-summary-toggle-truncation (&optional arg)
6580   "Toggle truncation of summary lines.
6581 With ARG, turn line truncation on if ARG is positive."
6582   (interactive "P")
6583   (setq truncate-lines
6584         (if (null arg) (not truncate-lines)
6585           (> (prefix-numeric-value arg) 0)))
6586   (redraw-display))
6587
6588 (defun gnus-summary-find-for-reselect ()
6589   "Return the number of an article to stay on across a reselect.
6590 The current article is considered, then following articles, then previous
6591 articles.  An article is sought which is not cancelled and isn't a temporary
6592 insertion from another group.  If there's no such then return a dummy 0."
6593   (let (found)
6594     (dolist (rev '(nil t))
6595       (unless found      ; don't demand the reverse list if we don't need it
6596         (let ((data (gnus-data-find-list
6597                      (gnus-summary-article-number) (gnus-data-list rev))))
6598           (while (and data (not found))
6599             (if (and (< 0 (gnus-data-number (car data)))
6600                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6601                 (setq found (gnus-data-number (car data))))
6602             (setq data (cdr data))))))
6603     (or found 0)))
6604
6605 (defun gnus-summary-reselect-current-group (&optional all rescan)
6606   "Exit and then reselect the current newsgroup.
6607 The prefix argument ALL means to select all articles."
6608   (interactive "P")
6609   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6610     (error "Ephemeral groups can't be reselected"))
6611   (let ((current-subject (gnus-summary-find-for-reselect))
6612         (group gnus-newsgroup-name))
6613     (setq gnus-newsgroup-begin nil)
6614     (gnus-summary-exit nil 'leave-hidden)
6615     ;; We have to adjust the point of group mode buffer because
6616     ;; point was moved to the next unread newsgroup by exiting.
6617     (gnus-summary-jump-to-group group)
6618     (when rescan
6619       (save-excursion
6620         (save-window-excursion
6621           ;; Don't show group contents.
6622           (set-window-start (selected-window) (point-max))
6623           (gnus-group-get-new-news-this-group 1))))
6624     (gnus-group-read-group all t)
6625     (gnus-summary-goto-subject current-subject nil t)))
6626
6627 (defun gnus-summary-rescan-group (&optional all)
6628   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6629   (interactive "P")
6630   (gnus-summary-reselect-current-group all t))
6631
6632 (defun gnus-summary-update-info (&optional non-destructive)
6633   (save-excursion
6634     (let ((group gnus-newsgroup-name))
6635       (when group
6636         (when gnus-newsgroup-kill-headers
6637           (setq gnus-newsgroup-killed
6638                 (gnus-compress-sequence
6639                  (gnus-sorted-union
6640                   (gnus-list-range-intersection
6641                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6642                   gnus-newsgroup-unreads)
6643                  t)))
6644         (unless (listp (cdr gnus-newsgroup-killed))
6645           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6646         (let ((headers gnus-newsgroup-headers))
6647           ;; Set the new ranges of read articles.
6648           (with-current-buffer gnus-group-buffer
6649             (gnus-undo-force-boundary))
6650           (gnus-update-read-articles
6651            group (gnus-sorted-union
6652                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6653           ;; Set the current article marks.
6654           (let ((gnus-newsgroup-scored
6655                  (if (and (not gnus-save-score)
6656                           (not non-destructive))
6657                      nil
6658                    gnus-newsgroup-scored)))
6659             (save-excursion
6660               (gnus-update-marks)))
6661           ;; Do the cross-ref thing.
6662           (when gnus-use-cross-reference
6663             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6664           ;; Do not switch windows but change the buffer to work.
6665           (set-buffer gnus-group-buffer)
6666           (unless (gnus-ephemeral-group-p group)
6667             (gnus-group-update-group group)))))))
6668
6669 (defun gnus-summary-save-newsrc (&optional force)
6670   "Save the current number of read/marked articles in the dribble buffer.
6671 The dribble buffer will then be saved.
6672 If FORCE (the prefix), also save the .newsrc file(s)."
6673   (interactive "P")
6674   (gnus-summary-update-info t)
6675   (if force
6676       (gnus-save-newsrc-file)
6677     (gnus-dribble-save)))
6678
6679 (defun gnus-summary-exit (&optional temporary leave-hidden)
6680   "Exit reading current newsgroup, and then return to group selection mode.
6681 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6682   (interactive)
6683   (gnus-set-global-variables)
6684   (gnus-kill-save-kill-buffer)
6685   (gnus-async-halt-prefetch)
6686   (let* ((group gnus-newsgroup-name)
6687          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6688          (gnus-group-is-exiting-p t)
6689          (mode major-mode)
6690          (group-point nil)
6691          (buf (current-buffer)))
6692     (unless quit-config
6693       ;; Do adaptive scoring, and possibly save score files.
6694       (when gnus-newsgroup-adaptive
6695         (gnus-score-adaptive))
6696       (when gnus-use-scoring
6697         (gnus-score-save)))
6698     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6699     ;; If we have several article buffers, we kill them at exit.
6700     (unless gnus-single-article-buffer
6701       (gnus-kill-buffer gnus-original-article-buffer)
6702       (setq gnus-article-current nil))
6703     (when gnus-use-cache
6704       (gnus-cache-possibly-remove-articles)
6705       (gnus-cache-save-buffers))
6706     (gnus-async-prefetch-remove-group group)
6707     (when gnus-suppress-duplicates
6708       (gnus-dup-enter-articles))
6709     (when gnus-use-trees
6710       (gnus-tree-close group))
6711     (when gnus-use-cache
6712       (gnus-cache-write-active))
6713     ;; Remove entries for this group.
6714     (nnmail-purge-split-history (gnus-group-real-name group))
6715     ;; Make all changes in this group permanent.
6716     (unless quit-config
6717       (gnus-run-hooks 'gnus-exit-group-hook)
6718       (gnus-summary-update-info))
6719     (gnus-close-group group)
6720     ;; Make sure where we were, and go to next newsgroup.
6721     (set-buffer gnus-group-buffer)
6722     (unless quit-config
6723       (gnus-group-jump-to-group group))
6724     (gnus-run-hooks 'gnus-summary-exit-hook)
6725     (unless (or quit-config
6726                 ;; If this group has disappeared from the summary
6727                 ;; buffer, don't skip forwards.
6728                 (not (string= group (gnus-group-group-name))))
6729       (gnus-group-next-unread-group 1))
6730     (setq group-point (point))
6731     (if temporary
6732         nil                             ;Nothing to do.
6733       ;; If we have several article buffers, we kill them at exit.
6734       (unless gnus-single-article-buffer
6735         (gnus-kill-buffer gnus-article-buffer)
6736         (gnus-kill-buffer gnus-original-article-buffer)
6737         (setq gnus-article-current nil))
6738       (set-buffer buf)
6739       (if (not gnus-kill-summary-on-exit)
6740           (progn
6741             (gnus-deaden-summary)
6742             (setq mode nil))
6743         ;; We set all buffer-local variables to nil.  It is unclear why
6744         ;; this is needed, but if we don't, buffer-local variables are
6745         ;; not garbage-collected, it seems.  This would the lead to en
6746         ;; ever-growing Emacs.
6747         (gnus-summary-clear-local-variables)
6748         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6749           (gnus-summary-clear-local-variables))
6750         (when (get-buffer gnus-article-buffer)
6751           (bury-buffer gnus-article-buffer))
6752         ;; Return to group mode buffer.
6753         (when (eq mode 'gnus-summary-mode)
6754           (gnus-kill-buffer buf)))
6755       (setq gnus-current-select-method gnus-select-method)
6756       (set-buffer gnus-group-buffer)
6757       (if quit-config
6758           (gnus-handle-ephemeral-exit quit-config)
6759         (goto-char group-point)
6760         ;; If gnus-group-buffer is already displayed, make sure we also move
6761         ;; the cursor in the window that displays it.
6762         (let ((win (get-buffer-window (current-buffer) 0)))
6763           (if win (set-window-point win (point))))
6764         (unless leave-hidden
6765           (gnus-configure-windows 'group 'force))
6766         (unless (pos-visible-in-window-p)
6767           (forward-line (/ (static-if (featurep 'xemacs)
6768                                (window-displayed-height)
6769                              (1- (window-height)))
6770                            -2))
6771           (set-window-start (selected-window) (point))
6772           (goto-char group-point)))
6773       ;; Clear the current group name.
6774       (unless quit-config
6775         (setq gnus-newsgroup-name nil)))))
6776
6777 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6778 (defun gnus-summary-exit-no-update (&optional no-questions)
6779   "Quit reading current newsgroup without updating read article info."
6780   (interactive)
6781   (let* ((group gnus-newsgroup-name)
6782          (gnus-group-is-exiting-p t)
6783          (gnus-group-is-exiting-without-update-p t)
6784          (quit-config (gnus-group-quit-config group)))
6785     (when (or no-questions
6786               gnus-expert-user
6787               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6788       (gnus-async-halt-prefetch)
6789       (run-hooks 'gnus-summary-prepare-exit-hook)
6790       ;; If we have several article buffers, we kill them at exit.
6791       (unless gnus-single-article-buffer
6792         (gnus-kill-buffer gnus-article-buffer)
6793         (gnus-kill-buffer gnus-original-article-buffer)
6794         (setq gnus-article-current nil))
6795       (if (not gnus-kill-summary-on-exit)
6796           (gnus-deaden-summary)
6797         (gnus-close-group group)
6798         (gnus-summary-clear-local-variables)
6799         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6800           (gnus-summary-clear-local-variables))
6801         (gnus-kill-buffer gnus-summary-buffer))
6802       (unless gnus-single-article-buffer
6803         (setq gnus-article-current nil))
6804       (when gnus-use-trees
6805         (gnus-tree-close group))
6806       (gnus-async-prefetch-remove-group group)
6807       (when (get-buffer gnus-article-buffer)
6808         (bury-buffer gnus-article-buffer))
6809       ;; Return to the group buffer.
6810       (gnus-configure-windows 'group 'force)
6811       ;; Clear the current group name.
6812       (setq gnus-newsgroup-name nil)
6813       (unless (gnus-ephemeral-group-p group)
6814         (gnus-group-update-group group))
6815       (when (equal (gnus-group-group-name) group)
6816         (gnus-group-next-unread-group 1))
6817       (when quit-config
6818         (gnus-handle-ephemeral-exit quit-config)))))
6819
6820 (defun gnus-handle-ephemeral-exit (quit-config)
6821   "Handle movement when leaving an ephemeral group.
6822 The state which existed when entering the ephemeral is reset."
6823   (if (not (buffer-name (car quit-config)))
6824       (gnus-configure-windows 'group 'force)
6825     (set-buffer (car quit-config))
6826     (cond ((eq major-mode 'gnus-summary-mode)
6827            (gnus-set-global-variables))
6828           ((eq major-mode 'gnus-article-mode)
6829            (save-excursion
6830              ;; The `gnus-summary-buffer' variable may point
6831              ;; to the old summary buffer when using a single
6832              ;; article buffer.
6833              (unless (gnus-buffer-live-p gnus-summary-buffer)
6834                (set-buffer gnus-group-buffer))
6835              (set-buffer gnus-summary-buffer)
6836              (gnus-set-global-variables))))
6837     (if (or (eq (cdr quit-config) 'article)
6838             (eq (cdr quit-config) 'pick))
6839         (progn
6840           ;; The current article may be from the ephemeral group
6841           ;; thus it is best that we reload this article
6842           ;;
6843           ;; If we're exiting from a large digest, this can be
6844           ;; extremely slow.  So, it's better not to reload it. -- jh.
6845           ;;(gnus-summary-show-article)
6846           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6847               (gnus-configure-windows 'pick 'force)
6848             (gnus-configure-windows (cdr quit-config) 'force)))
6849       (gnus-configure-windows (cdr quit-config) 'force))
6850     (when (eq major-mode 'gnus-summary-mode)
6851       (gnus-summary-next-subject 1 nil t)
6852       (gnus-summary-recenter)
6853       (gnus-summary-position-point))))
6854
6855 (defun gnus-summary-preview-mime-message ()
6856   "MIME decode and play this message."
6857   (interactive)
6858   (let ((gnus-break-pages nil)
6859         (gnus-show-mime t))
6860     (gnus-summary-select-article gnus-show-all-headers t))
6861   (let ((w (get-buffer-window gnus-article-buffer)))
6862     (when w
6863       (select-window (get-buffer-window gnus-article-buffer)))))
6864
6865 ;;; Dead summaries.
6866
6867 (defvar gnus-dead-summary-mode-map nil)
6868
6869 (unless gnus-dead-summary-mode-map
6870   (setq gnus-dead-summary-mode-map (make-keymap))
6871   (suppress-keymap gnus-dead-summary-mode-map)
6872   (substitute-key-definition
6873    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6874   (dolist (key '("\C-d" "\r" "\177" [delete]))
6875     (define-key gnus-dead-summary-mode-map
6876       key 'gnus-summary-wake-up-the-dead))
6877   (dolist (key '("q" "Q"))
6878     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6879
6880 (defvar gnus-dead-summary-mode nil
6881   "Minor mode for Gnus summary buffers.")
6882
6883 (defun gnus-dead-summary-mode (&optional arg)
6884   "Minor mode for Gnus summary buffers."
6885   (interactive "P")
6886   (when (eq major-mode 'gnus-summary-mode)
6887     (make-local-variable 'gnus-dead-summary-mode)
6888     (setq gnus-dead-summary-mode
6889           (if (null arg) (not gnus-dead-summary-mode)
6890             (> (prefix-numeric-value arg) 0)))
6891     (when gnus-dead-summary-mode
6892       (add-minor-mode
6893        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6894
6895 (defun gnus-deaden-summary ()
6896   "Make the current summary buffer into a dead summary buffer."
6897   ;; Kill any previous dead summary buffer.
6898   (when (and gnus-dead-summary
6899              (buffer-name gnus-dead-summary))
6900     (with-current-buffer gnus-dead-summary
6901       (when gnus-dead-summary-mode
6902         (kill-buffer (current-buffer)))))
6903   ;; Make this the current dead summary.
6904   (setq gnus-dead-summary (current-buffer))
6905   (gnus-dead-summary-mode 1)
6906   (let ((name (buffer-name)))
6907     (when (string-match "Summary" name)
6908       (rename-buffer
6909        (concat (substring name 0 (match-beginning 0)) "Dead "
6910                (substring name (match-beginning 0)))
6911        t)
6912       (bury-buffer))))
6913
6914 (defun gnus-kill-or-deaden-summary (buffer)
6915   "Kill or deaden the summary BUFFER."
6916   (save-excursion
6917     (when (and (buffer-name buffer)
6918                (not gnus-single-article-buffer))
6919       (with-current-buffer buffer
6920         (gnus-kill-buffer gnus-article-buffer)
6921         (gnus-kill-buffer gnus-original-article-buffer)))
6922     (cond
6923      ;; Kill the buffer.
6924      (gnus-kill-summary-on-exit
6925       (when (and gnus-use-trees
6926                  (gnus-buffer-exists-p buffer))
6927         (save-excursion
6928           (set-buffer buffer)
6929           (gnus-tree-close gnus-newsgroup-name)))
6930       (gnus-kill-buffer buffer))
6931      ;; Deaden the buffer.
6932      ((gnus-buffer-exists-p buffer)
6933       (save-excursion
6934         (set-buffer buffer)
6935         (gnus-deaden-summary))))))
6936
6937 (defun gnus-summary-wake-up-the-dead (&rest args)
6938   "Wake up the dead summary buffer."
6939   (interactive)
6940   (gnus-dead-summary-mode -1)
6941   (let ((name (buffer-name)))
6942     (when (string-match "Dead " name)
6943       (rename-buffer
6944        (concat (substring name 0 (match-beginning 0))
6945                (substring name (match-end 0)))
6946        t)))
6947   (gnus-message 3 "This dead summary is now alive again"))
6948
6949 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6950 (defun gnus-summary-fetch-faq (&optional faq-dir)
6951   "Fetch the FAQ for the current group.
6952 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6953 in."
6954   (interactive
6955    (list
6956     (when current-prefix-arg
6957       (completing-read
6958        "FAQ dir: " (and (listp gnus-group-faq-directory)
6959                         (mapcar 'list
6960                                 gnus-group-faq-directory))))))
6961   (let (gnus-faq-buffer)
6962     (when (setq gnus-faq-buffer
6963                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6964       (gnus-configure-windows 'summary-faq))))
6965
6966 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6967 (defun gnus-summary-describe-group (&optional force)
6968   "Describe the current newsgroup."
6969   (interactive "P")
6970   (gnus-group-describe-group force gnus-newsgroup-name))
6971
6972 (defun gnus-summary-describe-briefly ()
6973   "Describe summary mode commands briefly."
6974   (interactive)
6975   (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")))
6976
6977 ;; Walking around group mode buffer from summary mode.
6978
6979 (defun gnus-summary-next-group (&optional no-article target-group backward)
6980   "Exit current newsgroup and then select next unread newsgroup.
6981 If prefix argument NO-ARTICLE is non-nil, no article is selected
6982 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6983 previous group instead."
6984   (interactive "P")
6985   ;; Stop pre-fetching.
6986   (gnus-async-halt-prefetch)
6987   (let ((current-group gnus-newsgroup-name)
6988         (current-buffer (current-buffer))
6989         entered)
6990     ;; First we semi-exit this group to update Xrefs and all variables.
6991     ;; We can't do a real exit, because the window conf must remain
6992     ;; the same in case the user is prompted for info, and we don't
6993     ;; want the window conf to change before that...
6994     (gnus-summary-exit t)
6995     (while (not entered)
6996       ;; Then we find what group we are supposed to enter.
6997       (set-buffer gnus-group-buffer)
6998       (gnus-group-jump-to-group current-group)
6999       (setq target-group
7000             (or target-group
7001                 (if (eq gnus-keep-same-level 'best)
7002                     (gnus-summary-best-group gnus-newsgroup-name)
7003                   (gnus-summary-search-group backward gnus-keep-same-level))))
7004       (if (not target-group)
7005           ;; There are no further groups, so we return to the group
7006           ;; buffer.
7007           (progn
7008             (gnus-message 5 "Returning to the group buffer")
7009             (setq entered t)
7010             (when (gnus-buffer-live-p current-buffer)
7011               (set-buffer current-buffer)
7012               (gnus-summary-exit))
7013             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7014         ;; We try to enter the target group.
7015         (gnus-group-jump-to-group target-group)
7016         (let ((unreads (gnus-group-group-unread)))
7017           (if (and (or (eq t unreads)
7018                        (and unreads (not (zerop unreads))))
7019                    (gnus-summary-read-group
7020                     target-group nil no-article
7021                     (and (buffer-name current-buffer) current-buffer)
7022                     nil backward))
7023               (setq entered t)
7024             (setq current-group target-group
7025                   target-group nil)))))))
7026
7027 (defun gnus-summary-prev-group (&optional no-article)
7028   "Exit current newsgroup and then select previous unread newsgroup.
7029 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7030   (interactive "P")
7031   (gnus-summary-next-group no-article nil t))
7032
7033 ;; Walking around summary lines.
7034
7035 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7036   "Go to the first subject satisfying any non-nil constraint.
7037 If UNREAD is non-nil, the article should be unread.
7038 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7039 If UNSEEN is non-nil, the article should be unseen.
7040 Returns the article selected or nil if there are no matching articles."
7041   (interactive "P")
7042   (cond
7043    ;; Empty summary.
7044    ((null gnus-newsgroup-data)
7045     (gnus-message 3 "No articles in the group")
7046     nil)
7047    ;; Pick the first article.
7048    ((not (or unread undownloaded unseen))
7049     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7050     (gnus-data-number (car gnus-newsgroup-data)))
7051    ;; Find the first unread article.
7052    (t
7053     (let ((data gnus-newsgroup-data))
7054       (while (and data
7055                   (let ((num (gnus-data-number (car data))))
7056                     (or (memq num gnus-newsgroup-unfetched)
7057                         (not (or (and unread
7058                                       (memq num gnus-newsgroup-unreads))
7059                                  (and undownloaded
7060                                       (memq num gnus-newsgroup-undownloaded))
7061                                  (and unseen
7062                                       (memq num gnus-newsgroup-unseen)))))))
7063         (setq data (cdr data)))
7064       (prog1
7065           (if data
7066               (progn
7067                 (goto-char (gnus-data-pos (car data)))
7068                 (gnus-data-number (car data)))
7069             (gnus-message 3 "No more%s articles"
7070                           (let* ((r (when unread " unread"))
7071                                  (d (when undownloaded " undownloaded"))
7072                                  (s (when unseen " unseen"))
7073                                  (l (delq nil (list r d s))))
7074                             (cond ((= 3 (length l))
7075                                    (concat r "," d ", or" s))
7076                                   ((= 2 (length l))
7077                                    (concat (car l) ", or" (cadr l)))
7078                                   ((= 1 (length l))
7079                                    (car l))
7080                                   (t
7081                                    ""))))
7082             nil
7083             )
7084         (gnus-summary-position-point))))))
7085
7086 (defun gnus-summary-next-subject (n &optional unread dont-display)
7087   "Go to next N'th summary line.
7088 If N is negative, go to the previous N'th subject line.
7089 If UNREAD is non-nil, only unread articles are selected.
7090 The difference between N and the actual number of steps taken is
7091 returned."
7092   (interactive "p")
7093   (let ((backward (< n 0))
7094         (n (abs n)))
7095     (while (and (> n 0)
7096                 (if backward
7097                     (gnus-summary-find-prev unread)
7098                   (gnus-summary-find-next unread)))
7099       (unless (zerop (setq n (1- n)))
7100         (gnus-summary-show-thread)))
7101     (when (/= 0 n)
7102       (gnus-message 7 "No more%s articles"
7103                     (if unread " unread" "")))
7104     (unless dont-display
7105       (gnus-summary-recenter)
7106       (gnus-summary-position-point))
7107     n))
7108
7109 (defun gnus-summary-next-unread-subject (n)
7110   "Go to next N'th unread summary line."
7111   (interactive "p")
7112   (gnus-summary-next-subject n t))
7113
7114 (defun gnus-summary-prev-subject (n &optional unread)
7115   "Go to previous N'th summary line.
7116 If optional argument UNREAD is non-nil, only unread article is selected."
7117   (interactive "p")
7118   (gnus-summary-next-subject (- n) unread))
7119
7120 (defun gnus-summary-prev-unread-subject (n)
7121   "Go to previous N'th unread summary line."
7122   (interactive "p")
7123   (gnus-summary-next-subject (- n) t))
7124
7125 (defun gnus-summary-goto-subjects (articles)
7126   "Insert the subject header for ARTICLES in the current buffer."
7127   (save-excursion
7128     (dolist (article articles)
7129       (gnus-summary-goto-subject article t)))
7130   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7131   (gnus-summary-position-point))
7132
7133 (defun gnus-summary-goto-subject (article &optional force silent)
7134   "Go the subject line of ARTICLE.
7135 If FORCE, also allow jumping to articles not currently shown."
7136   (interactive "nArticle number: ")
7137   (unless (numberp article)
7138     (error "Article %s is not a number" article))
7139   (let ((b (point))
7140         (data (gnus-data-find article)))
7141     ;; We read in the article if we have to.
7142     (and (not data)
7143          force
7144          (gnus-summary-insert-subject
7145           article
7146           (if (or (numberp force) (vectorp force)) force)
7147           t)
7148          (setq data (gnus-data-find article)))
7149     (goto-char b)
7150     (if (not data)
7151         (progn
7152           (unless silent
7153             (gnus-message 3 "Can't find article %d" article))
7154           nil)
7155       (let ((pt (gnus-data-pos data)))
7156         (goto-char pt)
7157         (gnus-summary-set-article-display-arrow pt))
7158       (gnus-summary-position-point)
7159       article)))
7160
7161 ;; Walking around summary lines with displaying articles.
7162
7163 (defun gnus-summary-expand-window (&optional arg)
7164   "Make the summary buffer take up the entire Emacs frame.
7165 Given a prefix, will force an `article' buffer configuration."
7166   (interactive "P")
7167   (if arg
7168       (gnus-configure-windows 'article 'force)
7169     (gnus-configure-windows 'summary 'force)))
7170
7171 (defun gnus-summary-display-article (article &optional all-header)
7172   "Display ARTICLE in article buffer."
7173   (when (gnus-buffer-live-p gnus-article-buffer)
7174     (with-current-buffer gnus-article-buffer
7175       (set-buffer-multibyte t)))
7176   (gnus-set-global-variables)
7177   (when (gnus-buffer-live-p gnus-article-buffer)
7178     (with-current-buffer gnus-article-buffer
7179       (setq gnus-article-charset gnus-newsgroup-charset)
7180       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7181       (set-buffer-multibyte t)))
7182   (if (null article)
7183       nil
7184     (prog1
7185         (if gnus-summary-display-article-function
7186             (funcall gnus-summary-display-article-function article all-header)
7187           (gnus-article-prepare article all-header))
7188       (with-current-buffer gnus-article-buffer
7189         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7190              nil))
7191       (gnus-run-hooks 'gnus-select-article-hook)
7192       (when (and gnus-current-article
7193                  (not (zerop gnus-current-article)))
7194         (gnus-summary-goto-subject gnus-current-article))
7195       (gnus-summary-recenter)
7196       (when (and gnus-use-trees gnus-show-threads)
7197         (gnus-possibly-generate-tree article)
7198         (gnus-highlight-selected-tree article))
7199       ;; Successfully display article.
7200       (gnus-article-set-window-start
7201        (cdr (assq article gnus-newsgroup-bookmarks))))))
7202
7203 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7204   "Select the current article.
7205 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7206 non-nil, the article will be re-fetched even if it already present in
7207 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7208 be displayed."
7209   ;; Make sure we are in the summary buffer to work around bbdb bug.
7210   (unless (eq major-mode 'gnus-summary-mode)
7211     (set-buffer gnus-summary-buffer))
7212   (let ((article (or article (gnus-summary-article-number)))
7213         (all-headers (not (not all-headers))) ;Must be T or NIL.
7214         gnus-summary-display-article-function)
7215     (and (not pseudo)
7216          (gnus-summary-article-pseudo-p article)
7217          (error "This is a pseudo-article"))
7218     (save-excursion
7219       (set-buffer gnus-summary-buffer)
7220       (if (or (and gnus-single-article-buffer
7221                    (or (null gnus-current-article)
7222                        (null gnus-article-current)
7223                        (null (get-buffer gnus-article-buffer))
7224                        (not (eq article (cdr gnus-article-current)))
7225                        (not (equal (car gnus-article-current)
7226                                    gnus-newsgroup-name))))
7227               (and (not gnus-single-article-buffer)
7228                    (or (null gnus-current-article)
7229                        (not (eq gnus-current-article article))))
7230               force)
7231           ;; The requested article is different from the current article.
7232           (progn
7233             (gnus-summary-display-article article all-headers)
7234             (gnus-article-set-window-start
7235              (cdr (assq article gnus-newsgroup-bookmarks)))
7236             article)
7237         'old))))
7238
7239 (defun gnus-summary-force-verify-and-decrypt ()
7240   "Display buttons for signed/encrypted parts and verify/decrypt them."
7241   (interactive)
7242   (let ((mm-verify-option 'known)
7243         (mm-decrypt-option 'known)
7244         (gnus-article-emulate-mime t)
7245         (gnus-buttonized-mime-types (append (list "multipart/signed"
7246                                                   "multipart/encrypted")
7247                                             gnus-buttonized-mime-types)))
7248     (gnus-summary-select-article nil 'force)))
7249
7250 (defun gnus-summary-set-current-mark (&optional current-mark)
7251   "Obsolete function."
7252   nil)
7253
7254 (defun gnus-summary-next-article (&optional unread subject backward push)
7255   "Select the next article.
7256 If UNREAD, only unread articles are selected.
7257 If SUBJECT, only articles with SUBJECT are selected.
7258 If BACKWARD, the previous article is selected instead of the next."
7259   (interactive "P")
7260   (cond
7261    ;; Is there such an article?
7262    ((and (gnus-summary-search-forward unread subject backward)
7263          (or (gnus-summary-display-article (gnus-summary-article-number))
7264              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7265     (gnus-summary-position-point))
7266    ;; If not, we try the first unread, if that is wanted.
7267    ((and subject
7268          gnus-auto-select-same
7269          (gnus-summary-first-unread-article))
7270     (gnus-summary-position-point)
7271     (gnus-message 6 "Wrapped"))
7272    ;; Try to get next/previous article not displayed in this group.
7273    ((and gnus-auto-extend-newsgroup
7274          (not unread) (not subject))
7275     (gnus-summary-goto-article
7276      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7277      nil (count-lines (point-min) (point))))
7278    ;; Go to next/previous group.
7279    (t
7280     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7281       (gnus-summary-jump-to-group gnus-newsgroup-name))
7282     (let ((cmd last-command-char)
7283           (point
7284            (with-current-buffer gnus-group-buffer
7285              (point)))
7286           (group
7287            (if (eq gnus-keep-same-level 'best)
7288                (gnus-summary-best-group gnus-newsgroup-name)
7289              (gnus-summary-search-group backward gnus-keep-same-level))))
7290       ;; For some reason, the group window gets selected.  We change
7291       ;; it back.
7292       (select-window (get-buffer-window (current-buffer)))
7293       ;; Select next unread newsgroup automagically.
7294       (cond
7295        ((or (not gnus-auto-select-next)
7296             (not cmd))
7297         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7298        ((or (eq gnus-auto-select-next 'quietly)
7299             (and (eq gnus-auto-select-next 'slightly-quietly)
7300                  push)
7301             (and (eq gnus-auto-select-next 'almost-quietly)
7302                  (gnus-summary-last-article-p)))
7303         ;; Select quietly.
7304         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7305             (gnus-summary-exit)
7306           (gnus-message 7 "No more%s articles (%s)..."
7307                         (if unread " unread" "")
7308                         (if group (concat "selecting " group)
7309                           "exiting"))
7310           (gnus-summary-next-group nil group backward)))
7311        (t
7312         (when (gnus-key-press-event-p last-input-event)
7313           (gnus-summary-walk-group-buffer
7314            gnus-newsgroup-name cmd unread backward point))))))))
7315
7316 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7317   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7318                       (?\C-p (gnus-group-prev-unread-group 1))))
7319         (cursor-in-echo-area t)
7320         keve key group ended prompt)
7321     (save-excursion
7322       (set-buffer gnus-group-buffer)
7323       (goto-char start)
7324       (setq group
7325             (if (eq gnus-keep-same-level 'best)
7326                 (gnus-summary-best-group gnus-newsgroup-name)
7327               (gnus-summary-search-group backward gnus-keep-same-level))))
7328     (while (not ended)
7329       (setq prompt
7330             (format
7331              "No more%s articles%s " (if unread " unread" "")
7332              (if (and group
7333                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7334                  (format " (Type %s for %s [%s])"
7335                          (single-key-description cmd)
7336                          (gnus-group-decoded-name group)
7337                          (gnus-group-unread group))
7338                (format " (Type %s to exit %s)"
7339                        (single-key-description cmd)
7340                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7341       ;; Confirm auto selection.
7342       (setq key (car (setq keve (gnus-read-event-char prompt)))
7343             ended t)
7344       (cond
7345        ((assq key keystrokes)
7346         (let ((obuf (current-buffer)))
7347           (switch-to-buffer gnus-group-buffer)
7348           (when group
7349             (gnus-group-jump-to-group group))
7350           (eval (cadr (assq key keystrokes)))
7351           (setq group (gnus-group-group-name))
7352           (switch-to-buffer obuf))
7353         (setq ended nil))
7354        ((equal key cmd)
7355         (if (or (not group)
7356                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7357             (gnus-summary-exit)
7358           (gnus-summary-next-group nil group backward)))
7359        (t
7360         (push (cdr keve) unread-command-events))))))
7361
7362 (defun gnus-summary-next-unread-article ()
7363   "Select unread article after current one."
7364   (interactive)
7365   (gnus-summary-next-article
7366    (or (not (eq gnus-summary-goto-unread 'never))
7367        (gnus-summary-last-article-p (gnus-summary-article-number)))
7368    (and gnus-auto-select-same
7369         (gnus-summary-article-subject))))
7370
7371 (defun gnus-summary-prev-article (&optional unread subject)
7372   "Select the article after the current one.
7373 If UNREAD is non-nil, only unread articles are selected."
7374   (interactive "P")
7375   (gnus-summary-next-article unread subject t))
7376
7377 (defun gnus-summary-prev-unread-article ()
7378   "Select unread article before current one."
7379   (interactive)
7380   (gnus-summary-prev-article
7381    (or (not (eq gnus-summary-goto-unread 'never))
7382        (gnus-summary-first-article-p (gnus-summary-article-number)))
7383    (and gnus-auto-select-same
7384         (gnus-summary-article-subject))))
7385
7386 (defun gnus-summary-next-page (&optional lines circular stop)
7387   "Show next page of the selected article.
7388 If at the end of the current article, select the next article.
7389 LINES says how many lines should be scrolled up.
7390
7391 If CIRCULAR is non-nil, go to the start of the article instead of
7392 selecting the next article when reaching the end of the current
7393 article.
7394
7395 If STOP is non-nil, just stop when reaching the end of the message.
7396
7397 Also see the variable `gnus-article-skip-boring'."
7398   (interactive "P")
7399   (setq gnus-summary-buffer (current-buffer))
7400   (gnus-set-global-variables)
7401   (let ((article (gnus-summary-article-number))
7402         (article-window (get-buffer-window gnus-article-buffer t))
7403         endp)
7404     ;; If the buffer is empty, we have no article.
7405     (unless article
7406       (error "No article to select"))
7407     (gnus-configure-windows 'article)
7408     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7409         (if (and (eq gnus-summary-goto-unread 'never)
7410                  (not (gnus-summary-last-article-p article)))
7411             (gnus-summary-next-article)
7412           (gnus-summary-next-unread-article))
7413       (if (or (null gnus-current-article)
7414               (null gnus-article-current)
7415               (/= article (cdr gnus-article-current))
7416               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7417           ;; Selected subject is different from current article's.
7418           (gnus-summary-display-article article)
7419         (when article-window
7420           (gnus-eval-in-buffer-window gnus-article-buffer
7421             (setq endp (or (gnus-article-next-page lines)
7422                            (gnus-article-only-boring-p))))
7423           (when endp
7424             (cond (stop
7425                    (gnus-message 3 "End of message"))
7426                   (circular
7427                    (gnus-summary-beginning-of-article))
7428                   (lines
7429                    (gnus-message 3 "End of message"))
7430                   ((null lines)
7431                    (if (and (eq gnus-summary-goto-unread 'never)
7432                             (not (gnus-summary-last-article-p article)))
7433                        (gnus-summary-next-article)
7434                      (gnus-summary-next-unread-article))))))))
7435     (gnus-summary-recenter)
7436     (gnus-summary-position-point)))
7437
7438 (defun gnus-summary-prev-page (&optional lines move)
7439   "Show previous page of selected article.
7440 Argument LINES specifies lines to be scrolled down.
7441 If MOVE, move to the previous unread article if point is at
7442 the beginning of the buffer."
7443   (interactive "P")
7444   (let ((article (gnus-summary-article-number))
7445         (article-window (get-buffer-window gnus-article-buffer t))
7446         endp)
7447     (gnus-configure-windows 'article)
7448     (if (or (null gnus-current-article)
7449             (null gnus-article-current)
7450             (/= article (cdr gnus-article-current))
7451             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7452         ;; Selected subject is different from current article's.
7453         (gnus-summary-display-article article)
7454       (gnus-summary-recenter)
7455       (when article-window
7456         (gnus-eval-in-buffer-window gnus-article-buffer
7457           (setq endp (gnus-article-prev-page lines)))
7458         (when (and move endp)
7459           (cond (lines
7460                  (gnus-message 3 "Beginning of message"))
7461                 ((null lines)
7462                  (if (and (eq gnus-summary-goto-unread 'never)
7463                           (not (gnus-summary-first-article-p article)))
7464                      (gnus-summary-prev-article)
7465                    (gnus-summary-prev-unread-article))))))))
7466   (gnus-summary-position-point))
7467
7468 (defun gnus-summary-prev-page-or-article (&optional lines)
7469   "Show previous page of selected article.
7470 Argument LINES specifies lines to be scrolled down.
7471 If at the beginning of the article, go to the next article."
7472   (interactive "P")
7473   (gnus-summary-prev-page lines t))
7474
7475 (defun gnus-summary-scroll-up (lines)
7476   "Scroll up (or down) one line current article.
7477 Argument LINES specifies lines to be scrolled up (or down if negative)."
7478   (interactive "p")
7479   (gnus-configure-windows 'article)
7480   (gnus-summary-show-thread)
7481   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7482     (gnus-eval-in-buffer-window gnus-article-buffer
7483       (cond ((> lines 0)
7484              (when (gnus-article-next-page lines)
7485                (gnus-message 3 "End of message")))
7486             ((< lines 0)
7487              (gnus-article-prev-page (- lines))))))
7488   (gnus-summary-recenter)
7489   (gnus-summary-position-point))
7490
7491 (defun gnus-summary-scroll-down (lines)
7492   "Scroll down (or up) one line current article.
7493 Argument LINES specifies lines to be scrolled down (or up if negative)."
7494   (interactive "p")
7495   (gnus-summary-scroll-up (- lines)))
7496
7497 (defun gnus-summary-next-same-subject ()
7498   "Select next article which has the same subject as current one."
7499   (interactive)
7500   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7501
7502 (defun gnus-summary-prev-same-subject ()
7503   "Select previous article which has the same subject as current one."
7504   (interactive)
7505   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7506
7507 (defun gnus-summary-next-unread-same-subject ()
7508   "Select next unread article which has the same subject as current one."
7509   (interactive)
7510   (gnus-summary-next-article t (gnus-summary-article-subject)))
7511
7512 (defun gnus-summary-prev-unread-same-subject ()
7513   "Select previous unread article which has the same subject as current one."
7514   (interactive)
7515   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7516
7517 (defun gnus-summary-first-unread-article ()
7518   "Select the first unread article.
7519 Return nil if there are no unread articles."
7520   (interactive)
7521   (prog1
7522       (when (gnus-summary-first-subject t)
7523         (gnus-summary-show-thread)
7524         (gnus-summary-first-subject t)
7525         (gnus-summary-display-article (gnus-summary-article-number)))
7526     (gnus-summary-position-point)))
7527
7528 (defun gnus-summary-first-unread-subject ()
7529   "Place the point on the subject line of the first unread article.
7530 Return nil if there are no unread articles."
7531   (interactive)
7532   (prog1
7533       (when (gnus-summary-first-subject t)
7534         (gnus-summary-show-thread)
7535         (gnus-summary-first-subject t))
7536     (gnus-summary-position-point)))
7537
7538 (defun gnus-summary-first-unseen-subject ()
7539   "Place the point on the subject line of the first unseen article.
7540 Return nil if there are no unseen articles."
7541   (interactive)
7542   (prog1
7543       (when (gnus-summary-first-subject nil nil t)
7544         (gnus-summary-show-thread)
7545         (gnus-summary-first-subject nil nil t))
7546     (gnus-summary-position-point)))
7547
7548 (defun gnus-summary-first-unseen-or-unread-subject ()
7549   "Place the point on the subject line of the first unseen article or,
7550 if all article have been seen, on the subject line of the first unread
7551 article."
7552   (interactive)
7553   (prog1
7554       (unless (when (gnus-summary-first-subject nil nil t)
7555                 (gnus-summary-show-thread)
7556                 (gnus-summary-first-subject nil nil t))
7557         (when (gnus-summary-first-subject t)
7558           (gnus-summary-show-thread)
7559           (gnus-summary-first-subject t)))
7560     (gnus-summary-position-point)))
7561
7562 (defun gnus-summary-first-article ()
7563   "Select the first article.
7564 Return nil if there are no articles."
7565   (interactive)
7566   (prog1
7567       (when (gnus-summary-first-subject)
7568         (gnus-summary-show-thread)
7569         (gnus-summary-first-subject)
7570         (gnus-summary-display-article (gnus-summary-article-number)))
7571     (gnus-summary-position-point)))
7572
7573 (defun gnus-summary-best-unread-article (&optional arg)
7574   "Select the unread article with the highest score.
7575 If given a prefix argument, select the next unread article that has a
7576 score higher than the default score."
7577   (interactive "P")
7578   (let ((article (if arg
7579                      (gnus-summary-better-unread-subject)
7580                    (gnus-summary-best-unread-subject))))
7581     (if article
7582         (gnus-summary-goto-article article)
7583       (error "No unread articles"))))
7584
7585 (defun gnus-summary-best-unread-subject ()
7586   "Select the unread subject with the highest score."
7587   (interactive)
7588   (let ((best -1000000)
7589         (data gnus-newsgroup-data)
7590         article score)
7591     (while data
7592       (and (gnus-data-unread-p (car data))
7593            (> (setq score
7594                     (gnus-summary-article-score (gnus-data-number (car data))))
7595               best)
7596            (setq best score
7597                  article (gnus-data-number (car data))))
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-better-unread-subject ()
7605   "Select the first unread subject that has a score over the default score."
7606   (interactive)
7607   (let ((data gnus-newsgroup-data)
7608         article score)
7609     (while (and (setq article (gnus-data-number (car data)))
7610                 (or (gnus-data-read-p (car data))
7611                     (not (> (gnus-summary-article-score article)
7612                             gnus-summary-default-score))))
7613       (setq data (cdr data)))
7614     (when article
7615       (gnus-summary-goto-subject article))
7616     (gnus-summary-position-point)
7617     article))
7618
7619 (defun gnus-summary-last-subject ()
7620   "Go to the last displayed subject line in the group."
7621   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7622     (when article
7623       (gnus-summary-goto-subject article))))
7624
7625 (defun gnus-summary-goto-article (article &optional all-headers force)
7626   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7627 If ALL-HEADERS is non-nil, no header lines are hidden.
7628 If FORCE, go to the article even if it isn't displayed.  If FORCE
7629 is a number, it is the line the article is to be displayed on."
7630   (interactive
7631    (list
7632     (completing-read
7633      "Article number or Message-ID: "
7634      (mapcar (lambda (number) (list (int-to-string number)))
7635              gnus-newsgroup-limit))
7636     current-prefix-arg
7637     t))
7638   (prog1
7639       (if (and (stringp article)
7640                (string-match "@\\|%40" article))
7641           (gnus-summary-refer-article article)
7642         (when (stringp article)
7643           (setq article (string-to-number article)))
7644         (if (gnus-summary-goto-subject article force)
7645             (gnus-summary-display-article article all-headers)
7646           (gnus-message 4 "Couldn't go to article %s" article) nil))
7647     (gnus-summary-position-point)))
7648
7649 (defun gnus-summary-goto-last-article ()
7650   "Go to the previously read article."
7651   (interactive)
7652   (prog1
7653       (when gnus-last-article
7654         (gnus-summary-goto-article gnus-last-article nil t))
7655     (gnus-summary-position-point)))
7656
7657 (defun gnus-summary-pop-article (number)
7658   "Pop one article off the history and go to the previous.
7659 NUMBER articles will be popped off."
7660   (interactive "p")
7661   (let (to)
7662     (setq gnus-newsgroup-history
7663           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7664     (if to
7665         (gnus-summary-goto-article (car to) nil t)
7666       (error "Article history empty")))
7667   (gnus-summary-position-point))
7668
7669 ;; Summary commands and functions for limiting the summary buffer.
7670
7671 (defun gnus-summary-limit-to-articles (n)
7672   "Limit the summary buffer to the next N articles.
7673 If not given a prefix, use the process marked articles instead."
7674   (interactive "P")
7675   (prog1
7676       (let ((articles (gnus-summary-work-articles n)))
7677         (setq gnus-newsgroup-processable nil)
7678         (gnus-summary-limit articles))
7679     (gnus-summary-position-point)))
7680
7681 (defun gnus-summary-pop-limit (&optional total)
7682   "Restore the previous limit.
7683 If given a prefix, remove all limits."
7684   (interactive "P")
7685   (when total
7686     (setq gnus-newsgroup-limits
7687           (list (mapcar (lambda (h) (mail-header-number h))
7688                         gnus-newsgroup-headers))))
7689   (unless gnus-newsgroup-limits
7690     (error "No limit to pop"))
7691   (prog1
7692       (gnus-summary-limit nil 'pop)
7693     (gnus-summary-position-point)))
7694
7695 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7696   "Limit the summary buffer to articles that have subjects that match a regexp.
7697 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7698   (interactive
7699    (list (read-string (if current-prefix-arg
7700                           "Exclude subject (regexp): "
7701                         "Limit to subject (regexp): "))
7702          nil current-prefix-arg))
7703   (unless header
7704     (setq header "subject"))
7705   (when (not (equal "" subject))
7706     (prog1
7707         (let ((articles (gnus-summary-find-matching
7708                          (or header "subject") subject 'all nil nil
7709                          not-matching)))
7710           (unless articles
7711             (error "Found no matches for \"%s\"" subject))
7712           (gnus-summary-limit articles))
7713       (gnus-summary-position-point))))
7714
7715 (defun gnus-summary-limit-to-author (from &optional not-matching)
7716   "Limit the summary buffer to articles that have authors that match a regexp.
7717 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7718   (interactive
7719    (list (read-string (if current-prefix-arg
7720                           "Exclude author (regexp): "
7721                         "Limit to author (regexp): "))
7722          current-prefix-arg))
7723   (gnus-summary-limit-to-subject from "from" not-matching))
7724
7725 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7726   "Limit the summary buffer to articles with the given RECIPIENT.
7727
7728 If NOT-MATCHING, exclude RECIPIENT.
7729
7730 To and Cc headers are checked.  You need to include them in
7731 `nnmail-extra-headers'."
7732   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7733   (interactive
7734    (list (read-string (format "%s recipient (regexp): "
7735                               (if current-prefix-arg "Exclude" "Limit to")))
7736          current-prefix-arg))
7737   (when (not (equal "" recipient))
7738     (prog1 (let* ((to
7739                    (if (memq 'To nnmail-extra-headers)
7740                        (gnus-summary-find-matching
7741                         (cons 'extra 'To) recipient 'all nil nil
7742                         not-matching)
7743                      (gnus-message
7744                       1 "`To' isn't present in `nnmail-extra-headers'")
7745                      (sit-for 1)
7746                      nil))
7747                   (cc
7748                    (if (memq 'Cc nnmail-extra-headers)
7749                        (gnus-summary-find-matching
7750                         (cons 'extra 'Cc) recipient 'all nil nil
7751                         not-matching)
7752                      (gnus-message
7753                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7754                      (sit-for 1)
7755                      nil))
7756                   (articles
7757                    (if not-matching
7758                        ;; We need the numbers that are in both lists:
7759                        (mapcar (lambda (a)
7760                                  (and (memq a to) a))
7761                                cc)
7762                      (nconc to cc))))
7763              (unless articles
7764                (error "Found no matches for \"%s\"" recipient))
7765              (gnus-summary-limit articles))
7766       (gnus-summary-position-point))))
7767
7768 (defun gnus-summary-limit-to-age (age &optional younger-p)
7769   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7770 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7771 articles that are younger than AGE days."
7772   (interactive
7773    (let ((younger current-prefix-arg)
7774          (days-got nil)
7775          days)
7776      (while (not days-got)
7777        (setq days (if younger
7778                       (read-string "Limit to articles younger than (in days, older when negative): ")
7779                     (read-string
7780                      "Limit to articles older than (in days, younger when negative): ")))
7781        (when (> (length days) 0)
7782          (setq days (read days)))
7783        (if (numberp days)
7784            (progn
7785              (setq days-got t)
7786              (when (< days 0)
7787                (setq younger (not younger))
7788                (setq days (* days -1))))
7789          (message "Please enter a number.")
7790          (sleep-for 1)))
7791      (list days younger)))
7792   (prog1
7793       (let ((data gnus-newsgroup-data)
7794             (cutoff (days-to-time age))
7795             articles d date is-younger)
7796         (while (setq d (pop data))
7797           (when (and (vectorp (gnus-data-header d))
7798                      (setq date (mail-header-date (gnus-data-header d))))
7799             (setq is-younger (time-less-p
7800                               (time-since (condition-case ()
7801                                               (date-to-time date)
7802                                             (error '(0 0))))
7803                               cutoff))
7804             (when (if younger-p
7805                       is-younger
7806                     (not is-younger))
7807               (push (gnus-data-number d) articles))))
7808         (gnus-summary-limit (nreverse articles)))
7809     (gnus-summary-position-point)))
7810
7811 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7812   "Limit the summary buffer to articles that match an 'extra' header."
7813   (interactive
7814    (let ((header
7815           (intern
7816            (gnus-completing-read-with-default
7817             (symbol-name (car gnus-extra-headers))
7818             (if current-prefix-arg
7819                 "Exclude extra header"
7820               "Limit extra header")
7821             (mapcar (lambda (x)
7822                       (cons (symbol-name x) x))
7823                     gnus-extra-headers)
7824             nil
7825             t))))
7826      (list header
7827            (read-string (format "%s header %s (regexp): "
7828                                 (if current-prefix-arg "Exclude" "Limit to")
7829                                 header))
7830            current-prefix-arg)))
7831   (when (not (equal "" regexp))
7832     (prog1
7833         (let ((articles (gnus-summary-find-matching
7834                          (cons 'extra header) regexp 'all nil nil
7835                          not-matching)))
7836           (unless articles
7837             (error "Found no matches for \"%s\"" regexp))
7838           (gnus-summary-limit articles))
7839       (gnus-summary-position-point))))
7840
7841 (defun gnus-summary-limit-to-display-predicate ()
7842   "Limit the summary buffer to the predicated in the `display' group parameter."
7843   (interactive)
7844   (unless gnus-newsgroup-display
7845     (error "There is no `display' group parameter"))
7846   (let (articles)
7847     (dolist (number gnus-newsgroup-articles)
7848       (when (funcall gnus-newsgroup-display)
7849         (push number articles)))
7850     (gnus-summary-limit articles))
7851   (gnus-summary-position-point))
7852
7853 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7854 (make-obsolete
7855  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7856
7857 (defun gnus-summary-limit-to-unread (&optional all)
7858   "Limit the summary buffer to articles that are not marked as read.
7859 If ALL is non-nil, limit strictly to unread articles."
7860   (interactive "P")
7861   (if all
7862       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7863     (gnus-summary-limit-to-marks
7864      ;; Concat all the marks that say that an article is read and have
7865      ;; those removed.
7866      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7867            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7868            gnus-low-score-mark gnus-expirable-mark
7869            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7870            gnus-duplicate-mark gnus-souped-mark)
7871      'reverse)))
7872
7873 (defun gnus-summary-limit-to-replied (&optional unreplied)
7874   "Limit the summary buffer to replied articles.
7875 If UNREPLIED (the prefix), limit to unreplied articles."
7876   (interactive "P")
7877   (if unreplied
7878       (gnus-summary-limit
7879        (gnus-set-difference gnus-newsgroup-articles
7880         gnus-newsgroup-replied))
7881     (gnus-summary-limit gnus-newsgroup-replied))
7882   (gnus-summary-position-point))
7883
7884 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7885 (make-obsolete 'gnus-summary-delete-marked-with
7886                'gnus-summary-limit-exclude-marks)
7887
7888 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7889   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7890 If REVERSE, limit the summary buffer to articles that are marked
7891 with MARKS.  MARKS can either be a string of marks or a list of marks.
7892 Returns how many articles were removed."
7893   (interactive "sMarks: ")
7894   (gnus-summary-limit-to-marks marks t))
7895
7896 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7897   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7898 If REVERSE (the prefix), limit the summary buffer to articles that are
7899 not marked with MARKS.  MARKS can either be a string of marks or a
7900 list of marks.
7901 Returns how many articles were removed."
7902   (interactive "sMarks: \nP")
7903   (prog1
7904       (let ((data gnus-newsgroup-data)
7905             (marks (if (listp marks) marks
7906                      (append marks nil))) ; Transform to list.
7907             articles)
7908         (while data
7909           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7910                   (memq (gnus-data-mark (car data)) marks))
7911             (push (gnus-data-number (car data)) articles))
7912           (setq data (cdr data)))
7913         (gnus-summary-limit articles))
7914     (gnus-summary-position-point)))
7915
7916 (defun gnus-summary-limit-to-score (score)
7917   "Limit to articles with score at or above SCORE."
7918   (interactive "NLimit to articles with score of at least: ")
7919   (let ((data gnus-newsgroup-data)
7920         articles)
7921     (while data
7922       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7923                 score)
7924         (push (gnus-data-number (car data)) articles))
7925       (setq data (cdr data)))
7926     (prog1
7927         (gnus-summary-limit articles)
7928       (gnus-summary-position-point))))
7929
7930 (defun gnus-summary-limit-to-unseen ()
7931   "Limit to unseen articles."
7932   (interactive)
7933   (prog1
7934       (gnus-summary-limit gnus-newsgroup-unseen)
7935     (gnus-summary-position-point)))
7936
7937 (defun gnus-summary-limit-include-thread (id)
7938   "Display all the hidden articles that is in the thread with ID in it.
7939 When called interactively, ID is the Message-ID of the current
7940 article."
7941   (interactive (list (mail-header-id (gnus-summary-article-header))))
7942   (let ((articles (gnus-articles-in-thread
7943                    (gnus-id-to-thread (gnus-root-id id)))))
7944     (prog1
7945         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7946       (gnus-summary-limit-include-matching-articles
7947        "subject"
7948        (regexp-quote (gnus-simplify-subject-re
7949                       (mail-header-subject (gnus-id-to-header id)))))
7950       (gnus-summary-position-point))))
7951
7952 (defun gnus-summary-limit-include-matching-articles (header regexp)
7953   "Display all the hidden articles that have HEADERs that match REGEXP."
7954   (interactive (list (read-string "Match on header: ")
7955                      (read-string "Regexp: ")))
7956   (let ((articles (gnus-find-matching-articles header regexp)))
7957     (prog1
7958         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7959       (gnus-summary-position-point))))
7960
7961 (defun gnus-summary-insert-dormant-articles ()
7962   "Insert all the dormant articles for this group into the current buffer."
7963   (interactive)
7964   (let ((gnus-verbose (max 6 gnus-verbose)))
7965     (if (not gnus-newsgroup-dormant)
7966         (gnus-message 3 "No cached articles for this group")
7967       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7968
7969 (defun gnus-summary-limit-include-dormant ()
7970   "Display all the hidden articles that are marked as dormant.
7971 Note that this command only works on a subset of the articles currently
7972 fetched for this group."
7973   (interactive)
7974   (unless gnus-newsgroup-dormant
7975     (error "There are no dormant articles in this group"))
7976   (prog1
7977       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7978     (gnus-summary-position-point)))
7979
7980 (defun gnus-summary-limit-exclude-dormant ()
7981   "Hide all dormant articles."
7982   (interactive)
7983   (prog1
7984       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7985     (gnus-summary-position-point)))
7986
7987 (defun gnus-summary-limit-exclude-childless-dormant ()
7988   "Hide all dormant articles that have no children."
7989   (interactive)
7990   (let ((data (gnus-data-list t))
7991         articles d children)
7992     ;; Find all articles that are either not dormant or have
7993     ;; children.
7994     (while (setq d (pop data))
7995       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7996                 (and (setq children
7997                            (gnus-article-children (gnus-data-number d)))
7998                      (let (found)
7999                        (while children
8000                          (when (memq (car children) articles)
8001                            (setq children nil
8002                                  found t))
8003                          (pop children))
8004                        found)))
8005         (push (gnus-data-number d) articles)))
8006     ;; Do the limiting.
8007     (prog1
8008         (gnus-summary-limit articles)
8009       (gnus-summary-position-point))))
8010
8011 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8012   "Mark all unread excluded articles as read.
8013 If ALL, mark even excluded ticked and dormants as read."
8014   (interactive "P")
8015   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8016   (let ((articles (gnus-sorted-ndifference
8017                    (sort
8018                     (mapcar (lambda (h) (mail-header-number h))
8019                             gnus-newsgroup-headers)
8020                     '<)
8021                    gnus-newsgroup-limit))
8022         article)
8023     (setq gnus-newsgroup-unreads
8024           (gnus-sorted-intersection gnus-newsgroup-unreads
8025                                     gnus-newsgroup-limit))
8026     (if all
8027         (setq gnus-newsgroup-dormant nil
8028               gnus-newsgroup-marked nil
8029               gnus-newsgroup-reads
8030               (nconc
8031                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8032                gnus-newsgroup-reads))
8033       (while (setq article (pop articles))
8034         (unless (or (memq article gnus-newsgroup-dormant)
8035                     (memq article gnus-newsgroup-marked))
8036           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8037
8038 (defun gnus-summary-limit (articles &optional pop)
8039   (if pop
8040       ;; We pop the previous limit off the stack and use that.
8041       (setq articles (car gnus-newsgroup-limits)
8042             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8043     ;; We use the new limit, so we push the old limit on the stack.
8044     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8045   ;; Set the limit.
8046   (setq gnus-newsgroup-limit articles)
8047   (let ((total (length gnus-newsgroup-data))
8048         (data (gnus-data-find-list (gnus-summary-article-number)))
8049         (gnus-summary-mark-below nil)   ; Inhibit this.
8050         found)
8051     ;; This will do all the work of generating the new summary buffer
8052     ;; according to the new limit.
8053     (gnus-summary-prepare)
8054     ;; Hide any threads, possibly.
8055     (gnus-summary-maybe-hide-threads)
8056     ;; Try to return to the article you were at, or one in the
8057     ;; neighborhood.
8058     (when data
8059       ;; We try to find some article after the current one.
8060       (while data
8061         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8062           (setq data nil
8063                 found t))
8064         (setq data (cdr data))))
8065     (unless found
8066       ;; If there is no data, that means that we were after the last
8067       ;; article.  The same goes when we can't find any articles
8068       ;; after the current one.
8069       (goto-char (point-max))
8070       (gnus-summary-find-prev))
8071     (gnus-set-mode-line 'summary)
8072     ;; We return how many articles were removed from the summary
8073     ;; buffer as a result of the new limit.
8074     (- total (length gnus-newsgroup-data))))
8075
8076 (defsubst gnus-invisible-cut-children (threads)
8077   (let ((num 0))
8078     (while threads
8079       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8080         (incf num))
8081       (pop threads))
8082     (< num 2)))
8083
8084 (defsubst gnus-cut-thread (thread)
8085   "Go forwards in the thread until we find an article that we want to display."
8086   (when (or (eq gnus-fetch-old-headers 'some)
8087             (eq gnus-fetch-old-headers 'invisible)
8088             (numberp gnus-fetch-old-headers)
8089             (eq gnus-build-sparse-threads 'some)
8090             (eq gnus-build-sparse-threads 'more))
8091     ;; Deal with old-fetched headers and sparse threads.
8092     (while (and
8093             thread
8094             (or
8095              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8096              (gnus-summary-article-ancient-p
8097               (mail-header-number (car thread))))
8098             (if (or (<= (length (cdr thread)) 1)
8099                     (eq gnus-fetch-old-headers 'invisible))
8100                 (setq gnus-newsgroup-limit
8101                       (delq (mail-header-number (car thread))
8102                             gnus-newsgroup-limit)
8103                       thread (cadr thread))
8104               (when (gnus-invisible-cut-children (cdr thread))
8105                 (let ((th (cdr thread)))
8106                   (while th
8107                     (if (memq (mail-header-number (caar th))
8108                               gnus-newsgroup-limit)
8109                         (setq thread (car th)
8110                               th nil)
8111                       (setq th (cdr th))))))))))
8112   thread)
8113
8114 (defun gnus-cut-threads (threads)
8115   "Cut off all uninteresting articles from the beginning of THREADS."
8116   (when (or (eq gnus-fetch-old-headers 'some)
8117             (eq gnus-fetch-old-headers 'invisible)
8118             (numberp gnus-fetch-old-headers)
8119             (eq gnus-build-sparse-threads 'some)
8120             (eq gnus-build-sparse-threads 'more))
8121     (let ((th threads))
8122       (while th
8123         (setcar th (gnus-cut-thread (car th)))
8124         (setq th (cdr th)))))
8125   ;; Remove nixed out threads.
8126   (delq nil threads))
8127
8128 (defun gnus-summary-initial-limit (&optional show-if-empty)
8129   "Figure out what the initial limit is supposed to be on group entry.
8130 This entails weeding out unwanted dormants, low-scored articles,
8131 fetch-old-headers verbiage, and so on."
8132   ;; Most groups have nothing to remove.
8133   (if (or gnus-inhibit-limiting
8134           (and (null gnus-newsgroup-dormant)
8135                (eq gnus-newsgroup-display 'gnus-not-ignore)
8136                (not (eq gnus-fetch-old-headers 'some))
8137                (not (numberp gnus-fetch-old-headers))
8138                (not (eq gnus-fetch-old-headers 'invisible))
8139                (null gnus-summary-expunge-below)
8140                (not (eq gnus-build-sparse-threads 'some))
8141                (not (eq gnus-build-sparse-threads 'more))
8142                (null gnus-thread-expunge-below)
8143                (not gnus-use-nocem)))
8144       ()                                ; Do nothing.
8145     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8146     (setq gnus-newsgroup-limit nil)
8147     (mapatoms
8148      (lambda (node)
8149        (unless (car (symbol-value node))
8150          ;; These threads have no parents -- they are roots.
8151          (let ((nodes (cdr (symbol-value node)))
8152                thread)
8153            (while nodes
8154              (if (and gnus-thread-expunge-below
8155                       (< (gnus-thread-total-score (car nodes))
8156                          gnus-thread-expunge-below))
8157                  (gnus-expunge-thread (pop nodes))
8158                (setq thread (pop nodes))
8159                (gnus-summary-limit-children thread))))))
8160      gnus-newsgroup-dependencies)
8161     ;; If this limitation resulted in an empty group, we might
8162     ;; pop the previous limit and use it instead.
8163     (when (and (not gnus-newsgroup-limit)
8164                show-if-empty)
8165       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8166     gnus-newsgroup-limit))
8167
8168 (defun gnus-summary-limit-children (thread)
8169   "Return 1 if this subthread is visible and 0 if it is not."
8170   ;; First we get the number of visible children to this thread.  This
8171   ;; is done by recursing down the thread using this function, so this
8172   ;; will really go down to a leaf article first, before slowly
8173   ;; working its way up towards the root.
8174   (when thread
8175     (let* ((max-lisp-eval-depth 5000)
8176            (children
8177            (if (cdr thread)
8178                (apply '+ (mapcar 'gnus-summary-limit-children
8179                                  (cdr thread)))
8180              0))
8181           (number (mail-header-number (car thread)))
8182           score)
8183       (if (and
8184            (not (memq number gnus-newsgroup-marked))
8185            (or
8186             ;; If this article is dormant and has absolutely no visible
8187             ;; children, then this article isn't visible.
8188             (and (memq number gnus-newsgroup-dormant)
8189                  (zerop children))
8190             ;; If this is "fetch-old-headered" and there is no
8191             ;; visible children, then we don't want this article.
8192             (and (or (eq gnus-fetch-old-headers 'some)
8193                      (numberp gnus-fetch-old-headers))
8194                  (gnus-summary-article-ancient-p number)
8195                  (zerop children))
8196             ;; If this is "fetch-old-headered" and `invisible', then
8197             ;; we don't want this article.
8198             (and (eq gnus-fetch-old-headers 'invisible)
8199                  (gnus-summary-article-ancient-p number))
8200             ;; If this is a sparsely inserted article with no children,
8201             ;; we don't want it.
8202             (and (eq gnus-build-sparse-threads 'some)
8203                  (gnus-summary-article-sparse-p number)
8204                  (zerop children))
8205             ;; If we use expunging, and this article is really
8206             ;; low-scored, then we don't want this article.
8207             (when (and gnus-summary-expunge-below
8208                        (< (setq score
8209                                 (or (cdr (assq number gnus-newsgroup-scored))
8210                                     gnus-summary-default-score))
8211                           gnus-summary-expunge-below))
8212               ;; We increase the expunge-tally here, but that has
8213               ;; nothing to do with the limits, really.
8214               (incf gnus-newsgroup-expunged-tally)
8215               ;; We also mark as read here, if that's wanted.
8216               (when (and gnus-summary-mark-below
8217                          (< score gnus-summary-mark-below))
8218                 (setq gnus-newsgroup-unreads
8219                       (delq number gnus-newsgroup-unreads))
8220                 (if gnus-newsgroup-auto-expire
8221                     (push number gnus-newsgroup-expirable)
8222                   (push (cons number gnus-low-score-mark)
8223                         gnus-newsgroup-reads)))
8224               t)
8225             ;; Do the `display' group parameter.
8226             (and gnus-newsgroup-display
8227                  (not (funcall gnus-newsgroup-display)))
8228             ;; Check NoCeM things.
8229             (when (and gnus-use-nocem
8230                        (gnus-nocem-unwanted-article-p
8231                         (mail-header-id (car thread))))
8232               (setq gnus-newsgroup-unreads
8233                     (delq number gnus-newsgroup-unreads))
8234               t)))
8235           ;; Nope, invisible article.
8236           0
8237         ;; Ok, this article is to be visible, so we add it to the limit
8238         ;; and return 1.
8239         (push number gnus-newsgroup-limit)
8240         1))))
8241
8242 (defun gnus-expunge-thread (thread)
8243   "Mark all articles in THREAD as read."
8244   (let* ((number (mail-header-number (car thread))))
8245     (incf gnus-newsgroup-expunged-tally)
8246     ;; We also mark as read here, if that's wanted.
8247     (setq gnus-newsgroup-unreads
8248           (delq number gnus-newsgroup-unreads))
8249     (if gnus-newsgroup-auto-expire
8250         (push number gnus-newsgroup-expirable)
8251       (push (cons number gnus-low-score-mark)
8252             gnus-newsgroup-reads)))
8253   ;; Go recursively through all subthreads.
8254   (mapcar 'gnus-expunge-thread (cdr thread)))
8255
8256 ;; Summary article oriented commands
8257
8258 (defun gnus-summary-refer-parent-article (n)
8259   "Refer parent article N times.
8260 If N is negative, go to ancestor -N instead.
8261 The difference between N and the number of articles fetched is returned."
8262   (interactive "p")
8263   (let ((skip 1)
8264         error header ref)
8265     (when (not (natnump n))
8266       (setq skip (abs n)
8267             n 1))
8268     (while (and (> n 0)
8269                 (not error))
8270       (setq header (gnus-summary-article-header))
8271       (if (and (eq (mail-header-number header)
8272                    (cdr gnus-article-current))
8273                (equal gnus-newsgroup-name
8274                       (car gnus-article-current)))
8275           ;; If we try to find the parent of the currently
8276           ;; displayed article, then we take a look at the actual
8277           ;; References header, since this is slightly more
8278           ;; reliable than the References field we got from the
8279           ;; server.
8280           (save-excursion
8281             (set-buffer gnus-original-article-buffer)
8282             (nnheader-narrow-to-headers)
8283             (unless (setq ref (message-fetch-field "references"))
8284               (when (setq ref (message-fetch-field "in-reply-to"))
8285                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8286             (widen))
8287         (setq ref
8288               ;; It's not the current article, so we take a bet on
8289               ;; the value we got from the server.
8290               (mail-header-references header)))
8291       (if (and ref
8292                (not (equal ref "")))
8293           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8294             (gnus-message 1 "Couldn't find parent"))
8295         (gnus-message 1 "No references in article %d"
8296                       (gnus-summary-article-number))
8297         (setq error t))
8298       (decf n))
8299     (gnus-summary-position-point)
8300     n))
8301
8302 (defun gnus-summary-refer-references ()
8303   "Fetch all articles mentioned in the References header.
8304 Return the number of articles fetched."
8305   (interactive)
8306   (let ((ref (mail-header-references (gnus-summary-article-header)))
8307         (current (gnus-summary-article-number))
8308         (n 0))
8309     (if (or (not ref)
8310             (equal ref ""))
8311         (error "No References in the current article")
8312       ;; For each Message-ID in the References header...
8313       (while (string-match "<[^>]*>" ref)
8314         (incf n)
8315         ;; ... fetch that article.
8316         (gnus-summary-refer-article
8317          (prog1 (match-string 0 ref)
8318            (setq ref (substring ref (match-end 0))))))
8319       (gnus-summary-goto-subject current)
8320       (gnus-summary-position-point)
8321       n)))
8322
8323 (defun gnus-summary-refer-thread (&optional limit)
8324   "Fetch all articles in the current thread.
8325 If LIMIT (the numerical prefix), fetch that many old headers instead
8326 of what's specified by the `gnus-refer-thread-limit' variable."
8327   (interactive "P")
8328   (let ((id (mail-header-id (gnus-summary-article-header)))
8329         (limit (if limit (prefix-numeric-value limit)
8330                  gnus-refer-thread-limit)))
8331     (unless (eq gnus-fetch-old-headers 'invisible)
8332       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8333       ;; Retrieve the headers and read them in.
8334       (if (eq (if (numberp limit)
8335                   (gnus-retrieve-headers
8336                    (list (min
8337                           (+ (mail-header-number
8338                               (gnus-summary-article-header))
8339                              limit)
8340                           gnus-newsgroup-end))
8341                    gnus-newsgroup-name (* limit 2))
8342                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8343                 ;; headers.
8344                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8345                                        gnus-newsgroup-name limit))
8346               'nov)
8347           (gnus-build-all-threads)
8348         (error "Can't fetch thread from back ends that don't support NOV"))
8349       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8350     (gnus-summary-limit-include-thread id)))
8351
8352 (defun gnus-summary-refer-article (message-id)
8353   "Fetch an article specified by MESSAGE-ID."
8354   (interactive "sMessage-ID: ")
8355   (when (and (stringp message-id)
8356              (not (zerop (length message-id))))
8357     (setq message-id (gnus-replace-in-string message-id " " ""))
8358     ;; Construct the correct Message-ID if necessary.
8359     ;; Suggested by tale@pawl.rpi.edu.
8360     (unless (string-match "^<" message-id)
8361       (setq message-id (concat "<" message-id)))
8362     (unless (string-match ">$" message-id)
8363       (setq message-id (concat message-id ">")))
8364     ;; People often post MIDs from URLs, so unhex it:
8365     (unless (string-match "@" message-id)
8366       (setq message-id (gnus-url-unhex-string message-id)))
8367     (let* ((header (gnus-id-to-header message-id))
8368            (sparse (and header
8369                         (gnus-summary-article-sparse-p
8370                          (mail-header-number header))
8371                         (memq (mail-header-number header)
8372                               gnus-newsgroup-limit)))
8373            number)
8374       (cond
8375        ;; If the article is present in the buffer we just go to it.
8376        ((and header
8377              (or (not (gnus-summary-article-sparse-p
8378                        (mail-header-number header)))
8379                  sparse))
8380         (prog1
8381             (gnus-summary-goto-article
8382              (mail-header-number header) nil t)
8383           (when sparse
8384             (gnus-summary-update-article (mail-header-number header)))))
8385        (t
8386         ;; We fetch the article.
8387         (catch 'found
8388           (dolist (gnus-override-method (gnus-refer-article-methods))
8389             (when (and (gnus-check-server gnus-override-method)
8390                        ;; Fetch the header,
8391                        (setq number (gnus-summary-insert-subject message-id)))
8392               ;; and display the article.
8393               (gnus-summary-select-article nil nil nil number)
8394               (throw 'found t)))
8395           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8396
8397 (defun gnus-refer-article-methods ()
8398   "Return a list of referable methods."
8399   (cond
8400    ;; No method, so we default to current and native.
8401    ((null gnus-refer-article-method)
8402     (list gnus-current-select-method gnus-select-method))
8403    ;; Current.
8404    ((eq 'current gnus-refer-article-method)
8405     (list gnus-current-select-method))
8406    ;; List of select methods.
8407    ((not (and (symbolp (car gnus-refer-article-method))
8408               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8409     (let (out)
8410       (dolist (method gnus-refer-article-method)
8411         (push (if (eq 'current method)
8412                   gnus-current-select-method
8413                 method)
8414               out))
8415       (nreverse out)))
8416    ;; One single select method.
8417    (t
8418     (list gnus-refer-article-method))))
8419
8420 (defun gnus-summary-edit-parameters ()
8421   "Edit the group parameters of the current group."
8422   (interactive)
8423   (gnus-group-edit-group gnus-newsgroup-name 'params))
8424
8425 (defun gnus-summary-customize-parameters ()
8426   "Customize the group parameters of the current group."
8427   (interactive)
8428   (gnus-group-customize gnus-newsgroup-name))
8429
8430 (defun gnus-summary-enter-digest-group (&optional force)
8431   "Enter an nndoc group based on the current article.
8432 If FORCE, force a digest interpretation.  If not, try
8433 to guess what the document format is."
8434   (interactive "P")
8435   (let ((conf gnus-current-window-configuration))
8436     (save-window-excursion
8437       (save-excursion
8438         (let (gnus-article-prepare-hook
8439               gnus-display-mime-function
8440               gnus-break-pages)
8441           (gnus-summary-select-article))))
8442     (setq gnus-current-window-configuration conf)
8443     (let* ((name (format "%s-%d"
8444                          (gnus-group-prefixed-name
8445                           gnus-newsgroup-name (list 'nndoc ""))
8446                          (with-current-buffer gnus-summary-buffer
8447                            gnus-current-article)))
8448            (ogroup gnus-newsgroup-name)
8449            (params (append (gnus-info-params (gnus-get-info ogroup))
8450                            (list (cons 'to-group ogroup))
8451                            (list (cons 'parent-group ogroup))
8452                            (list (cons 'save-article-group ogroup))))
8453            (case-fold-search t)
8454            (buf (current-buffer))
8455            dig to-address)
8456       (save-excursion
8457         (set-buffer gnus-original-article-buffer)
8458         ;; Have the digest group inherit the main mail address of
8459         ;; the parent article.
8460         (when (setq to-address (or (gnus-fetch-field "reply-to")
8461                                    (gnus-fetch-field "from")))
8462           (setq params (append
8463                         (list (cons 'to-address
8464                                     (funcall gnus-decode-encoded-word-function
8465                                              to-address))))))
8466         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8467         (insert-buffer-substring gnus-original-article-buffer)
8468         ;; Remove lines that may lead nndoc to misinterpret the
8469         ;; document type.
8470         (narrow-to-region
8471          (goto-char (point-min))
8472          (or (search-forward "\n\n" nil t) (point)))
8473         (goto-char (point-min))
8474         (delete-matching-lines "^Path:\\|^From ")
8475         (widen))
8476       (unwind-protect
8477           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8478                     (gnus-newsgroup-ephemeral-ignored-charsets
8479                      gnus-newsgroup-ignored-charsets))
8480                 (gnus-group-read-ephemeral-group
8481                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8482                               (nndoc-article-type
8483                                ,(if force 'mbox 'guess)))
8484                  t nil nil nil
8485                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8486                                                         "ADAPT")))))
8487               ;; Make all postings to this group go to the parent group.
8488               (nconc (gnus-info-params (gnus-get-info name))
8489                      params)
8490             ;; Couldn't select this doc group.
8491             (switch-to-buffer buf)
8492             (gnus-set-global-variables)
8493             (gnus-configure-windows 'summary)
8494             (gnus-message 3 "Article couldn't be entered?"))
8495         (kill-buffer dig)))))
8496
8497 (defun gnus-summary-read-document (n)
8498   "Open a new group based on the current article(s).
8499 This will allow you to read digests and other similar
8500 documents as newsgroups.
8501 Obeys the standard process/prefix convention."
8502   (interactive "P")
8503   (let* ((ogroup gnus-newsgroup-name)
8504          (params (append (gnus-info-params (gnus-get-info ogroup))
8505                          (list (cons 'to-group ogroup))))
8506          group egroup groups vgroup)
8507     (dolist (article (gnus-summary-work-articles n))
8508       (setq group (format "%s-%d" gnus-newsgroup-name article))
8509       (gnus-summary-remove-process-mark article)
8510       (when (gnus-summary-display-article article)
8511         (save-excursion
8512           (with-temp-buffer
8513             (insert-buffer-substring gnus-original-article-buffer)
8514             ;; Remove some headers that may lead nndoc to make
8515             ;; the wrong guess.
8516             (message-narrow-to-head)
8517             (goto-char (point-min))
8518             (delete-matching-lines "^Path:\\|^From ")
8519             (widen)
8520             (if (setq egroup
8521                       (gnus-group-read-ephemeral-group
8522                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8523                                      (nndoc-article-type guess))
8524                        t nil t))
8525                 (progn
8526                   ;; Make all postings to this group go to the parent group.
8527                   (nconc (gnus-info-params (gnus-get-info egroup))
8528                          params)
8529                   (push egroup groups))
8530               ;; Couldn't select this doc group.
8531               (gnus-error 3 "Article couldn't be entered"))))))
8532     ;; Now we have selected all the documents.
8533     (cond
8534      ((not groups)
8535       (error "None of the articles could be interpreted as documents"))
8536      ((gnus-group-read-ephemeral-group
8537        (setq vgroup (format
8538                      "nnvirtual:%s-%s" gnus-newsgroup-name
8539                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8540        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8541        t
8542        (cons (current-buffer) 'summary)))
8543      (t
8544       (error "Couldn't select virtual nndoc group")))))
8545
8546 (defun gnus-summary-isearch-article (&optional regexp-p)
8547   "Do incremental search forward on the current article.
8548 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8549   (interactive "P")
8550   (let* ((gnus-inhibit-treatment t)
8551          (old (gnus-summary-select-article)))
8552     (gnus-configure-windows 'article)
8553     (gnus-eval-in-buffer-window gnus-article-buffer
8554       (save-restriction
8555         (widen)
8556         (when (eq 'old old)
8557           (gnus-article-show-all-headers))
8558         (goto-char (point-min))
8559         (isearch-forward regexp-p)))))
8560
8561 (defun gnus-summary-search-article-forward (regexp &optional backward)
8562   "Search for an article containing REGEXP forward.
8563 If BACKWARD, search backward instead."
8564   (interactive
8565    (list (read-string
8566           (format "Search article %s (regexp%s): "
8567                   (if current-prefix-arg "backward" "forward")
8568                   (if gnus-last-search-regexp
8569                       (concat ", default " gnus-last-search-regexp)
8570                     "")))
8571          current-prefix-arg))
8572   (if (string-equal regexp "")
8573       (setq regexp (or gnus-last-search-regexp ""))
8574     (setq gnus-last-search-regexp regexp)
8575     (setq gnus-article-before-search gnus-current-article))
8576   ;; Intentionally set gnus-last-article.
8577   (setq gnus-last-article gnus-article-before-search)
8578   (let ((gnus-last-article gnus-last-article))
8579     (if (gnus-summary-search-article regexp backward)
8580         (gnus-summary-show-thread)
8581       (signal 'search-failed (list regexp)))))
8582
8583 (defun gnus-summary-search-article-backward (regexp)
8584   "Search for an article containing REGEXP backward."
8585   (interactive
8586    (list (read-string
8587           (format "Search article backward (regexp%s): "
8588                   (if gnus-last-search-regexp
8589                       (concat ", default " gnus-last-search-regexp)
8590                     "")))))
8591   (gnus-summary-search-article-forward regexp 'backward))
8592
8593 (eval-when-compile
8594   (defmacro gnus-summary-search-article-position-point (regexp backward)
8595     "Dehighlight the last matched text and goto the beginning position."
8596     (` (if (and gnus-summary-search-article-matched-data
8597                 (let ((text (caddr gnus-summary-search-article-matched-data))
8598                       (inhibit-read-only t)
8599                       buffer-read-only)
8600                   (delete-region
8601                    (goto-char (car gnus-summary-search-article-matched-data))
8602                    (cadr gnus-summary-search-article-matched-data))
8603                   (insert text)
8604                   (string-match (, regexp) text)))
8605            (if (, backward) (beginning-of-line) (end-of-line))
8606          (goto-char (if (, backward) (point-max) (point-min))))))
8607
8608   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8609     "Place point where X-Face image is displayed."
8610     (if (featurep 'xemacs)
8611         (` (let ((end (if (search-forward "\n\n" nil t)
8612                           (goto-char (1- (point)))
8613                         (point-min)))
8614                  extent)
8615              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8616              (unless (and (re-search-forward "^From:" end t)
8617                           (setq extent (extent-at (point)))
8618                           (extent-begin-glyph extent))
8619                (goto-char (, opoint)))))
8620       (` (let ((end (if (search-forward "\n\n" nil t)
8621                         (goto-char (1- (point)))
8622                       (point-min)))
8623                (start (or (search-backward "\n\n" nil t) (point-min))))
8624            (goto-char
8625             (or (text-property-any start end 'x-face-image t);; x-face-e21
8626                 (, opoint)))))))
8627
8628   (defmacro gnus-summary-search-article-highlight-matched-text
8629     (backward treated x-face)
8630     "Highlight matched text in the function `gnus-summary-search-article'."
8631     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8632              (end (set-marker (make-marker) (match-end 0)))
8633              (inhibit-read-only t)
8634              buffer-read-only)
8635          (unless treated
8636            (let ((,@
8637                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8638                     (mapcar
8639                      (lambda (item) (setq items (delq item items)))
8640                      '(gnus-treat-buttonize
8641                        gnus-treat-fill-article
8642                        gnus-treat-fill-long-lines
8643                        gnus-treat-emphasize
8644                        gnus-treat-highlight-headers
8645                        gnus-treat-highlight-citation
8646                        gnus-treat-highlight-signature
8647                        gnus-treat-overstrike
8648                        gnus-treat-display-x-face
8649                        gnus-treat-buttonize-head
8650                        gnus-treat-decode-article-as-default-mime-charset))
8651                     items))
8652                  (gnus-treat-display-x-face
8653                   (when (, x-face) gnus-treat-display-x-face)))
8654              (gnus-article-prepare-mime-display)))
8655          (goto-char (if (, backward) start end))
8656          (when (, x-face)
8657            (gnus-summary-search-article-highlight-goto-x-face (point)))
8658          (setq gnus-summary-search-article-matched-data
8659                (list start end (buffer-substring start end)))
8660          (unless (eq start end);; matched text has been deleted. :-<
8661            (put-text-property start end 'face
8662                               (or (find-face 'isearch)
8663                                   'secondary-selection))))))
8664   )
8665
8666 (defun gnus-summary-search-article (regexp &optional backward)
8667   "Search for an article containing REGEXP.
8668 Optional argument BACKWARD means do search for backward.
8669 `gnus-select-article-hook' is not called during the search."
8670   ;; We have to require this here to make sure that the following
8671   ;; dynamic binding isn't shadowed by autoloading.
8672   (require 'gnus-async)
8673   (require 'gnus-art)
8674   (let ((gnus-select-article-hook nil)  ;Disable hook.
8675         (gnus-article-prepare-hook nil)
8676         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8677         (gnus-use-article-prefetch nil)
8678         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8679         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8680         (gnus-visual nil)
8681         (gnus-keep-backlog nil)
8682         (gnus-break-pages nil)
8683         (gnus-summary-display-arrow nil)
8684         (gnus-updated-mode-lines nil)
8685         (gnus-auto-center-summary nil)
8686         (sum (current-buffer))
8687         (found nil)
8688         point treated)
8689     (gnus-save-hidden-threads
8690       (static-if (featurep 'xemacs)
8691           (let ((gnus-inhibit-treatment t))
8692             (setq treated (eq 'old (gnus-summary-select-article)))
8693             (when (and treated
8694                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8695                                  (window-live-p (get-buffer-window
8696                                                  gnus-article-buffer t)))))
8697               (gnus-summary-select-article nil t)
8698               (setq treated nil)))
8699         (let ((gnus-inhibit-treatment t))
8700           (setq treated (eq 'old (gnus-summary-select-article)))
8701           (when (and treated
8702                      (not
8703                       (and (gnus-buffer-live-p gnus-article-buffer)
8704                            (window-live-p (get-buffer-window
8705                                            gnus-article-buffer t))
8706                            (or (not (string-match "^\\^X-Face:" regexp))
8707                                (with-current-buffer gnus-article-buffer
8708                                  gnus-summary-search-article-matched-data)))))
8709             (gnus-summary-select-article nil t)
8710             (setq treated nil))))
8711       (set-buffer gnus-article-buffer)
8712       (widen)
8713       (if treated
8714           (progn
8715             (gnus-article-show-all-headers)
8716             (gnus-summary-search-article-position-point regexp backward))
8717         (goto-char (if backward (point-max) (point-min))))
8718       (while (not found)
8719         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8720         (if (if backward
8721                 (re-search-backward regexp nil t)
8722               (re-search-forward regexp nil t))
8723             ;; We found the regexp.
8724             (progn
8725               (gnus-summary-search-article-highlight-matched-text
8726                backward treated (string-match "^\\^X-Face:" regexp))
8727               (setq found 'found)
8728               (forward-line
8729                (/ (- 2 (window-height
8730                         (get-buffer-window gnus-article-buffer t)))
8731                   2))
8732               (set-window-start
8733                (get-buffer-window (current-buffer))
8734                (point))
8735               (set-buffer sum)
8736               (setq point (point)))
8737           ;; We didn't find it, so we go to the next article.
8738           (set-buffer sum)
8739           (setq found 'not)
8740           (while (eq found 'not)
8741             (if (not (if backward (gnus-summary-find-prev)
8742                        (gnus-summary-find-next)))
8743                 ;; No more articles.
8744                 (setq found t)
8745               ;; Select the next article and adjust point.
8746               (unless (gnus-summary-article-sparse-p
8747                        (gnus-summary-article-number))
8748                 (setq found nil)
8749                 (let ((gnus-inhibit-treatment t))
8750                   (gnus-summary-select-article))
8751                 (setq treated nil)
8752                 (set-buffer gnus-article-buffer)
8753                 (widen)
8754                 (goto-char (if backward (point-max) (point-min))))))))
8755       (gnus-message 7 ""))
8756     ;; Return whether we found the regexp.
8757     (when (eq found 'found)
8758       (goto-char point)
8759       (gnus-summary-show-thread)
8760       (gnus-summary-goto-subject gnus-current-article)
8761       (gnus-summary-position-point)
8762       t)))
8763
8764 (defun gnus-find-matching-articles (header regexp)
8765   "Return a list of all articles that match REGEXP on HEADER.
8766 This search includes all articles in the current group that Gnus has
8767 fetched headers for, whether they are displayed or not."
8768   (let ((articles nil)
8769         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8770         (case-fold-search t))
8771     (dolist (header gnus-newsgroup-headers)
8772       (when (string-match regexp (funcall func header))
8773         (push (mail-header-number header) articles)))
8774     (nreverse articles)))
8775
8776 (defun gnus-summary-find-matching (header regexp &optional backward unread
8777                                           not-case-fold not-matching)
8778   "Return a list of all articles that match REGEXP on HEADER.
8779 The search stars on the current article and goes forwards unless
8780 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8781 If UNREAD is non-nil, only unread articles will
8782 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8783 in the comparisons. If NOT-MATCHING, return a list of all articles that
8784 not match REGEXP on HEADER."
8785   (let ((case-fold-search (not not-case-fold))
8786         articles d func)
8787     (if (consp header)
8788         (if (eq (car header) 'extra)
8789             (setq func
8790                   `(lambda (h)
8791                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8792                          "")))
8793           (error "%s is an invalid header" header))
8794       (unless (fboundp (intern (concat "mail-header-" header)))
8795         (error "%s is not a valid header" header))
8796       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8797     (dolist (d (if (eq backward 'all)
8798                    gnus-newsgroup-data
8799                  (gnus-data-find-list
8800                   (gnus-summary-article-number)
8801                   (gnus-data-list backward))))
8802       (when (and (or (not unread)       ; We want all articles...
8803                      (gnus-data-unread-p d)) ; Or just unreads.
8804                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8805                  (if not-matching
8806                      (not (string-match
8807                            regexp
8808                            (funcall func (gnus-data-header d))))
8809                    (string-match regexp
8810                                  (funcall func (gnus-data-header d)))))
8811         (push (gnus-data-number d) articles))) ; Success!
8812     (nreverse articles)))
8813
8814 (defun gnus-summary-execute-command (header regexp command &optional backward)
8815   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8816 If HEADER is an empty string (or nil), the match is done on the entire
8817 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8818   (interactive
8819    (list (let ((completion-ignore-case t))
8820            (completing-read
8821             "Header name: "
8822             (mapcar (lambda (header) (list (format "%s" header)))
8823                     (append
8824                      '("Number" "Subject" "From" "Lines" "Date"
8825                        "Message-ID" "Xref" "References" "Body")
8826                      gnus-extra-headers))
8827             nil 'require-match))
8828          (read-string "Regexp: ")
8829          (read-key-sequence "Command: ")
8830          current-prefix-arg))
8831   (when (equal header "Body")
8832     (setq header ""))
8833   ;; Hidden thread subtrees must be searched as well.
8834   (gnus-summary-show-all-threads)
8835   ;; We don't want to change current point nor window configuration.
8836   (save-excursion
8837     (save-window-excursion
8838       (let (gnus-visual
8839             gnus-treat-strip-trailing-blank-lines
8840             gnus-treat-strip-leading-blank-lines
8841             gnus-treat-strip-multiple-blank-lines
8842             gnus-treat-hide-boring-headers
8843             gnus-treat-fold-newsgroups
8844             gnus-article-prepare-hook)
8845         (gnus-message 6 "Executing %s..." (key-description command))
8846         ;; We'd like to execute COMMAND interactively so as to give arguments.
8847         (gnus-execute header regexp
8848                       `(call-interactively ',(key-binding command))
8849                       backward)
8850         (gnus-message 6 "Executing %s...done" (key-description command))))))
8851
8852 (defun gnus-summary-beginning-of-article ()
8853   "Scroll the article back to the beginning."
8854   (interactive)
8855   (gnus-summary-select-article)
8856   (gnus-configure-windows 'article)
8857   (gnus-eval-in-buffer-window gnus-article-buffer
8858     (widen)
8859     (goto-char (point-min))
8860     (when gnus-break-pages
8861       (gnus-narrow-to-page))))
8862
8863 (defun gnus-summary-end-of-article ()
8864   "Scroll to the end of the article."
8865   (interactive)
8866   (gnus-summary-select-article)
8867   (gnus-configure-windows 'article)
8868   (gnus-eval-in-buffer-window gnus-article-buffer
8869     (widen)
8870     (goto-char (point-max))
8871     (recenter -3)
8872     (when gnus-break-pages
8873       (when (re-search-backward page-delimiter nil t)
8874         (narrow-to-region (match-end 0) (point-max)))
8875       (gnus-narrow-to-page))))
8876
8877 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8878   "Truncate to LEN and quote all \"(\"'s in STRING."
8879   (gnus-replace-in-string (if (and len (> (length string) len))
8880                               (substring string 0 len)
8881                             string)
8882                           "[()]" "\\\\\\&"))
8883
8884 (defun gnus-summary-print-article (&optional filename n)
8885   "Generate and print a PostScript image of the process-marked (mail) articles.
8886
8887 If used interactively, print the current article if none are
8888 process-marked.  With prefix arg, prompt the user for the name of the
8889 file to save in.
8890
8891 When used from Lisp, accept two optional args FILENAME and N.  N means
8892 to print the next N articles.  If N is negative, print the N previous
8893 articles.  If N is nil and articles have been marked with the process
8894 mark, print these instead.
8895
8896 If the optional first argument FILENAME is nil, send the image to the
8897 printer.  If FILENAME is a string, save the PostScript image in a file with
8898 that name.  If FILENAME is a number, prompt the user for the name of the file
8899 to save in."
8900   (interactive (list (ps-print-preprint current-prefix-arg)))
8901   (dolist (article (gnus-summary-work-articles n))
8902     (gnus-summary-select-article nil nil 'pseudo article)
8903     (gnus-eval-in-buffer-window gnus-article-buffer
8904       (gnus-print-buffer))
8905     (gnus-summary-remove-process-mark article))
8906   (ps-despool filename))
8907
8908 (defun gnus-print-buffer ()
8909   (let ((buffer (generate-new-buffer " *print*")))
8910     (unwind-protect
8911         (progn
8912           (copy-to-buffer buffer (point-min) (point-max))
8913           (set-buffer buffer)
8914           (gnus-remove-text-with-property 'gnus-decoration)
8915           (when (gnus-visual-p 'article-highlight 'highlight)
8916             ;; Copy-to-buffer doesn't copy overlay.  So redo
8917             ;; highlight.
8918             (let ((gnus-article-buffer buffer))
8919               (gnus-article-highlight-citation t)
8920               (gnus-article-highlight-signature)
8921               (gnus-article-emphasize)
8922               (gnus-article-delete-invisible-text)))
8923           (let ((ps-left-header
8924                  (list
8925                   (concat "("
8926                           (gnus-summary-print-truncate-and-quote
8927                            (mail-header-subject gnus-current-headers)
8928                            66) ")")
8929                   (concat "("
8930                           (gnus-summary-print-truncate-and-quote
8931                            (mail-header-from gnus-current-headers)
8932                            45) ")")))
8933                 (ps-right-header
8934                  (list
8935                   "/pagenumberstring load"
8936                   (concat "("
8937                           (mail-header-date gnus-current-headers) ")"))))
8938             (gnus-run-hooks 'gnus-ps-print-hook)
8939             (save-excursion
8940               (if window-system
8941                   (ps-spool-buffer-with-faces)
8942                 (ps-spool-buffer)))))
8943       (kill-buffer buffer))))
8944
8945 (defun gnus-summary-show-article (&optional arg)
8946   "Force redisplaying of the current article.
8947 If ARG (the prefix) is a number, show the article with the charset
8948 defined in `gnus-summary-show-article-charset-alist', or the charset
8949 input.
8950 If ARG (the prefix) is non-nil and not a number, show the raw article
8951 without any article massaging functions being run.  Normally, the key
8952 strokes are `C-u g'."
8953   (interactive "P")
8954   (cond
8955    ((numberp arg)
8956     (gnus-summary-show-article t)
8957     (let* ((gnus-newsgroup-charset
8958             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8959                 (mm-read-coding-system
8960                  "View as charset: " ;; actually it is coding system.
8961                  (with-current-buffer gnus-article-buffer
8962                    (mm-detect-coding-region (point) (point-max))))))
8963            (default-mime-charset gnus-newsgroup-charset)
8964            (gnus-newsgroup-ignored-charsets 'gnus-all))
8965       (gnus-summary-select-article nil 'force)
8966       (let ((deps gnus-newsgroup-dependencies)
8967             head header lines)
8968         (save-excursion
8969           (set-buffer gnus-original-article-buffer)
8970           (save-restriction
8971             (message-narrow-to-head)
8972             (setq head (buffer-string))
8973             (goto-char (point-min))
8974             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8975               (goto-char (point-max))
8976               (widen)
8977               (setq lines (1- (count-lines (point) (point-max))))))
8978           (with-temp-buffer
8979             (insert (format "211 %d Article retrieved.\n"
8980                             (cdr gnus-article-current)))
8981             (insert head)
8982             (if lines (insert (format "Lines: %d\n" lines)))
8983             (insert ".\n")
8984             (let ((nntp-server-buffer (current-buffer)))
8985               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8986         (gnus-data-set-header
8987          (gnus-data-find (cdr gnus-article-current))
8988          header)
8989         (gnus-summary-update-article-line
8990          (cdr gnus-article-current) header)
8991         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8992           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8993    ((not arg)
8994     ;; Select the article the normal way.
8995     (gnus-summary-select-article nil 'force))
8996    (t
8997     ;; We have to require this here to make sure that the following
8998     ;; dynamic binding isn't shadowed by autoloading.
8999     (require 'gnus-async)
9000     (require 'gnus-art)
9001     ;; Bind the article treatment functions to nil.
9002     (let ((gnus-have-all-headers t)
9003           gnus-article-prepare-hook
9004           gnus-article-decode-hook
9005           gnus-break-pages
9006           gnus-show-mime
9007           (gnus-inhibit-treatment t))
9008       (gnus-summary-select-article nil 'force))))
9009   (gnus-summary-goto-subject gnus-current-article)
9010   (gnus-summary-position-point))
9011
9012 (defun gnus-summary-show-raw-article ()
9013   "Show the raw article without any article massaging functions being run."
9014   (interactive)
9015   (gnus-summary-show-article t))
9016
9017 (defun gnus-summary-verbose-headers (&optional arg)
9018   "Toggle permanent full header display.
9019 If ARG is a positive number, turn header display on.
9020 If ARG is a negative number, turn header display off."
9021   (interactive "P")
9022   (setq gnus-show-all-headers
9023         (cond ((or (not (numberp arg))
9024                    (zerop arg))
9025                (not gnus-show-all-headers))
9026               ((natnump arg)
9027                t)))
9028   (gnus-summary-show-article))
9029
9030 (defun gnus-summary-toggle-header (&optional arg)
9031   "Show the headers if they are hidden, or hide them if they are shown.
9032 If ARG is a positive number, show the entire header.
9033 If ARG is a negative number, hide the unwanted header lines."
9034   (interactive "P")
9035   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9036                      (get-buffer-window gnus-article-buffer t))))
9037     (with-current-buffer gnus-article-buffer
9038       (widen)
9039       (article-narrow-to-head)
9040       (let* ((buffer-read-only nil)
9041              (inhibit-point-motion-hooks t)
9042              (hidden (if (numberp arg)
9043                          (>= arg 0)
9044                        (or (not (looking-at "[^ \t\n]+:"))
9045                            (gnus-article-hidden-text-p 'headers))))
9046              s e)
9047         (delete-region (point-min) (point-max))
9048         (with-current-buffer gnus-original-article-buffer
9049           (goto-char (setq s (point-min)))
9050           (setq e (if (search-forward "\n\n" nil t)
9051                       (1- (point))
9052                     (point-max))))
9053         (insert-buffer-substring gnus-original-article-buffer s e)
9054         ;; In T-gnus, gnus-article-decode-hook doesn't contain
9055         ;; article-decode-encoded-words by default.
9056         (article-decode-encoded-words)
9057         (run-hooks 'gnus-article-decode-hook)
9058         (if hidden
9059             (let ((gnus-treat-hide-headers nil)
9060                   (gnus-treat-hide-boring-headers nil))
9061               (gnus-delete-wash-type 'headers)
9062               (gnus-treat-article 'head))
9063           (gnus-treat-article 'head))
9064         (widen)
9065         (if window
9066             (set-window-start window (goto-char (point-min))))
9067         (if gnus-break-pages
9068             (gnus-narrow-to-page)
9069           (when (gnus-visual-p 'page-marker)
9070             (let ((buffer-read-only nil))
9071               (gnus-remove-text-with-property 'gnus-prev)
9072               (gnus-remove-text-with-property 'gnus-next))))
9073         (gnus-set-mode-line 'article)))))
9074
9075 (defun gnus-summary-show-all-headers ()
9076   "Make all header lines visible."
9077   (interactive)
9078   (gnus-summary-toggle-header 1))
9079
9080 (defun gnus-summary-toggle-mime (&optional arg)
9081   "Toggle MIME processing.
9082 If ARG is a positive number, turn MIME processing on."
9083   (interactive "P")
9084   (setq gnus-show-mime
9085         (if (null arg)
9086             (not gnus-show-mime)
9087           (> (prefix-numeric-value arg) 0)))
9088   (gnus-summary-select-article t 'force))
9089
9090 (defun gnus-summary-caesar-message (&optional arg)
9091   "Caesar rotate the current article by 13.
9092 The numerical prefix specifies how many places to rotate each letter
9093 forward."
9094   (interactive "P")
9095   (gnus-summary-select-article)
9096   (let ((mail-header-separator ""))
9097     (gnus-eval-in-buffer-window gnus-article-buffer
9098       (save-restriction
9099         (widen)
9100         (let ((start (window-start))
9101               buffer-read-only)
9102           (message-caesar-buffer-body arg)
9103           (set-window-start (get-buffer-window (current-buffer)) start)))))
9104   ;; Create buttons and stuff...
9105   (gnus-treat-article nil))
9106
9107 (defun gnus-summary-idna-message (&optional arg)
9108   "Decode IDNA encoded domain names in the current articles.
9109 IDNA encoded domain names looks like `xn--bar'.  If a string
9110 remain unencoded after running this function, it is likely an
9111 invalid IDNA string (`xn--bar' is invalid).
9112
9113 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9114 installed for this command to work."
9115   (interactive "P")
9116   (if (not (and (condition-case nil (require 'idna)
9117                   (file-error))
9118                 (mm-coding-system-p 'utf-8)
9119                 (executable-find (symbol-value 'idna-program))))
9120       (gnus-message
9121        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9122     (gnus-summary-select-article)
9123     (let ((mail-header-separator ""))
9124       (gnus-eval-in-buffer-window gnus-article-buffer
9125         (save-restriction
9126           (widen)
9127           (let ((start (window-start))
9128                 buffer-read-only)
9129             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9130               (replace-match (idna-to-unicode (match-string 1))))
9131             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9132
9133 (autoload 'unmorse-region "morse"
9134   "Convert morse coded text in region to ordinary ASCII text."
9135   t)
9136
9137 (defun gnus-summary-morse-message (&optional arg)
9138   "Morse decode the current article."
9139   (interactive "P")
9140   (gnus-summary-select-article)
9141   (let ((mail-header-separator ""))
9142     (gnus-eval-in-buffer-window gnus-article-buffer
9143       (save-excursion
9144         (save-restriction
9145           (widen)
9146           (let ((pos (window-start))
9147                 buffer-read-only)
9148             (goto-char (point-min))
9149             (when (message-goto-body)
9150               (gnus-narrow-to-body))
9151             (goto-char (point-min))
9152             (while (search-forward "·" (point-max) t)
9153               (replace-match "."))
9154             (unmorse-region (point-min) (point-max))
9155             (widen)
9156             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9157
9158 (defun gnus-summary-stop-page-breaking ()
9159   "Stop page breaking in the current article."
9160   (interactive)
9161   (gnus-summary-select-article)
9162   (gnus-eval-in-buffer-window gnus-article-buffer
9163     (widen)
9164     (when (gnus-visual-p 'page-marker)
9165       (let ((buffer-read-only nil))
9166         (gnus-remove-text-with-property 'gnus-prev)
9167         (gnus-remove-text-with-property 'gnus-next))
9168       (setq gnus-page-broken nil))))
9169
9170 (defun gnus-summary-move-article (&optional n to-newsgroup
9171                                             select-method action)
9172   "Move the current article to a different newsgroup.
9173 If N is a positive number, move the N next articles.
9174 If N is a negative number, move the N previous articles.
9175 If N is nil and any articles have been marked with the process mark,
9176 move those articles instead.
9177 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9178 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9179 re-spool using this method.
9180
9181 When called interactively with TO-NEWSGROUP being nil, the value of
9182 the variable `gnus-move-split-methods' is used for finding a default
9183 for the target newsgroup.
9184
9185 For this function to work, both the current newsgroup and the
9186 newsgroup that you want to move to have to support the `request-move'
9187 and `request-accept' functions.
9188
9189 ACTION can be either `move' (the default), `crosspost' or `copy'."
9190   (interactive "P")
9191   (unless action
9192     (setq action 'move))
9193   ;; Check whether the source group supports the required functions.
9194   (cond ((and (eq action 'move)
9195               (not (gnus-check-backend-function
9196                     'request-move-article gnus-newsgroup-name)))
9197          (error "The current group does not support article moving"))
9198         ((and (eq action 'crosspost)
9199               (not (gnus-check-backend-function
9200                     'request-replace-article gnus-newsgroup-name)))
9201          (error "The current group does not support article editing")))
9202   (let ((articles (gnus-summary-work-articles n))
9203         (prefix (if (gnus-check-backend-function
9204                      'request-move-article gnus-newsgroup-name)
9205                     (funcall gnus-move-group-prefix-function
9206                              gnus-newsgroup-name)
9207                   ""))
9208         (names '((move "Move" "Moving")
9209                  (copy "Copy" "Copying")
9210                  (crosspost "Crosspost" "Crossposting")))
9211         (copy-buf (save-excursion
9212                     (nnheader-set-temp-buffer " *copy article*")))
9213         art-group to-method new-xref article to-groups articles-to-update-marks)
9214     (unless (assq action names)
9215       (error "Unknown action %s" action))
9216     ;; Read the newsgroup name.
9217     (when (and (not to-newsgroup)
9218                (not select-method))
9219       (if (and gnus-move-split-methods
9220                (not
9221                 (and (memq gnus-current-article articles)
9222                      (gnus-buffer-live-p gnus-original-article-buffer))))
9223           ;; When `gnus-move-split-methods' is non-nil, we have to
9224           ;; select an article to give `gnus-read-move-group-name' an
9225           ;; opportunity to suggest an appropriate default.  However,
9226           ;; we needn't render or mark the article.
9227           (let ((gnus-display-mime-function nil)
9228                 (gnus-article-prepare-hook nil)
9229                 (gnus-mark-article-hook nil))
9230             (gnus-summary-select-article nil nil nil (car articles))))
9231       (setq to-newsgroup
9232             (gnus-read-move-group-name
9233              (cadr (assq action names))
9234              (symbol-value (intern (format "gnus-current-%s-group" action)))
9235              articles prefix))
9236       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9237     (setq to-method (or select-method
9238                         (gnus-server-to-method
9239                          (gnus-group-method to-newsgroup))))
9240     ;; Check the method we are to move this article to...
9241     (unless (gnus-check-backend-function
9242              'request-accept-article (car to-method))
9243       (error "%s does not support article copying" (car to-method)))
9244     (unless (gnus-check-server to-method)
9245       (error "Can't open server %s" (car to-method)))
9246     (gnus-message 6 "%s to %s: %s..."
9247                   (caddr (assq action names))
9248                   (or (car select-method) to-newsgroup) articles)
9249     (while articles
9250       (setq article (pop articles))
9251       (setq
9252        art-group
9253        (cond
9254         ;; Move the article.
9255         ((eq action 'move)
9256          ;; Remove this article from future suppression.
9257          (gnus-dup-unsuppress-article article)
9258          (let* ((from-method (gnus-find-method-for-group
9259                               gnus-newsgroup-name))
9260                 (to-method (gnus-find-method-for-group
9261                             to-newsgroup))
9262                 (move-is-internal (gnus-method-equal from-method to-method)))
9263          (gnus-request-move-article
9264           article                       ; Article to move
9265           gnus-newsgroup-name           ; From newsgroup
9266           (nth 1 (gnus-find-method-for-group
9267                   gnus-newsgroup-name)) ; Server
9268           (list 'gnus-request-accept-article
9269                 to-newsgroup (list 'quote select-method)
9270                 (not articles) t)       ; Accept form
9271           (not articles)                ; Only save nov last time
9272           move-is-internal)))           ; is this move internal?
9273         ;; Copy the article.
9274         ((eq action 'copy)
9275          (save-excursion
9276            (set-buffer copy-buf)
9277            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9278              (save-restriction
9279                (nnheader-narrow-to-headers)
9280                (dolist (hdr gnus-copy-article-ignored-headers)
9281                  (message-remove-header hdr t)))
9282              (gnus-request-accept-article
9283               to-newsgroup select-method (not articles) t))))
9284         ;; Crosspost the article.
9285         ((eq action 'crosspost)
9286          (let ((xref (message-tokenize-header
9287                       (mail-header-xref (gnus-summary-article-header article))
9288                       " ")))
9289            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9290                                   ":" (number-to-string article)))
9291            (unless xref
9292              (setq xref (list (system-name))))
9293            (setq new-xref
9294                  (concat
9295                   (mapconcat 'identity
9296                              (delete "Xref:" (delete new-xref xref))
9297                              " ")
9298                   " " new-xref))
9299            (save-excursion
9300              (set-buffer copy-buf)
9301              ;; First put the article in the destination group.
9302              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9303              (when (consp (setq art-group
9304                                 (gnus-request-accept-article
9305                                  to-newsgroup select-method (not articles))))
9306                (setq new-xref (concat new-xref " " (car art-group)
9307                                       ":"
9308                                       (number-to-string (cdr art-group))))
9309                ;; Now we have the new Xrefs header, so we insert
9310                ;; it and replace the new article.
9311                (nnheader-replace-header "Xref" new-xref)
9312                (gnus-request-replace-article
9313                 (cdr art-group) to-newsgroup (current-buffer))
9314                art-group))))))
9315       (cond
9316        ((not art-group)
9317         (gnus-message 1 "Couldn't %s article %s: %s"
9318                       (cadr (assq action names)) article
9319                       (nnheader-get-report (car to-method))))
9320        ((eq art-group 'junk)
9321         (when (eq action 'move)
9322           (gnus-summary-mark-article article gnus-canceled-mark)
9323           (gnus-message 4 "Deleted article %s" article)
9324           ;; run the delete hook
9325           (run-hook-with-args 'gnus-summary-article-delete-hook
9326                               action
9327                               (gnus-data-header
9328                                (assoc article (gnus-data-list nil)))
9329                               gnus-newsgroup-name nil
9330                               select-method)))
9331        (t
9332         (let* ((pto-group (gnus-group-prefixed-name
9333                            (car art-group) to-method))
9334                (info (gnus-get-info pto-group))
9335                (to-group (gnus-info-group info))
9336                to-marks)
9337           ;; Update the group that has been moved to.
9338           (when (and info
9339                      (memq action '(move copy)))
9340             (unless (member to-group to-groups)
9341               (push to-group to-groups))
9342
9343             (unless (memq article gnus-newsgroup-unreads)
9344               (push 'read to-marks)
9345               (gnus-info-set-read
9346                info (gnus-add-to-range (gnus-info-read info)
9347                                        (list (cdr art-group)))))
9348
9349             ;; See whether the article is to be put in the cache.
9350             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9351                              gnus-article-mark-lists
9352                            (delete '(expirable . expire)
9353                                    (copy-sequence gnus-article-mark-lists))))
9354                   (to-article (cdr art-group)))
9355
9356               ;; Enter the article into the cache in the new group,
9357               ;; if that is required.
9358               (when gnus-use-cache
9359                 (gnus-cache-possibly-enter-article
9360                  to-group to-article
9361                  (let ((header (copy-sequence
9362                                 (gnus-summary-article-header article))))
9363                    (mail-header-set-number header to-article)
9364                    header)
9365                  (memq article gnus-newsgroup-marked)
9366                  (memq article gnus-newsgroup-dormant)
9367                  (memq article gnus-newsgroup-unreads)))
9368
9369               (when gnus-preserve-marks
9370                 ;; Copy any marks over to the new group.
9371                 (when (and (equal to-group gnus-newsgroup-name)
9372                            (not (memq article gnus-newsgroup-unreads)))
9373                   ;; Mark this article as read in this group.
9374                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9375                   (setcdr (gnus-active to-group) to-article)
9376                   (setcdr gnus-newsgroup-active to-article))
9377
9378                 (while marks
9379                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9380                     (when (memq article (symbol-value
9381                                          (intern (format "gnus-newsgroup-%s"
9382                                                          (caar marks)))))
9383                       (push (cdar marks) to-marks)
9384                       ;; If the other group is the same as this group,
9385                       ;; then we have to add the mark to the list.
9386                       (when (equal to-group gnus-newsgroup-name)
9387                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9388                              (cons to-article
9389                                    (symbol-value
9390                                     (intern (format "gnus-newsgroup-%s"
9391                                                     (caar marks)))))))
9392                       ;; Copy the marks to other group.
9393                       (gnus-add-marked-articles
9394                        to-group (cdar marks) (list to-article) info)))
9395                   (setq marks (cdr marks)))
9396
9397                 (gnus-request-set-mark
9398                  to-group (list (list (list to-article) 'add to-marks))))
9399
9400               (gnus-dribble-enter
9401                (concat "(gnus-group-set-info '"
9402                        (gnus-prin1-to-string (gnus-get-info to-group))
9403                        ")"))))
9404
9405           ;; Update the Xref header in this article to point to
9406           ;; the new crossposted article we have just created.
9407           (when (eq action 'crosspost)
9408             (save-excursion
9409               (set-buffer copy-buf)
9410               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9411               (nnheader-replace-header "Xref" new-xref)
9412               (gnus-request-replace-article
9413                article gnus-newsgroup-name (current-buffer))))
9414
9415           ;; run the move/copy/crosspost/respool hook
9416           (run-hook-with-args 'gnus-summary-article-move-hook
9417                               action
9418                               (gnus-data-header
9419                                (assoc article (gnus-data-list nil)))
9420                               gnus-newsgroup-name
9421                               to-newsgroup
9422                               select-method))
9423
9424         ;;;!!!Why is this necessary?
9425         (set-buffer gnus-summary-buffer)
9426         
9427         (gnus-summary-goto-subject article)
9428         (when (eq action 'move)
9429           (gnus-summary-mark-article article gnus-canceled-mark))))
9430       (push article articles-to-update-marks))
9431
9432     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9433     ;; Re-activate all groups that have been moved to.
9434     (save-excursion
9435       (set-buffer gnus-group-buffer)
9436       (let ((gnus-group-marked to-groups))
9437         (gnus-group-get-new-news-this-group nil t)))
9438     
9439     (gnus-kill-buffer copy-buf)
9440     (gnus-summary-position-point)
9441     (gnus-set-mode-line 'summary)))
9442
9443 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9444   "Copy the current article to some other group.
9445 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9446 When called interactively, if TO-NEWSGROUP is nil, use the value of
9447 the variable `gnus-move-split-methods' for finding a default target
9448 newsgroup.
9449 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9450 re-spool using this method."
9451   (interactive "P")
9452   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9453
9454 (defun gnus-summary-crosspost-article (&optional n)
9455   "Crosspost the current article to some other group."
9456   (interactive "P")
9457   (gnus-summary-move-article n nil nil 'crosspost))
9458
9459 (defcustom gnus-summary-respool-default-method nil
9460   "Default method type for respooling an article.
9461 If nil, use to the current newsgroup method."
9462   :type 'symbol
9463   :group 'gnus-summary-mail)
9464
9465 (defcustom gnus-summary-display-while-building nil
9466   "If non-nil, show and update the summary buffer as it's being built.
9467 If the value is t, update the buffer after every line is inserted.  If
9468 the value is an integer (N), update the display every N lines."
9469   :version "22.1"
9470   :group 'gnus-thread
9471   :type '(choice (const :tag "off" nil)
9472                  number
9473                  (const :tag "frequently" t)))
9474
9475 (defun gnus-summary-respool-article (&optional n method)
9476   "Respool the current article.
9477 The article will be squeezed through the mail spooling process again,
9478 which means that it will be put in some mail newsgroup or other
9479 depending on `nnmail-split-methods'.
9480 If N is a positive number, respool the N next articles.
9481 If N is a negative number, respool the N previous articles.
9482 If N is nil and any articles have been marked with the process mark,
9483 respool those articles instead.
9484
9485 Respooling can be done both from mail groups and \"real\" newsgroups.
9486 In the former case, the articles in question will be moved from the
9487 current group into whatever groups they are destined to.  In the
9488 latter case, they will be copied into the relevant groups."
9489   (interactive
9490    (list current-prefix-arg
9491          (let* ((methods (gnus-methods-using 'respool))
9492                 (methname
9493                  (symbol-name (or gnus-summary-respool-default-method
9494                                   (car (gnus-find-method-for-group
9495                                         gnus-newsgroup-name)))))
9496                 (method
9497                  (gnus-completing-read-with-default
9498                   methname "Backend to use when respooling"
9499                   methods nil t nil 'gnus-mail-method-history))
9500                 ms)
9501            (cond
9502             ((zerop (length (setq ms (gnus-servers-using-backend
9503                                       (intern method)))))
9504              (list (intern method) ""))
9505             ((= 1 (length ms))
9506              (car ms))
9507             (t
9508              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9509                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9510                            ms-alist))))))))
9511   (unless method
9512     (error "No method given for respooling"))
9513   (if (assoc (symbol-name
9514               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9515              (gnus-methods-using 'respool))
9516       (gnus-summary-move-article n nil method)
9517     (gnus-summary-copy-article n nil method)))
9518
9519 (defun gnus-summary-import-article (file &optional edit)
9520   "Import an arbitrary file into a mail newsgroup."
9521   (interactive "fImport file: \nP")
9522   (let ((group gnus-newsgroup-name)
9523         (now (current-time))
9524         atts lines group-art)
9525     (unless (gnus-check-backend-function 'request-accept-article group)
9526       (error "%s does not support article importing" group))
9527     (or (file-readable-p file)
9528         (not (file-regular-p file))
9529         (error "Can't read %s" file))
9530     (save-excursion
9531       (set-buffer (gnus-get-buffer-create " *import file*"))
9532       (erase-buffer)
9533       (nnheader-insert-file-contents file)
9534       (goto-char (point-min))
9535       (if (nnheader-article-p)
9536           (save-restriction
9537             (goto-char (point-min))
9538             (search-forward "\n\n" nil t)
9539             (narrow-to-region (point-min) (1- (point)))
9540             (goto-char (point-min))
9541             (unless (re-search-forward "^date:" nil t)
9542               (goto-char (point-max))
9543               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9544         ;; This doesn't look like an article, so we fudge some headers.
9545         (setq atts (file-attributes file)
9546               lines (count-lines (point-min) (point-max)))
9547         (insert "From: " (read-string "From: ") "\n"
9548                 "Subject: " (read-string "Subject: ") "\n"
9549                 "Date: " (message-make-date (nth 5 atts)) "\n"
9550                 "Message-ID: " (message-make-message-id) "\n"
9551                 "Lines: " (int-to-string lines) "\n"
9552                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9553       (setq group-art (gnus-request-accept-article group nil t))
9554       (kill-buffer (current-buffer)))
9555     (setq gnus-newsgroup-active (gnus-activate-group group))
9556     (forward-line 1)
9557     (gnus-summary-goto-article (cdr group-art) nil t)
9558     (when edit
9559       (gnus-summary-edit-article))))
9560
9561 (defun gnus-summary-create-article ()
9562   "Create an article in a mail newsgroup."
9563   (interactive)
9564   (let ((group gnus-newsgroup-name)
9565         (now (current-time))
9566         group-art)
9567     (unless (gnus-check-backend-function 'request-accept-article group)
9568       (error "%s does not support article importing" group))
9569     (save-excursion
9570       (set-buffer (gnus-get-buffer-create " *import file*"))
9571       (erase-buffer)
9572       (goto-char (point-min))
9573       ;; This doesn't look like an article, so we fudge some headers.
9574       (insert "From: " (read-string "From: ") "\n"
9575               "Subject: " (read-string "Subject: ") "\n"
9576               "Date: " (message-make-date now) "\n"
9577               "Message-ID: " (message-make-message-id) "\n")
9578       (setq group-art (gnus-request-accept-article group nil t))
9579       (kill-buffer (current-buffer)))
9580     (setq gnus-newsgroup-active (gnus-activate-group group))
9581     (forward-line 1)
9582     (gnus-summary-goto-article (cdr group-art) nil t)
9583     (gnus-summary-edit-article)))
9584
9585 (defun gnus-summary-article-posted-p ()
9586   "Say whether the current (mail) article is available from news as well.
9587 This will be the case if the article has both been mailed and posted."
9588   (interactive)
9589   (let ((id (mail-header-references (gnus-summary-article-header)))
9590         (gnus-override-method (car (gnus-refer-article-methods))))
9591     (if (gnus-request-head id "")
9592         (gnus-message 2 "The current message was found on %s"
9593                       gnus-override-method)
9594       (gnus-message 2 "The current message couldn't be found on %s"
9595                     gnus-override-method)
9596       nil)))
9597
9598 (defun gnus-summary-expire-articles (&optional now)
9599   "Expire all articles that are marked as expirable in the current group."
9600   (interactive)
9601   (when (and (not gnus-group-is-exiting-without-update-p)
9602              (gnus-check-backend-function
9603               'request-expire-articles gnus-newsgroup-name))
9604     ;; This backend supports expiry.
9605     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9606            (expirable (if total
9607                           (progn
9608                             ;; We need to update the info for
9609                             ;; this group for `gnus-list-of-read-articles'
9610                             ;; to give us the right answer.
9611                             (gnus-run-hooks 'gnus-exit-group-hook)
9612                             (gnus-summary-update-info)
9613                             (gnus-list-of-read-articles gnus-newsgroup-name))
9614                         (setq gnus-newsgroup-expirable
9615                               (sort gnus-newsgroup-expirable '<))))
9616            (expiry-wait (if now 'immediate
9617                           (gnus-group-find-parameter
9618                            gnus-newsgroup-name 'expiry-wait)))
9619            (nnmail-expiry-target
9620             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9621                 nnmail-expiry-target))
9622            es)
9623       (when expirable
9624         ;; There are expirable articles in this group, so we run them
9625         ;; through the expiry process.
9626         (gnus-message 6 "Expiring articles...")
9627         (unless (gnus-check-group gnus-newsgroup-name)
9628           (error "Can't open server for %s" gnus-newsgroup-name))
9629         ;; The list of articles that weren't expired is returned.
9630         (save-excursion
9631           (if expiry-wait
9632               (let ((nnmail-expiry-wait-function nil)
9633                     (nnmail-expiry-wait expiry-wait))
9634                 (setq es (gnus-request-expire-articles
9635                           expirable gnus-newsgroup-name)))
9636             (setq es (gnus-request-expire-articles
9637                       expirable gnus-newsgroup-name)))
9638           (unless total
9639             (setq gnus-newsgroup-expirable es))
9640           ;; We go through the old list of expirable, and mark all
9641           ;; really expired articles as nonexistent.
9642           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9643             (let ((gnus-use-cache nil))
9644               (dolist (article expirable)
9645                 (when (and (not (memq article es))
9646                            (gnus-data-find article))
9647                   (gnus-summary-mark-article article gnus-canceled-mark)
9648                   (run-hook-with-args 'gnus-summary-article-expire-hook
9649                                       'delete
9650                                       (gnus-data-header
9651                                        (assoc article (gnus-data-list nil)))
9652                                       gnus-newsgroup-name
9653                                       nil
9654                                       nil))))))
9655         (gnus-message 6 "Expiring articles...done")))))
9656
9657 (defun gnus-summary-expire-articles-now ()
9658   "Expunge all expirable articles in the current group.
9659 This means that *all* articles that are marked as expirable will be
9660 deleted forever, right now."
9661   (interactive)
9662   (or gnus-expert-user
9663       (gnus-yes-or-no-p
9664        "Are you really, really, really sure you want to delete all these messages? ")
9665       (error "Phew!"))
9666   (gnus-summary-expire-articles t))
9667
9668 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9669 (defun gnus-summary-delete-article (&optional n)
9670   "Delete the N next (mail) articles.
9671 This command actually deletes articles.  This is not a marking
9672 command.  The article will disappear forever from your life, never to
9673 return.
9674
9675 If N is negative, delete backwards.
9676 If N is nil and articles have been marked with the process mark,
9677 delete these instead.
9678
9679 If `gnus-novice-user' is non-nil you will be asked for
9680 confirmation before the articles are deleted."
9681   (interactive "P")
9682   (unless (gnus-check-backend-function 'request-expire-articles
9683                                        gnus-newsgroup-name)
9684     (error "The current newsgroup does not support article deletion"))
9685   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9686     (error "Couldn't open server"))
9687   ;; Compute the list of articles to delete.
9688   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9689         (nnmail-expiry-target 'delete)
9690         not-deleted)
9691     (if (and gnus-novice-user
9692              (not (gnus-yes-or-no-p
9693                    (format "Do you really want to delete %s forever? "
9694                            (if (> (length articles) 1)
9695                                (format "these %s articles" (length articles))
9696                              "this article")))))
9697         ()
9698       ;; Delete the articles.
9699       (setq not-deleted (gnus-request-expire-articles
9700                          articles gnus-newsgroup-name 'force))
9701       (while articles
9702         (gnus-summary-remove-process-mark (car articles))
9703         ;; The backend might not have been able to delete the article
9704         ;; after all.
9705         (unless (memq (car articles) not-deleted)
9706           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9707         (let* ((article (car articles))
9708                (ghead  (gnus-data-header
9709                                     (assoc article (gnus-data-list nil)))))
9710           (run-hook-with-args 'gnus-summary-article-delete-hook
9711                               'delete ghead gnus-newsgroup-name nil
9712                               nil))
9713         (setq articles (cdr articles)))
9714       (when not-deleted
9715         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9716     (gnus-summary-position-point)
9717     (gnus-set-mode-line 'summary)
9718     not-deleted))
9719
9720 (defun gnus-summary-edit-article (&optional force)
9721   "Edit the current article.
9722 This will have permanent effect only in mail groups.
9723 If FORCE is non-nil, allow editing of articles even in read-only
9724 groups."
9725   (interactive "P")
9726   (save-excursion
9727     (set-buffer gnus-summary-buffer)
9728     (let ((mail-parse-charset gnus-newsgroup-charset)
9729           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9730       (gnus-set-global-variables)
9731       (when (and (not force)
9732                  (gnus-group-read-only-p))
9733         (error "The current newsgroup does not support article editing"))
9734       (gnus-summary-show-article t)
9735       (gnus-article-edit-article
9736        'ignore
9737        `(lambda (no-highlight)
9738           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9739                 (message-options message-options)
9740                 (message-options-set-recipient)
9741                 (mail-parse-ignored-charsets
9742                  ',gnus-newsgroup-ignored-charsets))
9743             (gnus-summary-edit-article-done
9744              ,(or (mail-header-references gnus-current-headers) "")
9745              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9746
9747 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9748
9749 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9750                                                  no-highlight)
9751   "Make edits to the current article permanent."
9752   (interactive)
9753   (save-excursion
9754     ;; The buffer restriction contains the entire article if it exists.
9755     (when (article-goto-body)
9756       (let ((lines (count-lines (point) (point-max)))
9757             (length (- (point-max) (point)))
9758             (case-fold-search t)
9759             (body (copy-marker (point))))
9760         (goto-char (point-min))
9761         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9762           (delete-region (match-beginning 1) (match-end 1))
9763           (insert (number-to-string length)))
9764         (goto-char (point-min))
9765         (when (re-search-forward
9766                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9767           (delete-region (match-beginning 1) (match-end 1))
9768           (insert (number-to-string length)))
9769         (goto-char (point-min))
9770         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9771           (delete-region (match-beginning 1) (match-end 1))
9772           (insert (number-to-string lines))))))
9773   ;; Replace the article.
9774   (let ((buf (current-buffer)))
9775     (with-temp-buffer
9776       (insert-buffer-substring buf)
9777
9778       (if (and (not read-only)
9779                (not (gnus-request-replace-article
9780                      (cdr gnus-article-current) (car gnus-article-current)
9781                      (current-buffer) t)))
9782           (error "Couldn't replace article")
9783         ;; Update the summary buffer.
9784         (if (and references
9785                  (equal (message-tokenize-header references " ")
9786                         (message-tokenize-header
9787                          (or (message-fetch-field "references") "") " ")))
9788             ;; We only have to update this line.
9789             (save-excursion
9790               (save-restriction
9791                 (message-narrow-to-head)
9792                 (let ((head (buffer-substring-no-properties
9793                              (point-min) (point-max)))
9794                       header)
9795                   (with-temp-buffer
9796                     (insert (format "211 %d Article retrieved.\n"
9797                                     (cdr gnus-article-current)))
9798                     (insert head)
9799                     (insert ".\n")
9800                     (let ((nntp-server-buffer (current-buffer)))
9801                       (setq header (car (gnus-get-newsgroup-headers
9802                                          nil t))))
9803                     (save-excursion
9804                       (set-buffer gnus-summary-buffer)
9805                       (gnus-data-set-header
9806                        (gnus-data-find (cdr gnus-article-current))
9807                        header)
9808                       (gnus-summary-update-article-line
9809                        (cdr gnus-article-current) header)
9810                       (if (gnus-summary-goto-subject
9811                            (cdr gnus-article-current) nil t)
9812                           (gnus-summary-update-secondary-mark
9813                            (cdr gnus-article-current))))))))
9814           ;; Update threads.
9815           (set-buffer (or buffer gnus-summary-buffer))
9816           (gnus-summary-update-article (cdr gnus-article-current))
9817           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9818               (gnus-summary-update-secondary-mark
9819                (cdr gnus-article-current))))
9820         ;; Prettify the article buffer again.
9821         (unless no-highlight
9822           (save-excursion
9823             (set-buffer gnus-article-buffer)
9824             ;;;!!! Fix this -- article should be rehighlighted.
9825             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9826             (set-buffer gnus-original-article-buffer)
9827             (gnus-request-article
9828              (cdr gnus-article-current)
9829              (car gnus-article-current) (current-buffer))))
9830         ;; Prettify the summary buffer line.
9831         (when (gnus-visual-p 'summary-highlight 'highlight)
9832           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9833
9834 (defun gnus-summary-edit-wash (key)
9835   "Perform editing command KEY in the article buffer."
9836   (interactive
9837    (list
9838     (progn
9839       (message "%s" (concat (this-command-keys) "- "))
9840       (read-char))))
9841   (message "")
9842   (gnus-summary-edit-article)
9843   (execute-kbd-macro (concat (this-command-keys) key))
9844   (gnus-article-edit-done))
9845
9846 ;;; Respooling
9847
9848 (defun gnus-summary-respool-query (&optional silent trace)
9849   "Query where the respool algorithm would put this article."
9850   (interactive)
9851   (let (gnus-mark-article-hook)
9852     (gnus-summary-select-article)
9853     (save-excursion
9854       (set-buffer gnus-original-article-buffer)
9855       (let ((groups (nnmail-article-group 'identity trace)))
9856         (unless silent
9857           (if groups
9858               (message "This message would go to %s"
9859                        (mapconcat 'car groups ", "))
9860             (message "This message would go to no groups"))
9861           groups)))))
9862
9863 (defun gnus-summary-respool-trace ()
9864   "Trace where the respool algorithm would put this article.
9865 Display a buffer showing all fancy splitting patterns which matched."
9866   (interactive)
9867   (gnus-summary-respool-query nil t))
9868
9869 ;; Summary marking commands.
9870
9871 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9872   "Mark articles which has the same subject as read, and then select the next.
9873 If UNMARK is positive, remove any kind of mark.
9874 If UNMARK is negative, tick articles."
9875   (interactive "P")
9876   (when unmark
9877     (setq unmark (prefix-numeric-value unmark)))
9878   (let ((count
9879          (gnus-summary-mark-same-subject
9880           (gnus-summary-article-subject) unmark)))
9881     ;; Select next unread article.  If auto-select-same mode, should
9882     ;; select the first unread article.
9883     (gnus-summary-next-article t (and gnus-auto-select-same
9884                                       (gnus-summary-article-subject)))
9885     (gnus-message 7 "%d article%s marked as %s"
9886                   count (if (= count 1) " is" "s are")
9887                   (if unmark "unread" "read"))))
9888
9889 (defun gnus-summary-kill-same-subject (&optional unmark)
9890   "Mark articles which has the same subject as read.
9891 If UNMARK is positive, remove any kind of mark.
9892 If UNMARK is negative, tick articles."
9893   (interactive "P")
9894   (when unmark
9895     (setq unmark (prefix-numeric-value unmark)))
9896   (let ((count
9897          (gnus-summary-mark-same-subject
9898           (gnus-summary-article-subject) unmark)))
9899     ;; If marked as read, go to next unread subject.
9900     (when (null unmark)
9901       ;; Go to next unread subject.
9902       (gnus-summary-next-subject 1 t))
9903     (gnus-message 7 "%d articles are marked as %s"
9904                   count (if unmark "unread" "read"))))
9905
9906 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9907   "Mark articles with same SUBJECT as read, and return marked number.
9908 If optional argument UNMARK is positive, remove any kinds of marks.
9909 If optional argument UNMARK is negative, mark articles as unread instead."
9910   (let ((count 1))
9911     (save-excursion
9912       (cond
9913        ((null unmark)                   ; Mark as read.
9914         (while (and
9915                 (progn
9916                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9917                   (gnus-summary-show-thread) t)
9918                 (gnus-summary-find-subject subject))
9919           (setq count (1+ count))))
9920        ((> unmark 0)                    ; Tick.
9921         (while (and
9922                 (progn
9923                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9924                   (gnus-summary-show-thread) t)
9925                 (gnus-summary-find-subject subject))
9926           (setq count (1+ count))))
9927        (t                               ; Mark as unread.
9928         (while (and
9929                 (progn
9930                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9931                   (gnus-summary-show-thread) t)
9932                 (gnus-summary-find-subject subject))
9933           (setq count (1+ count)))))
9934       (gnus-set-mode-line 'summary)
9935       ;; Return the number of marked articles.
9936       count)))
9937
9938 (defun gnus-summary-mark-as-processable (n &optional unmark)
9939   "Set the process mark on the next N articles.
9940 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9941 the process mark instead.  The difference between N and the actual
9942 number of articles marked is returned."
9943   (interactive "P")
9944   (if (and (null n) (gnus-region-active-p))
9945       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9946     (setq n (prefix-numeric-value n))
9947     (let ((backward (< n 0))
9948           (n (abs n)))
9949       (while (and
9950               (> n 0)
9951               (if unmark
9952                   (gnus-summary-remove-process-mark
9953                    (gnus-summary-article-number))
9954                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9955               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9956         (setq n (1- n)))
9957       (when (/= 0 n)
9958         (gnus-message 7 "No more articles"))
9959       (gnus-summary-recenter)
9960       (gnus-summary-position-point)
9961       n)))
9962
9963 (defun gnus-summary-unmark-as-processable (n)
9964   "Remove the process mark from the next N articles.
9965 If N is negative, unmark backward instead.  The difference between N and
9966 the actual number of articles unmarked is returned."
9967   (interactive "P")
9968   (gnus-summary-mark-as-processable n t))
9969
9970 (defun gnus-summary-unmark-all-processable ()
9971   "Remove the process mark from all articles."
9972   (interactive)
9973   (save-excursion
9974     (while gnus-newsgroup-processable
9975       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9976   (gnus-summary-position-point))
9977
9978 (defun gnus-summary-add-mark (article type)
9979   "Mark ARTICLE with a mark of TYPE."
9980   (let ((vtype (car (assq type gnus-article-mark-lists)))
9981         var)
9982     (if (not vtype)
9983         (error "No such mark type: %s" type)
9984       (setq var (intern (format "gnus-newsgroup-%s" type)))
9985       (set var (cons article (symbol-value var)))
9986       (if (memq type '(processable cached replied forwarded recent saved))
9987           (gnus-summary-update-secondary-mark article)
9988         ;;; !!! This is bogus.  We should find out what primary
9989         ;;; !!! mark we want to set.
9990         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9991
9992 (defun gnus-summary-mark-as-expirable (n)
9993   "Mark N articles forward as expirable.
9994 If N is negative, mark backward instead.  The difference between N and
9995 the actual number of articles marked is returned."
9996   (interactive "p")
9997   (gnus-summary-mark-forward n gnus-expirable-mark))
9998
9999 (defun gnus-summary-mark-as-spam (n)
10000   "Mark N articles forward as spam.
10001 If N is negative, mark backward instead.  The difference between N and
10002 the actual number of articles marked is returned."
10003   (interactive "p")
10004   (gnus-summary-mark-forward n gnus-spam-mark))
10005
10006 (defun gnus-summary-mark-article-as-replied (article)
10007   "Mark ARTICLE as replied to and update the summary line.
10008 ARTICLE can also be a list of articles."
10009   (interactive (list (gnus-summary-article-number)))
10010   (let ((articles (if (listp article) article (list article))))
10011     (dolist (article articles)
10012       (unless (numberp article)
10013         (error "%s is not a number" article))
10014       (push article gnus-newsgroup-replied)
10015       (let ((buffer-read-only nil))
10016         (when (gnus-summary-goto-subject article nil t)
10017           (gnus-summary-update-secondary-mark article))))))
10018
10019 (defun gnus-summary-mark-article-as-forwarded (article)
10020   "Mark ARTICLE as forwarded and update the summary line.
10021 ARTICLE can also be a list of articles."
10022   (let ((articles (if (listp article) article (list article))))
10023     (dolist (article articles)
10024       (push article gnus-newsgroup-forwarded)
10025       (let ((buffer-read-only nil))
10026         (when (gnus-summary-goto-subject article nil t)
10027           (gnus-summary-update-secondary-mark article))))))
10028
10029 (defun gnus-summary-set-bookmark (article)
10030   "Set a bookmark in current article."
10031   (interactive (list (gnus-summary-article-number)))
10032   (when (or (not (get-buffer gnus-article-buffer))
10033             (not gnus-current-article)
10034             (not gnus-article-current)
10035             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10036     (error "No current article selected"))
10037   ;; Remove old bookmark, if one exists.
10038   (gnus-pull article gnus-newsgroup-bookmarks)
10039   ;; Set the new bookmark, which is on the form
10040   ;; (article-number . line-number-in-body).
10041   (push
10042    (cons article
10043          (with-current-buffer gnus-article-buffer
10044            (count-lines
10045             (min (point)
10046                  (save-excursion
10047                    (article-goto-body)
10048                    (point)))
10049             (point))))
10050    gnus-newsgroup-bookmarks)
10051   (gnus-message 6 "A bookmark has been added to the current article."))
10052
10053 (defun gnus-summary-remove-bookmark (article)
10054   "Remove the bookmark from the current article."
10055   (interactive (list (gnus-summary-article-number)))
10056   ;; Remove old bookmark, if one exists.
10057   (if (not (assq article gnus-newsgroup-bookmarks))
10058       (gnus-message 6 "No bookmark in current article.")
10059     (gnus-pull article gnus-newsgroup-bookmarks)
10060     (gnus-message 6 "Removed bookmark.")))
10061
10062 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10063 (defun gnus-summary-mark-as-dormant (n)
10064   "Mark N articles forward as dormant.
10065 If N is negative, mark backward instead.  The difference between N and
10066 the actual number of articles marked is returned."
10067   (interactive "p")
10068   (gnus-summary-mark-forward n gnus-dormant-mark))
10069
10070 (defun gnus-summary-set-process-mark (article)
10071   "Set the process mark on ARTICLE and update the summary line."
10072   (setq gnus-newsgroup-processable
10073         (cons article
10074               (delq article gnus-newsgroup-processable)))
10075   (when (gnus-summary-goto-subject article)
10076     (gnus-summary-show-thread)
10077     (gnus-summary-goto-subject article)
10078     (gnus-summary-update-secondary-mark article)))
10079
10080 (defun gnus-summary-remove-process-mark (&rest articles)
10081   "Remove the process mark from ARTICLES and update the summary line."
10082   (dolist (article articles)
10083     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10084     (when (gnus-summary-goto-subject article)
10085       (gnus-summary-show-thread)
10086       (gnus-summary-goto-subject article)
10087       (gnus-summary-update-secondary-mark article))))
10088
10089 (defun gnus-summary-set-saved-mark (article)
10090   "Set the process mark on ARTICLE and update the summary line."
10091   (push article gnus-newsgroup-saved)
10092   (when (gnus-summary-goto-subject article)
10093     (gnus-summary-update-secondary-mark article)))
10094
10095 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10096   "Mark N articles as read forwards.
10097 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10098 The difference between N and the actual number of articles marked is
10099 returned.
10100 If NO-EXPIRE, auto-expiry will be inhibited."
10101   (interactive "p")
10102   (gnus-summary-show-thread)
10103   (let ((backward (< n 0))
10104         (gnus-summary-goto-unread
10105          (and gnus-summary-goto-unread
10106               (not (eq gnus-summary-goto-unread 'never))
10107               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10108                                     gnus-ticked-mark gnus-dormant-mark)))))
10109         (n (abs n))
10110         (mark (or mark gnus-del-mark)))
10111     (while (and (> n 0)
10112                 (gnus-summary-mark-article nil mark no-expire)
10113                 (zerop (gnus-summary-next-subject
10114                         (if backward -1 1)
10115                         (and gnus-summary-goto-unread
10116                              (not (eq gnus-summary-goto-unread 'never)))
10117                         t)))
10118       (setq n (1- n)))
10119     (when (/= 0 n)
10120       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10121     (gnus-summary-recenter)
10122     (gnus-summary-position-point)
10123     (gnus-set-mode-line 'summary)
10124     n))
10125
10126 (defun gnus-summary-mark-article-as-read (mark)
10127   "Mark the current article quickly as read with MARK."
10128   (let ((article (gnus-summary-article-number)))
10129     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10130     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10131     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10132     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10133     (push (cons article mark) gnus-newsgroup-reads)
10134     ;; Possibly remove from cache, if that is used.
10135     (when gnus-use-cache
10136       (gnus-cache-enter-remove-article article))
10137     ;; Allow the backend to change the mark.
10138     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10139     ;; Check for auto-expiry.
10140     (when (and gnus-newsgroup-auto-expire
10141                (memq mark gnus-auto-expirable-marks))
10142       (setq mark gnus-expirable-mark)
10143       ;; Let the backend know about the mark change.
10144       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10145       (push article gnus-newsgroup-expirable))
10146     ;; Set the mark in the buffer.
10147     (gnus-summary-update-mark mark 'unread)
10148     t))
10149
10150 (defun gnus-summary-mark-article-as-unread (mark)
10151   "Mark the current article quickly as unread with MARK."
10152   (let* ((article (gnus-summary-article-number))
10153          (old-mark (gnus-summary-article-mark article)))
10154     ;; Allow the backend to change the mark.
10155     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10156     (if (eq mark old-mark)
10157         t
10158       (if (<= article 0)
10159           (progn
10160             (gnus-error 1 "Can't mark negative article numbers")
10161             nil)
10162         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10163         (setq gnus-newsgroup-spam-marked
10164               (delq article gnus-newsgroup-spam-marked))
10165         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10166         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10167         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10168         (cond ((= mark gnus-ticked-mark)
10169                (setq gnus-newsgroup-marked
10170                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10171                                               article)))
10172               ((= mark gnus-spam-mark)
10173                (setq gnus-newsgroup-spam-marked
10174                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10175                                               article)))
10176               ((= mark gnus-dormant-mark)
10177                (setq gnus-newsgroup-dormant
10178                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10179                                               article)))
10180               (t
10181                (setq gnus-newsgroup-unreads
10182                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10183                                               article))))
10184         (gnus-pull article gnus-newsgroup-reads)
10185
10186         ;; See whether the article is to be put in the cache.
10187         (and gnus-use-cache
10188              (vectorp (gnus-summary-article-header article))
10189              (save-excursion
10190                (gnus-cache-possibly-enter-article
10191                 gnus-newsgroup-name article
10192                 (gnus-summary-article-header article)
10193                 (= mark gnus-ticked-mark)
10194                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10195
10196         ;; Fix the mark.
10197         (gnus-summary-update-mark mark 'unread)
10198         t))))
10199
10200 (defun gnus-summary-mark-article (&optional article mark no-expire)
10201   "Mark ARTICLE with MARK.  MARK can be any character.
10202 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10203 `??' (dormant) and `?E' (expirable).
10204 If MARK is nil, then the default character `?r' is used.
10205 If ARTICLE is nil, then the article on the current line will be
10206 marked.
10207 If NO-EXPIRE, auto-expiry will be inhibited."
10208   ;; The mark might be a string.
10209   (when (stringp mark)
10210     (setq mark (aref mark 0)))
10211   ;; If no mark is given, then we check auto-expiring.
10212   (when (null mark)
10213     (setq mark gnus-del-mark))
10214   (when (and (not no-expire)
10215              gnus-newsgroup-auto-expire
10216              (memq mark gnus-auto-expirable-marks))
10217     (setq mark gnus-expirable-mark))
10218   (let ((article (or article (gnus-summary-article-number)))
10219         (old-mark (gnus-summary-article-mark article)))
10220     ;; Allow the backend to change the mark.
10221     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10222     (if (eq mark old-mark)
10223         t
10224       (unless article
10225         (error "No article on current line"))
10226       (if (not (if (or (= mark gnus-unread-mark)
10227                        (= mark gnus-ticked-mark)
10228                        (= mark gnus-spam-mark)
10229                        (= mark gnus-dormant-mark))
10230                    (gnus-mark-article-as-unread article mark)
10231                  (gnus-mark-article-as-read article mark)))
10232           t
10233         ;; See whether the article is to be put in the cache.
10234         (and gnus-use-cache
10235              (not (= mark gnus-canceled-mark))
10236              (vectorp (gnus-summary-article-header article))
10237              (save-excursion
10238                (gnus-cache-possibly-enter-article
10239                 gnus-newsgroup-name article
10240                 (gnus-summary-article-header article)
10241                 (= mark gnus-ticked-mark)
10242                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10243
10244         (when (gnus-summary-goto-subject article nil t)
10245           (let ((buffer-read-only nil))
10246             (gnus-summary-show-thread)
10247             ;; Fix the mark.
10248             (gnus-summary-update-mark mark 'unread)
10249             t))))))
10250
10251 (defun gnus-summary-update-secondary-mark (article)
10252   "Update the secondary (read, process, cache) mark."
10253   (gnus-summary-update-mark
10254    (cond ((memq article gnus-newsgroup-processable)
10255           gnus-process-mark)
10256          ((memq article gnus-newsgroup-cached)
10257           gnus-cached-mark)
10258          ((memq article gnus-newsgroup-replied)
10259           gnus-replied-mark)
10260          ((memq article gnus-newsgroup-forwarded)
10261           gnus-forwarded-mark)
10262          ((memq article gnus-newsgroup-saved)
10263           gnus-saved-mark)
10264          ((memq article gnus-newsgroup-recent)
10265           gnus-recent-mark)
10266          ((memq article gnus-newsgroup-unseen)
10267           gnus-unseen-mark)
10268          (t gnus-no-mark))
10269    'replied)
10270   (when (gnus-visual-p 'summary-highlight 'highlight)
10271     (gnus-run-hooks 'gnus-summary-update-hook))
10272   t)
10273
10274 (defun gnus-summary-update-download-mark (article)
10275   "Update the download mark."
10276   (gnus-summary-update-mark
10277    (cond ((memq article gnus-newsgroup-undownloaded)
10278           gnus-undownloaded-mark)
10279          (gnus-newsgroup-agentized
10280           gnus-downloaded-mark)
10281          (t
10282           gnus-no-mark))
10283    'download)
10284   (gnus-summary-update-line t)
10285   t)
10286
10287 (defun gnus-summary-update-mark (mark type)
10288   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10289         (buffer-read-only nil))
10290     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10291     (when forward
10292       (when (looking-at "\r")
10293         (incf forward))
10294       (when (<= (+ forward (point)) (point-max))
10295         ;; Go to the right position on the line.
10296         (goto-char (+ forward (point)))
10297         ;; Replace the old mark with the new mark.
10298         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10299         ;; Optionally update the marks by some user rule.
10300         (when (eq type 'unread)
10301           (gnus-data-set-mark
10302            (gnus-data-find (gnus-summary-article-number)) mark)
10303           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10304
10305 (defun gnus-mark-article-as-read (article &optional mark)
10306   "Enter ARTICLE in the pertinent lists and remove it from others."
10307   ;; Make the article expirable.
10308   (let ((mark (or mark gnus-del-mark)))
10309     (setq gnus-newsgroup-expirable
10310           (if (= mark gnus-expirable-mark)
10311               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10312             (delq article gnus-newsgroup-expirable)))
10313     ;; Remove from unread and marked lists.
10314     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10315     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10316     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10317     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10318     (push (cons article mark) gnus-newsgroup-reads)
10319     ;; Possibly remove from cache, if that is used.
10320     (when gnus-use-cache
10321       (gnus-cache-enter-remove-article article))
10322     t))
10323
10324 (defun gnus-mark-article-as-unread (article &optional mark)
10325   "Enter ARTICLE in the pertinent lists and remove it from others."
10326   (let ((mark (or mark gnus-ticked-mark)))
10327     (if (<= article 0)
10328         (progn
10329           (gnus-error 1 "Can't mark negative article numbers")
10330           nil)
10331       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10332             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10333             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10334             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10335             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10336
10337       ;; Unsuppress duplicates?
10338       (when gnus-suppress-duplicates
10339         (gnus-dup-unsuppress-article article))
10340
10341       (cond ((= mark gnus-ticked-mark)
10342              (setq gnus-newsgroup-marked
10343                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10344             ((= mark gnus-spam-mark)
10345              (setq gnus-newsgroup-spam-marked
10346                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10347                                             article)))
10348             ((= mark gnus-dormant-mark)
10349              (setq gnus-newsgroup-dormant
10350                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10351             (t
10352              (setq gnus-newsgroup-unreads
10353                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10354       (gnus-pull article gnus-newsgroup-reads)
10355       t)))
10356
10357 (defalias 'gnus-summary-mark-as-unread-forward
10358   'gnus-summary-tick-article-forward)
10359 (make-obsolete 'gnus-summary-mark-as-unread-forward
10360                'gnus-summary-tick-article-forward)
10361 (defun gnus-summary-tick-article-forward (n)
10362   "Tick N articles forwards.
10363 If N is negative, tick backwards instead.
10364 The difference between N and the number of articles ticked is returned."
10365   (interactive "p")
10366   (gnus-summary-mark-forward n gnus-ticked-mark))
10367
10368 (defalias 'gnus-summary-mark-as-unread-backward
10369   'gnus-summary-tick-article-backward)
10370 (make-obsolete 'gnus-summary-mark-as-unread-backward
10371                'gnus-summary-tick-article-backward)
10372 (defun gnus-summary-tick-article-backward (n)
10373   "Tick N articles backwards.
10374 The difference between N and the number of articles ticked is returned."
10375   (interactive "p")
10376   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10377
10378 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10379 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10380 (defun gnus-summary-tick-article (&optional article clear-mark)
10381   "Mark current article as unread.
10382 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10383 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10384   (interactive)
10385   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10386                                        gnus-ticked-mark)))
10387
10388 (defun gnus-summary-mark-as-read-forward (n)
10389   "Mark N articles as read forwards.
10390 If N is negative, mark backwards instead.
10391 The difference between N and the actual number of articles marked is
10392 returned."
10393   (interactive "p")
10394   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10395
10396 (defun gnus-summary-mark-as-read-backward (n)
10397   "Mark the N articles as read backwards.
10398 The difference between N and the actual number of articles marked is
10399 returned."
10400   (interactive "p")
10401   (gnus-summary-mark-forward
10402    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10403
10404 (defun gnus-summary-mark-as-read (&optional article mark)
10405   "Mark current article as read.
10406 ARTICLE specifies the article to be marked as read.
10407 MARK specifies a string to be inserted at the beginning of the line."
10408   (gnus-summary-mark-article article mark))
10409
10410 (defun gnus-summary-clear-mark-forward (n)
10411   "Clear marks from N articles forward.
10412 If N is negative, clear backward instead.
10413 The difference between N and the number of marks cleared is returned."
10414   (interactive "p")
10415   (gnus-summary-mark-forward n gnus-unread-mark))
10416
10417 (defun gnus-summary-clear-mark-backward (n)
10418   "Clear marks from N articles backward.
10419 The difference between N and the number of marks cleared is returned."
10420   (interactive "p")
10421   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10422
10423 (defun gnus-summary-mark-unread-as-read ()
10424   "Intended to be used by `gnus-summary-mark-article-hook'."
10425   (when (memq gnus-current-article gnus-newsgroup-unreads)
10426     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10427
10428 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10429   "Intended to be used by `gnus-summary-mark-article-hook'."
10430   (let ((mark (gnus-summary-article-mark)))
10431     (when (or (gnus-unread-mark-p mark)
10432               (gnus-read-mark-p mark))
10433       (gnus-summary-mark-article gnus-current-article
10434                                  (or new-mark gnus-read-mark)))))
10435
10436 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10437   "Intended to be used by `gnus-summary-mark-article-hook'."
10438   (let ((mark (gnus-summary-article-mark)))
10439     (when (or (gnus-unread-mark-p mark)
10440               (gnus-read-mark-p mark))
10441       (gnus-summary-mark-article (gnus-summary-article-number)
10442                                  (or new-mark gnus-read-mark)))))
10443
10444 (defun gnus-summary-mark-unread-as-ticked ()
10445   "Intended to be used by `gnus-summary-mark-article-hook'."
10446   (when (memq gnus-current-article gnus-newsgroup-unreads)
10447     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10448
10449 (defun gnus-summary-mark-region-as-read (point mark all)
10450   "Mark all unread articles between point and mark as read.
10451 If given a prefix, mark all articles between point and mark as read,
10452 even ticked and dormant ones."
10453   (interactive "r\nP")
10454   (save-excursion
10455     (let (article)
10456       (goto-char point)
10457       (beginning-of-line)
10458       (while (and
10459               (< (point) mark)
10460               (progn
10461                 (when (or all
10462                           (memq (setq article (gnus-summary-article-number))
10463                                 gnus-newsgroup-unreads))
10464                   (gnus-summary-mark-article article gnus-del-mark))
10465                 t)
10466               (gnus-summary-find-next))))))
10467
10468 (defun gnus-summary-mark-below (score mark)
10469   "Mark articles with score less than SCORE with MARK."
10470   (interactive "P\ncMark: ")
10471   (setq score (if score
10472                   (prefix-numeric-value score)
10473                 (or gnus-summary-default-score 0)))
10474   (save-excursion
10475     (set-buffer gnus-summary-buffer)
10476     (goto-char (point-min))
10477     (while
10478         (progn
10479           (and (< (gnus-summary-article-score) score)
10480                (gnus-summary-mark-article nil mark))
10481           (gnus-summary-find-next)))))
10482
10483 (defun gnus-summary-kill-below (&optional score)
10484   "Mark articles with score below SCORE as read."
10485   (interactive "P")
10486   (gnus-summary-mark-below score gnus-killed-mark))
10487
10488 (defun gnus-summary-clear-above (&optional score)
10489   "Clear all marks from articles with score above SCORE."
10490   (interactive "P")
10491   (gnus-summary-mark-above score gnus-unread-mark))
10492
10493 (defun gnus-summary-tick-above (&optional score)
10494   "Tick all articles with score above SCORE."
10495   (interactive "P")
10496   (gnus-summary-mark-above score gnus-ticked-mark))
10497
10498 (defun gnus-summary-mark-above (score mark)
10499   "Mark articles with score over SCORE with MARK."
10500   (interactive "P\ncMark: ")
10501   (setq score (if score
10502                   (prefix-numeric-value score)
10503                 (or gnus-summary-default-score 0)))
10504   (save-excursion
10505     (set-buffer gnus-summary-buffer)
10506     (goto-char (point-min))
10507     (while (and (progn
10508                   (when (> (gnus-summary-article-score) score)
10509                     (gnus-summary-mark-article nil mark))
10510                   t)
10511                 (gnus-summary-find-next)))))
10512
10513 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10514 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10515 (defun gnus-summary-limit-include-expunged (&optional no-error)
10516   "Display all the hidden articles that were expunged for low scores."
10517   (interactive)
10518   (let ((buffer-read-only nil))
10519     (let ((scored gnus-newsgroup-scored)
10520           headers h)
10521       (while scored
10522         (unless (gnus-summary-article-header (caar scored))
10523           (and (setq h (gnus-number-to-header (caar scored)))
10524                (< (cdar scored) gnus-summary-expunge-below)
10525                (push h headers)))
10526         (setq scored (cdr scored)))
10527       (if (not headers)
10528           (when (not no-error)
10529             (error "No expunged articles hidden"))
10530         (goto-char (point-min))
10531         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10532         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10533         (mapcar (lambda (x) (push (mail-header-number x)
10534                                   gnus-newsgroup-limit))
10535                 headers)
10536         (gnus-summary-prepare-unthreaded (nreverse headers))
10537         (goto-char (point-min))
10538         (gnus-summary-position-point)
10539         t))))
10540
10541 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10542   "Mark all unread articles in this newsgroup as read.
10543 If prefix argument ALL is non-nil, ticked and dormant articles will
10544 also be marked as read.
10545 If QUIETLY is non-nil, no questions will be asked.
10546
10547 If TO-HERE is non-nil, it should be a point in the buffer.  All
10548 articles before (after, if REVERSE is set) this point will be marked
10549 as read.
10550
10551 Note that this function will only catch up the unread article
10552 in the current summary buffer limitation.
10553
10554 The number of articles marked as read is returned."
10555   (interactive "P")
10556   (prog1
10557       (save-excursion
10558         (when (or quietly
10559                   (not gnus-interactive-catchup) ;Without confirmation?
10560                   gnus-expert-user
10561                   (gnus-y-or-n-p
10562                    (if all
10563                        "Mark absolutely all articles as read? "
10564                      "Mark all unread articles as read? ")))
10565           (if (and not-mark
10566                    (not gnus-newsgroup-adaptive)
10567                    (not gnus-newsgroup-auto-expire)
10568                    (not gnus-suppress-duplicates)
10569                    (or (not gnus-use-cache)
10570                        (eq gnus-use-cache 'passive)))
10571               (progn
10572                 (when all
10573                   (setq gnus-newsgroup-marked nil
10574                         gnus-newsgroup-spam-marked nil
10575                         gnus-newsgroup-dormant nil))
10576                 (setq gnus-newsgroup-unreads
10577                       (gnus-sorted-nunion
10578                        (gnus-intersection gnus-newsgroup-unreads
10579                                           gnus-newsgroup-downloadable)
10580                        gnus-newsgroup-unfetched)))
10581             ;; We actually mark all articles as canceled, which we
10582             ;; have to do when using auto-expiry or adaptive scoring.
10583             (gnus-summary-show-all-threads)
10584             (if (and to-here reverse)
10585                 (progn
10586                   (goto-char to-here)
10587                   (gnus-summary-mark-current-read-and-unread-as-read
10588                    gnus-catchup-mark)
10589                   (while (gnus-summary-find-next (not all))
10590                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10591               (when (gnus-summary-first-subject (not all))
10592                 (while (and
10593                         (if to-here (< (point) to-here) t)
10594                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10595                         (gnus-summary-find-next (not all))))))
10596             (gnus-set-mode-line 'summary))
10597           t))
10598     (gnus-summary-position-point)))
10599
10600 (defun gnus-summary-catchup-to-here (&optional all)
10601   "Mark all unticked articles before the current one as read.
10602 If ALL is non-nil, also mark ticked and dormant articles as read."
10603   (interactive "P")
10604   (save-excursion
10605     (gnus-save-hidden-threads
10606       (let ((beg (point)))
10607         ;; We check that there are unread articles.
10608         (when (or all (gnus-summary-find-prev))
10609           (gnus-summary-catchup all t beg)))))
10610   (gnus-summary-position-point))
10611
10612 (defun gnus-summary-catchup-from-here (&optional all)
10613   "Mark all unticked articles after (and including) the current one as read.
10614 If ALL is non-nil, also mark ticked and dormant articles as read."
10615   (interactive "P")
10616   (save-excursion
10617     (gnus-save-hidden-threads
10618       (let ((beg (point)))
10619         ;; We check that there are unread articles.
10620         (when (or all (gnus-summary-find-next))
10621           (gnus-summary-catchup all t beg nil t)))))
10622   (gnus-summary-position-point))
10623
10624 (defun gnus-summary-catchup-all (&optional quietly)
10625   "Mark all articles in this newsgroup as read.
10626 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10627 instead, which marks only unread articles as read."
10628   (interactive "P")
10629   (gnus-summary-catchup t quietly))
10630
10631 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10632   "Mark all unread articles in this group as read, then exit.
10633 If prefix argument ALL is non-nil, all articles are marked as read.
10634 If QUIETLY is non-nil, no questions will be asked."
10635   (interactive "P")
10636   (when (gnus-summary-catchup all quietly nil 'fast)
10637     ;; Select next newsgroup or exit.
10638     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10639              (eq gnus-auto-select-next 'quietly))
10640         (gnus-summary-next-group nil)
10641       (gnus-summary-exit))))
10642
10643 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10644   "Mark all articles in this newsgroup as read, and then exit.
10645 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10646 instead, which marks only unread articles as read."
10647   (interactive "P")
10648   (gnus-summary-catchup-and-exit t quietly))
10649
10650 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10651   "Mark all articles in this group as read and select the next group.
10652 If given a prefix, mark all articles, unread as well as ticked, as
10653 read."
10654   (interactive "P")
10655   (save-excursion
10656     (gnus-summary-catchup all))
10657   (gnus-summary-next-group))
10658
10659 ;;;
10660 ;;; with article
10661 ;;;
10662
10663 (defmacro gnus-with-article (article &rest forms)
10664   "Select ARTICLE and perform FORMS in the original article buffer.
10665 Then replace the article with the result."
10666   `(progn
10667      ;; We don't want the article to be marked as read.
10668      (let (gnus-mark-article-hook)
10669        (gnus-summary-select-article t t nil ,article))
10670      (set-buffer gnus-original-article-buffer)
10671      ,@forms
10672      (if (not (gnus-check-backend-function
10673                'request-replace-article (car gnus-article-current)))
10674          (gnus-message 5 "Read-only group; not replacing")
10675        (unless (gnus-request-replace-article
10676                 ,article (car gnus-article-current)
10677                 (current-buffer) t)
10678          (error "Couldn't replace article")))
10679      ;; The cache and backlog have to be flushed somewhat.
10680      (when gnus-keep-backlog
10681        (gnus-backlog-remove-article
10682         (car gnus-article-current) (cdr gnus-article-current)))
10683      (when gnus-use-cache
10684        (gnus-cache-update-article
10685         (car gnus-article-current) (cdr gnus-article-current)))))
10686
10687 (put 'gnus-with-article 'lisp-indent-function 1)
10688 (put 'gnus-with-article 'edebug-form-spec '(form body))
10689
10690 ;; Thread-based commands.
10691
10692 (defun gnus-summary-articles-in-thread (&optional article)
10693   "Return a list of all articles in the current thread.
10694 If ARTICLE is non-nil, return all articles in the thread that starts
10695 with that article."
10696   (let* ((article (or article (gnus-summary-article-number)))
10697          (data (gnus-data-find-list article))
10698          (top-level (gnus-data-level (car data)))
10699          (top-subject
10700           (cond ((null gnus-thread-operation-ignore-subject)
10701                  (gnus-simplify-subject-re
10702                   (mail-header-subject (gnus-data-header (car data)))))
10703                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10704                  (gnus-simplify-subject-fuzzy
10705                   (mail-header-subject (gnus-data-header (car data)))))
10706                 (t nil)))
10707          (end-point (save-excursion
10708                       (if (gnus-summary-go-to-next-thread)
10709                           (point) (point-max))))
10710          articles)
10711     (while (and data
10712                 (< (gnus-data-pos (car data)) end-point))
10713       (when (or (not top-subject)
10714                 (string= top-subject
10715                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10716                              (gnus-simplify-subject-fuzzy
10717                               (mail-header-subject
10718                                (gnus-data-header (car data))))
10719                            (gnus-simplify-subject-re
10720                             (mail-header-subject
10721                              (gnus-data-header (car data)))))))
10722         (push (gnus-data-number (car data)) articles))
10723       (unless (and (setq data (cdr data))
10724                    (> (gnus-data-level (car data)) top-level))
10725         (setq data nil)))
10726     ;; Return the list of articles.
10727     (nreverse articles)))
10728
10729 (defun gnus-summary-rethread-current ()
10730   "Rethread the thread the current article is part of."
10731   (interactive)
10732   (let* ((gnus-show-threads t)
10733          (article (gnus-summary-article-number))
10734          (id (mail-header-id (gnus-summary-article-header)))
10735          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10736     (unless id
10737       (error "No article on the current line"))
10738     (gnus-rebuild-thread id)
10739     (gnus-summary-goto-subject article)))
10740
10741 (defun gnus-summary-reparent-thread ()
10742   "Make the current article child of the marked (or previous) article.
10743
10744 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10745 is non-nil or the Subject: of both articles are the same."
10746   (interactive)
10747   (unless (not (gnus-group-read-only-p))
10748     (error "The current newsgroup does not support article editing"))
10749   (unless (<= (length gnus-newsgroup-processable) 1)
10750     (error "No more than one article may be marked"))
10751   (save-window-excursion
10752     (let ((gnus-article-buffer " *reparent*")
10753           (current-article (gnus-summary-article-number))
10754           ;; First grab the marked article, otherwise one line up.
10755           (parent-article (if (not (null gnus-newsgroup-processable))
10756                               (car gnus-newsgroup-processable)
10757                             (save-excursion
10758                               (if (eq (forward-line -1) 0)
10759                                   (gnus-summary-article-number)
10760                                 (error "Beginning of summary buffer"))))))
10761       (unless (not (eq current-article parent-article))
10762         (error "An article may not be self-referential"))
10763       (let ((message-id (mail-header-id
10764                          (gnus-summary-article-header parent-article))))
10765         (unless (and message-id (not (equal message-id "")))
10766           (error "No message-id in desired parent"))
10767         (gnus-with-article current-article
10768           (save-restriction
10769             (goto-char (point-min))
10770             (message-narrow-to-head)
10771             (if (re-search-forward "^References: " nil t)
10772                 (progn
10773                   (re-search-forward "^[^ \t]" nil t)
10774                   (forward-line -1)
10775                   (end-of-line)
10776                   (insert " " message-id))
10777               (insert "References: " message-id "\n"))))
10778         (set-buffer gnus-summary-buffer)
10779         (gnus-summary-unmark-all-processable)
10780         (gnus-summary-update-article current-article)
10781         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10782             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10783         (gnus-summary-rethread-current)
10784         (gnus-message 3 "Article %d is now the child of article %d"
10785                       current-article parent-article)))))
10786
10787 (defun gnus-summary-toggle-threads (&optional arg)
10788   "Toggle showing conversation threads.
10789 If ARG is positive number, turn showing conversation threads on."
10790   (interactive "P")
10791   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10792     (setq gnus-show-threads
10793           (if (null arg) (not gnus-show-threads)
10794             (> (prefix-numeric-value arg) 0)))
10795     (gnus-summary-prepare)
10796     (gnus-summary-goto-subject current)
10797     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10798     (gnus-summary-position-point)))
10799
10800 (defun gnus-summary-show-all-threads ()
10801   "Show all threads."
10802   (interactive)
10803   (save-excursion
10804     (let ((buffer-read-only nil))
10805       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10806   (gnus-summary-position-point))
10807
10808 (defun gnus-summary-show-thread ()
10809   "Show thread subtrees.
10810 Returns nil if no thread was there to be shown."
10811   (interactive)
10812   (let ((buffer-read-only nil)
10813         (orig (point))
10814         (end (point-at-eol))
10815         ;; Leave point at bol
10816         (beg (progn (beginning-of-line) (point))))
10817     (prog1
10818         ;; Any hidden lines here?
10819         (search-forward "\r" end t)
10820       (subst-char-in-region beg end ?\^M ?\n t)
10821       (goto-char orig)
10822       (gnus-summary-position-point))))
10823
10824 (defun gnus-summary-maybe-hide-threads ()
10825   "If requested, hide the threads that should be hidden."
10826   (when (and gnus-show-threads
10827              gnus-thread-hide-subtree)
10828     (gnus-summary-hide-all-threads
10829      (if (or (consp gnus-thread-hide-subtree)
10830              (functionp gnus-thread-hide-subtree))
10831          (gnus-make-predicate gnus-thread-hide-subtree)
10832        nil))))
10833
10834 ;;; Hiding predicates.
10835
10836 (defun gnus-article-unread-p (header)
10837   (memq (mail-header-number header) gnus-newsgroup-unreads))
10838
10839 (defun gnus-article-unseen-p (header)
10840   (memq (mail-header-number header) gnus-newsgroup-unseen))
10841
10842 (defun gnus-map-articles (predicate articles)
10843   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10844   (apply 'gnus-or (mapcar predicate
10845                           (mapcar 'gnus-summary-article-header articles))))
10846
10847 (defun gnus-summary-hide-all-threads (&optional predicate)
10848   "Hide all thread subtrees.
10849 If PREDICATE is supplied, threads that satisfy this predicate
10850 will not be hidden."
10851   (interactive)
10852   (save-excursion
10853     (goto-char (point-min))
10854     (let ((end nil))
10855       (while (not end)
10856         (when (or (not predicate)
10857                   (gnus-map-articles
10858                    predicate (gnus-summary-article-children)))
10859             (gnus-summary-hide-thread))
10860         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10861   (gnus-summary-position-point))
10862
10863 (defun gnus-summary-hide-thread ()
10864   "Hide thread subtrees.
10865 If PREDICATE is supplied, threads that satisfy this predicate
10866 will not be hidden.
10867 Returns nil if no threads were there to be hidden."
10868   (interactive)
10869   (let ((buffer-read-only nil)
10870         (start (point))
10871         (article (gnus-summary-article-number)))
10872     (goto-char start)
10873     ;; Go forward until either the buffer ends or the subthread
10874     ;; ends.
10875     (when (and (not (eobp))
10876                (or (zerop (gnus-summary-next-thread 1 t))
10877                    (goto-char (point-max))))
10878       (prog1
10879           (if (and (> (point) start)
10880                    (search-backward "\n" start t))
10881               (progn
10882                 (subst-char-in-region start (point) ?\n ?\^M)
10883                 (gnus-summary-goto-subject article))
10884             (goto-char start)
10885             nil)))))
10886
10887 (defun gnus-summary-go-to-next-thread (&optional previous)
10888   "Go to the same level (or less) next thread.
10889 If PREVIOUS is non-nil, go to previous thread instead.
10890 Return the article number moved to, or nil if moving was impossible."
10891   (let ((level (gnus-summary-thread-level))
10892         (way (if previous -1 1))
10893         (beg (point)))
10894     (forward-line way)
10895     (while (and (not (eobp))
10896                 (< level (gnus-summary-thread-level)))
10897       (forward-line way))
10898     (if (eobp)
10899         (progn
10900           (goto-char beg)
10901           nil)
10902       (setq beg (point))
10903       (prog1
10904           (gnus-summary-article-number)
10905         (goto-char beg)))))
10906
10907 (defun gnus-summary-next-thread (n &optional silent)
10908   "Go to the same level next N'th thread.
10909 If N is negative, search backward instead.
10910 Returns the difference between N and the number of skips actually
10911 done.
10912
10913 If SILENT, don't output messages."
10914   (interactive "p")
10915   (let ((backward (< n 0))
10916         (n (abs n)))
10917     (while (and (> n 0)
10918                 (gnus-summary-go-to-next-thread backward))
10919       (decf n))
10920     (unless silent
10921       (gnus-summary-position-point))
10922     (when (and (not silent) (/= 0 n))
10923       (gnus-message 7 "No more threads"))
10924     n))
10925
10926 (defun gnus-summary-prev-thread (n)
10927   "Go to the same level previous N'th thread.
10928 Returns the difference between N and the number of skips actually
10929 done."
10930   (interactive "p")
10931   (gnus-summary-next-thread (- n)))
10932
10933 (defun gnus-summary-go-down-thread ()
10934   "Go down one level in the current thread."
10935   (let ((children (gnus-summary-article-children)))
10936     (when children
10937       (gnus-summary-goto-subject (car children)))))
10938
10939 (defun gnus-summary-go-up-thread ()
10940   "Go up one level in the current thread."
10941   (let ((parent (gnus-summary-article-parent)))
10942     (when parent
10943       (gnus-summary-goto-subject parent))))
10944
10945 (defun gnus-summary-down-thread (n)
10946   "Go down thread N steps.
10947 If N is negative, go up instead.
10948 Returns the difference between N and how many steps down that were
10949 taken."
10950   (interactive "p")
10951   (let ((up (< n 0))
10952         (n (abs n)))
10953     (while (and (> n 0)
10954                 (if up (gnus-summary-go-up-thread)
10955                   (gnus-summary-go-down-thread)))
10956       (setq n (1- n)))
10957     (gnus-summary-position-point)
10958     (when (/= 0 n)
10959       (gnus-message 7 "Can't go further"))
10960     n))
10961
10962 (defun gnus-summary-up-thread (n)
10963   "Go up thread N steps.
10964 If N is negative, go down instead.
10965 Returns the difference between N and how many steps down that were
10966 taken."
10967   (interactive "p")
10968   (gnus-summary-down-thread (- n)))
10969
10970 (defun gnus-summary-top-thread ()
10971   "Go to the top of the thread."
10972   (interactive)
10973   (while (gnus-summary-go-up-thread))
10974   (gnus-summary-article-number))
10975
10976 (defun gnus-summary-kill-thread (&optional unmark)
10977   "Mark articles under current thread as read.
10978 If the prefix argument is positive, remove any kinds of marks.
10979 If the prefix argument is negative, tick articles instead."
10980   (interactive "P")
10981   (when unmark
10982     (setq unmark (prefix-numeric-value unmark)))
10983   (let ((articles (gnus-summary-articles-in-thread)))
10984     (save-excursion
10985       ;; Expand the thread.
10986       (gnus-summary-show-thread)
10987       ;; Mark all the articles.
10988       (while articles
10989         (gnus-summary-goto-subject (car articles))
10990         (cond ((null unmark)
10991                (gnus-summary-mark-article-as-read gnus-killed-mark))
10992               ((> unmark 0)
10993                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10994               (t
10995                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10996         (setq articles (cdr articles))))
10997     ;; Hide killed subtrees.
10998     (and (null unmark)
10999          gnus-thread-hide-killed
11000          (gnus-summary-hide-thread))
11001     ;; If marked as read, go to next unread subject.
11002     (when (null unmark)
11003       ;; Go to next unread subject.
11004       (gnus-summary-next-subject 1 t)))
11005   (gnus-set-mode-line 'summary))
11006
11007 ;; Summary sorting commands
11008
11009 (defun gnus-summary-sort-by-number (&optional reverse)
11010   "Sort the summary buffer by article number.
11011 Argument REVERSE means reverse order."
11012   (interactive "P")
11013   (gnus-summary-sort 'number reverse))
11014
11015 (defun gnus-summary-sort-by-random (&optional reverse)
11016   "Randomize the order in the summary buffer.
11017 Argument REVERSE means to randomize in reverse order."
11018   (interactive "P")
11019   (gnus-summary-sort 'random reverse))
11020
11021 (defun gnus-summary-sort-by-author (&optional reverse)
11022   "Sort the summary buffer by author name alphabetically.
11023 If `case-fold-search' is non-nil, case of letters is ignored.
11024 Argument REVERSE means reverse order."
11025   (interactive "P")
11026   (gnus-summary-sort 'author reverse))
11027
11028 (defun gnus-summary-sort-by-recipient (&optional reverse)
11029   "Sort the summary buffer by recipient name alphabetically.
11030 If `case-fold-search' is non-nil, case of letters is ignored.
11031 Argument REVERSE means reverse order."
11032   (interactive "P")
11033   (gnus-summary-sort 'recipient reverse))
11034
11035 (defun gnus-summary-sort-by-subject (&optional reverse)
11036   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11037 If `case-fold-search' is non-nil, case of letters is ignored.
11038 Argument REVERSE means reverse order."
11039   (interactive "P")
11040   (gnus-summary-sort 'subject reverse))
11041
11042 (defun gnus-summary-sort-by-date (&optional reverse)
11043   "Sort the summary buffer by date.
11044 Argument REVERSE means reverse order."
11045   (interactive "P")
11046   (gnus-summary-sort 'date reverse))
11047
11048 (defun gnus-summary-sort-by-score (&optional reverse)
11049   "Sort the summary buffer by score.
11050 Argument REVERSE means reverse order."
11051   (interactive "P")
11052   (gnus-summary-sort 'score reverse))
11053
11054 (defun gnus-summary-sort-by-lines (&optional reverse)
11055   "Sort the summary buffer by the number of lines.
11056 Argument REVERSE means reverse order."
11057   (interactive "P")
11058   (gnus-summary-sort 'lines reverse))
11059
11060 (defun gnus-summary-sort-by-chars (&optional reverse)
11061   "Sort the summary buffer by article length.
11062 Argument REVERSE means reverse order."
11063   (interactive "P")
11064   (gnus-summary-sort 'chars reverse))
11065
11066 (defun gnus-summary-sort-by-original (&optional reverse)
11067   "Sort the summary buffer using the default sorting method.
11068 Argument REVERSE means reverse order."
11069   (interactive "P")
11070   (let* ((buffer-read-only)
11071          (gnus-summary-prepare-hook nil))
11072     ;; We do the sorting by regenerating the threads.
11073     (gnus-summary-prepare)
11074     ;; Hide subthreads if needed.
11075     (gnus-summary-maybe-hide-threads)))
11076
11077 (defun gnus-summary-sort (predicate reverse)
11078   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11079   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11080          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11081          (gnus-thread-sort-functions
11082           (if (not reverse)
11083               thread
11084             `(lambda (t1 t2)
11085                (,thread t2 t1))))
11086          (gnus-sort-gathered-threads-function
11087           gnus-thread-sort-functions)
11088          (gnus-article-sort-functions
11089           (if (not reverse)
11090               article
11091             `(lambda (t1 t2)
11092                (,article t2 t1))))
11093          (buffer-read-only)
11094          (gnus-summary-prepare-hook nil))
11095     ;; We do the sorting by regenerating the threads.
11096     (gnus-summary-prepare)
11097     ;; Hide subthreads if needed.
11098     (gnus-summary-maybe-hide-threads)))
11099
11100 ;; Summary saving commands.
11101
11102 (defun gnus-summary-save-article (&optional n not-saved)
11103   "Save the current article using the default saver function.
11104 If N is a positive number, save the N next articles.
11105 If N is a negative number, save the N previous articles.
11106 If N is nil and any articles have been marked with the process mark,
11107 save those articles instead.
11108 The variable `gnus-default-article-saver' specifies the saver function."
11109   (interactive "P")
11110   (let* ((articles (gnus-summary-work-articles n))
11111          (save-buffer (save-excursion
11112                         (nnheader-set-temp-buffer " *Gnus Save*")))
11113          (num (length articles))
11114          header file)
11115     (dolist (article articles)
11116       (setq header (gnus-summary-article-header article))
11117       (if (not (vectorp header))
11118           ;; This is a pseudo-article.
11119           (if (assq 'name header)
11120               (gnus-copy-file (cdr (assq 'name header)))
11121             (gnus-message 1 "Article %d is unsaveable" article))
11122         ;; This is a real article.
11123         (save-window-excursion
11124           (let ((gnus-display-mime-function nil)
11125                 (gnus-article-prepare-hook nil))
11126             (gnus-summary-select-article t nil nil article)))
11127         (save-excursion
11128           (set-buffer save-buffer)
11129           (erase-buffer)
11130           (insert-buffer-substring gnus-original-article-buffer))
11131         (setq file (gnus-article-save save-buffer file num))
11132         (gnus-summary-remove-process-mark article)
11133         (unless not-saved
11134           (gnus-summary-set-saved-mark article))))
11135     (gnus-kill-buffer save-buffer)
11136     (gnus-summary-position-point)
11137     (gnus-set-mode-line 'summary)
11138     n))
11139
11140 (defun gnus-summary-pipe-output (&optional arg headers)
11141   "Pipe the current article to a subprocess.
11142 If N is a positive number, pipe the N next articles.
11143 If N is a negative number, pipe the N previous articles.
11144 If N is nil and any articles have been marked with the process mark,
11145 pipe those articles instead.
11146 If HEADERS (the symbolic prefix), include the headers, too."
11147   (interactive (gnus-interactive "P\ny"))
11148   (require 'gnus-art)
11149   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11150         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11151     (gnus-summary-save-article arg t))
11152   (let ((buffer (get-buffer "*Shell Command Output*")))
11153     (when (and buffer
11154                (not (zerop (buffer-size buffer))))
11155       (gnus-configure-windows 'pipe))))
11156
11157 (defun gnus-summary-save-article-mail (&optional arg)
11158   "Append the current article to an mail file.
11159 If N is a positive number, save the N next articles.
11160 If N is a negative number, save the N previous articles.
11161 If N is nil and any articles have been marked with the process mark,
11162 save those articles instead."
11163   (interactive "P")
11164   (require 'gnus-art)
11165   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11166     (gnus-summary-save-article arg)))
11167
11168 (defun gnus-summary-save-article-rmail (&optional arg)
11169   "Append the current article to an rmail file.
11170 If N is a positive number, save the N next articles.
11171 If N is a negative number, save the N previous articles.
11172 If N is nil and any articles have been marked with the process mark,
11173 save those articles instead."
11174   (interactive "P")
11175   (require 'gnus-art)
11176   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11177     (gnus-summary-save-article arg)))
11178
11179 (defun gnus-summary-save-article-file (&optional arg)
11180   "Append the current article to a file.
11181 If N is a positive number, save the N next articles.
11182 If N is a negative number, save the N previous articles.
11183 If N is nil and any articles have been marked with the process mark,
11184 save those articles instead."
11185   (interactive "P")
11186   (require 'gnus-art)
11187   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11188     (gnus-summary-save-article arg)))
11189
11190 (defun gnus-summary-write-article-file (&optional arg)
11191   "Write the current article to a file, deleting the previous file.
11192 If N is a positive number, save the N next articles.
11193 If N is a negative number, save the N previous articles.
11194 If N is nil and any articles have been marked with the process mark,
11195 save those articles instead."
11196   (interactive "P")
11197   (require 'gnus-art)
11198   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11199     (gnus-summary-save-article arg)))
11200
11201 (defun gnus-summary-save-article-body-file (&optional arg)
11202   "Append the current article body to a file.
11203 If N is a positive number, save the N next articles.
11204 If N is a negative number, save the N previous articles.
11205 If N is nil and any articles have been marked with the process mark,
11206 save those articles instead."
11207   (interactive "P")
11208   (require 'gnus-art)
11209   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11210     (gnus-summary-save-article arg)))
11211
11212 (defun gnus-summary-muttprint (&optional arg)
11213   "Print the current article using Muttprint.
11214 If N is a positive number, save the N next articles.
11215 If N is a negative number, save the N previous articles.
11216 If N is nil and any articles have been marked with the process mark,
11217 save those articles instead."
11218   (interactive "P")
11219   (require 'gnus-art)
11220   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11221     (gnus-summary-save-article arg t)))
11222
11223 (defun gnus-summary-pipe-message (program)
11224   "Pipe the current article through PROGRAM."
11225   (interactive "sProgram: ")
11226   (gnus-summary-select-article)
11227   (let ((mail-header-separator ""))
11228     (gnus-eval-in-buffer-window gnus-article-buffer
11229       (save-restriction
11230         (widen)
11231         (let ((start (window-start))
11232               buffer-read-only)
11233           (message-pipe-buffer-body program)
11234           (set-window-start (get-buffer-window (current-buffer)) start))))))
11235
11236 (defun gnus-get-split-value (methods)
11237   "Return a value based on the split METHODS."
11238   (let (split-name method result match)
11239     (when methods
11240       (save-excursion
11241         (set-buffer gnus-original-article-buffer)
11242         (save-restriction
11243           (nnheader-narrow-to-headers)
11244           (while (and methods (not split-name))
11245             (goto-char (point-min))
11246             (setq method (pop methods))
11247             (setq match (car method))
11248             (when (cond
11249                    ((stringp match)
11250                     ;; Regular expression.
11251                     (ignore-errors
11252                       (re-search-forward match nil t)))
11253                    ((functionp match)
11254                     ;; Function.
11255                     (save-restriction
11256                       (widen)
11257                       (setq result (funcall match gnus-newsgroup-name))))
11258                    ((consp match)
11259                     ;; Form.
11260                     (save-restriction
11261                       (widen)
11262                       (setq result (eval match)))))
11263               (setq split-name (cdr method))
11264               (cond ((stringp result)
11265                      (push (expand-file-name
11266                             result gnus-article-save-directory)
11267                            split-name))
11268                     ((consp result)
11269                      (setq split-name (append result split-name)))))))))
11270     (nreverse split-name)))
11271
11272 (defun gnus-valid-move-group-p (group)
11273   (and (boundp group)
11274        (symbol-name group)
11275        (symbol-value group)
11276        (gnus-get-function (gnus-find-method-for-group
11277                            (symbol-name group)) 'request-accept-article t)))
11278
11279 (defun gnus-read-move-group-name (prompt default articles prefix)
11280   "Read a group name."
11281   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11282          (minibuffer-confirm-incomplete nil) ; XEmacs
11283          (prom
11284           (format "%s %s to"
11285                   prompt
11286                   (if (> (length articles) 1)
11287                       (format "these %d articles" (length articles))
11288                     "this article")))
11289          (to-newsgroup
11290           (cond
11291            ((null split-name)
11292             (gnus-completing-read-with-default
11293              default prom
11294              gnus-active-hashtb
11295              'gnus-valid-move-group-p
11296              nil prefix
11297              'gnus-group-history))
11298            ((= 1 (length split-name))
11299             (gnus-completing-read-with-default
11300              (car split-name) prom
11301              gnus-active-hashtb
11302              'gnus-valid-move-group-p
11303              nil nil
11304              'gnus-group-history))
11305            (t
11306             (gnus-completing-read-with-default
11307              nil prom
11308              (mapcar 'list (nreverse split-name))
11309              nil nil nil
11310              'gnus-group-history))))
11311          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11312     (when to-newsgroup
11313       (if (or (string= to-newsgroup "")
11314               (string= to-newsgroup prefix))
11315           (setq to-newsgroup default))
11316       (unless to-newsgroup
11317         (error "No group name entered"))
11318       (or (gnus-active to-newsgroup)
11319           (gnus-activate-group to-newsgroup nil nil to-method)
11320           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11321                                      to-newsgroup))
11322               (or (and (gnus-request-create-group to-newsgroup to-method)
11323                        (gnus-activate-group
11324                         to-newsgroup nil nil to-method)
11325                        (gnus-subscribe-group to-newsgroup))
11326                   (error "Couldn't create group %s" to-newsgroup)))
11327           (error "No such group: %s" to-newsgroup)))
11328     to-newsgroup))
11329
11330 (defun gnus-summary-save-parts (type dir n &optional reverse)
11331   "Save parts matching TYPE to DIR.
11332 If REVERSE, save parts that do not match TYPE."
11333   (interactive
11334    (list (read-string "Save parts of type: "
11335                       (or (car gnus-summary-save-parts-type-history)
11336                           gnus-summary-save-parts-default-mime)
11337                       'gnus-summary-save-parts-type-history)
11338          (setq gnus-summary-save-parts-last-directory
11339                (read-file-name "Save to directory: "
11340                                gnus-summary-save-parts-last-directory
11341                                nil t))
11342          current-prefix-arg))
11343   (gnus-summary-iterate n
11344     (let ((gnus-display-mime-function nil)
11345           (gnus-inhibit-treatment t))
11346       (gnus-summary-select-article))
11347     (save-excursion
11348       (set-buffer gnus-article-buffer)
11349       (let ((handles (or gnus-article-mime-handles
11350                          (mm-dissect-buffer nil gnus-article-loose-mime)
11351                          (and gnus-article-emulate-mime
11352                               (mm-uu-dissect)))))
11353         (when handles
11354           (gnus-summary-save-parts-1 type dir handles reverse)
11355           (unless gnus-article-mime-handles ;; Don't destroy this case.
11356             (mm-destroy-parts handles)))))))
11357
11358 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11359   (if (stringp (car handle))
11360       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11361               (cdr handle))
11362     (when (if reverse
11363               (not (string-match type (mm-handle-media-type handle)))
11364             (string-match type (mm-handle-media-type handle)))
11365       (let ((file (expand-file-name
11366                    (gnus-map-function
11367                     mm-file-name-rewrite-functions
11368                     (file-name-nondirectory
11369                      (or
11370                       (mail-content-type-get
11371                        (mm-handle-disposition handle) 'filename)
11372                       (mail-content-type-get
11373                        (mm-handle-type handle) 'name)
11374                       (concat gnus-newsgroup-name
11375                               "." (number-to-string
11376                                    (cdr gnus-article-current))))))
11377                    dir)))
11378         (unless (file-exists-p file)
11379           (mm-save-part-to-file handle file))))))
11380
11381 ;; Summary extract commands
11382
11383 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11384   (let ((buffer-read-only nil)
11385         (article (gnus-summary-article-number))
11386         after-article b e)
11387     (unless (gnus-summary-goto-subject article)
11388       (error "No such article: %d" article))
11389     (gnus-summary-position-point)
11390     ;; If all commands are to be bunched up on one line, we collect
11391     ;; them here.
11392     (unless gnus-view-pseudos-separately
11393       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11394             files action)
11395         (while ps
11396           (setq action (cdr (assq 'action (car ps))))
11397           (setq files (list (cdr (assq 'name (car ps)))))
11398           (while (and ps (cdr ps)
11399                       (string= (or action "1")
11400                                (or (cdr (assq 'action (cadr ps))) "2")))
11401             (push (cdr (assq 'name (cadr ps))) files)
11402             (setcdr ps (cddr ps)))
11403           (when files
11404             (when (not (string-match "%s" action))
11405               (push " " files))
11406             (push " " files)
11407             (when (assq 'execute (car ps))
11408               (setcdr (assq 'execute (car ps))
11409                       (funcall (if (string-match "%s" action)
11410                                    'format 'concat)
11411                                action
11412                                (mapconcat
11413                                 (lambda (f)
11414                                   (if (equal f " ")
11415                                       f
11416                                     (shell-quote-argument f)))
11417                                 files " ")))))
11418           (setq ps (cdr ps)))))
11419     (if (and gnus-view-pseudos (not not-view))
11420         (while pslist
11421           (when (assq 'execute (car pslist))
11422             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11423                                   (eq gnus-view-pseudos 'not-confirm)))
11424           (setq pslist (cdr pslist)))
11425       (save-excursion
11426         (while pslist
11427           (setq after-article (or (cdr (assq 'article (car pslist)))
11428                                   (gnus-summary-article-number)))
11429           (gnus-summary-goto-subject after-article)
11430           (forward-line 1)
11431           (setq b (point))
11432           (insert "    " (file-name-nondirectory
11433                           (cdr (assq 'name (car pslist))))
11434                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11435           (setq e (point))
11436           (forward-line -1)             ; back to `b'
11437           (gnus-add-text-properties
11438            b (1- e) (list 'gnus-number gnus-reffed-article-number
11439                           gnus-mouse-face-prop gnus-mouse-face))
11440           (gnus-data-enter
11441            after-article gnus-reffed-article-number
11442            gnus-unread-mark b (car pslist) 0 (- e b))
11443           (setq gnus-newsgroup-unreads
11444                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11445                                          gnus-reffed-article-number))
11446           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11447           (setq pslist (cdr pslist)))))))
11448
11449 (defun gnus-pseudos< (p1 p2)
11450   (let ((c1 (cdr (assq 'action p1)))
11451         (c2 (cdr (assq 'action p2))))
11452     (and c1 c2 (string< c1 c2))))
11453
11454 (defun gnus-request-pseudo-article (props)
11455   (cond ((assq 'execute props)
11456          (gnus-execute-command (cdr (assq 'execute props)))))
11457   (let ((gnus-current-article (gnus-summary-article-number)))
11458     (gnus-run-hooks 'gnus-mark-article-hook)))
11459
11460 (defun gnus-execute-command (command &optional automatic)
11461   (save-excursion
11462     (gnus-article-setup-buffer)
11463     (set-buffer gnus-article-buffer)
11464     (setq buffer-read-only nil)
11465     (let ((command (if automatic command
11466                      (read-string "Command: " (cons command 0)))))
11467       (erase-buffer)
11468       (insert "$ " command "\n\n")
11469       (if gnus-view-pseudo-asynchronously
11470           (start-process "gnus-execute" (current-buffer) shell-file-name
11471                          shell-command-switch command)
11472         (call-process shell-file-name nil t nil
11473                       shell-command-switch command)))))
11474
11475 ;; Summary kill commands.
11476
11477 (defun gnus-summary-edit-global-kill (article)
11478   "Edit the \"global\" kill file."
11479   (interactive (list (gnus-summary-article-number)))
11480   (gnus-group-edit-global-kill article))
11481
11482 (defun gnus-summary-edit-local-kill ()
11483   "Edit a local kill file applied to the current newsgroup."
11484   (interactive)
11485   (setq gnus-current-headers (gnus-summary-article-header))
11486   (gnus-group-edit-local-kill
11487    (gnus-summary-article-number) gnus-newsgroup-name))
11488
11489 ;;; Header reading.
11490
11491 (defun gnus-read-header (id &optional header)
11492   "Read the headers of article ID and enter them into the Gnus system."
11493   (let ((group gnus-newsgroup-name)
11494         (gnus-override-method
11495          (or
11496           gnus-override-method
11497           (and (gnus-news-group-p gnus-newsgroup-name)
11498                (car (gnus-refer-article-methods)))))
11499         where)
11500     ;; First we check to see whether the header in question is already
11501     ;; fetched.
11502     (if (stringp id)
11503         ;; This is a Message-ID.
11504         (setq header (or header (gnus-id-to-header id)))
11505       ;; This is an article number.
11506       (setq header (or header (gnus-summary-article-header id))))
11507     (if (and header
11508              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11509         ;; We have found the header.
11510         header
11511       ;; We have to really fetch the header to this article.
11512       (save-excursion
11513         (set-buffer nntp-server-buffer)
11514         (when (setq where (gnus-request-head id group))
11515           (nnheader-fold-continuation-lines)
11516           (goto-char (point-max))
11517           (insert ".\n")
11518           (goto-char (point-min))
11519           (insert "211 ")
11520           (princ (cond
11521                   ((numberp id) id)
11522                   ((cdr where) (cdr where))
11523                   (header (mail-header-number header))
11524                   (t gnus-reffed-article-number))
11525                  (current-buffer))
11526           (insert " Article retrieved.\n"))
11527         (if (or (not where)
11528                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11529             ()                          ; Malformed head.
11530           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11531             (when (and (stringp id)
11532                        (not (string= (gnus-group-real-name group)
11533                                      (car where))))
11534               ;; If we fetched by Message-ID and the article came
11535               ;; from a different group, we fudge some bogus article
11536               ;; numbers for this article.
11537               (mail-header-set-number header gnus-reffed-article-number))
11538             (save-excursion
11539               (set-buffer gnus-summary-buffer)
11540               (decf gnus-reffed-article-number)
11541               (gnus-remove-header (mail-header-number header))
11542               (push header gnus-newsgroup-headers)
11543               (setq gnus-current-headers header)
11544               (push (mail-header-number header) gnus-newsgroup-limit)))
11545           header)))))
11546
11547 (defun gnus-remove-header (number)
11548   "Remove header NUMBER from `gnus-newsgroup-headers'."
11549   (if (and gnus-newsgroup-headers
11550            (= number (mail-header-number (car gnus-newsgroup-headers))))
11551       (pop gnus-newsgroup-headers)
11552     (let ((headers gnus-newsgroup-headers))
11553       (while (and (cdr headers)
11554                   (not (= number (mail-header-number (cadr headers)))))
11555         (pop headers))
11556       (when (cdr headers)
11557         (setcdr headers (cddr headers))))))
11558
11559 ;;;
11560 ;;; summary highlights
11561 ;;;
11562
11563 (defun gnus-highlight-selected-summary ()
11564   "Highlight selected article in summary buffer."
11565   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11566   (when gnus-summary-selected-face
11567     (save-excursion
11568       (let* ((beg (point-at-bol))
11569              (end (point-at-eol))
11570              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11571              (from (if (get-text-property beg gnus-mouse-face-prop)
11572                        beg
11573                      (or (next-single-property-change
11574                           beg gnus-mouse-face-prop nil end)
11575                          beg)))
11576              (to
11577               (if (= from end)
11578                   (- from 2)
11579                 (or (next-single-property-change
11580                      from gnus-mouse-face-prop nil end)
11581                     end))))
11582         ;; If no mouse-face prop on line we will have to = from = end,
11583         ;; so we highlight the entire line instead.
11584         (when (= (+ to 2) from)
11585           (setq from beg)
11586           (setq to end))
11587         (if gnus-newsgroup-selected-overlay
11588             ;; Move old overlay.
11589             (gnus-move-overlay
11590              gnus-newsgroup-selected-overlay from to (current-buffer))
11591           ;; Create new overlay.
11592           (gnus-overlay-put
11593            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11594            'face gnus-summary-selected-face))))))
11595
11596 (defvar gnus-summary-highlight-line-cached nil)
11597 (defvar gnus-summary-highlight-line-trigger nil)
11598
11599 (defun gnus-summary-highlight-line-0 ()
11600   (if (and (eq gnus-summary-highlight-line-trigger
11601                gnus-summary-highlight)
11602            gnus-summary-highlight-line-cached)
11603       gnus-summary-highlight-line-cached
11604     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11605           gnus-summary-highlight-line-cached
11606           (let* ((cond (list 'cond))
11607                  (c cond)
11608                  (list gnus-summary-highlight))
11609             (while list
11610               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11611                               nil))
11612               (setq c (cdr c)
11613                     list (cdr list)))
11614             (gnus-byte-compile (list 'lambda nil cond))))))
11615
11616 (defun gnus-summary-highlight-line ()
11617   "Highlight current line according to `gnus-summary-highlight'."
11618   (let* ((beg (point-at-bol))
11619          (article (or (gnus-summary-article-number) gnus-current-article))
11620          (score (or (cdr (assq article
11621                                gnus-newsgroup-scored))
11622                     gnus-summary-default-score 0))
11623          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11624          (inhibit-read-only t)
11625          (default gnus-summary-default-score)
11626          (default-high gnus-summary-default-high-score)
11627          (default-low gnus-summary-default-low-score)
11628          (uncached (and gnus-summary-use-undownloaded-faces
11629                         (memq article gnus-newsgroup-undownloaded)
11630                         (not (memq article gnus-newsgroup-cached)))))
11631     (let ((face (funcall (gnus-summary-highlight-line-0))))
11632       (unless (eq face (get-text-property beg 'face))
11633         (gnus-put-text-property-excluding-characters-with-faces
11634          beg (point-at-eol) 'face
11635          (setq face (if (boundp face) (symbol-value face) face)))
11636         (when gnus-summary-highlight-line-function
11637           (funcall gnus-summary-highlight-line-function article face))))))
11638
11639 (defun gnus-update-read-articles (group unread &optional compute)
11640   "Update the list of read articles in GROUP.
11641 UNREAD is a sorted list."
11642   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11643         (info (gnus-get-info group))
11644         (prev 1)
11645         read)
11646     (if (or (not info) (not active))
11647         ;; There is no info on this group if it was, in fact,
11648         ;; killed.  Gnus stores no information on killed groups, so
11649         ;; there's nothing to be done.
11650         ;; One could store the information somewhere temporarily,
11651         ;; perhaps...  Hmmm...
11652         ()
11653       ;; Remove any negative articles numbers.
11654       (while (and unread (< (car unread) 0))
11655         (setq unread (cdr unread)))
11656       ;; Remove any expired article numbers
11657       (while (and unread (< (car unread) (car active)))
11658         (setq unread (cdr unread)))
11659       ;; Compute the ranges of read articles by looking at the list of
11660       ;; unread articles.
11661       (while unread
11662         (when (/= (car unread) prev)
11663           (push (if (= prev (1- (car unread))) prev
11664                   (cons prev (1- (car unread))))
11665                 read))
11666         (setq prev (1+ (car unread)))
11667         (setq unread (cdr unread)))
11668       (when (<= prev (cdr active))
11669         (push (cons prev (cdr active)) read))
11670       (setq read (if (> (length read) 1) (nreverse read) read))
11671       (if compute
11672           read
11673         (save-excursion
11674           (let (setmarkundo)
11675             ;; Propagate the read marks to the backend.
11676             (when (gnus-check-backend-function 'request-set-mark group)
11677               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11678                     (add (gnus-remove-from-range read (gnus-info-read info))))
11679                 (when (or add del)
11680                   (unless (gnus-check-group group)
11681                     (error "Can't open server for %s" group))
11682                   (gnus-request-set-mark
11683                    group (delq nil (list (if add (list add 'add '(read)))
11684                                          (if del (list del 'del '(read))))))
11685                   (setq setmarkundo
11686                         `(gnus-request-set-mark
11687                           ,group
11688                           ',(delq nil (list
11689                                        (if del (list del 'add '(read)))
11690                                        (if add (list add 'del '(read))))))))))
11691             (set-buffer gnus-group-buffer)
11692             (gnus-undo-register
11693               `(progn
11694                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11695                  (gnus-info-set-read ',info ',(gnus-info-read info))
11696                  (gnus-get-unread-articles-in-group ',info
11697                                                     (gnus-active ,group))
11698                  (gnus-group-update-group ,group t)
11699                  ,setmarkundo))))
11700         ;; Enter this list into the group info.
11701         (gnus-info-set-read info read)
11702         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11703         (gnus-get-unread-articles-in-group info (gnus-active group))
11704         t))))
11705
11706 (defun gnus-offer-save-summaries ()
11707   "Offer to save all active summary buffers."
11708   (let (buffers)
11709     ;; Go through all buffers and find all summaries.
11710     (dolist (buffer (buffer-list))
11711       (when (and (setq buffer (buffer-name buffer))
11712                  (string-match "Summary" buffer)
11713                  (with-current-buffer buffer
11714                    ;; We check that this is, indeed, a summary buffer.
11715                    (and (eq major-mode 'gnus-summary-mode)
11716                         ;; Also make sure this isn't bogus.
11717                         gnus-newsgroup-prepared
11718                         ;; Also make sure that this isn't a
11719                         ;; dead summary buffer.
11720                         (not gnus-dead-summary-mode))))
11721         (push buffer buffers)))
11722     ;; Go through all these summary buffers and offer to save them.
11723     (when buffers
11724       (save-excursion
11725         (map-y-or-n-p
11726          "Update summary buffer %s? "
11727          (lambda (buf)
11728            (switch-to-buffer buf)
11729            (gnus-summary-exit))
11730          buffers)))))
11731
11732
11733 ;;; @ for mime-partial
11734 ;;;
11735
11736 (defun gnus-request-partial-message ()
11737   (save-excursion
11738     (let ((number (gnus-summary-article-number))
11739           (group gnus-newsgroup-name)
11740           (mother gnus-article-buffer))
11741       (set-buffer (get-buffer-create " *Partial Article*"))
11742       (erase-buffer)
11743       (setq mime-preview-buffer mother)
11744       (gnus-request-article-this-buffer number group)
11745       (mime-parse-buffer)
11746       )))
11747
11748 (autoload 'mime-combine-message/partial-pieces-automatically
11749   "mime-partial"
11750   "Internal method to combine message/partial messages automatically.")
11751
11752 (mime-add-condition
11753  'action '((type . message)(subtype . partial)
11754            (major-mode . gnus-original-article-mode)
11755            (method . mime-combine-message/partial-pieces-automatically)
11756            (summary-buffer-exp . gnus-summary-buffer)
11757            (request-partial-message-method . gnus-request-partial-message)
11758            ))
11759
11760
11761 ;;; @ for message/rfc822
11762 ;;;
11763
11764 (defun gnus-mime-extract-message/rfc822 (entity situation)
11765   "Burst a forwarded article."
11766   (save-excursion
11767     (set-buffer gnus-summary-buffer)
11768     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11769                                    gnus-newsgroup-name 'gnus-group-history))
11770            (gnus-group-marked (list group))
11771            article info)
11772       (with-temp-buffer
11773         (mime-insert-entity-content entity)
11774         (setq article (gnus-request-accept-article group)))
11775       (when (and (consp article)
11776                  (numberp (setq article (cdr article))))
11777         (setq info (gnus-get-info group))
11778         (gnus-info-set-read info
11779                             (gnus-remove-from-range (gnus-info-read info)
11780                                                     (list article)))
11781         (when (string-equal group gnus-newsgroup-name)
11782           (forward-line 1)
11783           (let (gnus-show-threads)
11784             (gnus-summary-goto-subject article t))
11785           (gnus-summary-clear-mark-forward 1))
11786         (set-buffer gnus-group-buffer)
11787         (gnus-group-get-new-news-this-group nil t)))))
11788
11789 (mime-add-condition
11790  'action '((type . message)(subtype . rfc822)
11791            (major-mode . gnus-original-article-mode)
11792            (method . gnus-mime-extract-message/rfc822)
11793            (mode . "extract")
11794            ))
11795
11796 (mime-add-condition
11797  'action '((type . message)(subtype . news)
11798            (major-mode . gnus-original-article-mode)
11799            (method . gnus-mime-extract-message/rfc822)
11800            (mode . "extract")
11801            ))
11802
11803 (defun gnus-mime-extract-multipart (entity situation)
11804   (let ((children (mime-entity-children entity))
11805         mime-acting-situation-to-override
11806         f)
11807     (while children
11808       (mime-play-entity (car children)
11809                         (cons (assq 'mode situation)
11810                               mime-acting-situation-to-override))
11811       (setq children (cdr children)))
11812     (if (setq f (cdr (assq 'after-method
11813                            mime-acting-situation-to-override)))
11814         (eval f)
11815       )))
11816
11817 (mime-add-condition
11818  'action '((type . multipart)
11819            (method . gnus-mime-extract-multipart)
11820            (mode . "extract")
11821            )
11822  'with-default)
11823
11824
11825 ;;; @ end
11826 ;;;
11827
11828 (defun gnus-summary-inherit-default-charset ()
11829   "Import `default-mime-charset' from summary buffer.
11830 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11831 of FLIM is used."
11832   (if (buffer-live-p gnus-summary-buffer)
11833       (let (d-m-c d-m-c-u)
11834         (with-current-buffer gnus-summary-buffer
11835           (setq d-m-c (if (local-variable-p 'default-mime-charset
11836                                             gnus-summary-buffer)
11837                           default-mime-charset
11838                         t)
11839                 ;; LIMIT
11840                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11841                                               gnus-summary-buffer)
11842                             (symbol-value 'default-mime-charset-unlimited)
11843                           t)))
11844         (if (eq t d-m-c)
11845             (kill-local-variable 'default-mime-charset)
11846           (set (make-local-variable 'default-mime-charset) d-m-c))
11847         (if (eq t d-m-c-u)
11848             (kill-local-variable 'default-mime-charset-unlimited)
11849           (set (make-local-variable 'default-mime-charset-unlimited)
11850                d-m-c-u)))))
11851
11852 (defun gnus-summary-setup-default-charset ()
11853   "Setup newsgroup default charset."
11854   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11855       (progn
11856         (setq gnus-newsgroup-charset nil)
11857         (set (make-local-variable 'default-mime-charset) nil)
11858         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11859           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11860     (let ((ignored-charsets
11861            (or gnus-newsgroup-ephemeral-ignored-charsets
11862                (append
11863                 (and gnus-newsgroup-name
11864                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11865                 gnus-newsgroup-ignored-charsets)))
11866           charset)
11867       (setq gnus-newsgroup-charset
11868             (or gnus-newsgroup-ephemeral-charset
11869                 (when (and gnus-newsgroup-name
11870                            (setq charset (gnus-parameter-charset
11871                                           gnus-newsgroup-name)))
11872                   (make-local-variable 'default-mime-charset)
11873                   (setq default-mime-charset charset))
11874                 gnus-default-charset))
11875       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11876            ignored-charsets))))
11877
11878 ;;;
11879 ;;; Mime Commands
11880 ;;;
11881
11882 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11883   "Display the current article buffer fully MIME-buttonized.
11884 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11885 treated as multipart/mixed."
11886   (interactive "P")
11887   (require 'gnus-art)
11888   (let ((gnus-unbuttonized-mime-types nil)
11889         (gnus-mime-display-multipart-as-mixed show-all-parts))
11890     (gnus-summary-show-article)))
11891
11892 (defun gnus-summary-repair-multipart (article)
11893   "Add a Content-Type header to a multipart article without one."
11894   (interactive (list (gnus-summary-article-number)))
11895   (gnus-with-article article
11896     (message-narrow-to-head)
11897     (message-remove-header "Mime-Version")
11898     (goto-char (point-max))
11899     (insert "Mime-Version: 1.0\n")
11900     (widen)
11901     (when (search-forward "\n--" nil t)
11902       (let ((separator (buffer-substring (point) (point-at-eol))))
11903         (message-narrow-to-head)
11904         (message-remove-header "Content-Type")
11905         (goto-char (point-max))
11906         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11907                         separator))
11908         (widen))))
11909   (let (gnus-mark-article-hook)
11910     (gnus-summary-select-article t t nil article)))
11911
11912 (defun gnus-summary-toggle-display-buttonized ()
11913   "Toggle the buttonizing of the article buffer."
11914   (interactive)
11915   (require 'gnus-art)
11916   (if (setq gnus-inhibit-mime-unbuttonizing
11917             (not gnus-inhibit-mime-unbuttonizing))
11918       (let ((gnus-unbuttonized-mime-types nil))
11919         (gnus-summary-show-article))
11920     (gnus-summary-show-article)))
11921
11922 ;;;
11923 ;;; Intelli-mouse commmands
11924 ;;;
11925
11926 (defun gnus-wheel-summary-scroll (event)
11927   (interactive "e")
11928   (let ((amount (if (memq 'shift (event-modifiers event))
11929                     (car gnus-wheel-scroll-amount)
11930                   (cdr gnus-wheel-scroll-amount)))
11931         (direction (- (* (static-if (featurep 'xemacs)
11932                              (event-button event)
11933                            (cond ((eq 'mouse-4 (event-basic-type event))
11934                                   4)
11935                                  ((eq 'mouse-5 (event-basic-type event))
11936                                   5)))
11937                          2) 9))
11938         edge)
11939     (gnus-summary-scroll-up (* amount direction))
11940     (when (gnus-eval-in-buffer-window gnus-article-buffer
11941             (save-restriction
11942               (widen)
11943               (and (if (< 0 direction)
11944                        (gnus-article-next-page 0)
11945                      (gnus-article-prev-page 0)
11946                      (bobp))
11947                    (if (setq edge (get-text-property
11948                                    (point-min) 'gnus-wheel-edge))
11949                        (setq edge (* edge direction))
11950                      (setq edge -1))
11951                    (or (plusp edge)
11952                        (let ((buffer-read-only nil)
11953                              (inhibit-read-only t))
11954                          (put-text-property (point-min) (point-max)
11955                                             'gnus-wheel-edge direction)
11956                          nil))
11957                    (or (> edge gnus-wheel-edge-resistance)
11958                        (let ((buffer-read-only nil)
11959                              (inhibit-read-only t))
11960                          (put-text-property (point-min) (point-max)
11961                                             'gnus-wheel-edge
11962                                             (* (1+ edge) direction))
11963                          nil))
11964                    (eq last-command 'gnus-wheel-summary-scroll))))
11965       (gnus-summary-next-article nil nil (minusp direction)))))
11966
11967 (defun gnus-wheel-install ()
11968   "Enable mouse wheel support on summary window."
11969   (when gnus-use-wheel
11970     (let ((keys
11971            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11972       (dolist (key keys)
11973         (define-key gnus-summary-mode-map key
11974           'gnus-wheel-summary-scroll)))))
11975
11976 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11977
11978 ;;;
11979 ;;; Traditional PGP commmands
11980 ;;;
11981
11982 (defun gnus-summary-decrypt-article (&optional force)
11983   "Decrypt the current article in traditional PGP way.
11984 This will have permanent effect only in mail groups.
11985 If FORCE is non-nil, allow editing of articles even in read-only
11986 groups."
11987   (interactive "P")
11988   (gnus-summary-select-article t)
11989   (gnus-eval-in-buffer-window gnus-article-buffer
11990     (save-excursion
11991       (save-restriction
11992         (widen)
11993         (goto-char (point-min))
11994         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11995           (error "Not a traditional PGP message!"))
11996         (let ((armor-start (match-beginning 0)))
11997           (if (and (pgg-decrypt-region armor-start (point-max))
11998                    (or force (not (gnus-group-read-only-p))))
11999               (let ((inhibit-read-only t)
12000                     buffer-read-only)
12001                 (delete-region armor-start
12002                                (progn
12003                                  (re-search-forward "^-+END PGP" nil t)
12004                                  (beginning-of-line 2)
12005                                  (point)))
12006                 (insert-buffer-substring pgg-output-buffer))))))))
12007
12008 (defun gnus-summary-verify-article ()
12009   "Verify the current article in traditional PGP way."
12010   (interactive)
12011   (save-excursion
12012     (set-buffer gnus-original-article-buffer)
12013     (goto-char (point-min))
12014     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
12015       (error "Not a traditional PGP message!"))
12016     (re-search-forward "^-+END PGP" nil t)
12017     (beginning-of-line 2)
12018     (call-interactively (function pgg-verify-region))))
12019
12020 ;;;
12021 ;;; Generic summary marking commands
12022 ;;;
12023
12024 (defvar gnus-summary-marking-alist
12025   '((read gnus-del-mark "d")
12026     (unread gnus-unread-mark "u")
12027     (ticked gnus-ticked-mark "!")
12028     (dormant gnus-dormant-mark "?")
12029     (expirable gnus-expirable-mark "e"))
12030   "An alist of names/marks/keystrokes.")
12031
12032 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12033 (defvar gnus-summary-mark-map)
12034
12035 (defun gnus-summary-make-all-marking-commands ()
12036   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12037   (dolist (elem gnus-summary-marking-alist)
12038     (apply 'gnus-summary-make-marking-command elem)))
12039
12040 (defun gnus-summary-make-marking-command (name mark keystroke)
12041   (let ((map (make-sparse-keymap)))
12042     (define-key gnus-summary-generic-mark-map keystroke map)
12043     (dolist (lway `((next "next" next nil "n")
12044                     (next-unread "next unread" next t "N")
12045                     (prev "previous" prev nil "p")
12046                     (prev-unread "previous unread" prev t "P")
12047                     (nomove "" nil nil ,keystroke)))
12048       (let ((func (gnus-summary-make-marking-command-1
12049                    mark (car lway) lway name)))
12050         (setq func (eval func))
12051         (define-key map (nth 4 lway) func)))))
12052
12053 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12054   `(defun ,(intern
12055             (format "gnus-summary-put-mark-as-%s%s"
12056                     name (if (eq way 'nomove)
12057                              ""
12058                            (concat "-" (symbol-name way)))))
12059      (n)
12060      ,(format
12061        "Mark the current article as %s%s.
12062 If N, the prefix, then repeat N times.
12063 If N is negative, move in reverse order.
12064 The difference between N and the actual number of articles marked is
12065 returned."
12066        name (car (cdr lway)))
12067      (interactive "p")
12068      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12069
12070 (defun gnus-summary-generic-mark (n mark move unread)
12071   "Mark N articles with MARK."
12072   (unless (eq major-mode 'gnus-summary-mode)
12073     (error "This command can only be used in the summary buffer"))
12074   (gnus-summary-show-thread)
12075   (let ((nummove
12076          (cond
12077           ((eq move 'next) 1)
12078           ((eq move 'prev) -1)
12079           (t 0))))
12080     (if (zerop nummove)
12081         (setq n 1)
12082       (when (< n 0)
12083         (setq n (abs n)
12084               nummove (* -1 nummove))))
12085     (while (and (> n 0)
12086                 (gnus-summary-mark-article nil mark)
12087                 (zerop (gnus-summary-next-subject nummove unread t)))
12088       (setq n (1- n)))
12089     (when (/= 0 n)
12090       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12091     (gnus-summary-recenter)
12092     (gnus-summary-position-point)
12093     (gnus-set-mode-line 'summary)
12094     n))
12095
12096 (defun gnus-summary-insert-articles (articles)
12097   (when (setq articles
12098               (gnus-sorted-difference articles
12099                                       (mapcar (lambda (h)
12100                                                 (mail-header-number h))
12101                                               gnus-newsgroup-headers)))
12102     (setq gnus-newsgroup-headers
12103           (gnus-merge 'list
12104                       gnus-newsgroup-headers
12105                       (gnus-fetch-headers articles)
12106                       'gnus-article-sort-by-number))
12107     ;; Suppress duplicates?
12108     (when gnus-suppress-duplicates
12109       (gnus-dup-suppress-articles))
12110
12111     ;; We might want to build some more threads first.
12112     (when (and gnus-fetch-old-headers
12113                (eq gnus-headers-retrieved-by 'nov))
12114       (if (eq gnus-fetch-old-headers 'invisible)
12115           (gnus-build-all-threads)
12116         (gnus-build-old-threads)))
12117     ;; Let the Gnus agent mark articles as read.
12118     (when gnus-agent
12119       (gnus-agent-get-undownloaded-list))
12120     ;; Remove list identifiers from subject
12121     (when gnus-list-identifiers
12122       (gnus-summary-remove-list-identifiers))
12123     ;; First and last article in this newsgroup.
12124     (when gnus-newsgroup-headers
12125       (setq gnus-newsgroup-begin
12126             (mail-header-number (car gnus-newsgroup-headers))
12127             gnus-newsgroup-end
12128             (mail-header-number
12129              (gnus-last-element gnus-newsgroup-headers))))
12130     (when gnus-use-scoring
12131       (gnus-possibly-score-headers))))
12132
12133 (defun gnus-summary-insert-old-articles (&optional all)
12134   "Insert all old articles in this group.
12135 If ALL is non-nil, already read articles become readable.
12136 If ALL is a number, fetch this number of articles."
12137   (interactive "P")
12138   (prog1
12139       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12140             older len)
12141         (setq older
12142               ;; Some nntp servers lie about their active range.  When
12143               ;; this happens, the active range can be in the millions.
12144               ;; Use a compressed range to avoid creating a huge list.
12145               (gnus-range-difference (list gnus-newsgroup-active) old))
12146         (setq len (gnus-range-length older))
12147         (cond
12148          ((null older) nil)
12149          ((numberp all)
12150           (if (< all len)
12151               (let ((older-range (nreverse older)))
12152                 (setq older nil)
12153
12154                 (while (> all 0)
12155                   (let* ((r (pop older-range))
12156                          (min (if (numberp r) r (car r)))
12157                          (max (if (numberp r) r (cdr r))))
12158                     (while (and (<= min max)
12159                                 (> all 0))
12160                       (push max older)
12161                       (setq all (1- all)
12162                             max (1- max))))))
12163             (setq older (gnus-uncompress-range older))))
12164          (all
12165           (setq older (gnus-uncompress-range older)))
12166          (t
12167           (when (and (numberp gnus-large-newsgroup)
12168                    (> len gnus-large-newsgroup))
12169               (let* ((cursor-in-echo-area nil)
12170                      (initial (gnus-parameter-large-newsgroup-initial
12171                                gnus-newsgroup-name))
12172                      (input
12173                       (read-string
12174                        (format
12175                         "How many articles from %s (%s %d): "
12176                         (gnus-limit-string
12177                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12178                         (if initial "max" "default")
12179                         len)
12180                        (if initial
12181                            (cons (number-to-string initial)
12182                                  0)))))
12183                 (unless (string-match "^[ \t]*$" input)
12184                   (setq all (string-to-number input))
12185                   (if (< all len)
12186                       (let ((older-range (nreverse older)))
12187                         (setq older nil)
12188
12189                         (while (> all 0)
12190                           (let* ((r (pop older-range))
12191                                  (min (if (numberp r) r (car r)))
12192                                  (max (if (numberp r) r (cdr r))))
12193                             (while (and (<= min max)
12194                                         (> all 0))
12195                               (push max older)
12196                               (setq all (1- all)
12197                                     max (1- max))))))))))
12198           (setq older (gnus-uncompress-range older))))
12199         (if (not older)
12200             (message "No old news.")
12201           (gnus-summary-insert-articles older)
12202           (gnus-summary-limit (gnus-sorted-nunion old older))))
12203     (gnus-summary-position-point)))
12204
12205 (defun gnus-summary-insert-new-articles ()
12206   "Insert all new articles in this group."
12207   (interactive)
12208   (prog1
12209       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12210             (old-active gnus-newsgroup-active)
12211             (nnmail-fetched-sources (list t))
12212             i new)
12213         (setq gnus-newsgroup-active
12214               (gnus-activate-group gnus-newsgroup-name 'scan))
12215         (setq i (cdr gnus-newsgroup-active))
12216         (while (> i (cdr old-active))
12217           (push i new)
12218           (decf i))
12219         (if (not new)
12220             (message "No gnus is bad news")
12221           (gnus-summary-insert-articles new)
12222           (setq gnus-newsgroup-unreads
12223                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12224           (gnus-summary-limit (gnus-sorted-nunion old new))))
12225     (gnus-summary-position-point)))
12226
12227 (gnus-summary-make-all-marking-commands)
12228
12229 (gnus-ems-redefine)
12230
12231 (provide 'gnus-sum)
12232
12233 (run-hooks 'gnus-sum-load-hook)
12234
12235 ;; Local Variables:
12236 ;; coding: iso-8859-1
12237 ;; End:
12238
12239 ;;; gnus-sum.el ends here