Synch to No Gnus 200401202256.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile
32   (require 'cl)
33   (defvar tool-bar-map))
34
35 (require 'gnus)
36 (require 'gnus-group)
37 (require 'gnus-spec)
38 (require 'gnus-range)
39 (require 'gnus-int)
40 (require 'gnus-undo)
41 (require 'gnus-util)
42 (require 'nnoo)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
55 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
56 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
59   "Deuglify broken Outlook (Express) articles and redisplay."
60   t)
61 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
62 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
63 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
64
65 (defcustom gnus-kill-summary-on-exit t
66   "*If non-nil, kill the summary buffer when you exit from it.
67 If nil, the summary will become a \"*Dead Summary*\" buffer, and
68 it will be killed sometime later."
69   :group 'gnus-summary-exit
70   :type 'boolean)
71
72 (defcustom gnus-fetch-old-headers nil
73   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
74 If an unread article in the group refers to an older, already read (or
75 just marked as read) article, the old article will not normally be
76 displayed in the Summary buffer.  If this variable is non-nil, Gnus
77 will attempt to grab the headers to the old articles, and thereby
78 build complete threads.  If it has the value `some', only enough
79 headers to connect otherwise loose threads will be displayed.  This
80 variable can also be a number.  In that case, no more than that number
81 of old headers will be fetched.  If it has the value `invisible', all
82 old headers will be fetched, but none will be displayed.
83
84 The server has to support NOV for any of this to work."
85   :group 'gnus-thread
86   :type '(choice (const :tag "off" nil)
87                  (const some)
88                  number
89                  (sexp :menu-tag "other" t)))
90
91 (defcustom gnus-refer-thread-limit 200
92   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
93 If t, fetch all the available old headers."
94   :group 'gnus-thread
95   :type '(choice number
96                  (sexp :menu-tag "other" t)))
97
98 (defcustom gnus-summary-make-false-root 'adopt
99   "*nil means that Gnus won't gather loose threads.
100 If the root of a thread has expired or been read in a previous
101 session, the information necessary to build a complete thread has been
102 lost.  Instead of having many small sub-threads from this original thread
103 scattered all over the summary buffer, Gnus can gather them.
104
105 If non-nil, Gnus will try to gather all loose sub-threads from an
106 original thread into one large thread.
107
108 If this variable is non-nil, it should be one of `none', `adopt',
109 `dummy' or `empty'.
110
111 If this variable is `none', Gnus will not make a false root, but just
112 present the sub-threads after another.
113 If this variable is `dummy', Gnus will create a dummy root that will
114 have all the sub-threads as children.
115 If this variable is `adopt', Gnus will make one of the \"children\"
116 the parent and mark all the step-children as such.
117 If this variable is `empty', the \"children\" are printed with empty
118 subject fields.  (Or rather, they will be printed with a string
119 given by the `gnus-summary-same-subject' variable.)"
120   :group 'gnus-thread
121   :type '(choice (const :tag "off" nil)
122                  (const none)
123                  (const dummy)
124                  (const adopt)
125                  (const empty)))
126
127 (defcustom gnus-summary-make-false-root-always nil
128   "Always make a false dummy root."
129   :group 'gnus-thread
130   :type 'boolean)
131
132 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
133   "*A regexp to match subjects to be excluded from loose thread gathering.
134 As loose thread gathering is done on subjects only, that means that
135 there can be many false gatherings performed.  By rooting out certain
136 common subjects, gathering might become saner."
137   :group 'gnus-thread
138   :type 'regexp)
139
140 (defcustom gnus-summary-gather-subject-limit nil
141   "*Maximum length of subject comparisons when gathering loose threads.
142 Use nil to compare full subjects.  Setting this variable to a low
143 number will help gather threads that have been corrupted by
144 newsreaders chopping off subject lines, but it might also mean that
145 unrelated articles that have subject that happen to begin with the
146 same few characters will be incorrectly gathered.
147
148 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
149 comparing subjects."
150   :group 'gnus-thread
151   :type '(choice (const :tag "off" nil)
152                  (const fuzzy)
153                  (sexp :menu-tag "on" t)))
154
155 (defcustom gnus-simplify-subject-functions nil
156   "List of functions taking a string argument that simplify subjects.
157 The functions are applied recursively.
158
159 Useful functions to put in this list include:
160 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
161 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
162   :group 'gnus-thread
163   :type '(repeat function))
164
165 (defcustom gnus-simplify-ignored-prefixes nil
166   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  regexp))
170
171 (defcustom gnus-build-sparse-threads nil
172   "*If non-nil, fill in the gaps in threads.
173 If `some', only fill in the gaps that are needed to tie loose threads
174 together.  If `more', fill in all leaf nodes that Gnus can find.  If
175 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
176   :group 'gnus-thread
177   :type '(choice (const :tag "off" nil)
178                  (const some)
179                  (const more)
180                  (sexp :menu-tag "all" t)))
181
182 (defcustom gnus-summary-thread-gathering-function
183   'gnus-gather-threads-by-subject
184   "*Function used for gathering loose threads.
185 There are two pre-defined functions: `gnus-gather-threads-by-subject',
186 which only takes Subjects into consideration; and
187 `gnus-gather-threads-by-references', which compared the References
188 headers of the articles to find matches."
189   :group 'gnus-thread
190   :type '(radio (function-item gnus-gather-threads-by-subject)
191                 (function-item gnus-gather-threads-by-references)
192                 (function :tag "other")))
193
194 (defcustom gnus-summary-same-subject ""
195   "*String indicating that the current article has the same subject as the previous.
196 This variable will only be used if the value of
197 `gnus-summary-make-false-root' is `empty'."
198   :group 'gnus-summary-format
199   :type 'string)
200
201 (defcustom gnus-summary-goto-unread t
202   "*If t, many commands will go to the next unread article.
203 This applies to marking commands as well as other commands that
204 \"naturally\" select the next article, like, for instance, `SPC' at
205 the end of an article.
206
207 If nil, the marking commands do NOT go to the next unread article
208 \(they go to the next article instead).  If `never', commands that
209 usually go to the next unread article, will go to the next article,
210 whether it is read or not."
211   :group 'gnus-summary-marks
212   :link '(custom-manual "(gnus)Setting Marks")
213   :type '(choice (const :tag "off" nil)
214                  (const never)
215                  (sexp :menu-tag "on" t)))
216
217 (defcustom gnus-summary-default-score 0
218   "*Default article score level.
219 All scores generated by the score files will be added to this score.
220 If this variable is nil, scoring will be disabled."
221   :group 'gnus-score-default
222   :type '(choice (const :tag "disable")
223                  integer))
224
225 (defcustom gnus-summary-default-high-score 0
226   "*Default threshold for a high scored article.
227 An article will be highlighted as high scored if its score is greater
228 than this score."
229   :group 'gnus-score-default
230   :type 'integer)
231
232 (defcustom gnus-summary-default-low-score 0
233   "*Default threshold for a low scored article.
234 An article will be highlighted as low scored if its score is smaller
235 than this score."
236   :group 'gnus-score-default
237   :type 'integer)
238
239 (defcustom gnus-summary-zcore-fuzz 0
240   "*Fuzziness factor for the zcore in the summary buffer.
241 Articles with scores closer than this to `gnus-summary-default-score'
242 will not be marked."
243   :group 'gnus-summary-format
244   :type 'integer)
245
246 (defcustom gnus-simplify-subject-fuzzy-regexp nil
247   "*Strings to be removed when doing fuzzy matches.
248 This can either be a regular expression or list of regular expressions
249 that will be removed from subject strings if fuzzy subject
250 simplification is selected."
251   :group 'gnus-thread
252   :type '(repeat regexp))
253
254 (defcustom gnus-show-threads t
255   "*If non-nil, display threads in summary mode."
256   :group 'gnus-thread
257   :type 'boolean)
258
259 (defcustom gnus-thread-hide-subtree nil
260   "*If non-nil, hide all threads initially.
261 This can be a predicate specifier which says which threads to hide.
262 If threads are hidden, you have to run the command
263 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
264 to expose hidden threads."
265   :group 'gnus-thread
266   :type '(radio (sexp :format "Non-nil\n"
267                       :match (lambda (widget value)
268                                (not (or (consp value) (functionp value))))
269                       :value t)
270                 (const nil)
271                 (sexp :tag "Predicate specifier" :size 0)))
272
273 (defcustom gnus-thread-hide-killed t
274   "*If non-nil, hide killed threads automatically."
275   :group 'gnus-thread
276   :type 'boolean)
277
278 (defcustom gnus-thread-ignore-subject t
279   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
280 If nil, articles that have different subjects from their parents will
281 start separate threads."
282   :group 'gnus-thread
283   :type 'boolean)
284
285 (defcustom gnus-thread-operation-ignore-subject t
286   "*If non-nil, subjects will be ignored when doing thread commands.
287 This affects commands like `gnus-summary-kill-thread' and
288 `gnus-summary-lower-thread'.
289
290 If this variable is nil, articles in the same thread with different
291 subjects will not be included in the operation in question.  If this
292 variable is `fuzzy', only articles that have subjects that are fuzzily
293 equal will be included."
294   :group 'gnus-thread
295   :type '(choice (const :tag "off" nil)
296                  (const fuzzy)
297                  (sexp :tag "on" t)))
298
299 (defcustom gnus-thread-indent-level 4
300   "*Number that says how much each sub-thread should be indented."
301   :group 'gnus-thread
302   :type 'integer)
303
304 (defcustom gnus-auto-extend-newsgroup t
305   "*If non-nil, extend newsgroup forward and backward when requested."
306   :group 'gnus-summary-choose
307   :type 'boolean)
308
309 (defcustom gnus-auto-select-first t
310   "*If non-nil, select the article under point.
311 Which article this is is controlled by the `gnus-auto-select-subject'
312 variable.
313
314 If you want to prevent automatic selection of articles in some
315 newsgroups, set the variable to nil in `gnus-select-group-hook'."
316   :group 'gnus-group-select
317   :type '(choice (const :tag "none" nil)
318                  (sexp :menu-tag "first" t)))
319
320 (defcustom gnus-auto-select-subject 'unread
321   "*Says what subject to place under point when entering a group.
322
323 This variable can either be the symbols `first' (place point on the
324 first subject), `unread' (place point on the subject line of the first
325 unread article), `best' (place point on the subject line of the
326 higest-scored article), `unseen' (place point on the subject line of
327 the first unseen article), 'unseen-or-unread' (place point on the subject
328 line of the first unseen article or, if all article have been seen, on the
329 subject line of the first unread article), or a function to be called to
330 place point on some subject line."
331   :group 'gnus-group-select
332   :type '(choice (const best)
333                  (const unread)
334                  (const first)
335                  (const unseen)
336                  (const unseen-or-unread)))
337
338 (defcustom gnus-dont-select-after-jump-to-other-group nil
339   "If non-nil, don't select the first unread article after entering the
340 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
341 it is depend on the value of `gnus-auto-select-first' whether to select
342 or not."
343   :group 'gnus-group-select
344   :type 'boolean)
345
346 (defcustom gnus-auto-select-next t
347   "*If non-nil, offer to go to the next group from the end of the previous.
348 If the value is t and the next newsgroup is empty, Gnus will exit
349 summary mode and go back to group mode.  If the value is neither nil
350 nor t, Gnus will select the following unread newsgroup.  In
351 particular, if the value is the symbol `quietly', the next unread
352 newsgroup will be selected without any confirmation, and if it is
353 `almost-quietly', the next group will be selected without any
354 confirmation if you are located on the last article in the group.
355 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
356 will go to the next group without confirmation."
357   :group 'gnus-summary-maneuvering
358   :type '(choice (const :tag "off" nil)
359                  (const quietly)
360                  (const almost-quietly)
361                  (const slightly-quietly)
362                  (sexp :menu-tag "on" t)))
363
364 (defcustom gnus-auto-select-same nil
365   "*If non-nil, select the next article with the same subject.
366 If there are no more articles with the same subject, go to
367 the first unread article."
368   :group 'gnus-summary-maneuvering
369   :type 'boolean)
370
371 (defcustom gnus-auto-goto-ignores 'unfetched
372   "*Says how to handle unfetched articles when maneuvering.
373
374 This variable can either be the symbols nil (maneuver to any
375 article), `undownloaded' (maneuvering while unplugged ignores articles
376 that have not been fetched), `always-undownloaded' (maneuvering always
377 ignores articles that have not been fetched), `unfetched' (maneuvering
378 ignores articles whose headers have not been fetched).
379
380 NOTE: The list of unfetched articles will always be nil when plugged
381 and, when unplugged, a subset of the undownloaded article list."
382   :group 'gnus-summary-maneuvering
383   :type '(choice (const :tag "None" nil)
384                  (const :tag "Undownloaded when unplugged" undownloaded)
385                  (const :tag "Undownloaded" always-undownloaded)
386                  (const :tag "Unfetched" unfetched)))
387
388 (defcustom gnus-summary-check-current nil
389   "*If non-nil, consider the current article when moving.
390 The \"unread\" movement commands will stay on the same line if the
391 current article is unread."
392   :group 'gnus-summary-maneuvering
393   :type 'boolean)
394
395 (defcustom gnus-auto-center-summary t
396   "*If non-nil, always center the current summary buffer.
397 In particular, if `vertical' do only vertical recentering.  If non-nil
398 and non-`vertical', do both horizontal and vertical recentering."
399   :group 'gnus-summary-maneuvering
400   :type '(choice (const :tag "none" nil)
401                  (const vertical)
402                  (integer :tag "height")
403                  (sexp :menu-tag "both" t)))
404
405 (defvar gnus-auto-center-group t
406   "*If non-nil, always center the group buffer.")
407
408 (defcustom gnus-show-all-headers nil
409   "*If non-nil, don't hide any headers."
410   :group 'gnus-article-hiding
411   :group 'gnus-article-headers
412   :type 'boolean)
413
414 (defcustom gnus-summary-ignore-duplicates nil
415   "*If non-nil, ignore articles with identical Message-ID headers."
416   :group 'gnus-summary
417   :type 'boolean)
418
419 (defcustom gnus-single-article-buffer t
420   "*If non-nil, display all articles in the same buffer.
421 If nil, each group will get its own article buffer."
422   :group 'gnus-article-various
423   :type 'boolean)
424
425 (defcustom gnus-break-pages t
426   "*If non-nil, do page breaking on articles.
427 The page delimiter is specified by the `gnus-page-delimiter'
428 variable."
429   :group 'gnus-article-various
430   :type 'boolean)
431
432 (defcustom gnus-show-mime t
433   "*If non-nil, do mime processing of articles.
434 The articles will simply be fed to the function given by
435 `gnus-article-display-method-for-mime'."
436   :group 'gnus-article-mime
437   :type 'boolean)
438
439 (defcustom gnus-move-split-methods nil
440   "*Variable used to suggest where articles are to be moved to.
441 It uses the same syntax as the `gnus-split-methods' variable.
442 However, whereas `gnus-split-methods' specifies file names as targets,
443 this variable specifies group names."
444   :group 'gnus-summary-mail
445   :type '(repeat (choice (list :value (fun) function)
446                          (cons :value ("" "") regexp (repeat string))
447                          (sexp :value nil))))
448
449 (defcustom gnus-unread-mark ?\ ;;;Whitespace
450   "*Mark used for unread articles."
451   :group 'gnus-summary-marks
452   :type 'character)
453
454 (defcustom gnus-ticked-mark ?!
455   "*Mark used for ticked articles."
456   :group 'gnus-summary-marks
457   :type 'character)
458
459 (defcustom gnus-dormant-mark ??
460   "*Mark used for dormant articles."
461   :group 'gnus-summary-marks
462   :type 'character)
463
464 (defcustom gnus-del-mark ?r
465   "*Mark used for del'd articles."
466   :group 'gnus-summary-marks
467   :type 'character)
468
469 (defcustom gnus-read-mark ?R
470   "*Mark used for read articles."
471   :group 'gnus-summary-marks
472   :type 'character)
473
474 (defcustom gnus-expirable-mark ?E
475   "*Mark used for expirable articles."
476   :group 'gnus-summary-marks
477   :type 'character)
478
479 (defcustom gnus-killed-mark ?K
480   "*Mark used for killed articles."
481   :group 'gnus-summary-marks
482   :type 'character)
483
484 (defcustom gnus-spam-mark ?$
485   "*Mark used for spam articles."
486   :group 'gnus-summary-marks
487   :type 'character)
488
489 (defcustom gnus-souped-mark ?F
490   "*Mark used for souped articles."
491   :group 'gnus-summary-marks
492   :type 'character)
493
494 (defcustom gnus-kill-file-mark ?X
495   "*Mark used for articles killed by kill files."
496   :group 'gnus-summary-marks
497   :type 'character)
498
499 (defcustom gnus-low-score-mark ?Y
500   "*Mark used for articles with a low score."
501   :group 'gnus-summary-marks
502   :type 'character)
503
504 (defcustom gnus-catchup-mark ?C
505   "*Mark used for articles that are caught up."
506   :group 'gnus-summary-marks
507   :type 'character)
508
509 (defcustom gnus-replied-mark ?A
510   "*Mark used for articles that have been replied to."
511   :group 'gnus-summary-marks
512   :type 'character)
513
514 (defcustom gnus-forwarded-mark ?F
515   "*Mark used for articles that have been forwarded."
516   :group 'gnus-summary-marks
517   :type 'character)
518
519 (defcustom gnus-recent-mark ?N
520   "*Mark used for articles that are recent."
521   :group 'gnus-summary-marks
522   :type 'character)
523
524 (defcustom gnus-cached-mark ?*
525   "*Mark used for articles that are in the cache."
526   :group 'gnus-summary-marks
527   :type 'character)
528
529 (defcustom gnus-saved-mark ?S
530   "*Mark used for articles that have been saved."
531   :group 'gnus-summary-marks
532   :type 'character)
533
534 (defcustom gnus-unseen-mark ?.
535   "*Mark used for articles that haven't been seen."
536   :group 'gnus-summary-marks
537   :type 'character)
538
539 (defcustom gnus-no-mark ?\ ;;;Whitespace
540   "*Mark used for articles that have no other secondary mark."
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-ancient-mark ?O
545   "*Mark used for ancient articles."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-sparse-mark ?Q
550   "*Mark used for sparsely reffed articles."
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-canceled-mark ?G
555   "*Mark used for canceled articles."
556   :group 'gnus-summary-marks
557   :type 'character)
558
559 (defcustom gnus-duplicate-mark ?M
560   "*Mark used for duplicate articles."
561   :group 'gnus-summary-marks
562   :type 'character)
563
564 (defcustom gnus-undownloaded-mark ?-
565   "*Mark used for articles that weren't downloaded."
566   :group 'gnus-summary-marks
567   :type 'character)
568
569 (defcustom gnus-downloaded-mark ?+
570   "*Mark used for articles that were downloaded."
571   :group 'gnus-summary-marks
572   :type 'character)
573
574 (defcustom gnus-downloadable-mark ?%
575   "*Mark used for articles that are to be downloaded."
576   :group 'gnus-summary-marks
577   :type 'character)
578
579 (defcustom gnus-unsendable-mark ?=
580   "*Mark used for articles that won't be sent."
581   :group 'gnus-summary-marks
582   :type 'character)
583
584 (defcustom gnus-score-over-mark ?+
585   "*Score mark used for articles with high scores."
586   :group 'gnus-summary-marks
587   :type 'character)
588
589 (defcustom gnus-score-below-mark ?-
590   "*Score mark used for articles with low scores."
591   :group 'gnus-summary-marks
592   :type 'character)
593
594 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
595   "*There is no thread under the article."
596   :group 'gnus-summary-marks
597   :type 'character)
598
599 (defcustom gnus-not-empty-thread-mark ?=
600   "*There is a thread under the article."
601   :group 'gnus-summary-marks
602   :type 'character)
603
604 (defcustom gnus-view-pseudo-asynchronously nil
605   "*If non-nil, Gnus will view pseudo-articles asynchronously."
606   :group 'gnus-extract-view
607   :type 'boolean)
608
609 (defcustom gnus-auto-expirable-marks
610   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
611         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
612         gnus-souped-mark gnus-duplicate-mark)
613   "*The list of marks converted into expiration if a group is auto-expirable."
614   :version "21.1"
615   :group 'gnus-summary
616   :type '(repeat character))
617
618 (defcustom gnus-inhibit-user-auto-expire t
619   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
620   :version "21.1"
621   :group 'gnus-summary
622   :type 'boolean)
623
624 (defcustom gnus-view-pseudos nil
625   "*If `automatic', pseudo-articles will be viewed automatically.
626 If `not-confirm', pseudos will be viewed automatically, and the user
627 will not be asked to confirm the command."
628   :group 'gnus-extract-view
629   :type '(choice (const :tag "off" nil)
630                  (const automatic)
631                  (const not-confirm)))
632
633 (defcustom gnus-view-pseudos-separately t
634   "*If non-nil, one pseudo-article will be created for each file to be viewed.
635 If nil, all files that use the same viewing command will be given as a
636 list of parameters to that command."
637   :group 'gnus-extract-view
638   :type 'boolean)
639
640 (defcustom gnus-insert-pseudo-articles t
641   "*If non-nil, insert pseudo-articles when decoding articles."
642   :group 'gnus-extract-view
643   :type 'boolean)
644
645 (defcustom gnus-summary-dummy-line-format
646   "   %(:                             :%) %S\n"
647   "*The format specification for the dummy roots in the summary buffer.
648 It works along the same lines as a normal formatting string,
649 with some simple extensions.
650
651 %S  The subject
652
653 General format specifiers can also be used.
654 See `(gnus)Formatting Variables'."
655   :link '(custom-manual "(gnus)Formatting Variables")
656   :group 'gnus-threading
657   :type 'string)
658
659 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
660   "*The format specification for the summary mode line.
661 It works along the same lines as a normal formatting string,
662 with some simple extensions:
663
664 %G  Group name
665 %p  Unprefixed group name
666 %A  Current article number
667 %z  Current article score
668 %V  Gnus version
669 %U  Number of unread articles in the group
670 %e  Number of unselected articles in the group
671 %Z  A string with unread/unselected article counts
672 %g  Shortish group name
673 %S  Subject of the current article
674 %u  User-defined spec
675 %s  Current score file name
676 %d  Number of dormant articles
677 %r  Number of articles that have been marked as read in this session
678 %E  Number of articles expunged by the score files"
679   :group 'gnus-summary-format
680   :type 'string)
681
682 (defcustom gnus-list-identifiers nil
683   "Regexp that matches list identifiers to be removed from subject.
684 This can also be a list of regexps."
685   :version "21.1"
686   :group 'gnus-summary-format
687   :group 'gnus-article-hiding
688   :type '(choice (const :tag "none" nil)
689                  (regexp :value ".*")
690                  (repeat :value (".*") regexp)))
691
692 (defcustom gnus-summary-mark-below 0
693   "*Mark all articles with a score below this variable as read.
694 This variable is local to each summary buffer and usually set by the
695 score file."
696   :group 'gnus-score-default
697   :type 'integer)
698
699 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
700   "*List of functions used for sorting articles in the summary buffer.
701
702 Each function takes two articles and returns non-nil if the first
703 article should be sorted before the other.  If you use more than one
704 function, the primary sort function should be the last.  You should
705 probably always include `gnus-article-sort-by-number' in the list of
706 sorting functions -- preferably first.  Also note that sorting by date
707 is often much slower than sorting by number, and the sorting order is
708 very similar.  (Sorting by date means sorting by the time the message
709 was sent, sorting by number means sorting by arrival time.)
710
711 Ready-made functions include `gnus-article-sort-by-number',
712 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
713 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
714 and `gnus-article-sort-by-score'.
715
716 When threading is turned on, the variable `gnus-thread-sort-functions'
717 controls how articles are sorted."
718   :group 'gnus-summary-sort
719   :type '(repeat (choice (function-item gnus-article-sort-by-number)
720                          (function-item gnus-article-sort-by-author)
721                          (function-item gnus-article-sort-by-subject)
722                          (function-item gnus-article-sort-by-date)
723                          (function-item gnus-article-sort-by-score)
724                          (function-item gnus-article-sort-by-random)
725                          (function :tag "other"))))
726
727 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
728   "*List of functions used for sorting threads in the summary buffer.
729 By default, threads are sorted by article number.
730
731 Each function takes two threads and returns non-nil if the first
732 thread should be sorted before the other.  If you use more than one
733 function, the primary sort function should be the last.  You should
734 probably always include `gnus-thread-sort-by-number' in the list of
735 sorting functions -- preferably first.  Also note that sorting by date
736 is often much slower than sorting by number, and the sorting order is
737 very similar.  (Sorting by date means sorting by the time the message
738 was sent, sorting by number means sorting by arrival time.)
739
740 Ready-made functions include `gnus-thread-sort-by-number',
741 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
742 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
743 `gnus-thread-sort-by-most-recent-number',
744 `gnus-thread-sort-by-most-recent-date',
745 `gnus-thread-sort-by-random', and
746 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
747
748 When threading is turned off, the variable
749 `gnus-article-sort-functions' controls how articles are sorted."
750   :group 'gnus-summary-sort
751   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
752                          (function-item gnus-thread-sort-by-author)
753                          (function-item gnus-thread-sort-by-subject)
754                          (function-item gnus-thread-sort-by-date)
755                          (function-item gnus-thread-sort-by-score)
756                          (function-item gnus-thread-sort-by-total-score)
757                          (function-item gnus-thread-sort-by-random)
758                          (function :tag "other"))))
759
760 (defcustom gnus-thread-score-function '+
761   "*Function used for calculating the total score of a thread.
762
763 The function is called with the scores of the article and each
764 subthread and should then return the score of the thread.
765
766 Some functions you can use are `+', `max', or `min'."
767   :group 'gnus-summary-sort
768   :type 'function)
769
770 (defcustom gnus-summary-expunge-below nil
771   "All articles that have a score less than this variable will be expunged.
772 This variable is local to the summary buffers."
773   :group 'gnus-score-default
774   :type '(choice (const :tag "off" nil)
775                  integer))
776
777 (defcustom gnus-thread-expunge-below nil
778   "All threads that have a total score less than this variable will be expunged.
779 See `gnus-thread-score-function' for en explanation of what a
780 \"thread score\" is.
781
782 This variable is local to the summary buffers."
783   :group 'gnus-threading
784   :group 'gnus-score-default
785   :type '(choice (const :tag "off" nil)
786                  integer))
787
788 (defcustom gnus-summary-mode-hook nil
789   "*A hook for Gnus summary mode.
790 This hook is run before any variables are set in the summary buffer."
791   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
792   :group 'gnus-summary-various
793   :type 'hook)
794
795 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
796 (when (featurep 'xemacs)
797   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
798   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
799   (add-hook 'gnus-summary-mode-hook
800             'gnus-xmas-switch-horizontal-scrollbar-off))
801
802 (defcustom gnus-summary-menu-hook nil
803   "*Hook run after the creation of the summary mode menu."
804   :group 'gnus-summary-visual
805   :type 'hook)
806
807 (defcustom gnus-summary-exit-hook nil
808   "*A hook called on exit from the summary buffer.
809 It will be called with point in the group buffer."
810   :group 'gnus-summary-exit
811   :type 'hook)
812
813 (defcustom gnus-summary-prepare-hook nil
814   "*A hook called after the summary buffer has been generated.
815 If you want to modify the summary buffer, you can use this hook."
816   :group 'gnus-summary-various
817   :type 'hook)
818
819 (defcustom gnus-summary-prepared-hook nil
820   "*A hook called as the last thing after the summary buffer has been generated."
821   :group 'gnus-summary-various
822   :type 'hook)
823
824 (defcustom gnus-summary-generate-hook nil
825   "*A hook run just before generating the summary buffer.
826 This hook is commonly used to customize threading variables and the
827 like."
828   :group 'gnus-summary-various
829   :type 'hook)
830
831 (defcustom gnus-select-group-hook nil
832   "*A hook called when a newsgroup is selected.
833
834 If you'd like to simplify subjects like the
835 `gnus-summary-next-same-subject' command does, you can use the
836 following hook:
837
838  (add-hook gnus-select-group-hook
839            (lambda ()
840              (mapcar (lambda (header)
841                        (mail-header-set-subject
842                         header
843                         (gnus-simplify-subject
844                          (mail-header-subject header) 're-only)))
845                      gnus-newsgroup-headers)))"
846   :group 'gnus-group-select
847   :type 'hook)
848
849 (defcustom gnus-select-article-hook nil
850   "*A hook called when an article is selected."
851   :group 'gnus-summary-choose
852   :options '(gnus-agent-fetch-selected-article)
853   :type 'hook)
854
855 (defcustom gnus-visual-mark-article-hook
856   (list 'gnus-highlight-selected-summary)
857   "*Hook run after selecting an article in the summary buffer.
858 It is meant to be used for highlighting the article in some way.  It
859 is not run if `gnus-visual' is nil."
860   :group 'gnus-summary-visual
861   :type 'hook)
862
863 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
864   "*A hook called before parsing the headers."
865   :group 'gnus-various
866   :type 'hook)
867
868 (defcustom gnus-exit-group-hook nil
869   "*A hook called when exiting summary mode.
870 This hook is not called from the non-updating exit commands like `Q'."
871   :group 'gnus-various
872   :type 'hook)
873
874 (defcustom gnus-summary-update-hook
875   (list 'gnus-summary-highlight-line)
876   "*A hook called when a summary line is changed.
877 The hook will not be called if `gnus-visual' is nil.
878
879 The default function `gnus-summary-highlight-line' will
880 highlight the line according to the `gnus-summary-highlight'
881 variable."
882   :group 'gnus-summary-visual
883   :type 'hook)
884
885 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
886   "*A hook called when an article is selected for the first time.
887 The hook is intended to mark an article as read (or unread)
888 automatically when it is selected."
889   :group 'gnus-summary-choose
890   :type 'hook)
891
892 (defcustom gnus-group-no-more-groups-hook nil
893   "*A hook run when returning to group mode having no more (unread) groups."
894   :group 'gnus-group-select
895   :type 'hook)
896
897 (defcustom gnus-ps-print-hook nil
898   "*A hook run before ps-printing something from Gnus."
899   :group 'gnus-summary
900   :type 'hook)
901
902 (defcustom gnus-summary-article-move-hook nil
903   "*A hook called after an article is moved, copied, respooled, or crossposted."
904   :group 'gnus-summary
905   :type 'hook)
906
907 (defcustom gnus-summary-article-delete-hook nil
908   "*A hook called after an article is deleted."
909   :group 'gnus-summary
910   :type 'hook)
911
912 (defcustom gnus-summary-article-expire-hook nil
913   "*A hook called after an article is expired."
914   :group 'gnus-summary
915   :type 'hook)
916
917 (defcustom gnus-summary-display-arrow
918   (and (fboundp 'display-graphic-p)
919        (display-graphic-p))
920   "*If non-nil, display an arrow highlighting the current article."
921   :version "21.1"
922   :group 'gnus-summary
923   :type 'boolean)
924
925 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
926   "Face used for highlighting the current article in the summary buffer."
927   :group 'gnus-summary-visual
928   :type 'face)
929
930 (defvar gnus-tmp-downloaded nil)
931
932 (defcustom gnus-summary-highlight
933   '(((eq mark gnus-canceled-mark)
934      . gnus-summary-cancelled-face)
935     ((and uncached (> score default-high))
936      . gnus-summary-high-undownloaded-face)
937     ((and uncached (< score default-low))
938      . gnus-summary-low-undownloaded-face)
939     (uncached
940      . gnus-summary-normal-undownloaded-face)
941     ((and (> score default-high)
942           (or (eq mark gnus-dormant-mark)
943               (eq mark gnus-ticked-mark)))
944      . gnus-summary-high-ticked-face)
945     ((and (< score default-low)
946           (or (eq mark gnus-dormant-mark)
947               (eq mark gnus-ticked-mark)))
948      . gnus-summary-low-ticked-face)
949     ((or (eq mark gnus-dormant-mark)
950          (eq mark gnus-ticked-mark))
951      . gnus-summary-normal-ticked-face)
952     ((and (> score default-high) (eq mark gnus-ancient-mark))
953      . gnus-summary-high-ancient-face)
954     ((and (< score default-low) (eq mark gnus-ancient-mark))
955      . gnus-summary-low-ancient-face)
956     ((eq mark gnus-ancient-mark)
957      . gnus-summary-normal-ancient-face)
958     ((and (> score default-high) (eq mark gnus-unread-mark))
959      . gnus-summary-high-unread-face)
960     ((and (< score default-low) (eq mark gnus-unread-mark))
961      . gnus-summary-low-unread-face)
962     ((eq mark gnus-unread-mark)
963      . gnus-summary-normal-unread-face)
964     ((> score default-high)
965      . gnus-summary-high-read-face)
966     ((< score default-low)
967      . gnus-summary-low-read-face)
968     (t
969      . gnus-summary-normal-read-face))
970   "*Controls the highlighting of summary buffer lines.
971
972 A list of (FORM . FACE) pairs.  When deciding how a a particular
973 summary line should be displayed, each form is evaluated.  The content
974 of the face field after the first true form is used.  You can change
975 how those summary lines are displayed, by editing the face field.
976
977 You can use the following variables in the FORM field.
978
979 score:        The article's score
980 default:      The default article score.
981 default-high: The default score for high scored articles.
982 default-low:  The default score for low scored articles.
983 below:        The score below which articles are automatically marked as read.
984 mark:         The article's mark.
985 uncached:     Non-nil if the article is uncached."
986   :group 'gnus-summary-visual
987   :type '(repeat (cons (sexp :tag "Form" nil)
988                        face)))
989
990 (defcustom gnus-alter-header-function nil
991   "Function called to allow alteration of article header structures.
992 The function is called with one parameter, the article header vector,
993 which it may alter in any way."
994   :type '(choice (const :tag "None" nil)
995                  function)
996   :group 'gnus-summary)
997
998 (defvar gnus-decode-encoded-word-function
999   (mime-find-field-decoder 'From 'nov)
1000   "Variable that says which function should be used to decode a string with encoded words.")
1001
1002 (defcustom gnus-extra-headers '(To Newsgroups)
1003   "*Extra headers to parse."
1004   :version "21.1"
1005   :group 'gnus-summary
1006   :type '(repeat symbol))
1007
1008 (defcustom gnus-ignored-from-addresses
1009   (and user-mail-address (regexp-quote user-mail-address))
1010   "*Regexp of From headers that may be suppressed in favor of To headers."
1011   :version "21.1"
1012   :group 'gnus-summary
1013   :type 'regexp)
1014
1015 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1016   "List of charsets that should be ignored.
1017 When these charsets are used in the \"charset\" parameter, the
1018 default charset will be used instead."
1019   :version "21.1"
1020   :type '(repeat symbol)
1021   :group 'gnus-charset)
1022
1023 (gnus-define-group-parameter
1024  ignored-charsets
1025  :type list
1026  :function-document
1027  "Return the ignored charsets of GROUP."
1028  :variable gnus-group-ignored-charsets-alist
1029  :variable-default
1030  '(("alt\\.chinese\\.text" iso-8859-1))
1031  :variable-document
1032  "Alist of regexps (to match group names) and charsets that should be ignored.
1033 When these charsets are used in the \"charset\" parameter, the
1034 default charset will be used instead."
1035  :variable-group gnus-charset
1036  :variable-type '(repeat (cons (regexp :tag "Group")
1037                                (repeat symbol)))
1038  :parameter-type '(choice :tag "Ignored charsets"
1039                           :value nil
1040                           (repeat (symbol)))
1041  :parameter-document       "\
1042 List of charsets that should be ignored.
1043
1044 When these charsets are used in the \"charset\" parameter, the
1045 default charset will be used instead.")
1046
1047 (defcustom gnus-group-highlight-words-alist nil
1048   "Alist of group regexps and highlight regexps.
1049 This variable uses the same syntax as `gnus-emphasis-alist'."
1050   :version "21.1"
1051   :type '(repeat (cons (regexp :tag "Group")
1052                        (repeat (list (regexp :tag "Highlight regexp")
1053                                      (number :tag "Group for entire word" 0)
1054                                      (number :tag "Group for displayed part" 0)
1055                                      (symbol :tag "Face"
1056                                              gnus-emphasis-highlight-words)))))
1057   :group 'gnus-summary-visual)
1058
1059 (defcustom gnus-use-wheel nil
1060   "Use Intelli-mouse on summary movement"
1061   :type 'boolean
1062   :group 'gnus-summary-maneuvering)
1063
1064 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1065   "Amount to scroll messages by spinning the mouse wheel.
1066 This is actually a cons cell, where the first item is the amount to scroll
1067 on a normal wheel event, and the second is the amount to scroll when the
1068 wheel is moved with the shift key depressed."
1069   :type '(cons (integer :tag "Shift") integer)
1070   :group 'gnus-summary-maneuvering)
1071
1072 (defcustom gnus-wheel-edge-resistance 2
1073   "How hard it should be to change the current article
1074 by moving the mouse over the edge of the article window."
1075   :type 'integer
1076   :group 'gnus-summary-maneuvering)
1077
1078 (defcustom gnus-summary-show-article-charset-alist
1079   nil
1080   "Alist of number and charset.
1081 The article will be shown with the charset corresponding to the
1082 numbered argument.
1083 For example: ((1 . cn-gb-2312) (2 . big5))."
1084   :version "21.1"
1085   :type '(repeat (cons (number :tag "Argument" 1)
1086                        (symbol :tag "Charset")))
1087   :group 'gnus-charset)
1088
1089 (defcustom gnus-preserve-marks t
1090   "Whether marks are preserved when moving, copying and respooling messages."
1091   :version "21.1"
1092   :type 'boolean
1093   :group 'gnus-summary-marks)
1094
1095 (defcustom gnus-alter-articles-to-read-function nil
1096   "Function to be called to alter the list of articles to be selected."
1097   :type '(choice (const nil) function)
1098   :group 'gnus-summary)
1099
1100 (defcustom gnus-orphan-score nil
1101   "*All orphans get this score added.  Set in the score file."
1102   :group 'gnus-score-default
1103   :type '(choice (const nil)
1104                  integer))
1105
1106 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1107   "*A regexp to match MIME parts when saving multiple parts of a
1108 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1109 This regexp will be used by default when prompting the user for which
1110 type of files to save."
1111   :group 'gnus-summary
1112   :type 'regexp)
1113
1114 (defcustom gnus-read-all-available-headers nil
1115   "Whether Gnus should parse all headers made available to it.
1116 This is mostly relevant for slow back ends where the user may
1117 wish to widen the summary buffer to include all headers
1118 that were fetched.  Say, for nnultimate groups."
1119   :group 'gnus-summary
1120   :type '(choice boolean regexp))
1121
1122 (defcustom gnus-summary-muttprint-program "muttprint"
1123   "Command (and optional arguments) used to run Muttprint."
1124   :version "21.3"
1125   :group 'gnus-summary
1126   :type 'string)
1127
1128 (defcustom gnus-article-loose-mime nil
1129   "If non-nil, don't require MIME-Version header.
1130 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1131 supply the MIME-Version header or deliberately strip it From the mail.
1132 Set it to non-nil, Gnus will treat some articles as MIME even if
1133 the MIME-Version header is missed."
1134   :version "21.3"
1135   :type 'boolean
1136   :group 'gnus-article-mime)
1137
1138 (defcustom gnus-article-emulate-mime t
1139   "If non-nil, use MIME emulation for uuencode and the like.
1140 This means that Gnus will search message bodies for text that look
1141 like uuencoded bits, yEncoded bits, and so on, and present that using
1142 the normal Gnus MIME machinery."
1143   :type 'boolean
1144   :group 'gnus-article-mime)
1145
1146 ;;; Internal variables
1147
1148 (defvar gnus-summary-display-cache nil)
1149 (defvar gnus-article-mime-handles nil)
1150 (defvar gnus-article-decoded-p nil)
1151 (defvar gnus-article-charset nil)
1152 (defvar gnus-article-ignored-charsets nil)
1153 (defvar gnus-scores-exclude-files nil)
1154 (defvar gnus-page-broken nil)
1155
1156 (defvar gnus-original-article nil)
1157 (defvar gnus-article-internal-prepare-hook nil)
1158 (defvar gnus-newsgroup-process-stack nil)
1159
1160 (defvar gnus-thread-indent-array nil)
1161 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1162 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1163   "Function called to sort the articles within a thread after it has been gathered together.")
1164
1165 (defvar gnus-summary-save-parts-type-history nil)
1166 (defvar gnus-summary-save-parts-last-directory nil)
1167
1168 ;; Avoid highlighting in kill files.
1169 (defvar gnus-summary-inhibit-highlight nil)
1170 (defvar gnus-newsgroup-selected-overlay nil)
1171 (defvar gnus-inhibit-limiting nil)
1172 (defvar gnus-newsgroup-adaptive-score-file nil)
1173 (defvar gnus-current-score-file nil)
1174 (defvar gnus-current-move-group nil)
1175 (defvar gnus-current-copy-group nil)
1176 (defvar gnus-current-crosspost-group nil)
1177 (defvar gnus-newsgroup-display nil)
1178
1179 (defvar gnus-newsgroup-dependencies nil)
1180 (defvar gnus-newsgroup-adaptive nil)
1181 (defvar gnus-summary-display-article-function nil)
1182 (defvar gnus-summary-highlight-line-function nil
1183   "Function called after highlighting a summary line.")
1184
1185 (defvar gnus-summary-line-format-alist
1186   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1187     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1188     (?s gnus-tmp-subject-or-nil ?s)
1189     (?n gnus-tmp-name ?s)
1190     (?A (std11-address-string
1191          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1192     (?a (or (std11-full-name-string
1193              (car (mime-entity-read-field gnus-tmp-header 'From)))
1194             gnus-tmp-from) ?s)
1195     (?F gnus-tmp-from ?s)
1196     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1197     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1198     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1199     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1200     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1201     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1202     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1203     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1204     (?L gnus-tmp-lines ?s)
1205     (?O gnus-tmp-downloaded ?c)
1206     (?I gnus-tmp-indentation ?s)
1207     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1208     (?R gnus-tmp-replied ?c)
1209     (?\[ gnus-tmp-opening-bracket ?c)
1210     (?\] gnus-tmp-closing-bracket ?c)
1211     (?\> (make-string gnus-tmp-level ? ) ?s)
1212     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1213     (?i gnus-tmp-score ?d)
1214     (?z gnus-tmp-score-char ?c)
1215     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1216     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1217     (?U gnus-tmp-unread ?c)
1218     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1219         ?s)
1220     (?t (gnus-summary-number-of-articles-in-thread
1221          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1222         ?d)
1223     (?e (gnus-summary-number-of-articles-in-thread
1224          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1225         ?c)
1226     (?u gnus-tmp-user-defined ?s)
1227     (?P (gnus-pick-line-number) ?d)
1228     (?B gnus-tmp-thread-tree-header-string ?s)
1229     (user-date (gnus-user-date
1230                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1231   "An alist of format specifications that can appear in summary lines.
1232 These are paired with what variables they correspond with, along with
1233 the type of the variable (string, integer, character, etc).")
1234
1235 (defvar gnus-summary-dummy-line-format-alist
1236   `((?S gnus-tmp-subject ?s)
1237     (?N gnus-tmp-number ?d)
1238     (?u gnus-tmp-user-defined ?s)))
1239
1240 (defvar gnus-summary-mode-line-format-alist
1241   `((?G gnus-tmp-group-name ?s)
1242     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1243     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1244     (?A gnus-tmp-article-number ?d)
1245     (?Z gnus-tmp-unread-and-unselected ?s)
1246     (?V gnus-version ?s)
1247     (?U gnus-tmp-unread-and-unticked ?d)
1248     (?S gnus-tmp-subject ?s)
1249     (?e gnus-tmp-unselected ?d)
1250     (?u gnus-tmp-user-defined ?s)
1251     (?d (length gnus-newsgroup-dormant) ?d)
1252     (?t (length gnus-newsgroup-marked) ?d)
1253     (?h (length gnus-newsgroup-spam-marked) ?d)
1254     (?r (length gnus-newsgroup-reads) ?d)
1255     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1256     (?E gnus-newsgroup-expunged-tally ?d)
1257     (?s (gnus-current-score-file-nondirectory) ?s)))
1258
1259 (defvar gnus-last-search-regexp nil
1260   "Default regexp for article search command.")
1261
1262 (defvar gnus-summary-search-article-matched-data nil
1263   "Last matched data of article search command.  It is the local variable
1264 in `gnus-article-buffer' which consists of the list of start position,
1265 end position and text.")
1266
1267 (defvar gnus-last-shell-command nil
1268   "Default shell command on article.")
1269
1270 (defvar gnus-newsgroup-agentized nil
1271   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1272 (defvar gnus-newsgroup-begin nil)
1273 (defvar gnus-newsgroup-end nil)
1274 (defvar gnus-newsgroup-last-rmail nil)
1275 (defvar gnus-newsgroup-last-mail nil)
1276 (defvar gnus-newsgroup-last-folder nil)
1277 (defvar gnus-newsgroup-last-file nil)
1278 (defvar gnus-newsgroup-auto-expire nil)
1279 (defvar gnus-newsgroup-active nil)
1280
1281 (defvar gnus-newsgroup-data nil)
1282 (defvar gnus-newsgroup-data-reverse nil)
1283 (defvar gnus-newsgroup-limit nil)
1284 (defvar gnus-newsgroup-limits nil)
1285 (defvar gnus-summary-use-undownloaded-faces nil)
1286
1287 (defvar gnus-newsgroup-unreads nil
1288   "Sorted list of unread articles in the current newsgroup.")
1289
1290 (defvar gnus-newsgroup-unselected nil
1291   "Sorted list of unselected unread articles in the current newsgroup.")
1292
1293 (defvar gnus-newsgroup-reads nil
1294   "Alist of read articles and article marks in the current newsgroup.")
1295
1296 (defvar gnus-newsgroup-expunged-tally nil)
1297
1298 (defvar gnus-newsgroup-marked nil
1299   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1300
1301 (defvar gnus-newsgroup-spam-marked nil
1302   "List of ranges of articles that have been marked as spam.")
1303
1304 (defvar gnus-newsgroup-killed nil
1305   "List of ranges of articles that have been through the scoring process.")
1306
1307 (defvar gnus-newsgroup-cached nil
1308   "Sorted list of articles that come from the article cache.")
1309
1310 (defvar gnus-newsgroup-saved nil
1311   "List of articles that have been saved.")
1312
1313 (defvar gnus-newsgroup-kill-headers nil)
1314
1315 (defvar gnus-newsgroup-replied nil
1316   "List of articles that have been replied to in the current newsgroup.")
1317
1318 (defvar gnus-newsgroup-forwarded nil
1319   "List of articles that have been forwarded in the current newsgroup.")
1320
1321 (defvar gnus-newsgroup-recent nil
1322   "List of articles that have are recent in the current newsgroup.")
1323
1324 (defvar gnus-newsgroup-expirable nil
1325   "Sorted list of articles in the current newsgroup that can be expired.")
1326
1327 (defvar gnus-newsgroup-processable nil
1328   "List of articles in the current newsgroup that can be processed.")
1329
1330 (defvar gnus-newsgroup-downloadable nil
1331   "Sorted list of articles in the current newsgroup that can be processed.")
1332
1333 (defvar gnus-newsgroup-unfetched nil
1334   "Sorted list of articles in the current newsgroup whose headers have
1335 not been fetched into the agent.
1336
1337 This list will always be a subset of gnus-newsgroup-undownloaded.")
1338
1339 (defvar gnus-newsgroup-undownloaded nil
1340   "List of articles in the current newsgroup that haven't been downloaded.")
1341
1342 (defvar gnus-newsgroup-unsendable nil
1343   "List of articles in the current newsgroup that won't be sent.")
1344
1345 (defvar gnus-newsgroup-bookmarks nil
1346   "List of articles in the current newsgroup that have bookmarks.")
1347
1348 (defvar gnus-newsgroup-dormant nil
1349   "Sorted list of dormant articles in the current newsgroup.")
1350
1351 (defvar gnus-newsgroup-unseen nil
1352   "List of unseen articles in the current newsgroup.")
1353
1354 (defvar gnus-newsgroup-seen nil
1355   "Range of seen articles in the current newsgroup.")
1356
1357 (defvar gnus-newsgroup-articles nil
1358   "List of articles in the current newsgroup.")
1359
1360 (defvar gnus-newsgroup-scored nil
1361   "List of scored articles in the current newsgroup.")
1362
1363 (defvar gnus-newsgroup-incorporated nil
1364   "List of incorporated articles in the current newsgroup.")
1365
1366 (defvar gnus-newsgroup-headers nil
1367   "List of article headers in the current newsgroup.")
1368
1369 (defvar gnus-newsgroup-threads nil)
1370
1371 (defvar gnus-newsgroup-prepared nil
1372   "Whether the current group has been prepared properly.")
1373
1374 (defvar gnus-newsgroup-ancient nil
1375   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1376
1377 (defvar gnus-newsgroup-sparse nil)
1378
1379 (defvar gnus-current-article nil)
1380 (defvar gnus-article-current nil)
1381 (defvar gnus-current-headers nil)
1382 (defvar gnus-have-all-headers nil)
1383 (defvar gnus-last-article nil)
1384 (defvar gnus-newsgroup-history nil)
1385 (defvar gnus-newsgroup-charset nil)
1386 (defvar gnus-newsgroup-ephemeral-charset nil)
1387 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1388
1389 (defvar gnus-article-before-search nil)
1390
1391 (defvar gnus-summary-local-variables
1392   '(gnus-newsgroup-name
1393     gnus-newsgroup-begin gnus-newsgroup-end
1394     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1395     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1396     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1397     gnus-newsgroup-unselected gnus-newsgroup-marked
1398     gnus-newsgroup-spam-marked
1399     gnus-newsgroup-reads gnus-newsgroup-saved
1400     gnus-newsgroup-replied gnus-newsgroup-forwarded
1401     gnus-newsgroup-recent
1402     gnus-newsgroup-expirable
1403     gnus-newsgroup-processable gnus-newsgroup-killed
1404     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1405     gnus-newsgroup-unfetched
1406     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1407     gnus-newsgroup-seen gnus-newsgroup-articles
1408     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1409     gnus-newsgroup-headers gnus-newsgroup-threads
1410     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1411     gnus-current-article gnus-current-headers gnus-have-all-headers
1412     gnus-last-article gnus-article-internal-prepare-hook
1413     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1414     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1415     gnus-thread-expunge-below
1416     gnus-score-alist gnus-current-score-file
1417     (gnus-summary-expunge-below . global)
1418     (gnus-summary-mark-below . global)
1419     (gnus-orphan-score . global)
1420     gnus-newsgroup-active gnus-scores-exclude-files
1421     gnus-newsgroup-history gnus-newsgroup-ancient
1422     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1423     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1424     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1425     (gnus-newsgroup-expunged-tally . 0)
1426     gnus-cache-removable-articles gnus-newsgroup-cached
1427     gnus-newsgroup-data gnus-newsgroup-data-reverse
1428     gnus-newsgroup-limit gnus-newsgroup-limits
1429     gnus-newsgroup-charset gnus-newsgroup-display
1430     gnus-summary-use-undownloaded-faces
1431     gnus-newsgroup-incorporated)
1432   "Variables that are buffer-local to the summary buffers.")
1433
1434 (defvar gnus-newsgroup-variables nil
1435   "A list of variables that have separate values in different newsgroups.
1436 A list of newsgroup (summary buffer) local variables, or cons of
1437 variables and their default values (when the default values are not
1438 nil), that should be made global while the summary buffer is active.
1439 These variables can be used to set variables in the group parameters
1440 while still allowing them to affect operations done in other
1441 buffers. For example:
1442
1443 \(setq gnus-newsgroup-variables
1444      '(message-use-followup-to
1445        (gnus-visible-headers .
1446          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1447 ")
1448
1449 ;; Byte-compiler warning.
1450 (eval-when-compile
1451   ;; Bind features so that require will believe that gnus-sum has
1452   ;; already been loaded (avoids infinite recursion)
1453   (let ((features (cons 'gnus-sum features)))
1454     ;; Several of the declarations in gnus-sum are needed to load the
1455     ;; following files. Right now, these definitions have been
1456     ;; compiled but not defined (evaluated).  We could either do a
1457     ;; eval-and-compile about all of the declarations or evaluate the
1458     ;; source file.
1459     (if (boundp 'gnus-newsgroup-variables)
1460         nil
1461       (load "gnus-sum.el" t t t))
1462     (require 'gnus)
1463     (require 'gnus-agent)
1464     (require 'gnus-art)))
1465
1466 ;; Subject simplification.
1467
1468 (defun gnus-simplify-whitespace (str)
1469   "Remove excessive whitespace from STR."
1470   ;; Multiple spaces.
1471   (while (string-match "[ \t][ \t]+" str)
1472     (setq str (concat (substring str 0 (match-beginning 0))
1473                         " "
1474                         (substring str (match-end 0)))))
1475   ;; Leading spaces.
1476   (when (string-match "^[ \t]+" str)
1477     (setq str (substring str (match-end 0))))
1478   ;; Trailing spaces.
1479   (when (string-match "[ \t]+$" str)
1480     (setq str (substring str 0 (match-beginning 0))))
1481   str)
1482
1483 (defun gnus-simplify-all-whitespace (str)
1484   "Remove all whitespace from STR."
1485   (while (string-match "[ \t\n]+" str)
1486     (setq str (replace-match "" nil nil str)))
1487   str)
1488
1489 (defsubst gnus-simplify-subject-re (subject)
1490   "Remove \"Re:\" from subject lines."
1491   (if (string-match message-subject-re-regexp subject)
1492       (substring subject (match-end 0))
1493     subject))
1494
1495 (defun gnus-simplify-subject (subject &optional re-only)
1496   "Remove `Re:' and words in parentheses.
1497 If RE-ONLY is non-nil, strip leading `Re:'s only."
1498   (let ((case-fold-search t))           ;Ignore case.
1499     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1500     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1501       (setq subject (substring subject (match-end 0))))
1502     ;; Remove uninteresting prefixes.
1503     (when (and (not re-only)
1504                gnus-simplify-ignored-prefixes
1505                (string-match gnus-simplify-ignored-prefixes subject))
1506       (setq subject (substring subject (match-end 0))))
1507     ;; Remove words in parentheses from end.
1508     (unless re-only
1509       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1510         (setq subject (substring subject 0 (match-beginning 0)))))
1511     ;; Return subject string.
1512     subject))
1513
1514 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1515 ;; all whitespace.
1516 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1517   (goto-char (point-min))
1518   (while (re-search-forward regexp nil t)
1519     (replace-match (or newtext ""))))
1520
1521 (defun gnus-simplify-buffer-fuzzy ()
1522   "Simplify string in the buffer fuzzily.
1523 The string in the accessible portion of the current buffer is simplified.
1524 It is assumed to be a single-line subject.
1525 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1526 matter is removed.  Additional things can be deleted by setting
1527 `gnus-simplify-subject-fuzzy-regexp'."
1528   (let ((case-fold-search t)
1529         (modified-tick))
1530     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1531
1532     (while (not (eq modified-tick (buffer-modified-tick)))
1533       (setq modified-tick (buffer-modified-tick))
1534       (cond
1535        ((listp gnus-simplify-subject-fuzzy-regexp)
1536         (mapcar 'gnus-simplify-buffer-fuzzy-step
1537                 gnus-simplify-subject-fuzzy-regexp))
1538        (gnus-simplify-subject-fuzzy-regexp
1539         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1540       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1541       (gnus-simplify-buffer-fuzzy-step
1542        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1543       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1544
1545     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1546     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1547     (gnus-simplify-buffer-fuzzy-step " $")
1548     (gnus-simplify-buffer-fuzzy-step "^ +")))
1549
1550 (defun gnus-simplify-subject-fuzzy (subject)
1551   "Simplify a subject string fuzzily.
1552 See `gnus-simplify-buffer-fuzzy' for details."
1553   (save-excursion
1554     (gnus-set-work-buffer)
1555     (let ((case-fold-search t))
1556       ;; Remove uninteresting prefixes.
1557       (when (and gnus-simplify-ignored-prefixes
1558                  (string-match gnus-simplify-ignored-prefixes subject))
1559         (setq subject (substring subject (match-end 0))))
1560       (insert subject)
1561       (inline (gnus-simplify-buffer-fuzzy))
1562       (buffer-string))))
1563
1564 (defsubst gnus-simplify-subject-fully (subject)
1565   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1566   (cond
1567    (gnus-simplify-subject-functions
1568     (gnus-map-function gnus-simplify-subject-functions subject))
1569    ((null gnus-summary-gather-subject-limit)
1570     (gnus-simplify-subject-re subject))
1571    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1572     (gnus-simplify-subject-fuzzy subject))
1573    ((numberp gnus-summary-gather-subject-limit)
1574     (gnus-limit-string (gnus-simplify-subject-re subject)
1575                        gnus-summary-gather-subject-limit))
1576    (t
1577     subject)))
1578
1579 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1580   "Check whether two subjects are equal.
1581 If optional argument SIMPLE-FIRST is t, first argument is already
1582 simplified."
1583   (cond
1584    ((null simple-first)
1585     (equal (gnus-simplify-subject-fully s1)
1586            (gnus-simplify-subject-fully s2)))
1587    (t
1588     (equal s1
1589            (gnus-simplify-subject-fully s2)))))
1590
1591 (defun gnus-summary-bubble-group ()
1592   "Increase the score of the current group.
1593 This is a handy function to add to `gnus-summary-exit-hook' to
1594 increase the score of each group you read."
1595   (gnus-group-add-score gnus-newsgroup-name))
1596
1597 \f
1598 ;;;
1599 ;;; Gnus summary mode
1600 ;;;
1601
1602 (put 'gnus-summary-mode 'mode-class 'special)
1603
1604 (defvar gnus-article-commands-menu)
1605
1606 ;; Non-orthogonal keys
1607
1608 (gnus-define-keys gnus-summary-mode-map
1609   " " gnus-summary-next-page
1610   "\177" gnus-summary-prev-page
1611   [delete] gnus-summary-prev-page
1612   [backspace] gnus-summary-prev-page
1613   "\r" gnus-summary-scroll-up
1614   "\M-\r" gnus-summary-scroll-down
1615   "n" gnus-summary-next-unread-article
1616   "p" gnus-summary-prev-unread-article
1617   "N" gnus-summary-next-article
1618   "P" gnus-summary-prev-article
1619   "\M-\C-n" gnus-summary-next-same-subject
1620   "\M-\C-p" gnus-summary-prev-same-subject
1621   "\M-n" gnus-summary-next-unread-subject
1622   "\M-p" gnus-summary-prev-unread-subject
1623   "." gnus-summary-first-unread-article
1624   "," gnus-summary-best-unread-article
1625   "\M-s" gnus-summary-search-article-forward
1626   "\M-r" gnus-summary-search-article-backward
1627   "<" gnus-summary-beginning-of-article
1628   ">" gnus-summary-end-of-article
1629   "j" gnus-summary-goto-article
1630   "^" gnus-summary-refer-parent-article
1631   "\M-^" gnus-summary-refer-article
1632   "u" gnus-summary-tick-article-forward
1633   "!" gnus-summary-tick-article-forward
1634   "U" gnus-summary-tick-article-backward
1635   "d" gnus-summary-mark-as-read-forward
1636   "D" gnus-summary-mark-as-read-backward
1637   "E" gnus-summary-mark-as-expirable
1638   "\M-u" gnus-summary-clear-mark-forward
1639   "\M-U" gnus-summary-clear-mark-backward
1640   "k" gnus-summary-kill-same-subject-and-select
1641   "\C-k" gnus-summary-kill-same-subject
1642   "\M-\C-k" gnus-summary-kill-thread
1643   "\M-\C-l" gnus-summary-lower-thread
1644   "e" gnus-summary-edit-article
1645   "#" gnus-summary-mark-as-processable
1646   "\M-#" gnus-summary-unmark-as-processable
1647   "\M-\C-t" gnus-summary-toggle-threads
1648   "\M-\C-s" gnus-summary-show-thread
1649   "\M-\C-h" gnus-summary-hide-thread
1650   "\M-\C-f" gnus-summary-next-thread
1651   "\M-\C-b" gnus-summary-prev-thread
1652   [(meta down)] gnus-summary-next-thread
1653   [(meta up)] gnus-summary-prev-thread
1654   "\M-\C-u" gnus-summary-up-thread
1655   "\M-\C-d" gnus-summary-down-thread
1656   "&" gnus-summary-execute-command
1657   "c" gnus-summary-catchup-and-exit
1658   "\C-w" gnus-summary-mark-region-as-read
1659   "\C-t" gnus-summary-toggle-truncation
1660   "?" gnus-summary-mark-as-dormant
1661   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1662   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1663   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1664   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1665   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1666   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1667   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1668   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1669   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1670   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1671   "=" gnus-summary-expand-window
1672   "\C-x\C-s" gnus-summary-reselect-current-group
1673   "\M-g" gnus-summary-rescan-group
1674   "w" gnus-summary-stop-page-breaking
1675   "\C-c\C-r" gnus-summary-caesar-message
1676   "\M-t" gnus-summary-toggle-mime
1677   "f" gnus-summary-followup
1678   "F" gnus-summary-followup-with-original
1679   "C" gnus-summary-cancel-article
1680   "r" gnus-summary-reply
1681   "R" gnus-summary-reply-with-original
1682   "\C-c\C-f" gnus-summary-mail-forward
1683   "o" gnus-summary-save-article
1684   "\C-o" gnus-summary-save-article-mail
1685   "|" gnus-summary-pipe-output
1686   "\M-k" gnus-summary-edit-local-kill
1687   "\M-K" gnus-summary-edit-global-kill
1688   ;; "V" gnus-version
1689   "\C-c\C-d" gnus-summary-describe-group
1690   "q" gnus-summary-exit
1691   "Q" gnus-summary-exit-no-update
1692   "\C-c\C-i" gnus-info-find-node
1693   gnus-mouse-2 gnus-mouse-pick-article
1694   "m" gnus-summary-mail-other-window
1695   "a" gnus-summary-post-news
1696   "i" gnus-summary-news-other-window
1697   "x" gnus-summary-limit-to-unread
1698   "s" gnus-summary-isearch-article
1699   "t" gnus-summary-toggle-header
1700   "g" gnus-summary-show-article
1701   "l" gnus-summary-goto-last-article
1702   "v" gnus-summary-preview-mime-message
1703   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1704   "\C-d" gnus-summary-enter-digest-group
1705   "\M-\C-d" gnus-summary-read-document
1706   "\M-\C-e" gnus-summary-edit-parameters
1707   "\M-\C-a" gnus-summary-customize-parameters
1708   "\C-c\C-b" gnus-bug
1709   "\C-c\C-n" gnus-namazu-search
1710   "*" gnus-cache-enter-article
1711   "\M-*" gnus-cache-remove-article
1712   "\M-&" gnus-summary-universal-argument
1713   "\C-l" gnus-recenter
1714   "I" gnus-summary-increase-score
1715   "L" gnus-summary-lower-score
1716   "\M-i" gnus-symbolic-argument
1717   "h" gnus-summary-select-article-buffer
1718
1719   "V" gnus-summary-score-map
1720   "X" gnus-uu-extract-map
1721   "S" gnus-summary-send-map)
1722
1723   ;; Sort of orthogonal keymap
1724 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1725   "t" gnus-summary-tick-article-forward
1726   "!" gnus-summary-tick-article-forward
1727   "d" gnus-summary-mark-as-read-forward
1728   "r" gnus-summary-mark-as-read-forward
1729   "c" gnus-summary-clear-mark-forward
1730   " " gnus-summary-clear-mark-forward
1731   "e" gnus-summary-mark-as-expirable
1732   "x" gnus-summary-mark-as-expirable
1733   "?" gnus-summary-mark-as-dormant
1734   "b" gnus-summary-set-bookmark
1735   "B" gnus-summary-remove-bookmark
1736   "#" gnus-summary-mark-as-processable
1737   "\M-#" gnus-summary-unmark-as-processable
1738   "S" gnus-summary-limit-include-expunged
1739   "C" gnus-summary-catchup
1740   "H" gnus-summary-catchup-to-here
1741   "h" gnus-summary-catchup-from-here
1742   "\C-c" gnus-summary-catchup-all
1743   "k" gnus-summary-kill-same-subject-and-select
1744   "K" gnus-summary-kill-same-subject
1745   "P" gnus-uu-mark-map)
1746
1747 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1748   "c" gnus-summary-clear-above
1749   "u" gnus-summary-tick-above
1750   "m" gnus-summary-mark-above
1751   "k" gnus-summary-kill-below)
1752
1753 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1754   "/" gnus-summary-limit-to-subject
1755   "n" gnus-summary-limit-to-articles
1756   "w" gnus-summary-pop-limit
1757   "s" gnus-summary-limit-to-subject
1758   "a" gnus-summary-limit-to-author
1759   "u" gnus-summary-limit-to-unread
1760   "m" gnus-summary-limit-to-marks
1761   "M" gnus-summary-limit-exclude-marks
1762   "v" gnus-summary-limit-to-score
1763   "*" gnus-summary-limit-include-cached
1764   "D" gnus-summary-limit-include-dormant
1765   "T" gnus-summary-limit-include-thread
1766   "d" gnus-summary-limit-exclude-dormant
1767   "t" gnus-summary-limit-to-age
1768   "." gnus-summary-limit-to-unseen
1769   "x" gnus-summary-limit-to-extra
1770   "p" gnus-summary-limit-to-display-predicate
1771   "E" gnus-summary-limit-include-expunged
1772   "c" gnus-summary-limit-exclude-childless-dormant
1773   "C" gnus-summary-limit-mark-excluded-as-read
1774   "o" gnus-summary-insert-old-articles
1775   "N" gnus-summary-insert-new-articles
1776   "r" gnus-summary-limit-to-replied)
1777
1778 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1779   "n" gnus-summary-next-unread-article
1780   "p" gnus-summary-prev-unread-article
1781   "N" gnus-summary-next-article
1782   "P" gnus-summary-prev-article
1783   "\C-n" gnus-summary-next-same-subject
1784   "\C-p" gnus-summary-prev-same-subject
1785   "\M-n" gnus-summary-next-unread-subject
1786   "\M-p" gnus-summary-prev-unread-subject
1787   "f" gnus-summary-first-unread-article
1788   "b" gnus-summary-best-unread-article
1789   "j" gnus-summary-goto-article
1790   "g" gnus-summary-goto-subject
1791   "l" gnus-summary-goto-last-article
1792   "o" gnus-summary-pop-article)
1793
1794 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1795   "k" gnus-summary-kill-thread
1796   "l" gnus-summary-lower-thread
1797   "i" gnus-summary-raise-thread
1798   "T" gnus-summary-toggle-threads
1799   "t" gnus-summary-rethread-current
1800   "^" gnus-summary-reparent-thread
1801   "s" gnus-summary-show-thread
1802   "S" gnus-summary-show-all-threads
1803   "h" gnus-summary-hide-thread
1804   "H" gnus-summary-hide-all-threads
1805   "n" gnus-summary-next-thread
1806   "p" gnus-summary-prev-thread
1807   "u" gnus-summary-up-thread
1808   "o" gnus-summary-top-thread
1809   "d" gnus-summary-down-thread
1810   "#" gnus-uu-mark-thread
1811   "\M-#" gnus-uu-unmark-thread)
1812
1813 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1814   "g" gnus-summary-prepare
1815   "c" gnus-summary-insert-cached-articles
1816   "d" gnus-summary-insert-dormant-articles)
1817
1818 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1819   "c" gnus-summary-catchup-and-exit
1820   "C" gnus-summary-catchup-all-and-exit
1821   "E" gnus-summary-exit-no-update
1822   "J" gnus-summary-jump-to-other-group
1823   "Q" gnus-summary-exit
1824   "Z" gnus-summary-exit
1825   "n" gnus-summary-catchup-and-goto-next-group
1826   "R" gnus-summary-reselect-current-group
1827   "G" gnus-summary-rescan-group
1828   "N" gnus-summary-next-group
1829   "s" gnus-summary-save-newsrc
1830   "P" gnus-summary-prev-group)
1831
1832 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1833   " " gnus-summary-next-page
1834   "n" gnus-summary-next-page
1835   "\177" gnus-summary-prev-page
1836   [delete] gnus-summary-prev-page
1837   "p" gnus-summary-prev-page
1838   "\r" gnus-summary-scroll-up
1839   "\M-\r" gnus-summary-scroll-down
1840   "<" gnus-summary-beginning-of-article
1841   ">" gnus-summary-end-of-article
1842   "b" gnus-summary-beginning-of-article
1843   "e" gnus-summary-end-of-article
1844   "^" gnus-summary-refer-parent-article
1845   "r" gnus-summary-refer-parent-article
1846   "D" gnus-summary-enter-digest-group
1847   "R" gnus-summary-refer-references
1848   "T" gnus-summary-refer-thread
1849   "g" gnus-summary-show-article
1850   "s" gnus-summary-isearch-article
1851   "P" gnus-summary-print-article
1852   "M" gnus-mailing-list-insinuate
1853   "t" gnus-article-babel)
1854
1855 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1856   "b" gnus-article-add-buttons
1857   "B" gnus-article-add-buttons-to-head
1858   "o" gnus-article-treat-overstrike
1859   "e" gnus-article-emphasize
1860   "w" gnus-article-fill-cited-article
1861   "Q" gnus-article-fill-long-lines
1862   "C" gnus-article-capitalize-sentences
1863   "c" gnus-article-remove-cr
1864   "Z" gnus-article-decode-HZ
1865   "A" gnus-article-treat-ansi-sequences
1866   "h" gnus-article-wash-html
1867   "u" gnus-article-unsplit-urls
1868   "f" gnus-article-display-x-face
1869   "l" gnus-summary-stop-page-breaking
1870   "r" gnus-summary-caesar-message
1871   "m" gnus-summary-morse-message
1872   "t" gnus-summary-toggle-header
1873   "g" gnus-treat-smiley
1874   "v" gnus-summary-verbose-headers
1875   "m" gnus-summary-toggle-mime
1876   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1877   "p" gnus-article-verify-x-pgp-sig
1878   "d" gnus-article-treat-dumbquotes)
1879
1880 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1881   ;; mnemonic: deuglif*Y*
1882   "u" gnus-article-outlook-unwrap-lines
1883   "a" gnus-article-outlook-repair-attribution
1884   "c" gnus-article-outlook-rearrange-citation
1885   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1886
1887 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1888   "a" gnus-article-hide
1889   "h" gnus-article-hide-headers
1890   "b" gnus-article-hide-boring-headers
1891   "s" gnus-article-hide-signature
1892   "c" gnus-article-hide-citation
1893   "C" gnus-article-hide-citation-in-followups
1894   "l" gnus-article-hide-list-identifiers
1895   "B" gnus-article-strip-banner
1896   "P" gnus-article-hide-pem
1897   "\C-c" gnus-article-hide-citation-maybe)
1898
1899 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1900   "a" gnus-article-highlight
1901   "h" gnus-article-highlight-headers
1902   "c" gnus-article-highlight-citation
1903   "s" gnus-article-highlight-signature)
1904
1905 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1906   "f" gnus-article-treat-fold-headers
1907   "u" gnus-article-treat-unfold-headers
1908   "n" gnus-article-treat-fold-newsgroups)
1909
1910 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1911   "x" gnus-article-display-x-face
1912   "d" gnus-article-display-face
1913   "s" gnus-treat-smiley
1914   "D" gnus-article-remove-images
1915   "f" gnus-treat-from-picon
1916   "m" gnus-treat-mail-picon
1917   "n" gnus-treat-newsgroups-picon)
1918
1919 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1920   "z" gnus-article-date-ut
1921   "u" gnus-article-date-ut
1922   "l" gnus-article-date-local
1923   "p" gnus-article-date-english
1924   "e" gnus-article-date-lapsed
1925   "o" gnus-article-date-original
1926   "i" gnus-article-date-iso8601
1927   "s" gnus-article-date-user)
1928
1929 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1930   "t" gnus-article-remove-trailing-blank-lines
1931   "l" gnus-article-strip-leading-blank-lines
1932   "m" gnus-article-strip-multiple-blank-lines
1933   "a" gnus-article-strip-blank-lines
1934   "A" gnus-article-strip-all-blank-lines
1935   "s" gnus-article-strip-leading-space
1936   "e" gnus-article-strip-trailing-space
1937   "w" gnus-article-remove-leading-whitespace)
1938
1939 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1940   "v" gnus-version
1941   "f" gnus-summary-fetch-faq
1942   "d" gnus-summary-describe-group
1943   "h" gnus-summary-describe-briefly
1944   "i" gnus-info-find-node
1945   "c" gnus-group-fetch-charter
1946   "C" gnus-group-fetch-control)
1947
1948 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1949   "e" gnus-summary-expire-articles
1950   "\M-\C-e" gnus-summary-expire-articles-now
1951   "\177" gnus-summary-delete-article
1952   [delete] gnus-summary-delete-article
1953   [backspace] gnus-summary-delete-article
1954   "m" gnus-summary-move-article
1955   "r" gnus-summary-respool-article
1956   "w" gnus-summary-edit-article
1957   "c" gnus-summary-copy-article
1958   "B" gnus-summary-crosspost-article
1959   "q" gnus-summary-respool-query
1960   "t" gnus-summary-respool-trace
1961   "i" gnus-summary-import-article
1962   "I" gnus-summary-create-article
1963   "p" gnus-summary-article-posted-p)
1964
1965 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1966   "o" gnus-summary-save-article
1967   "m" gnus-summary-save-article-mail
1968   "F" gnus-summary-write-article-file
1969   "r" gnus-summary-save-article-rmail
1970   "f" gnus-summary-save-article-file
1971   "b" gnus-summary-save-article-body-file
1972   "h" gnus-summary-save-article-folder
1973   "v" gnus-summary-save-article-vm
1974   "p" gnus-summary-pipe-output
1975   "P" gnus-summary-muttprint
1976   "s" gnus-soup-add-article)
1977
1978 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1979   "b" gnus-summary-display-buttonized
1980   "m" gnus-summary-repair-multipart
1981   "v" gnus-article-view-part
1982   "o" gnus-article-save-part
1983   "c" gnus-article-copy-part
1984   "C" gnus-article-view-part-as-charset
1985   "e" gnus-article-view-part-externally
1986   "E" gnus-article-encrypt-body
1987   "i" gnus-article-inline-part
1988   "|" gnus-article-pipe-part)
1989
1990 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1991   "p" gnus-summary-mark-as-processable
1992   "u" gnus-summary-unmark-as-processable
1993   "U" gnus-summary-unmark-all-processable
1994   "v" gnus-uu-mark-over
1995   "s" gnus-uu-mark-series
1996   "r" gnus-uu-mark-region
1997   "g" gnus-uu-unmark-region
1998   "R" gnus-uu-mark-by-regexp
1999   "G" gnus-uu-unmark-by-regexp
2000   "t" gnus-uu-mark-thread
2001   "T" gnus-uu-unmark-thread
2002   "a" gnus-uu-mark-all
2003   "b" gnus-uu-mark-buffer
2004   "S" gnus-uu-mark-sparse
2005   "k" gnus-summary-kill-process-mark
2006   "y" gnus-summary-yank-process-mark
2007   "w" gnus-summary-save-process-mark
2008   "i" gnus-uu-invert-processable)
2009
2010 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2011   ;;"x" gnus-uu-extract-any
2012   "m" gnus-summary-save-parts
2013   "u" gnus-uu-decode-uu
2014   "U" gnus-uu-decode-uu-and-save
2015   "s" gnus-uu-decode-unshar
2016   "S" gnus-uu-decode-unshar-and-save
2017   "o" gnus-uu-decode-save
2018   "O" gnus-uu-decode-save
2019   "b" gnus-uu-decode-binhex
2020   "B" gnus-uu-decode-binhex
2021   "p" gnus-uu-decode-postscript
2022   "P" gnus-uu-decode-postscript-and-save)
2023
2024 (gnus-define-keys
2025     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2026   "u" gnus-uu-decode-uu-view
2027   "U" gnus-uu-decode-uu-and-save-view
2028   "s" gnus-uu-decode-unshar-view
2029   "S" gnus-uu-decode-unshar-and-save-view
2030   "o" gnus-uu-decode-save-view
2031   "O" gnus-uu-decode-save-view
2032   "b" gnus-uu-decode-binhex-view
2033   "B" gnus-uu-decode-binhex-view
2034   "p" gnus-uu-decode-postscript-view
2035   "P" gnus-uu-decode-postscript-and-save-view)
2036
2037 (defvar gnus-article-post-menu nil)
2038
2039 (defconst gnus-summary-menu-maxlen 20)
2040
2041 (defun gnus-summary-menu-split (menu)
2042   ;; If we have lots of elements, divide them into groups of 20
2043   ;; and make a pane (or submenu) for each one.
2044   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2045       (let ((menu menu) sublists next
2046             (i 1))
2047         (while menu
2048           ;; Pull off the next gnus-summary-menu-maxlen elements
2049           ;; and make them the next element of sublist.
2050           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2051           (if next
2052               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2053                       nil))
2054           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2055                                              (aref (car (last menu)) 0)) menu)
2056                                sublists))
2057           (setq i (1+ i))
2058           (setq menu next))
2059         (nreverse sublists))
2060     ;; Few elements--put them all in one pane.
2061     menu))
2062
2063 (defun gnus-summary-make-menu-bar ()
2064   (gnus-turn-off-edit-menu 'summary)
2065
2066   (unless (boundp 'gnus-summary-misc-menu)
2067
2068     (easy-menu-define
2069      gnus-summary-kill-menu gnus-summary-mode-map ""
2070      (cons
2071       "Score"
2072       (nconc
2073        (list
2074         ["Customize" gnus-score-customize t])
2075        (gnus-make-score-map 'increase)
2076        (gnus-make-score-map 'lower)
2077        '(("Mark"
2078           ["Kill below" gnus-summary-kill-below t]
2079           ["Mark above" gnus-summary-mark-above t]
2080           ["Tick above" gnus-summary-tick-above t]
2081           ["Clear above" gnus-summary-clear-above t])
2082          ["Current score" gnus-summary-current-score t]
2083          ["Set score" gnus-summary-set-score t]
2084          ["Switch current score file..." gnus-score-change-score-file t]
2085          ["Set mark below..." gnus-score-set-mark-below t]
2086          ["Set expunge below..." gnus-score-set-expunge-below t]
2087          ["Edit current score file" gnus-score-edit-current-scores t]
2088          ["Edit score file" gnus-score-edit-file t]
2089          ["Trace score" gnus-score-find-trace t]
2090          ["Find words" gnus-score-find-favourite-words t]
2091          ["Rescore buffer" gnus-summary-rescore t]
2092          ["Increase score..." gnus-summary-increase-score t]
2093          ["Lower score..." gnus-summary-lower-score t]))))
2094
2095     ;; Define both the Article menu in the summary buffer and the
2096     ;; equivalent Commands menu in the article buffer here for
2097     ;; consistency.
2098     (let ((innards
2099            `(("Hide"
2100               ["All" gnus-article-hide t]
2101               ["Headers" gnus-article-hide-headers t]
2102               ["Signature" gnus-article-hide-signature t]
2103               ["Citation" gnus-article-hide-citation t]
2104               ["List identifiers" gnus-article-hide-list-identifiers t]
2105               ["Banner" gnus-article-strip-banner t]
2106               ["Boring headers" gnus-article-hide-boring-headers t])
2107              ("Highlight"
2108               ["All" gnus-article-highlight t]
2109               ["Headers" gnus-article-highlight-headers t]
2110               ["Signature" gnus-article-highlight-signature t]
2111               ["Citation" gnus-article-highlight-citation t])
2112              ("Date"
2113               ["Local" gnus-article-date-local t]
2114               ["ISO8601" gnus-article-date-iso8601 t]
2115               ["UT" gnus-article-date-ut t]
2116               ["Original" gnus-article-date-original t]
2117               ["Lapsed" gnus-article-date-lapsed t]
2118               ["User-defined" gnus-article-date-user t])
2119              ("Display"
2120               ["Remove images" gnus-article-remove-images t]
2121               ["Toggle smiley" gnus-treat-smiley t]
2122               ["Show X-Face" gnus-article-display-x-face t]
2123               ["Show picons in From" gnus-treat-from-picon t]
2124               ["Show picons in mail headers" gnus-treat-mail-picon t]
2125               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2126               ("View as different encoding"
2127                ,@(gnus-summary-menu-split
2128                   (mapcar
2129                    (lambda (cs)
2130                      ;; Since easymenu under Emacs doesn't allow
2131                      ;; lambda forms for menu commands, we should
2132                      ;; provide intern'ed function symbols.
2133                      (let ((command (intern (format "\
2134 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2135                        (fset command
2136                              `(lambda ()
2137                                 (interactive)
2138                                 (let ((gnus-summary-show-article-charset-alist
2139                                        '((1 . ,cs))))
2140                                   (gnus-summary-show-article 1))))
2141                        `[,(symbol-name cs) ,command t]))
2142                    (sort (if (fboundp 'coding-system-list)
2143                              (coding-system-list)
2144                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2145                            )
2146                          'string<)))))
2147              ("Washing"
2148               ("Remove Blanks"
2149                ["Leading" gnus-article-strip-leading-blank-lines t]
2150                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2151                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2152                ["All of the above" gnus-article-strip-blank-lines t]
2153                ["All" gnus-article-strip-all-blank-lines t]
2154                ["Leading space" gnus-article-strip-leading-space t]
2155                ["Trailing space" gnus-article-strip-trailing-space t]
2156                ["Leading space in headers"
2157                 gnus-article-remove-leading-whitespace t])
2158               ["Overstrike" gnus-article-treat-overstrike t]
2159               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2160               ["Emphasis" gnus-article-emphasize t]
2161               ["Word wrap" gnus-article-fill-cited-article t]
2162               ["Fill long lines" gnus-article-fill-long-lines t]
2163               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2164               ["Remove CR" gnus-article-remove-cr t]
2165               ["Rot 13" gnus-summary-caesar-message
2166                ,@(if (featurep 'xemacs) '(t)
2167                    '(:help "\"Caesar rotate\" article by 13"))]
2168               ["Morse decode" gnus-summary-morse-message t]
2169               ["Unix pipe..." gnus-summary-pipe-message t]
2170               ["Add buttons" gnus-article-add-buttons t]
2171               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2172               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2173               ["Toggle MIME" gnus-summary-toggle-mime t]
2174               ["Verbose header" gnus-summary-verbose-headers t]
2175               ["Toggle header" gnus-summary-toggle-header t]
2176               ["Unfold headers" gnus-article-treat-unfold-headers t]
2177               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2178               ["Html" gnus-article-wash-html t]
2179               ["Unsplit URLs" gnus-article-unsplit-urls t]
2180               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2181               ["Decode HZ" gnus-article-decode-HZ t]
2182               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2183               ("(Outlook) Deuglify"
2184                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2185                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2186                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2187                ["Full (Outlook) deuglify"
2188                 gnus-article-outlook-deuglify-article t])
2189               )
2190              ("Output"
2191               ["Save in default format..." gnus-summary-save-article
2192                ,@(if (featurep 'xemacs) '(t)
2193                    '(:help "Save article using default method"))]
2194               ["Save in file..." gnus-summary-save-article-file
2195                ,@(if (featurep 'xemacs) '(t)
2196                    '(:help "Save article in file"))]
2197               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2198               ["Save in MH folder..." gnus-summary-save-article-folder t]
2199               ["Save in VM folder..." gnus-summary-save-article-vm t]
2200               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2201               ["Save body in file..." gnus-summary-save-article-body-file t]
2202               ["Pipe through a filter..." gnus-summary-pipe-output t]
2203               ["Add to SOUP packet" gnus-soup-add-article t]
2204               ["Print with Muttprint..." gnus-summary-muttprint t]
2205               ["Print" gnus-summary-print-article t])
2206              ("Backend"
2207               ["Respool article..." gnus-summary-respool-article t]
2208               ["Move article..." gnus-summary-move-article
2209                (gnus-check-backend-function
2210                 'request-move-article gnus-newsgroup-name)]
2211               ["Copy article..." gnus-summary-copy-article t]
2212               ["Crosspost article..." gnus-summary-crosspost-article
2213                (gnus-check-backend-function
2214                 'request-replace-article gnus-newsgroup-name)]
2215               ["Import file..." gnus-summary-import-article
2216                (gnus-check-backend-function
2217                 'request-accept-article gnus-newsgroup-name)]
2218               ["Create article..." gnus-summary-create-article
2219                (gnus-check-backend-function
2220                 'request-accept-article gnus-newsgroup-name)]
2221               ["Check if posted" gnus-summary-article-posted-p t]
2222               ["Edit article" gnus-summary-edit-article
2223                (not (gnus-group-read-only-p))]
2224               ["Delete article" gnus-summary-delete-article
2225                (gnus-check-backend-function
2226                 'request-expire-articles gnus-newsgroup-name)]
2227               ["Query respool" gnus-summary-respool-query t]
2228               ["Trace respool" gnus-summary-respool-trace t]
2229               ["Delete expirable articles" gnus-summary-expire-articles-now
2230                (gnus-check-backend-function
2231                 'request-expire-articles gnus-newsgroup-name)])
2232              ("Extract"
2233               ["Uudecode" gnus-uu-decode-uu
2234                ,@(if (featurep 'xemacs) '(t)
2235                    '(:help "Decode uuencoded article(s)"))]
2236               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2237               ["Unshar" gnus-uu-decode-unshar t]
2238               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2239               ["Save" gnus-uu-decode-save t]
2240               ["Binhex" gnus-uu-decode-binhex t]
2241               ["Postscript" gnus-uu-decode-postscript t])
2242              ("Cache"
2243               ["Enter article" gnus-cache-enter-article t]
2244               ["Remove article" gnus-cache-remove-article t])
2245              ["Translate" gnus-article-babel t]
2246              ["Select article buffer" gnus-summary-select-article-buffer t]
2247              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2248              ["Isearch article..." gnus-summary-isearch-article t]
2249              ["Beginning of the article" gnus-summary-beginning-of-article t]
2250              ["End of the article" gnus-summary-end-of-article t]
2251              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2252              ["Fetch referenced articles" gnus-summary-refer-references t]
2253              ["Fetch current thread" gnus-summary-refer-thread t]
2254              ["Fetch article with id..." gnus-summary-refer-article t]
2255              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2256              ["Redisplay" gnus-summary-show-article t]
2257              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2258       (easy-menu-define
2259        gnus-summary-article-menu gnus-summary-mode-map ""
2260        (cons "Article" innards))
2261
2262       (if (not (keymapp gnus-summary-article-menu))
2263           (easy-menu-define
2264            gnus-article-commands-menu gnus-article-mode-map ""
2265            (cons "Commands" innards))
2266         ;; in Emacs, don't share menu.
2267         (setq gnus-article-commands-menu
2268               (copy-keymap gnus-summary-article-menu))
2269         (define-key gnus-article-mode-map [menu-bar commands]
2270           (cons "Commands" gnus-article-commands-menu))))
2271
2272     (easy-menu-define
2273      gnus-summary-thread-menu gnus-summary-mode-map ""
2274      '("Threads"
2275        ["Find all messages in thread" gnus-summary-refer-thread t]
2276        ["Toggle threading" gnus-summary-toggle-threads t]
2277        ["Hide threads" gnus-summary-hide-all-threads t]
2278        ["Show threads" gnus-summary-show-all-threads t]
2279        ["Hide thread" gnus-summary-hide-thread t]
2280        ["Show thread" gnus-summary-show-thread t]
2281        ["Go to next thread" gnus-summary-next-thread t]
2282        ["Go to previous thread" gnus-summary-prev-thread t]
2283        ["Go down thread" gnus-summary-down-thread t]
2284        ["Go up thread" gnus-summary-up-thread t]
2285        ["Top of thread" gnus-summary-top-thread t]
2286        ["Mark thread as read" gnus-summary-kill-thread t]
2287        ["Lower thread score" gnus-summary-lower-thread t]
2288        ["Raise thread score" gnus-summary-raise-thread t]
2289        ["Rethread current" gnus-summary-rethread-current t]))
2290
2291     (easy-menu-define
2292      gnus-summary-post-menu gnus-summary-mode-map ""
2293      `("Post"
2294        ["Send a message (mail or news)" gnus-summary-post-news
2295         ,@(if (featurep 'xemacs) '(t)
2296             '(:help "Post an article"))]
2297        ["Followup" gnus-summary-followup
2298         ,@(if (featurep 'xemacs) '(t)
2299             '(:help "Post followup to this article"))]
2300        ["Followup and yank" gnus-summary-followup-with-original
2301         ,@(if (featurep 'xemacs) '(t)
2302             '(:help "Post followup to this article, quoting its contents"))]
2303        ["Supersede article" gnus-summary-supersede-article t]
2304        ["Cancel article" gnus-summary-cancel-article
2305         ,@(if (featurep 'xemacs) '(t)
2306             '(:help "Cancel an article you posted"))]
2307        ["Reply" gnus-summary-reply t]
2308        ["Reply and yank" gnus-summary-reply-with-original t]
2309        ["Wide reply" gnus-summary-wide-reply t]
2310        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2311         ,@(if (featurep 'xemacs) '(t)
2312             '(:help "Mail a reply, quoting this article"))]
2313        ["Very wide reply" gnus-summary-very-wide-reply t]
2314        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2315         ,@(if (featurep 'xemacs) '(t)
2316             '(:help "Mail a very wide reply, quoting this article"))]
2317        ["Mail forward" gnus-summary-mail-forward t]
2318        ["Post forward" gnus-summary-post-forward t]
2319        ["Digest and mail" gnus-summary-digest-mail-forward t]
2320        ["Digest and post" gnus-summary-digest-post-forward t]
2321        ["Resend message" gnus-summary-resend-message t]
2322        ["Resend message edit" gnus-summary-resend-message-edit t]
2323        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2324        ["Send a mail" gnus-summary-mail-other-window t]
2325        ["Create a local message" gnus-summary-news-other-window t]
2326        ["Uuencode and post" gnus-uu-post-news
2327         ,@(if (featurep 'xemacs) '(t)
2328             '(:help "Post a uuencoded article"))]
2329        ["Followup via news" gnus-summary-followup-to-mail t]
2330        ["Followup via news and yank"
2331         gnus-summary-followup-to-mail-with-original t]
2332        ;;("Draft"
2333        ;;["Send" gnus-summary-send-draft t]
2334        ;;["Send bounced" gnus-resend-bounced-mail t])
2335        ))
2336
2337     (cond
2338      ((not (keymapp gnus-summary-post-menu))
2339       (setq gnus-article-post-menu gnus-summary-post-menu))
2340      ((not gnus-article-post-menu)
2341       ;; Don't share post menu.
2342       (setq gnus-article-post-menu
2343             (copy-keymap gnus-summary-post-menu))))
2344     (define-key gnus-article-mode-map [menu-bar post]
2345       (cons "Post" gnus-article-post-menu))
2346
2347     (easy-menu-define
2348      gnus-summary-misc-menu gnus-summary-mode-map ""
2349      `("Gnus"
2350        ("Mark Read"
2351         ["Mark as read" gnus-summary-mark-as-read-forward t]
2352         ["Mark same subject and select"
2353          gnus-summary-kill-same-subject-and-select t]
2354         ["Mark same subject" gnus-summary-kill-same-subject t]
2355         ["Catchup" gnus-summary-catchup
2356          ,@(if (featurep 'xemacs) '(t)
2357              '(:help "Mark unread articles in this group as read"))]
2358         ["Catchup all" gnus-summary-catchup-all t]
2359         ["Catchup to here" gnus-summary-catchup-to-here t]
2360         ["Catchup from here" gnus-summary-catchup-from-here t]
2361         ["Catchup region" gnus-summary-mark-region-as-read
2362          (gnus-mark-active-p)]
2363         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2364        ("Mark Various"
2365         ["Tick" gnus-summary-tick-article-forward t]
2366         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2367         ["Remove marks" gnus-summary-clear-mark-forward t]
2368         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2369         ["Set bookmark" gnus-summary-set-bookmark t]
2370         ["Remove bookmark" gnus-summary-remove-bookmark t])
2371        ("Limit to"
2372         ["Marks..." gnus-summary-limit-to-marks t]
2373         ["Subject..." gnus-summary-limit-to-subject t]
2374         ["Author..." gnus-summary-limit-to-author t]
2375         ["Age..." gnus-summary-limit-to-age t]
2376         ["Extra..." gnus-summary-limit-to-extra t]
2377         ["Score..." gnus-summary-limit-to-score t]
2378         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2379         ["Unread" gnus-summary-limit-to-unread t]
2380         ["Unseen" gnus-summary-limit-to-unseen t]
2381         ["Replied" gnus-summary-limit-to-replied t]
2382         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2383         ["Next articles" gnus-summary-limit-to-articles t]
2384         ["Pop limit" gnus-summary-pop-limit t]
2385         ["Show dormant" gnus-summary-limit-include-dormant t]
2386         ["Hide childless dormant"
2387          gnus-summary-limit-exclude-childless-dormant t]
2388         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2389         ["Hide marked" gnus-summary-limit-exclude-marks t]
2390         ["Show expunged" gnus-summary-limit-include-expunged t])
2391        ("Process Mark"
2392         ["Set mark" gnus-summary-mark-as-processable t]
2393         ["Remove mark" gnus-summary-unmark-as-processable t]
2394         ["Remove all marks" gnus-summary-unmark-all-processable t]
2395         ["Mark above" gnus-uu-mark-over t]
2396         ["Mark series" gnus-uu-mark-series t]
2397         ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2398         ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2399         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2400         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2401         ["Mark all" gnus-uu-mark-all t]
2402         ["Mark buffer" gnus-uu-mark-buffer t]
2403         ["Mark sparse" gnus-uu-mark-sparse t]
2404         ["Mark thread" gnus-uu-mark-thread t]
2405         ["Unmark thread" gnus-uu-unmark-thread t]
2406         ("Process Mark Sets"
2407          ["Kill" gnus-summary-kill-process-mark t]
2408          ["Yank" gnus-summary-yank-process-mark
2409           gnus-newsgroup-process-stack]
2410          ["Save" gnus-summary-save-process-mark t]
2411          ["Run command on marked..." gnus-summary-universal-argument t]))
2412        ("Scroll article"
2413         ["Page forward" gnus-summary-next-page
2414          ,@(if (featurep 'xemacs) '(t)
2415              '(:help "Show next page of article"))]
2416         ["Page backward" gnus-summary-prev-page
2417          ,@(if (featurep 'xemacs) '(t)
2418              '(:help "Show previous page of article"))]
2419         ["Line forward" gnus-summary-scroll-up t])
2420        ("Move"
2421         ["Next unread article" gnus-summary-next-unread-article t]
2422         ["Previous unread article" gnus-summary-prev-unread-article t]
2423         ["Next article" gnus-summary-next-article t]
2424         ["Previous article" gnus-summary-prev-article t]
2425         ["Next unread subject" gnus-summary-next-unread-subject t]
2426         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2427         ["Next article same subject" gnus-summary-next-same-subject t]
2428         ["Previous article same subject" gnus-summary-prev-same-subject t]
2429         ["First unread article" gnus-summary-first-unread-article t]
2430         ["Best unread article" gnus-summary-best-unread-article t]
2431         ["Go to subject number..." gnus-summary-goto-subject t]
2432         ["Go to article number..." gnus-summary-goto-article t]
2433         ["Go to the last article" gnus-summary-goto-last-article t]
2434         ["Pop article off history" gnus-summary-pop-article t])
2435        ("Sort"
2436         ["Sort by number" gnus-summary-sort-by-number t]
2437         ["Sort by author" gnus-summary-sort-by-author t]
2438         ["Sort by subject" gnus-summary-sort-by-subject t]
2439         ["Sort by date" gnus-summary-sort-by-date t]
2440         ["Sort by score" gnus-summary-sort-by-score t]
2441         ["Sort by lines" gnus-summary-sort-by-lines t]
2442         ["Sort by characters" gnus-summary-sort-by-chars t]
2443         ["Randomize" gnus-summary-sort-by-random t]
2444         ["Original sort" gnus-summary-sort-by-original t])
2445        ("Help"
2446         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2447         ["Describe group" gnus-summary-describe-group t]
2448         ["Fetch charter" gnus-group-fetch-charter
2449          ,@(if (featurep 'xemacs) nil
2450              '(:help "Display the charter of the current group"))]
2451         ["Fetch control message" gnus-group-fetch-control
2452          ,@(if (featurep 'xemacs) nil
2453              '(:help "Display the archived control message for the current group"))]
2454         ["Read manual" gnus-info-find-node t])
2455        ("Modes"
2456         ["Pick and read" gnus-pick-mode t]
2457         ["Binary" gnus-binary-mode t])
2458        ("Regeneration"
2459         ["Regenerate" gnus-summary-prepare t]
2460         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2461         ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2462         ["Toggle threading" gnus-summary-toggle-threads t])
2463        ["See old articles" gnus-summary-insert-old-articles t]
2464        ["See new articles" gnus-summary-insert-new-articles t]
2465        ["Filter articles..." gnus-summary-execute-command t]
2466        ["Run command on articles..." gnus-summary-universal-argument t]
2467        ["Search articles forward..." gnus-summary-search-article-forward t]
2468        ["Search articles backward..." gnus-summary-search-article-backward t]
2469        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2470        ["Expand window" gnus-summary-expand-window t]
2471        ["Expire expirable articles" gnus-summary-expire-articles
2472         (gnus-check-backend-function
2473          'request-expire-articles gnus-newsgroup-name)]
2474        ["Edit local kill file" gnus-summary-edit-local-kill t]
2475        ["Edit main kill file" gnus-summary-edit-global-kill t]
2476        ["Edit group parameters" gnus-summary-edit-parameters t]
2477        ["Customize group parameters" gnus-summary-customize-parameters t]
2478        ["Send a bug report" gnus-bug t]
2479        ("Exit"
2480         ["Catchup and exit" gnus-summary-catchup-and-exit
2481          ,@(if (featurep 'xemacs) '(t)
2482              '(:help "Mark unread articles in this group as read, then exit"))]
2483         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2484         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2485         ["Exit group" gnus-summary-exit
2486          ,@(if (featurep 'xemacs) '(t)
2487              '(:help "Exit current group, return to group selection mode"))]
2488         ["Exit group without updating" gnus-summary-exit-no-update t]
2489         ["Exit and goto next group" gnus-summary-next-group t]
2490         ["Exit and goto prev group" gnus-summary-prev-group t]
2491         ["Reselect group" gnus-summary-reselect-current-group t]
2492         ["Rescan group" gnus-summary-rescan-group t]
2493         ["Update dribble" gnus-summary-save-newsrc t])))
2494
2495     (gnus-run-hooks 'gnus-summary-menu-hook)))
2496
2497 (defvar gnus-summary-tool-bar-map nil)
2498
2499 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2500 (defun gnus-summary-make-tool-bar ()
2501   (if (and (fboundp 'tool-bar-add-item-from-menu)
2502            (default-value 'tool-bar-mode)
2503            (not gnus-summary-tool-bar-map))
2504       (setq gnus-summary-tool-bar-map
2505             (let ((tool-bar-map (make-sparse-keymap))
2506                   (load-path (mm-image-load-path)))
2507               (tool-bar-add-item-from-menu
2508                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2509               (tool-bar-add-item-from-menu
2510                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2511               (tool-bar-add-item-from-menu
2512                'gnus-summary-post-news "post" gnus-summary-mode-map)
2513               (tool-bar-add-item-from-menu
2514                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2515               (tool-bar-add-item-from-menu
2516                'gnus-summary-followup "followup" gnus-summary-mode-map)
2517               (tool-bar-add-item-from-menu
2518                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2519               (tool-bar-add-item-from-menu
2520                'gnus-summary-reply "reply" gnus-summary-mode-map)
2521               (tool-bar-add-item-from-menu
2522                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2523               (tool-bar-add-item-from-menu
2524                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2525               (tool-bar-add-item-from-menu
2526                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2527               (tool-bar-add-item-from-menu
2528                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2529               (tool-bar-add-item-from-menu
2530                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2531               (tool-bar-add-item-from-menu
2532                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2533               (tool-bar-add-item-from-menu
2534                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2535               (tool-bar-add-item-from-menu
2536                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2537               tool-bar-map)))
2538   (if gnus-summary-tool-bar-map
2539       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2540
2541 (defun gnus-score-set-default (var value)
2542   "A version of set that updates the GNU Emacs menu-bar."
2543   (set var value)
2544   ;; It is the message that forces the active status to be updated.
2545   (message ""))
2546
2547 (defun gnus-make-score-map (type)
2548   "Make a summary score map of type TYPE."
2549   (if t
2550       nil
2551     (let ((headers '(("author" "from" string)
2552                      ("subject" "subject" string)
2553                      ("article body" "body" string)
2554                      ("article head" "head" string)
2555                      ("xref" "xref" string)
2556                      ("extra header" "extra" string)
2557                      ("lines" "lines" number)
2558                      ("followups to author" "followup" string)))
2559           (types '((number ("less than" <)
2560                            ("greater than" >)
2561                            ("equal" =))
2562                    (string ("substring" s)
2563                            ("exact string" e)
2564                            ("fuzzy string" f)
2565                            ("regexp" r))))
2566           (perms '(("temporary" (current-time-string))
2567                    ("permanent" nil)
2568                    ("immediate" now)))
2569           header)
2570       (list
2571        (apply
2572         'nconc
2573         (list
2574          (if (eq type 'lower)
2575              "Lower score"
2576            "Increase score"))
2577         (let (outh)
2578           (while headers
2579             (setq header (car headers))
2580             (setq outh
2581                   (cons
2582                    (apply
2583                     'nconc
2584                     (list (car header))
2585                     (let ((ts (cdr (assoc (nth 2 header) types)))
2586                           outt)
2587                       (while ts
2588                         (setq outt
2589                               (cons
2590                                (apply
2591                                 'nconc
2592                                 (list (caar ts))
2593                                 (let ((ps perms)
2594                                       outp)
2595                                   (while ps
2596                                     (setq outp
2597                                           (cons
2598                                            (vector
2599                                             (caar ps)
2600                                             (list
2601                                              'gnus-summary-score-entry
2602                                              (nth 1 header)
2603                                              (if (or (string= (nth 1 header)
2604                                                               "head")
2605                                                      (string= (nth 1 header)
2606                                                               "body"))
2607                                                  ""
2608                                                (list 'gnus-summary-header
2609                                                      (nth 1 header)))
2610                                              (list 'quote (nth 1 (car ts)))
2611                                              (list 'gnus-score-delta-default
2612                                                    nil)
2613                                              (nth 1 (car ps))
2614                                              t)
2615                                             t)
2616                                            outp))
2617                                     (setq ps (cdr ps)))
2618                                   (list (nreverse outp))))
2619                                outt))
2620                         (setq ts (cdr ts)))
2621                       (list (nreverse outt))))
2622                    outh))
2623             (setq headers (cdr headers)))
2624           (list (nreverse outh))))))))
2625
2626 \f
2627
2628 (defun gnus-summary-mode (&optional group)
2629   "Major mode for reading articles.
2630
2631 All normal editing commands are switched off.
2632 \\<gnus-summary-mode-map>
2633 Each line in this buffer represents one article.  To read an
2634 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2635 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2636 respectively.
2637
2638 You can also post articles and send mail from this buffer.  To
2639 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2640 of an article, type `\\[gnus-summary-reply]'.
2641
2642 There are approx. one gazillion commands you can execute in this
2643 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2644
2645 The following commands are available:
2646
2647 \\{gnus-summary-mode-map}"
2648   (interactive)
2649   (kill-all-local-variables)
2650   (when (gnus-visual-p 'summary-menu 'menu)
2651     (gnus-summary-make-menu-bar)
2652     (gnus-summary-make-tool-bar))
2653   (gnus-summary-make-local-variables)
2654   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2655     (gnus-summary-make-local-variables))
2656   (gnus-make-thread-indent-array)
2657   (gnus-simplify-mode-line)
2658   (setq major-mode 'gnus-summary-mode)
2659   (setq mode-name "Summary")
2660   (make-local-variable 'minor-mode-alist)
2661   (use-local-map gnus-summary-mode-map)
2662   (buffer-disable-undo)
2663   (setq buffer-read-only t)             ;Disable modification
2664   (setq truncate-lines t)
2665   (setq selective-display t)
2666   (setq selective-display-ellipses t)   ;Display `...'
2667   (gnus-summary-set-display-table)
2668   (gnus-set-default-directory)
2669   (setq gnus-newsgroup-name group)
2670   (unless (gnus-news-group-p group)
2671     (setq gnus-newsgroup-incorporated
2672           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2673   (make-local-variable 'gnus-summary-line-format)
2674   (make-local-variable 'gnus-summary-line-format-spec)
2675   (make-local-variable 'gnus-summary-dummy-line-format)
2676   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2677   (make-local-variable 'gnus-summary-mark-positions)
2678   (gnus-make-local-hook 'pre-command-hook)
2679   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2680   (gnus-run-hooks 'gnus-summary-mode-hook)
2681   (turn-on-gnus-mailing-list-mode)
2682   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2683   (gnus-update-summary-mark-positions))
2684
2685 (defun gnus-summary-make-local-variables ()
2686   "Make all the local summary buffer variables."
2687   (let (global)
2688     (dolist (local gnus-summary-local-variables)
2689       (if (consp local)
2690           (progn
2691             (if (eq (cdr local) 'global)
2692                 ;; Copy the global value of the variable.
2693                 (setq global (symbol-value (car local)))
2694               ;; Use the value from the list.
2695               (setq global (eval (cdr local))))
2696             (set (make-local-variable (car local)) global))
2697         ;; Simple nil-valued local variable.
2698         (set (make-local-variable local) nil)))))
2699
2700 (defun gnus-summary-clear-local-variables ()
2701   (let ((locals gnus-summary-local-variables))
2702     (while locals
2703       (if (consp (car locals))
2704           (and (vectorp (caar locals))
2705                (set (caar locals) nil))
2706         (and (vectorp (car locals))
2707              (set (car locals) nil)))
2708       (setq locals (cdr locals)))))
2709
2710 ;; Summary data functions.
2711
2712 (defmacro gnus-data-number (data)
2713   `(car ,data))
2714
2715 (defmacro gnus-data-set-number (data number)
2716   `(setcar ,data ,number))
2717
2718 (defmacro gnus-data-mark (data)
2719   `(nth 1 ,data))
2720
2721 (defmacro gnus-data-set-mark (data mark)
2722   `(setcar (nthcdr 1 ,data) ,mark))
2723
2724 (defmacro gnus-data-pos (data)
2725   `(nth 2 ,data))
2726
2727 (defmacro gnus-data-set-pos (data pos)
2728   `(setcar (nthcdr 2 ,data) ,pos))
2729
2730 (defmacro gnus-data-header (data)
2731   `(nth 3 ,data))
2732
2733 (defmacro gnus-data-set-header (data header)
2734   `(setcar (nthcdr 3 ,data) ,header))
2735
2736 (defmacro gnus-data-level (data)
2737   `(nth 4 ,data))
2738
2739 (defmacro gnus-data-unread-p (data)
2740   `(= (nth 1 ,data) gnus-unread-mark))
2741
2742 (defmacro gnus-data-read-p (data)
2743   `(/= (nth 1 ,data) gnus-unread-mark))
2744
2745 (defmacro gnus-data-pseudo-p (data)
2746   `(consp (nth 3 ,data)))
2747
2748 (defmacro gnus-data-find (number)
2749   `(assq ,number gnus-newsgroup-data))
2750
2751 (defmacro gnus-data-find-list (number &optional data)
2752   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2753      (memq (assq ,number bdata)
2754            bdata)))
2755
2756 (defmacro gnus-data-make (number mark pos header level)
2757   `(list ,number ,mark ,pos ,header ,level))
2758
2759 (defun gnus-data-enter (after-article number mark pos header level offset)
2760   (let ((data (gnus-data-find-list after-article)))
2761     (unless data
2762       (error "No such article: %d" after-article))
2763     (setcdr data (cons (gnus-data-make number mark pos header level)
2764                        (cdr data)))
2765     (setq gnus-newsgroup-data-reverse nil)
2766     (gnus-data-update-list (cddr data) offset)))
2767
2768 (defun gnus-data-enter-list (after-article list &optional offset)
2769   (when list
2770     (let ((data (and after-article (gnus-data-find-list after-article)))
2771           (ilist list))
2772       (if (not (or data
2773                    after-article))
2774           (let ((odata gnus-newsgroup-data))
2775             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2776             (when offset
2777               (gnus-data-update-list odata offset)))
2778         ;; Find the last element in the list to be spliced into the main
2779         ;; list.
2780         (while (cdr list)
2781           (setq list (cdr list)))
2782         (if (not data)
2783             (progn
2784               (setcdr list gnus-newsgroup-data)
2785               (setq gnus-newsgroup-data ilist)
2786               (when offset
2787                 (gnus-data-update-list (cdr list) offset)))
2788           (setcdr list (cdr data))
2789           (setcdr data ilist)
2790           (when offset
2791             (gnus-data-update-list (cdr list) offset))))
2792       (setq gnus-newsgroup-data-reverse nil))))
2793
2794 (defun gnus-data-remove (article &optional offset)
2795   (let ((data gnus-newsgroup-data))
2796     (if (= (gnus-data-number (car data)) article)
2797         (progn
2798           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2799                 gnus-newsgroup-data-reverse nil)
2800           (when offset
2801             (gnus-data-update-list gnus-newsgroup-data offset)))
2802       (while (cdr data)
2803         (when (= (gnus-data-number (cadr data)) article)
2804           (setcdr data (cddr data))
2805           (when offset
2806             (gnus-data-update-list (cdr data) offset))
2807           (setq data nil
2808                 gnus-newsgroup-data-reverse nil))
2809         (setq data (cdr data))))))
2810
2811 (defmacro gnus-data-list (backward)
2812   `(if ,backward
2813        (or gnus-newsgroup-data-reverse
2814            (setq gnus-newsgroup-data-reverse
2815                  (reverse gnus-newsgroup-data)))
2816      gnus-newsgroup-data))
2817
2818 (defun gnus-data-update-list (data offset)
2819   "Add OFFSET to the POS of all data entries in DATA."
2820   (setq gnus-newsgroup-data-reverse nil)
2821   (while data
2822     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2823     (setq data (cdr data))))
2824
2825 (defun gnus-summary-article-pseudo-p (article)
2826   "Say whether this article is a pseudo article or not."
2827   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2828
2829 (defmacro gnus-summary-article-sparse-p (article)
2830   "Say whether this article is a sparse article or not."
2831   `(memq ,article gnus-newsgroup-sparse))
2832
2833 (defmacro gnus-summary-article-ancient-p (article)
2834   "Say whether this article is a sparse article or not."
2835   `(memq ,article gnus-newsgroup-ancient))
2836
2837 (defun gnus-article-parent-p (number)
2838   "Say whether this article is a parent or not."
2839   (let ((data (gnus-data-find-list number)))
2840     (and (cdr data)                     ; There has to be an article after...
2841          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2842             (gnus-data-level (nth 1 data))))))
2843
2844 (defun gnus-article-children (number)
2845   "Return a list of all children to NUMBER."
2846   (let* ((data (gnus-data-find-list number))
2847          (level (gnus-data-level (car data)))
2848          children)
2849     (setq data (cdr data))
2850     (while (and data
2851                 (= (gnus-data-level (car data)) (1+ level)))
2852       (push (gnus-data-number (car data)) children)
2853       (setq data (cdr data)))
2854     children))
2855
2856 (defmacro gnus-summary-skip-intangible ()
2857   "If the current article is intangible, then jump to a different article."
2858   '(let ((to (get-text-property (point) 'gnus-intangible)))
2859      (and to (gnus-summary-goto-subject to))))
2860
2861 (defmacro gnus-summary-article-intangible-p ()
2862   "Say whether this article is intangible or not."
2863   '(get-text-property (point) 'gnus-intangible))
2864
2865 (defun gnus-article-read-p (article)
2866   "Say whether ARTICLE is read or not."
2867   (not (or (memq article gnus-newsgroup-marked)
2868            (memq article gnus-newsgroup-spam-marked)
2869            (memq article gnus-newsgroup-unreads)
2870            (memq article gnus-newsgroup-unselected)
2871            (memq article gnus-newsgroup-dormant))))
2872
2873 ;; Some summary mode macros.
2874
2875 (defmacro gnus-summary-article-number ()
2876   "The article number of the article on the current line.
2877 If there isn't an article number here, then we return the current
2878 article number."
2879   '(progn
2880      (gnus-summary-skip-intangible)
2881      (or (get-text-property (point) 'gnus-number)
2882          (gnus-summary-last-subject))))
2883
2884 (defmacro gnus-summary-article-header (&optional number)
2885   "Return the header of article NUMBER."
2886   `(gnus-data-header (gnus-data-find
2887                       ,(or number '(gnus-summary-article-number)))))
2888
2889 (defmacro gnus-summary-thread-level (&optional number)
2890   "Return the level of thread that starts with article NUMBER."
2891   `(if (and (eq gnus-summary-make-false-root 'dummy)
2892             (get-text-property (point) 'gnus-intangible))
2893        0
2894      (gnus-data-level (gnus-data-find
2895                        ,(or number '(gnus-summary-article-number))))))
2896
2897 (defmacro gnus-summary-article-mark (&optional number)
2898   "Return the mark of article NUMBER."
2899   `(gnus-data-mark (gnus-data-find
2900                     ,(or number '(gnus-summary-article-number)))))
2901
2902 (defmacro gnus-summary-article-pos (&optional number)
2903   "Return the position of the line of article NUMBER."
2904   `(gnus-data-pos (gnus-data-find
2905                    ,(or number '(gnus-summary-article-number)))))
2906
2907 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2908 (defmacro gnus-summary-article-subject (&optional number)
2909   "Return current subject string or nil if nothing."
2910   `(let ((headers
2911           ,(if number
2912                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2913              '(gnus-data-header (assq (gnus-summary-article-number)
2914                                       gnus-newsgroup-data)))))
2915      (and headers
2916           (vectorp headers)
2917           (mail-header-subject headers))))
2918
2919 (defmacro gnus-summary-article-score (&optional number)
2920   "Return current article score."
2921   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2922                   gnus-newsgroup-scored))
2923        gnus-summary-default-score 0))
2924
2925 (defun gnus-summary-article-children (&optional number)
2926   "Return a list of article numbers that are children of article NUMBER."
2927   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2928          (level (gnus-data-level (car data)))
2929          l children)
2930     (while (and (setq data (cdr data))
2931                 (> (setq l (gnus-data-level (car data))) level))
2932       (and (= (1+ level) l)
2933            (push (gnus-data-number (car data))
2934                  children)))
2935     (nreverse children)))
2936
2937 (defun gnus-summary-article-parent (&optional number)
2938   "Return the article number of the parent of article NUMBER."
2939   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2940                                     (gnus-data-list t)))
2941          (level (gnus-data-level (car data))))
2942     (if (zerop level)
2943         ()                              ; This is a root.
2944       ;; We search until we find an article with a level less than
2945       ;; this one.  That function has to be the parent.
2946       (while (and (setq data (cdr data))
2947                   (not (< (gnus-data-level (car data)) level))))
2948       (and data (gnus-data-number (car data))))))
2949
2950 (defun gnus-unread-mark-p (mark)
2951   "Say whether MARK is the unread mark."
2952   (= mark gnus-unread-mark))
2953
2954 (defun gnus-read-mark-p (mark)
2955   "Say whether MARK is one of the marks that mark as read.
2956 This is all marks except unread, ticked, dormant, and expirable."
2957   (not (or (= mark gnus-unread-mark)
2958            (= mark gnus-ticked-mark)
2959            (= mark gnus-spam-mark)
2960            (= mark gnus-dormant-mark)
2961            (= mark gnus-expirable-mark))))
2962
2963 (defmacro gnus-article-mark (number)
2964   "Return the MARK of article NUMBER.
2965 This macro should only be used when computing the mark the \"first\"
2966 time; i.e., when generating the summary lines.  After that,
2967 `gnus-summary-article-mark' should be used to examine the
2968 marks of articles."
2969   `(cond
2970     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2971     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2972     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2973     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2974     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2975     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2976     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2977     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2978            gnus-ancient-mark))))
2979
2980 ;; Saving hidden threads.
2981
2982 (defmacro gnus-save-hidden-threads (&rest forms)
2983   "Save hidden threads, eval FORMS, and restore the hidden threads."
2984   (let ((config (make-symbol "config")))
2985     `(let ((,config (gnus-hidden-threads-configuration)))
2986        (unwind-protect
2987            (save-excursion
2988              ,@forms)
2989          (gnus-restore-hidden-threads-configuration ,config)))))
2990 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2991 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2992
2993 (defun gnus-data-compute-positions ()
2994   "Compute the positions of all articles."
2995   (setq gnus-newsgroup-data-reverse nil)
2996   (let ((data gnus-newsgroup-data))
2997     (save-excursion
2998       (gnus-save-hidden-threads
2999         (gnus-summary-show-all-threads)
3000         (goto-char (point-min))
3001         (while data
3002           (while (get-text-property (point) 'gnus-intangible)
3003             (forward-line 1))
3004           (gnus-data-set-pos (car data) (+ (point) 3))
3005           (setq data (cdr data))
3006           (forward-line 1))))))
3007
3008 (defun gnus-hidden-threads-configuration ()
3009   "Return the current hidden threads configuration."
3010   (save-excursion
3011     (let (config)
3012       (goto-char (point-min))
3013       (while (search-forward "\r" nil t)
3014         (push (1- (point)) config))
3015       config)))
3016
3017 (defun gnus-restore-hidden-threads-configuration (config)
3018   "Restore hidden threads configuration from CONFIG."
3019   (save-excursion
3020     (let (point buffer-read-only)
3021       (while (setq point (pop config))
3022         (when (and (< point (point-max))
3023                    (goto-char point)
3024                    (eq (char-after) ?\n))
3025           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3026
3027 ;; Various summary mode internalish functions.
3028
3029 (defun gnus-mouse-pick-article (e)
3030   (interactive "e")
3031   (mouse-set-point e)
3032   (gnus-summary-next-page nil t))
3033
3034 (defun gnus-summary-set-display-table ()
3035   "Change the display table.
3036 Odd characters have a tendency to mess
3037 up nicely formatted displays - we make all possible glyphs
3038 display only a single character."
3039
3040   ;; We start from the standard display table, if any.
3041   (let ((table (or (copy-sequence standard-display-table)
3042                    (make-display-table)))
3043         (i 32))
3044     ;; Nix out all the control chars...
3045     (while (>= (setq i (1- i)) 0)
3046       (aset table i [??]))
3047     ;; ... but not newline and cr, of course.  (cr is necessary for the
3048     ;; selective display).
3049     (aset table ?\n nil)
3050     (aset table ?\r nil)
3051     ;; We keep TAB as well.
3052     (aset table ?\t nil)
3053     ;; We nix out any glyphs over 126 that are not set already.
3054     (let ((i 256))
3055       (while (>= (setq i (1- i)) 127)
3056         ;; Only modify if the entry is nil.
3057         (unless (aref table i)
3058           (aset table i [??]))))
3059     (setq buffer-display-table table)))
3060
3061 (defun gnus-summary-set-article-display-arrow (pos)
3062   "Update the overlay arrow to point to line at position POS."
3063   (when (and gnus-summary-display-arrow
3064              (boundp 'overlay-arrow-position)
3065              (boundp 'overlay-arrow-string))
3066     (save-excursion
3067       (goto-char pos)
3068       (beginning-of-line)
3069       (unless overlay-arrow-position
3070         (setq overlay-arrow-position (make-marker)))
3071       (setq overlay-arrow-string "=>"
3072             overlay-arrow-position (set-marker overlay-arrow-position
3073                                                (point)
3074                                                (current-buffer))))))
3075
3076 (defun gnus-summary-setup-buffer (group)
3077   "Initialize summary buffer."
3078   (let ((buffer (gnus-summary-buffer-name group))
3079         (dead-name (concat "*Dead Summary "
3080                            (gnus-group-decoded-name group) "*")))
3081     ;; If a dead summary buffer exists, we kill it.
3082     (when (gnus-buffer-live-p dead-name)
3083       (gnus-kill-buffer dead-name))
3084     (if (get-buffer buffer)
3085         (progn
3086           (set-buffer buffer)
3087           (setq gnus-summary-buffer (current-buffer))
3088           (not gnus-newsgroup-prepared))
3089       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3090       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3091       (gnus-summary-mode group)
3092       (when gnus-carpal
3093         (gnus-carpal-setup-buffer 'summary))
3094       (unless gnus-single-article-buffer
3095         (make-local-variable 'gnus-article-buffer)
3096         (make-local-variable 'gnus-article-current)
3097         (make-local-variable 'gnus-original-article-buffer))
3098       (setq gnus-newsgroup-name group)
3099       ;; Set any local variables in the group parameters.
3100       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3101       t)))
3102
3103 (defun gnus-set-global-variables ()
3104   "Set the global equivalents of the buffer-local variables.
3105 They are set to the latest values they had.  These reflect the summary
3106 buffer that was in action when the last article was fetched."
3107   (when (eq major-mode 'gnus-summary-mode)
3108     (setq gnus-summary-buffer (current-buffer))
3109     (let ((name gnus-newsgroup-name)
3110           (marked gnus-newsgroup-marked)
3111           (spam gnus-newsgroup-spam-marked)
3112           (unread gnus-newsgroup-unreads)
3113           (headers gnus-current-headers)
3114           (data gnus-newsgroup-data)
3115           (summary gnus-summary-buffer)
3116           (article-buffer gnus-article-buffer)
3117           (original gnus-original-article-buffer)
3118           (gac gnus-article-current)
3119           (reffed gnus-reffed-article-number)
3120           (score-file gnus-current-score-file)
3121           (default-charset gnus-newsgroup-charset)
3122           vlist)
3123       (let ((locals gnus-newsgroup-variables))
3124         (while locals
3125           (if (consp (car locals))
3126               (push (eval (caar locals)) vlist)
3127             (push (eval (car locals)) vlist))
3128           (setq locals (cdr locals)))
3129         (setq vlist (nreverse vlist)))
3130       (save-excursion
3131         (set-buffer gnus-group-buffer)
3132         (setq gnus-newsgroup-name name
3133               gnus-newsgroup-marked marked
3134               gnus-newsgroup-spam-marked spam
3135               gnus-newsgroup-unreads unread
3136               gnus-current-headers headers
3137               gnus-newsgroup-data data
3138               gnus-article-current gac
3139               gnus-summary-buffer summary
3140               gnus-article-buffer article-buffer
3141               gnus-original-article-buffer original
3142               gnus-reffed-article-number reffed
3143               gnus-current-score-file score-file
3144               gnus-newsgroup-charset default-charset)
3145         (let ((locals gnus-newsgroup-variables))
3146           (while locals
3147             (if (consp (car locals))
3148                 (set (caar locals) (pop vlist))
3149               (set (car locals) (pop vlist)))
3150             (setq locals (cdr locals))))
3151         ;; The article buffer also has local variables.
3152         (when (gnus-buffer-live-p gnus-article-buffer)
3153           (set-buffer gnus-article-buffer)
3154           (setq gnus-summary-buffer summary))))))
3155
3156 (defun gnus-summary-article-unread-p (article)
3157   "Say whether ARTICLE is unread or not."
3158   (memq article gnus-newsgroup-unreads))
3159
3160 (defun gnus-summary-first-article-p (&optional article)
3161   "Return whether ARTICLE is the first article in the buffer."
3162   (if (not (setq article (or article (gnus-summary-article-number))))
3163       nil
3164     (eq article (caar gnus-newsgroup-data))))
3165
3166 (defun gnus-summary-last-article-p (&optional article)
3167   "Return whether ARTICLE is the last article in the buffer."
3168   (if (not (setq article (or article (gnus-summary-article-number))))
3169       ;; All non-existent numbers are the last article.  :-)
3170       t
3171     (not (cdr (gnus-data-find-list article)))))
3172
3173 (defun gnus-make-thread-indent-array ()
3174   (let ((n 200))
3175     (unless (and gnus-thread-indent-array
3176                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3177       (setq gnus-thread-indent-array (make-vector 201 "")
3178             gnus-thread-indent-array-level gnus-thread-indent-level)
3179       (while (>= n 0)
3180         (aset gnus-thread-indent-array n
3181               (make-string (* n gnus-thread-indent-level) ? ))
3182         (setq n (1- n))))))
3183
3184 (defun gnus-update-summary-mark-positions ()
3185   "Compute where the summary marks are to go."
3186   (save-excursion
3187     (when (gnus-buffer-exists-p gnus-summary-buffer)
3188       (set-buffer gnus-summary-buffer))
3189     (let ((gnus-replied-mark 129)
3190           (gnus-score-below-mark 130)
3191           (gnus-score-over-mark 130)
3192           (gnus-undownloaded-mark 131)
3193           (spec gnus-summary-line-format-spec)
3194           gnus-visual pos)
3195       (save-excursion
3196         (gnus-set-work-buffer)
3197         (let ((gnus-summary-line-format-spec spec)
3198               (gnus-newsgroup-downloadable '(0)))
3199           (gnus-summary-insert-line
3200            (make-full-mail-header 0 "" "nobody"
3201                                   "05 Apr 2001 23:33:09 +0400"
3202                                   "" "" 0 0 "" nil)
3203            0 nil t 128 t nil "" nil 1)
3204           (goto-char (point-min))
3205           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3206                                              (- (point) (point-min) 1)))))
3207           (goto-char (point-min))
3208           (push (cons 'replied (and (search-forward "\201" nil t)
3209                                     (- (point) (point-min) 1)))
3210                 pos)
3211           (goto-char (point-min))
3212           (push (cons 'score (and (search-forward "\202" nil t)
3213                                   (- (point) (point-min) 1)))
3214                 pos)
3215           (goto-char (point-min))
3216           (push (cons 'download
3217                       (and (search-forward "\203" nil t)
3218                            (- (point) (point-min) 1)))
3219                 pos)))
3220       (setq gnus-summary-mark-positions pos))))
3221
3222 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3223   "Insert a dummy root in the summary buffer."
3224   (beginning-of-line)
3225   (gnus-add-text-properties
3226    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3227    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3228
3229 (defun gnus-summary-extract-address-component (from)
3230   (or (car (funcall gnus-extract-address-components from))
3231       from))
3232
3233 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3234   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3235                                 default-mime-charset)))
3236     ;; Is it really necessary to do this next part for each summary line?
3237     ;; Luckily, doesn't seem to slow things down much.
3238     (or
3239      (and gnus-ignored-from-addresses
3240           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3241           (let ((extra-headers (mail-header-extra header))
3242                 to
3243                 newsgroups)
3244             (cond
3245              ((setq to (cdr (assq 'To extra-headers)))
3246               (concat "-> "
3247                       (inline
3248                         (gnus-summary-extract-address-component
3249                          (funcall gnus-decode-encoded-word-function to)))))
3250              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3251               (concat "=> " newsgroups)))))
3252      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3253
3254 (defun gnus-summary-insert-line (gnus-tmp-header
3255                                  gnus-tmp-level gnus-tmp-current
3256                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3257                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3258                                  &optional gnus-tmp-dummy gnus-tmp-score
3259                                  gnus-tmp-process)
3260   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3261          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3262          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3263          (gnus-tmp-score-char
3264           (if (or (null gnus-summary-default-score)
3265                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3266                       gnus-summary-zcore-fuzz))
3267               ?\ ;;;Whitespace
3268             (if (< gnus-tmp-score gnus-summary-default-score)
3269                 gnus-score-below-mark gnus-score-over-mark)))
3270          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3271          (gnus-tmp-replied
3272           (cond (gnus-tmp-process gnus-process-mark)
3273                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3274                  gnus-cached-mark)
3275                 (gnus-tmp-replied gnus-replied-mark)
3276                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3277                  gnus-forwarded-mark)
3278                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3279                  gnus-saved-mark)
3280                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3281                  gnus-recent-mark)
3282                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3283                  gnus-unseen-mark)
3284                 (t gnus-no-mark)))
3285          (gnus-tmp-downloaded
3286           (cond (undownloaded
3287                  gnus-undownloaded-mark)
3288                 (gnus-newsgroup-agentized
3289                  gnus-downloaded-mark)
3290                 (t
3291                  gnus-no-mark)))
3292          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3293          (gnus-tmp-name
3294           (cond
3295            ((string-match "<[^>]+> *$" gnus-tmp-from)
3296             (let ((beg (match-beginning 0)))
3297               (or (and (string-match "^\".+\"" gnus-tmp-from)
3298                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3299                   (substring gnus-tmp-from 0 beg))))
3300            ((string-match "(.+)" gnus-tmp-from)
3301             (substring gnus-tmp-from
3302                        (1+ (match-beginning 0)) (1- (match-end 0))))
3303            (t gnus-tmp-from)))
3304          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3305          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3306          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3307          (buffer-read-only nil))
3308     (when (string= gnus-tmp-name "")
3309       (setq gnus-tmp-name gnus-tmp-from))
3310     (unless (numberp gnus-tmp-lines)
3311       (setq gnus-tmp-lines -1))
3312     (if (= gnus-tmp-lines -1)
3313         (setq gnus-tmp-lines "?")
3314       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3315     (gnus-put-text-property-excluding-characters-with-faces
3316      (point)
3317      (progn (eval gnus-summary-line-format-spec) (point))
3318      'gnus-number gnus-tmp-number)
3319     (when (gnus-visual-p 'summary-highlight 'highlight)
3320       (forward-line -1)
3321       (gnus-run-hooks 'gnus-summary-update-hook)
3322       (forward-line 1))))
3323
3324 (defun gnus-summary-update-line (&optional dont-update)
3325   "Update summary line after change."
3326   (when (and gnus-summary-default-score
3327              (not gnus-summary-inhibit-highlight))
3328     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3329            (article (gnus-summary-article-number))
3330            (score (gnus-summary-article-score article)))
3331       (unless dont-update
3332         (if (and gnus-summary-mark-below
3333                  (< (gnus-summary-article-score)
3334                     gnus-summary-mark-below))
3335             ;; This article has a low score, so we mark it as read.
3336             (when (memq article gnus-newsgroup-unreads)
3337               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3338           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3339             ;; This article was previously marked as read on account
3340             ;; of a low score, but now it has risen, so we mark it as
3341             ;; unread.
3342             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3343         (gnus-summary-update-mark
3344          (if (or (null gnus-summary-default-score)
3345                  (<= (abs (- score gnus-summary-default-score))
3346                      gnus-summary-zcore-fuzz))
3347              ?\ ;;;Whitespace
3348            (if (< score gnus-summary-default-score)
3349                gnus-score-below-mark gnus-score-over-mark))
3350          'score))
3351       ;; Do visual highlighting.
3352       (when (gnus-visual-p 'summary-highlight 'highlight)
3353         (gnus-run-hooks 'gnus-summary-update-hook)))))
3354
3355 (defvar gnus-tmp-new-adopts nil)
3356
3357 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3358   "Return the number of articles in THREAD.
3359 This may be 0 in some cases -- if none of the articles in
3360 the thread are to be displayed."
3361   (let* ((number
3362           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3363           (cond
3364            ((not (listp thread))
3365             1)
3366            ((and (consp thread) (cdr thread))
3367             (apply
3368              '+ 1 (mapcar
3369                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3370            ((null thread)
3371             1)
3372            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3373             1)
3374            (t 0))))
3375     (when (and level (zerop level) gnus-tmp-new-adopts)
3376       (incf number
3377             (apply '+ (mapcar
3378                        'gnus-summary-number-of-articles-in-thread
3379                        gnus-tmp-new-adopts))))
3380     (if char
3381         (if (> number 1) gnus-not-empty-thread-mark
3382           gnus-empty-thread-mark)
3383       number)))
3384
3385 (defsubst gnus-summary-line-message-size (head)
3386   "Return pretty-printed version of message size.
3387 This function is intended to be used in
3388 `gnus-summary-line-format-alist'."
3389   (let ((c (or (mail-header-chars head) -1)))
3390     (cond ((< c 0) "n/a")               ; chars not available
3391           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3392           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3393           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3394           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3395
3396
3397 (defun gnus-summary-set-local-parameters (group)
3398   "Go through the local params of GROUP and set all variable specs in that list."
3399   (let ((params (gnus-group-find-parameter group))
3400         (vars '(quit-config))           ; Ignore quit-config.
3401         elem)
3402     (while params
3403       (setq elem (car params)
3404             params (cdr params))
3405       (and (consp elem)                 ; Has to be a cons.
3406            (consp (cdr elem))           ; The cdr has to be a list.
3407            (symbolp (car elem))         ; Has to be a symbol in there.
3408            (not (memq (car elem) vars))
3409            (ignore-errors               ; So we set it.
3410              (push (car elem) vars)
3411              (make-local-variable (car elem))
3412              (set (car elem) (eval (nth 1 elem))))))))
3413
3414 (defun gnus-summary-read-group (group &optional show-all no-article
3415                                       kill-buffer no-display backward
3416                                       select-articles)
3417   "Start reading news in newsgroup GROUP.
3418 If SHOW-ALL is non-nil, already read articles are also listed.
3419 If NO-ARTICLE is non-nil, no article is selected initially.
3420 If NO-DISPLAY, don't generate a summary buffer."
3421   (let (result)
3422     (while (and group
3423                 (null (setq result
3424                             (let ((gnus-auto-select-next nil))
3425                               (or (gnus-summary-read-group-1
3426                                    group show-all no-article
3427                                    kill-buffer no-display
3428                                    select-articles)
3429                                   (setq show-all nil
3430                                         select-articles nil)))))
3431                 (eq gnus-auto-select-next 'quietly))
3432       (set-buffer gnus-group-buffer)
3433       ;; The entry function called above goes to the next
3434       ;; group automatically, so we go two groups back
3435       ;; if we are searching for the previous group.
3436       (when backward
3437         (gnus-group-prev-unread-group 2))
3438       (if (not (equal group (gnus-group-group-name)))
3439           (setq group (gnus-group-group-name))
3440         (setq group nil)))
3441     result))
3442
3443 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3444   "Directly jump to the other GROUP from summary buffer.
3445 If SHOW-ALL is non-nil, already read articles are also listed."
3446   (interactive
3447    (if (eq gnus-summary-buffer (current-buffer))
3448        (list (completing-read
3449               "Group: " gnus-active-hashtb nil t
3450               (when (and gnus-newsgroup-name
3451                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3452                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3453               'gnus-group-history)
3454              current-prefix-arg)
3455      (error "%s must be invoked from a gnus summary buffer." this-command)))
3456   (unless (or (zerop (length group))
3457               (and gnus-newsgroup-name
3458                    (string-equal gnus-newsgroup-name group)))
3459     (gnus-summary-exit)
3460     (gnus-summary-read-group group show-all
3461                              gnus-dont-select-after-jump-to-other-group)))
3462
3463 (defun gnus-summary-read-group-1 (group show-all no-article
3464                                         kill-buffer no-display
3465                                         &optional select-articles)
3466   ;; Killed foreign groups can't be entered.
3467   ;;  (when (and (not (gnus-group-native-p group))
3468   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3469   ;;    (error "Dead non-native groups can't be entered"))
3470   (gnus-message 5 "Retrieving newsgroup: %s..."
3471                 (gnus-group-decoded-name group))
3472   (let* ((new-group (gnus-summary-setup-buffer group))
3473          (quit-config (gnus-group-quit-config group))
3474          (did-select (and new-group (gnus-select-newsgroup
3475                                      group show-all select-articles))))
3476     (cond
3477      ;; This summary buffer exists already, so we just select it.
3478      ((not new-group)
3479       (gnus-set-global-variables)
3480       (when kill-buffer
3481         (gnus-kill-or-deaden-summary kill-buffer))
3482       (gnus-configure-windows 'summary 'force)
3483       (gnus-set-mode-line 'summary)
3484       (gnus-summary-position-point)
3485       (message "")
3486       t)
3487      ;; We couldn't select this group.
3488      ((null did-select)
3489       (when (and (eq major-mode 'gnus-summary-mode)
3490                  (not (equal (current-buffer) kill-buffer)))
3491         (kill-buffer (current-buffer))
3492         (if (not quit-config)
3493             (progn
3494               ;; Update the info -- marks might need to be removed,
3495               ;; for instance.
3496               (gnus-summary-update-info)
3497               (set-buffer gnus-group-buffer)
3498               (gnus-group-jump-to-group group)
3499               (gnus-group-next-unread-group 1))
3500           (gnus-handle-ephemeral-exit quit-config)))
3501       (let ((grpinfo (gnus-get-info group)))
3502         (if (null (gnus-info-read grpinfo))
3503             (gnus-message 3 "Group %s contains no messages"
3504                           (gnus-group-decoded-name group))
3505           (gnus-message 3 "Can't select group")))
3506       nil)
3507      ;; The user did a `C-g' while prompting for number of articles,
3508      ;; so we exit this group.
3509      ((eq did-select 'quit)
3510       (and (eq major-mode 'gnus-summary-mode)
3511            (not (equal (current-buffer) kill-buffer))
3512            (kill-buffer (current-buffer)))
3513       (when kill-buffer
3514         (gnus-kill-or-deaden-summary kill-buffer))
3515       (if (not quit-config)
3516           (progn
3517             (set-buffer gnus-group-buffer)
3518             (gnus-group-jump-to-group group)
3519             (gnus-group-next-unread-group 1)
3520             (gnus-configure-windows 'group 'force))
3521         (gnus-handle-ephemeral-exit quit-config))
3522       ;; Finally signal the quit.
3523       (signal 'quit nil))
3524      ;; The group was successfully selected.
3525      (t
3526       (gnus-set-global-variables)
3527       ;; Save the active value in effect when the group was entered.
3528       (setq gnus-newsgroup-active
3529             (gnus-copy-sequence
3530              (gnus-active gnus-newsgroup-name)))
3531       ;; You can change the summary buffer in some way with this hook.
3532       (gnus-run-hooks 'gnus-select-group-hook)
3533       (gnus-update-format-specifications
3534        nil 'summary 'summary-mode 'summary-dummy)
3535       (gnus-update-summary-mark-positions)
3536       ;; Do score processing.
3537       (when gnus-use-scoring
3538         (gnus-possibly-score-headers))
3539       ;; Check whether to fill in the gaps in the threads.
3540       (when gnus-build-sparse-threads
3541         (gnus-build-sparse-threads))
3542       ;; Find the initial limit.
3543       (if gnus-show-threads
3544           (if show-all
3545               (let ((gnus-newsgroup-dormant nil))
3546                 (gnus-summary-initial-limit show-all))
3547             (gnus-summary-initial-limit show-all))
3548         ;; When unthreaded, all articles are always shown.
3549         (setq gnus-newsgroup-limit
3550               (mapcar
3551                (lambda (header) (mail-header-number header))
3552                gnus-newsgroup-headers)))
3553       ;; Generate the summary buffer.
3554       (unless no-display
3555         (gnus-summary-prepare))
3556       (when gnus-use-trees
3557         (gnus-tree-open group)
3558         (setq gnus-summary-highlight-line-function
3559               'gnus-tree-highlight-article))
3560       ;; If the summary buffer is empty, but there are some low-scored
3561       ;; articles or some excluded dormants, we include these in the
3562       ;; buffer.
3563       (when (and (zerop (buffer-size))
3564                  (not no-display))
3565         (cond (gnus-newsgroup-dormant
3566                (gnus-summary-limit-include-dormant))
3567               ((and gnus-newsgroup-scored show-all)
3568                (gnus-summary-limit-include-expunged t))))
3569       ;; Function `gnus-apply-kill-file' must be called in this hook.
3570       (gnus-run-hooks 'gnus-apply-kill-hook)
3571       (if (and (zerop (buffer-size))
3572                (not no-display))
3573           (progn
3574             ;; This newsgroup is empty.
3575             (gnus-summary-catchup-and-exit nil t)
3576             (gnus-message 6 "No unread news")
3577             (when kill-buffer
3578               (gnus-kill-or-deaden-summary kill-buffer))
3579             ;; Return nil from this function.
3580             nil)
3581         ;; Hide conversation thread subtrees.  We cannot do this in
3582         ;; gnus-summary-prepare-hook since kill processing may not
3583         ;; work with hidden articles.
3584         (gnus-summary-maybe-hide-threads)
3585         (when kill-buffer
3586           (gnus-kill-or-deaden-summary kill-buffer))
3587         (gnus-summary-auto-select-subject)
3588         ;; Show first unread article if requested.
3589         (if (and (not no-article)
3590                  (not no-display)
3591                  gnus-newsgroup-unreads
3592                  gnus-auto-select-first)
3593             (progn
3594               (gnus-configure-windows 'summary)
3595               (let ((art (gnus-summary-article-number)))
3596                 (unless (and (not gnus-plugged)
3597                              (or (memq art gnus-newsgroup-undownloaded)
3598                                  (memq art gnus-newsgroup-downloadable)))
3599                   (gnus-summary-goto-article art))))
3600           ;; Don't select any articles.
3601           (gnus-summary-position-point)
3602           (gnus-configure-windows 'summary 'force)
3603           (gnus-set-mode-line 'summary))
3604         (when (and gnus-auto-center-group
3605                    (get-buffer-window gnus-group-buffer t))
3606           ;; Gotta use windows, because recenter does weird stuff if
3607           ;; the current buffer ain't the displayed window.
3608           (let ((owin (selected-window)))
3609             (select-window (get-buffer-window gnus-group-buffer t))
3610             (when (gnus-group-goto-group group)
3611               (recenter))
3612             (select-window owin)))
3613         ;; Mark this buffer as "prepared".
3614         (setq gnus-newsgroup-prepared t)
3615         (gnus-run-hooks 'gnus-summary-prepared-hook)
3616         (unless (gnus-ephemeral-group-p group)
3617           (gnus-group-update-group group))
3618         t)))))
3619
3620 (defun gnus-summary-auto-select-subject ()
3621   "Select the subject line on initial group entry."
3622   (goto-char (point-min))
3623   (cond
3624    ((eq gnus-auto-select-subject 'best)
3625     (gnus-summary-best-unread-subject))
3626    ((eq gnus-auto-select-subject 'unread)
3627     (gnus-summary-first-unread-subject))
3628    ((eq gnus-auto-select-subject 'unseen)
3629     (gnus-summary-first-unseen-subject))
3630    ((eq gnus-auto-select-subject 'unseen-or-unread)
3631     (gnus-summary-first-unseen-or-unread-subject))
3632    ((eq gnus-auto-select-subject 'first)
3633     ;; Do nothing.
3634     )
3635    ((functionp gnus-auto-select-subject)
3636     (funcall gnus-auto-select-subject))))
3637
3638 (defun gnus-summary-prepare ()
3639   "Generate the summary buffer."
3640   (interactive)
3641   (let ((buffer-read-only nil))
3642     (erase-buffer)
3643     (setq gnus-newsgroup-data nil
3644           gnus-newsgroup-data-reverse nil)
3645     (gnus-run-hooks 'gnus-summary-generate-hook)
3646     ;; Generate the buffer, either with threads or without.
3647     (when gnus-newsgroup-headers
3648       (gnus-summary-prepare-threads
3649        (if gnus-show-threads
3650            (gnus-sort-gathered-threads
3651             (funcall gnus-summary-thread-gathering-function
3652                      (gnus-sort-threads
3653                       (gnus-cut-threads (gnus-make-threads)))))
3654          ;; Unthreaded display.
3655          (gnus-sort-articles gnus-newsgroup-headers))))
3656     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3657     ;; Call hooks for modifying summary buffer.
3658     (goto-char (point-min))
3659     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3660
3661 (defsubst gnus-general-simplify-subject (subject)
3662   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3663   (setq subject
3664         (cond
3665          ;; Truncate the subject.
3666          (gnus-simplify-subject-functions
3667           (gnus-map-function gnus-simplify-subject-functions subject))
3668          ((numberp gnus-summary-gather-subject-limit)
3669           (setq subject (gnus-simplify-subject-re subject))
3670           (if (> (length subject) gnus-summary-gather-subject-limit)
3671               (substring subject 0 gnus-summary-gather-subject-limit)
3672             subject))
3673          ;; Fuzzily simplify it.
3674          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3675           (gnus-simplify-subject-fuzzy subject))
3676          ;; Just remove the leading "Re:".
3677          (t
3678           (gnus-simplify-subject-re subject))))
3679
3680   (if (and gnus-summary-gather-exclude-subject
3681            (string-match gnus-summary-gather-exclude-subject subject))
3682       nil                               ; This article shouldn't be gathered
3683     subject))
3684
3685 (defun gnus-summary-simplify-subject-query ()
3686   "Query where the respool algorithm would put this article."
3687   (interactive)
3688   (gnus-summary-select-article)
3689   (message "%s"
3690            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3691
3692 (defun gnus-gather-threads-by-subject (threads)
3693   "Gather threads by looking at Subject headers."
3694   (if (not gnus-summary-make-false-root)
3695       threads
3696     (let ((hashtb (gnus-make-hashtable 1024))
3697           (prev threads)
3698           (result threads)
3699           subject hthread whole-subject)
3700       (while threads
3701         (setq subject (gnus-general-simplify-subject
3702                        (setq whole-subject (mail-header-subject
3703                                             (caar threads)))))
3704         (when subject
3705           (if (setq hthread (gnus-gethash subject hashtb))
3706               (progn
3707                 ;; We enter a dummy root into the thread, if we
3708                 ;; haven't done that already.
3709                 (unless (stringp (caar hthread))
3710                   (setcar hthread (list whole-subject (car hthread))))
3711                 ;; We add this new gathered thread to this gathered
3712                 ;; thread.
3713                 (setcdr (car hthread)
3714                         (nconc (cdar hthread) (list (car threads))))
3715                 ;; Remove it from the list of threads.
3716                 (setcdr prev (cdr threads))
3717                 (setq threads prev))
3718             ;; Enter this thread into the hash table.
3719             (gnus-sethash subject
3720                           (if gnus-summary-make-false-root-always
3721                               (progn
3722                                 ;; If you want a dummy root above all
3723                                 ;; threads...
3724                                 (setcar threads (list whole-subject
3725                                                       (car threads)))
3726                                 threads)
3727                             threads)
3728                           hashtb)))
3729         (setq prev threads)
3730         (setq threads (cdr threads)))
3731       result)))
3732
3733 (defun gnus-gather-threads-by-references (threads)
3734   "Gather threads by looking at References headers."
3735   (let ((idhashtb (gnus-make-hashtable 1024))
3736         (thhashtb (gnus-make-hashtable 1024))
3737         (prev threads)
3738         (result threads)
3739         ids references id gthread gid entered ref)
3740     (while threads
3741       (when (setq references (mail-header-references (caar threads)))
3742         (setq id (mail-header-id (caar threads))
3743               ids (inline (gnus-split-references references))
3744               entered nil)
3745         (while (setq ref (pop ids))
3746           (setq ids (delete ref ids))
3747           (if (not (setq gid (gnus-gethash ref idhashtb)))
3748               (progn
3749                 (gnus-sethash ref id idhashtb)
3750                 (gnus-sethash id threads thhashtb))
3751             (setq gthread (gnus-gethash gid thhashtb))
3752             (unless entered
3753               ;; We enter a dummy root into the thread, if we
3754               ;; haven't done that already.
3755               (unless (stringp (caar gthread))
3756                 (setcar gthread (list (mail-header-subject (caar gthread))
3757                                       (car gthread))))
3758               ;; We add this new gathered thread to this gathered
3759               ;; thread.
3760               (setcdr (car gthread)
3761                       (nconc (cdar gthread) (list (car threads)))))
3762             ;; Add it into the thread hash table.
3763             (gnus-sethash id gthread thhashtb)
3764             (setq entered t)
3765             ;; Remove it from the list of threads.
3766             (setcdr prev (cdr threads))
3767             (setq threads prev))))
3768       (setq prev threads)
3769       (setq threads (cdr threads)))
3770     result))
3771
3772 (defun gnus-sort-gathered-threads (threads)
3773   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3774   (let ((result threads))
3775     (while threads
3776       (when (stringp (caar threads))
3777         (setcdr (car threads)
3778                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3779       (setq threads (cdr threads)))
3780     result))
3781
3782 (defun gnus-thread-loop-p (root thread)
3783   "Say whether ROOT is in THREAD."
3784   (let ((stack (list thread))
3785         (infloop 0)
3786         th)
3787     (while (setq thread (pop stack))
3788       (setq th (cdr thread))
3789       (while (and th
3790                   (not (eq (caar th) root)))
3791         (pop th))
3792       (if th
3793           ;; We have found a loop.
3794           (let (ref-dep)
3795             (setcdr thread (delq (car th) (cdr thread)))
3796             (if (boundp (setq ref-dep (intern "none"
3797                                               gnus-newsgroup-dependencies)))
3798                 (setcdr (symbol-value ref-dep)
3799                         (nconc (cdr (symbol-value ref-dep))
3800                                (list (car th))))
3801               (set ref-dep (list nil (car th))))
3802             (setq infloop 1
3803                   stack nil))
3804         ;; Push all the subthreads onto the stack.
3805         (push (cdr thread) stack)))
3806     infloop))
3807
3808 (defun gnus-make-threads ()
3809   "Go through the dependency hashtb and find the roots.  Return all threads."
3810   (let (threads)
3811     (while (catch 'infloop
3812              (mapatoms
3813               (lambda (refs)
3814                 ;; Deal with self-referencing References loops.
3815                 (when (and (car (symbol-value refs))
3816                            (not (zerop
3817                                  (apply
3818                                   '+
3819                                   (mapcar
3820                                    (lambda (thread)
3821                                      (gnus-thread-loop-p
3822                                       (car (symbol-value refs)) thread))
3823                                    (cdr (symbol-value refs)))))))
3824                   (setq threads nil)
3825                   (throw 'infloop t))
3826                 (unless (car (symbol-value refs))
3827                   ;; These threads do not refer back to any other articles,
3828                   ;; so they're roots.
3829                   (setq threads (append (cdr (symbol-value refs)) threads))))
3830               gnus-newsgroup-dependencies)))
3831     threads))
3832
3833 ;; Build the thread tree.
3834 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3835   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3836
3837 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3838 if it was already present.
3839
3840 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3841 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3842 Message-IDs will be renamed to a unique Message-ID before being
3843 entered.
3844
3845 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3846   (let* ((id (mail-header-id header))
3847          (id-dep (and id (intern id dependencies)))
3848          parent-id ref ref-dep ref-header replaced)
3849     ;; Enter this `header' in the `dependencies' table.
3850     (cond
3851      ((not id-dep)
3852       (setq header nil))
3853      ;; The first two cases do the normal part: enter a new `header'
3854      ;; in the `dependencies' table.
3855      ((not (boundp id-dep))
3856       (set id-dep (list header)))
3857      ((null (car (symbol-value id-dep)))
3858       (setcar (symbol-value id-dep) header))
3859
3860      ;; From here the `header' was already present in the
3861      ;; `dependencies' table.
3862      (force-new
3863       ;; Overrides an existing entry;
3864       ;; just set the header part of the entry.
3865       (setcar (symbol-value id-dep) header)
3866       (setq replaced t))
3867
3868      ;; Renames the existing `header' to a unique Message-ID.
3869      ((not gnus-summary-ignore-duplicates)
3870       ;; An article with this Message-ID has already been seen.
3871       ;; We rename the Message-ID.
3872       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3873            (list header))
3874       (mail-header-set-id header id))
3875
3876      ;; The last case ignores an existing entry, except it adds any
3877      ;; additional Xrefs (in case the two articles came from different
3878      ;; servers.
3879      ;; Also sets `header' to `nil' meaning that the `dependencies'
3880      ;; table was *not* modified.
3881      (t
3882       (mail-header-set-xref
3883        (car (symbol-value id-dep))
3884        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3885                    "")
3886                (or (mail-header-xref header) "")))
3887       (setq header nil)))
3888
3889     (when (and header (not replaced))
3890       ;; First check that we are not creating a References loop.
3891       (setq parent-id (gnus-parent-id (mail-header-references header)))
3892       (setq ref parent-id)
3893       (while (and ref
3894                   (setq ref-dep (intern-soft ref dependencies))
3895                   (boundp ref-dep)
3896                   (setq ref-header (car (symbol-value ref-dep))))
3897         (if (string= id ref)
3898             ;; Yuk!  This is a reference loop.  Make the article be a
3899             ;; root article.
3900             (progn
3901               (mail-header-set-references (car (symbol-value id-dep)) "none")
3902               (setq ref nil)
3903               (setq parent-id nil))
3904           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3905       (setq ref-dep (intern (or parent-id "none") dependencies))
3906       (if (boundp ref-dep)
3907           (setcdr (symbol-value ref-dep)
3908                   (nconc (cdr (symbol-value ref-dep))
3909                          (list (symbol-value id-dep))))
3910         (set ref-dep (list nil (symbol-value id-dep)))))
3911     header))
3912
3913 (defun gnus-extract-message-id-from-in-reply-to (string)
3914   (if (string-match "<[^>]+>" string)
3915       (substring string (match-beginning 0) (match-end 0))
3916     nil))
3917
3918 (defun gnus-build-sparse-threads ()
3919   (let ((headers gnus-newsgroup-headers)
3920         (mail-parse-charset gnus-newsgroup-charset)
3921         (gnus-summary-ignore-duplicates t)
3922         header references generation relations
3923         subject child end new-child date)
3924     ;; First we create an alist of generations/relations, where
3925     ;; generations is how much we trust the relation, and the relation
3926     ;; is parent/child.
3927     (gnus-message 7 "Making sparse threads...")
3928     (save-excursion
3929       (nnheader-set-temp-buffer " *gnus sparse threads*")
3930       (while (setq header (pop headers))
3931         (when (and (setq references (mail-header-references header))
3932                    (not (string= references "")))
3933           (insert references)
3934           (setq child (mail-header-id header)
3935                 subject (mail-header-subject header)
3936                 date (mail-header-date header)
3937                 generation 0)
3938           (while (search-backward ">" nil t)
3939             (setq end (1+ (point)))
3940             (when (search-backward "<" nil t)
3941               (setq new-child (buffer-substring (point) end))
3942               (push (list (incf generation)
3943                           child (setq child new-child)
3944                           subject date)
3945                     relations)))
3946           (when child
3947             (push (list (1+ generation) child nil subject) relations))
3948           (erase-buffer)))
3949       (kill-buffer (current-buffer)))
3950     ;; Sort over trustworthiness.
3951     (mapcar
3952      (lambda (relation)
3953        (when (gnus-dependencies-add-header
3954               (make-full-mail-header-from-decoded-header
3955                gnus-reffed-article-number
3956                (nth 3 relation) "" (or (nth 4 relation) "")
3957                (nth 1 relation)
3958                (or (nth 2 relation) "") 0 0 "")
3959               gnus-newsgroup-dependencies nil)
3960          (push gnus-reffed-article-number gnus-newsgroup-limit)
3961          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3962          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3963                gnus-newsgroup-reads)
3964          (decf gnus-reffed-article-number)))
3965      (sort relations 'car-less-than-car))
3966     (gnus-message 7 "Making sparse threads...done")))
3967
3968 (defun gnus-build-old-threads ()
3969   ;; Look at all the articles that refer back to old articles, and
3970   ;; fetch the headers for the articles that aren't there.  This will
3971   ;; build complete threads - if the roots haven't been expired by the
3972   ;; server, that is.
3973   (let ((mail-parse-charset gnus-newsgroup-charset)
3974         id heads)
3975     (mapatoms
3976      (lambda (refs)
3977        (when (not (car (symbol-value refs)))
3978          (setq heads (cdr (symbol-value refs)))
3979          (while heads
3980            (if (memq (mail-header-number (caar heads))
3981                      gnus-newsgroup-dormant)
3982                (setq heads (cdr heads))
3983              (setq id (symbol-name refs))
3984              (while (and (setq id (gnus-build-get-header id))
3985                          (not (car (gnus-id-to-thread id)))))
3986              (setq heads nil)))))
3987      gnus-newsgroup-dependencies)))
3988
3989 (defsubst gnus-remove-odd-characters (string)
3990   "Translate STRING into something that doesn't contain weird characters."
3991   (mm-subst-char-in-string
3992    ?\r ?\-
3993    (mm-subst-char-in-string ?\n ?\- string t) t))
3994
3995 ;; This function has to be called with point after the article number
3996 ;; on the beginning of the line.
3997 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3998   (let ((eol (point-at-eol))
3999         (buffer (current-buffer))
4000         header references in-reply-to)
4001
4002     ;; overview: [num subject from date id refs chars lines misc]
4003     (unwind-protect
4004         (progn
4005           (narrow-to-region (point) eol)
4006           (unless (eobp)
4007             (forward-char))
4008
4009           (setq header
4010                 (make-full-mail-header
4011                  number                         ; number
4012                  (nnheader-nov-field)           ; subject
4013                  (nnheader-nov-field)           ; from
4014                  (nnheader-nov-field)           ; date
4015                  (nnheader-nov-read-message-id) ; id
4016                  (nnheader-nov-field)           ; refs
4017                  (nnheader-nov-read-integer)    ; chars
4018                  (nnheader-nov-read-integer)    ; lines
4019                  (unless (eobp)
4020                    (if (looking-at "Xref: ")
4021                        (goto-char (match-end 0)))
4022                    (nnheader-nov-field))        ; Xref
4023                  (nnheader-nov-parse-extra))))  ; extra
4024
4025       (widen))
4026
4027     (when (and (string= references "")
4028                (setq in-reply-to (mail-header-extra header))
4029                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4030       (mail-header-set-references
4031        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4032
4033     (when gnus-alter-header-function
4034       (funcall gnus-alter-header-function header))
4035     (gnus-dependencies-add-header header dependencies force-new)))
4036
4037 (defun gnus-build-get-header (id)
4038   "Look through the buffer of NOV lines and find the header to ID.
4039 Enter this line into the dependencies hash table, and return
4040 the id of the parent article (if any)."
4041   (let ((deps gnus-newsgroup-dependencies)
4042         found header)
4043     (prog1
4044         (save-excursion
4045           (set-buffer nntp-server-buffer)
4046           (let ((case-fold-search nil))
4047             (goto-char (point-min))
4048             (while (and (not found)
4049                         (search-forward id nil t))
4050               (beginning-of-line)
4051               (setq found (looking-at
4052                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4053                                    (regexp-quote id))))
4054               (or found (beginning-of-line 2)))
4055             (when found
4056               (beginning-of-line)
4057               (and
4058                (setq header (gnus-nov-parse-line
4059                              (read (current-buffer)) deps))
4060                (gnus-parent-id (mail-header-references header))))))
4061       (when header
4062         (let ((number (mail-header-number header)))
4063           (push number gnus-newsgroup-limit)
4064           (push header gnus-newsgroup-headers)
4065           (if (memq number gnus-newsgroup-unselected)
4066               (progn
4067                 (setq gnus-newsgroup-unreads
4068                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4069                                                number))
4070                 (setq gnus-newsgroup-unselected
4071                       (delq number gnus-newsgroup-unselected)))
4072             (push number gnus-newsgroup-ancient)))))))
4073
4074 (defun gnus-build-all-threads ()
4075   "Read all the headers."
4076   (let ((gnus-summary-ignore-duplicates t)
4077         (mail-parse-charset gnus-newsgroup-charset)
4078         (dependencies gnus-newsgroup-dependencies)
4079         header article)
4080     (save-excursion
4081       (set-buffer nntp-server-buffer)
4082       (let ((case-fold-search nil))
4083         (goto-char (point-min))
4084         (while (not (eobp))
4085           (ignore-errors
4086             (setq article (read (current-buffer))
4087                   header (gnus-nov-parse-line article dependencies)))
4088           (when header
4089             (save-excursion
4090               (set-buffer gnus-summary-buffer)
4091               (push header gnus-newsgroup-headers)
4092               (if (memq (setq article (mail-header-number header))
4093                         gnus-newsgroup-unselected)
4094                   (progn
4095                     (setq gnus-newsgroup-unreads
4096                           (gnus-add-to-sorted-list
4097                            gnus-newsgroup-unreads article))
4098                     (setq gnus-newsgroup-unselected
4099                           (delq article gnus-newsgroup-unselected)))
4100                 (push article gnus-newsgroup-ancient)))
4101             (forward-line 1)))))))
4102
4103 (defun gnus-summary-update-article-line (article header)
4104   "Update the line for ARTICLE using HEADER."
4105   (let* ((id (mail-header-id header))
4106          (thread (gnus-id-to-thread id)))
4107     (unless thread
4108       (error "Article in no thread"))
4109     ;; Update the thread.
4110     (setcar thread header)
4111     (gnus-summary-goto-subject article)
4112     (let* ((datal (gnus-data-find-list article))
4113            (data (car datal))
4114            (buffer-read-only nil)
4115            (level (gnus-summary-thread-level)))
4116       (gnus-delete-line)
4117       (let ((inserted (- (point)
4118                          (progn
4119                            (gnus-summary-insert-line
4120                             header level nil
4121                             (memq article gnus-newsgroup-undownloaded)
4122                             (gnus-article-mark article)
4123                             (memq article gnus-newsgroup-replied)
4124                             (memq article gnus-newsgroup-expirable)
4125                             ;; Only insert the Subject string when it's different
4126                             ;; from the previous Subject string.
4127                             (if (and
4128                                  gnus-show-threads
4129                                  (gnus-subject-equal
4130                                   (condition-case ()
4131                                       (mail-header-subject
4132                                        (gnus-data-header
4133                                         (cadr
4134                                          (gnus-data-find-list
4135                                           article
4136                                           (gnus-data-list t)))))
4137                                     ;; Error on the side of excessive subjects.
4138                                     (error ""))
4139                                   (mail-header-subject header)))
4140                                 ""
4141                               (mail-header-subject header))
4142                             nil (cdr (assq article gnus-newsgroup-scored))
4143                             (memq article gnus-newsgroup-processable))
4144                            (point)))))
4145         (when (cdr datal)
4146           (gnus-data-update-list
4147            (cdr datal)
4148            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4149
4150 (defun gnus-summary-update-article (article &optional iheader)
4151   "Update ARTICLE in the summary buffer."
4152   (set-buffer gnus-summary-buffer)
4153   (let* ((header (gnus-summary-article-header article))
4154          (id (mail-header-id header))
4155          (data (gnus-data-find article))
4156          (thread (gnus-id-to-thread id))
4157          (references (mail-header-references header))
4158          (parent
4159           (gnus-id-to-thread
4160            (or (gnus-parent-id
4161                 (when (and references
4162                            (not (equal "" references)))
4163                   references))
4164                "none")))
4165          (buffer-read-only nil)
4166          (old (car thread)))
4167     (when thread
4168       (unless iheader
4169         (setcar thread nil)
4170         (when parent
4171           (delq thread parent)))
4172       (if (gnus-summary-insert-subject id header)
4173           ;; Set the (possibly) new article number in the data structure.
4174           (gnus-data-set-number data (gnus-id-to-article id))
4175         (setcar thread old)
4176         nil))))
4177
4178 (defun gnus-rebuild-thread (id &optional line)
4179   "Rebuild the thread containing ID.
4180 If LINE, insert the rebuilt thread starting on line LINE."
4181   (let ((buffer-read-only nil)
4182         old-pos current thread data)
4183     (if (not gnus-show-threads)
4184         (setq thread (list (car (gnus-id-to-thread id))))
4185       ;; Get the thread this article is part of.
4186       (setq thread (gnus-remove-thread id)))
4187     (setq old-pos (point-at-bol))
4188     (setq current (save-excursion
4189                     (and (re-search-backward "[\r\n]" nil t)
4190                          (gnus-summary-article-number))))
4191     ;; If this is a gathered thread, we have to go some re-gathering.
4192     (when (stringp (car thread))
4193       (let ((subject (car thread))
4194             roots thr)
4195         (setq thread (cdr thread))
4196         (while thread
4197           (unless (memq (setq thr (gnus-id-to-thread
4198                                    (gnus-root-id
4199                                     (mail-header-id (caar thread)))))
4200                         roots)
4201             (push thr roots))
4202           (setq thread (cdr thread)))
4203         ;; We now have all (unique) roots.
4204         (if (= (length roots) 1)
4205             ;; All the loose roots are now one solid root.
4206             (setq thread (car roots))
4207           (setq thread (cons subject (gnus-sort-threads roots))))))
4208     (let (threads)
4209       ;; We then insert this thread into the summary buffer.
4210       (when line
4211         (goto-char (point-min))
4212         (forward-line (1- line)))
4213       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4214         (if gnus-show-threads
4215             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4216           (gnus-summary-prepare-unthreaded thread))
4217         (setq data (nreverse gnus-newsgroup-data))
4218         (setq threads gnus-newsgroup-threads))
4219       ;; We splice the new data into the data structure.
4220       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4221       ;;!!! then we want to insert at the beginning of the buffer.
4222       ;;!!! That happens to be true with Gnus now, but that may
4223       ;;!!! change in the future.  Perhaps.
4224       (gnus-data-enter-list
4225        (if line nil current) data (- (point) old-pos))
4226       (setq gnus-newsgroup-threads
4227             (nconc threads gnus-newsgroup-threads))
4228       (gnus-data-compute-positions))))
4229
4230 (defun gnus-number-to-header (number)
4231   "Return the header for article NUMBER."
4232   (let ((headers gnus-newsgroup-headers))
4233     (while (and headers
4234                 (not (= number (mail-header-number (car headers)))))
4235       (pop headers))
4236     (when headers
4237       (car headers))))
4238
4239 (defun gnus-parent-headers (in-headers &optional generation)
4240   "Return the headers of the GENERATIONeth parent of HEADERS."
4241   (unless generation
4242     (setq generation 1))
4243   (let ((parent t)
4244         (headers in-headers)
4245         references)
4246     (while (and parent
4247                 (not (zerop generation))
4248                 (setq references (mail-header-references headers)))
4249       (setq headers (if (and references
4250                              (setq parent (gnus-parent-id references)))
4251                         (car (gnus-id-to-thread parent))
4252                       nil))
4253       (decf generation))
4254     (and (not (eq headers in-headers))
4255          headers)))
4256
4257 (defun gnus-id-to-thread (id)
4258   "Return the (sub-)thread where ID appears."
4259   (gnus-gethash id gnus-newsgroup-dependencies))
4260
4261 (defun gnus-id-to-article (id)
4262   "Return the article number of ID."
4263   (let ((thread (gnus-id-to-thread id)))
4264     (when (and thread
4265                (car thread))
4266       (mail-header-number (car thread)))))
4267
4268 (defun gnus-id-to-header (id)
4269   "Return the article headers of ID."
4270   (car (gnus-id-to-thread id)))
4271
4272 (defun gnus-article-displayed-root-p (article)
4273   "Say whether ARTICLE is a root(ish) article."
4274   (let ((level (gnus-summary-thread-level article))
4275         (refs (mail-header-references  (gnus-summary-article-header article)))
4276         particle)
4277     (cond
4278      ((null level) nil)
4279      ((zerop level) t)
4280      ((null refs) t)
4281      ((null (gnus-parent-id refs)) t)
4282      ((and (= 1 level)
4283            (null (setq particle (gnus-id-to-article
4284                                  (gnus-parent-id refs))))
4285            (null (gnus-summary-thread-level particle)))))))
4286
4287 (defun gnus-root-id (id)
4288   "Return the id of the root of the thread where ID appears."
4289   (let (last-id prev)
4290     (while (and id (setq prev (car (gnus-id-to-thread id))))
4291       (setq last-id id
4292             id (gnus-parent-id (mail-header-references prev))))
4293     last-id))
4294
4295 (defun gnus-articles-in-thread (thread)
4296   "Return the list of articles in THREAD."
4297   (cons (mail-header-number (car thread))
4298         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4299
4300 (defun gnus-remove-thread (id &optional dont-remove)
4301   "Remove the thread that has ID in it."
4302   (let (headers thread last-id)
4303     ;; First go up in this thread until we find the root.
4304     (setq last-id (gnus-root-id id)
4305           headers (message-flatten-list (gnus-id-to-thread last-id)))
4306     ;; We have now found the real root of this thread.  It might have
4307     ;; been gathered into some loose thread, so we have to search
4308     ;; through the threads to find the thread we wanted.
4309     (let ((threads gnus-newsgroup-threads)
4310           sub)
4311       (while threads
4312         (setq sub (car threads))
4313         (if (stringp (car sub))
4314             ;; This is a gathered thread, so we look at the roots
4315             ;; below it to find whether this article is in this
4316             ;; gathered root.
4317             (progn
4318               (setq sub (cdr sub))
4319               (while sub
4320                 (when (member (caar sub) headers)
4321                   (setq thread (car threads)
4322                         threads nil
4323                         sub nil))
4324                 (setq sub (cdr sub))))
4325           ;; It's an ordinary thread, so we check it.
4326           (when (eq (car sub) (car headers))
4327             (setq thread sub
4328                   threads nil)))
4329         (setq threads (cdr threads)))
4330       ;; If this article is in no thread, then it's a root.
4331       (if thread
4332           (unless dont-remove
4333             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4334         (setq thread (gnus-id-to-thread last-id)))
4335       (when thread
4336         (prog1
4337             thread                      ; We return this thread.
4338           (unless dont-remove
4339             (if (stringp (car thread))
4340                 (progn
4341                   ;; If we use dummy roots, then we have to remove the
4342                   ;; dummy root as well.
4343                   (when (eq gnus-summary-make-false-root 'dummy)
4344                     ;; We go to the dummy root by going to
4345                     ;; the first sub-"thread", and then one line up.
4346                     (gnus-summary-goto-article
4347                      (mail-header-number (caadr thread)))
4348                     (forward-line -1)
4349                     (gnus-delete-line)
4350                     (gnus-data-compute-positions))
4351                   (setq thread (cdr thread))
4352                   (while thread
4353                     (gnus-remove-thread-1 (car thread))
4354                     (setq thread (cdr thread))))
4355               (gnus-remove-thread-1 thread))))))))
4356
4357 (defun gnus-remove-thread-1 (thread)
4358   "Remove the thread THREAD recursively."
4359   (let ((number (mail-header-number (pop thread)))
4360         d)
4361     (setq thread (reverse thread))
4362     (while thread
4363       (gnus-remove-thread-1 (pop thread)))
4364     (when (setq d (gnus-data-find number))
4365       (goto-char (gnus-data-pos d))
4366       (gnus-summary-show-thread)
4367       (gnus-data-remove
4368        number
4369        (- (point-at-bol)
4370           (prog1
4371               (1+ (point-at-eol))
4372             (gnus-delete-line)))))))
4373
4374 (defun gnus-sort-threads-1 (threads func)
4375   (sort (mapcar (lambda (thread)
4376                   (cons (car thread)
4377                         (and (cdr thread)
4378                              (gnus-sort-threads-1 (cdr thread) func))))
4379                 threads) func))
4380
4381 (defun gnus-sort-threads (threads)
4382   "Sort THREADS."
4383   (if (not gnus-thread-sort-functions)
4384       threads
4385     (gnus-message 8 "Sorting threads...")
4386     (let ((max-lisp-eval-depth 5000))
4387       (prog1 (gnus-sort-threads-1
4388          threads
4389          (gnus-make-sort-function gnus-thread-sort-functions))
4390         (gnus-message 8 "Sorting threads...done")))))
4391
4392 (defun gnus-sort-articles (articles)
4393   "Sort ARTICLES."
4394   (when gnus-article-sort-functions
4395     (gnus-message 7 "Sorting articles...")
4396     (prog1
4397         (setq gnus-newsgroup-headers
4398               (sort articles (gnus-make-sort-function
4399                               gnus-article-sort-functions)))
4400       (gnus-message 7 "Sorting articles...done"))))
4401
4402 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4403 (defmacro gnus-thread-header (thread)
4404   "Return header of first article in THREAD.
4405 Note that THREAD must never, ever be anything else than a variable -
4406 using some other form will lead to serious barfage."
4407   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4408   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4409   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4410         (vector thread) 2))
4411
4412 (defsubst gnus-article-sort-by-number (h1 h2)
4413   "Sort articles by article number."
4414   (< (mail-header-number h1)
4415      (mail-header-number h2)))
4416
4417 (defun gnus-thread-sort-by-number (h1 h2)
4418   "Sort threads by root article number."
4419   (gnus-article-sort-by-number
4420    (gnus-thread-header h1) (gnus-thread-header h2)))
4421
4422 (defsubst gnus-article-sort-by-random (h1 h2)
4423   "Sort articles by article number."
4424   (zerop (random 2)))
4425
4426 (defun gnus-thread-sort-by-random (h1 h2)
4427   "Sort threads by root article number."
4428   (gnus-article-sort-by-random
4429    (gnus-thread-header h1) (gnus-thread-header h2)))
4430
4431 (defsubst gnus-article-sort-by-lines (h1 h2)
4432   "Sort articles by article Lines header."
4433   (< (mail-header-lines h1)
4434      (mail-header-lines h2)))
4435
4436 (defun gnus-thread-sort-by-lines (h1 h2)
4437   "Sort threads by root article Lines header."
4438   (gnus-article-sort-by-lines
4439    (gnus-thread-header h1) (gnus-thread-header h2)))
4440
4441 (defsubst gnus-article-sort-by-chars (h1 h2)
4442   "Sort articles by octet length."
4443   (< (mail-header-chars h1)
4444      (mail-header-chars h2)))
4445
4446 (defun gnus-thread-sort-by-chars (h1 h2)
4447   "Sort threads by root article octet length."
4448   (gnus-article-sort-by-chars
4449    (gnus-thread-header h1) (gnus-thread-header h2)))
4450
4451 (defsubst gnus-article-sort-by-author (h1 h2)
4452   "Sort articles by root author."
4453   (string-lessp
4454    (let ((addr (car (mime-entity-read-field h1 'From))))
4455      (or (std11-full-name-string addr)
4456          (std11-address-string addr)
4457          ""))
4458    (let ((addr (car (mime-entity-read-field h2 'From))))
4459      (or (std11-full-name-string addr)
4460          (std11-address-string addr)
4461          ""))
4462    ))
4463
4464 (defun gnus-thread-sort-by-author (h1 h2)
4465   "Sort threads by root author."
4466   (gnus-article-sort-by-author
4467    (gnus-thread-header h1)  (gnus-thread-header h2)))
4468
4469 (defsubst gnus-article-sort-by-subject (h1 h2)
4470   "Sort articles by root subject."
4471   (string-lessp
4472    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4473    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4474
4475 (defun gnus-thread-sort-by-subject (h1 h2)
4476   "Sort threads by root subject."
4477   (gnus-article-sort-by-subject
4478    (gnus-thread-header h1) (gnus-thread-header h2)))
4479
4480 (defsubst gnus-article-sort-by-date (h1 h2)
4481   "Sort articles by root article date."
4482   (time-less-p
4483    (gnus-date-get-time (mail-header-date h1))
4484    (gnus-date-get-time (mail-header-date h2))))
4485
4486 (defun gnus-thread-sort-by-date (h1 h2)
4487   "Sort threads by root article date."
4488   (gnus-article-sort-by-date
4489    (gnus-thread-header h1) (gnus-thread-header h2)))
4490
4491 (defsubst gnus-article-sort-by-score (h1 h2)
4492   "Sort articles by root article score.
4493 Unscored articles will be counted as having a score of zero."
4494   (> (or (cdr (assq (mail-header-number h1)
4495                     gnus-newsgroup-scored))
4496          gnus-summary-default-score 0)
4497      (or (cdr (assq (mail-header-number h2)
4498                     gnus-newsgroup-scored))
4499          gnus-summary-default-score 0)))
4500
4501 (defun gnus-thread-sort-by-score (h1 h2)
4502   "Sort threads by root article score."
4503   (gnus-article-sort-by-score
4504    (gnus-thread-header h1) (gnus-thread-header h2)))
4505
4506 (defun gnus-thread-sort-by-total-score (h1 h2)
4507   "Sort threads by the sum of all scores in the thread.
4508 Unscored articles will be counted as having a score of zero."
4509   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4510
4511 (defun gnus-thread-total-score (thread)
4512   ;; This function find the total score of THREAD.
4513   (cond
4514    ((null thread)
4515     0)
4516    ((consp thread)
4517     (if (stringp (car thread))
4518         (apply gnus-thread-score-function 0
4519                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4520       (gnus-thread-total-score-1 thread)))
4521    (t
4522     (gnus-thread-total-score-1 (list thread)))))
4523
4524 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4525   "Sort threads such that the thread with the most recently arrived article comes first."
4526   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4527
4528 (defun gnus-thread-highest-number (thread)
4529   "Return the highest article number in THREAD."
4530   (apply 'max (mapcar (lambda (header)
4531                         (mail-header-number header))
4532                       (message-flatten-list thread))))
4533
4534 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4535   "Sort threads such that the thread with the most recently dated article comes first."
4536   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4537
4538 (defun gnus-thread-latest-date (thread)
4539   "Return the highest article date in THREAD."
4540   (let ((previous-time 0))
4541     (apply 'max
4542            (mapcar
4543             (lambda (header)
4544               (setq previous-time
4545                     (condition-case ()
4546                         (time-to-seconds (mail-header-parse-date
4547                                           (mail-header-date header)))
4548                       (error previous-time))))
4549             (sort
4550              (message-flatten-list thread)
4551              (lambda (h1 h2)
4552                (< (mail-header-number h1)
4553                   (mail-header-number h2))))))))
4554
4555 (defun gnus-thread-total-score-1 (root)
4556   ;; This function find the total score of the thread below ROOT.
4557   (setq root (car root))
4558   (apply gnus-thread-score-function
4559          (or (append
4560               (mapcar 'gnus-thread-total-score
4561                       (cdr (gnus-id-to-thread (mail-header-id root))))
4562               (when (> (mail-header-number root) 0)
4563                 (list (or (cdr (assq (mail-header-number root)
4564                                      gnus-newsgroup-scored))
4565                           gnus-summary-default-score 0))))
4566              (list gnus-summary-default-score)
4567              '(0))))
4568
4569 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4570 (defvar gnus-tmp-prev-subject nil)
4571 (defvar gnus-tmp-false-parent nil)
4572 (defvar gnus-tmp-root-expunged nil)
4573 (defvar gnus-tmp-dummy-line nil)
4574
4575 (eval-when-compile (defvar gnus-tmp-header))
4576 (defun gnus-extra-header (type &optional header)
4577   "Return the extra header of TYPE."
4578   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4579       ""))
4580
4581 (defvar gnus-tmp-thread-tree-header-string "")
4582
4583 (defcustom gnus-sum-thread-tree-root "> "
4584   "With %B spec, used for the root of a thread.
4585 If nil, use subject instead."
4586   :type '(radio (const :format "%v  " nil) (string :size 0))
4587   :group 'gnus-thread)
4588 (defcustom gnus-sum-thread-tree-false-root "> "
4589   "With %B spec, used for a false root of a thread.
4590 If nil, use subject instead."
4591   :type '(radio (const :format "%v  " nil) (string :size 0))
4592   :group 'gnus-thread)
4593 (defcustom gnus-sum-thread-tree-single-indent ""
4594   "With %B spec, used for a thread with just one message.
4595 If nil, use subject instead."
4596   :type '(radio (const :format "%v  " nil) (string :size 0))
4597   :group 'gnus-thread)
4598 (defcustom gnus-sum-thread-tree-vertical "| "
4599   "With %B spec, used for drawing a vertical line."
4600   :type 'string
4601   :group 'gnus-thread)
4602 (defcustom gnus-sum-thread-tree-indent "  "
4603   "With %B spec, used for indenting."
4604   :type 'string
4605   :group 'gnus-thread)
4606 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4607   "With %B spec, used for a leaf with brothers."
4608   :type 'string
4609   :group 'gnus-thread)
4610 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4611   "With %B spec, used for a leaf without brothers."
4612   :type 'string
4613   :group 'gnus-thread)
4614
4615 (defun gnus-summary-prepare-threads (threads)
4616   "Prepare summary buffer from THREADS and indentation LEVEL.
4617 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4618 or a straight list of headers."
4619   (gnus-message 7 "Generating summary...")
4620
4621   (setq gnus-newsgroup-threads threads)
4622   (beginning-of-line)
4623
4624   (let ((gnus-tmp-level 0)
4625         (default-score (or gnus-summary-default-score 0))
4626         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4627         (building-line-count gnus-summary-display-while-building)
4628         (building-count (integerp gnus-summary-display-while-building))
4629         thread number subject stack state gnus-tmp-gathered beg-match
4630         new-roots gnus-tmp-new-adopts thread-end simp-subject
4631         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4632         gnus-tmp-replied gnus-tmp-subject-or-nil
4633         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4634         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4635         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4636         tree-stack)
4637
4638     (setq gnus-tmp-prev-subject nil
4639           gnus-tmp-thread-tree-header-string "")
4640
4641     (if (vectorp (car threads))
4642         ;; If this is a straight (sic) list of headers, then a
4643         ;; threaded summary display isn't required, so we just create
4644         ;; an unthreaded one.
4645         (gnus-summary-prepare-unthreaded threads)
4646
4647       ;; Do the threaded display.
4648
4649       (if gnus-summary-display-while-building
4650           (switch-to-buffer (buffer-name)))
4651       (while (or threads stack gnus-tmp-new-adopts new-roots)
4652
4653         (if (and (= gnus-tmp-level 0)
4654                  (or (not stack)
4655                      (= (caar stack) 0))
4656                  (not gnus-tmp-false-parent)
4657                  (or gnus-tmp-new-adopts new-roots))
4658             (if gnus-tmp-new-adopts
4659                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4660                       thread (list (car gnus-tmp-new-adopts))
4661                       gnus-tmp-header (caar thread)
4662                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4663               (when new-roots
4664                 (setq thread (list (car new-roots))
4665                       gnus-tmp-header (caar thread)
4666                       new-roots (cdr new-roots))))
4667
4668           (if threads
4669               ;; If there are some threads, we do them before the
4670               ;; threads on the stack.
4671               (setq thread threads
4672                     gnus-tmp-header (caar thread))
4673             ;; There were no current threads, so we pop something off
4674             ;; the stack.
4675             (setq state (car stack)
4676                   gnus-tmp-level (car state)
4677                   tree-stack (cadr state)
4678                   thread (caddr state)
4679                   stack (cdr stack)
4680                   gnus-tmp-header (caar thread))))
4681
4682         (setq gnus-tmp-false-parent nil)
4683         (setq gnus-tmp-root-expunged nil)
4684         (setq thread-end nil)
4685
4686         (if (stringp gnus-tmp-header)
4687             ;; The header is a dummy root.
4688             (cond
4689              ((eq gnus-summary-make-false-root 'adopt)
4690               ;; We let the first article adopt the rest.
4691               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4692                                                (cddar thread)))
4693               (setq gnus-tmp-gathered
4694                     (nconc (mapcar
4695                             (lambda (h) (mail-header-number (car h)))
4696                             (cddar thread))
4697                            gnus-tmp-gathered))
4698               (setq thread (cons (list (caar thread)
4699                                        (cadar thread))
4700                                  (cdr thread)))
4701               (setq gnus-tmp-level -1
4702                     gnus-tmp-false-parent t))
4703              ((eq gnus-summary-make-false-root 'empty)
4704               ;; We print adopted articles with empty subject fields.
4705               (setq gnus-tmp-gathered
4706                     (nconc (mapcar
4707                             (lambda (h) (mail-header-number (car h)))
4708                             (cddar thread))
4709                            gnus-tmp-gathered))
4710               (setq gnus-tmp-level -1))
4711              ((eq gnus-summary-make-false-root 'dummy)
4712               ;; We remember that we probably want to output a dummy
4713               ;; root.
4714               (setq gnus-tmp-dummy-line gnus-tmp-header)
4715               (setq gnus-tmp-prev-subject gnus-tmp-header))
4716              (t
4717               ;; We do not make a root for the gathered
4718               ;; sub-threads at all.
4719               (setq gnus-tmp-level -1)))
4720
4721           (setq number (mail-header-number gnus-tmp-header)
4722                 subject (mail-header-subject gnus-tmp-header)
4723                 simp-subject (gnus-simplify-subject-fully subject))
4724
4725           (cond
4726            ;; If the thread has changed subject, we might want to make
4727            ;; this subthread into a root.
4728            ((and (null gnus-thread-ignore-subject)
4729                  (not (zerop gnus-tmp-level))
4730                  gnus-tmp-prev-subject
4731                  (not (string= gnus-tmp-prev-subject simp-subject)))
4732             (setq new-roots (nconc new-roots (list (car thread)))
4733                   thread-end t
4734                   gnus-tmp-header nil))
4735            ;; If the article lies outside the current limit,
4736            ;; then we do not display it.
4737            ((not (memq number gnus-newsgroup-limit))
4738             (setq gnus-tmp-gathered
4739                   (nconc (mapcar
4740                           (lambda (h) (mail-header-number (car h)))
4741                           (cdar thread))
4742                          gnus-tmp-gathered))
4743             (setq gnus-tmp-new-adopts (if (cdar thread)
4744                                           (append gnus-tmp-new-adopts
4745                                                   (cdar thread))
4746                                         gnus-tmp-new-adopts)
4747                   thread-end t
4748                   gnus-tmp-header nil)
4749             (when (zerop gnus-tmp-level)
4750               (setq gnus-tmp-root-expunged t)))
4751            ;; Perhaps this article is to be marked as read?
4752            ((and gnus-summary-mark-below
4753                  (< (or (cdr (assq number gnus-newsgroup-scored))
4754                         default-score)
4755                     gnus-summary-mark-below)
4756                  ;; Don't touch sparse articles.
4757                  (not (gnus-summary-article-sparse-p number))
4758                  (not (gnus-summary-article-ancient-p number)))
4759             (setq gnus-newsgroup-unreads
4760                   (delq number gnus-newsgroup-unreads))
4761             (if gnus-newsgroup-auto-expire
4762                 (setq gnus-newsgroup-expirable
4763                       (gnus-add-to-sorted-list
4764                        gnus-newsgroup-expirable number))
4765               (push (cons number gnus-low-score-mark)
4766                     gnus-newsgroup-reads))))
4767
4768           (when gnus-tmp-header
4769             ;; We may have an old dummy line to output before this
4770             ;; article.
4771             (when (and gnus-tmp-dummy-line
4772                        (gnus-subject-equal
4773                         gnus-tmp-dummy-line
4774                         (mail-header-subject gnus-tmp-header)))
4775               (gnus-summary-insert-dummy-line
4776                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4777               (setq gnus-tmp-dummy-line nil))
4778
4779             ;; Compute the mark.
4780             (setq gnus-tmp-unread (gnus-article-mark number))
4781
4782             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4783                                   gnus-tmp-header gnus-tmp-level)
4784                   gnus-newsgroup-data)
4785
4786             ;; Actually insert the line.
4787             (setq
4788              gnus-tmp-subject-or-nil
4789              (cond
4790               ((and gnus-thread-ignore-subject
4791                     gnus-tmp-prev-subject
4792                     (not (string= gnus-tmp-prev-subject simp-subject)))
4793                subject)
4794               ((zerop gnus-tmp-level)
4795                (if (and (eq gnus-summary-make-false-root 'empty)
4796                         (memq number gnus-tmp-gathered)
4797                         gnus-tmp-prev-subject
4798                         (string= gnus-tmp-prev-subject simp-subject))
4799                    gnus-summary-same-subject
4800                  subject))
4801               (t gnus-summary-same-subject)))
4802             (if (and (eq gnus-summary-make-false-root 'adopt)
4803                      (= gnus-tmp-level 1)
4804                      (memq number gnus-tmp-gathered))
4805                 (setq gnus-tmp-opening-bracket ?\<
4806                       gnus-tmp-closing-bracket ?\>)
4807               (setq gnus-tmp-opening-bracket ?\[
4808                     gnus-tmp-closing-bracket ?\]))
4809             (setq
4810              gnus-tmp-indentation
4811              (aref gnus-thread-indent-array gnus-tmp-level)
4812              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4813              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4814                                 gnus-summary-default-score 0)
4815              gnus-tmp-score-char
4816              (if (or (null gnus-summary-default-score)
4817                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4818                          gnus-summary-zcore-fuzz))
4819                  ?\ ;;;Whitespace
4820                (if (< gnus-tmp-score gnus-summary-default-score)
4821                    gnus-score-below-mark gnus-score-over-mark))
4822              gnus-tmp-replied
4823              (cond ((memq number gnus-newsgroup-processable)
4824                     gnus-process-mark)
4825                    ((memq number gnus-newsgroup-cached)
4826                     gnus-cached-mark)
4827                    ((memq number gnus-newsgroup-replied)
4828                     gnus-replied-mark)
4829                    ((memq number gnus-newsgroup-forwarded)
4830                     gnus-forwarded-mark)
4831                    ((memq number gnus-newsgroup-saved)
4832                     gnus-saved-mark)
4833                    ((memq number gnus-newsgroup-recent)
4834                     gnus-recent-mark)
4835                    ((memq number gnus-newsgroup-unseen)
4836                     gnus-unseen-mark)
4837                    (t gnus-no-mark))
4838              gnus-tmp-downloaded
4839              (cond ((memq number gnus-newsgroup-undownloaded)
4840                     gnus-undownloaded-mark)
4841                    (gnus-newsgroup-agentized
4842                     gnus-downloaded-mark)
4843                    (t
4844                     gnus-no-mark))
4845              gnus-tmp-from (mail-header-from gnus-tmp-header)
4846              gnus-tmp-name
4847              (cond
4848               ((string-match "<[^>]+> *$" gnus-tmp-from)
4849                (setq beg-match (match-beginning 0))
4850                (or (and (string-match "^\".+\"" gnus-tmp-from)
4851                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4852                    (substring gnus-tmp-from 0 beg-match)))
4853               ((string-match "(.+)" gnus-tmp-from)
4854                (substring gnus-tmp-from
4855                           (1+ (match-beginning 0)) (1- (match-end 0))))
4856               (t gnus-tmp-from))
4857
4858              ;; Do the %B string
4859              gnus-tmp-thread-tree-header-string
4860              (cond
4861               ((not gnus-show-threads) "")
4862               ((zerop gnus-tmp-level)
4863                (cond ((cdar thread)
4864                       (or gnus-sum-thread-tree-root subject))
4865                      (gnus-tmp-new-adopts
4866                       (or gnus-sum-thread-tree-false-root subject))
4867                      (t
4868                       (or gnus-sum-thread-tree-single-indent subject))))
4869               (t
4870                (concat (apply 'concat
4871                               (mapcar (lambda (item)
4872                                         (if (= item 1)
4873                                             gnus-sum-thread-tree-vertical
4874                                           gnus-sum-thread-tree-indent))
4875                                       (cdr (reverse tree-stack))))
4876                        (if (nth 1 thread)
4877                            gnus-sum-thread-tree-leaf-with-other
4878                          gnus-sum-thread-tree-single-leaf)))))
4879             (when (string= gnus-tmp-name "")
4880               (setq gnus-tmp-name gnus-tmp-from))
4881             (unless (numberp gnus-tmp-lines)
4882               (setq gnus-tmp-lines -1))
4883             (if (= gnus-tmp-lines -1)
4884                 (setq gnus-tmp-lines "?")
4885               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4886               (gnus-put-text-property
4887              (point)
4888              (progn (eval gnus-summary-line-format-spec) (point))
4889                'gnus-number number)
4890             (when gnus-visual-p
4891               (forward-line -1)
4892               (gnus-run-hooks 'gnus-summary-update-hook)
4893               (forward-line 1))
4894
4895             (setq gnus-tmp-prev-subject simp-subject)))
4896
4897         (when (nth 1 thread)
4898           (push (list (max 0 gnus-tmp-level)
4899                       (copy-sequence tree-stack)
4900                       (nthcdr 1 thread))
4901                 stack))
4902         (push (if (nth 1 thread) 1 0) tree-stack)
4903         (incf gnus-tmp-level)
4904         (setq threads (if thread-end nil (cdar thread)))
4905         (if gnus-summary-display-while-building
4906             (if building-count
4907                 (progn
4908                   ;; use a set frequency
4909                   (setq building-line-count (1- building-line-count))
4910                   (when (= building-line-count 0)
4911                     (sit-for 0)
4912                     (setq building-line-count
4913                           gnus-summary-display-while-building)))
4914               ;; always
4915               (sit-for 0)))
4916         (unless threads
4917           (setq gnus-tmp-level 0)))))
4918   (gnus-message 7 "Generating summary...done"))
4919
4920 (defun gnus-summary-prepare-unthreaded (headers)
4921   "Generate an unthreaded summary buffer based on HEADERS."
4922   (let (header number mark)
4923
4924     (beginning-of-line)
4925
4926     (while headers
4927       ;; We may have to root out some bad articles...
4928       (when (memq (setq number (mail-header-number
4929                                 (setq header (pop headers))))
4930                   gnus-newsgroup-limit)
4931         ;; Mark article as read when it has a low score.
4932         (when (and gnus-summary-mark-below
4933                    (< (or (cdr (assq number gnus-newsgroup-scored))
4934                           gnus-summary-default-score 0)
4935                       gnus-summary-mark-below)
4936                    (not (gnus-summary-article-ancient-p number)))
4937           (setq gnus-newsgroup-unreads
4938                 (delq number gnus-newsgroup-unreads))
4939           (if gnus-newsgroup-auto-expire
4940               (push number gnus-newsgroup-expirable)
4941             (push (cons number gnus-low-score-mark)
4942                   gnus-newsgroup-reads)))
4943
4944         (setq mark (gnus-article-mark number))
4945         (push (gnus-data-make number mark (1+ (point)) header 0)
4946               gnus-newsgroup-data)
4947         (gnus-summary-insert-line
4948          header 0 number
4949          (memq number gnus-newsgroup-undownloaded)
4950          mark (memq number gnus-newsgroup-replied)
4951          (memq number gnus-newsgroup-expirable)
4952          (mail-header-subject header) nil
4953          (cdr (assq number gnus-newsgroup-scored))
4954          (memq number gnus-newsgroup-processable))))))
4955
4956 (defun gnus-summary-remove-list-identifiers ()
4957   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4958   (let ((regexp (if (consp gnus-list-identifiers)
4959                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4960                   gnus-list-identifiers))
4961         changed subject)
4962     (when regexp
4963       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
4964       (dolist (header gnus-newsgroup-headers)
4965         (setq subject (mail-header-subject header)
4966               changed nil)
4967         (while (string-match regexp subject)
4968           (setq subject
4969                 (concat (substring subject 0 (match-beginning 1))
4970                         (substring subject (match-end 0)))
4971                 changed t))
4972         (when changed
4973           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
4974             (setq subject
4975                   (concat (substring subject 0 (match-beginning 1))
4976                           (substring subject (match-end 1)))))
4977           (mail-header-set-subject header subject))))))
4978
4979 (defun gnus-fetch-headers (articles)
4980   "Fetch headers of ARTICLES."
4981   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4982     (gnus-message 5 "Fetching headers for %s..." name)
4983     (prog1
4984         (if (eq 'nov
4985                 (setq gnus-headers-retrieved-by
4986                       (gnus-retrieve-headers
4987                        articles gnus-newsgroup-name
4988                        ;; We might want to fetch old headers, but
4989                        ;; not if there is only 1 article.
4990                        (and (or (and
4991                                  (not (eq gnus-fetch-old-headers 'some))
4992                                  (not (numberp gnus-fetch-old-headers)))
4993                                 (> (length articles) 1))
4994                             gnus-fetch-old-headers))))
4995             (gnus-get-newsgroup-headers-xover
4996              articles nil nil gnus-newsgroup-name t)
4997           (gnus-get-newsgroup-headers))
4998       (gnus-message 5 "Fetching headers for %s...done" name))))
4999
5000 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5001   "Select newsgroup GROUP.
5002 If READ-ALL is non-nil, all articles in the group are selected.
5003 If SELECT-ARTICLES, only select those articles from GROUP."
5004   (let* ((entry (gnus-group-entry group))
5005          ;;!!! Dirty hack; should be removed.
5006          (gnus-summary-ignore-duplicates
5007           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5008               t
5009             gnus-summary-ignore-duplicates))
5010          (info (nth 2 entry))
5011          articles fetched-articles cached)
5012
5013     (unless (gnus-check-server
5014              (set (make-local-variable 'gnus-current-select-method)
5015                   (gnus-find-method-for-group group)))
5016       (error "Couldn't open server"))
5017
5018     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5019         (gnus-activate-group group)     ; Or we can activate it...
5020         (progn                          ; Or we bug out.
5021           (when (equal major-mode 'gnus-summary-mode)
5022             (gnus-kill-buffer (current-buffer)))
5023           (error "Couldn't activate group %s: %s"
5024                  group (gnus-status-message group))))
5025
5026     (unless (gnus-request-group group t)
5027       (when (equal major-mode 'gnus-summary-mode)
5028         (gnus-kill-buffer (current-buffer)))
5029       (error "Couldn't request group %s: %s"
5030              group (gnus-status-message group)))
5031
5032     (when gnus-agent
5033       ;; The agent may be storing articles that are no longer in the
5034       ;; server's active range.  If that is the case, the active range
5035       ;; needs to be expanded such that the agent's articles can be
5036       ;; included in the summary.
5037       (let* ((gnus-command-method (gnus-find-method-for-group group))
5038              (alist (gnus-agent-load-alist group))
5039              (active (gnus-active group)))
5040         (if (and (car alist)
5041                  (< (caar alist) (car active)))
5042             (gnus-set-active group (cons (caar alist) (cdr active)))))
5043
5044       (setq gnus-summary-use-undownloaded-faces
5045             (gnus-agent-find-parameter
5046              group
5047              'agent-enable-undownloaded-faces)))
5048
5049     (setq gnus-newsgroup-name group
5050           gnus-newsgroup-unselected nil
5051           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5052
5053     (let ((display (gnus-group-find-parameter group 'display)))
5054       (setq gnus-newsgroup-display
5055             (cond
5056              ((not (zerop (or (car-safe read-all) 0)))
5057               ;; The user entered the group with C-u SPC/RET, let's show
5058               ;; all articles.
5059               'gnus-not-ignore)
5060              ((eq display 'all)
5061               'gnus-not-ignore)
5062              ((arrayp display)
5063               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5064              ((numberp display)
5065               ;; The following is probably the "correct" solution, but
5066               ;; it makes Gnus fetch all headers and then limit the
5067               ;; articles (which is slow), so instead we hack the
5068               ;; select-articles parameter instead. -- Simon Josefsson
5069               ;; <jas@kth.se>
5070               ;;
5071               ;; (gnus-byte-compile
5072               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5073               ;;                         display)))))
5074               (setq select-articles
5075                     (gnus-uncompress-range
5076                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5077                              (if (> tmp 0)
5078                                  tmp
5079                                1))
5080                            (cdr (gnus-active group)))))
5081               nil)
5082              (t
5083               nil))))
5084
5085     (gnus-summary-setup-default-charset)
5086
5087     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5088     (when (gnus-virtual-group-p group)
5089       (setq cached gnus-newsgroup-cached))
5090
5091     (setq gnus-newsgroup-unreads
5092           (gnus-sorted-ndifference
5093            (gnus-sorted-ndifference gnus-newsgroup-unreads
5094                                     gnus-newsgroup-marked)
5095            gnus-newsgroup-dormant))
5096
5097     (setq gnus-newsgroup-processable nil)
5098
5099     (gnus-update-read-articles group gnus-newsgroup-unreads)
5100
5101     ;; Adjust and set lists of article marks.
5102     (when info
5103       (gnus-adjust-marked-articles info))
5104     (if (setq articles select-articles)
5105         (setq gnus-newsgroup-unselected
5106               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5107       (setq articles (gnus-articles-to-read group read-all)))
5108
5109     (cond
5110      ((null articles)
5111       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5112       'quit)
5113      ((eq articles 0) nil)
5114      (t
5115       ;; Init the dependencies hash table.
5116       (setq gnus-newsgroup-dependencies
5117             (gnus-make-hashtable (length articles)))
5118       (gnus-set-global-variables)
5119       ;; Retrieve the headers and read them in.
5120
5121       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5122
5123       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5124       (when cached
5125         (setq gnus-newsgroup-cached cached))
5126
5127       ;; Suppress duplicates?
5128       (when gnus-suppress-duplicates
5129         (gnus-dup-suppress-articles))
5130
5131       ;; Set the initial limit.
5132       (setq gnus-newsgroup-limit (copy-sequence articles))
5133       ;; Remove canceled articles from the list of unread articles.
5134       (setq fetched-articles
5135             (mapcar (lambda (headers) (mail-header-number headers))
5136                     gnus-newsgroup-headers))
5137       (setq gnus-newsgroup-articles fetched-articles)
5138       (setq gnus-newsgroup-unreads
5139             (gnus-sorted-nintersection
5140              gnus-newsgroup-unreads fetched-articles))
5141       (gnus-compute-unseen-list)
5142
5143       ;; Removed marked articles that do not exist.
5144       (gnus-update-missing-marks
5145        (gnus-sorted-difference articles fetched-articles))
5146       ;; We might want to build some more threads first.
5147       (when (and gnus-fetch-old-headers
5148                  (eq gnus-headers-retrieved-by 'nov))
5149         (if (eq gnus-fetch-old-headers 'invisible)
5150             (gnus-build-all-threads)
5151           (gnus-build-old-threads)))
5152       ;; Let the Gnus agent mark articles as read.
5153       (when gnus-agent
5154         (gnus-agent-get-undownloaded-list))
5155       ;; Remove list identifiers from subject
5156       (when gnus-list-identifiers
5157         (gnus-summary-remove-list-identifiers))
5158       ;; Check whether auto-expire is to be done in this group.
5159       (setq gnus-newsgroup-auto-expire
5160             (gnus-group-auto-expirable-p group))
5161       ;; Set up the article buffer now, if necessary.
5162       (unless gnus-single-article-buffer
5163         (gnus-article-setup-buffer))
5164       ;; First and last article in this newsgroup.
5165       (when gnus-newsgroup-headers
5166         (setq gnus-newsgroup-begin
5167               (mail-header-number (car gnus-newsgroup-headers))
5168               gnus-newsgroup-end
5169               (mail-header-number
5170                (gnus-last-element gnus-newsgroup-headers))))
5171       ;; GROUP is successfully selected.
5172       (or gnus-newsgroup-headers t)))))
5173
5174 (defun gnus-compute-unseen-list ()
5175   ;; The `seen' marks are treated specially.
5176   (if (not gnus-newsgroup-seen)
5177       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5178     (setq gnus-newsgroup-unseen
5179           (gnus-inverse-list-range-intersection
5180            gnus-newsgroup-articles gnus-newsgroup-seen))))
5181
5182 (defun gnus-summary-display-make-predicate (display)
5183   (require 'gnus-agent)
5184   (when (= (length display) 1)
5185     (setq display (car display)))
5186   (unless gnus-summary-display-cache
5187     (dolist (elem (append '((unread . unread)
5188                             (read . read)
5189                             (unseen . unseen))
5190                           gnus-article-mark-lists))
5191       (push (cons (cdr elem)
5192                   (gnus-byte-compile
5193                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5194             gnus-summary-display-cache)))
5195   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5196         (gnus-category-predicate-cache gnus-summary-display-cache))
5197     (gnus-get-predicate display)))
5198
5199 ;; Uses the dynamically bound `number' variable.
5200 (eval-when-compile
5201   (defvar number))
5202 (defun gnus-article-marked-p (type &optional article)
5203   (let ((article (or article number)))
5204     (cond
5205      ((eq type 'tick)
5206       (memq article gnus-newsgroup-marked))
5207      ((eq type 'spam)
5208       (memq article gnus-newsgroup-spam-marked))
5209      ((eq type 'unsend)
5210       (memq article gnus-newsgroup-unsendable))
5211      ((eq type 'undownload)
5212       (memq article gnus-newsgroup-undownloaded))
5213      ((eq type 'download)
5214       (memq article gnus-newsgroup-downloadable))
5215      ((eq type 'unread)
5216       (memq article gnus-newsgroup-unreads))
5217      ((eq type 'read)
5218       (memq article gnus-newsgroup-reads))
5219      ((eq type 'dormant)
5220       (memq article gnus-newsgroup-dormant) )
5221      ((eq type 'expire)
5222       (memq article gnus-newsgroup-expirable))
5223      ((eq type 'reply)
5224       (memq article gnus-newsgroup-replied))
5225      ((eq type 'killed)
5226       (memq article gnus-newsgroup-killed))
5227      ((eq type 'bookmark)
5228       (assq article gnus-newsgroup-bookmarks))
5229      ((eq type 'score)
5230       (assq article gnus-newsgroup-scored))
5231      ((eq type 'save)
5232       (memq article gnus-newsgroup-saved))
5233      ((eq type 'cache)
5234       (memq article gnus-newsgroup-cached))
5235      ((eq type 'forward)
5236       (memq article gnus-newsgroup-forwarded))
5237      ((eq type 'seen)
5238       (not (memq article gnus-newsgroup-unseen)))
5239      ((eq type 'recent)
5240       (memq article gnus-newsgroup-recent))
5241      (t t))))
5242
5243 (defun gnus-articles-to-read (group &optional read-all)
5244   "Find out what articles the user wants to read."
5245   (let* ((display (gnus-group-find-parameter group 'display))
5246          (articles
5247           ;; Select all articles if `read-all' is non-nil, or if there
5248           ;; are no unread articles.
5249           (if (or read-all
5250                   (and (zerop (length gnus-newsgroup-marked))
5251                        (zerop (length gnus-newsgroup-unreads)))
5252                   ;; Fetch all if the predicate is non-nil.
5253                   gnus-newsgroup-display)
5254               ;; We want to select the headers for all the articles in
5255               ;; the group, so we select either all the active
5256               ;; articles in the group, or (if that's nil), the
5257               ;; articles in the cache.
5258               (or
5259                (gnus-uncompress-range (gnus-active group))
5260                (gnus-cache-articles-in-group group))
5261             ;; Select only the "normal" subset of articles.
5262             (gnus-sorted-nunion
5263              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5264              gnus-newsgroup-unreads)))
5265          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5266          (scored (length scored-list))
5267          (number (length articles))
5268          (marked (+ (length gnus-newsgroup-marked)
5269                     (length gnus-newsgroup-dormant)))
5270          (select
5271           (cond
5272            ((numberp read-all)
5273             read-all)
5274            ((numberp gnus-newsgroup-display)
5275             gnus-newsgroup-display)
5276            (t
5277             (condition-case ()
5278                 (cond
5279                  ((and (or (<= scored marked) (= scored number))
5280                        (numberp gnus-large-newsgroup)
5281                        (> number gnus-large-newsgroup))
5282                   (let* ((cursor-in-echo-area nil)
5283                          (initial (gnus-parameter-large-newsgroup-initial
5284                                    gnus-newsgroup-name))
5285                          (input
5286                           (read-string
5287                            (format
5288                             "How many articles from %s (%s %d): "
5289                             (gnus-limit-string
5290                              (gnus-group-decoded-name gnus-newsgroup-name)
5291                              35)
5292                             (if initial "max" "default")
5293                             number)
5294                            (if initial
5295                                (cons (number-to-string initial)
5296                                      0)))))
5297                     (if (string-match "^[ \t]*$" input) number input)))
5298                  ((and (> scored marked) (< scored number)
5299                        (> (- scored number) 20))
5300                   (let ((input
5301                          (read-string
5302                           (format "%s %s (%d scored, %d total): "
5303                                   "How many articles from"
5304                                   (gnus-group-decoded-name group)
5305                                   scored number))))
5306                     (if (string-match "^[ \t]*$" input)
5307                         number input)))
5308                  (t number))
5309               (quit
5310                (message "Quit getting the articles to read")
5311                nil))))))
5312     (setq select (if (stringp select) (string-to-number select) select))
5313     (if (or (null select) (zerop select))
5314         select
5315       (if (and (not (zerop scored)) (<= (abs select) scored))
5316           (progn
5317             (setq articles (sort scored-list '<))
5318             (setq number (length articles)))
5319         (setq articles (copy-sequence articles)))
5320
5321       (when (< (abs select) number)
5322         (if (< select 0)
5323             ;; Select the N oldest articles.
5324             (setcdr (nthcdr (1- (abs select)) articles) nil)
5325           ;; Select the N most recent articles.
5326           (setq articles (nthcdr (- number select) articles))))
5327       (setq gnus-newsgroup-unselected
5328             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5329       (when gnus-alter-articles-to-read-function
5330         (setq articles
5331               (sort
5332                (funcall gnus-alter-articles-to-read-function
5333                         gnus-newsgroup-name articles)
5334                '<)))
5335       articles)))
5336
5337 (defun gnus-killed-articles (killed articles)
5338   (let (out)
5339     (while articles
5340       (when (inline (gnus-member-of-range (car articles) killed))
5341         (push (car articles) out))
5342       (setq articles (cdr articles)))
5343     out))
5344
5345 (defun gnus-uncompress-marks (marks)
5346   "Uncompress the mark ranges in MARKS."
5347   (let ((uncompressed '(score bookmark))
5348         out)
5349     (while marks
5350       (if (memq (caar marks) uncompressed)
5351           (push (car marks) out)
5352         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5353       (setq marks (cdr marks)))
5354     out))
5355
5356 (defun gnus-article-mark-to-type (mark)
5357   "Return the type of MARK."
5358   (or (cadr (assq mark gnus-article-special-mark-lists))
5359       'list))
5360
5361 (defun gnus-article-unpropagatable-p (mark)
5362   "Return whether MARK should be propagated to back end."
5363   (memq mark gnus-article-unpropagated-mark-lists))
5364
5365 (defun gnus-adjust-marked-articles (info)
5366   "Set all article lists and remove all marks that are no longer valid."
5367   (let* ((marked-lists (gnus-info-marks info))
5368          (active (gnus-active (gnus-info-group info)))
5369          (min (car active))
5370          (max (cdr active))
5371          (types gnus-article-mark-lists)
5372          marks var articles article mark mark-type)
5373
5374     (dolist (marks marked-lists)
5375       (setq mark (car marks)
5376             mark-type (gnus-article-mark-to-type mark)
5377             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5378
5379       ;; We set the variable according to the type of the marks list,
5380       ;; and then adjust the marks to a subset of the active articles.
5381       (cond
5382        ;; Adjust "simple" lists.
5383        ((eq mark-type 'list)
5384         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5385         (when (memq mark '(tick dormant expire reply save))
5386           (while articles
5387             (when (or (< (setq article (pop articles)) min) (> article max))
5388               (set var (delq article (symbol-value var)))))))
5389        ;; Adjust assocs.
5390        ((eq mark-type 'tuple)
5391         (set var (setq articles (cdr marks)))
5392         (when (not (listp (cdr (symbol-value var))))
5393           (set var (list (symbol-value var))))
5394         (when (not (listp (cdr articles)))
5395           (setq articles (list articles)))
5396         (while articles
5397           (when (or (not (consp (setq article (pop articles))))
5398                     (< (car article) min)
5399                     (> (car article) max))
5400             (set var (delq article (symbol-value var))))))
5401        ;; Adjust ranges (sloppily).
5402        ((eq mark-type 'range)
5403         (cond
5404          ((eq mark 'seen)
5405           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5406           ;; It should be (seen (NUM1 . NUM2)).
5407           (when (numberp (cddr marks))
5408             (setcdr marks (list (cdr marks))))
5409           (setq articles (cdr marks))
5410           (while (and articles
5411                       (or (and (consp (car articles))
5412                                (> min (cdar articles)))
5413                           (and (numberp (car articles))
5414                                (> min (car articles)))))
5415             (pop articles))
5416           (set var articles))))))))
5417
5418 (defun gnus-update-missing-marks (missing)
5419   "Go through the list of MISSING articles and remove them from the mark lists."
5420   (when missing
5421     (let (var m)
5422       ;; Go through all types.
5423       (dolist (elem gnus-article-mark-lists)
5424         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5425           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5426           (when (symbol-value var)
5427             ;; This list has articles.  So we delete all missing
5428             ;; articles from it.
5429             (setq m missing)
5430             (while m
5431               (set var (delq (pop m) (symbol-value var))))))))))
5432
5433 (defun gnus-update-marks ()
5434   "Enter the various lists of marked articles into the newsgroup info list."
5435   (let ((types gnus-article-mark-lists)
5436         (info (gnus-get-info gnus-newsgroup-name))
5437         type list newmarked symbol delta-marks)
5438     (when info
5439       ;; Add all marks lists to the list of marks lists.
5440       (while (setq type (pop types))
5441         (setq list (symbol-value
5442                     (setq symbol
5443                           (intern (format "gnus-newsgroup-%s" (car type))))))
5444
5445         (when list
5446           ;; Get rid of the entries of the articles that have the
5447           ;; default score.
5448           (when (and (eq (cdr type) 'score)
5449                      gnus-save-score
5450                      list)
5451             (let* ((arts list)
5452                    (prev (cons nil list))
5453                    (all prev))
5454               (while arts
5455                 (if (or (not (consp (car arts)))
5456                         (= (cdar arts) gnus-summary-default-score))
5457                     (setcdr prev (cdr arts))
5458                   (setq prev arts))
5459                 (setq arts (cdr arts)))
5460               (setq list (cdr all)))))
5461
5462         (when (eq (cdr type) 'seen)
5463           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5464
5465         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5466           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5467
5468         (when (and (gnus-check-backend-function
5469                     'request-set-mark gnus-newsgroup-name)
5470                    (not (gnus-article-unpropagatable-p (cdr type))))
5471           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5472                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5473                  (add (gnus-remove-from-range
5474                        (gnus-copy-sequence list) old)))
5475             (when add
5476               (push (list add 'add (list (cdr type))) delta-marks))
5477             (when del
5478               (push (list del 'del (list (cdr type))) delta-marks))))
5479
5480         (when list
5481           (push (cons (cdr type) list) newmarked)))
5482
5483       (when delta-marks
5484         (unless (gnus-check-group gnus-newsgroup-name)
5485           (error "Can't open server for %s" gnus-newsgroup-name))
5486         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5487
5488       ;; Enter these new marks into the info of the group.
5489       (if (nthcdr 3 info)
5490           (setcar (nthcdr 3 info) newmarked)
5491         ;; Add the marks lists to the end of the info.
5492         (when newmarked
5493           (setcdr (nthcdr 2 info) (list newmarked))))
5494
5495       ;; Cut off the end of the info if there's nothing else there.
5496       (let ((i 5))
5497         (while (and (> i 2)
5498                     (not (nth i info)))
5499           (when (nthcdr (decf i) info)
5500             (setcdr (nthcdr i info) nil)))))))
5501
5502 (defun gnus-set-mode-line (where)
5503   "Set the mode line of the article or summary buffers.
5504 If WHERE is `summary', the summary mode line format will be used."
5505   ;; Is this mode line one we keep updated?
5506   (when (and (memq where gnus-updated-mode-lines)
5507              (symbol-value
5508               (intern (format "gnus-%s-mode-line-format-spec" where))))
5509     (let (mode-string)
5510       (save-excursion
5511         ;; We evaluate this in the summary buffer since these
5512         ;; variables are buffer-local to that buffer.
5513         (set-buffer gnus-summary-buffer)
5514         ;; We bind all these variables that are used in the `eval' form
5515         ;; below.
5516         (let* ((mformat (symbol-value
5517                          (intern
5518                           (format "gnus-%s-mode-line-format-spec" where))))
5519                (gnus-tmp-group-name (gnus-group-decoded-name
5520                                      gnus-newsgroup-name))
5521                (gnus-tmp-article-number (or gnus-current-article 0))
5522                (gnus-tmp-unread gnus-newsgroup-unreads)
5523                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5524                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5525                (gnus-tmp-unread-and-unselected
5526                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5527                             (zerop gnus-tmp-unselected))
5528                        "")
5529                       ((zerop gnus-tmp-unselected)
5530                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5531                       (t (format "{%d(+%d) more}"
5532                                  gnus-tmp-unread-and-unticked
5533                                  gnus-tmp-unselected))))
5534                (gnus-tmp-subject
5535                 (if (and gnus-current-headers
5536                          (vectorp gnus-current-headers))
5537                     (gnus-mode-string-quote
5538                      (mail-header-subject gnus-current-headers))
5539                   ""))
5540                bufname-length max-len
5541                gnus-tmp-header);; passed as argument to any user-format-funcs
5542           (setq mode-string (eval mformat))
5543           (setq bufname-length (if (string-match "%b" mode-string)
5544                                    (- (length
5545                                        (buffer-name
5546                                         (if (eq where 'summary)
5547                                             nil
5548                                           (get-buffer gnus-article-buffer))))
5549                                       2)
5550                                  0))
5551           (setq max-len (max 4 (if gnus-mode-non-string-length
5552                                    (- (window-width)
5553                                       gnus-mode-non-string-length
5554                                       bufname-length)
5555                                  (length mode-string))))
5556           ;; We might have to chop a bit of the string off...
5557           (when (> (length mode-string) max-len)
5558             (setq mode-string
5559                   (concat (gnus-truncate-string mode-string (- max-len 3))
5560                           "...")))
5561           ;; Pad the mode string a bit.
5562           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5563       ;; Update the mode line.
5564       (setq mode-line-buffer-identification
5565             (gnus-mode-line-buffer-identification (list mode-string)))
5566       (set-buffer-modified-p t))))
5567
5568 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5569   "Go through the HEADERS list and add all Xrefs to a hash table.
5570 The resulting hash table is returned, or nil if no Xrefs were found."
5571   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5572          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5573          (xref-hashtb (gnus-make-hashtable))
5574          start group entry number xrefs header)
5575     (while headers
5576       (setq header (pop headers))
5577       (when (and (setq xrefs (mail-header-xref header))
5578                  (not (memq (setq number (mail-header-number header))
5579                             unreads)))
5580         (setq start 0)
5581         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5582           (setq start (match-end 0))
5583           (setq group (if prefix
5584                           (concat prefix (substring xrefs (match-beginning 1)
5585                                                     (match-end 1)))
5586                         (substring xrefs (match-beginning 1) (match-end 1))))
5587           (setq number
5588                 (string-to-int (substring xrefs (match-beginning 2)
5589                                           (match-end 2))))
5590           (if (setq entry (gnus-gethash group xref-hashtb))
5591               (setcdr entry (cons number (cdr entry)))
5592             (gnus-sethash group (cons number nil) xref-hashtb)))))
5593     (and start xref-hashtb)))
5594
5595 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5596   "Look through all the headers and mark the Xrefs as read."
5597   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5598         name info xref-hashtb idlist method nth4)
5599     (save-excursion
5600       (set-buffer gnus-group-buffer)
5601       (when (setq xref-hashtb
5602                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5603         (mapatoms
5604          (lambda (group)
5605            (unless (string= from-newsgroup (setq name (symbol-name group)))
5606              (setq idlist (symbol-value group))
5607              ;; Dead groups are not updated.
5608              (and (prog1
5609                       (setq info (gnus-get-info name))
5610                     (when (stringp (setq nth4 (gnus-info-method info)))
5611                       (setq nth4 (gnus-server-to-method nth4))))
5612                   ;; Only do the xrefs if the group has the same
5613                   ;; select method as the group we have just read.
5614                   (or (gnus-methods-equal-p
5615                        nth4 (gnus-find-method-for-group from-newsgroup))
5616                       virtual
5617                       (equal nth4 (setq method (gnus-find-method-for-group
5618                                                 from-newsgroup)))
5619                       (and (equal (car nth4) (car method))
5620                            (equal (nth 1 nth4) (nth 1 method))))
5621                   gnus-use-cross-reference
5622                   (or (not (eq gnus-use-cross-reference t))
5623                       virtual
5624                       ;; Only do cross-references on subscribed
5625                       ;; groups, if that is what is wanted.
5626                       (<= (gnus-info-level info) gnus-level-subscribed))
5627                   (gnus-group-make-articles-read name idlist))))
5628          xref-hashtb)))))
5629
5630 (defun gnus-compute-read-articles (group articles)
5631   (let* ((entry (gnus-group-entry group))
5632          (info (nth 2 entry))
5633          (active (gnus-active group))
5634          ninfo)
5635     (when entry
5636       ;; First peel off all invalid article numbers.
5637       (when active
5638         (let ((ids articles)
5639               id first)
5640           (while (setq id (pop ids))
5641             (when (and first (> id (cdr active)))
5642               ;; We'll end up in this situation in one particular
5643               ;; obscure situation.  If you re-scan a group and get
5644               ;; a new article that is cross-posted to a different
5645               ;; group that has not been re-scanned, you might get
5646               ;; crossposted article that has a higher number than
5647               ;; Gnus believes possible.  So we re-activate this
5648               ;; group as well.  This might mean doing the
5649               ;; crossposting thingy will *increase* the number
5650               ;; of articles in some groups.  Tsk, tsk.
5651               (setq active (or (gnus-activate-group group) active)))
5652             (when (or (> id (cdr active))
5653                       (< id (car active)))
5654               (setq articles (delq id articles))))))
5655       ;; If the read list is nil, we init it.
5656       (if (and active
5657                (null (gnus-info-read info))
5658                (> (car active) 1))
5659           (setq ninfo (cons 1 (1- (car active))))
5660         (setq ninfo (gnus-info-read info)))
5661       ;; Then we add the read articles to the range.
5662       (gnus-add-to-range
5663        ninfo (setq articles (sort articles '<))))))
5664
5665 (defun gnus-group-make-articles-read (group articles)
5666   "Update the info of GROUP to say that ARTICLES are read."
5667   (let* ((num 0)
5668          (entry (gnus-group-entry group))
5669          (info (nth 2 entry))
5670          (active (gnus-active group))
5671          range)
5672     (when entry
5673       (setq range (gnus-compute-read-articles group articles))
5674       (with-current-buffer gnus-group-buffer
5675         (gnus-undo-register
5676           `(progn
5677              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5678              (gnus-info-set-read ',info ',(gnus-info-read info))
5679              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5680              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5681              (gnus-group-update-group ,group t))))
5682       ;; Add the read articles to the range.
5683       (gnus-info-set-read info range)
5684       (gnus-request-set-mark group (list (list range 'add '(read))))
5685       ;; Then we have to re-compute how many unread
5686       ;; articles there are in this group.
5687       (when active
5688         (cond
5689          ((not range)
5690           (setq num (- (1+ (cdr active)) (car active))))
5691          ((not (listp (cdr range)))
5692           (setq num (- (cdr active) (- (1+ (cdr range))
5693                                        (car range)))))
5694          (t
5695           (while range
5696             (if (numberp (car range))
5697                 (setq num (1+ num))
5698               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5699             (setq range (cdr range)))
5700           (setq num (- (cdr active) num))))
5701         ;; Update the number of unread articles.
5702         (setcar entry num)
5703         ;; Update the group buffer.
5704         (unless (gnus-ephemeral-group-p group)
5705           (gnus-group-update-group group t))))))
5706
5707 (defvar gnus-newsgroup-none-id 0)
5708
5709 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5710   (let ((cur nntp-server-buffer)
5711         (dependencies
5712          (or dependencies
5713              (save-excursion (set-buffer gnus-summary-buffer)
5714                              gnus-newsgroup-dependencies)))
5715         headers id end ref
5716         (mail-parse-charset gnus-newsgroup-charset)
5717         (mail-parse-ignored-charsets
5718          (save-excursion (condition-case nil
5719                              (set-buffer gnus-summary-buffer)
5720                            (error))
5721                          gnus-newsgroup-ignored-charsets)))
5722     (save-excursion
5723       (set-buffer nntp-server-buffer)
5724       ;; Translate all TAB characters into SPACE characters.
5725       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5726       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5727       (ietf-drums-unfold-fws)
5728       (gnus-run-hooks 'gnus-parse-headers-hook)
5729       (let ((case-fold-search t)
5730             in-reply-to header p lines chars ctype)
5731         (goto-char (point-min))
5732         ;; Search to the beginning of the next header.  Error messages
5733         ;; do not begin with 2 or 3.
5734         (while (re-search-forward "^[23][0-9]+ " nil t)
5735           (setq id nil
5736                 ref nil)
5737           ;; This implementation of this function, with nine
5738           ;; search-forwards instead of the one re-search-forward and
5739           ;; a case (which basically was the old function) is actually
5740           ;; about twice as fast, even though it looks messier.  You
5741           ;; can't have everything, I guess.  Speed and elegance
5742           ;; doesn't always go hand in hand.
5743           (setq
5744            header
5745            (make-full-mail-header
5746             ;; Number.
5747             (prog1
5748                 (read cur)
5749               (end-of-line)
5750               (setq p (point))
5751               (narrow-to-region (point)
5752                                 (or (and (search-forward "\n.\n" nil t)
5753                                          (- (point) 2))
5754                                     (point))))
5755             ;; Subject.
5756             (progn
5757               (goto-char p)
5758               (if (search-forward "\nsubject:" nil t)
5759                   (nnheader-header-value)
5760                 "(none)"))
5761             ;; From.
5762             (progn
5763               (goto-char p)
5764               (if (search-forward "\nfrom:" nil t)
5765                   (nnheader-header-value)
5766                 "(nobody)"))
5767             ;; Date.
5768             (progn
5769               (goto-char p)
5770               (if (search-forward "\ndate:" nil t)
5771                   (nnheader-header-value) ""))
5772             ;; Message-ID.
5773             (progn
5774               (goto-char p)
5775               (setq id (if (re-search-forward
5776                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5777                            ;; We do it this way to make sure the Message-ID
5778                            ;; is (somewhat) syntactically valid.
5779                            (buffer-substring (match-beginning 1)
5780                                              (match-end 1))
5781                          ;; If there was no message-id, we just fake one
5782                          ;; to make subsequent routines simpler.
5783                          (nnheader-generate-fake-message-id))))
5784             ;; References.
5785             (progn
5786               (goto-char p)
5787               (if (search-forward "\nreferences:" nil t)
5788                   (progn
5789                     (setq end (point))
5790                     (prog1
5791                         (nnheader-header-value)
5792                       (setq ref
5793                             (buffer-substring
5794                              (progn
5795                                ;; (end-of-line)
5796                                (search-backward ">" end t)
5797                                (1+ (point)))
5798                              (progn
5799                                (search-backward "<" end t)
5800                                (point))))))
5801                 ;; Get the references from the in-reply-to header if there
5802                 ;; were no references and the in-reply-to header looks
5803                 ;; promising.
5804                 (if (and (search-forward "\nin-reply-to:" nil t)
5805                          (setq in-reply-to (nnheader-header-value))
5806                          (string-match "<[^>]+>" in-reply-to))
5807                     (let (ref2)
5808                       (setq ref (substring in-reply-to (match-beginning 0)
5809                                            (match-end 0)))
5810                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5811                         (setq ref2 (substring in-reply-to (match-beginning 0)
5812                                               (match-end 0)))
5813                         (when (> (length ref2) (length ref))
5814                           (setq ref ref2)))
5815                       ref)
5816                   (setq ref nil))))
5817             ;; Chars.
5818             (progn
5819               (goto-char p)
5820               (if (search-forward "\nchars: " nil t)
5821                   (if (numberp (setq chars (ignore-errors (read cur))))
5822                       chars -1)
5823                 -1))
5824             ;; Lines.
5825             (progn
5826               (goto-char p)
5827               (if (search-forward "\nlines: " nil t)
5828                   (if (numberp (setq lines (ignore-errors (read cur))))
5829                       lines -1)
5830                 -1))
5831             ;; Xref.
5832             (progn
5833               (goto-char p)
5834               (and (search-forward "\nxref:" nil t)
5835                    (nnheader-header-value)))
5836             ;; Extra.
5837             (when gnus-extra-headers
5838               (let ((extra gnus-extra-headers)
5839                     out)
5840                 (while extra
5841                   (goto-char p)
5842                   (when (search-forward
5843                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5844                     (push (cons (car extra) (nnheader-header-value)) out))
5845                   (pop extra))
5846                 out))))
5847           (goto-char p)
5848           (if (and (search-forward "\ncontent-type: " nil t)
5849                    (setq ctype (nnheader-header-value)))
5850               (mime-entity-set-content-type-internal
5851                header (mime-parse-Content-Type ctype)))
5852           (when (equal id ref)
5853             (setq ref nil))
5854
5855           (when gnus-alter-header-function
5856             (funcall gnus-alter-header-function header)
5857             (setq id (mail-header-id header)
5858                   ref (gnus-parent-id (mail-header-references header))))
5859
5860           (when (setq header
5861                       (gnus-dependencies-add-header
5862                        header dependencies force-new))
5863             (push header headers))
5864           (goto-char (point-max))
5865           (widen))
5866         (nreverse headers)))))
5867
5868 ;; Goes through the xover lines and returns a list of vectors
5869 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5870                                                   force-new dependencies
5871                                                   group also-fetch-heads)
5872   "Parse the news overview data in the server buffer.
5873 Return a list of headers that match SEQUENCE (see
5874 `nntp-retrieve-headers')."
5875   ;; Get the Xref when the users reads the articles since most/some
5876   ;; NNTP servers do not include Xrefs when using XOVER.
5877   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5878   (let ((mail-parse-charset gnus-newsgroup-charset)
5879         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5880         (cur nntp-server-buffer)
5881         (dependencies (or dependencies gnus-newsgroup-dependencies))
5882         (allp (cond
5883                ((eq gnus-read-all-available-headers t)
5884                 t)
5885                ((stringp gnus-read-all-available-headers)
5886                 (string-match gnus-read-all-available-headers group))
5887                (t
5888                 nil)))
5889         number headers header)
5890     (save-excursion
5891       (set-buffer nntp-server-buffer)
5892       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5893       ;; Allow the user to mangle the headers before parsing them.
5894       (gnus-run-hooks 'gnus-parse-headers-hook)
5895       (goto-char (point-min))
5896       (gnus-parse-without-error
5897         (while (and (or sequence allp)
5898                     (not (eobp)))
5899           (setq number (read cur))
5900           (when (not allp)
5901             (while (and sequence
5902                         (< (car sequence) number))
5903               (setq sequence (cdr sequence))))
5904           (when (and (or allp
5905                          (and sequence
5906                               (eq number (car sequence))))
5907                      (progn
5908                        (setq sequence (cdr sequence))
5909                        (setq header (inline
5910                                       (gnus-nov-parse-line
5911                                        number dependencies force-new)))))
5912             (push header headers))
5913           (forward-line 1)))
5914       ;; A common bug in inn is that if you have posted an article and
5915       ;; then retrieves the active file, it will answer correctly --
5916       ;; the new article is included.  However, a NOV entry for the
5917       ;; article may not have been generated yet, so this may fail.
5918       ;; We work around this problem by retrieving the last few
5919       ;; headers using HEAD.
5920       (if (or (not also-fetch-heads)
5921               (not sequence))
5922           ;; We (probably) got all the headers.
5923           (nreverse headers)
5924         (let ((gnus-nov-is-evil t))
5925           (nconc
5926            (nreverse headers)
5927            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5928              (gnus-get-newsgroup-headers))))))))
5929
5930 (defun gnus-article-get-xrefs ()
5931   "Fill in the Xref value in `gnus-current-headers', if necessary.
5932 This is meant to be called in `gnus-article-internal-prepare-hook'."
5933   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5934                                  gnus-current-headers)))
5935     (or (not gnus-use-cross-reference)
5936         (not headers)
5937         (and (mail-header-xref headers)
5938              (not (string= (mail-header-xref headers) "")))
5939         (let ((case-fold-search t)
5940               xref)
5941           (save-restriction
5942             (nnheader-narrow-to-headers)
5943             (goto-char (point-min))
5944             (when (or (and (not (eobp))
5945                            (eq (downcase (char-after)) ?x)
5946                            (looking-at "Xref:"))
5947                       (search-forward "\nXref:" nil t))
5948               (goto-char (1+ (match-end 0)))
5949               (setq xref (buffer-substring (point) (point-at-eol)))
5950               (mail-header-set-xref headers xref)))))))
5951
5952 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5953   "Find article ID and insert the summary line for that article.
5954 OLD-HEADER can either be a header or a line number to insert
5955 the subject line on."
5956   (let* ((line (and (numberp old-header) old-header))
5957          (old-header (and (vectorp old-header) old-header))
5958          (header (cond ((and old-header use-old-header)
5959                         old-header)
5960                        ((and (numberp id)
5961                              (gnus-number-to-header id))
5962                         (gnus-number-to-header id))
5963                        (t
5964                         (gnus-read-header id))))
5965          (number (and (numberp id) id))
5966          d)
5967     (when header
5968       ;; Rebuild the thread that this article is part of and go to the
5969       ;; article we have fetched.
5970       (when (and (not gnus-show-threads)
5971                  old-header)
5972         (when (and number
5973                    (setq d (gnus-data-find (mail-header-number old-header))))
5974           (goto-char (gnus-data-pos d))
5975           (gnus-data-remove
5976            number
5977            (- (point-at-bol)
5978               (prog1
5979                   (1+ (point-at-eol))
5980                 (gnus-delete-line))))))
5981       (when old-header
5982         (mail-header-set-number header (mail-header-number old-header)))
5983       (setq gnus-newsgroup-sparse
5984             (delq (setq number (mail-header-number header))
5985                   gnus-newsgroup-sparse))
5986       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5987       (push number gnus-newsgroup-limit)
5988       (gnus-rebuild-thread (mail-header-id header) line)
5989       (gnus-summary-goto-subject number nil t))
5990     (when (and (numberp number)
5991                (> number 0))
5992       ;; We have to update the boundaries even if we can't fetch the
5993       ;; article if ID is a number -- so that the next `P' or `N'
5994       ;; command will fetch the previous (or next) article even
5995       ;; if the one we tried to fetch this time has been canceled.
5996       (when (> number gnus-newsgroup-end)
5997         (setq gnus-newsgroup-end number))
5998       (when (< number gnus-newsgroup-begin)
5999         (setq gnus-newsgroup-begin number))
6000       (setq gnus-newsgroup-unselected
6001             (delq number gnus-newsgroup-unselected)))
6002     ;; Report back a success?
6003     (and header (mail-header-number header))))
6004
6005 ;;; Process/prefix in the summary buffer
6006
6007 (defun gnus-summary-work-articles (n)
6008   "Return a list of articles to be worked upon.
6009 The prefix argument, the list of process marked articles, and the
6010 current article will be taken into consideration."
6011   (save-excursion
6012     (set-buffer gnus-summary-buffer)
6013     (cond
6014      (n
6015       ;; A numerical prefix has been given.
6016       (setq n (prefix-numeric-value n))
6017       (let ((backward (< n 0))
6018             (n (abs (prefix-numeric-value n)))
6019             articles article)
6020         (save-excursion
6021           (while
6022               (and (> n 0)
6023                    (push (setq article (gnus-summary-article-number))
6024                          articles)
6025                    (if backward
6026                        (gnus-summary-find-prev nil article)
6027                      (gnus-summary-find-next nil article)))
6028             (decf n)))
6029         (nreverse articles)))
6030      ((and (gnus-region-active-p) (mark))
6031       (message "region active")
6032       ;; Work on the region between point and mark.
6033       (let ((max (max (point) (mark)))
6034             articles article)
6035         (save-excursion
6036           (goto-char (min (point) (mark)))
6037           (while
6038               (and
6039                (push (setq article (gnus-summary-article-number)) articles)
6040                (gnus-summary-find-next nil article)
6041                (< (point) max)))
6042           (nreverse articles))))
6043      (gnus-newsgroup-processable
6044       ;; There are process-marked articles present.
6045       ;; Save current state.
6046       (gnus-summary-save-process-mark)
6047       ;; Return the list.
6048       (reverse gnus-newsgroup-processable))
6049      (t
6050       ;; Just return the current article.
6051       (list (gnus-summary-article-number))))))
6052
6053 (defmacro gnus-summary-iterate (arg &rest forms)
6054   "Iterate over the process/prefixed articles and do FORMS.
6055 ARG is the interactive prefix given to the command.  FORMS will be
6056 executed with point over the summary line of the articles."
6057   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6058     `(let ((,articles (gnus-summary-work-articles ,arg)))
6059        (while ,articles
6060          (gnus-summary-goto-subject (car ,articles))
6061          ,@forms
6062          (pop ,articles)))))
6063
6064 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6065 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6066
6067 (defun gnus-summary-save-process-mark ()
6068   "Push the current set of process marked articles on the stack."
6069   (interactive)
6070   (push (copy-sequence gnus-newsgroup-processable)
6071         gnus-newsgroup-process-stack))
6072
6073 (defun gnus-summary-kill-process-mark ()
6074   "Push the current set of process marked articles on the stack and unmark."
6075   (interactive)
6076   (gnus-summary-save-process-mark)
6077   (gnus-summary-unmark-all-processable))
6078
6079 (defun gnus-summary-yank-process-mark ()
6080   "Pop the last process mark state off the stack and restore it."
6081   (interactive)
6082   (unless gnus-newsgroup-process-stack
6083     (error "Empty mark stack"))
6084   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6085
6086 (defun gnus-summary-process-mark-set (set)
6087   "Make SET into the current process marked articles."
6088   (gnus-summary-unmark-all-processable)
6089   (while set
6090     (gnus-summary-set-process-mark (pop set))))
6091
6092 ;;; Searching and stuff
6093
6094 (defun gnus-summary-search-group (&optional backward use-level)
6095   "Search for next unread newsgroup.
6096 If optional argument BACKWARD is non-nil, search backward instead."
6097   (save-excursion
6098     (set-buffer gnus-group-buffer)
6099     (when (gnus-group-search-forward
6100            backward nil (if use-level (gnus-group-group-level) nil))
6101       (gnus-group-group-name))))
6102
6103 (defun gnus-summary-best-group (&optional exclude-group)
6104   "Find the name of the best unread group.
6105 If EXCLUDE-GROUP, do not go to this group."
6106   (save-excursion
6107     (set-buffer gnus-group-buffer)
6108     (save-excursion
6109       (gnus-group-best-unread-group exclude-group))))
6110
6111 (defun gnus-summary-find-next (&optional unread article backward)
6112   (if backward
6113       (gnus-summary-find-prev unread article)
6114     (let* ((dummy (gnus-summary-article-intangible-p))
6115            (article (or article (gnus-summary-article-number)))
6116            (data (gnus-data-find-list article))
6117            result)
6118       (when (and (not dummy)
6119                  (or (not gnus-summary-check-current)
6120                      (not unread)
6121                      (not (gnus-data-unread-p (car data)))))
6122         (setq data (cdr data)))
6123       (when (setq result
6124                   (if unread
6125                       (progn
6126                         (while data
6127                           (unless (memq (gnus-data-number (car data))
6128                                         (cond
6129                                          ((eq gnus-auto-goto-ignores
6130                                               'always-undownloaded)
6131                                           gnus-newsgroup-undownloaded)
6132                                          (gnus-plugged
6133                                           nil)
6134                                          ((eq gnus-auto-goto-ignores
6135                                               'unfetched)
6136                                           gnus-newsgroup-unfetched)
6137                                          ((eq gnus-auto-goto-ignores
6138                                               'undownloaded)
6139                                           gnus-newsgroup-undownloaded)))
6140                             (when (gnus-data-unread-p (car data))
6141                               (setq result (car data)
6142                                     data nil)))
6143                           (setq data (cdr data)))
6144                         result)
6145                     (car data)))
6146         (goto-char (gnus-data-pos result))
6147         (gnus-data-number result)))))
6148
6149 (defun gnus-summary-find-prev (&optional unread article)
6150   (let* ((eobp (eobp))
6151          (article (or article (gnus-summary-article-number)))
6152          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6153          result)
6154     (when (and (not eobp)
6155                (or (not gnus-summary-check-current)
6156                    (not unread)
6157                    (not (gnus-data-unread-p (car data)))))
6158       (setq data (cdr data)))
6159     (when (setq result
6160                 (if unread
6161                     (progn
6162                       (while data
6163                         (unless (memq (gnus-data-number (car data))
6164                                       (cond
6165                                        ((eq gnus-auto-goto-ignores
6166                                             'always-undownloaded)
6167                                         gnus-newsgroup-undownloaded)
6168                                        (gnus-plugged
6169                                         nil)
6170                                        ((eq gnus-auto-goto-ignores
6171                                             'unfetched)
6172                                         gnus-newsgroup-unfetched)
6173                                        ((eq gnus-auto-goto-ignores
6174                                             'undownloaded)
6175                                         gnus-newsgroup-undownloaded)))
6176                           (when (gnus-data-unread-p (car data))
6177                             (setq result (car data)
6178                                   data nil)))
6179                         (setq data (cdr data)))
6180                       result)
6181                   (car data)))
6182       (goto-char (gnus-data-pos result))
6183       (gnus-data-number result))))
6184
6185 (defun gnus-summary-find-subject (subject &optional unread backward article)
6186   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6187          (article (or article (gnus-summary-article-number)))
6188          (articles (gnus-data-list backward))
6189          (arts (gnus-data-find-list article articles))
6190          result)
6191     (when (or (not gnus-summary-check-current)
6192               (not unread)
6193               (not (gnus-data-unread-p (car arts))))
6194       (setq arts (cdr arts)))
6195     (while arts
6196       (and (or (not unread)
6197                (gnus-data-unread-p (car arts)))
6198            (vectorp (gnus-data-header (car arts)))
6199            (gnus-subject-equal
6200             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6201            (setq result (car arts)
6202                  arts nil))
6203       (setq arts (cdr arts)))
6204     (and result
6205          (goto-char (gnus-data-pos result))
6206          (gnus-data-number result))))
6207
6208 (defun gnus-summary-search-forward (&optional unread subject backward)
6209   "Search forward for an article.
6210 If UNREAD, look for unread articles.  If SUBJECT, look for
6211 articles with that subject.  If BACKWARD, search backward instead."
6212   (cond (subject (gnus-summary-find-subject subject unread backward))
6213         (backward (gnus-summary-find-prev unread))
6214         (t (gnus-summary-find-next unread))))
6215
6216 (defun gnus-recenter (&optional n)
6217   "Center point in window and redisplay frame.
6218 Also do horizontal recentering."
6219   (interactive "P")
6220   (when (and gnus-auto-center-summary
6221              (not (eq gnus-auto-center-summary 'vertical)))
6222     (gnus-horizontal-recenter))
6223   (recenter n))
6224
6225 (defun gnus-summary-recenter ()
6226   "Center point in the summary window.
6227 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6228 displayed, no centering will be performed."
6229   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6230   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6231   (interactive)
6232   ;; The user has to want it.
6233   (when gnus-auto-center-summary
6234     (let* ((top (cond ((< (window-height) 4) 0)
6235                       ((< (window-height) 7) 1)
6236                       (t (if (numberp gnus-auto-center-summary)
6237                              gnus-auto-center-summary
6238                            2))))
6239            (height (1- (window-height)))
6240            (bottom (save-excursion (goto-char (point-max))
6241                                    (forward-line (- height))
6242                                    (point)))
6243            (window (get-buffer-window (current-buffer))))
6244       (when (get-buffer-window gnus-article-buffer)
6245         ;; Only do recentering when the article buffer is displayed,
6246         ;; Set the window start to either `bottom', which is the biggest
6247         ;; possible valid number, or the second line from the top,
6248         ;; whichever is the least.
6249         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6250           (if (> bottom top-pos)
6251               ;; Keep the second line from the top visible
6252               (set-window-start window top-pos t)
6253             ;; Try to keep the bottom line visible; if it's partially
6254             ;; obscured, either scroll one more line to make it fully
6255             ;; visible, or revert to using TOP-POS.
6256             (save-excursion
6257               (goto-char (point-max))
6258               (forward-line -1)
6259               (let ((last-line-start (point)))
6260                 (goto-char bottom)
6261                 (set-window-start window (point) t)
6262                 (when (not (pos-visible-in-window-p last-line-start window))
6263                   (forward-line 1)
6264                   (set-window-start window (min (point) top-pos) t)))))))
6265       ;; Do horizontal recentering while we're at it.
6266       (when (and (get-buffer-window (current-buffer) t)
6267                  (not (eq gnus-auto-center-summary 'vertical)))
6268         (let ((selected (selected-window)))
6269           (select-window (get-buffer-window (current-buffer) t))
6270           (gnus-summary-position-point)
6271           (gnus-horizontal-recenter)
6272           (select-window selected))))))
6273
6274 (defun gnus-summary-jump-to-group (newsgroup)
6275   "Move point to NEWSGROUP in group mode buffer."
6276   ;; Keep update point of group mode buffer if visible.
6277   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6278       (save-window-excursion
6279         ;; Take care of tree window mode.
6280         (when (get-buffer-window gnus-group-buffer)
6281           (pop-to-buffer gnus-group-buffer))
6282         (gnus-group-jump-to-group newsgroup))
6283     (save-excursion
6284       ;; Take care of tree window mode.
6285       (if (get-buffer-window gnus-group-buffer)
6286           (pop-to-buffer gnus-group-buffer)
6287         (set-buffer gnus-group-buffer))
6288       (gnus-group-jump-to-group newsgroup))))
6289
6290 ;; This function returns a list of article numbers based on the
6291 ;; difference between the ranges of read articles in this group and
6292 ;; the range of active articles.
6293 (defun gnus-list-of-unread-articles (group)
6294   (let* ((read (gnus-info-read (gnus-get-info group)))
6295          (active (or (gnus-active group) (gnus-activate-group group)))
6296          (last (cdr active))
6297          first nlast unread)
6298     ;; If none are read, then all are unread.
6299     (if (not read)
6300         (setq first (car active))
6301       ;; If the range of read articles is a single range, then the
6302       ;; first unread article is the article after the last read
6303       ;; article.  Sounds logical, doesn't it?
6304       (if (and (not (listp (cdr read)))
6305                (or (< (car read) (car active))
6306                    (progn (setq read (list read))
6307                           nil)))
6308           (setq first (max (car active) (1+ (cdr read))))
6309         ;; `read' is a list of ranges.
6310         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6311                                   (caar read)))
6312                   1)
6313           (setq first (car active)))
6314         (while read
6315           (when first
6316             (while (< first nlast)
6317               (push first unread)
6318               (setq first (1+ first))))
6319           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6320           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6321           (setq read (cdr read)))))
6322     ;; And add the last unread articles.
6323     (while (<= first last)
6324       (push first unread)
6325       (setq first (1+ first)))
6326     ;; Return the list of unread articles.
6327     (delq 0 (nreverse unread))))
6328
6329 (defun gnus-list-of-read-articles (group)
6330   "Return a list of unread, unticked and non-dormant articles."
6331   (let* ((info (gnus-get-info group))
6332          (marked (gnus-info-marks info))
6333          (active (gnus-active group)))
6334     (and info active
6335          (gnus-list-range-difference
6336           (gnus-list-range-difference
6337            (gnus-sorted-complement
6338             (gnus-uncompress-range active)
6339             (gnus-list-of-unread-articles group))
6340            (cdr (assq 'dormant marked)))
6341           (cdr (assq 'tick marked))))))
6342
6343 ;; Various summary commands
6344
6345 (defun gnus-summary-select-article-buffer ()
6346   "Reconfigure windows to show article buffer."
6347   (interactive)
6348   (if (not (gnus-buffer-live-p gnus-article-buffer))
6349       (error "There is no article buffer for this summary buffer")
6350     (gnus-configure-windows 'article)
6351     (select-window (get-buffer-window gnus-article-buffer))))
6352
6353 (defun gnus-summary-universal-argument (arg)
6354   "Perform any operation on all articles that are process/prefixed."
6355   (interactive "P")
6356   (let ((articles (gnus-summary-work-articles arg))
6357         func article)
6358     (if (eq
6359          (setq
6360           func
6361           (key-binding
6362            (read-key-sequence
6363             (substitute-command-keys
6364              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6365          'undefined)
6366         (gnus-error 1 "Undefined key")
6367       (save-excursion
6368         (while articles
6369           (gnus-summary-goto-subject (setq article (pop articles)))
6370           (let (gnus-newsgroup-processable)
6371             (command-execute func))
6372           (gnus-summary-remove-process-mark article)))))
6373   (gnus-summary-position-point))
6374
6375 (defun gnus-summary-toggle-truncation (&optional arg)
6376   "Toggle truncation of summary lines.
6377 With ARG, turn line truncation on if ARG is positive."
6378   (interactive "P")
6379   (setq truncate-lines
6380         (if (null arg) (not truncate-lines)
6381           (> (prefix-numeric-value arg) 0)))
6382   (redraw-display))
6383
6384 (defun gnus-summary-find-for-reselect ()
6385   "Return the number of an article to stay on across a reselect.
6386 The current article is considered, then following articles, then previous
6387 articles.  An article is sought which is not cancelled and isn't a temporary
6388 insertion from another group.  If there's no such then return a dummy 0."
6389   (let (found)
6390     (dolist (rev '(nil t))
6391       (unless found      ; don't demand the reverse list if we don't need it
6392         (let ((data (gnus-data-find-list
6393                      (gnus-summary-article-number) (gnus-data-list rev))))
6394           (while (and data (not found))
6395             (if (and (< 0 (gnus-data-number (car data)))
6396                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6397                 (setq found (gnus-data-number (car data))))
6398             (setq data (cdr data))))))
6399     (or found 0)))
6400
6401 (defun gnus-summary-reselect-current-group (&optional all rescan)
6402   "Exit and then reselect the current newsgroup.
6403 The prefix argument ALL means to select all articles."
6404   (interactive "P")
6405   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6406     (error "Ephemeral groups can't be reselected"))
6407   (let ((current-subject (gnus-summary-find-for-reselect))
6408         (group gnus-newsgroup-name))
6409     (setq gnus-newsgroup-begin nil)
6410     (gnus-summary-exit nil 'leave-hidden)
6411     ;; We have to adjust the point of group mode buffer because
6412     ;; point was moved to the next unread newsgroup by exiting.
6413     (gnus-summary-jump-to-group group)
6414     (when rescan
6415       (save-excursion
6416         (save-window-excursion
6417           ;; Don't show group contents.
6418           (set-window-start (selected-window) (point-max))
6419           (gnus-group-get-new-news-this-group 1))))
6420     (gnus-group-read-group all t)
6421     (gnus-summary-goto-subject current-subject nil t)))
6422
6423 (defun gnus-summary-rescan-group (&optional all)
6424   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6425   (interactive "P")
6426   (gnus-summary-reselect-current-group all t))
6427
6428 (defun gnus-summary-update-info (&optional non-destructive)
6429   (save-excursion
6430     (let ((group gnus-newsgroup-name))
6431       (when group
6432         (when gnus-newsgroup-kill-headers
6433           (setq gnus-newsgroup-killed
6434                 (gnus-compress-sequence
6435                  (gnus-sorted-union
6436                   (gnus-list-range-intersection
6437                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6438                   gnus-newsgroup-unreads)
6439                  t)))
6440         (unless (listp (cdr gnus-newsgroup-killed))
6441           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6442         (let ((headers gnus-newsgroup-headers))
6443           ;; Set the new ranges of read articles.
6444           (save-excursion
6445             (set-buffer gnus-group-buffer)
6446             (gnus-undo-force-boundary))
6447           (gnus-update-read-articles
6448            group (gnus-sorted-union
6449                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6450           ;; Set the current article marks.
6451           (let ((gnus-newsgroup-scored
6452                  (if (and (not gnus-save-score)
6453                           (not non-destructive))
6454                      nil
6455                    gnus-newsgroup-scored)))
6456             (save-excursion
6457               (gnus-update-marks)))
6458           ;; Do the cross-ref thing.
6459           (when gnus-use-cross-reference
6460             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6461           ;; Do not switch windows but change the buffer to work.
6462           (set-buffer gnus-group-buffer)
6463           (unless (gnus-ephemeral-group-p group)
6464             (gnus-group-update-group group)))))))
6465
6466 (defun gnus-summary-save-newsrc (&optional force)
6467   "Save the current number of read/marked articles in the dribble buffer.
6468 The dribble buffer will then be saved.
6469 If FORCE (the prefix), also save the .newsrc file(s)."
6470   (interactive "P")
6471   (gnus-summary-update-info t)
6472   (if force
6473       (gnus-save-newsrc-file)
6474     (gnus-dribble-save)))
6475
6476 (defun gnus-summary-exit (&optional temporary leave-hidden)
6477   "Exit reading current newsgroup, and then return to group selection mode.
6478 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6479   (interactive)
6480   (gnus-set-global-variables)
6481   (gnus-kill-save-kill-buffer)
6482   (gnus-async-halt-prefetch)
6483   (let* ((group gnus-newsgroup-name)
6484          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6485          (gnus-group-is-exiting-p t)
6486          (mode major-mode)
6487          (group-point nil)
6488          (buf (current-buffer)))
6489     (unless quit-config
6490       ;; Do adaptive scoring, and possibly save score files.
6491       (when gnus-newsgroup-adaptive
6492         (gnus-score-adaptive))
6493       (when gnus-use-scoring
6494         (gnus-score-save)))
6495     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6496     ;; If we have several article buffers, we kill them at exit.
6497     (unless gnus-single-article-buffer
6498       (gnus-kill-buffer gnus-original-article-buffer)
6499       (setq gnus-article-current nil))
6500     (when gnus-use-cache
6501       (gnus-cache-possibly-remove-articles)
6502       (gnus-cache-save-buffers))
6503     (gnus-async-prefetch-remove-group group)
6504     (when gnus-suppress-duplicates
6505       (gnus-dup-enter-articles))
6506     (when gnus-use-trees
6507       (gnus-tree-close group))
6508     (when gnus-use-cache
6509       (gnus-cache-write-active))
6510     ;; Remove entries for this group.
6511     (nnmail-purge-split-history (gnus-group-real-name group))
6512     ;; Make all changes in this group permanent.
6513     (unless quit-config
6514       (gnus-run-hooks 'gnus-exit-group-hook)
6515       (gnus-summary-update-info))
6516     (gnus-close-group group)
6517     ;; Make sure where we were, and go to next newsgroup.
6518     (set-buffer gnus-group-buffer)
6519     (unless quit-config
6520       (gnus-group-jump-to-group group))
6521     (gnus-run-hooks 'gnus-summary-exit-hook)
6522     (unless (or quit-config
6523                 ;; If this group has disappeared from the summary
6524                 ;; buffer, don't skip forwards.
6525                 (not (string= group (gnus-group-group-name))))
6526       (gnus-group-next-unread-group 1))
6527     (setq group-point (point))
6528     (if temporary
6529         nil                             ;Nothing to do.
6530       ;; If we have several article buffers, we kill them at exit.
6531       (unless gnus-single-article-buffer
6532         (gnus-kill-buffer gnus-article-buffer)
6533         (gnus-kill-buffer gnus-original-article-buffer)
6534         (setq gnus-article-current nil))
6535       (set-buffer buf)
6536       (if (not gnus-kill-summary-on-exit)
6537           (progn
6538             (gnus-deaden-summary)
6539             (setq mode nil))
6540         ;; We set all buffer-local variables to nil.  It is unclear why
6541         ;; this is needed, but if we don't, buffer-local variables are
6542         ;; not garbage-collected, it seems.  This would the lead to en
6543         ;; ever-growing Emacs.
6544         (gnus-summary-clear-local-variables)
6545         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6546           (gnus-summary-clear-local-variables))
6547         (when (get-buffer gnus-article-buffer)
6548           (bury-buffer gnus-article-buffer))
6549         ;; We clear the global counterparts of the buffer-local
6550         ;; variables as well, just to be on the safe side.
6551         (set-buffer gnus-group-buffer)
6552         (gnus-summary-clear-local-variables)
6553         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6554           (gnus-summary-clear-local-variables))
6555         ;; Return to group mode buffer.
6556         (when (eq mode 'gnus-summary-mode)
6557           (gnus-kill-buffer buf)))
6558       (setq gnus-current-select-method gnus-select-method)
6559       (if leave-hidden
6560           (set-buffer gnus-group-buffer)
6561         (pop-to-buffer gnus-group-buffer))
6562       (if (not quit-config)
6563           (progn
6564             (goto-char group-point)
6565             (unless leave-hidden
6566               (gnus-configure-windows 'group 'force))
6567             (unless (pos-visible-in-window-p)
6568               (forward-line (/ (static-if (featurep 'xemacs)
6569                                    (window-displayed-height)
6570                                  (1- (window-height)))
6571                                -2))
6572               (set-window-start (selected-window) (point))
6573               (goto-char group-point)))
6574         (gnus-handle-ephemeral-exit quit-config))
6575       ;; Clear the current group name.
6576       (unless quit-config
6577         (setq gnus-newsgroup-name nil)))))
6578
6579 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6580 (defun gnus-summary-exit-no-update (&optional no-questions)
6581   "Quit reading current newsgroup without updating read article info."
6582   (interactive)
6583   (let* ((group gnus-newsgroup-name)
6584          (gnus-group-is-exiting-p t)
6585          (gnus-group-is-exiting-without-update-p t)
6586          (quit-config (gnus-group-quit-config group)))
6587     (when (or no-questions
6588               gnus-expert-user
6589               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6590       (gnus-async-halt-prefetch)
6591       (run-hooks 'gnus-summary-prepare-exit-hook)
6592       ;; If we have several article buffers, we kill them at exit.
6593       (unless gnus-single-article-buffer
6594         (gnus-kill-buffer gnus-article-buffer)
6595         (gnus-kill-buffer gnus-original-article-buffer)
6596         (setq gnus-article-current nil))
6597       (if (not gnus-kill-summary-on-exit)
6598           (gnus-deaden-summary)
6599         (gnus-close-group group)
6600         (gnus-summary-clear-local-variables)
6601         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6602           (gnus-summary-clear-local-variables))
6603         (set-buffer gnus-group-buffer)
6604         (gnus-summary-clear-local-variables)
6605         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6606           (gnus-summary-clear-local-variables))
6607         (gnus-kill-buffer gnus-summary-buffer))
6608       (unless gnus-single-article-buffer
6609         (setq gnus-article-current nil))
6610       (when gnus-use-trees
6611         (gnus-tree-close group))
6612       (gnus-async-prefetch-remove-group group)
6613       (when (get-buffer gnus-article-buffer)
6614         (bury-buffer gnus-article-buffer))
6615       ;; Return to the group buffer.
6616       (gnus-configure-windows 'group 'force)
6617       ;; Clear the current group name.
6618       (setq gnus-newsgroup-name nil)
6619       (unless (gnus-ephemeral-group-p group)
6620         (gnus-group-update-group group))
6621       (when (equal (gnus-group-group-name) group)
6622         (gnus-group-next-unread-group 1))
6623       (when quit-config
6624         (gnus-handle-ephemeral-exit quit-config)))))
6625
6626 (defun gnus-handle-ephemeral-exit (quit-config)
6627   "Handle movement when leaving an ephemeral group.
6628 The state which existed when entering the ephemeral is reset."
6629   (if (not (buffer-name (car quit-config)))
6630       (gnus-configure-windows 'group 'force)
6631     (set-buffer (car quit-config))
6632     (cond ((eq major-mode 'gnus-summary-mode)
6633            (gnus-set-global-variables))
6634           ((eq major-mode 'gnus-article-mode)
6635            (save-excursion
6636              ;; The `gnus-summary-buffer' variable may point
6637              ;; to the old summary buffer when using a single
6638              ;; article buffer.
6639              (unless (gnus-buffer-live-p gnus-summary-buffer)
6640                (set-buffer gnus-group-buffer))
6641              (set-buffer gnus-summary-buffer)
6642              (gnus-set-global-variables))))
6643     (if (or (eq (cdr quit-config) 'article)
6644             (eq (cdr quit-config) 'pick))
6645         (progn
6646           ;; The current article may be from the ephemeral group
6647           ;; thus it is best that we reload this article
6648           ;;
6649           ;; If we're exiting from a large digest, this can be
6650           ;; extremely slow.  So, it's better not to reload it. -- jh.
6651           ;;(gnus-summary-show-article)
6652           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6653               (gnus-configure-windows 'pick 'force)
6654             (gnus-configure-windows (cdr quit-config) 'force)))
6655       (gnus-configure-windows (cdr quit-config) 'force))
6656     (when (eq major-mode 'gnus-summary-mode)
6657       (gnus-summary-next-subject 1 nil t)
6658       (gnus-summary-recenter)
6659       (gnus-summary-position-point))))
6660
6661 (defun gnus-summary-preview-mime-message ()
6662   "MIME decode and play this message."
6663   (interactive)
6664   (let ((gnus-break-pages nil)
6665         (gnus-show-mime t))
6666     (gnus-summary-select-article gnus-show-all-headers t))
6667   (let ((w (get-buffer-window gnus-article-buffer)))
6668     (when w
6669       (select-window (get-buffer-window gnus-article-buffer)))))
6670
6671 ;;; Dead summaries.
6672
6673 (defvar gnus-dead-summary-mode-map nil)
6674
6675 (unless gnus-dead-summary-mode-map
6676   (setq gnus-dead-summary-mode-map (make-keymap))
6677   (suppress-keymap gnus-dead-summary-mode-map)
6678   (substitute-key-definition
6679    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6680   (dolist (key '("\C-d" "\r" "\177" [delete]))
6681     (define-key gnus-dead-summary-mode-map
6682       key 'gnus-summary-wake-up-the-dead))
6683   (dolist (key '("q" "Q"))
6684     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6685
6686 (defvar gnus-dead-summary-mode nil
6687   "Minor mode for Gnus summary buffers.")
6688
6689 (defun gnus-dead-summary-mode (&optional arg)
6690   "Minor mode for Gnus summary buffers."
6691   (interactive "P")
6692   (when (eq major-mode 'gnus-summary-mode)
6693     (make-local-variable 'gnus-dead-summary-mode)
6694     (setq gnus-dead-summary-mode
6695           (if (null arg) (not gnus-dead-summary-mode)
6696             (> (prefix-numeric-value arg) 0)))
6697     (when gnus-dead-summary-mode
6698       (add-minor-mode
6699        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6700
6701 (defun gnus-deaden-summary ()
6702   "Make the current summary buffer into a dead summary buffer."
6703   ;; Kill any previous dead summary buffer.
6704   (when (and gnus-dead-summary
6705              (buffer-name gnus-dead-summary))
6706     (save-excursion
6707       (set-buffer gnus-dead-summary)
6708       (when gnus-dead-summary-mode
6709         (kill-buffer (current-buffer)))))
6710   ;; Make this the current dead summary.
6711   (setq gnus-dead-summary (current-buffer))
6712   (gnus-dead-summary-mode 1)
6713   (let ((name (buffer-name)))
6714     (when (string-match "Summary" name)
6715       (rename-buffer
6716        (concat (substring name 0 (match-beginning 0)) "Dead "
6717                (substring name (match-beginning 0)))
6718        t)
6719       (bury-buffer))))
6720
6721 (defun gnus-kill-or-deaden-summary (buffer)
6722   "Kill or deaden the summary BUFFER."
6723   (save-excursion
6724     (when (and (buffer-name buffer)
6725                (not gnus-single-article-buffer))
6726       (save-excursion
6727         (set-buffer buffer)
6728         (gnus-kill-buffer gnus-article-buffer)
6729         (gnus-kill-buffer gnus-original-article-buffer)))
6730     (cond
6731      ;; Kill the buffer.
6732      (gnus-kill-summary-on-exit
6733       (when (and gnus-use-trees
6734                  (gnus-buffer-exists-p buffer))
6735         (save-excursion
6736           (set-buffer buffer)
6737           (gnus-tree-close gnus-newsgroup-name)))
6738       (gnus-kill-buffer buffer))
6739      ;; Deaden the buffer.
6740      ((gnus-buffer-exists-p buffer)
6741       (save-excursion
6742         (set-buffer buffer)
6743         (gnus-deaden-summary))))))
6744
6745 (defun gnus-summary-wake-up-the-dead (&rest args)
6746   "Wake up the dead summary buffer."
6747   (interactive)
6748   (gnus-dead-summary-mode -1)
6749   (let ((name (buffer-name)))
6750     (when (string-match "Dead " name)
6751       (rename-buffer
6752        (concat (substring name 0 (match-beginning 0))
6753                (substring name (match-end 0)))
6754        t)))
6755   (gnus-message 3 "This dead summary is now alive again"))
6756
6757 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6758 (defun gnus-summary-fetch-faq (&optional faq-dir)
6759   "Fetch the FAQ for the current group.
6760 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6761 in."
6762   (interactive
6763    (list
6764     (when current-prefix-arg
6765       (completing-read
6766        "FAQ dir: " (and (listp gnus-group-faq-directory)
6767                         (mapcar (lambda (file) (list file))
6768                                 gnus-group-faq-directory))))))
6769   (let (gnus-faq-buffer)
6770     (when (setq gnus-faq-buffer
6771                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6772       (gnus-configure-windows 'summary-faq))))
6773
6774 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6775 (defun gnus-summary-describe-group (&optional force)
6776   "Describe the current newsgroup."
6777   (interactive "P")
6778   (gnus-group-describe-group force gnus-newsgroup-name))
6779
6780 (defun gnus-summary-describe-briefly ()
6781   "Describe summary mode commands briefly."
6782   (interactive)
6783   (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")))
6784
6785 ;; Walking around group mode buffer from summary mode.
6786
6787 (defun gnus-summary-next-group (&optional no-article target-group backward)
6788   "Exit current newsgroup and then select next unread newsgroup.
6789 If prefix argument NO-ARTICLE is non-nil, no article is selected
6790 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6791 previous group instead."
6792   (interactive "P")
6793   ;; Stop pre-fetching.
6794   (gnus-async-halt-prefetch)
6795   (let ((current-group gnus-newsgroup-name)
6796         (current-buffer (current-buffer))
6797         entered)
6798     ;; First we semi-exit this group to update Xrefs and all variables.
6799     ;; We can't do a real exit, because the window conf must remain
6800     ;; the same in case the user is prompted for info, and we don't
6801     ;; want the window conf to change before that...
6802     (gnus-summary-exit t)
6803     (while (not entered)
6804       ;; Then we find what group we are supposed to enter.
6805       (set-buffer gnus-group-buffer)
6806       (gnus-group-jump-to-group current-group)
6807       (setq target-group
6808             (or target-group
6809                 (if (eq gnus-keep-same-level 'best)
6810                     (gnus-summary-best-group gnus-newsgroup-name)
6811                   (gnus-summary-search-group backward gnus-keep-same-level))))
6812       (if (not target-group)
6813           ;; There are no further groups, so we return to the group
6814           ;; buffer.
6815           (progn
6816             (gnus-message 5 "Returning to the group buffer")
6817             (setq entered t)
6818             (when (gnus-buffer-live-p current-buffer)
6819               (set-buffer current-buffer)
6820               (gnus-summary-exit))
6821             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6822         ;; We try to enter the target group.
6823         (gnus-group-jump-to-group target-group)
6824         (let ((unreads (gnus-group-group-unread)))
6825           (if (and (or (eq t unreads)
6826                        (and unreads (not (zerop unreads))))
6827                    (gnus-summary-read-group
6828                     target-group nil no-article
6829                     (and (buffer-name current-buffer) current-buffer)
6830                     nil backward))
6831               (setq entered t)
6832             (setq current-group target-group
6833                   target-group nil)))))))
6834
6835 (defun gnus-summary-prev-group (&optional no-article)
6836   "Exit current newsgroup and then select previous unread newsgroup.
6837 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6838   (interactive "P")
6839   (gnus-summary-next-group no-article nil t))
6840
6841 ;; Walking around summary lines.
6842
6843 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6844   "Go to the first subject satisfying any non-nil constraint.
6845 If UNREAD is non-nil, the article should be unread.
6846 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6847 If UNSEEN is non-nil, the article should be unseen.
6848 Returns the article selected or nil if there are no matching articles."
6849   (interactive "P")
6850   (cond
6851    ;; Empty summary.
6852    ((null gnus-newsgroup-data)
6853     (gnus-message 3 "No articles in the group")
6854     nil)
6855    ;; Pick the first article.
6856    ((not (or unread undownloaded unseen))
6857     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6858     (gnus-data-number (car gnus-newsgroup-data)))
6859    ;; Find the first unread article.
6860    (t
6861     (let ((data gnus-newsgroup-data))
6862       (while (and data
6863                   (let ((num (gnus-data-number (car data))))
6864                     (or (memq num gnus-newsgroup-unfetched)
6865                         (not (or (and unread
6866                                       (memq num gnus-newsgroup-unreads))
6867                                  (and undownloaded
6868                                       (memq num gnus-newsgroup-undownloaded))
6869                                  (and unseen
6870                                       (memq num gnus-newsgroup-unseen)))))))
6871         (setq data (cdr data)))
6872       (prog1
6873           (if data
6874               (progn
6875                 (goto-char (gnus-data-pos (car data)))
6876                 (gnus-data-number (car data)))
6877             (gnus-message 3 "No more%s articles"
6878                           (let* ((r (when unread " unread"))
6879                                  (d (when undownloaded " undownloaded"))
6880                                  (s (when unseen " unseen"))
6881                                  (l (delq nil (list r d s))))
6882                             (cond ((= 3 (length l))
6883                                    (concat r "," d ", or" s))
6884                                   ((= 2 (length l))
6885                                    (concat (car l) ", or" (cadr l)))
6886                                   ((= 1 (length l))
6887                                    (car l))
6888                                   (t
6889                                    ""))))
6890             nil
6891             )
6892         (gnus-summary-position-point))))))
6893
6894 (defun gnus-summary-next-subject (n &optional unread dont-display)
6895   "Go to next N'th summary line.
6896 If N is negative, go to the previous N'th subject line.
6897 If UNREAD is non-nil, only unread articles are selected.
6898 The difference between N and the actual number of steps taken is
6899 returned."
6900   (interactive "p")
6901   (let ((backward (< n 0))
6902         (n (abs n)))
6903     (while (and (> n 0)
6904                 (if backward
6905                     (gnus-summary-find-prev unread)
6906                   (gnus-summary-find-next unread)))
6907       (unless (zerop (setq n (1- n)))
6908         (gnus-summary-show-thread)))
6909     (when (/= 0 n)
6910       (gnus-message 7 "No more%s articles"
6911                     (if unread " unread" "")))
6912     (unless dont-display
6913       (gnus-summary-recenter)
6914       (gnus-summary-position-point))
6915     n))
6916
6917 (defun gnus-summary-next-unread-subject (n)
6918   "Go to next N'th unread summary line."
6919   (interactive "p")
6920   (gnus-summary-next-subject n t))
6921
6922 (defun gnus-summary-prev-subject (n &optional unread)
6923   "Go to previous N'th summary line.
6924 If optional argument UNREAD is non-nil, only unread article is selected."
6925   (interactive "p")
6926   (gnus-summary-next-subject (- n) unread))
6927
6928 (defun gnus-summary-prev-unread-subject (n)
6929   "Go to previous N'th unread summary line."
6930   (interactive "p")
6931   (gnus-summary-next-subject (- n) t))
6932
6933 (defun gnus-summary-goto-subjects (articles)
6934   "Insert the subject header for ARTICLES in the current buffer."
6935   (save-excursion
6936     (dolist (article articles)
6937       (gnus-summary-goto-subject article t)))
6938   (gnus-summary-limit (append articles gnus-newsgroup-limit))
6939   (gnus-summary-position-point))
6940  
6941 (defun gnus-summary-goto-subject (article &optional force silent)
6942   "Go the subject line of ARTICLE.
6943 If FORCE, also allow jumping to articles not currently shown."
6944   (interactive "nArticle number: ")
6945   (unless (numberp article)
6946     (error "Article %s is not a number" article))
6947   (let ((b (point))
6948         (data (gnus-data-find article)))
6949     ;; We read in the article if we have to.
6950     (and (not data)
6951          force
6952          (gnus-summary-insert-subject
6953           article
6954           (if (or (numberp force) (vectorp force)) force)
6955           t)
6956          (setq data (gnus-data-find article)))
6957     (goto-char b)
6958     (if (not data)
6959         (progn
6960           (unless silent
6961             (gnus-message 3 "Can't find article %d" article))
6962           nil)
6963       (let ((pt (gnus-data-pos data)))
6964         (goto-char pt)
6965         (gnus-summary-set-article-display-arrow pt))
6966       (gnus-summary-position-point)
6967       article)))
6968
6969 ;; Walking around summary lines with displaying articles.
6970
6971 (defun gnus-summary-expand-window (&optional arg)
6972   "Make the summary buffer take up the entire Emacs frame.
6973 Given a prefix, will force an `article' buffer configuration."
6974   (interactive "P")
6975   (if arg
6976       (gnus-configure-windows 'article 'force)
6977     (gnus-configure-windows 'summary 'force)))
6978
6979 (defun gnus-summary-display-article (article &optional all-header)
6980   "Display ARTICLE in article buffer."
6981   (when (gnus-buffer-live-p gnus-article-buffer)
6982     (with-current-buffer gnus-article-buffer
6983       (set-buffer-multibyte t)))
6984   (gnus-set-global-variables)
6985   (when (gnus-buffer-live-p gnus-article-buffer)
6986     (with-current-buffer gnus-article-buffer
6987       (setq gnus-article-charset gnus-newsgroup-charset)
6988       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6989       (set-buffer-multibyte t)))
6990   (if (null article)
6991       nil
6992     (prog1
6993         (if gnus-summary-display-article-function
6994             (funcall gnus-summary-display-article-function article all-header)
6995           (gnus-article-prepare article all-header))
6996       (with-current-buffer gnus-article-buffer
6997         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6998              nil))
6999       (gnus-run-hooks 'gnus-select-article-hook)
7000       (when (and gnus-current-article
7001                  (not (zerop gnus-current-article)))
7002         (gnus-summary-goto-subject gnus-current-article))
7003       (gnus-summary-recenter)
7004       (when (and gnus-use-trees gnus-show-threads)
7005         (gnus-possibly-generate-tree article)
7006         (gnus-highlight-selected-tree article))
7007       ;; Successfully display article.
7008       (gnus-article-set-window-start
7009        (cdr (assq article gnus-newsgroup-bookmarks))))))
7010
7011 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7012   "Select the current article.
7013 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7014 non-nil, the article will be re-fetched even if it already present in
7015 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7016 be displayed."
7017   ;; Make sure we are in the summary buffer to work around bbdb bug.
7018   (unless (eq major-mode 'gnus-summary-mode)
7019     (set-buffer gnus-summary-buffer))
7020   (let ((article (or article (gnus-summary-article-number)))
7021         (all-headers (not (not all-headers))) ;Must be T or NIL.
7022         gnus-summary-display-article-function)
7023     (and (not pseudo)
7024          (gnus-summary-article-pseudo-p article)
7025          (error "This is a pseudo-article"))
7026     (save-excursion
7027       (set-buffer gnus-summary-buffer)
7028       (if (or (and gnus-single-article-buffer
7029                    (or (null gnus-current-article)
7030                        (null gnus-article-current)
7031                        (null (get-buffer gnus-article-buffer))
7032                        (not (eq article (cdr gnus-article-current)))
7033                        (not (equal (car gnus-article-current)
7034                                    gnus-newsgroup-name))))
7035               (and (not gnus-single-article-buffer)
7036                    (or (null gnus-current-article)
7037                        (not (eq gnus-current-article article))))
7038               force)
7039           ;; The requested article is different from the current article.
7040           (progn
7041             (gnus-summary-display-article article all-headers)
7042             (gnus-article-set-window-start
7043              (cdr (assq article gnus-newsgroup-bookmarks)))
7044             article)
7045         'old))))
7046
7047 (defun gnus-summary-force-verify-and-decrypt ()
7048   "Display buttons for signed/encrypted parts and verify/decrypt them."
7049   (interactive)
7050   (let ((mm-verify-option 'known)
7051         (mm-decrypt-option 'known)
7052         (gnus-article-emulate-mime t)
7053         (gnus-buttonized-mime-types (append (list "multipart/signed"
7054                                                   "multipart/encrypted")
7055                                             gnus-buttonized-mime-types)))
7056     (gnus-summary-select-article nil 'force)))
7057
7058 (defun gnus-summary-set-current-mark (&optional current-mark)
7059   "Obsolete function."
7060   nil)
7061
7062 (defun gnus-summary-next-article (&optional unread subject backward push)
7063   "Select the next article.
7064 If UNREAD, only unread articles are selected.
7065 If SUBJECT, only articles with SUBJECT are selected.
7066 If BACKWARD, the previous article is selected instead of the next."
7067   (interactive "P")
7068   (cond
7069    ;; Is there such an article?
7070    ((and (gnus-summary-search-forward unread subject backward)
7071          (or (gnus-summary-display-article (gnus-summary-article-number))
7072              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7073     (gnus-summary-position-point))
7074    ;; If not, we try the first unread, if that is wanted.
7075    ((and subject
7076          gnus-auto-select-same
7077          (gnus-summary-first-unread-article))
7078     (gnus-summary-position-point)
7079     (gnus-message 6 "Wrapped"))
7080    ;; Try to get next/previous article not displayed in this group.
7081    ((and gnus-auto-extend-newsgroup
7082          (not unread) (not subject))
7083     (gnus-summary-goto-article
7084      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7085      nil (count-lines (point-min) (point))))
7086    ;; Go to next/previous group.
7087    (t
7088     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7089       (gnus-summary-jump-to-group gnus-newsgroup-name))
7090     (let ((cmd last-command-char)
7091           (point
7092            (save-excursion
7093              (set-buffer gnus-group-buffer)
7094              (point)))
7095           (group
7096            (if (eq gnus-keep-same-level 'best)
7097                (gnus-summary-best-group gnus-newsgroup-name)
7098              (gnus-summary-search-group backward gnus-keep-same-level))))
7099       ;; For some reason, the group window gets selected.  We change
7100       ;; it back.
7101       (select-window (get-buffer-window (current-buffer)))
7102       ;; Select next unread newsgroup automagically.
7103       (cond
7104        ((or (not gnus-auto-select-next)
7105             (not cmd))
7106         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7107        ((or (eq gnus-auto-select-next 'quietly)
7108             (and (eq gnus-auto-select-next 'slightly-quietly)
7109                  push)
7110             (and (eq gnus-auto-select-next 'almost-quietly)
7111                  (gnus-summary-last-article-p)))
7112         ;; Select quietly.
7113         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7114             (gnus-summary-exit)
7115           (gnus-message 7 "No more%s articles (%s)..."
7116                         (if unread " unread" "")
7117                         (if group (concat "selecting " group)
7118                           "exiting"))
7119           (gnus-summary-next-group nil group backward)))
7120        (t
7121         (when (gnus-key-press-event-p last-input-event)
7122           (gnus-summary-walk-group-buffer
7123            gnus-newsgroup-name cmd unread backward point))))))))
7124
7125 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7126   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7127                       (?\C-p (gnus-group-prev-unread-group 1))))
7128         (cursor-in-echo-area t)
7129         keve key group ended prompt)
7130     (save-excursion
7131       (set-buffer gnus-group-buffer)
7132       (goto-char start)
7133       (setq group
7134             (if (eq gnus-keep-same-level 'best)
7135                 (gnus-summary-best-group gnus-newsgroup-name)
7136               (gnus-summary-search-group backward gnus-keep-same-level))))
7137     (while (not ended)
7138       (setq prompt
7139             (format
7140              "No more%s articles%s " (if unread " unread" "")
7141              (if (and group
7142                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7143                  (format " (Type %s for %s [%s])"
7144                          (single-key-description cmd) group
7145                          (gnus-group-unread group))
7146                (format " (Type %s to exit %s)"
7147                        (single-key-description cmd)
7148                        gnus-newsgroup-name))))
7149       ;; Confirm auto selection.
7150       (setq key (car (setq keve (gnus-read-event-char prompt)))
7151             ended t)
7152       (cond
7153        ((assq key keystrokes)
7154         (let ((obuf (current-buffer)))
7155           (switch-to-buffer gnus-group-buffer)
7156           (when group
7157             (gnus-group-jump-to-group group))
7158           (eval (cadr (assq key keystrokes)))
7159           (setq group (gnus-group-group-name))
7160           (switch-to-buffer obuf))
7161         (setq ended nil))
7162        ((equal key cmd)
7163         (if (or (not group)
7164                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7165             (gnus-summary-exit)
7166           (gnus-summary-next-group nil group backward)))
7167        (t
7168         (push (cdr keve) unread-command-events))))))
7169
7170 (defun gnus-summary-next-unread-article ()
7171   "Select unread article after current one."
7172   (interactive)
7173   (gnus-summary-next-article
7174    (or (not (eq gnus-summary-goto-unread 'never))
7175        (gnus-summary-last-article-p (gnus-summary-article-number)))
7176    (and gnus-auto-select-same
7177         (gnus-summary-article-subject))))
7178
7179 (defun gnus-summary-prev-article (&optional unread subject)
7180   "Select the article after the current one.
7181 If UNREAD is non-nil, only unread articles are selected."
7182   (interactive "P")
7183   (gnus-summary-next-article unread subject t))
7184
7185 (defun gnus-summary-prev-unread-article ()
7186   "Select unread article before current one."
7187   (interactive)
7188   (gnus-summary-prev-article
7189    (or (not (eq gnus-summary-goto-unread 'never))
7190        (gnus-summary-first-article-p (gnus-summary-article-number)))
7191    (and gnus-auto-select-same
7192         (gnus-summary-article-subject))))
7193
7194 (defun gnus-summary-next-page (&optional lines circular stop)
7195   "Show next page of the selected article.
7196 If at the end of the current article, select the next article.
7197 LINES says how many lines should be scrolled up.
7198
7199 If CIRCULAR is non-nil, go to the start of the article instead of
7200 selecting the next article when reaching the end of the current
7201 article.
7202
7203 If STOP is non-nil, just stop when reaching the end of the message.
7204
7205 Also see the variable `gnus-article-skip-boring'."
7206   (interactive "P")
7207   (setq gnus-summary-buffer (current-buffer))
7208   (gnus-set-global-variables)
7209   (let ((article (gnus-summary-article-number))
7210         (article-window (get-buffer-window gnus-article-buffer t))
7211         endp)
7212     ;; If the buffer is empty, we have no article.
7213     (unless article
7214       (error "No article to select"))
7215     (gnus-configure-windows 'article)
7216     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7217         (if (and (eq gnus-summary-goto-unread 'never)
7218                  (not (gnus-summary-last-article-p article)))
7219             (gnus-summary-next-article)
7220           (gnus-summary-next-unread-article))
7221       (if (or (null gnus-current-article)
7222               (null gnus-article-current)
7223               (/= article (cdr gnus-article-current))
7224               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7225           ;; Selected subject is different from current article's.
7226           (gnus-summary-display-article article)
7227         (when article-window
7228           (gnus-eval-in-buffer-window gnus-article-buffer
7229             (setq endp (or (gnus-article-next-page lines)
7230                            (gnus-article-only-boring-p))))
7231           (when endp
7232             (cond (stop
7233                    (gnus-message 3 "End of message"))
7234                   (circular
7235                    (gnus-summary-beginning-of-article))
7236                   (lines
7237                    (gnus-message 3 "End of message"))
7238                   ((null lines)
7239                    (if (and (eq gnus-summary-goto-unread 'never)
7240                             (not (gnus-summary-last-article-p article)))
7241                        (gnus-summary-next-article)
7242                      (gnus-summary-next-unread-article))))))))
7243     (gnus-summary-recenter)
7244     (gnus-summary-position-point)))
7245
7246 (defun gnus-summary-prev-page (&optional lines move)
7247   "Show previous page of selected article.
7248 Argument LINES specifies lines to be scrolled down.
7249 If MOVE, move to the previous unread article if point is at
7250 the beginning of the buffer."
7251   (interactive "P")
7252   (let ((article (gnus-summary-article-number))
7253         (article-window (get-buffer-window gnus-article-buffer t))
7254         endp)
7255     (gnus-configure-windows 'article)
7256     (if (or (null gnus-current-article)
7257             (null gnus-article-current)
7258             (/= article (cdr gnus-article-current))
7259             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7260         ;; Selected subject is different from current article's.
7261         (gnus-summary-display-article article)
7262       (gnus-summary-recenter)
7263       (when article-window
7264         (gnus-eval-in-buffer-window gnus-article-buffer
7265           (setq endp (gnus-article-prev-page lines)))
7266         (when (and move endp)
7267           (cond (lines
7268                  (gnus-message 3 "Beginning of message"))
7269                 ((null lines)
7270                  (if (and (eq gnus-summary-goto-unread 'never)
7271                           (not (gnus-summary-first-article-p article)))
7272                      (gnus-summary-prev-article)
7273                    (gnus-summary-prev-unread-article))))))))
7274   (gnus-summary-position-point))
7275
7276 (defun gnus-summary-prev-page-or-article (&optional lines)
7277   "Show previous page of selected article.
7278 Argument LINES specifies lines to be scrolled down.
7279 If at the beginning of the article, go to the next article."
7280   (interactive "P")
7281   (gnus-summary-prev-page lines t))
7282
7283 (defun gnus-summary-scroll-up (lines)
7284   "Scroll up (or down) one line current article.
7285 Argument LINES specifies lines to be scrolled up (or down if negative)."
7286   (interactive "p")
7287   (gnus-configure-windows 'article)
7288   (gnus-summary-show-thread)
7289   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7290     (gnus-eval-in-buffer-window gnus-article-buffer
7291       (cond ((> lines 0)
7292              (when (gnus-article-next-page lines)
7293                (gnus-message 3 "End of message")))
7294             ((< lines 0)
7295              (gnus-article-prev-page (- lines))))))
7296   (gnus-summary-recenter)
7297   (gnus-summary-position-point))
7298
7299 (defun gnus-summary-scroll-down (lines)
7300   "Scroll down (or up) one line current article.
7301 Argument LINES specifies lines to be scrolled down (or up if negative)."
7302   (interactive "p")
7303   (gnus-summary-scroll-up (- lines)))
7304
7305 (defun gnus-summary-next-same-subject ()
7306   "Select next article which has the same subject as current one."
7307   (interactive)
7308   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7309
7310 (defun gnus-summary-prev-same-subject ()
7311   "Select previous article which has the same subject as current one."
7312   (interactive)
7313   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7314
7315 (defun gnus-summary-next-unread-same-subject ()
7316   "Select next unread article which has the same subject as current one."
7317   (interactive)
7318   (gnus-summary-next-article t (gnus-summary-article-subject)))
7319
7320 (defun gnus-summary-prev-unread-same-subject ()
7321   "Select previous unread article which has the same subject as current one."
7322   (interactive)
7323   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7324
7325 (defun gnus-summary-first-unread-article ()
7326   "Select the first unread article.
7327 Return nil if there are no unread articles."
7328   (interactive)
7329   (prog1
7330       (when (gnus-summary-first-subject t)
7331         (gnus-summary-show-thread)
7332         (gnus-summary-first-subject t)
7333         (gnus-summary-display-article (gnus-summary-article-number)))
7334     (gnus-summary-position-point)))
7335
7336 (defun gnus-summary-first-unread-subject ()
7337   "Place the point on the subject line of the first unread article.
7338 Return nil if there are no unread articles."
7339   (interactive)
7340   (prog1
7341       (when (gnus-summary-first-subject t)
7342         (gnus-summary-show-thread)
7343         (gnus-summary-first-subject t))
7344     (gnus-summary-position-point)))
7345
7346 (defun gnus-summary-first-unseen-subject ()
7347   "Place the point on the subject line of the first unseen article.
7348 Return nil if there are no unseen articles."
7349   (interactive)
7350   (prog1
7351       (when (gnus-summary-first-subject nil nil t)
7352         (gnus-summary-show-thread)
7353         (gnus-summary-first-subject nil nil t))
7354     (gnus-summary-position-point)))
7355
7356 (defun gnus-summary-first-unseen-or-unread-subject ()
7357   "Place the point on the subject line of the first unseen article or,
7358 if all article have been seen, on the subject line of the first unread
7359 article."
7360   (interactive)
7361   (prog1
7362       (unless (when (gnus-summary-first-subject nil nil t)
7363                 (gnus-summary-show-thread)
7364                 (gnus-summary-first-subject nil nil t))
7365         (when (gnus-summary-first-subject t)
7366           (gnus-summary-show-thread)
7367           (gnus-summary-first-subject t)))
7368     (gnus-summary-position-point)))
7369
7370 (defun gnus-summary-first-article ()
7371   "Select the first article.
7372 Return nil if there are no articles."
7373   (interactive)
7374   (prog1
7375       (when (gnus-summary-first-subject)
7376         (gnus-summary-show-thread)
7377         (gnus-summary-first-subject)
7378         (gnus-summary-display-article (gnus-summary-article-number)))
7379     (gnus-summary-position-point)))
7380
7381 (defun gnus-summary-best-unread-article (&optional arg)
7382   "Select the unread article with the highest score.
7383 If given a prefix argument, select the next unread article that has a
7384 score higher than the default score."
7385   (interactive "P")
7386   (let ((article (if arg
7387                      (gnus-summary-better-unread-subject)
7388                    (gnus-summary-best-unread-subject))))
7389     (if article
7390         (gnus-summary-goto-article article)
7391       (error "No unread articles"))))
7392
7393 (defun gnus-summary-best-unread-subject ()
7394   "Select the unread subject with the highest score."
7395   (interactive)
7396   (let ((best -1000000)
7397         (data gnus-newsgroup-data)
7398         article score)
7399     (while data
7400       (and (gnus-data-unread-p (car data))
7401            (> (setq score
7402                     (gnus-summary-article-score (gnus-data-number (car data))))
7403               best)
7404            (setq best score
7405                  article (gnus-data-number (car data))))
7406       (setq data (cdr data)))
7407     (when article
7408       (gnus-summary-goto-subject article))
7409     (gnus-summary-position-point)
7410     article))
7411
7412 (defun gnus-summary-better-unread-subject ()
7413   "Select the first unread subject that has a score over the default score."
7414   (interactive)
7415   (let ((data gnus-newsgroup-data)
7416         article score)
7417     (while (and (setq article (gnus-data-number (car data)))
7418                 (or (gnus-data-read-p (car data))
7419                     (not (> (gnus-summary-article-score article)
7420                             gnus-summary-default-score))))
7421       (setq data (cdr data)))
7422     (when article
7423       (gnus-summary-goto-subject article))
7424     (gnus-summary-position-point)
7425     article))
7426
7427 (defun gnus-summary-last-subject ()
7428   "Go to the last displayed subject line in the group."
7429   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7430     (when article
7431       (gnus-summary-goto-subject article))))
7432
7433 (defun gnus-summary-goto-article (article &optional all-headers force)
7434   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7435 If ALL-HEADERS is non-nil, no header lines are hidden.
7436 If FORCE, go to the article even if it isn't displayed.  If FORCE
7437 is a number, it is the line the article is to be displayed on."
7438   (interactive
7439    (list
7440     (completing-read
7441      "Article number or Message-ID: "
7442      (mapcar (lambda (number) (list (int-to-string number)))
7443              gnus-newsgroup-limit))
7444     current-prefix-arg
7445     t))
7446   (prog1
7447       (if (and (stringp article)
7448                (string-match "@\\|%40" article))
7449           (gnus-summary-refer-article article)
7450         (when (stringp article)
7451           (setq article (string-to-number article)))
7452         (if (gnus-summary-goto-subject article force)
7453             (gnus-summary-display-article article all-headers)
7454           (gnus-message 4 "Couldn't go to article %s" article) nil))
7455     (gnus-summary-position-point)))
7456
7457 (defun gnus-summary-goto-last-article ()
7458   "Go to the previously read article."
7459   (interactive)
7460   (prog1
7461       (when gnus-last-article
7462         (gnus-summary-goto-article gnus-last-article nil t))
7463     (gnus-summary-position-point)))
7464
7465 (defun gnus-summary-pop-article (number)
7466   "Pop one article off the history and go to the previous.
7467 NUMBER articles will be popped off."
7468   (interactive "p")
7469   (let (to)
7470     (setq gnus-newsgroup-history
7471           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7472     (if to
7473         (gnus-summary-goto-article (car to) nil t)
7474       (error "Article history empty")))
7475   (gnus-summary-position-point))
7476
7477 ;; Summary commands and functions for limiting the summary buffer.
7478
7479 (defun gnus-summary-limit-to-articles (n)
7480   "Limit the summary buffer to the next N articles.
7481 If not given a prefix, use the process marked articles instead."
7482   (interactive "P")
7483   (prog1
7484       (let ((articles (gnus-summary-work-articles n)))
7485         (setq gnus-newsgroup-processable nil)
7486         (gnus-summary-limit articles))
7487     (gnus-summary-position-point)))
7488
7489 (defun gnus-summary-pop-limit (&optional total)
7490   "Restore the previous limit.
7491 If given a prefix, remove all limits."
7492   (interactive "P")
7493   (when total
7494     (setq gnus-newsgroup-limits
7495           (list (mapcar (lambda (h) (mail-header-number h))
7496                         gnus-newsgroup-headers))))
7497   (unless gnus-newsgroup-limits
7498     (error "No limit to pop"))
7499   (prog1
7500       (gnus-summary-limit nil 'pop)
7501     (gnus-summary-position-point)))
7502
7503 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7504   "Limit the summary buffer to articles that have subjects that match a regexp.
7505 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7506   (interactive
7507    (list (read-string (if current-prefix-arg
7508                           "Exclude subject (regexp): "
7509                         "Limit to subject (regexp): "))
7510          nil current-prefix-arg))
7511   (unless header
7512     (setq header "subject"))
7513   (when (not (equal "" subject))
7514     (prog1
7515         (let ((articles (gnus-summary-find-matching
7516                          (or header "subject") subject 'all nil nil
7517                          not-matching)))
7518           (unless articles
7519             (error "Found no matches for \"%s\"" subject))
7520           (gnus-summary-limit articles))
7521       (gnus-summary-position-point))))
7522
7523 (defun gnus-summary-limit-to-author (from &optional not-matching)
7524   "Limit the summary buffer to articles that have authors that match a regexp.
7525 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7526   (interactive
7527    (list (read-string (if current-prefix-arg
7528                           "Exclude author (regexp): "
7529                         "Limit to author (regexp): "))
7530          current-prefix-arg))
7531   (gnus-summary-limit-to-subject from "from" not-matching))
7532
7533 (defun gnus-summary-limit-to-age (age &optional younger-p)
7534   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7535 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7536 articles that are younger than AGE days."
7537   (interactive
7538    (let ((younger current-prefix-arg)
7539          (days-got nil)
7540          days)
7541      (while (not days-got)
7542        (setq days (if younger
7543                       (read-string "Limit to articles younger than (in days, older when negative): ")
7544                     (read-string
7545                      "Limit to articles older than (in days, younger when negative): ")))
7546        (when (> (length days) 0)
7547          (setq days (read days)))
7548        (if (numberp days)
7549            (progn
7550              (setq days-got t)
7551              (if (< days 0)
7552                  (progn
7553                    (setq younger (not younger))
7554                    (setq days (* days -1)))))
7555          (message "Please enter a number.")
7556          (sleep-for 1)))
7557      (list days younger)))
7558   (prog1
7559       (let ((data gnus-newsgroup-data)
7560             (cutoff (days-to-time age))
7561             articles d date is-younger)
7562         (while (setq d (pop data))
7563           (when (and (vectorp (gnus-data-header d))
7564                      (setq date (mail-header-date (gnus-data-header d))))
7565             (setq is-younger (time-less-p
7566                               (time-since (condition-case ()
7567                                               (date-to-time date)
7568                                             (error '(0 0))))
7569                               cutoff))
7570             (when (if younger-p
7571                       is-younger
7572                     (not is-younger))
7573               (push (gnus-data-number d) articles))))
7574         (gnus-summary-limit (nreverse articles)))
7575     (gnus-summary-position-point)))
7576
7577 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7578   "Limit the summary buffer to articles that match an 'extra' header."
7579   (interactive
7580    (let ((header
7581           (intern
7582            (gnus-completing-read-with-default
7583             (symbol-name (car gnus-extra-headers))
7584             (if current-prefix-arg
7585                 "Exclude extra header:"
7586               "Limit extra header:")
7587             (mapcar (lambda (x)
7588                       (cons (symbol-name x) x))
7589                     gnus-extra-headers)
7590             nil
7591             t))))
7592      (list header
7593            (read-string (format "%s header %s (regexp): "
7594                                 (if current-prefix-arg "Exclude" "Limit to")
7595                                 header))
7596            current-prefix-arg)))
7597   (when (not (equal "" regexp))
7598     (prog1
7599         (let ((articles (gnus-summary-find-matching
7600                          (cons 'extra header) regexp 'all nil nil
7601                          not-matching)))
7602           (unless articles
7603             (error "Found no matches for \"%s\"" regexp))
7604           (gnus-summary-limit articles))
7605       (gnus-summary-position-point))))
7606
7607 (defun gnus-summary-limit-to-display-predicate ()
7608   "Limit the summary buffer to the predicated in the `display' group parameter."
7609   (interactive)
7610   (unless gnus-newsgroup-display
7611     (error "There is no `display' group parameter"))
7612   (let (articles)
7613     (dolist (number gnus-newsgroup-articles)
7614       (when (funcall gnus-newsgroup-display)
7615         (push number articles)))
7616     (gnus-summary-limit articles))
7617   (gnus-summary-position-point))
7618
7619 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7620 (make-obsolete
7621  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7622
7623 (defun gnus-summary-limit-to-unread (&optional all)
7624   "Limit the summary buffer to articles that are not marked as read.
7625 If ALL is non-nil, limit strictly to unread articles."
7626   (interactive "P")
7627   (if all
7628       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7629     (gnus-summary-limit-to-marks
7630      ;; Concat all the marks that say that an article is read and have
7631      ;; those removed.
7632      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7633            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7634            gnus-low-score-mark gnus-expirable-mark
7635            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7636            gnus-duplicate-mark gnus-souped-mark)
7637      'reverse)))
7638
7639 (defun gnus-summary-limit-to-replied (&optional unreplied)
7640   "Limit the summary buffer to replied articles.
7641 If UNREPLIED (the prefix), limit to unreplied articles."
7642   (interactive "P")
7643   (if unreplied
7644       (gnus-summary-limit
7645        (gnus-set-difference gnus-newsgroup-articles
7646         gnus-newsgroup-replied))
7647     (gnus-summary-limit gnus-newsgroup-replied))
7648   (gnus-summary-position-point))
7649
7650 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7651 (make-obsolete 'gnus-summary-delete-marked-with
7652                'gnus-summary-limit-exclude-marks)
7653
7654 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7655   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7656 If REVERSE, limit the summary buffer to articles that are marked
7657 with MARKS.  MARKS can either be a string of marks or a list of marks.
7658 Returns how many articles were removed."
7659   (interactive "sMarks: ")
7660   (gnus-summary-limit-to-marks marks t))
7661
7662 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7663   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7664 If REVERSE (the prefix), limit the summary buffer to articles that are
7665 not marked with MARKS.  MARKS can either be a string of marks or a
7666 list of marks.
7667 Returns how many articles were removed."
7668   (interactive "sMarks: \nP")
7669   (prog1
7670       (let ((data gnus-newsgroup-data)
7671             (marks (if (listp marks) marks
7672                      (append marks nil))) ; Transform to list.
7673             articles)
7674         (while data
7675           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7676                   (memq (gnus-data-mark (car data)) marks))
7677             (push (gnus-data-number (car data)) articles))
7678           (setq data (cdr data)))
7679         (gnus-summary-limit articles))
7680     (gnus-summary-position-point)))
7681
7682 (defun gnus-summary-limit-to-score (score)
7683   "Limit to articles with score at or above SCORE."
7684   (interactive "NLimit to articles with score of at least: ")
7685   (let ((data gnus-newsgroup-data)
7686         articles)
7687     (while data
7688       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7689                 score)
7690         (push (gnus-data-number (car data)) articles))
7691       (setq data (cdr data)))
7692     (prog1
7693         (gnus-summary-limit articles)
7694       (gnus-summary-position-point))))
7695
7696 (defun gnus-summary-limit-to-unseen ()
7697   "Limit to unseen articles."
7698   (interactive)
7699   (prog1
7700       (gnus-summary-limit gnus-newsgroup-unseen)
7701     (gnus-summary-position-point)))
7702
7703 (defun gnus-summary-limit-include-thread (id)
7704   "Display all the hidden articles that is in the thread with ID in it.
7705 When called interactively, ID is the Message-ID of the current
7706 article."
7707   (interactive (list (mail-header-id (gnus-summary-article-header))))
7708   (let ((articles (gnus-articles-in-thread
7709                    (gnus-id-to-thread (gnus-root-id id)))))
7710     (prog1
7711         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7712       (gnus-summary-limit-include-matching-articles
7713        "subject"
7714        (regexp-quote (gnus-simplify-subject-re
7715                       (mail-header-subject (gnus-id-to-header id)))))
7716       (gnus-summary-position-point))))
7717
7718 (defun gnus-summary-limit-include-matching-articles (header regexp)
7719   "Display all the hidden articles that have HEADERs that match REGEXP."
7720   (interactive (list (read-string "Match on header: ")
7721                      (read-string "Regexp: ")))
7722   (let ((articles (gnus-find-matching-articles header regexp)))
7723     (prog1
7724         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7725       (gnus-summary-position-point))))
7726
7727 (defun gnus-summary-insert-dormant-articles ()
7728   "Insert all the dormant articles for this group into the current buffer."
7729   (interactive)
7730   (let ((gnus-verbose (max 6 gnus-verbose)))
7731     (if (not gnus-newsgroup-dormant)
7732         (gnus-message 3 "No cached articles for this group")
7733       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7734
7735 (defun gnus-summary-limit-include-dormant ()
7736   "Display all the hidden articles that are marked as dormant.
7737 Note that this command only works on a subset of the articles currently
7738 fetched for this group."
7739   (interactive)
7740   (unless gnus-newsgroup-dormant
7741     (error "There are no dormant articles in this group"))
7742   (prog1
7743       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7744     (gnus-summary-position-point)))
7745
7746 (defun gnus-summary-limit-exclude-dormant ()
7747   "Hide all dormant articles."
7748   (interactive)
7749   (prog1
7750       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7751     (gnus-summary-position-point)))
7752
7753 (defun gnus-summary-limit-exclude-childless-dormant ()
7754   "Hide all dormant articles that have no children."
7755   (interactive)
7756   (let ((data (gnus-data-list t))
7757         articles d children)
7758     ;; Find all articles that are either not dormant or have
7759     ;; children.
7760     (while (setq d (pop data))
7761       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7762                 (and (setq children
7763                            (gnus-article-children (gnus-data-number d)))
7764                      (let (found)
7765                        (while children
7766                          (when (memq (car children) articles)
7767                            (setq children nil
7768                                  found t))
7769                          (pop children))
7770                        found)))
7771         (push (gnus-data-number d) articles)))
7772     ;; Do the limiting.
7773     (prog1
7774         (gnus-summary-limit articles)
7775       (gnus-summary-position-point))))
7776
7777 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7778   "Mark all unread excluded articles as read.
7779 If ALL, mark even excluded ticked and dormants as read."
7780   (interactive "P")
7781   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7782   (let ((articles (gnus-sorted-ndifference
7783                    (sort
7784                     (mapcar (lambda (h) (mail-header-number h))
7785                             gnus-newsgroup-headers)
7786                     '<)
7787                    gnus-newsgroup-limit))
7788         article)
7789     (setq gnus-newsgroup-unreads
7790           (gnus-sorted-intersection gnus-newsgroup-unreads
7791                                     gnus-newsgroup-limit))
7792     (if all
7793         (setq gnus-newsgroup-dormant nil
7794               gnus-newsgroup-marked nil
7795               gnus-newsgroup-reads
7796               (nconc
7797                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7798                gnus-newsgroup-reads))
7799       (while (setq article (pop articles))
7800         (unless (or (memq article gnus-newsgroup-dormant)
7801                     (memq article gnus-newsgroup-marked))
7802           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7803
7804 (defun gnus-summary-limit (articles &optional pop)
7805   (if pop
7806       ;; We pop the previous limit off the stack and use that.
7807       (setq articles (car gnus-newsgroup-limits)
7808             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7809     ;; We use the new limit, so we push the old limit on the stack.
7810     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7811   ;; Set the limit.
7812   (setq gnus-newsgroup-limit articles)
7813   (let ((total (length gnus-newsgroup-data))
7814         (data (gnus-data-find-list (gnus-summary-article-number)))
7815         (gnus-summary-mark-below nil)   ; Inhibit this.
7816         found)
7817     ;; This will do all the work of generating the new summary buffer
7818     ;; according to the new limit.
7819     (gnus-summary-prepare)
7820     ;; Hide any threads, possibly.
7821     (gnus-summary-maybe-hide-threads)
7822     ;; Try to return to the article you were at, or one in the
7823     ;; neighborhood.
7824     (when data
7825       ;; We try to find some article after the current one.
7826       (while data
7827         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7828           (setq data nil
7829                 found t))
7830         (setq data (cdr data))))
7831     (unless found
7832       ;; If there is no data, that means that we were after the last
7833       ;; article.  The same goes when we can't find any articles
7834       ;; after the current one.
7835       (goto-char (point-max))
7836       (gnus-summary-find-prev))
7837     (gnus-set-mode-line 'summary)
7838     ;; We return how many articles were removed from the summary
7839     ;; buffer as a result of the new limit.
7840     (- total (length gnus-newsgroup-data))))
7841
7842 (defsubst gnus-invisible-cut-children (threads)
7843   (let ((num 0))
7844     (while threads
7845       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7846         (incf num))
7847       (pop threads))
7848     (< num 2)))
7849
7850 (defsubst gnus-cut-thread (thread)
7851   "Go forwards in the thread until we find an article that we want to display."
7852   (when (or (eq gnus-fetch-old-headers 'some)
7853             (eq gnus-fetch-old-headers 'invisible)
7854             (numberp gnus-fetch-old-headers)
7855             (eq gnus-build-sparse-threads 'some)
7856             (eq gnus-build-sparse-threads 'more))
7857     ;; Deal with old-fetched headers and sparse threads.
7858     (while (and
7859             thread
7860             (or
7861              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7862              (gnus-summary-article-ancient-p
7863               (mail-header-number (car thread))))
7864             (if (or (<= (length (cdr thread)) 1)
7865                     (eq gnus-fetch-old-headers 'invisible))
7866                 (setq gnus-newsgroup-limit
7867                       (delq (mail-header-number (car thread))
7868                             gnus-newsgroup-limit)
7869                       thread (cadr thread))
7870               (when (gnus-invisible-cut-children (cdr thread))
7871                 (let ((th (cdr thread)))
7872                   (while th
7873                     (if (memq (mail-header-number (caar th))
7874                               gnus-newsgroup-limit)
7875                         (setq thread (car th)
7876                               th nil)
7877                       (setq th (cdr th))))))))))
7878   thread)
7879
7880 (defun gnus-cut-threads (threads)
7881   "Cut off all uninteresting articles from the beginning of THREADS."
7882   (when (or (eq gnus-fetch-old-headers 'some)
7883             (eq gnus-fetch-old-headers 'invisible)
7884             (numberp gnus-fetch-old-headers)
7885             (eq gnus-build-sparse-threads 'some)
7886             (eq gnus-build-sparse-threads 'more))
7887     (let ((th threads))
7888       (while th
7889         (setcar th (gnus-cut-thread (car th)))
7890         (setq th (cdr th)))))
7891   ;; Remove nixed out threads.
7892   (delq nil threads))
7893
7894 (defun gnus-summary-initial-limit (&optional show-if-empty)
7895   "Figure out what the initial limit is supposed to be on group entry.
7896 This entails weeding out unwanted dormants, low-scored articles,
7897 fetch-old-headers verbiage, and so on."
7898   ;; Most groups have nothing to remove.
7899   (if (or gnus-inhibit-limiting
7900           (and (null gnus-newsgroup-dormant)
7901                (eq gnus-newsgroup-display 'gnus-not-ignore)
7902                (not (eq gnus-fetch-old-headers 'some))
7903                (not (numberp gnus-fetch-old-headers))
7904                (not (eq gnus-fetch-old-headers 'invisible))
7905                (null gnus-summary-expunge-below)
7906                (not (eq gnus-build-sparse-threads 'some))
7907                (not (eq gnus-build-sparse-threads 'more))
7908                (null gnus-thread-expunge-below)
7909                (not gnus-use-nocem)))
7910       ()                                ; Do nothing.
7911     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7912     (setq gnus-newsgroup-limit nil)
7913     (mapatoms
7914      (lambda (node)
7915        (unless (car (symbol-value node))
7916          ;; These threads have no parents -- they are roots.
7917          (let ((nodes (cdr (symbol-value node)))
7918                thread)
7919            (while nodes
7920              (if (and gnus-thread-expunge-below
7921                       (< (gnus-thread-total-score (car nodes))
7922                          gnus-thread-expunge-below))
7923                  (gnus-expunge-thread (pop nodes))
7924                (setq thread (pop nodes))
7925                (gnus-summary-limit-children thread))))))
7926      gnus-newsgroup-dependencies)
7927     ;; If this limitation resulted in an empty group, we might
7928     ;; pop the previous limit and use it instead.
7929     (when (and (not gnus-newsgroup-limit)
7930                show-if-empty)
7931       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7932     gnus-newsgroup-limit))
7933
7934 (defun gnus-summary-limit-children (thread)
7935   "Return 1 if this subthread is visible and 0 if it is not."
7936   ;; First we get the number of visible children to this thread.  This
7937   ;; is done by recursing down the thread using this function, so this
7938   ;; will really go down to a leaf article first, before slowly
7939   ;; working its way up towards the root.
7940   (when thread
7941     (let* ((max-lisp-eval-depth 5000)
7942            (children
7943            (if (cdr thread)
7944                (apply '+ (mapcar 'gnus-summary-limit-children
7945                                  (cdr thread)))
7946              0))
7947           (number (mail-header-number (car thread)))
7948           score)
7949       (if (and
7950            (not (memq number gnus-newsgroup-marked))
7951            (or
7952             ;; If this article is dormant and has absolutely no visible
7953             ;; children, then this article isn't visible.
7954             (and (memq number gnus-newsgroup-dormant)
7955                  (zerop children))
7956             ;; If this is "fetch-old-headered" and there is no
7957             ;; visible children, then we don't want this article.
7958             (and (or (eq gnus-fetch-old-headers 'some)
7959                      (numberp gnus-fetch-old-headers))
7960                  (gnus-summary-article-ancient-p number)
7961                  (zerop children))
7962             ;; If this is "fetch-old-headered" and `invisible', then
7963             ;; we don't want this article.
7964             (and (eq gnus-fetch-old-headers 'invisible)
7965                  (gnus-summary-article-ancient-p number))
7966             ;; If this is a sparsely inserted article with no children,
7967             ;; we don't want it.
7968             (and (eq gnus-build-sparse-threads 'some)
7969                  (gnus-summary-article-sparse-p number)
7970                  (zerop children))
7971             ;; If we use expunging, and this article is really
7972             ;; low-scored, then we don't want this article.
7973             (when (and gnus-summary-expunge-below
7974                        (< (setq score
7975                                 (or (cdr (assq number gnus-newsgroup-scored))
7976                                     gnus-summary-default-score))
7977                           gnus-summary-expunge-below))
7978               ;; We increase the expunge-tally here, but that has
7979               ;; nothing to do with the limits, really.
7980               (incf gnus-newsgroup-expunged-tally)
7981               ;; We also mark as read here, if that's wanted.
7982               (when (and gnus-summary-mark-below
7983                          (< score gnus-summary-mark-below))
7984                 (setq gnus-newsgroup-unreads
7985                       (delq number gnus-newsgroup-unreads))
7986                 (if gnus-newsgroup-auto-expire
7987                     (push number gnus-newsgroup-expirable)
7988                   (push (cons number gnus-low-score-mark)
7989                         gnus-newsgroup-reads)))
7990               t)
7991             ;; Do the `display' group parameter.
7992             (and gnus-newsgroup-display
7993                  (not (funcall gnus-newsgroup-display)))
7994             ;; Check NoCeM things.
7995             (if (and gnus-use-nocem
7996                      (gnus-nocem-unwanted-article-p
7997                       (mail-header-id (car thread))))
7998                 (progn
7999                   (setq gnus-newsgroup-unreads
8000                         (delq number gnus-newsgroup-unreads))
8001                   t))))
8002           ;; Nope, invisible article.
8003           0
8004         ;; Ok, this article is to be visible, so we add it to the limit
8005         ;; and return 1.
8006         (push number gnus-newsgroup-limit)
8007         1))))
8008
8009 (defun gnus-expunge-thread (thread)
8010   "Mark all articles in THREAD as read."
8011   (let* ((number (mail-header-number (car thread))))
8012     (incf gnus-newsgroup-expunged-tally)
8013     ;; We also mark as read here, if that's wanted.
8014     (setq gnus-newsgroup-unreads
8015           (delq number gnus-newsgroup-unreads))
8016     (if gnus-newsgroup-auto-expire
8017         (push number gnus-newsgroup-expirable)
8018       (push (cons number gnus-low-score-mark)
8019             gnus-newsgroup-reads)))
8020   ;; Go recursively through all subthreads.
8021   (mapcar 'gnus-expunge-thread (cdr thread)))
8022
8023 ;; Summary article oriented commands
8024
8025 (defun gnus-summary-refer-parent-article (n)
8026   "Refer parent article N times.
8027 If N is negative, go to ancestor -N instead.
8028 The difference between N and the number of articles fetched is returned."
8029   (interactive "p")
8030   (let ((skip 1)
8031         error header ref)
8032     (when (not (natnump n))
8033       (setq skip (abs n)
8034             n 1))
8035     (while (and (> n 0)
8036                 (not error))
8037       (setq header (gnus-summary-article-header))
8038       (if (and (eq (mail-header-number header)
8039                    (cdr gnus-article-current))
8040                (equal gnus-newsgroup-name
8041                       (car gnus-article-current)))
8042           ;; If we try to find the parent of the currently
8043           ;; displayed article, then we take a look at the actual
8044           ;; References header, since this is slightly more
8045           ;; reliable than the References field we got from the
8046           ;; server.
8047           (save-excursion
8048             (set-buffer gnus-original-article-buffer)
8049             (nnheader-narrow-to-headers)
8050             (unless (setq ref (message-fetch-field "references"))
8051               (when (setq ref (message-fetch-field "in-reply-to"))
8052                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8053             (widen))
8054         (setq ref
8055               ;; It's not the current article, so we take a bet on
8056               ;; the value we got from the server.
8057               (mail-header-references header)))
8058       (if (and ref
8059                (not (equal ref "")))
8060           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8061             (gnus-message 1 "Couldn't find parent"))
8062         (gnus-message 1 "No references in article %d"
8063                       (gnus-summary-article-number))
8064         (setq error t))
8065       (decf n))
8066     (gnus-summary-position-point)
8067     n))
8068
8069 (defun gnus-summary-refer-references ()
8070   "Fetch all articles mentioned in the References header.
8071 Return the number of articles fetched."
8072   (interactive)
8073   (let ((ref (mail-header-references (gnus-summary-article-header)))
8074         (current (gnus-summary-article-number))
8075         (n 0))
8076     (if (or (not ref)
8077             (equal ref ""))
8078         (error "No References in the current article")
8079       ;; For each Message-ID in the References header...
8080       (while (string-match "<[^>]*>" ref)
8081         (incf n)
8082         ;; ... fetch that article.
8083         (gnus-summary-refer-article
8084          (prog1 (match-string 0 ref)
8085            (setq ref (substring ref (match-end 0))))))
8086       (gnus-summary-goto-subject current)
8087       (gnus-summary-position-point)
8088       n)))
8089
8090 (defun gnus-summary-refer-thread (&optional limit)
8091   "Fetch all articles in the current thread.
8092 If LIMIT (the numerical prefix), fetch that many old headers instead
8093 of what's specified by the `gnus-refer-thread-limit' variable."
8094   (interactive "P")
8095   (let ((id (mail-header-id (gnus-summary-article-header)))
8096         (limit (if limit (prefix-numeric-value limit)
8097                  gnus-refer-thread-limit)))
8098     (unless (eq gnus-fetch-old-headers 'invisible)
8099       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8100       ;; Retrieve the headers and read them in.
8101       (if (eq (if (numberp limit)
8102                   (gnus-retrieve-headers
8103                    (list (min
8104                           (+ (mail-header-number
8105                               (gnus-summary-article-header))
8106                              limit)
8107                           gnus-newsgroup-end))
8108                    gnus-newsgroup-name (* limit 2))
8109                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8110                 ;; headers.
8111                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8112                                        gnus-newsgroup-name limit))
8113               'nov)
8114           (gnus-build-all-threads)
8115         (error "Can't fetch thread from back ends that don't support NOV"))
8116       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8117     (gnus-summary-limit-include-thread id)))
8118
8119 (defun gnus-summary-refer-article (message-id)
8120   "Fetch an article specified by MESSAGE-ID."
8121   (interactive "sMessage-ID: ")
8122   (when (and (stringp message-id)
8123              (not (zerop (length message-id))))
8124     (setq message-id (gnus-replace-in-string message-id " " ""))
8125     ;; Construct the correct Message-ID if necessary.
8126     ;; Suggested by tale@pawl.rpi.edu.
8127     (unless (string-match "^<" message-id)
8128       (setq message-id (concat "<" message-id)))
8129     (unless (string-match ">$" message-id)
8130       (setq message-id (concat message-id ">")))
8131     ;; People often post MIDs from URLs, so unhex it:
8132     (unless (string-match "@" message-id)
8133       (setq message-id (gnus-url-unhex-string message-id)))
8134     (let* ((header (gnus-id-to-header message-id))
8135            (sparse (and header
8136                         (gnus-summary-article-sparse-p
8137                          (mail-header-number header))
8138                         (memq (mail-header-number header)
8139                               gnus-newsgroup-limit)))
8140            number)
8141       (cond
8142        ;; If the article is present in the buffer we just go to it.
8143        ((and header
8144              (or (not (gnus-summary-article-sparse-p
8145                        (mail-header-number header)))
8146                  sparse))
8147         (prog1
8148             (gnus-summary-goto-article
8149              (mail-header-number header) nil t)
8150           (when sparse
8151             (gnus-summary-update-article (mail-header-number header)))))
8152        (t
8153         ;; We fetch the article.
8154         (catch 'found
8155           (dolist (gnus-override-method (gnus-refer-article-methods))
8156             (when (and (gnus-check-server gnus-override-method)
8157                        ;; Fetch the header,
8158                        (setq number (gnus-summary-insert-subject message-id)))
8159               ;; and display the article.
8160               (gnus-summary-select-article nil nil nil number)
8161               (throw 'found t)))
8162           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8163
8164 (defun gnus-refer-article-methods ()
8165   "Return a list of referable methods."
8166   (cond
8167    ;; No method, so we default to current and native.
8168    ((null gnus-refer-article-method)
8169     (list gnus-current-select-method gnus-select-method))
8170    ;; Current.
8171    ((eq 'current gnus-refer-article-method)
8172     (list gnus-current-select-method))
8173    ;; List of select methods.
8174    ((not (and (symbolp (car gnus-refer-article-method))
8175               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8176     (let (out)
8177       (dolist (method gnus-refer-article-method)
8178         (push (if (eq 'current method)
8179                   gnus-current-select-method
8180                 method)
8181               out))
8182       (nreverse out)))
8183    ;; One single select method.
8184    (t
8185     (list gnus-refer-article-method))))
8186
8187 (defun gnus-summary-edit-parameters ()
8188   "Edit the group parameters of the current group."
8189   (interactive)
8190   (gnus-group-edit-group gnus-newsgroup-name 'params))
8191
8192 (defun gnus-summary-customize-parameters ()
8193   "Customize the group parameters of the current group."
8194   (interactive)
8195   (gnus-group-customize gnus-newsgroup-name))
8196
8197 (defun gnus-summary-enter-digest-group (&optional force)
8198   "Enter an nndoc group based on the current article.
8199 If FORCE, force a digest interpretation.  If not, try
8200 to guess what the document format is."
8201   (interactive "P")
8202   (let ((conf gnus-current-window-configuration))
8203     (save-window-excursion
8204       (save-excursion
8205         (let (gnus-article-prepare-hook
8206               gnus-display-mime-function
8207               gnus-break-pages)
8208           (gnus-summary-select-article))))
8209     (setq gnus-current-window-configuration conf)
8210     (let* ((name (format "%s-%d"
8211                          (gnus-group-prefixed-name
8212                           gnus-newsgroup-name (list 'nndoc ""))
8213                          (save-excursion
8214                            (set-buffer gnus-summary-buffer)
8215                            gnus-current-article)))
8216            (ogroup gnus-newsgroup-name)
8217            (params (append (gnus-info-params (gnus-get-info ogroup))
8218                            (list (cons 'to-group ogroup))
8219                            (list (cons 'parent-group ogroup))
8220                            (list (cons 'save-article-group ogroup))))
8221            (case-fold-search t)
8222            (buf (current-buffer))
8223            dig to-address)
8224       (save-excursion
8225         (set-buffer gnus-original-article-buffer)
8226         ;; Have the digest group inherit the main mail address of
8227         ;; the parent article.
8228         (when (setq to-address (or (gnus-fetch-field "reply-to")
8229                                    (gnus-fetch-field "from")))
8230           (setq params (append
8231                         (list (cons 'to-address
8232                                     (funcall gnus-decode-encoded-word-function
8233                                              to-address))))))
8234         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8235         (insert-buffer-substring gnus-original-article-buffer)
8236         ;; Remove lines that may lead nndoc to misinterpret the
8237         ;; document type.
8238         (narrow-to-region
8239          (goto-char (point-min))
8240          (or (search-forward "\n\n" nil t) (point)))
8241         (goto-char (point-min))
8242         (delete-matching-lines "^Path:\\|^From ")
8243         (widen))
8244       (unwind-protect
8245           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8246                     (gnus-newsgroup-ephemeral-ignored-charsets
8247                      gnus-newsgroup-ignored-charsets))
8248                 (gnus-group-read-ephemeral-group
8249                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8250                               (nndoc-article-type
8251                                ,(if force 'mbox 'guess)))
8252                  t nil nil nil
8253                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8254                                                         "ADAPT")))))
8255               ;; Make all postings to this group go to the parent group.
8256               (nconc (gnus-info-params (gnus-get-info name))
8257                      params)
8258             ;; Couldn't select this doc group.
8259             (switch-to-buffer buf)
8260             (gnus-set-global-variables)
8261             (gnus-configure-windows 'summary)
8262             (gnus-message 3 "Article couldn't be entered?"))
8263         (kill-buffer dig)))))
8264
8265 (defun gnus-summary-read-document (n)
8266   "Open a new group based on the current article(s).
8267 This will allow you to read digests and other similar
8268 documents as newsgroups.
8269 Obeys the standard process/prefix convention."
8270   (interactive "P")
8271   (let* ((articles (gnus-summary-work-articles n))
8272          (ogroup gnus-newsgroup-name)
8273          (params (append (gnus-info-params (gnus-get-info ogroup))
8274                          (list (cons 'to-group ogroup))))
8275          article group egroup groups vgroup)
8276     (while (setq article (pop articles))
8277       (setq group (format "%s-%d" gnus-newsgroup-name article))
8278       (gnus-summary-remove-process-mark article)
8279       (when (gnus-summary-display-article article)
8280         (save-excursion
8281           (with-temp-buffer
8282             (insert-buffer-substring gnus-original-article-buffer)
8283             ;; Remove some headers that may lead nndoc to make
8284             ;; the wrong guess.
8285             (message-narrow-to-head)
8286             (goto-char (point-min))
8287             (delete-matching-lines "^Path:\\|^From ")
8288             (widen)
8289             (if (setq egroup
8290                       (gnus-group-read-ephemeral-group
8291                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8292                                      (nndoc-article-type guess))
8293                        t nil t))
8294                 (progn
8295                   ;; Make all postings to this group go to the parent group.
8296                   (nconc (gnus-info-params (gnus-get-info egroup))
8297                          params)
8298                   (push egroup groups))
8299               ;; Couldn't select this doc group.
8300               (gnus-error 3 "Article couldn't be entered"))))))
8301     ;; Now we have selected all the documents.
8302     (cond
8303      ((not groups)
8304       (error "None of the articles could be interpreted as documents"))
8305      ((gnus-group-read-ephemeral-group
8306        (setq vgroup (format
8307                      "nnvirtual:%s-%s" gnus-newsgroup-name
8308                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8309        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8310        t
8311        (cons (current-buffer) 'summary)))
8312      (t
8313       (error "Couldn't select virtual nndoc group")))))
8314
8315 (defun gnus-summary-isearch-article (&optional regexp-p)
8316   "Do incremental search forward on the current article.
8317 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8318   (interactive "P")
8319   (let* ((gnus-inhibit-treatment t)
8320          (old (gnus-summary-select-article)))
8321     (gnus-configure-windows 'article)
8322     (gnus-eval-in-buffer-window gnus-article-buffer
8323       (save-restriction
8324         (widen)
8325         (when (eq 'old old)
8326           (gnus-article-show-all-headers))
8327         (goto-char (point-min))
8328         (isearch-forward regexp-p)))))
8329
8330 (defun gnus-summary-search-article-forward (regexp &optional backward)
8331   "Search for an article containing REGEXP forward.
8332 If BACKWARD, search backward instead."
8333   (interactive
8334    (list (read-string
8335           (format "Search article %s (regexp%s): "
8336                   (if current-prefix-arg "backward" "forward")
8337                   (if gnus-last-search-regexp
8338                       (concat ", default " gnus-last-search-regexp)
8339                     "")))
8340          current-prefix-arg))
8341   (if (string-equal regexp "")
8342       (setq regexp (or gnus-last-search-regexp ""))
8343     (setq gnus-last-search-regexp regexp)
8344     (setq gnus-article-before-search gnus-current-article))
8345   ;; Intentionally set gnus-last-article.
8346   (setq gnus-last-article gnus-article-before-search)
8347   (let ((gnus-last-article gnus-last-article))
8348     (if (gnus-summary-search-article regexp backward)
8349         (gnus-summary-show-thread)
8350       (error "Search failed: \"%s\"" regexp))))
8351
8352 (defun gnus-summary-search-article-backward (regexp)
8353   "Search for an article containing REGEXP backward."
8354   (interactive
8355    (list (read-string
8356           (format "Search article backward (regexp%s): "
8357                   (if gnus-last-search-regexp
8358                       (concat ", default " gnus-last-search-regexp)
8359                     "")))))
8360   (gnus-summary-search-article-forward regexp 'backward))
8361
8362 (eval-when-compile
8363   (defmacro gnus-summary-search-article-position-point (regexp backward)
8364     "Dehighlight the last matched text and goto the beginning position."
8365     (` (if (and gnus-summary-search-article-matched-data
8366                 (let ((text (caddr gnus-summary-search-article-matched-data))
8367                       (inhibit-read-only t)
8368                       buffer-read-only)
8369                   (delete-region
8370                    (goto-char (car gnus-summary-search-article-matched-data))
8371                    (cadr gnus-summary-search-article-matched-data))
8372                   (insert text)
8373                   (string-match (, regexp) text)))
8374            (if (, backward) (beginning-of-line) (end-of-line))
8375          (goto-char (if (, backward) (point-max) (point-min))))))
8376
8377   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8378     "Place point where X-Face image is displayed."
8379     (if (featurep 'xemacs)
8380         (` (let ((end (if (search-forward "\n\n" nil t)
8381                           (goto-char (1- (point)))
8382                         (point-min)))
8383                  extent)
8384              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8385              (unless (and (re-search-forward "^From:" end t)
8386                           (setq extent (extent-at (point)))
8387                           (extent-begin-glyph extent))
8388                (goto-char (, opoint)))))
8389       (` (let ((end (if (search-forward "\n\n" nil t)
8390                         (goto-char (1- (point)))
8391                       (point-min)))
8392                (start (or (search-backward "\n\n" nil t) (point-min))))
8393            (goto-char
8394             (or (text-property-any start end 'x-face-image t);; x-face-e21
8395                 (text-property-any start end 'x-face-mule-bitmap-image t)
8396                 (, opoint)))))))
8397
8398   (defmacro gnus-summary-search-article-highlight-matched-text
8399     (backward treated x-face)
8400     "Highlight matched text in the function `gnus-summary-search-article'."
8401     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8402              (end (set-marker (make-marker) (match-end 0)))
8403              (inhibit-read-only t)
8404              buffer-read-only)
8405          (unless treated
8406            (let ((,@
8407                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8408                     (mapcar
8409                      (lambda (item) (setq items (delq item items)))
8410                      '(gnus-treat-buttonize
8411                        gnus-treat-fill-article
8412                        gnus-treat-fill-long-lines
8413                        gnus-treat-emphasize
8414                        gnus-treat-highlight-headers
8415                        gnus-treat-highlight-citation
8416                        gnus-treat-highlight-signature
8417                        gnus-treat-overstrike
8418                        gnus-treat-display-x-face
8419                        gnus-treat-buttonize-head
8420                        gnus-treat-decode-article-as-default-mime-charset))
8421                     (static-if (featurep 'xemacs)
8422                         items
8423                       (cons '(x-face-mule-delete-x-face-field
8424                               (quote never))
8425                             items))))
8426                  (gnus-treat-display-x-face
8427                   (when (, x-face) gnus-treat-display-x-face)))
8428              (gnus-article-prepare-mime-display)))
8429          (goto-char (if (, backward) start end))
8430          (when (, x-face)
8431            (gnus-summary-search-article-highlight-goto-x-face (point)))
8432          (setq gnus-summary-search-article-matched-data
8433                (list start end (buffer-substring start end)))
8434          (unless (eq start end);; matched text has been deleted. :-<
8435            (put-text-property start end 'face
8436                               (or (find-face 'isearch)
8437                                   'secondary-selection))))))
8438   )
8439
8440 (defun gnus-summary-search-article (regexp &optional backward)
8441   "Search for an article containing REGEXP.
8442 Optional argument BACKWARD means do search for backward.
8443 `gnus-select-article-hook' is not called during the search."
8444   ;; We have to require this here to make sure that the following
8445   ;; dynamic binding isn't shadowed by autoloading.
8446   (require 'gnus-async)
8447   (require 'gnus-art)
8448   (let ((gnus-select-article-hook nil)  ;Disable hook.
8449         (gnus-article-prepare-hook nil)
8450         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8451         (gnus-use-article-prefetch nil)
8452         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8453         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8454         (gnus-visual nil)
8455         (gnus-keep-backlog nil)
8456         (gnus-break-pages nil)
8457         (gnus-summary-display-arrow nil)
8458         (gnus-updated-mode-lines nil)
8459         (gnus-auto-center-summary nil)
8460         (sum (current-buffer))
8461         (found nil)
8462         point treated)
8463     (gnus-save-hidden-threads
8464       (static-if (featurep 'xemacs)
8465           (let ((gnus-inhibit-treatment t))
8466             (setq treated (eq 'old (gnus-summary-select-article)))
8467             (when (and treated
8468                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8469                                  (window-live-p (get-buffer-window
8470                                                  gnus-article-buffer t)))))
8471               (gnus-summary-select-article nil t)
8472               (setq treated nil)))
8473         (let ((gnus-inhibit-treatment t)
8474               (x-face-mule-delete-x-face-field 'never))
8475           (setq treated (eq 'old (gnus-summary-select-article)))
8476           (when (and treated
8477                      (not
8478                       (and (gnus-buffer-live-p gnus-article-buffer)
8479                            (window-live-p (get-buffer-window
8480                                            gnus-article-buffer t))
8481                            (or (not (string-match "^\\^X-Face:" regexp))
8482                                (with-current-buffer gnus-article-buffer
8483                                  gnus-summary-search-article-matched-data)))))
8484             (gnus-summary-select-article nil t)
8485             (setq treated nil))))
8486       (set-buffer gnus-article-buffer)
8487       (widen)
8488       (if treated
8489           (progn
8490             (gnus-article-show-all-headers)
8491             (gnus-summary-search-article-position-point regexp backward))
8492         (goto-char (if backward (point-max) (point-min))))
8493       (while (not found)
8494         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8495         (if (if backward
8496                 (re-search-backward regexp nil t)
8497               (re-search-forward regexp nil t))
8498             ;; We found the regexp.
8499             (progn
8500               (gnus-summary-search-article-highlight-matched-text
8501                backward treated (string-match "^\\^X-Face:" regexp))
8502               (setq found 'found)
8503               (forward-line
8504                (/ (- 2 (window-height
8505                         (get-buffer-window gnus-article-buffer t)))
8506                   2))
8507               (set-window-start
8508                (get-buffer-window (current-buffer))
8509                (point))
8510               (set-buffer sum)
8511               (setq point (point)))
8512           ;; We didn't find it, so we go to the next article.
8513           (set-buffer sum)
8514           (setq found 'not)
8515           (while (eq found 'not)
8516             (if (not (if backward (gnus-summary-find-prev)
8517                        (gnus-summary-find-next)))
8518                 ;; No more articles.
8519                 (setq found t)
8520               ;; Select the next article and adjust point.
8521               (unless (gnus-summary-article-sparse-p
8522                        (gnus-summary-article-number))
8523                 (setq found nil)
8524                 (let ((gnus-inhibit-treatment t))
8525                   (gnus-summary-select-article))
8526                 (setq treated nil)
8527                 (set-buffer gnus-article-buffer)
8528                 (widen)
8529                 (goto-char (if backward (point-max) (point-min))))))))
8530       (gnus-message 7 ""))
8531     ;; Return whether we found the regexp.
8532     (when (eq found 'found)
8533       (goto-char point)
8534       (gnus-summary-show-thread)
8535       (gnus-summary-goto-subject gnus-current-article)
8536       (gnus-summary-position-point)
8537       t)))
8538
8539 (defun gnus-find-matching-articles (header regexp)
8540   "Return a list of all articles that match REGEXP on HEADER.
8541 This search includes all articles in the current group that Gnus has
8542 fetched headers for, whether they are displayed or not."
8543   (let ((articles nil)
8544         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8545         (case-fold-search t))
8546     (dolist (header gnus-newsgroup-headers)
8547       (when (string-match regexp (funcall func header))
8548         (push (mail-header-number header) articles)))
8549     (nreverse articles)))
8550
8551 (defun gnus-summary-find-matching (header regexp &optional backward unread
8552                                           not-case-fold not-matching)
8553   "Return a list of all articles that match REGEXP on HEADER.
8554 The search stars on the current article and goes forwards unless
8555 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8556 If UNREAD is non-nil, only unread articles will
8557 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8558 in the comparisons. If NOT-MATCHING, return a list of all articles that
8559 not match REGEXP on HEADER."
8560   (let ((case-fold-search (not not-case-fold))
8561         articles d func)
8562     (if (consp header)
8563         (if (eq (car header) 'extra)
8564             (setq func
8565                   `(lambda (h)
8566                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8567                          "")))
8568           (error "%s is an invalid header" header))
8569       (unless (fboundp (intern (concat "mail-header-" header)))
8570         (error "%s is not a valid header" header))
8571       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8572     (dolist (d (if (eq backward 'all)
8573                    gnus-newsgroup-data
8574                  (gnus-data-find-list
8575                   (gnus-summary-article-number)
8576                   (gnus-data-list backward))))
8577       (when (and (or (not unread)       ; We want all articles...
8578                      (gnus-data-unread-p d)) ; Or just unreads.
8579                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8580                  (if not-matching
8581                      (not (string-match
8582                            regexp
8583                            (funcall func (gnus-data-header d))))
8584                    (string-match regexp
8585                                  (funcall func (gnus-data-header d)))))
8586         (push (gnus-data-number d) articles))) ; Success!
8587     (nreverse articles)))
8588
8589 (defun gnus-summary-execute-command (header regexp command &optional backward)
8590   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8591 If HEADER is an empty string (or nil), the match is done on the entire
8592 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8593   (interactive
8594    (list (let ((completion-ignore-case t))
8595            (completing-read
8596             "Header name: "
8597             (mapcar (lambda (header) (list (format "%s" header)))
8598                     (append
8599                      '("Number" "Subject" "From" "Lines" "Date"
8600                        "Message-ID" "Xref" "References" "Body")
8601                      gnus-extra-headers))
8602             nil 'require-match))
8603          (read-string "Regexp: ")
8604          (read-key-sequence "Command: ")
8605          current-prefix-arg))
8606   (when (equal header "Body")
8607     (setq header ""))
8608   ;; Hidden thread subtrees must be searched as well.
8609   (gnus-summary-show-all-threads)
8610   ;; We don't want to change current point nor window configuration.
8611   (save-excursion
8612     (save-window-excursion
8613       (let (gnus-visual
8614             gnus-treat-strip-trailing-blank-lines
8615             gnus-treat-strip-leading-blank-lines
8616             gnus-treat-strip-multiple-blank-lines
8617             gnus-treat-hide-boring-headers
8618             gnus-treat-fold-newsgroups
8619             gnus-article-prepare-hook)
8620         (gnus-message 6 "Executing %s..." (key-description command))
8621         ;; We'd like to execute COMMAND interactively so as to give arguments.
8622         (gnus-execute header regexp
8623                       `(call-interactively ',(key-binding command))
8624                       backward)
8625         (gnus-message 6 "Executing %s...done" (key-description command))))))
8626
8627 (defun gnus-summary-beginning-of-article ()
8628   "Scroll the article back to the beginning."
8629   (interactive)
8630   (gnus-summary-select-article)
8631   (gnus-configure-windows 'article)
8632   (gnus-eval-in-buffer-window gnus-article-buffer
8633     (widen)
8634     (goto-char (point-min))
8635     (when gnus-break-pages
8636       (gnus-narrow-to-page))))
8637
8638 (defun gnus-summary-end-of-article ()
8639   "Scroll to the end of the article."
8640   (interactive)
8641   (gnus-summary-select-article)
8642   (gnus-configure-windows 'article)
8643   (gnus-eval-in-buffer-window gnus-article-buffer
8644     (widen)
8645     (goto-char (point-max))
8646     (recenter -3)
8647     (when gnus-break-pages
8648       (when (re-search-backward page-delimiter nil t)
8649         (narrow-to-region (match-end 0) (point-max)))
8650       (gnus-narrow-to-page))))
8651
8652 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8653   "Truncate to LEN and quote all \"(\"'s in STRING."
8654   (gnus-replace-in-string (if (and len (> (length string) len))
8655                               (substring string 0 len)
8656                             string)
8657                           "[()]" "\\\\\\&"))
8658
8659 (defun gnus-summary-print-article (&optional filename n)
8660   "Generate and print a PostScript image of the process-marked (mail) articles.
8661
8662 If used interactively, print the current article if none are
8663 process-marked.  With prefix arg, prompt the user for the name of the
8664 file to save in.
8665
8666 When used from Lisp, accept two optional args FILENAME and N.  N means
8667 to print the next N articles.  If N is negative, print the N previous
8668 articles.  If N is nil and articles have been marked with the process
8669 mark, print these instead.
8670
8671 If the optional first argument FILENAME is nil, send the image to the
8672 printer.  If FILENAME is a string, save the PostScript image in a file with
8673 that name.  If FILENAME is a number, prompt the user for the name of the file
8674 to save in."
8675   (interactive (list (ps-print-preprint current-prefix-arg)))
8676   (dolist (article (gnus-summary-work-articles n))
8677     (gnus-summary-select-article nil nil 'pseudo article)
8678     (gnus-eval-in-buffer-window gnus-article-buffer
8679       (gnus-print-buffer))
8680     (gnus-summary-remove-process-mark article))
8681   (ps-despool filename))
8682
8683 (defun gnus-print-buffer ()
8684   (let ((buffer (generate-new-buffer " *print*")))
8685     (unwind-protect
8686         (progn
8687           (copy-to-buffer buffer (point-min) (point-max))
8688           (set-buffer buffer)
8689           (gnus-remove-text-with-property 'gnus-decoration)
8690           (when (gnus-visual-p 'article-highlight 'highlight)
8691             ;; Copy-to-buffer doesn't copy overlay.  So redo
8692             ;; highlight.
8693             (let ((gnus-article-buffer buffer))
8694               (gnus-article-highlight-citation t)
8695               (gnus-article-highlight-signature)
8696               (gnus-article-emphasize)
8697               (gnus-article-delete-invisible-text)))
8698           (let ((ps-left-header
8699                  (list
8700                   (concat "("
8701                           (gnus-summary-print-truncate-and-quote
8702                            (mail-header-subject gnus-current-headers)
8703                            66) ")")
8704                   (concat "("
8705                           (gnus-summary-print-truncate-and-quote
8706                            (mail-header-from gnus-current-headers)
8707                            45) ")")))
8708                 (ps-right-header
8709                  (list
8710                   "/pagenumberstring load"
8711                   (concat "("
8712                           (mail-header-date gnus-current-headers) ")"))))
8713             (gnus-run-hooks 'gnus-ps-print-hook)
8714             (save-excursion
8715               (if window-system
8716                   (ps-spool-buffer-with-faces)
8717                 (ps-spool-buffer)))))
8718       (kill-buffer buffer))))
8719
8720 (defun gnus-summary-show-article (&optional arg)
8721   "Force redisplaying of the current article.
8722 If ARG (the prefix) is a number, show the article with the charset
8723 defined in `gnus-summary-show-article-charset-alist', or the charset
8724 input.
8725 If ARG (the prefix) is non-nil and not a number, show the raw article
8726 without any article massaging functions being run.  Normally, the key
8727 strokes are `C-u g'."
8728   (interactive "P")
8729   (cond
8730    ((numberp arg)
8731     (gnus-summary-show-article t)
8732     (let* ((gnus-newsgroup-charset
8733             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8734                 (mm-read-coding-system
8735                  "View as charset: " ;; actually it is coding system.
8736                  (save-excursion
8737                    (set-buffer gnus-article-buffer)
8738                    (mm-detect-coding-region (point) (point-max))))))
8739            (default-mime-charset gnus-newsgroup-charset)
8740            (gnus-newsgroup-ignored-charsets 'gnus-all))
8741       (gnus-summary-select-article nil 'force)
8742       (let ((deps gnus-newsgroup-dependencies)
8743             head header lines)
8744         (save-excursion
8745           (set-buffer gnus-original-article-buffer)
8746           (save-restriction
8747             (message-narrow-to-head)
8748             (setq head (buffer-string))
8749             (goto-char (point-min))
8750             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8751               (goto-char (point-max))
8752               (widen)
8753               (setq lines (1- (count-lines (point) (point-max))))))
8754           (with-temp-buffer
8755             (insert (format "211 %d Article retrieved.\n"
8756                             (cdr gnus-article-current)))
8757             (insert head)
8758             (if lines (insert (format "Lines: %d\n" lines)))
8759             (insert ".\n")
8760             (let ((nntp-server-buffer (current-buffer)))
8761               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8762         (gnus-data-set-header
8763          (gnus-data-find (cdr gnus-article-current))
8764          header)
8765         (gnus-summary-update-article-line
8766          (cdr gnus-article-current) header)
8767         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8768           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8769    ((not arg)
8770     ;; Select the article the normal way.
8771     (gnus-summary-select-article nil 'force))
8772    (t
8773     ;; We have to require this here to make sure that the following
8774     ;; dynamic binding isn't shadowed by autoloading.
8775     (require 'gnus-async)
8776     (require 'gnus-art)
8777     ;; Bind the article treatment functions to nil.
8778     (let ((gnus-have-all-headers t)
8779           gnus-article-prepare-hook
8780           gnus-article-decode-hook
8781           gnus-break-pages
8782           gnus-show-mime
8783           (gnus-inhibit-treatment t))
8784       (gnus-summary-select-article nil 'force))))
8785   (gnus-summary-goto-subject gnus-current-article)
8786   (gnus-summary-position-point))
8787
8788 (defun gnus-summary-show-raw-article ()
8789   "Show the raw article without any article massaging functions being run."
8790   (interactive)
8791   (gnus-summary-show-article t))
8792
8793 (defun gnus-summary-verbose-headers (&optional arg)
8794   "Toggle permanent full header display.
8795 If ARG is a positive number, turn header display on.
8796 If ARG is a negative number, turn header display off."
8797   (interactive "P")
8798   (setq gnus-show-all-headers
8799         (cond ((or (not (numberp arg))
8800                    (zerop arg))
8801                (not gnus-show-all-headers))
8802               ((natnump arg)
8803                t)))
8804   (gnus-summary-show-article))
8805
8806 (defun gnus-summary-toggle-header (&optional arg)
8807   "Show the headers if they are hidden, or hide them if they are shown.
8808 If ARG is a positive number, show the entire header.
8809 If ARG is a negative number, hide the unwanted header lines."
8810   (interactive "P")
8811   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8812                      (get-buffer-window gnus-article-buffer t))))
8813     (with-current-buffer gnus-article-buffer
8814       (widen)
8815       (article-narrow-to-head)
8816       (let* ((buffer-read-only nil)
8817              (inhibit-point-motion-hooks t)
8818              (hidden (if (numberp arg)
8819                          (>= arg 0)
8820                        (gnus-article-hidden-text-p 'headers)))
8821              s e)
8822         (delete-region (point-min) (point-max))
8823         (with-current-buffer gnus-original-article-buffer
8824           (goto-char (setq s (point-min)))
8825           (setq e (if (search-forward "\n\n" nil t)
8826                       (1- (point))
8827                     (point-max))))
8828         (insert-buffer-substring gnus-original-article-buffer s e)
8829         ;; In T-gnus, gnus-article-decode-hook doesn't contain
8830         ;; article-decode-encoded-words by default.
8831         (article-decode-encoded-words)
8832         (run-hooks 'gnus-article-decode-hook)
8833         (if hidden
8834             (let ((gnus-treat-hide-headers nil)
8835                   (gnus-treat-hide-boring-headers nil))
8836               (gnus-delete-wash-type 'headers)
8837               (gnus-treat-article 'head))
8838           (gnus-treat-article 'head))
8839         (widen)
8840         (if window
8841             (set-window-start window (goto-char (point-min))))
8842         (if gnus-break-pages
8843             (gnus-narrow-to-page)
8844           (when (gnus-visual-p 'page-marker)
8845             (let ((buffer-read-only nil))
8846               (gnus-remove-text-with-property 'gnus-prev)
8847               (gnus-remove-text-with-property 'gnus-next))))
8848         (gnus-set-mode-line 'article)))))
8849
8850 (defun gnus-summary-show-all-headers ()
8851   "Make all header lines visible."
8852   (interactive)
8853   (gnus-summary-toggle-header 1))
8854
8855 (defun gnus-summary-toggle-mime (&optional arg)
8856   "Toggle MIME processing.
8857 If ARG is a positive number, turn MIME processing on."
8858   (interactive "P")
8859   (setq gnus-show-mime
8860         (if (null arg)
8861             (not gnus-show-mime)
8862           (> (prefix-numeric-value arg) 0)))
8863   (gnus-summary-select-article t 'force))
8864
8865 (defun gnus-summary-caesar-message (&optional arg)
8866   "Caesar rotate the current article by 13.
8867 The numerical prefix specifies how many places to rotate each letter
8868 forward."
8869   (interactive "P")
8870   (gnus-summary-select-article)
8871   (let ((mail-header-separator ""))
8872     (gnus-eval-in-buffer-window gnus-article-buffer
8873       (save-restriction
8874         (widen)
8875         (let ((start (window-start))
8876               buffer-read-only)
8877           (message-caesar-buffer-body arg)
8878           (set-window-start (get-buffer-window (current-buffer)) start))))))
8879
8880 (autoload 'unmorse-region "morse"
8881   "Convert morse coded text in region to ordinary ASCII text."
8882   t)
8883
8884 (defun gnus-summary-morse-message (&optional arg)
8885   "Morse decode the current article."
8886   (interactive "P")
8887   (gnus-summary-select-article)
8888   (let ((mail-header-separator ""))
8889     (gnus-eval-in-buffer-window gnus-article-buffer
8890       (save-excursion
8891         (save-restriction
8892           (widen)
8893           (let ((pos (window-start))
8894                 buffer-read-only)
8895             (goto-char (point-min))
8896             (when (message-goto-body)
8897               (gnus-narrow-to-body))
8898             (goto-char (point-min))
8899             (while (re-search-forward "·" (point-max) t)
8900               (replace-match "."))
8901             (unmorse-region (point-min) (point-max))
8902             (widen)
8903             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8904
8905 (defun gnus-summary-stop-page-breaking ()
8906   "Stop page breaking in the current article."
8907   (interactive)
8908   (gnus-summary-select-article)
8909   (gnus-eval-in-buffer-window gnus-article-buffer
8910     (widen)
8911     (when (gnus-visual-p 'page-marker)
8912       (let ((buffer-read-only nil))
8913         (gnus-remove-text-with-property 'gnus-prev)
8914         (gnus-remove-text-with-property 'gnus-next))
8915       (setq gnus-page-broken nil))))
8916
8917 (defun gnus-summary-move-article (&optional n to-newsgroup
8918                                             select-method action)
8919   "Move the current article to a different newsgroup.
8920 If N is a positive number, move the N next articles.
8921 If N is a negative number, move the N previous articles.
8922 If N is nil and any articles have been marked with the process mark,
8923 move those articles instead.
8924 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8925 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8926 re-spool using this method.
8927
8928 When called interactively with TO-NEWSGROUP being nil, the value of
8929 the variable `gnus-move-split-methods' is used for finding a default
8930 for the target newsgroup.
8931
8932 For this function to work, both the current newsgroup and the
8933 newsgroup that you want to move to have to support the `request-move'
8934 and `request-accept' functions.
8935
8936 ACTION can be either `move' (the default), `crosspost' or `copy'."
8937   (interactive "P")
8938   (unless action
8939     (setq action 'move))
8940   ;; Check whether the source group supports the required functions.
8941   (cond ((and (eq action 'move)
8942               (not (gnus-check-backend-function
8943                     'request-move-article gnus-newsgroup-name)))
8944          (error "The current group does not support article moving"))
8945         ((and (eq action 'crosspost)
8946               (not (gnus-check-backend-function
8947                     'request-replace-article gnus-newsgroup-name)))
8948          (error "The current group does not support article editing")))
8949   (let ((articles (gnus-summary-work-articles n))
8950         (prefix (if (gnus-check-backend-function
8951                      'request-move-article gnus-newsgroup-name)
8952                     (gnus-group-real-prefix gnus-newsgroup-name)
8953                   ""))
8954         (names '((move "Move" "Moving")
8955                  (copy "Copy" "Copying")
8956                  (crosspost "Crosspost" "Crossposting")))
8957         (copy-buf (save-excursion
8958                     (nnheader-set-temp-buffer " *copy article*")))
8959         art-group to-method new-xref article to-groups)
8960     (unless (assq action names)
8961       (error "Unknown action %s" action))
8962     ;; Read the newsgroup name.
8963     (when (and (not to-newsgroup)
8964                (not select-method))
8965       (if (and gnus-move-split-methods
8966                (not
8967                 (and (memq gnus-current-article articles)
8968                      (gnus-buffer-live-p gnus-original-article-buffer))))
8969           ;; When `gnus-move-split-methods' is non-nil, we have to
8970           ;; select an article to give `gnus-read-move-group-name' an
8971           ;; opportunity to suggest an appropriate default.  However,
8972           ;; we needn't render or mark the article.
8973           (let ((gnus-display-mime-function nil)
8974                 (gnus-article-prepare-hook nil)
8975                 (gnus-mark-article-hook nil))
8976             (gnus-summary-select-article nil nil nil (car articles))))
8977       (setq to-newsgroup
8978             (gnus-read-move-group-name
8979              (cadr (assq action names))
8980              (symbol-value (intern (format "gnus-current-%s-group" action)))
8981              articles prefix))
8982       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8983     (setq to-method (or select-method
8984                         (gnus-server-to-method
8985                          (gnus-group-method to-newsgroup))))
8986     ;; Check the method we are to move this article to...
8987     (unless (gnus-check-backend-function
8988              'request-accept-article (car to-method))
8989       (error "%s does not support article copying" (car to-method)))
8990     (unless (gnus-check-server to-method)
8991       (error "Can't open server %s" (car to-method)))
8992     (gnus-message 6 "%s to %s: %s..."
8993                   (caddr (assq action names))
8994                   (or (car select-method) to-newsgroup) articles)
8995     (while articles
8996       (setq article (pop articles))
8997       (setq
8998        art-group
8999        (cond
9000         ;; Move the article.
9001         ((eq action 'move)
9002          ;; Remove this article from future suppression.
9003          (gnus-dup-unsuppress-article article)
9004          (gnus-request-move-article
9005           article                       ; Article to move
9006           gnus-newsgroup-name           ; From newsgroup
9007           (nth 1 (gnus-find-method-for-group
9008                   gnus-newsgroup-name)) ; Server
9009           (list 'gnus-request-accept-article
9010                 to-newsgroup (list 'quote select-method)
9011                 (not articles) t)       ; Accept form
9012           (not articles)))              ; Only save nov last time
9013         ;; Copy the article.
9014         ((eq action 'copy)
9015          (save-excursion
9016            (set-buffer copy-buf)
9017            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9018              (gnus-request-accept-article
9019               to-newsgroup select-method (not articles) t))))
9020         ;; Crosspost the article.
9021         ((eq action 'crosspost)
9022          (let ((xref (message-tokenize-header
9023                       (mail-header-xref (gnus-summary-article-header article))
9024                       " ")))
9025            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9026                                   ":" (number-to-string article)))
9027            (unless xref
9028              (setq xref (list (system-name))))
9029            (setq new-xref
9030                  (concat
9031                   (mapconcat 'identity
9032                              (delete "Xref:" (delete new-xref xref))
9033                              " ")
9034                   " " new-xref))
9035            (save-excursion
9036              (set-buffer copy-buf)
9037              ;; First put the article in the destination group.
9038              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9039              (when (consp (setq art-group
9040                                 (gnus-request-accept-article
9041                                  to-newsgroup select-method (not articles))))
9042                (setq new-xref (concat new-xref " " (car art-group)
9043                                       ":"
9044                                       (number-to-string (cdr art-group))))
9045                ;; Now we have the new Xrefs header, so we insert
9046                ;; it and replace the new article.
9047                (nnheader-replace-header "Xref" new-xref)
9048                (gnus-request-replace-article
9049                 (cdr art-group) to-newsgroup (current-buffer))
9050                art-group))))))
9051       (cond
9052        ((not art-group)
9053         (gnus-message 1 "Couldn't %s article %s: %s"
9054                       (cadr (assq action names)) article
9055                       (nnheader-get-report (car to-method))))
9056        ((eq art-group 'junk)
9057         (when (eq action 'move)
9058           (gnus-summary-mark-article article gnus-canceled-mark)
9059           (gnus-message 4 "Deleted article %s" article)
9060           ;; run the delete hook
9061           (run-hook-with-args 'gnus-summary-article-delete-hook
9062                               action
9063                               (gnus-data-header
9064                                (assoc article (gnus-data-list nil)))
9065                               gnus-newsgroup-name nil
9066                               select-method)))
9067        (t
9068         (let* ((pto-group (gnus-group-prefixed-name
9069                            (car art-group) to-method))
9070                (info (gnus-get-info pto-group))
9071                (to-group (gnus-info-group info))
9072                to-marks)
9073           ;; Update the group that has been moved to.
9074           (when (and info
9075                      (memq action '(move copy)))
9076             (unless (member to-group to-groups)
9077               (push to-group to-groups))
9078
9079             (unless (memq article gnus-newsgroup-unreads)
9080               (push 'read to-marks)
9081               (gnus-info-set-read
9082                info (gnus-add-to-range (gnus-info-read info)
9083                                        (list (cdr art-group)))))
9084
9085             ;; See whether the article is to be put in the cache.
9086             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9087                              gnus-article-mark-lists
9088                            (delete '(expirable . expire)
9089                                    (copy-sequence gnus-article-mark-lists))))
9090                   (to-article (cdr art-group)))
9091
9092               ;; Enter the article into the cache in the new group,
9093               ;; if that is required.
9094               (when gnus-use-cache
9095                 (gnus-cache-possibly-enter-article
9096                  to-group to-article
9097                  (let ((header (copy-sequence
9098                                 (gnus-summary-article-header article))))
9099                    (mail-header-set-number header to-article)
9100                    header)
9101                  (memq article gnus-newsgroup-marked)
9102                  (memq article gnus-newsgroup-dormant)
9103                  (memq article gnus-newsgroup-unreads)))
9104
9105               (when gnus-preserve-marks
9106                 ;; Copy any marks over to the new group.
9107                 (when (and (equal to-group gnus-newsgroup-name)
9108                            (not (memq article gnus-newsgroup-unreads)))
9109                   ;; Mark this article as read in this group.
9110                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9111                   (setcdr (gnus-active to-group) to-article)
9112                   (setcdr gnus-newsgroup-active to-article))
9113
9114                 (while marks
9115                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9116                     (when (memq article (symbol-value
9117                                          (intern (format "gnus-newsgroup-%s"
9118                                                          (caar marks)))))
9119                       (push (cdar marks) to-marks)
9120                       ;; If the other group is the same as this group,
9121                       ;; then we have to add the mark to the list.
9122                       (when (equal to-group gnus-newsgroup-name)
9123                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9124                              (cons to-article
9125                                    (symbol-value
9126                                     (intern (format "gnus-newsgroup-%s"
9127                                                     (caar marks)))))))
9128                       ;; Copy the marks to other group.
9129                       (gnus-add-marked-articles
9130                        to-group (cdar marks) (list to-article) info)))
9131                   (setq marks (cdr marks)))
9132
9133                 (gnus-request-set-mark
9134                  to-group (list (list (list to-article) 'add to-marks))))
9135
9136               (gnus-dribble-enter
9137                (concat "(gnus-group-set-info '"
9138                        (gnus-prin1-to-string (gnus-get-info to-group))
9139                        ")"))))
9140
9141           ;; Update the Xref header in this article to point to
9142           ;; the new crossposted article we have just created.
9143           (when (eq action 'crosspost)
9144             (save-excursion
9145               (set-buffer copy-buf)
9146               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9147               (nnheader-replace-header "Xref" new-xref)
9148               (gnus-request-replace-article
9149                article gnus-newsgroup-name (current-buffer))))
9150
9151           ;; run the move/copy/crosspost/respool hook
9152           (run-hook-with-args 'gnus-summary-article-move-hook
9153                               action
9154                               (gnus-data-header
9155                                (assoc article (gnus-data-list nil)))
9156                               gnus-newsgroup-name
9157                               to-newsgroup
9158                               select-method))
9159
9160         ;;;!!!Why is this necessary?
9161         (set-buffer gnus-summary-buffer)
9162         
9163         (gnus-summary-goto-subject article)
9164         (when (eq action 'move)
9165           (gnus-summary-mark-article article gnus-canceled-mark))))
9166       (gnus-summary-remove-process-mark article))
9167     ;; Re-activate all groups that have been moved to.
9168     (save-excursion
9169       (set-buffer gnus-group-buffer)
9170       (let ((gnus-group-marked to-groups))
9171         (gnus-group-get-new-news-this-group nil t)))
9172
9173     (gnus-kill-buffer copy-buf)
9174     (gnus-summary-position-point)
9175     (gnus-set-mode-line 'summary)))
9176
9177 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9178   "Move the current article to a different newsgroup.
9179 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9180 When called interactively, if TO-NEWSGROUP is nil, use the value of
9181 the variable `gnus-move-split-methods' for finding a default target
9182 newsgroup.
9183 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9184 re-spool using this method."
9185   (interactive "P")
9186   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9187
9188 (defun gnus-summary-crosspost-article (&optional n)
9189   "Crosspost the current article to some other group."
9190   (interactive "P")
9191   (gnus-summary-move-article n nil nil 'crosspost))
9192
9193 (defcustom gnus-summary-respool-default-method nil
9194   "Default method type for respooling an article.
9195 If nil, use to the current newsgroup method."
9196   :type 'symbol
9197   :group 'gnus-summary-mail)
9198
9199 (defcustom gnus-summary-display-while-building nil
9200   "If non-nil, show and update the summary buffer as it's being built.
9201 If the value is t, update the buffer after every line is inserted.  If
9202 the value is an integer (N), update the display every N lines."
9203   :group 'gnus-thread
9204   :type '(choice (const :tag "off" nil)
9205                  number
9206                  (const :tag "frequently" t)))
9207
9208 (defun gnus-summary-respool-article (&optional n method)
9209   "Respool the current article.
9210 The article will be squeezed through the mail spooling process again,
9211 which means that it will be put in some mail newsgroup or other
9212 depending on `nnmail-split-methods'.
9213 If N is a positive number, respool the N next articles.
9214 If N is a negative number, respool the N previous articles.
9215 If N is nil and any articles have been marked with the process mark,
9216 respool those articles instead.
9217
9218 Respooling can be done both from mail groups and \"real\" newsgroups.
9219 In the former case, the articles in question will be moved from the
9220 current group into whatever groups they are destined to.  In the
9221 latter case, they will be copied into the relevant groups."
9222   (interactive
9223    (list current-prefix-arg
9224          (let* ((methods (gnus-methods-using 'respool))
9225                 (methname
9226                  (symbol-name (or gnus-summary-respool-default-method
9227                                   (car (gnus-find-method-for-group
9228                                         gnus-newsgroup-name)))))
9229                 (method
9230                  (gnus-completing-read-with-default
9231                   methname "What backend do you want to use when respooling?"
9232                   methods nil t nil 'gnus-mail-method-history))
9233                 ms)
9234            (cond
9235             ((zerop (length (setq ms (gnus-servers-using-backend
9236                                       (intern method)))))
9237              (list (intern method) ""))
9238             ((= 1 (length ms))
9239              (car ms))
9240             (t
9241              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9242                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9243                            ms-alist))))))))
9244   (unless method
9245     (error "No method given for respooling"))
9246   (if (assoc (symbol-name
9247               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9248              (gnus-methods-using 'respool))
9249       (gnus-summary-move-article n nil method)
9250     (gnus-summary-copy-article n nil method)))
9251
9252 (defun gnus-summary-import-article (file &optional edit)
9253   "Import an arbitrary file into a mail newsgroup."
9254   (interactive "fImport file: \nP")
9255   (let ((group gnus-newsgroup-name)
9256         (now (current-time))
9257         atts lines group-art)
9258     (unless (gnus-check-backend-function 'request-accept-article group)
9259       (error "%s does not support article importing" group))
9260     (or (file-readable-p file)
9261         (not (file-regular-p file))
9262         (error "Can't read %s" file))
9263     (save-excursion
9264       (set-buffer (gnus-get-buffer-create " *import file*"))
9265       (erase-buffer)
9266       (nnheader-insert-file-contents file)
9267       (goto-char (point-min))
9268       (if (nnheader-article-p)
9269           (save-restriction
9270             (goto-char (point-min))
9271             (search-forward "\n\n" nil t)
9272             (narrow-to-region (point-min) (1- (point)))
9273             (goto-char (point-min))
9274             (unless (re-search-forward "^date:" nil t)
9275               (goto-char (point-max))
9276               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9277         ;; This doesn't look like an article, so we fudge some headers.
9278         (setq atts (file-attributes file)
9279               lines (count-lines (point-min) (point-max)))
9280         (insert "From: " (read-string "From: ") "\n"
9281                 "Subject: " (read-string "Subject: ") "\n"
9282                 "Date: " (message-make-date (nth 5 atts)) "\n"
9283                 "Message-ID: " (message-make-message-id) "\n"
9284                 "Lines: " (int-to-string lines) "\n"
9285                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9286       (setq group-art (gnus-request-accept-article group nil t))
9287       (kill-buffer (current-buffer)))
9288     (setq gnus-newsgroup-active (gnus-activate-group group))
9289     (forward-line 1)
9290     (gnus-summary-goto-article (cdr group-art) nil t)
9291     (when edit
9292       (gnus-summary-edit-article))))
9293
9294 (defun gnus-summary-create-article ()
9295   "Create an article in a mail newsgroup."
9296   (interactive)
9297   (let ((group gnus-newsgroup-name)
9298         (now (current-time))
9299         group-art)
9300     (unless (gnus-check-backend-function 'request-accept-article group)
9301       (error "%s does not support article importing" group))
9302     (save-excursion
9303       (set-buffer (gnus-get-buffer-create " *import file*"))
9304       (erase-buffer)
9305       (goto-char (point-min))
9306       ;; This doesn't look like an article, so we fudge some headers.
9307       (insert "From: " (read-string "From: ") "\n"
9308               "Subject: " (read-string "Subject: ") "\n"
9309               "Date: " (message-make-date now) "\n"
9310               "Message-ID: " (message-make-message-id) "\n")
9311       (setq group-art (gnus-request-accept-article group nil t))
9312       (kill-buffer (current-buffer)))
9313     (setq gnus-newsgroup-active (gnus-activate-group group))
9314     (forward-line 1)
9315     (gnus-summary-goto-article (cdr group-art) nil t)
9316     (gnus-summary-edit-article)))
9317
9318 (defun gnus-summary-article-posted-p ()
9319   "Say whether the current (mail) article is available from news as well.
9320 This will be the case if the article has both been mailed and posted."
9321   (interactive)
9322   (let ((id (mail-header-references (gnus-summary-article-header)))
9323         (gnus-override-method (car (gnus-refer-article-methods))))
9324     (if (gnus-request-head id "")
9325         (gnus-message 2 "The current message was found on %s"
9326                       gnus-override-method)
9327       (gnus-message 2 "The current message couldn't be found on %s"
9328                     gnus-override-method)
9329       nil)))
9330
9331 (defun gnus-summary-expire-articles (&optional now)
9332   "Expire all articles that are marked as expirable in the current group."
9333   (interactive)
9334   (when (and (not gnus-group-is-exiting-without-update-p)
9335              (gnus-check-backend-function
9336               'request-expire-articles gnus-newsgroup-name))
9337     ;; This backend supports expiry.
9338     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9339            (expirable (if total
9340                           (progn
9341                             ;; We need to update the info for
9342                             ;; this group for `gnus-list-of-read-articles'
9343                             ;; to give us the right answer.
9344                             (gnus-run-hooks 'gnus-exit-group-hook)
9345                             (gnus-summary-update-info)
9346                             (gnus-list-of-read-articles gnus-newsgroup-name))
9347                         (setq gnus-newsgroup-expirable
9348                               (sort gnus-newsgroup-expirable '<))))
9349            (expiry-wait (if now 'immediate
9350                           (gnus-group-find-parameter
9351                            gnus-newsgroup-name 'expiry-wait)))
9352            (nnmail-expiry-target
9353             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9354                 nnmail-expiry-target))
9355            es)
9356       (when expirable
9357         ;; There are expirable articles in this group, so we run them
9358         ;; through the expiry process.
9359         (gnus-message 6 "Expiring articles...")
9360         (unless (gnus-check-group gnus-newsgroup-name)
9361           (error "Can't open server for %s" gnus-newsgroup-name))
9362         ;; The list of articles that weren't expired is returned.
9363         (save-excursion
9364           (if expiry-wait
9365               (let ((nnmail-expiry-wait-function nil)
9366                     (nnmail-expiry-wait expiry-wait))
9367                 (setq es (gnus-request-expire-articles
9368                           expirable gnus-newsgroup-name)))
9369             (setq es (gnus-request-expire-articles
9370                       expirable gnus-newsgroup-name)))
9371           (unless total
9372             (setq gnus-newsgroup-expirable es))
9373           ;; We go through the old list of expirable, and mark all
9374           ;; really expired articles as nonexistent.
9375           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9376             (let ((gnus-use-cache nil))
9377               (dolist (article expirable)
9378                 (when (and (not (memq article es))
9379                            (gnus-data-find article))
9380                   (gnus-summary-mark-article article gnus-canceled-mark)
9381                   (run-hook-with-args 'gnus-summary-article-expire-hook
9382                                       'delete
9383                                       (gnus-data-header
9384                                        (assoc article (gnus-data-list nil)))
9385                                       gnus-newsgroup-name
9386                                       nil
9387                                       nil))))))
9388         (gnus-message 6 "Expiring articles...done")))))
9389
9390 (defun gnus-summary-expire-articles-now ()
9391   "Expunge all expirable articles in the current group.
9392 This means that *all* articles that are marked as expirable will be
9393 deleted forever, right now."
9394   (interactive)
9395   (or gnus-expert-user
9396       (gnus-yes-or-no-p
9397        "Are you really, really, really sure you want to delete all these messages? ")
9398       (error "Phew!"))
9399   (gnus-summary-expire-articles t))
9400
9401 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9402 (defun gnus-summary-delete-article (&optional n)
9403   "Delete the N next (mail) articles.
9404 This command actually deletes articles.  This is not a marking
9405 command.  The article will disappear forever from your life, never to
9406 return.
9407
9408 If N is negative, delete backwards.
9409 If N is nil and articles have been marked with the process mark,
9410 delete these instead.
9411
9412 If `gnus-novice-user' is non-nil you will be asked for
9413 confirmation before the articles are deleted."
9414   (interactive "P")
9415   (unless (gnus-check-backend-function 'request-expire-articles
9416                                        gnus-newsgroup-name)
9417     (error "The current newsgroup does not support article deletion"))
9418   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9419     (error "Couldn't open server"))
9420   ;; Compute the list of articles to delete.
9421   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9422         (nnmail-expiry-target 'delete)
9423         not-deleted)
9424     (if (and gnus-novice-user
9425              (not (gnus-yes-or-no-p
9426                    (format "Do you really want to delete %s forever? "
9427                            (if (> (length articles) 1)
9428                                (format "these %s articles" (length articles))
9429                              "this article")))))
9430         ()
9431       ;; Delete the articles.
9432       (setq not-deleted (gnus-request-expire-articles
9433                          articles gnus-newsgroup-name 'force))
9434       (while articles
9435         (gnus-summary-remove-process-mark (car articles))
9436         ;; The backend might not have been able to delete the article
9437         ;; after all.
9438         (unless (memq (car articles) not-deleted)
9439           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9440         (let* ((article (car articles))
9441                (id (mail-header-id (gnus-data-header
9442                                     (assoc article (gnus-data-list nil))))))
9443           (run-hook-with-args 'gnus-summary-article-delete-hook
9444                               'delete id gnus-newsgroup-name nil
9445                               nil))
9446         (setq articles (cdr articles)))
9447       (when not-deleted
9448         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9449     (gnus-summary-position-point)
9450     (gnus-set-mode-line 'summary)
9451     not-deleted))
9452
9453 (defun gnus-summary-edit-article (&optional force)
9454   "Edit the current article.
9455 This will have permanent effect only in mail groups.
9456 If FORCE is non-nil, allow editing of articles even in read-only
9457 groups."
9458   (interactive "P")
9459   (save-excursion
9460     (set-buffer gnus-summary-buffer)
9461     (let ((mail-parse-charset gnus-newsgroup-charset)
9462           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9463       (gnus-set-global-variables)
9464       (when (and (not force)
9465                  (gnus-group-read-only-p))
9466         (error "The current newsgroup does not support article editing"))
9467       (gnus-summary-show-article t)
9468       (gnus-article-edit-article
9469        'ignore
9470        `(lambda (no-highlight)
9471           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9472                 (message-options message-options)
9473                 (message-options-set-recipient)
9474                 (mail-parse-ignored-charsets
9475                  ',gnus-newsgroup-ignored-charsets))
9476             (gnus-summary-edit-article-done
9477              ,(or (mail-header-references gnus-current-headers) "")
9478              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9479
9480 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9481
9482 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9483                                                  no-highlight)
9484   "Make edits to the current article permanent."
9485   (interactive)
9486   (save-excursion
9487     ;; The buffer restriction contains the entire article if it exists.
9488     (when (article-goto-body)
9489       (let ((lines (count-lines (point) (point-max)))
9490             (length (- (point-max) (point)))
9491             (case-fold-search t)
9492             (body (copy-marker (point))))
9493         (goto-char (point-min))
9494         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9495           (delete-region (match-beginning 1) (match-end 1))
9496           (insert (number-to-string length)))
9497         (goto-char (point-min))
9498         (when (re-search-forward
9499                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9500           (delete-region (match-beginning 1) (match-end 1))
9501           (insert (number-to-string length)))
9502         (goto-char (point-min))
9503         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9504           (delete-region (match-beginning 1) (match-end 1))
9505           (insert (number-to-string lines))))))
9506   ;; Replace the article.
9507   (let ((buf (current-buffer)))
9508     (with-temp-buffer
9509       (insert-buffer-substring buf)
9510
9511       (if (and (not read-only)
9512                (not (gnus-request-replace-article
9513                      (cdr gnus-article-current) (car gnus-article-current)
9514                      (current-buffer) t)))
9515           (error "Couldn't replace article")
9516         ;; Update the summary buffer.
9517         (if (and references
9518                  (equal (message-tokenize-header references " ")
9519                         (message-tokenize-header
9520                          (or (message-fetch-field "references") "") " ")))
9521             ;; We only have to update this line.
9522             (save-excursion
9523               (save-restriction
9524                 (message-narrow-to-head)
9525                 (let ((head (buffer-string))
9526                       header)
9527                   (with-temp-buffer
9528                     (insert (format "211 %d Article retrieved.\n"
9529                                     (cdr gnus-article-current)))
9530                     (insert head)
9531                     (insert ".\n")
9532                     (let ((nntp-server-buffer (current-buffer)))
9533                       (setq header (car (gnus-get-newsgroup-headers
9534                                          nil t))))
9535                     (save-excursion
9536                       (set-buffer gnus-summary-buffer)
9537                       (gnus-data-set-header
9538                        (gnus-data-find (cdr gnus-article-current))
9539                        header)
9540                       (gnus-summary-update-article-line
9541                        (cdr gnus-article-current) header)
9542                       (if (gnus-summary-goto-subject
9543                            (cdr gnus-article-current) nil t)
9544                           (gnus-summary-update-secondary-mark
9545                            (cdr gnus-article-current))))))))
9546           ;; Update threads.
9547           (set-buffer (or buffer gnus-summary-buffer))
9548           (gnus-summary-update-article (cdr gnus-article-current))
9549           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9550               (gnus-summary-update-secondary-mark
9551                (cdr gnus-article-current))))
9552         ;; Prettify the article buffer again.
9553         (unless no-highlight
9554           (save-excursion
9555             (set-buffer gnus-article-buffer)
9556             ;;;!!! Fix this -- article should be rehighlighted.
9557             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9558             (set-buffer gnus-original-article-buffer)
9559             (gnus-request-article
9560              (cdr gnus-article-current)
9561              (car gnus-article-current) (current-buffer))))
9562         ;; Prettify the summary buffer line.
9563         (when (gnus-visual-p 'summary-highlight 'highlight)
9564           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9565
9566 (defun gnus-summary-edit-wash (key)
9567   "Perform editing command KEY in the article buffer."
9568   (interactive
9569    (list
9570     (progn
9571       (message "%s" (concat (this-command-keys) "- "))
9572       (read-char))))
9573   (message "")
9574   (gnus-summary-edit-article)
9575   (execute-kbd-macro (concat (this-command-keys) key))
9576   (gnus-article-edit-done))
9577
9578 ;;; Respooling
9579
9580 (defun gnus-summary-respool-query (&optional silent trace)
9581   "Query where the respool algorithm would put this article."
9582   (interactive)
9583   (let (gnus-mark-article-hook)
9584     (gnus-summary-select-article)
9585     (save-excursion
9586       (set-buffer gnus-original-article-buffer)
9587       (let ((groups (nnmail-article-group 'identity trace)))
9588         (unless silent
9589           (if groups
9590               (message "This message would go to %s"
9591                        (mapconcat 'car groups ", "))
9592             (message "This message would go to no groups"))
9593           groups)))))
9594
9595 (defun gnus-summary-respool-trace ()
9596   "Trace where the respool algorithm would put this article.
9597 Display a buffer showing all fancy splitting patterns which matched."
9598   (interactive)
9599   (gnus-summary-respool-query nil t))
9600
9601 ;; Summary marking commands.
9602
9603 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9604   "Mark articles which has the same subject as read, and then select the next.
9605 If UNMARK is positive, remove any kind of mark.
9606 If UNMARK is negative, tick articles."
9607   (interactive "P")
9608   (when unmark
9609     (setq unmark (prefix-numeric-value unmark)))
9610   (let ((count
9611          (gnus-summary-mark-same-subject
9612           (gnus-summary-article-subject) unmark)))
9613     ;; Select next unread article.  If auto-select-same mode, should
9614     ;; select the first unread article.
9615     (gnus-summary-next-article t (and gnus-auto-select-same
9616                                       (gnus-summary-article-subject)))
9617     (gnus-message 7 "%d article%s marked as %s"
9618                   count (if (= count 1) " is" "s are")
9619                   (if unmark "unread" "read"))))
9620
9621 (defun gnus-summary-kill-same-subject (&optional unmark)
9622   "Mark articles which has the same subject as read.
9623 If UNMARK is positive, remove any kind of mark.
9624 If UNMARK is negative, tick articles."
9625   (interactive "P")
9626   (when unmark
9627     (setq unmark (prefix-numeric-value unmark)))
9628   (let ((count
9629          (gnus-summary-mark-same-subject
9630           (gnus-summary-article-subject) unmark)))
9631     ;; If marked as read, go to next unread subject.
9632     (when (null unmark)
9633       ;; Go to next unread subject.
9634       (gnus-summary-next-subject 1 t))
9635     (gnus-message 7 "%d articles are marked as %s"
9636                   count (if unmark "unread" "read"))))
9637
9638 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9639   "Mark articles with same SUBJECT as read, and return marked number.
9640 If optional argument UNMARK is positive, remove any kinds of marks.
9641 If optional argument UNMARK is negative, mark articles as unread instead."
9642   (let ((count 1))
9643     (save-excursion
9644       (cond
9645        ((null unmark)                   ; Mark as read.
9646         (while (and
9647                 (progn
9648                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9649                   (gnus-summary-show-thread) t)
9650                 (gnus-summary-find-subject subject))
9651           (setq count (1+ count))))
9652        ((> unmark 0)                    ; Tick.
9653         (while (and
9654                 (progn
9655                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9656                   (gnus-summary-show-thread) t)
9657                 (gnus-summary-find-subject subject))
9658           (setq count (1+ count))))
9659        (t                               ; Mark as unread.
9660         (while (and
9661                 (progn
9662                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9663                   (gnus-summary-show-thread) t)
9664                 (gnus-summary-find-subject subject))
9665           (setq count (1+ count)))))
9666       (gnus-set-mode-line 'summary)
9667       ;; Return the number of marked articles.
9668       count)))
9669
9670 (defun gnus-summary-mark-as-processable (n &optional unmark)
9671   "Set the process mark on the next N articles.
9672 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9673 the process mark instead.  The difference between N and the actual
9674 number of articles marked is returned."
9675   (interactive "P")
9676   (if (and (null n) (gnus-region-active-p))
9677       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9678     (setq n (prefix-numeric-value n))
9679     (let ((backward (< n 0))
9680           (n (abs n)))
9681       (while (and
9682               (> n 0)
9683               (if unmark
9684                   (gnus-summary-remove-process-mark
9685                    (gnus-summary-article-number))
9686                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9687               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9688         (setq n (1- n)))
9689       (when (/= 0 n)
9690         (gnus-message 7 "No more articles"))
9691       (gnus-summary-recenter)
9692       (gnus-summary-position-point)
9693       n)))
9694
9695 (defun gnus-summary-unmark-as-processable (n)
9696   "Remove the process mark from the next N articles.
9697 If N is negative, unmark backward instead.  The difference between N and
9698 the actual number of articles unmarked is returned."
9699   (interactive "P")
9700   (gnus-summary-mark-as-processable n t))
9701
9702 (defun gnus-summary-unmark-all-processable ()
9703   "Remove the process mark from all articles."
9704   (interactive)
9705   (save-excursion
9706     (while gnus-newsgroup-processable
9707       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9708   (gnus-summary-position-point))
9709
9710 (defun gnus-summary-add-mark (article type)
9711   "Mark ARTICLE with a mark of TYPE."
9712   (let ((vtype (car (assq type gnus-article-mark-lists)))
9713         var)
9714     (if (not vtype)
9715         (error "No such mark type: %s" type)
9716       (setq var (intern (format "gnus-newsgroup-%s" type)))
9717       (set var (cons article (symbol-value var)))
9718       (if (memq type '(processable cached replied forwarded recent saved))
9719           (gnus-summary-update-secondary-mark article)
9720         ;;; !!! This is bogus.  We should find out what primary
9721         ;;; !!! mark we want to set.
9722         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9723
9724 (defun gnus-summary-mark-as-expirable (n)
9725   "Mark N articles forward as expirable.
9726 If N is negative, mark backward instead.  The difference between N and
9727 the actual number of articles marked is returned."
9728   (interactive "p")
9729   (gnus-summary-mark-forward n gnus-expirable-mark))
9730
9731 (defun gnus-summary-mark-as-spam (n)
9732   "Mark N articles forward as spam.
9733 If N is negative, mark backward instead.  The difference between N and
9734 the actual number of articles marked is returned."
9735   (interactive "p")
9736   (gnus-summary-mark-forward n gnus-spam-mark))
9737
9738 (defun gnus-summary-mark-article-as-replied (article)
9739   "Mark ARTICLE as replied to and update the summary line.
9740 ARTICLE can also be a list of articles."
9741   (interactive (list (gnus-summary-article-number)))
9742   (let ((articles (if (listp article) article (list article))))
9743     (dolist (article articles)
9744       (unless (numberp article)
9745         (error "%s is not a number" article))
9746       (push article gnus-newsgroup-replied)
9747       (let ((buffer-read-only nil))
9748         (when (gnus-summary-goto-subject article nil t)
9749           (gnus-summary-update-secondary-mark article))))))
9750
9751 (defun gnus-summary-mark-article-as-forwarded (article)
9752   "Mark ARTICLE as forwarded and update the summary line.
9753 ARTICLE can also be a list of articles."
9754   (let ((articles (if (listp article) article (list article))))
9755     (dolist (article articles)
9756       (push article gnus-newsgroup-forwarded)
9757       (let ((buffer-read-only nil))
9758         (when (gnus-summary-goto-subject article nil t)
9759           (gnus-summary-update-secondary-mark article))))))
9760
9761 (defun gnus-summary-set-bookmark (article)
9762   "Set a bookmark in current article."
9763   (interactive (list (gnus-summary-article-number)))
9764   (when (or (not (get-buffer gnus-article-buffer))
9765             (not gnus-current-article)
9766             (not gnus-article-current)
9767             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9768     (error "No current article selected"))
9769   ;; Remove old bookmark, if one exists.
9770   (gnus-pull article gnus-newsgroup-bookmarks)
9771   ;; Set the new bookmark, which is on the form
9772   ;; (article-number . line-number-in-body).
9773   (push
9774    (cons article
9775          (save-excursion
9776            (set-buffer gnus-article-buffer)
9777            (count-lines
9778             (min (point)
9779                  (save-excursion
9780                    (article-goto-body)
9781                    (point)))
9782             (point))))
9783    gnus-newsgroup-bookmarks)
9784   (gnus-message 6 "A bookmark has been added to the current article."))
9785
9786 (defun gnus-summary-remove-bookmark (article)
9787   "Remove the bookmark from the current article."
9788   (interactive (list (gnus-summary-article-number)))
9789   ;; Remove old bookmark, if one exists.
9790   (if (not (assq article gnus-newsgroup-bookmarks))
9791       (gnus-message 6 "No bookmark in current article.")
9792     (gnus-pull article gnus-newsgroup-bookmarks)
9793     (gnus-message 6 "Removed bookmark.")))
9794
9795 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9796 (defun gnus-summary-mark-as-dormant (n)
9797   "Mark N articles forward as dormant.
9798 If N is negative, mark backward instead.  The difference between N and
9799 the actual number of articles marked is returned."
9800   (interactive "p")
9801   (gnus-summary-mark-forward n gnus-dormant-mark))
9802
9803 (defun gnus-summary-set-process-mark (article)
9804   "Set the process mark on ARTICLE and update the summary line."
9805   (setq gnus-newsgroup-processable
9806         (cons article
9807               (delq article gnus-newsgroup-processable)))
9808   (when (gnus-summary-goto-subject article)
9809     (gnus-summary-show-thread)
9810     (gnus-summary-goto-subject article)
9811     (gnus-summary-update-secondary-mark article)))
9812
9813 (defun gnus-summary-remove-process-mark (article)
9814   "Remove the process mark from ARTICLE and update the summary line."
9815   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9816   (when (gnus-summary-goto-subject article)
9817     (gnus-summary-show-thread)
9818     (gnus-summary-goto-subject article)
9819     (gnus-summary-update-secondary-mark article)))
9820
9821 (defun gnus-summary-set-saved-mark (article)
9822   "Set the process mark on ARTICLE and update the summary line."
9823   (push article gnus-newsgroup-saved)
9824   (when (gnus-summary-goto-subject article)
9825     (gnus-summary-update-secondary-mark article)))
9826
9827 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9828   "Mark N articles as read forwards.
9829 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9830 The difference between N and the actual number of articles marked is
9831 returned.
9832 If NO-EXPIRE, auto-expiry will be inhibited."
9833   (interactive "p")
9834   (gnus-summary-show-thread)
9835   (let ((backward (< n 0))
9836         (gnus-summary-goto-unread
9837          (and gnus-summary-goto-unread
9838               (not (eq gnus-summary-goto-unread 'never))
9839               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9840                                     gnus-ticked-mark gnus-dormant-mark)))))
9841         (n (abs n))
9842         (mark (or mark gnus-del-mark)))
9843     (while (and (> n 0)
9844                 (gnus-summary-mark-article nil mark no-expire)
9845                 (zerop (gnus-summary-next-subject
9846                         (if backward -1 1)
9847                         (and gnus-summary-goto-unread
9848                              (not (eq gnus-summary-goto-unread 'never)))
9849                         t)))
9850       (setq n (1- n)))
9851     (when (/= 0 n)
9852       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9853     (gnus-summary-recenter)
9854     (gnus-summary-position-point)
9855     (gnus-set-mode-line 'summary)
9856     n))
9857
9858 (defun gnus-summary-mark-article-as-read (mark)
9859   "Mark the current article quickly as read with MARK."
9860   (let ((article (gnus-summary-article-number)))
9861     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9862     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9863     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9864     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9865     (push (cons article mark) gnus-newsgroup-reads)
9866     ;; Possibly remove from cache, if that is used.
9867     (when gnus-use-cache
9868       (gnus-cache-enter-remove-article article))
9869     ;; Allow the backend to change the mark.
9870     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9871     ;; Check for auto-expiry.
9872     (when (and gnus-newsgroup-auto-expire
9873                (memq mark gnus-auto-expirable-marks))
9874       (setq mark gnus-expirable-mark)
9875       ;; Let the backend know about the mark change.
9876       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9877       (push article gnus-newsgroup-expirable))
9878     ;; Set the mark in the buffer.
9879     (gnus-summary-update-mark mark 'unread)
9880     t))
9881
9882 (defun gnus-summary-mark-article-as-unread (mark)
9883   "Mark the current article quickly as unread with MARK."
9884   (let* ((article (gnus-summary-article-number))
9885          (old-mark (gnus-summary-article-mark article)))
9886     ;; Allow the backend to change the mark.
9887     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9888     (if (eq mark old-mark)
9889         t
9890       (if (<= article 0)
9891           (progn
9892             (gnus-error 1 "Can't mark negative article numbers")
9893             nil)
9894         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9895         (setq gnus-newsgroup-spam-marked
9896               (delq article gnus-newsgroup-spam-marked))
9897         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9898         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9899         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9900         (cond ((= mark gnus-ticked-mark)
9901                (setq gnus-newsgroup-marked
9902                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9903                                               article)))
9904               ((= mark gnus-spam-mark)
9905                (setq gnus-newsgroup-spam-marked
9906                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9907                                               article)))
9908               ((= mark gnus-dormant-mark)
9909                (setq gnus-newsgroup-dormant
9910                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9911                                               article)))
9912               (t
9913                (setq gnus-newsgroup-unreads
9914                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9915                                               article))))
9916         (gnus-pull article gnus-newsgroup-reads)
9917
9918         ;; See whether the article is to be put in the cache.
9919         (and gnus-use-cache
9920              (vectorp (gnus-summary-article-header article))
9921              (save-excursion
9922                (gnus-cache-possibly-enter-article
9923                 gnus-newsgroup-name article
9924                 (gnus-summary-article-header article)
9925                 (= mark gnus-ticked-mark)
9926                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9927
9928         ;; Fix the mark.
9929         (gnus-summary-update-mark mark 'unread)
9930         t))))
9931
9932 (defun gnus-summary-mark-article (&optional article mark no-expire)
9933   "Mark ARTICLE with MARK.  MARK can be any character.
9934 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9935 `??' (dormant) and `?E' (expirable).
9936 If MARK is nil, then the default character `?r' is used.
9937 If ARTICLE is nil, then the article on the current line will be
9938 marked.
9939 If NO-EXPIRE, auto-expiry will be inhibited."
9940   ;; The mark might be a string.
9941   (when (stringp mark)
9942     (setq mark (aref mark 0)))
9943   ;; If no mark is given, then we check auto-expiring.
9944   (when (null mark)
9945     (setq mark gnus-del-mark))
9946   (when (and (not no-expire)
9947              gnus-newsgroup-auto-expire
9948              (memq mark gnus-auto-expirable-marks))
9949     (setq mark gnus-expirable-mark))
9950   (let ((article (or article (gnus-summary-article-number)))
9951         (old-mark (gnus-summary-article-mark article)))
9952     ;; Allow the backend to change the mark.
9953     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9954     (if (eq mark old-mark)
9955         t
9956       (unless article
9957         (error "No article on current line"))
9958       (if (not (if (or (= mark gnus-unread-mark)
9959                        (= mark gnus-ticked-mark)
9960                        (= mark gnus-spam-mark)
9961                        (= mark gnus-dormant-mark))
9962                    (gnus-mark-article-as-unread article mark)
9963                  (gnus-mark-article-as-read article mark)))
9964           t
9965         ;; See whether the article is to be put in the cache.
9966         (and gnus-use-cache
9967              (not (= mark gnus-canceled-mark))
9968              (vectorp (gnus-summary-article-header article))
9969              (save-excursion
9970                (gnus-cache-possibly-enter-article
9971                 gnus-newsgroup-name article
9972                 (gnus-summary-article-header article)
9973                 (= mark gnus-ticked-mark)
9974                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9975
9976         (when (gnus-summary-goto-subject article nil t)
9977           (let ((buffer-read-only nil))
9978             (gnus-summary-show-thread)
9979             ;; Fix the mark.
9980             (gnus-summary-update-mark mark 'unread)
9981             t))))))
9982
9983 (defun gnus-summary-update-secondary-mark (article)
9984   "Update the secondary (read, process, cache) mark."
9985   (gnus-summary-update-mark
9986    (cond ((memq article gnus-newsgroup-processable)
9987           gnus-process-mark)
9988          ((memq article gnus-newsgroup-cached)
9989           gnus-cached-mark)
9990          ((memq article gnus-newsgroup-replied)
9991           gnus-replied-mark)
9992          ((memq article gnus-newsgroup-forwarded)
9993           gnus-forwarded-mark)
9994          ((memq article gnus-newsgroup-saved)
9995           gnus-saved-mark)
9996          ((memq article gnus-newsgroup-recent)
9997           gnus-recent-mark)
9998          ((memq article gnus-newsgroup-unseen)
9999           gnus-unseen-mark)
10000          (t gnus-no-mark))
10001    'replied)
10002   (when (gnus-visual-p 'summary-highlight 'highlight)
10003     (gnus-run-hooks 'gnus-summary-update-hook))
10004   t)
10005
10006 (defun gnus-summary-update-download-mark (article)
10007   "Update the download mark."
10008   (gnus-summary-update-mark
10009    (cond ((memq article gnus-newsgroup-undownloaded)
10010           gnus-undownloaded-mark)
10011          (gnus-newsgroup-agentized
10012           gnus-downloaded-mark)
10013          (t
10014           gnus-no-mark))
10015    'download)
10016   (gnus-summary-update-line t)
10017   t)
10018
10019 (defun gnus-summary-update-mark (mark type)
10020   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10021         (buffer-read-only nil))
10022     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10023     (when forward
10024       (when (looking-at "\r")
10025         (incf forward))
10026       (when (<= (+ forward (point)) (point-max))
10027         ;; Go to the right position on the line.
10028         (goto-char (+ forward (point)))
10029         ;; Replace the old mark with the new mark.
10030         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10031         ;; Optionally update the marks by some user rule.
10032         (when (eq type 'unread)
10033           (gnus-data-set-mark
10034            (gnus-data-find (gnus-summary-article-number)) mark)
10035           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10036
10037 (defun gnus-mark-article-as-read (article &optional mark)
10038   "Enter ARTICLE in the pertinent lists and remove it from others."
10039   ;; Make the article expirable.
10040   (let ((mark (or mark gnus-del-mark)))
10041     (setq gnus-newsgroup-expirable
10042           (if (= mark gnus-expirable-mark)
10043               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10044             (delq article gnus-newsgroup-expirable)))
10045     ;; Remove from unread and marked lists.
10046     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10047     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10048     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10049     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10050     (push (cons article mark) gnus-newsgroup-reads)
10051     ;; Possibly remove from cache, if that is used.
10052     (when gnus-use-cache
10053       (gnus-cache-enter-remove-article article))
10054     t))
10055
10056 (defun gnus-mark-article-as-unread (article &optional mark)
10057   "Enter ARTICLE in the pertinent lists and remove it from others."
10058   (let ((mark (or mark gnus-ticked-mark)))
10059     (if (<= article 0)
10060         (progn
10061           (gnus-error 1 "Can't mark negative article numbers")
10062           nil)
10063       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10064             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10065             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10066             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10067             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10068
10069       ;; Unsuppress duplicates?
10070       (when gnus-suppress-duplicates
10071         (gnus-dup-unsuppress-article article))
10072
10073       (cond ((= mark gnus-ticked-mark)
10074              (setq gnus-newsgroup-marked
10075                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10076             ((= mark gnus-spam-mark)
10077              (setq gnus-newsgroup-spam-marked
10078                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10079                                             article)))
10080             ((= mark gnus-dormant-mark)
10081              (setq gnus-newsgroup-dormant
10082                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10083             (t
10084              (setq gnus-newsgroup-unreads
10085                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10086       (gnus-pull article gnus-newsgroup-reads)
10087       t)))
10088
10089 (defalias 'gnus-summary-mark-as-unread-forward
10090   'gnus-summary-tick-article-forward)
10091 (make-obsolete 'gnus-summary-mark-as-unread-forward
10092                'gnus-summary-tick-article-forward)
10093 (defun gnus-summary-tick-article-forward (n)
10094   "Tick N articles forwards.
10095 If N is negative, tick backwards instead.
10096 The difference between N and the number of articles ticked is returned."
10097   (interactive "p")
10098   (gnus-summary-mark-forward n gnus-ticked-mark))
10099
10100 (defalias 'gnus-summary-mark-as-unread-backward
10101   'gnus-summary-tick-article-backward)
10102 (make-obsolete 'gnus-summary-mark-as-unread-backward
10103                'gnus-summary-tick-article-backward)
10104 (defun gnus-summary-tick-article-backward (n)
10105   "Tick N articles backwards.
10106 The difference between N and the number of articles ticked is returned."
10107   (interactive "p")
10108   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10109
10110 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10111 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10112 (defun gnus-summary-tick-article (&optional article clear-mark)
10113   "Mark current article as unread.
10114 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10115 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10116   (interactive)
10117   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10118                                        gnus-ticked-mark)))
10119
10120 (defun gnus-summary-mark-as-read-forward (n)
10121   "Mark N articles as read forwards.
10122 If N is negative, mark backwards instead.
10123 The difference between N and the actual number of articles marked is
10124 returned."
10125   (interactive "p")
10126   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10127
10128 (defun gnus-summary-mark-as-read-backward (n)
10129   "Mark the N articles as read backwards.
10130 The difference between N and the actual number of articles marked is
10131 returned."
10132   (interactive "p")
10133   (gnus-summary-mark-forward
10134    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10135
10136 (defun gnus-summary-mark-as-read (&optional article mark)
10137   "Mark current article as read.
10138 ARTICLE specifies the article to be marked as read.
10139 MARK specifies a string to be inserted at the beginning of the line."
10140   (gnus-summary-mark-article article mark))
10141
10142 (defun gnus-summary-clear-mark-forward (n)
10143   "Clear marks from N articles forward.
10144 If N is negative, clear backward instead.
10145 The difference between N and the number of marks cleared is returned."
10146   (interactive "p")
10147   (gnus-summary-mark-forward n gnus-unread-mark))
10148
10149 (defun gnus-summary-clear-mark-backward (n)
10150   "Clear marks from N articles backward.
10151 The difference between N and the number of marks cleared is returned."
10152   (interactive "p")
10153   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10154
10155 (defun gnus-summary-mark-unread-as-read ()
10156   "Intended to be used by `gnus-summary-mark-article-hook'."
10157   (when (memq gnus-current-article gnus-newsgroup-unreads)
10158     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10159
10160 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10161   "Intended to be used by `gnus-summary-mark-article-hook'."
10162   (let ((mark (gnus-summary-article-mark)))
10163     (when (or (gnus-unread-mark-p mark)
10164               (gnus-read-mark-p mark))
10165       (gnus-summary-mark-article gnus-current-article
10166                                  (or new-mark gnus-read-mark)))))
10167
10168 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10169   "Intended to be used by `gnus-summary-mark-article-hook'."
10170   (let ((mark (gnus-summary-article-mark)))
10171     (when (or (gnus-unread-mark-p mark)
10172               (gnus-read-mark-p mark))
10173       (gnus-summary-mark-article (gnus-summary-article-number)
10174                                  (or new-mark gnus-read-mark)))))
10175
10176 (defun gnus-summary-mark-unread-as-ticked ()
10177   "Intended to be used by `gnus-summary-mark-article-hook'."
10178   (when (memq gnus-current-article gnus-newsgroup-unreads)
10179     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10180
10181 (defun gnus-summary-mark-region-as-read (point mark all)
10182   "Mark all unread articles between point and mark as read.
10183 If given a prefix, mark all articles between point and mark as read,
10184 even ticked and dormant ones."
10185   (interactive "r\nP")
10186   (save-excursion
10187     (let (article)
10188       (goto-char point)
10189       (beginning-of-line)
10190       (while (and
10191               (< (point) mark)
10192               (progn
10193                 (when (or all
10194                           (memq (setq article (gnus-summary-article-number))
10195                                 gnus-newsgroup-unreads))
10196                   (gnus-summary-mark-article article gnus-del-mark))
10197                 t)
10198               (gnus-summary-find-next))))))
10199
10200 (defun gnus-summary-mark-below (score mark)
10201   "Mark articles with score less than SCORE with MARK."
10202   (interactive "P\ncMark: ")
10203   (setq score (if score
10204                   (prefix-numeric-value score)
10205                 (or gnus-summary-default-score 0)))
10206   (save-excursion
10207     (set-buffer gnus-summary-buffer)
10208     (goto-char (point-min))
10209     (while
10210         (progn
10211           (and (< (gnus-summary-article-score) score)
10212                (gnus-summary-mark-article nil mark))
10213           (gnus-summary-find-next)))))
10214
10215 (defun gnus-summary-kill-below (&optional score)
10216   "Mark articles with score below SCORE as read."
10217   (interactive "P")
10218   (gnus-summary-mark-below score gnus-killed-mark))
10219
10220 (defun gnus-summary-clear-above (&optional score)
10221   "Clear all marks from articles with score above SCORE."
10222   (interactive "P")
10223   (gnus-summary-mark-above score gnus-unread-mark))
10224
10225 (defun gnus-summary-tick-above (&optional score)
10226   "Tick all articles with score above SCORE."
10227   (interactive "P")
10228   (gnus-summary-mark-above score gnus-ticked-mark))
10229
10230 (defun gnus-summary-mark-above (score mark)
10231   "Mark articles with score over SCORE with MARK."
10232   (interactive "P\ncMark: ")
10233   (setq score (if score
10234                   (prefix-numeric-value score)
10235                 (or gnus-summary-default-score 0)))
10236   (save-excursion
10237     (set-buffer gnus-summary-buffer)
10238     (goto-char (point-min))
10239     (while (and (progn
10240                   (when (> (gnus-summary-article-score) score)
10241                     (gnus-summary-mark-article nil mark))
10242                   t)
10243                 (gnus-summary-find-next)))))
10244
10245 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10246 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10247 (defun gnus-summary-limit-include-expunged (&optional no-error)
10248   "Display all the hidden articles that were expunged for low scores."
10249   (interactive)
10250   (let ((buffer-read-only nil))
10251     (let ((scored gnus-newsgroup-scored)
10252           headers h)
10253       (while scored
10254         (unless (gnus-summary-article-header (caar scored))
10255           (and (setq h (gnus-number-to-header (caar scored)))
10256                (< (cdar scored) gnus-summary-expunge-below)
10257                (push h headers)))
10258         (setq scored (cdr scored)))
10259       (if (not headers)
10260           (when (not no-error)
10261             (error "No expunged articles hidden"))
10262         (goto-char (point-min))
10263         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10264         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10265         (mapcar (lambda (x) (push (mail-header-number x)
10266                                   gnus-newsgroup-limit))
10267                 headers)
10268         (gnus-summary-prepare-unthreaded (nreverse headers))
10269         (goto-char (point-min))
10270         (gnus-summary-position-point)
10271         t))))
10272
10273 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10274   "Mark all unread articles in this newsgroup as read.
10275 If prefix argument ALL is non-nil, ticked and dormant articles will
10276 also be marked as read.
10277 If QUIETLY is non-nil, no questions will be asked.
10278
10279 If TO-HERE is non-nil, it should be a point in the buffer.  All
10280 articles before (after, if REVERSE is set) this point will be marked
10281 as read.
10282
10283 Note that this function will only catch up the unread article
10284 in the current summary buffer limitation.
10285
10286 The number of articles marked as read is returned."
10287   (interactive "P")
10288   (prog1
10289       (save-excursion
10290         (when (or quietly
10291                   (not gnus-interactive-catchup) ;Without confirmation?
10292                   gnus-expert-user
10293                   (gnus-y-or-n-p
10294                    (if all
10295                        "Mark absolutely all articles as read? "
10296                      "Mark all unread articles as read? ")))
10297           (if (and not-mark
10298                    (not gnus-newsgroup-adaptive)
10299                    (not gnus-newsgroup-auto-expire)
10300                    (not gnus-suppress-duplicates)
10301                    (or (not gnus-use-cache)
10302                        (eq gnus-use-cache 'passive)))
10303               (progn
10304                 (when all
10305                   (setq gnus-newsgroup-marked nil
10306                         gnus-newsgroup-spam-marked nil
10307                         gnus-newsgroup-dormant nil))
10308                 (setq gnus-newsgroup-unreads
10309                       (gnus-sorted-nunion
10310                        (gnus-intersection gnus-newsgroup-unreads
10311                                           gnus-newsgroup-downloadable)
10312                        gnus-newsgroup-unfetched)))
10313             ;; We actually mark all articles as canceled, which we
10314             ;; have to do when using auto-expiry or adaptive scoring.
10315             (gnus-summary-show-all-threads)
10316             (if (and to-here reverse)
10317                 (progn
10318                   (goto-char to-here)
10319                   (gnus-summary-mark-current-read-and-unread-as-read
10320                    gnus-catchup-mark)
10321                   (while (gnus-summary-find-next (not all))
10322                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10323               (when (gnus-summary-first-subject (not all))
10324                 (while (and
10325                         (if to-here (< (point) to-here) t)
10326                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10327                         (gnus-summary-find-next (not all))))))
10328             (gnus-set-mode-line 'summary))
10329           t))
10330     (gnus-summary-position-point)))
10331
10332 (defun gnus-summary-catchup-to-here (&optional all)
10333   "Mark all unticked articles before the current one as read.
10334 If ALL is non-nil, also mark ticked and dormant articles as read."
10335   (interactive "P")
10336   (save-excursion
10337     (gnus-save-hidden-threads
10338       (let ((beg (point)))
10339         ;; We check that there are unread articles.
10340         (when (or all (gnus-summary-find-prev))
10341           (gnus-summary-catchup all t beg)))))
10342   (gnus-summary-position-point))
10343
10344 (defun gnus-summary-catchup-from-here (&optional all)
10345   "Mark all unticked articles after (and including) the current one as read.
10346 If ALL is non-nil, also mark ticked and dormant articles as read."
10347   (interactive "P")
10348   (save-excursion
10349     (gnus-save-hidden-threads
10350       (let ((beg (point)))
10351         ;; We check that there are unread articles.
10352         (when (or all (gnus-summary-find-next))
10353           (gnus-summary-catchup all t beg nil t)))))
10354   (gnus-summary-position-point))
10355
10356 (defun gnus-summary-catchup-all (&optional quietly)
10357   "Mark all articles in this newsgroup as read.
10358 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10359 instead, which marks only unread articles as read."
10360   (interactive "P")
10361   (gnus-summary-catchup t quietly))
10362
10363 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10364   "Mark all unread articles in this group as read, then exit.
10365 If prefix argument ALL is non-nil, all articles are marked as read.
10366 If QUIETLY is non-nil, no questions will be asked."
10367   (interactive "P")
10368   (when (gnus-summary-catchup all quietly nil 'fast)
10369     ;; Select next newsgroup or exit.
10370     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10371              (eq gnus-auto-select-next 'quietly))
10372         (gnus-summary-next-group nil)
10373       (gnus-summary-exit))))
10374
10375 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10376   "Mark all articles in this newsgroup as read, and then exit.
10377 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10378 instead, which marks only unread articles as read."
10379   (interactive "P")
10380   (gnus-summary-catchup-and-exit t quietly))
10381
10382 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10383   "Mark all articles in this group as read and select the next group.
10384 If given a prefix, mark all articles, unread as well as ticked, as
10385 read."
10386   (interactive "P")
10387   (save-excursion
10388     (gnus-summary-catchup all))
10389   (gnus-summary-next-group))
10390
10391 ;;;
10392 ;;; with article
10393 ;;;
10394
10395 (defmacro gnus-with-article (article &rest forms)
10396   "Select ARTICLE and perform FORMS in the original article buffer.
10397 Then replace the article with the result."
10398   `(progn
10399      ;; We don't want the article to be marked as read.
10400      (let (gnus-mark-article-hook)
10401        (gnus-summary-select-article t t nil ,article))
10402      (set-buffer gnus-original-article-buffer)
10403      ,@forms
10404      (if (not (gnus-check-backend-function
10405                'request-replace-article (car gnus-article-current)))
10406          (gnus-message 5 "Read-only group; not replacing")
10407        (unless (gnus-request-replace-article
10408                 ,article (car gnus-article-current)
10409                 (current-buffer) t)
10410          (error "Couldn't replace article")))
10411      ;; The cache and backlog have to be flushed somewhat.
10412      (when gnus-keep-backlog
10413        (gnus-backlog-remove-article
10414         (car gnus-article-current) (cdr gnus-article-current)))
10415      (when gnus-use-cache
10416        (gnus-cache-update-article
10417         (car gnus-article-current) (cdr gnus-article-current)))))
10418
10419 (put 'gnus-with-article 'lisp-indent-function 1)
10420 (put 'gnus-with-article 'edebug-form-spec '(form body))
10421
10422 ;; Thread-based commands.
10423
10424 (defun gnus-summary-articles-in-thread (&optional article)
10425   "Return a list of all articles in the current thread.
10426 If ARTICLE is non-nil, return all articles in the thread that starts
10427 with that article."
10428   (let* ((article (or article (gnus-summary-article-number)))
10429          (data (gnus-data-find-list article))
10430          (top-level (gnus-data-level (car data)))
10431          (top-subject
10432           (cond ((null gnus-thread-operation-ignore-subject)
10433                  (gnus-simplify-subject-re
10434                   (mail-header-subject (gnus-data-header (car data)))))
10435                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10436                  (gnus-simplify-subject-fuzzy
10437                   (mail-header-subject (gnus-data-header (car data)))))
10438                 (t nil)))
10439          (end-point (save-excursion
10440                       (if (gnus-summary-go-to-next-thread)
10441                           (point) (point-max))))
10442          articles)
10443     (while (and data
10444                 (< (gnus-data-pos (car data)) end-point))
10445       (when (or (not top-subject)
10446                 (string= top-subject
10447                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10448                              (gnus-simplify-subject-fuzzy
10449                               (mail-header-subject
10450                                (gnus-data-header (car data))))
10451                            (gnus-simplify-subject-re
10452                             (mail-header-subject
10453                              (gnus-data-header (car data)))))))
10454         (push (gnus-data-number (car data)) articles))
10455       (unless (and (setq data (cdr data))
10456                    (> (gnus-data-level (car data)) top-level))
10457         (setq data nil)))
10458     ;; Return the list of articles.
10459     (nreverse articles)))
10460
10461 (defun gnus-summary-rethread-current ()
10462   "Rethread the thread the current article is part of."
10463   (interactive)
10464   (let* ((gnus-show-threads t)
10465          (article (gnus-summary-article-number))
10466          (id (mail-header-id (gnus-summary-article-header)))
10467          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10468     (unless id
10469       (error "No article on the current line"))
10470     (gnus-rebuild-thread id)
10471     (gnus-summary-goto-subject article)))
10472
10473 (defun gnus-summary-reparent-thread ()
10474   "Make the current article child of the marked (or previous) article.
10475
10476 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10477 is non-nil or the Subject: of both articles are the same."
10478   (interactive)
10479   (unless (not (gnus-group-read-only-p))
10480     (error "The current newsgroup does not support article editing"))
10481   (unless (<= (length gnus-newsgroup-processable) 1)
10482     (error "No more than one article may be marked"))
10483   (save-window-excursion
10484     (let ((gnus-article-buffer " *reparent*")
10485           (current-article (gnus-summary-article-number))
10486           ;; First grab the marked article, otherwise one line up.
10487           (parent-article (if (not (null gnus-newsgroup-processable))
10488                               (car gnus-newsgroup-processable)
10489                             (save-excursion
10490                               (if (eq (forward-line -1) 0)
10491                                   (gnus-summary-article-number)
10492                                 (error "Beginning of summary buffer"))))))
10493       (unless (not (eq current-article parent-article))
10494         (error "An article may not be self-referential"))
10495       (let ((message-id (mail-header-id
10496                          (gnus-summary-article-header parent-article))))
10497         (unless (and message-id (not (equal message-id "")))
10498           (error "No message-id in desired parent"))
10499         (gnus-with-article current-article
10500           (save-restriction
10501             (goto-char (point-min))
10502             (message-narrow-to-head)
10503             (if (re-search-forward "^References: " nil t)
10504                 (progn
10505                   (re-search-forward "^[^ \t]" nil t)
10506                   (forward-line -1)
10507                   (end-of-line)
10508                   (insert " " message-id))
10509               (insert "References: " message-id "\n"))))
10510         (set-buffer gnus-summary-buffer)
10511         (gnus-summary-unmark-all-processable)
10512         (gnus-summary-update-article current-article)
10513         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10514             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10515         (gnus-summary-rethread-current)
10516         (gnus-message 3 "Article %d is now the child of article %d"
10517                       current-article parent-article)))))
10518
10519 (defun gnus-summary-toggle-threads (&optional arg)
10520   "Toggle showing conversation threads.
10521 If ARG is positive number, turn showing conversation threads on."
10522   (interactive "P")
10523   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10524     (setq gnus-show-threads
10525           (if (null arg) (not gnus-show-threads)
10526             (> (prefix-numeric-value arg) 0)))
10527     (gnus-summary-prepare)
10528     (gnus-summary-goto-subject current)
10529     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10530     (gnus-summary-position-point)))
10531
10532 (defun gnus-summary-show-all-threads ()
10533   "Show all threads."
10534   (interactive)
10535   (save-excursion
10536     (let ((buffer-read-only nil))
10537       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10538   (gnus-summary-position-point))
10539
10540 (defun gnus-summary-show-thread ()
10541   "Show thread subtrees.
10542 Returns nil if no thread was there to be shown."
10543   (interactive)
10544   (let ((buffer-read-only nil)
10545         (orig (point))
10546         (end (point-at-eol))
10547         ;; Leave point at bol
10548         (beg (progn (beginning-of-line) (point))))
10549     (prog1
10550         ;; Any hidden lines here?
10551         (search-forward "\r" end t)
10552       (subst-char-in-region beg end ?\^M ?\n t)
10553       (goto-char orig)
10554       (gnus-summary-position-point))))
10555
10556 (defun gnus-summary-maybe-hide-threads ()
10557   "If requested, hide the threads that should be hidden."
10558   (when (and gnus-show-threads
10559              gnus-thread-hide-subtree)
10560     (gnus-summary-hide-all-threads
10561      (if (or (consp gnus-thread-hide-subtree)
10562              (functionp gnus-thread-hide-subtree))
10563          (gnus-make-predicate gnus-thread-hide-subtree)
10564        nil))))
10565
10566 ;;; Hiding predicates.
10567
10568 (defun gnus-article-unread-p (header)
10569   (memq (mail-header-number header) gnus-newsgroup-unreads))
10570
10571 (defun gnus-article-unseen-p (header)
10572   (memq (mail-header-number header) gnus-newsgroup-unseen))
10573
10574 (defun gnus-map-articles (predicate articles)
10575   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10576   (apply 'gnus-or (mapcar predicate
10577                           (mapcar 'gnus-summary-article-header articles))))
10578
10579 (defun gnus-summary-hide-all-threads (&optional predicate)
10580   "Hide all thread subtrees.
10581 If PREDICATE is supplied, threads that satisfy this predicate
10582 will not be hidden."
10583   (interactive)
10584   (save-excursion
10585     (goto-char (point-min))
10586     (let ((end nil))
10587       (while (not end)
10588         (when (or (not predicate)
10589                   (gnus-map-articles
10590                    predicate (gnus-summary-article-children)))
10591             (gnus-summary-hide-thread))
10592         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10593   (gnus-summary-position-point))
10594
10595 (defun gnus-summary-hide-thread ()
10596   "Hide thread subtrees.
10597 If PREDICATE is supplied, threads that satisfy this predicate
10598 will not be hidden.
10599 Returns nil if no threads were there to be hidden."
10600   (interactive)
10601   (let ((buffer-read-only nil)
10602         (start (point))
10603         (article (gnus-summary-article-number)))
10604     (goto-char start)
10605     ;; Go forward until either the buffer ends or the subthread
10606     ;; ends.
10607     (when (and (not (eobp))
10608                (or (zerop (gnus-summary-next-thread 1 t))
10609                    (goto-char (point-max))))
10610       (prog1
10611           (if (and (> (point) start)
10612                    (search-backward "\n" start t))
10613               (progn
10614                 (subst-char-in-region start (point) ?\n ?\^M)
10615                 (gnus-summary-goto-subject article))
10616             (goto-char start)
10617             nil)))))
10618
10619 (defun gnus-summary-go-to-next-thread (&optional previous)
10620   "Go to the same level (or less) next thread.
10621 If PREVIOUS is non-nil, go to previous thread instead.
10622 Return the article number moved to, or nil if moving was impossible."
10623   (let ((level (gnus-summary-thread-level))
10624         (way (if previous -1 1))
10625         (beg (point)))
10626     (forward-line way)
10627     (while (and (not (eobp))
10628                 (< level (gnus-summary-thread-level)))
10629       (forward-line way))
10630     (if (eobp)
10631         (progn
10632           (goto-char beg)
10633           nil)
10634       (setq beg (point))
10635       (prog1
10636           (gnus-summary-article-number)
10637         (goto-char beg)))))
10638
10639 (defun gnus-summary-next-thread (n &optional silent)
10640   "Go to the same level next N'th thread.
10641 If N is negative, search backward instead.
10642 Returns the difference between N and the number of skips actually
10643 done.
10644
10645 If SILENT, don't output messages."
10646   (interactive "p")
10647   (let ((backward (< n 0))
10648         (n (abs n)))
10649     (while (and (> n 0)
10650                 (gnus-summary-go-to-next-thread backward))
10651       (decf n))
10652     (unless silent
10653       (gnus-summary-position-point))
10654     (when (and (not silent) (/= 0 n))
10655       (gnus-message 7 "No more threads"))
10656     n))
10657
10658 (defun gnus-summary-prev-thread (n)
10659   "Go to the same level previous N'th thread.
10660 Returns the difference between N and the number of skips actually
10661 done."
10662   (interactive "p")
10663   (gnus-summary-next-thread (- n)))
10664
10665 (defun gnus-summary-go-down-thread ()
10666   "Go down one level in the current thread."
10667   (let ((children (gnus-summary-article-children)))
10668     (when children
10669       (gnus-summary-goto-subject (car children)))))
10670
10671 (defun gnus-summary-go-up-thread ()
10672   "Go up one level in the current thread."
10673   (let ((parent (gnus-summary-article-parent)))
10674     (when parent
10675       (gnus-summary-goto-subject parent))))
10676
10677 (defun gnus-summary-down-thread (n)
10678   "Go down thread N steps.
10679 If N is negative, go up instead.
10680 Returns the difference between N and how many steps down that were
10681 taken."
10682   (interactive "p")
10683   (let ((up (< n 0))
10684         (n (abs n)))
10685     (while (and (> n 0)
10686                 (if up (gnus-summary-go-up-thread)
10687                   (gnus-summary-go-down-thread)))
10688       (setq n (1- n)))
10689     (gnus-summary-position-point)
10690     (when (/= 0 n)
10691       (gnus-message 7 "Can't go further"))
10692     n))
10693
10694 (defun gnus-summary-up-thread (n)
10695   "Go up thread N steps.
10696 If N is negative, go down instead.
10697 Returns the difference between N and how many steps down that were
10698 taken."
10699   (interactive "p")
10700   (gnus-summary-down-thread (- n)))
10701
10702 (defun gnus-summary-top-thread ()
10703   "Go to the top of the thread."
10704   (interactive)
10705   (while (gnus-summary-go-up-thread))
10706   (gnus-summary-article-number))
10707
10708 (defun gnus-summary-kill-thread (&optional unmark)
10709   "Mark articles under current thread as read.
10710 If the prefix argument is positive, remove any kinds of marks.
10711 If the prefix argument is negative, tick articles instead."
10712   (interactive "P")
10713   (when unmark
10714     (setq unmark (prefix-numeric-value unmark)))
10715   (let ((articles (gnus-summary-articles-in-thread)))
10716     (save-excursion
10717       ;; Expand the thread.
10718       (gnus-summary-show-thread)
10719       ;; Mark all the articles.
10720       (while articles
10721         (gnus-summary-goto-subject (car articles))
10722         (cond ((null unmark)
10723                (gnus-summary-mark-article-as-read gnus-killed-mark))
10724               ((> unmark 0)
10725                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10726               (t
10727                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10728         (setq articles (cdr articles))))
10729     ;; Hide killed subtrees.
10730     (and (null unmark)
10731          gnus-thread-hide-killed
10732          (gnus-summary-hide-thread))
10733     ;; If marked as read, go to next unread subject.
10734     (when (null unmark)
10735       ;; Go to next unread subject.
10736       (gnus-summary-next-subject 1 t)))
10737   (gnus-set-mode-line 'summary))
10738
10739 ;; Summary sorting commands
10740
10741 (defun gnus-summary-sort-by-number (&optional reverse)
10742   "Sort the summary buffer by article number.
10743 Argument REVERSE means reverse order."
10744   (interactive "P")
10745   (gnus-summary-sort 'number reverse))
10746
10747 (defun gnus-summary-sort-by-random (&optional reverse)
10748   "Randomize the order in the summary buffer.
10749 Argument REVERSE means to randomize in reverse order."
10750   (interactive "P")
10751   (gnus-summary-sort 'random reverse))
10752
10753 (defun gnus-summary-sort-by-author (&optional reverse)
10754   "Sort the summary buffer by author name alphabetically.
10755 If `case-fold-search' is non-nil, case of letters is ignored.
10756 Argument REVERSE means reverse order."
10757   (interactive "P")
10758   (gnus-summary-sort 'author reverse))
10759
10760 (defun gnus-summary-sort-by-subject (&optional reverse)
10761   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10762 If `case-fold-search' is non-nil, case of letters is ignored.
10763 Argument REVERSE means reverse order."
10764   (interactive "P")
10765   (gnus-summary-sort 'subject reverse))
10766
10767 (defun gnus-summary-sort-by-date (&optional reverse)
10768   "Sort the summary buffer by date.
10769 Argument REVERSE means reverse order."
10770   (interactive "P")
10771   (gnus-summary-sort 'date reverse))
10772
10773 (defun gnus-summary-sort-by-score (&optional reverse)
10774   "Sort the summary buffer by score.
10775 Argument REVERSE means reverse order."
10776   (interactive "P")
10777   (gnus-summary-sort 'score reverse))
10778
10779 (defun gnus-summary-sort-by-lines (&optional reverse)
10780   "Sort the summary buffer by the number of lines.
10781 Argument REVERSE means reverse order."
10782   (interactive "P")
10783   (gnus-summary-sort 'lines reverse))
10784
10785 (defun gnus-summary-sort-by-chars (&optional reverse)
10786   "Sort the summary buffer by article length.
10787 Argument REVERSE means reverse order."
10788   (interactive "P")
10789   (gnus-summary-sort 'chars reverse))
10790
10791 (defun gnus-summary-sort-by-original (&optional reverse)
10792   "Sort the summary buffer using the default sorting method.
10793 Argument REVERSE means reverse order."
10794   (interactive "P")
10795   (let* ((buffer-read-only)
10796          (gnus-summary-prepare-hook nil))
10797     ;; We do the sorting by regenerating the threads.
10798     (gnus-summary-prepare)
10799     ;; Hide subthreads if needed.
10800     (gnus-summary-maybe-hide-threads)))
10801
10802 (defun gnus-summary-sort (predicate reverse)
10803   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10804   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10805          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10806          (gnus-thread-sort-functions
10807           (if (not reverse)
10808               thread
10809             `(lambda (t1 t2)
10810                (,thread t2 t1))))
10811          (gnus-sort-gathered-threads-function
10812           gnus-thread-sort-functions)
10813          (gnus-article-sort-functions
10814           (if (not reverse)
10815               article
10816             `(lambda (t1 t2)
10817                (,article t2 t1))))
10818          (buffer-read-only)
10819          (gnus-summary-prepare-hook nil))
10820     ;; We do the sorting by regenerating the threads.
10821     (gnus-summary-prepare)
10822     ;; Hide subthreads if needed.
10823     (gnus-summary-maybe-hide-threads)))
10824
10825 ;; Summary saving commands.
10826
10827 (defun gnus-summary-save-article (&optional n not-saved)
10828   "Save the current article using the default saver function.
10829 If N is a positive number, save the N next articles.
10830 If N is a negative number, save the N previous articles.
10831 If N is nil and any articles have been marked with the process mark,
10832 save those articles instead.
10833 The variable `gnus-default-article-saver' specifies the saver function."
10834   (interactive "P")
10835   (let* ((articles (gnus-summary-work-articles n))
10836          (save-buffer (save-excursion
10837                         (nnheader-set-temp-buffer " *Gnus Save*")))
10838          (num (length articles))
10839          header file)
10840     (dolist (article articles)
10841       (setq header (gnus-summary-article-header article))
10842       (if (not (vectorp header))
10843           ;; This is a pseudo-article.
10844           (if (assq 'name header)
10845               (gnus-copy-file (cdr (assq 'name header)))
10846             (gnus-message 1 "Article %d is unsaveable" article))
10847         ;; This is a real article.
10848         (save-window-excursion
10849           (let ((gnus-display-mime-function nil)
10850                 (gnus-article-prepare-hook nil))
10851             (gnus-summary-select-article t nil nil article)))
10852         (save-excursion
10853           (set-buffer save-buffer)
10854           (erase-buffer)
10855           (insert-buffer-substring gnus-original-article-buffer))
10856         (setq file (gnus-article-save save-buffer file num))
10857         (gnus-summary-remove-process-mark article)
10858         (unless not-saved
10859           (gnus-summary-set-saved-mark article))))
10860     (gnus-kill-buffer save-buffer)
10861     (gnus-summary-position-point)
10862     (gnus-set-mode-line 'summary)
10863     n))
10864
10865 (defun gnus-summary-pipe-output (&optional arg headers)
10866   "Pipe the current article to a subprocess.
10867 If N is a positive number, pipe the N next articles.
10868 If N is a negative number, pipe the N previous articles.
10869 If N is nil and any articles have been marked with the process mark,
10870 pipe those articles instead.
10871 If HEADERS (the symbolic prefix), include the headers, too."
10872   (interactive (gnus-interactive "P\ny"))
10873   (require 'gnus-art)
10874   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10875         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10876     (gnus-summary-save-article arg t))
10877   (let ((buffer (get-buffer "*Shell Command Output*")))
10878     (when (and buffer
10879                (not (zerop (buffer-size buffer))))
10880       (gnus-configure-windows 'pipe))))
10881
10882 (defun gnus-summary-save-article-mail (&optional arg)
10883   "Append the current article to an mail file.
10884 If N is a positive number, save the N next articles.
10885 If N is a negative number, save the N previous articles.
10886 If N is nil and any articles have been marked with the process mark,
10887 save those articles instead."
10888   (interactive "P")
10889   (require 'gnus-art)
10890   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10891     (gnus-summary-save-article arg)))
10892
10893 (defun gnus-summary-save-article-rmail (&optional arg)
10894   "Append the current article to an rmail file.
10895 If N is a positive number, save the N next articles.
10896 If N is a negative number, save the N previous articles.
10897 If N is nil and any articles have been marked with the process mark,
10898 save those articles instead."
10899   (interactive "P")
10900   (require 'gnus-art)
10901   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10902     (gnus-summary-save-article arg)))
10903
10904 (defun gnus-summary-save-article-file (&optional arg)
10905   "Append the current article to a file.
10906 If N is a positive number, save the N next articles.
10907 If N is a negative number, save the N previous articles.
10908 If N is nil and any articles have been marked with the process mark,
10909 save those articles instead."
10910   (interactive "P")
10911   (require 'gnus-art)
10912   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10913     (gnus-summary-save-article arg)))
10914
10915 (defun gnus-summary-write-article-file (&optional arg)
10916   "Write the current article to a file, deleting the previous file.
10917 If N is a positive number, save the N next articles.
10918 If N is a negative number, save the N previous articles.
10919 If N is nil and any articles have been marked with the process mark,
10920 save those articles instead."
10921   (interactive "P")
10922   (require 'gnus-art)
10923   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10924     (gnus-summary-save-article arg)))
10925
10926 (defun gnus-summary-save-article-body-file (&optional arg)
10927   "Append the current article body to a file.
10928 If N is a positive number, save the N next articles.
10929 If N is a negative number, save the N previous articles.
10930 If N is nil and any articles have been marked with the process mark,
10931 save those articles instead."
10932   (interactive "P")
10933   (require 'gnus-art)
10934   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10935     (gnus-summary-save-article arg)))
10936
10937 (defun gnus-summary-muttprint (&optional arg)
10938   "Print the current article using Muttprint.
10939 If N is a positive number, save the N next articles.
10940 If N is a negative number, save the N previous articles.
10941 If N is nil and any articles have been marked with the process mark,
10942 save those articles instead."
10943   (interactive "P")
10944   (require 'gnus-art)
10945   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10946     (gnus-summary-save-article arg t)))
10947
10948 (defun gnus-summary-pipe-message (program)
10949   "Pipe the current article through PROGRAM."
10950   (interactive "sProgram: ")
10951   (gnus-summary-select-article)
10952   (let ((mail-header-separator ""))
10953     (gnus-eval-in-buffer-window gnus-article-buffer
10954       (save-restriction
10955         (widen)
10956         (let ((start (window-start))
10957               buffer-read-only)
10958           (message-pipe-buffer-body program)
10959           (set-window-start (get-buffer-window (current-buffer)) start))))))
10960
10961 (defun gnus-get-split-value (methods)
10962   "Return a value based on the split METHODS."
10963   (let (split-name method result match)
10964     (when methods
10965       (save-excursion
10966         (set-buffer gnus-original-article-buffer)
10967         (save-restriction
10968           (nnheader-narrow-to-headers)
10969           (while (and methods (not split-name))
10970             (goto-char (point-min))
10971             (setq method (pop methods))
10972             (setq match (car method))
10973             (when (cond
10974                    ((stringp match)
10975                     ;; Regular expression.
10976                     (ignore-errors
10977                       (re-search-forward match nil t)))
10978                    ((functionp match)
10979                     ;; Function.
10980                     (save-restriction
10981                       (widen)
10982                       (setq result (funcall match gnus-newsgroup-name))))
10983                    ((consp match)
10984                     ;; Form.
10985                     (save-restriction
10986                       (widen)
10987                       (setq result (eval match)))))
10988               (setq split-name (cdr method))
10989               (cond ((stringp result)
10990                      (push (expand-file-name
10991                             result gnus-article-save-directory)
10992                            split-name))
10993                     ((consp result)
10994                      (setq split-name (append result split-name)))))))))
10995     (nreverse split-name)))
10996
10997 (defun gnus-valid-move-group-p (group)
10998   (and (boundp group)
10999        (symbol-name group)
11000        (symbol-value group)
11001        (gnus-get-function (gnus-find-method-for-group
11002                            (symbol-name group)) 'request-accept-article t)))
11003
11004 (defun gnus-read-move-group-name (prompt default articles prefix)
11005   "Read a group name."
11006   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11007          (minibuffer-confirm-incomplete nil) ; XEmacs
11008          (prom
11009           (format "%s %s to:"
11010                   prompt
11011                   (if (> (length articles) 1)
11012                       (format "these %d articles" (length articles))
11013                     "this article")))
11014          (to-newsgroup
11015           (cond
11016            ((null split-name)
11017             (gnus-completing-read-with-default
11018              default prom
11019              gnus-active-hashtb
11020              'gnus-valid-move-group-p
11021              nil prefix
11022              'gnus-group-history))
11023            ((= 1 (length split-name))
11024             (gnus-completing-read-with-default
11025              (car split-name) prom
11026              gnus-active-hashtb
11027              'gnus-valid-move-group-p
11028              nil nil
11029              'gnus-group-history))
11030            (t
11031             (gnus-completing-read-with-default
11032              nil prom
11033              (mapcar (lambda (el) (list el))
11034                      (nreverse split-name))
11035              nil nil nil
11036              'gnus-group-history))))
11037          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11038     (when to-newsgroup
11039       (if (or (string= to-newsgroup "")
11040               (string= to-newsgroup prefix))
11041           (setq to-newsgroup default))
11042       (unless to-newsgroup
11043         (error "No group name entered"))
11044       (or (gnus-active to-newsgroup)
11045           (gnus-activate-group to-newsgroup nil nil to-method)
11046           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11047                                      to-newsgroup))
11048               (or (and (gnus-request-create-group to-newsgroup to-method)
11049                        (gnus-activate-group
11050                         to-newsgroup nil nil to-method)
11051                        (gnus-subscribe-group to-newsgroup))
11052                   (error "Couldn't create group %s" to-newsgroup)))
11053           (error "No such group: %s" to-newsgroup)))
11054     to-newsgroup))
11055
11056 (defun gnus-summary-save-parts (type dir n &optional reverse)
11057   "Save parts matching TYPE to DIR.
11058 If REVERSE, save parts that do not match TYPE."
11059   (interactive
11060    (list (read-string "Save parts of type: "
11061                       (or (car gnus-summary-save-parts-type-history)
11062                           gnus-summary-save-parts-default-mime)
11063                       'gnus-summary-save-parts-type-history)
11064          (setq gnus-summary-save-parts-last-directory
11065                (read-file-name "Save to directory: "
11066                                gnus-summary-save-parts-last-directory
11067                                nil t))
11068          current-prefix-arg))
11069   (gnus-summary-iterate n
11070     (let ((gnus-display-mime-function nil)
11071           (gnus-inhibit-treatment t))
11072       (gnus-summary-select-article))
11073     (save-excursion
11074       (set-buffer gnus-article-buffer)
11075       (let ((handles (or gnus-article-mime-handles
11076                          (mm-dissect-buffer nil gnus-article-loose-mime)
11077                          (and gnus-article-emulate-mime
11078                               (mm-uu-dissect)))))
11079         (when handles
11080           (gnus-summary-save-parts-1 type dir handles reverse)
11081           (unless gnus-article-mime-handles ;; Don't destroy this case.
11082             (mm-destroy-parts handles)))))))
11083
11084 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11085   (if (stringp (car handle))
11086       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11087               (cdr handle))
11088     (when (if reverse
11089               (not (string-match type (mm-handle-media-type handle)))
11090             (string-match type (mm-handle-media-type handle)))
11091       (let ((file (expand-file-name
11092                    (gnus-map-function
11093                     mm-file-name-rewrite-functions
11094                     (file-name-nondirectory
11095                      (or
11096                       (mail-content-type-get
11097                        (mm-handle-disposition handle) 'filename)
11098                       (mail-content-type-get
11099                        (mm-handle-type handle) 'name)
11100                       (concat gnus-newsgroup-name
11101                               "." (number-to-string
11102                                    (cdr gnus-article-current))))))
11103                    dir)))
11104         (unless (file-exists-p file)
11105           (mm-save-part-to-file handle file))))))
11106
11107 ;; Summary extract commands
11108
11109 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11110   (let ((buffer-read-only nil)
11111         (article (gnus-summary-article-number))
11112         after-article b e)
11113     (unless (gnus-summary-goto-subject article)
11114       (error "No such article: %d" article))
11115     (gnus-summary-position-point)
11116     ;; If all commands are to be bunched up on one line, we collect
11117     ;; them here.
11118     (unless gnus-view-pseudos-separately
11119       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11120             files action)
11121         (while ps
11122           (setq action (cdr (assq 'action (car ps))))
11123           (setq files (list (cdr (assq 'name (car ps)))))
11124           (while (and ps (cdr ps)
11125                       (string= (or action "1")
11126                                (or (cdr (assq 'action (cadr ps))) "2")))
11127             (push (cdr (assq 'name (cadr ps))) files)
11128             (setcdr ps (cddr ps)))
11129           (when files
11130             (when (not (string-match "%s" action))
11131               (push " " files))
11132             (push " " files)
11133             (when (assq 'execute (car ps))
11134               (setcdr (assq 'execute (car ps))
11135                       (funcall (if (string-match "%s" action)
11136                                    'format 'concat)
11137                                action
11138                                (mapconcat
11139                                 (lambda (f)
11140                                   (if (equal f " ")
11141                                       f
11142                                     (shell-quote-argument f)))
11143                                 files " ")))))
11144           (setq ps (cdr ps)))))
11145     (if (and gnus-view-pseudos (not not-view))
11146         (while pslist
11147           (when (assq 'execute (car pslist))
11148             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11149                                   (eq gnus-view-pseudos 'not-confirm)))
11150           (setq pslist (cdr pslist)))
11151       (save-excursion
11152         (while pslist
11153           (setq after-article (or (cdr (assq 'article (car pslist)))
11154                                   (gnus-summary-article-number)))
11155           (gnus-summary-goto-subject after-article)
11156           (forward-line 1)
11157           (setq b (point))
11158           (insert "    " (file-name-nondirectory
11159                           (cdr (assq 'name (car pslist))))
11160                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11161           (setq e (point))
11162           (forward-line -1)             ; back to `b'
11163           (gnus-add-text-properties
11164            b (1- e) (list 'gnus-number gnus-reffed-article-number
11165                           gnus-mouse-face-prop gnus-mouse-face))
11166           (gnus-data-enter
11167            after-article gnus-reffed-article-number
11168            gnus-unread-mark b (car pslist) 0 (- e b))
11169           (setq gnus-newsgroup-unreads
11170                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11171                                          gnus-reffed-article-number))
11172           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11173           (setq pslist (cdr pslist)))))))
11174
11175 (defun gnus-pseudos< (p1 p2)
11176   (let ((c1 (cdr (assq 'action p1)))
11177         (c2 (cdr (assq 'action p2))))
11178     (and c1 c2 (string< c1 c2))))
11179
11180 (defun gnus-request-pseudo-article (props)
11181   (cond ((assq 'execute props)
11182          (gnus-execute-command (cdr (assq 'execute props)))))
11183   (let ((gnus-current-article (gnus-summary-article-number)))
11184     (gnus-run-hooks 'gnus-mark-article-hook)))
11185
11186 (defun gnus-execute-command (command &optional automatic)
11187   (save-excursion
11188     (gnus-article-setup-buffer)
11189     (set-buffer gnus-article-buffer)
11190     (setq buffer-read-only nil)
11191     (let ((command (if automatic command
11192                      (read-string "Command: " (cons command 0)))))
11193       (erase-buffer)
11194       (insert "$ " command "\n\n")
11195       (if gnus-view-pseudo-asynchronously
11196           (start-process "gnus-execute" (current-buffer) shell-file-name
11197                          shell-command-switch command)
11198         (call-process shell-file-name nil t nil
11199                       shell-command-switch command)))))
11200
11201 ;; Summary kill commands.
11202
11203 (defun gnus-summary-edit-global-kill (article)
11204   "Edit the \"global\" kill file."
11205   (interactive (list (gnus-summary-article-number)))
11206   (gnus-group-edit-global-kill article))
11207
11208 (defun gnus-summary-edit-local-kill ()
11209   "Edit a local kill file applied to the current newsgroup."
11210   (interactive)
11211   (setq gnus-current-headers (gnus-summary-article-header))
11212   (gnus-group-edit-local-kill
11213    (gnus-summary-article-number) gnus-newsgroup-name))
11214
11215 ;;; Header reading.
11216
11217 (defun gnus-read-header (id &optional header)
11218   "Read the headers of article ID and enter them into the Gnus system."
11219   (let ((group gnus-newsgroup-name)
11220         (gnus-override-method
11221          (or
11222           gnus-override-method
11223           (and (gnus-news-group-p gnus-newsgroup-name)
11224                (car (gnus-refer-article-methods)))))
11225         where)
11226     ;; First we check to see whether the header in question is already
11227     ;; fetched.
11228     (if (stringp id)
11229         ;; This is a Message-ID.
11230         (setq header (or header (gnus-id-to-header id)))
11231       ;; This is an article number.
11232       (setq header (or header (gnus-summary-article-header id))))
11233     (if (and header
11234              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11235         ;; We have found the header.
11236         header
11237       ;; If this is a sparse article, we have to nix out its
11238       ;; previous entry in the thread hashtb.
11239       (when (and header
11240                  (gnus-summary-article-sparse-p (mail-header-number header)))
11241         (let* ((parent (gnus-parent-id (mail-header-references header)))
11242                (thread (and parent (gnus-id-to-thread parent))))
11243           (when thread
11244             (delq (assq header thread) thread))))
11245       ;; We have to really fetch the header to this article.
11246       (save-excursion
11247         (set-buffer nntp-server-buffer)
11248         (when (setq where (gnus-request-head id group))
11249           (nnheader-fold-continuation-lines)
11250           (goto-char (point-max))
11251           (insert ".\n")
11252           (goto-char (point-min))
11253           (insert "211 ")
11254           (princ (cond
11255                   ((numberp id) id)
11256                   ((cdr where) (cdr where))
11257                   (header (mail-header-number header))
11258                   (t gnus-reffed-article-number))
11259                  (current-buffer))
11260           (insert " Article retrieved.\n"))
11261         (if (or (not where)
11262                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11263             ()                          ; Malformed head.
11264           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11265             (when (and (stringp id)
11266                        (not (string= (gnus-group-real-name group)
11267                                      (car where))))
11268               ;; If we fetched by Message-ID and the article came
11269               ;; from a different group, we fudge some bogus article
11270               ;; numbers for this article.
11271               (mail-header-set-number header gnus-reffed-article-number))
11272             (save-excursion
11273               (set-buffer gnus-summary-buffer)
11274               (decf gnus-reffed-article-number)
11275               (gnus-remove-header (mail-header-number header))
11276               (push header gnus-newsgroup-headers)
11277               (setq gnus-current-headers header)
11278               (push (mail-header-number header) gnus-newsgroup-limit)))
11279           header)))))
11280
11281 (defun gnus-remove-header (number)
11282   "Remove header NUMBER from `gnus-newsgroup-headers'."
11283   (if (and gnus-newsgroup-headers
11284            (= number (mail-header-number (car gnus-newsgroup-headers))))
11285       (pop gnus-newsgroup-headers)
11286     (let ((headers gnus-newsgroup-headers))
11287       (while (and (cdr headers)
11288                   (not (= number (mail-header-number (cadr headers)))))
11289         (pop headers))
11290       (when (cdr headers)
11291         (setcdr headers (cddr headers))))))
11292
11293 ;;;
11294 ;;; summary highlights
11295 ;;;
11296
11297 (defun gnus-highlight-selected-summary ()
11298   "Highlight selected article in summary buffer."
11299   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11300   (when gnus-summary-selected-face
11301     (save-excursion
11302       (let* ((beg (point-at-bol))
11303              (end (point-at-eol))
11304              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11305              (from (if (get-text-property beg gnus-mouse-face-prop)
11306                        beg
11307                      (or (next-single-property-change
11308                           beg gnus-mouse-face-prop nil end)
11309                          beg)))
11310              (to
11311               (if (= from end)
11312                   (- from 2)
11313                 (or (next-single-property-change
11314                      from gnus-mouse-face-prop nil end)
11315                     end))))
11316         ;; If no mouse-face prop on line we will have to = from = end,
11317         ;; so we highlight the entire line instead.
11318         (when (= (+ to 2) from)
11319           (setq from beg)
11320           (setq to end))
11321         (if gnus-newsgroup-selected-overlay
11322             ;; Move old overlay.
11323             (gnus-move-overlay
11324              gnus-newsgroup-selected-overlay from to (current-buffer))
11325           ;; Create new overlay.
11326           (gnus-overlay-put
11327            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11328            'face gnus-summary-selected-face))))))
11329
11330 (defvar gnus-summary-highlight-line-cached nil)
11331 (defvar gnus-summary-highlight-line-trigger nil)
11332
11333 (defun gnus-summary-highlight-line-0 ()
11334   (if (and (eq gnus-summary-highlight-line-trigger
11335                gnus-summary-highlight)
11336            gnus-summary-highlight-line-cached)
11337       gnus-summary-highlight-line-cached
11338     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11339           gnus-summary-highlight-line-cached
11340           (let* ((cond (list 'cond))
11341                  (c cond)
11342                  (list gnus-summary-highlight))
11343             (while list
11344               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11345                               nil))
11346               (setq c (cdr c)
11347                     list (cdr list)))
11348             (gnus-byte-compile (list 'lambda nil cond))))))
11349
11350 (defun gnus-summary-highlight-line ()
11351   "Highlight current line according to `gnus-summary-highlight'."
11352   (let* ((beg (point-at-bol))
11353          (article (or (gnus-summary-article-number) gnus-current-article))
11354          (score (or (cdr (assq article
11355                                gnus-newsgroup-scored))
11356                     gnus-summary-default-score 0))
11357          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11358          (inhibit-read-only t)
11359          (default gnus-summary-default-score)
11360          (default-high gnus-summary-default-high-score)
11361          (default-low gnus-summary-default-low-score)
11362          (uncached (and gnus-summary-use-undownloaded-faces
11363                         (memq article gnus-newsgroup-undownloaded))))
11364     (let ((face (funcall (gnus-summary-highlight-line-0))))
11365       (unless (eq face (get-text-property beg 'face))
11366         (gnus-put-text-property-excluding-characters-with-faces
11367          beg (point-at-eol) 'face
11368          (setq face (if (boundp face) (symbol-value face) face)))
11369         (when gnus-summary-highlight-line-function
11370           (funcall gnus-summary-highlight-line-function article face))))))
11371
11372 (defun gnus-update-read-articles (group unread &optional compute)
11373   "Update the list of read articles in GROUP.
11374 UNREAD is a sorted list."
11375   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11376         (info (gnus-get-info group))
11377         (prev 1)
11378         read)
11379     (if (or (not info) (not active))
11380         ;; There is no info on this group if it was, in fact,
11381         ;; killed.  Gnus stores no information on killed groups, so
11382         ;; there's nothing to be done.
11383         ;; One could store the information somewhere temporarily,
11384         ;; perhaps...  Hmmm...
11385         ()
11386       ;; Remove any negative articles numbers.
11387       (while (and unread (< (car unread) 0))
11388         (setq unread (cdr unread)))
11389       ;; Remove any expired article numbers
11390       (while (and unread (< (car unread) (car active)))
11391         (setq unread (cdr unread)))
11392       ;; Compute the ranges of read articles by looking at the list of
11393       ;; unread articles.
11394       (while unread
11395         (when (/= (car unread) prev)
11396           (push (if (= prev (1- (car unread))) prev
11397                   (cons prev (1- (car unread))))
11398                 read))
11399         (setq prev (1+ (car unread)))
11400         (setq unread (cdr unread)))
11401       (when (<= prev (cdr active))
11402         (push (cons prev (cdr active)) read))
11403       (setq read (if (> (length read) 1) (nreverse read) read))
11404       (if compute
11405           read
11406         (save-excursion
11407           (let (setmarkundo)
11408             ;; Propagate the read marks to the backend.
11409             (when (gnus-check-backend-function 'request-set-mark group)
11410               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11411                     (add (gnus-remove-from-range read (gnus-info-read info))))
11412                 (when (or add del)
11413                   (unless (gnus-check-group group)
11414                     (error "Can't open server for %s" group))
11415                   (gnus-request-set-mark
11416                    group (delq nil (list (if add (list add 'add '(read)))
11417                                          (if del (list del 'del '(read))))))
11418                   (setq setmarkundo
11419                         `(gnus-request-set-mark
11420                           ,group
11421                           ',(delq nil (list
11422                                        (if del (list del 'add '(read)))
11423                                        (if add (list add 'del '(read))))))))))
11424             (set-buffer gnus-group-buffer)
11425             (gnus-undo-register
11426               `(progn
11427                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11428                  (gnus-info-set-read ',info ',(gnus-info-read info))
11429                  (gnus-get-unread-articles-in-group ',info
11430                                                     (gnus-active ,group))
11431                  (gnus-group-update-group ,group t)
11432                  ,setmarkundo))))
11433         ;; Enter this list into the group info.
11434         (gnus-info-set-read info read)
11435         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11436         (gnus-get-unread-articles-in-group info (gnus-active group))
11437         t))))
11438
11439 (defun gnus-offer-save-summaries ()
11440   "Offer to save all active summary buffers."
11441   (let (buffers)
11442     ;; Go through all buffers and find all summaries.
11443     (dolist (buffer (buffer-list))
11444       (when (and (setq buffer (buffer-name buffer))
11445                  (string-match "Summary" buffer)
11446                  (save-excursion
11447                    (set-buffer buffer)
11448                    ;; We check that this is, indeed, a summary buffer.
11449                    (and (eq major-mode 'gnus-summary-mode)
11450                         ;; Also make sure this isn't bogus.
11451                         gnus-newsgroup-prepared
11452                         ;; Also make sure that this isn't a
11453                         ;; dead summary buffer.
11454                         (not gnus-dead-summary-mode))))
11455         (push buffer buffers)))
11456     ;; Go through all these summary buffers and offer to save them.
11457     (when buffers
11458       (save-excursion
11459         (map-y-or-n-p
11460          "Update summary buffer %s? "
11461          (lambda (buf)
11462            (switch-to-buffer buf)
11463            (gnus-summary-exit))
11464          buffers)))))
11465
11466
11467 ;;; @ for mime-partial
11468 ;;;
11469
11470 (defun gnus-request-partial-message ()
11471   (save-excursion
11472     (let ((number (gnus-summary-article-number))
11473           (group gnus-newsgroup-name)
11474           (mother gnus-article-buffer))
11475       (set-buffer (get-buffer-create " *Partial Article*"))
11476       (erase-buffer)
11477       (setq mime-preview-buffer mother)
11478       (gnus-request-article-this-buffer number group)
11479       (mime-parse-buffer)
11480       )))
11481
11482 (autoload 'mime-combine-message/partial-pieces-automatically
11483   "mime-partial"
11484   "Internal method to combine message/partial messages automatically.")
11485
11486 (mime-add-condition
11487  'action '((type . message)(subtype . partial)
11488            (major-mode . gnus-original-article-mode)
11489            (method . mime-combine-message/partial-pieces-automatically)
11490            (summary-buffer-exp . gnus-summary-buffer)
11491            (request-partial-message-method . gnus-request-partial-message)
11492            ))
11493
11494
11495 ;;; @ for message/rfc822
11496 ;;;
11497
11498 (defun gnus-mime-extract-message/rfc822 (entity situation)
11499   "Burst a forwarded article."
11500   (save-excursion
11501     (set-buffer gnus-summary-buffer)
11502     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11503                                    gnus-newsgroup-name 'gnus-group-history))
11504            (gnus-group-marked (list group))
11505            article info)
11506       (with-temp-buffer
11507         (mime-insert-entity-content entity)
11508         (setq article (gnus-request-accept-article group)))
11509       (when (and (consp article)
11510                  (numberp (setq article (cdr article))))
11511         (setq info (gnus-get-info group))
11512         (gnus-info-set-read info
11513                             (gnus-remove-from-range (gnus-info-read info)
11514                                                     (list article)))
11515         (when (string-equal group gnus-newsgroup-name)
11516           (forward-line 1)
11517           (let (gnus-show-threads)
11518             (gnus-summary-goto-subject article t))
11519           (gnus-summary-clear-mark-forward 1))
11520         (set-buffer gnus-group-buffer)
11521         (gnus-group-get-new-news-this-group nil t)))))
11522
11523 (mime-add-condition
11524  'action '((type . message)(subtype . rfc822)
11525            (major-mode . gnus-original-article-mode)
11526            (method . gnus-mime-extract-message/rfc822)
11527            (mode . "extract")
11528            ))
11529
11530 (mime-add-condition
11531  'action '((type . message)(subtype . news)
11532            (major-mode . gnus-original-article-mode)
11533            (method . gnus-mime-extract-message/rfc822)
11534            (mode . "extract")
11535            ))
11536
11537 (defun gnus-mime-extract-multipart (entity situation)
11538   (let ((children (mime-entity-children entity))
11539         mime-acting-situation-to-override
11540         f)
11541     (while children
11542       (mime-play-entity (car children)
11543                         (cons (assq 'mode situation)
11544                               mime-acting-situation-to-override))
11545       (setq children (cdr children)))
11546     (if (setq f (cdr (assq 'after-method
11547                            mime-acting-situation-to-override)))
11548         (eval f)
11549       )))
11550
11551 (mime-add-condition
11552  'action '((type . multipart)
11553            (method . gnus-mime-extract-multipart)
11554            (mode . "extract")
11555            )
11556  'with-default)
11557
11558
11559 ;;; @ end
11560 ;;;
11561
11562 (defun gnus-summary-inherit-default-charset ()
11563   "Import `default-mime-charset' from summary buffer.
11564 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11565 of FLIM is used."
11566   (if (buffer-live-p gnus-summary-buffer)
11567       (let (d-m-c d-m-c-u)
11568         (with-current-buffer gnus-summary-buffer
11569           (setq d-m-c (if (local-variable-p 'default-mime-charset
11570                                             gnus-summary-buffer)
11571                           default-mime-charset
11572                         t)
11573                 ;; LIMIT
11574                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11575                                               gnus-summary-buffer)
11576                             (symbol-value 'default-mime-charset-unlimited)
11577                           t)))
11578         (if (eq t d-m-c)
11579             (kill-local-variable 'default-mime-charset)
11580           (set (make-local-variable 'default-mime-charset) d-m-c))
11581         (if (eq t d-m-c-u)
11582             (kill-local-variable 'default-mime-charset-unlimited)
11583           (set (make-local-variable 'default-mime-charset-unlimited)
11584                d-m-c-u)))))
11585
11586 (defun gnus-summary-setup-default-charset ()
11587   "Setup newsgroup default charset."
11588   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11589       (progn
11590         (setq gnus-newsgroup-charset nil)
11591         (set (make-local-variable 'default-mime-charset) nil)
11592         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11593           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11594     (let ((ignored-charsets
11595            (or gnus-newsgroup-ephemeral-ignored-charsets
11596                (append
11597                 (and gnus-newsgroup-name
11598                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11599                 gnus-newsgroup-ignored-charsets)))
11600           charset)
11601       (setq gnus-newsgroup-charset
11602             (or gnus-newsgroup-ephemeral-charset
11603                 (when (and gnus-newsgroup-name
11604                            (setq charset (gnus-parameter-charset
11605                                           gnus-newsgroup-name)))
11606                   (make-local-variable 'default-mime-charset)
11607                   (setq default-mime-charset charset))
11608                 gnus-default-charset))
11609       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11610            ignored-charsets))))
11611
11612 ;;;
11613 ;;; Mime Commands
11614 ;;;
11615
11616 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11617   "Display the current article buffer fully MIME-buttonized.
11618 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11619 treated as multipart/mixed."
11620   (interactive "P")
11621   (require 'gnus-art)
11622   (let ((gnus-unbuttonized-mime-types nil)
11623         (gnus-mime-display-multipart-as-mixed show-all-parts))
11624     (gnus-summary-show-article)))
11625
11626 (defun gnus-summary-repair-multipart (article)
11627   "Add a Content-Type header to a multipart article without one."
11628   (interactive (list (gnus-summary-article-number)))
11629   (gnus-with-article article
11630     (message-narrow-to-head)
11631     (message-remove-header "Mime-Version")
11632     (goto-char (point-max))
11633     (insert "Mime-Version: 1.0\n")
11634     (widen)
11635     (when (search-forward "\n--" nil t)
11636       (let ((separator (buffer-substring (point) (point-at-eol))))
11637         (message-narrow-to-head)
11638         (message-remove-header "Content-Type")
11639         (goto-char (point-max))
11640         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11641                         separator))
11642         (widen))))
11643   (let (gnus-mark-article-hook)
11644     (gnus-summary-select-article t t nil article)))
11645
11646 (defun gnus-summary-toggle-display-buttonized ()
11647   "Toggle the buttonizing of the article buffer."
11648   (interactive)
11649   (require 'gnus-art)
11650   (if (setq gnus-inhibit-mime-unbuttonizing
11651             (not gnus-inhibit-mime-unbuttonizing))
11652       (let ((gnus-unbuttonized-mime-types nil))
11653         (gnus-summary-show-article))
11654     (gnus-summary-show-article)))
11655
11656 ;;;
11657 ;;; Intelli-mouse commmands
11658 ;;;
11659
11660 (defun gnus-wheel-summary-scroll (event)
11661   (interactive "e")
11662   (let ((amount (if (memq 'shift (event-modifiers event))
11663                     (car gnus-wheel-scroll-amount)
11664                   (cdr gnus-wheel-scroll-amount)))
11665         (direction (- (* (static-if (featurep 'xemacs)
11666                              (event-button event)
11667                            (cond ((eq 'mouse-4 (event-basic-type event))
11668                                   4)
11669                                  ((eq 'mouse-5 (event-basic-type event))
11670                                   5)))
11671                          2) 9))
11672         edge)
11673     (gnus-summary-scroll-up (* amount direction))
11674     (when (gnus-eval-in-buffer-window gnus-article-buffer
11675             (save-restriction
11676               (widen)
11677               (and (if (< 0 direction)
11678                        (gnus-article-next-page 0)
11679                      (gnus-article-prev-page 0)
11680                      (bobp))
11681                    (if (setq edge (get-text-property
11682                                    (point-min) 'gnus-wheel-edge))
11683                        (setq edge (* edge direction))
11684                      (setq edge -1))
11685                    (or (plusp edge)
11686                        (let ((buffer-read-only nil)
11687                              (inhibit-read-only t))
11688                          (put-text-property (point-min) (point-max)
11689                                             'gnus-wheel-edge direction)
11690                          nil))
11691                    (or (> edge gnus-wheel-edge-resistance)
11692                        (let ((buffer-read-only nil)
11693                              (inhibit-read-only t))
11694                          (put-text-property (point-min) (point-max)
11695                                             'gnus-wheel-edge
11696                                             (* (1+ edge) direction))
11697                          nil))
11698                    (eq last-command 'gnus-wheel-summary-scroll))))
11699       (gnus-summary-next-article nil nil (minusp direction)))))
11700
11701 (defun gnus-wheel-install ()
11702   "Enable mouse wheel support on summary window."
11703   (when gnus-use-wheel
11704     (let ((keys
11705            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11706       (dolist (key keys)
11707         (define-key gnus-summary-mode-map key
11708           'gnus-wheel-summary-scroll)))))
11709
11710 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11711
11712 ;;;
11713 ;;; Traditional PGP commmands
11714 ;;;
11715
11716 (defun gnus-summary-decrypt-article (&optional force)
11717   "Decrypt the current article in traditional PGP way.
11718 This will have permanent effect only in mail groups.
11719 If FORCE is non-nil, allow editing of articles even in read-only
11720 groups."
11721   (interactive "P")
11722   (gnus-summary-select-article t)
11723   (gnus-eval-in-buffer-window gnus-article-buffer
11724     (save-excursion
11725       (save-restriction
11726         (widen)
11727         (goto-char (point-min))
11728         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11729           (error "Not a traditional PGP message!"))
11730         (let ((armor-start (match-beginning 0)))
11731           (if (and (pgg-decrypt-region armor-start (point-max))
11732                    (or force (not (gnus-group-read-only-p))))
11733               (let ((inhibit-read-only t)
11734                     buffer-read-only)
11735                 (delete-region armor-start
11736                                (progn
11737                                  (re-search-forward "^-+END PGP" nil t)
11738                                  (beginning-of-line 2)
11739                                  (point)))
11740                 (insert-buffer-substring pgg-output-buffer))))))))
11741
11742 (defun gnus-summary-verify-article ()
11743   "Verify the current article in traditional PGP way."
11744   (interactive)
11745   (save-excursion
11746     (set-buffer gnus-original-article-buffer)
11747     (goto-char (point-min))
11748     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11749       (error "Not a traditional PGP message!"))
11750     (re-search-forward "^-+END PGP" nil t)
11751     (beginning-of-line 2)
11752     (call-interactively (function pgg-verify-region))))
11753
11754 ;;;
11755 ;;; Generic summary marking commands
11756 ;;;
11757
11758 (defvar gnus-summary-marking-alist
11759   '((read gnus-del-mark "d")
11760     (unread gnus-unread-mark "u")
11761     (ticked gnus-ticked-mark "!")
11762     (dormant gnus-dormant-mark "?")
11763     (expirable gnus-expirable-mark "e"))
11764   "An alist of names/marks/keystrokes.")
11765
11766 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11767 (defvar gnus-summary-mark-map)
11768
11769 (defun gnus-summary-make-all-marking-commands ()
11770   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11771   (dolist (elem gnus-summary-marking-alist)
11772     (apply 'gnus-summary-make-marking-command elem)))
11773
11774 (defun gnus-summary-make-marking-command (name mark keystroke)
11775   (let ((map (make-sparse-keymap)))
11776     (define-key gnus-summary-generic-mark-map keystroke map)
11777     (dolist (lway `((next "next" next nil "n")
11778                     (next-unread "next unread" next t "N")
11779                     (prev "previous" prev nil "p")
11780                     (prev-unread "previous unread" prev t "P")
11781                     (nomove "" nil nil ,keystroke)))
11782       (let ((func (gnus-summary-make-marking-command-1
11783                    mark (car lway) lway name)))
11784         (setq func (eval func))
11785         (define-key map (nth 4 lway) func)))))
11786
11787 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11788   `(defun ,(intern
11789             (format "gnus-summary-put-mark-as-%s%s"
11790                     name (if (eq way 'nomove)
11791                              ""
11792                            (concat "-" (symbol-name way)))))
11793      (n)
11794      ,(format
11795        "Mark the current article as %s%s.
11796 If N, the prefix, then repeat N times.
11797 If N is negative, move in reverse order.
11798 The difference between N and the actual number of articles marked is
11799 returned."
11800        name (car (cdr lway)))
11801      (interactive "p")
11802      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11803
11804 (defun gnus-summary-generic-mark (n mark move unread)
11805   "Mark N articles with MARK."
11806   (unless (eq major-mode 'gnus-summary-mode)
11807     (error "This command can only be used in the summary buffer"))
11808   (gnus-summary-show-thread)
11809   (let ((nummove
11810          (cond
11811           ((eq move 'next) 1)
11812           ((eq move 'prev) -1)
11813           (t 0))))
11814     (if (zerop nummove)
11815         (setq n 1)
11816       (when (< n 0)
11817         (setq n (abs n)
11818               nummove (* -1 nummove))))
11819     (while (and (> n 0)
11820                 (gnus-summary-mark-article nil mark)
11821                 (zerop (gnus-summary-next-subject nummove unread t)))
11822       (setq n (1- n)))
11823     (when (/= 0 n)
11824       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11825     (gnus-summary-recenter)
11826     (gnus-summary-position-point)
11827     (gnus-set-mode-line 'summary)
11828     n))
11829
11830 (defun gnus-summary-insert-articles (articles)
11831   (when (setq articles
11832               (gnus-sorted-difference articles
11833                                       (mapcar (lambda (h)
11834                                                 (mail-header-number h))
11835                                               gnus-newsgroup-headers)))
11836     (setq gnus-newsgroup-headers
11837           (gnus-merge 'list
11838                       gnus-newsgroup-headers
11839                       (gnus-fetch-headers articles)
11840                       'gnus-article-sort-by-number))
11841     ;; Suppress duplicates?
11842     (when gnus-suppress-duplicates
11843       (gnus-dup-suppress-articles))
11844
11845     ;; We might want to build some more threads first.
11846     (when (and gnus-fetch-old-headers
11847                (eq gnus-headers-retrieved-by 'nov))
11848       (if (eq gnus-fetch-old-headers 'invisible)
11849           (gnus-build-all-threads)
11850         (gnus-build-old-threads)))
11851     ;; Let the Gnus agent mark articles as read.
11852     (when gnus-agent
11853       (gnus-agent-get-undownloaded-list))
11854     ;; Remove list identifiers from subject
11855     (when gnus-list-identifiers
11856       (gnus-summary-remove-list-identifiers))
11857     ;; First and last article in this newsgroup.
11858     (when gnus-newsgroup-headers
11859       (setq gnus-newsgroup-begin
11860             (mail-header-number (car gnus-newsgroup-headers))
11861             gnus-newsgroup-end
11862             (mail-header-number
11863              (gnus-last-element gnus-newsgroup-headers))))
11864     (when gnus-use-scoring
11865       (gnus-possibly-score-headers))))
11866
11867 (defun gnus-summary-insert-old-articles (&optional all)
11868   "Insert all old articles in this group.
11869 If ALL is non-nil, already read articles become readable.
11870 If ALL is a number, fetch this number of articles."
11871   (interactive "P")
11872   (prog1
11873       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11874             older len)
11875         (setq older
11876               ;; Some nntp servers lie about their active range.  When
11877               ;; this happens, the active range can be in the millions.
11878               ;; Use a compressed range to avoid creating a huge list.
11879               (gnus-range-difference (list gnus-newsgroup-active) old))
11880         (setq len (gnus-range-length older))
11881         (cond
11882          ((null older) nil)
11883          ((numberp all)
11884           (if (< all len)
11885               (let ((older-range (nreverse older)))
11886                 (setq older nil)
11887
11888                 (while (> all 0)
11889                   (let* ((r (pop older-range))
11890                          (min (if (numberp r) r (car r)))
11891                          (max (if (numberp r) r (cdr r))))
11892                     (while (and (<= min max)
11893                                 (> all 0))
11894                       (push max older)
11895                       (setq all (1- all)
11896                             max (1- max))))))
11897             (setq older (gnus-uncompress-range older))))
11898          (all
11899           (setq older (gnus-uncompress-range older)))
11900          (t
11901           (when (and (numberp gnus-large-newsgroup)
11902                    (> len gnus-large-newsgroup))
11903               (let* ((cursor-in-echo-area nil)
11904                      (initial (gnus-parameter-large-newsgroup-initial
11905                                gnus-newsgroup-name))
11906                      (input
11907                       (read-string
11908                        (format
11909                         "How many articles from %s (%s %d): "
11910                         (gnus-limit-string
11911                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11912                         (if initial "max" "default")
11913                         len)
11914                        (if initial
11915                            (cons (number-to-string initial)
11916                                  0)))))
11917                 (unless (string-match "^[ \t]*$" input)
11918                   (setq all (string-to-number input))
11919                   (if (< all len)
11920                       (let ((older-range (nreverse older)))
11921                         (setq older nil)
11922
11923                         (while (> all 0)
11924                           (let* ((r (pop older-range))
11925                                  (min (if (numberp r) r (car r)))
11926                                  (max (if (numberp r) r (cdr r))))
11927                             (while (and (<= min max)
11928                                         (> all 0))
11929                               (push max older)
11930                               (setq all (1- all)
11931                                     max (1- max))))))))))
11932           (setq older (gnus-uncompress-range older))))
11933         (if (not older)
11934             (message "No old news.")
11935           (gnus-summary-insert-articles older)
11936           (gnus-summary-limit (gnus-sorted-nunion old older))))
11937     (gnus-summary-position-point)))
11938
11939 (defun gnus-summary-insert-new-articles ()
11940   "Insert all new articles in this group."
11941   (interactive)
11942   (prog1
11943       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11944             (old-active gnus-newsgroup-active)
11945             (nnmail-fetched-sources (list t))
11946             i new)
11947         (setq gnus-newsgroup-active
11948               (gnus-activate-group gnus-newsgroup-name 'scan))
11949         (setq i (cdr gnus-newsgroup-active))
11950         (while (> i (cdr old-active))
11951           (push i new)
11952           (decf i))
11953         (if (not new)
11954             (message "No gnus is bad news")
11955           (gnus-summary-insert-articles new)
11956           (setq gnus-newsgroup-unreads
11957                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11958           (gnus-summary-limit (gnus-sorted-nunion old new))))
11959     (gnus-summary-position-point)))
11960
11961 (gnus-summary-make-all-marking-commands)
11962
11963 (gnus-ems-redefine)
11964
11965 (provide 'gnus-sum)
11966
11967 (run-hooks 'gnus-sum-load-hook)
11968
11969 ;; Local Variables:
11970 ;; coding: iso-8859-1
11971 ;; End:
11972
11973 ;;; gnus-sum.el ends here