Synch to No Gnus 200410060926.
[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 t, Gnus
77 will attempt to grab the headers to the old articles, and thereby
78 build complete threads.  If it has the value `some', only enough
79 headers to connect otherwise loose threads will be displayed.  This
80 variable can also be a number.  In that case, no more than that number
81 of old headers will be fetched.  If it has the value `invisible', all
82 old headers will be fetched, but none will be displayed.
83
84 The server has to support NOV for any of this to work."
85   :group 'gnus-thread
86   :type '(choice (const :tag "off" nil)
87                  (const :tag "on" t)
88                  (const some)
89                  (const invisible)
90                  number
91                  (sexp :menu-tag "other" t)))
92
93 (defcustom gnus-refer-thread-limit 200
94   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
95 If t, fetch all the available old headers."
96   :group 'gnus-thread
97   :type '(choice number
98                  (sexp :menu-tag "other" t)))
99
100 (defcustom gnus-summary-make-false-root 'adopt
101   "*nil means that Gnus won't gather loose threads.
102 If the root of a thread has expired or been read in a previous
103 session, the information necessary to build a complete thread has been
104 lost.  Instead of having many small sub-threads from this original thread
105 scattered all over the summary buffer, Gnus can gather them.
106
107 If non-nil, Gnus will try to gather all loose sub-threads from an
108 original thread into one large thread.
109
110 If this variable is non-nil, it should be one of `none', `adopt',
111 `dummy' or `empty'.
112
113 If this variable is `none', Gnus will not make a false root, but just
114 present the sub-threads after another.
115 If this variable is `dummy', Gnus will create a dummy root that will
116 have all the sub-threads as children.
117 If this variable is `adopt', Gnus will make one of the \"children\"
118 the parent and mark all the step-children as such.
119 If this variable is `empty', the \"children\" are printed with empty
120 subject fields.  (Or rather, they will be printed with a string
121 given by the `gnus-summary-same-subject' variable.)"
122   :group 'gnus-thread
123   :type '(choice (const :tag "off" nil)
124                  (const none)
125                  (const dummy)
126                  (const adopt)
127                  (const empty)))
128
129 (defcustom gnus-summary-make-false-root-always nil
130   "Always make a false dummy root."
131   :version "21.4"
132   :group 'gnus-thread
133   :type 'boolean)
134
135 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
136   "*A regexp to match subjects to be excluded from loose thread gathering.
137 As loose thread gathering is done on subjects only, that means that
138 there can be many false gatherings performed.  By rooting out certain
139 common subjects, gathering might become saner."
140   :group 'gnus-thread
141   :type 'regexp)
142
143 (defcustom gnus-summary-gather-subject-limit nil
144   "*Maximum length of subject comparisons when gathering loose threads.
145 Use nil to compare full subjects.  Setting this variable to a low
146 number will help gather threads that have been corrupted by
147 newsreaders chopping off subject lines, but it might also mean that
148 unrelated articles that have subject that happen to begin with the
149 same few characters will be incorrectly gathered.
150
151 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
152 comparing subjects."
153   :group 'gnus-thread
154   :type '(choice (const :tag "off" nil)
155                  (const fuzzy)
156                  (sexp :menu-tag "on" t)))
157
158 (defcustom gnus-simplify-subject-functions nil
159   "List of functions taking a string argument that simplify subjects.
160 The functions are applied recursively.
161
162 Useful functions to put in this list include:
163 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
164 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
165   :group 'gnus-thread
166   :type '(repeat function))
167
168 (defcustom gnus-simplify-ignored-prefixes nil
169   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
170   :group 'gnus-thread
171   :type '(choice (const :tag "off" nil)
172                  regexp))
173
174 (defcustom gnus-build-sparse-threads nil
175   "*If non-nil, fill in the gaps in threads.
176 If `some', only fill in the gaps that are needed to tie loose threads
177 together.  If `more', fill in all leaf nodes that Gnus can find.  If
178 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
179   :group 'gnus-thread
180   :type '(choice (const :tag "off" nil)
181                  (const some)
182                  (const more)
183                  (sexp :menu-tag "all" t)))
184
185 (defcustom gnus-summary-thread-gathering-function
186   'gnus-gather-threads-by-subject
187   "*Function used for gathering loose threads.
188 There are two pre-defined functions: `gnus-gather-threads-by-subject',
189 which only takes Subjects into consideration; and
190 `gnus-gather-threads-by-references', which compared the References
191 headers of the articles to find matches."
192   :group 'gnus-thread
193   :type '(radio (function-item gnus-gather-threads-by-subject)
194                 (function-item gnus-gather-threads-by-references)
195                 (function :tag "other")))
196
197 (defcustom gnus-summary-same-subject ""
198   "*String indicating that the current article has the same subject as the previous.
199 This variable will only be used if the value of
200 `gnus-summary-make-false-root' is `empty'."
201   :group 'gnus-summary-format
202   :type 'string)
203
204 (defcustom gnus-summary-goto-unread t
205   "*If t, many commands will go to the next unread article.
206 This applies to marking commands as well as other commands that
207 \"naturally\" select the next article, like, for instance, `SPC' at
208 the end of an article.
209
210 If nil, the marking commands do NOT go to the next unread article
211 \(they go to the next article instead).  If `never', commands that
212 usually go to the next unread article, will go to the next article,
213 whether it is read or not."
214   :group 'gnus-summary-marks
215   :link '(custom-manual "(gnus)Setting Marks")
216   :type '(choice (const :tag "off" nil)
217                  (const never)
218                  (sexp :menu-tag "on" t)))
219
220 (defcustom gnus-summary-default-score 0
221   "*Default article score level.
222 All scores generated by the score files will be added to this score.
223 If this variable is nil, scoring will be disabled."
224   :group 'gnus-score-default
225   :type '(choice (const :tag "disable")
226                  integer))
227
228 (defcustom gnus-summary-default-high-score 0
229   "*Default threshold for a high scored article.
230 An article will be highlighted as high scored if its score is greater
231 than this score."
232   :version "21.4"
233   :group 'gnus-score-default
234   :type 'integer)
235
236 (defcustom gnus-summary-default-low-score 0
237   "*Default threshold for a low scored article.
238 An article will be highlighted as low scored if its score is smaller
239 than this score."
240   :version "21.4"
241   :group 'gnus-score-default
242   :type 'integer)
243
244 (defcustom gnus-summary-zcore-fuzz 0
245   "*Fuzziness factor for the zcore in the summary buffer.
246 Articles with scores closer than this to `gnus-summary-default-score'
247 will not be marked."
248   :group 'gnus-summary-format
249   :type 'integer)
250
251 (defcustom gnus-simplify-subject-fuzzy-regexp nil
252   "*Strings to be removed when doing fuzzy matches.
253 This can either be a regular expression or list of regular expressions
254 that will be removed from subject strings if fuzzy subject
255 simplification is selected."
256   :group 'gnus-thread
257   :type '(repeat regexp))
258
259 (defcustom gnus-show-threads t
260   "*If non-nil, display threads in summary mode."
261   :group 'gnus-thread
262   :type 'boolean)
263
264 (defcustom gnus-thread-hide-subtree nil
265   "*If non-nil, hide all threads initially.
266 This can be a predicate specifier which says which threads to hide.
267 If threads are hidden, you have to run the command
268 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
269 to expose hidden threads."
270   :group 'gnus-thread
271   :type '(radio (sexp :format "Non-nil\n"
272                       :match (lambda (widget value)
273                                (not (or (consp value) (functionp value))))
274                       :value t)
275                 (const nil)
276                 (sexp :tag "Predicate specifier" :size 0)))
277
278 (defcustom gnus-thread-hide-killed t
279   "*If non-nil, hide killed threads automatically."
280   :group 'gnus-thread
281   :type 'boolean)
282
283 (defcustom gnus-thread-ignore-subject t
284   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
285 If nil, articles that have different subjects from their parents will
286 start separate threads."
287   :group 'gnus-thread
288   :type 'boolean)
289
290 (defcustom gnus-thread-operation-ignore-subject t
291   "*If non-nil, subjects will be ignored when doing thread commands.
292 This affects commands like `gnus-summary-kill-thread' and
293 `gnus-summary-lower-thread'.
294
295 If this variable is nil, articles in the same thread with different
296 subjects will not be included in the operation in question.  If this
297 variable is `fuzzy', only articles that have subjects that are fuzzily
298 equal will be included."
299   :group 'gnus-thread
300   :type '(choice (const :tag "off" nil)
301                  (const fuzzy)
302                  (sexp :tag "on" t)))
303
304 (defcustom gnus-thread-indent-level 4
305   "*Number that says how much each sub-thread should be indented."
306   :group 'gnus-thread
307   :type 'integer)
308
309 (defcustom gnus-auto-extend-newsgroup t
310   "*If non-nil, extend newsgroup forward and backward when requested."
311   :group 'gnus-summary-choose
312   :type 'boolean)
313
314 (defcustom gnus-auto-select-first t
315   "*If non-nil, select the article under point.
316 Which article this is is controlled by the `gnus-auto-select-subject'
317 variable.
318
319 If you want to prevent automatic selection of articles in some
320 newsgroups, set the variable to nil in `gnus-select-group-hook'."
321   :group 'gnus-group-select
322   :type '(choice (const :tag "none" nil)
323                  (sexp :menu-tag "first" t)))
324
325 (defcustom gnus-auto-select-subject 'unread
326   "*Says what subject to place under point when entering a group.
327
328 This variable can either be the symbols `first' (place point on the
329 first subject), `unread' (place point on the subject line of the first
330 unread article), `best' (place point on the subject line of the
331 higest-scored article), `unseen' (place point on the subject line of
332 the first unseen article), 'unseen-or-unread' (place point on the subject
333 line of the first unseen article or, if all article have been seen, on the
334 subject line of the first unread article), or a function to be called to
335 place point on some subject line."
336   :version "21.4"
337   :group 'gnus-group-select
338   :type '(choice (const best)
339                  (const unread)
340                  (const first)
341                  (const unseen)
342                  (const unseen-or-unread)))
343
344 (defcustom gnus-dont-select-after-jump-to-other-group nil
345   "If non-nil, don't select the first unread article after entering the
346 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
347 it is depend on the value of `gnus-auto-select-first' whether to select
348 or not."
349   :group 'gnus-group-select
350   :type 'boolean)
351
352 (defcustom gnus-auto-select-next t
353   "*If non-nil, offer to go to the next group from the end of the previous.
354 If the value is t and the next newsgroup is empty, Gnus will exit
355 summary mode and go back to group mode.  If the value is neither nil
356 nor t, Gnus will select the following unread newsgroup.  In
357 particular, if the value is the symbol `quietly', the next unread
358 newsgroup will be selected without any confirmation, and if it is
359 `almost-quietly', the next group will be selected without any
360 confirmation if you are located on the last article in the group.
361 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
362 will go to the next group without confirmation."
363   :group 'gnus-summary-maneuvering
364   :type '(choice (const :tag "off" nil)
365                  (const quietly)
366                  (const almost-quietly)
367                  (const slightly-quietly)
368                  (sexp :menu-tag "on" t)))
369
370 (defcustom gnus-auto-select-same nil
371   "*If non-nil, select the next article with the same subject.
372 If there are no more articles with the same subject, go to
373 the first unread article."
374   :group 'gnus-summary-maneuvering
375   :type 'boolean)
376
377 (defcustom gnus-auto-goto-ignores 'unfetched
378   "*Says how to handle unfetched articles when maneuvering.
379
380 This variable can either be the symbols nil (maneuver to any
381 article), `undownloaded' (maneuvering while unplugged ignores articles
382 that have not been fetched), `always-undownloaded' (maneuvering always
383 ignores articles that have not been fetched), `unfetched' (maneuvering
384 ignores articles whose headers have not been fetched).
385
386 NOTE: The list of unfetched articles will always be nil when plugged
387 and, when unplugged, a subset of the undownloaded article list."
388   :version "21.4"
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "None" nil)
391                  (const :tag "Undownloaded when unplugged" undownloaded)
392                  (const :tag "Undownloaded" always-undownloaded)
393                  (const :tag "Unfetched" unfetched)))
394
395 (defcustom gnus-summary-check-current nil
396   "*If non-nil, consider the current article when moving.
397 The \"unread\" movement commands will stay on the same line if the
398 current article is unread."
399   :group 'gnus-summary-maneuvering
400   :type 'boolean)
401
402 (defcustom gnus-auto-center-summary 2
403   "*If non-nil, always center the current summary buffer.
404 In particular, if `vertical' do only vertical recentering.  If non-nil
405 and non-`vertical', do both horizontal and vertical recentering."
406   :group 'gnus-summary-maneuvering
407   :type '(choice (const :tag "none" nil)
408                  (const vertical)
409                  (integer :tag "height")
410                  (sexp :menu-tag "both" t)))
411
412 (defvar gnus-auto-center-group t
413   "*If non-nil, always center the group buffer.")
414
415 (defcustom gnus-show-all-headers nil
416   "*If non-nil, don't hide any headers."
417   :group 'gnus-article-hiding
418   :group 'gnus-article-headers
419   :type 'boolean)
420
421 (defcustom gnus-summary-ignore-duplicates nil
422   "*If non-nil, ignore articles with identical Message-ID headers."
423   :group 'gnus-summary
424   :type 'boolean)
425
426 (defcustom gnus-single-article-buffer t
427   "*If non-nil, display all articles in the same buffer.
428 If nil, each group will get its own article buffer."
429   :group 'gnus-article-various
430   :type 'boolean)
431
432 (defcustom gnus-break-pages t
433   "*If non-nil, do page breaking on articles.
434 The page delimiter is specified by the `gnus-page-delimiter'
435 variable."
436   :group 'gnus-article-various
437   :type 'boolean)
438
439 (defcustom gnus-show-mime t
440   "*If non-nil, do mime processing of articles.
441 The articles will simply be fed to the function given by
442 `gnus-article-display-method-for-mime'."
443   :group 'gnus-article-mime
444   :type 'boolean)
445
446 (defcustom gnus-move-split-methods nil
447   "*Variable used to suggest where articles are to be moved to.
448 It uses the same syntax as the `gnus-split-methods' variable.
449 However, whereas `gnus-split-methods' specifies file names as targets,
450 this variable specifies group names."
451   :group 'gnus-summary-mail
452   :type '(repeat (choice (list :value (fun) function)
453                          (cons :value ("" "") regexp (repeat string))
454                          (sexp :value nil))))
455
456 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
457   "Function used to compute default prefix for article move/copy/etc prompts.
458 The function should take one argument, a group name, and return a
459 string with the suggested prefix."
460   :group 'gnus-summary-mail
461   :type 'function)
462
463 (defcustom gnus-unread-mark ?\ ;;;Whitespace
464   "*Mark used for unread articles."
465   :group 'gnus-summary-marks
466   :type 'character)
467
468 (defcustom gnus-ticked-mark ?!
469   "*Mark used for ticked articles."
470   :group 'gnus-summary-marks
471   :type 'character)
472
473 (defcustom gnus-dormant-mark ??
474   "*Mark used for dormant articles."
475   :group 'gnus-summary-marks
476   :type 'character)
477
478 (defcustom gnus-del-mark ?r
479   "*Mark used for del'd articles."
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-read-mark ?R
484   "*Mark used for read articles."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-expirable-mark ?E
489   "*Mark used for expirable articles."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-killed-mark ?K
494   "*Mark used for killed articles."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-spam-mark ?$
499   "*Mark used for spam articles."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-souped-mark ?F
504   "*Mark used for souped articles."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-kill-file-mark ?X
509   "*Mark used for articles killed by kill files."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-low-score-mark ?Y
514   "*Mark used for articles with a low score."
515   :group 'gnus-summary-marks
516   :type 'character)
517
518 (defcustom gnus-catchup-mark ?C
519   "*Mark used for articles that are caught up."
520   :group 'gnus-summary-marks
521   :type 'character)
522
523 (defcustom gnus-replied-mark ?A
524   "*Mark used for articles that have been replied to."
525   :group 'gnus-summary-marks
526   :type 'character)
527
528 (defcustom gnus-forwarded-mark ?F
529   "*Mark used for articles that have been forwarded."
530   :version "21.4"
531   :group 'gnus-summary-marks
532   :type 'character)
533
534 (defcustom gnus-recent-mark ?N
535   "*Mark used for articles that are recent."
536   :group 'gnus-summary-marks
537   :type 'character)
538
539 (defcustom gnus-cached-mark ?*
540   "*Mark used for articles that are in the cache."
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-saved-mark ?S
545   "*Mark used for articles that have been saved."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-unseen-mark ?.
550   "*Mark used for articles that haven't been seen."
551   :version "21.4"
552   :group 'gnus-summary-marks
553   :type 'character)
554
555 (defcustom gnus-no-mark ?\ ;;;Whitespace
556   "*Mark used for articles that have no other secondary mark."
557   :version "21.4"
558   :group 'gnus-summary-marks
559   :type 'character)
560
561 (defcustom gnus-ancient-mark ?O
562   "*Mark used for ancient articles."
563   :group 'gnus-summary-marks
564   :type 'character)
565
566 (defcustom gnus-sparse-mark ?Q
567   "*Mark used for sparsely reffed articles."
568   :group 'gnus-summary-marks
569   :type 'character)
570
571 (defcustom gnus-canceled-mark ?G
572   "*Mark used for canceled articles."
573   :group 'gnus-summary-marks
574   :type 'character)
575
576 (defcustom gnus-duplicate-mark ?M
577   "*Mark used for duplicate articles."
578   :group 'gnus-summary-marks
579   :type 'character)
580
581 (defcustom gnus-undownloaded-mark ?-
582   "*Mark used for articles that weren't downloaded."
583   :group 'gnus-summary-marks
584   :type 'character)
585
586 (defcustom gnus-downloaded-mark ?+
587   "*Mark used for articles that were downloaded."
588   :group 'gnus-summary-marks
589   :type 'character)
590
591 (defcustom gnus-downloadable-mark ?%
592   "*Mark used for articles that are to be downloaded."
593   :group 'gnus-summary-marks
594   :type 'character)
595
596 (defcustom gnus-unsendable-mark ?=
597   "*Mark used for articles that won't be sent."
598   :group 'gnus-summary-marks
599   :type 'character)
600
601 (defcustom gnus-score-over-mark ?+
602   "*Score mark used for articles with high scores."
603   :group 'gnus-summary-marks
604   :type 'character)
605
606 (defcustom gnus-score-below-mark ?-
607   "*Score mark used for articles with low scores."
608   :group 'gnus-summary-marks
609   :type 'character)
610
611 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
612   "*There is no thread under the article."
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-not-empty-thread-mark ?=
617   "*There is a thread under the article."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-view-pseudo-asynchronously nil
622   "*If non-nil, Gnus will view pseudo-articles asynchronously."
623   :group 'gnus-extract-view
624   :type 'boolean)
625
626 (defcustom gnus-auto-expirable-marks
627   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
628         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
629         gnus-souped-mark gnus-duplicate-mark)
630   "*The list of marks converted into expiration if a group is auto-expirable."
631   :version "21.1"
632   :group 'gnus-summary
633   :type '(repeat character))
634
635 (defcustom gnus-inhibit-user-auto-expire t
636   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
637   :version "21.1"
638   :group 'gnus-summary
639   :type 'boolean)
640
641 (defcustom gnus-view-pseudos nil
642   "*If `automatic', pseudo-articles will be viewed automatically.
643 If `not-confirm', pseudos will be viewed automatically, and the user
644 will not be asked to confirm the command."
645   :group 'gnus-extract-view
646   :type '(choice (const :tag "off" nil)
647                  (const automatic)
648                  (const not-confirm)))
649
650 (defcustom gnus-view-pseudos-separately t
651   "*If non-nil, one pseudo-article will be created for each file to be viewed.
652 If nil, all files that use the same viewing command will be given as a
653 list of parameters to that command."
654   :group 'gnus-extract-view
655   :type 'boolean)
656
657 (defcustom gnus-insert-pseudo-articles t
658   "*If non-nil, insert pseudo-articles when decoding articles."
659   :group 'gnus-extract-view
660   :type 'boolean)
661
662 (defcustom gnus-summary-dummy-line-format
663   "   %(:                             :%) %S\n"
664   "*The format specification for the dummy roots in the summary buffer.
665 It works along the same lines as a normal formatting string,
666 with some simple extensions.
667
668 %S  The subject
669
670 General format specifiers can also be used.
671 See `(gnus)Formatting Variables'."
672   :link '(custom-manual "(gnus)Formatting Variables")
673   :group 'gnus-threading
674   :type 'string)
675
676 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
677   "*The format specification for the summary mode line.
678 It works along the same lines as a normal formatting string,
679 with some simple extensions:
680
681 %G  Group name
682 %p  Unprefixed group name
683 %A  Current article number
684 %z  Current article score
685 %V  Gnus version
686 %U  Number of unread articles in the group
687 %e  Number of unselected articles in the group
688 %Z  A string with unread/unselected article counts
689 %g  Shortish group name
690 %S  Subject of the current article
691 %u  User-defined spec
692 %s  Current score file name
693 %d  Number of dormant articles
694 %r  Number of articles that have been marked as read in this session
695 %E  Number of articles expunged by the score files"
696   :group 'gnus-summary-format
697   :type 'string)
698
699 (defcustom gnus-list-identifiers nil
700   "Regexp that matches list identifiers to be removed from subject.
701 This can also be a list of regexps."
702   :version "21.1"
703   :group 'gnus-summary-format
704   :group 'gnus-article-hiding
705   :type '(choice (const :tag "none" nil)
706                  (regexp :value ".*")
707                  (repeat :value (".*") regexp)))
708
709 (defcustom gnus-summary-mark-below 0
710   "*Mark all articles with a score below this variable as read.
711 This variable is local to each summary buffer and usually set by the
712 score file."
713   :group 'gnus-score-default
714   :type 'integer)
715
716 (defun gnus-widget-reversible-match (widget value)
717   "Ignoring WIDGET, convert VALUE to internal form.
718 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
719   ;; (debug value)
720   (or (symbolp value)
721       (and (listp value)
722            (eq (length value) 2)
723            (eq (nth 0 value) 'not)
724            (symbolp (nth 1 value)))))
725
726 (defun gnus-widget-reversible-to-internal (widget value)
727   "Ignoring WIDGET, convert VALUE to internal form.
728 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
729 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
730   ;; (debug value)
731   (if (atom value)
732       (list value nil)
733     (list (nth 1 value) t)))
734
735 (defun gnus-widget-reversible-to-external (widget value)
736   "Ignoring WIDGET, convert VALUE to external form.
737 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
738 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
739   ;; (debug value)
740   (if (nth 1 value)
741       (list 'not (nth 0 value))
742     (nth 0 value)))
743
744 (define-widget 'gnus-widget-reversible 'group
745   "A `group' that convert values."
746   :match 'gnus-widget-reversible-match
747   :value-to-internal 'gnus-widget-reversible-to-internal
748   :value-to-external 'gnus-widget-reversible-to-external)
749
750 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
751   "*List of functions used for sorting articles in the summary buffer.
752
753 Each function takes two articles and returns non-nil if the first
754 article should be sorted before the other.  If you use more than one
755 function, the primary sort function should be the last.  You should
756 probably always include `gnus-article-sort-by-number' in the list of
757 sorting functions -- preferably first.  Also note that sorting by date
758 is often much slower than sorting by number, and the sorting order is
759 very similar.  (Sorting by date means sorting by the time the message
760 was sent, sorting by number means sorting by arrival time.)
761
762 Each item can also be a list `(not F)' where F is a function;
763 this reverses the sort order.
764
765 Ready-made functions include `gnus-article-sort-by-number',
766 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
767 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
768 and `gnus-article-sort-by-score'.
769
770 When threading is turned on, the variable `gnus-thread-sort-functions'
771 controls how articles are sorted."
772   :group 'gnus-summary-sort
773   :type '(repeat (gnus-widget-reversible
774                   (choice (function-item gnus-article-sort-by-number)
775                           (function-item gnus-article-sort-by-author)
776                           (function-item gnus-article-sort-by-subject)
777                           (function-item gnus-article-sort-by-date)
778                           (function-item gnus-article-sort-by-score)
779                           (function-item gnus-article-sort-by-random)
780                           (function :tag "other"))
781                   (boolean :tag "Reverse order"))))
782
783
784 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
785   "*List of functions used for sorting threads in the summary buffer.
786 By default, threads are sorted by article number.
787
788 Each function takes two threads and returns non-nil if the first
789 thread should be sorted before the other.  If you use more than one
790 function, the primary sort function should be the last.  You should
791 probably always include `gnus-thread-sort-by-number' in the list of
792 sorting functions -- preferably first.  Also note that sorting by date
793 is often much slower than sorting by number, and the sorting order is
794 very similar.  (Sorting by date means sorting by the time the message
795 was sent, sorting by number means sorting by arrival time.)
796
797 Each list item can also be a list `(not F)' where F is a
798 function; this specifies reversed sort order.
799
800 Ready-made functions include `gnus-thread-sort-by-number',
801 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
802 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
803 `gnus-thread-sort-by-most-recent-number',
804 `gnus-thread-sort-by-most-recent-date',
805 `gnus-thread-sort-by-random', and
806 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
807
808 When threading is turned off, the variable
809 `gnus-article-sort-functions' controls how articles are sorted."
810   :group 'gnus-summary-sort
811   :type '(repeat 
812           (gnus-widget-reversible
813            (choice (function-item gnus-thread-sort-by-number)
814                    (function-item gnus-thread-sort-by-author)
815                    (function-item gnus-thread-sort-by-subject)
816                    (function-item gnus-thread-sort-by-date)
817                    (function-item gnus-thread-sort-by-score)
818                    (function-item gnus-thread-sort-by-most-recent-number)
819                    (function-item gnus-thread-sort-by-most-recent-date)
820                    (function-item gnus-thread-sort-by-random)
821                    (function-item gnus-thread-sort-by-total-score)
822                    (function :tag "other"))
823            (boolean :tag "Reverse order"))))
824
825 (defcustom gnus-thread-score-function '+
826   "*Function used for calculating the total score of a thread.
827
828 The function is called with the scores of the article and each
829 subthread and should then return the score of the thread.
830
831 Some functions you can use are `+', `max', or `min'."
832   :group 'gnus-summary-sort
833   :type 'function)
834
835 (defcustom gnus-summary-expunge-below nil
836   "All articles that have a score less than this variable will be expunged.
837 This variable is local to the summary buffers."
838   :group 'gnus-score-default
839   :type '(choice (const :tag "off" nil)
840                  integer))
841
842 (defcustom gnus-thread-expunge-below nil
843   "All threads that have a total score less than this variable will be expunged.
844 See `gnus-thread-score-function' for en explanation of what a
845 \"thread score\" is.
846
847 This variable is local to the summary buffers."
848   :group 'gnus-threading
849   :group 'gnus-score-default
850   :type '(choice (const :tag "off" nil)
851                  integer))
852
853 (defcustom gnus-summary-mode-hook nil
854   "*A hook for Gnus summary mode.
855 This hook is run before any variables are set in the summary buffer."
856   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
857   :group 'gnus-summary-various
858   :type 'hook)
859
860 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
861 (when (featurep 'xemacs)
862   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
863   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
864   (add-hook 'gnus-summary-mode-hook
865             'gnus-xmas-switch-horizontal-scrollbar-off))
866
867 (defcustom gnus-summary-menu-hook nil
868   "*Hook run after the creation of the summary mode menu."
869   :group 'gnus-summary-visual
870   :type 'hook)
871
872 (defcustom gnus-summary-exit-hook nil
873   "*A hook called on exit from the summary buffer.
874 It will be called with point in the group buffer."
875   :group 'gnus-summary-exit
876   :type 'hook)
877
878 (defcustom gnus-summary-prepare-hook nil
879   "*A hook called after the summary buffer has been generated.
880 If you want to modify the summary buffer, you can use this hook."
881   :group 'gnus-summary-various
882   :type 'hook)
883
884 (defcustom gnus-summary-prepared-hook nil
885   "*A hook called as the last thing after the summary buffer has been generated."
886   :group 'gnus-summary-various
887   :type 'hook)
888
889 (defcustom gnus-summary-generate-hook nil
890   "*A hook run just before generating the summary buffer.
891 This hook is commonly used to customize threading variables and the
892 like."
893   :group 'gnus-summary-various
894   :type 'hook)
895
896 (defcustom gnus-select-group-hook nil
897   "*A hook called when a newsgroup is selected.
898
899 If you'd like to simplify subjects like the
900 `gnus-summary-next-same-subject' command does, you can use the
901 following hook:
902
903  (add-hook gnus-select-group-hook
904            (lambda ()
905              (mapcar (lambda (header)
906                        (mail-header-set-subject
907                         header
908                         (gnus-simplify-subject
909                          (mail-header-subject header) 're-only)))
910                      gnus-newsgroup-headers)))"
911   :group 'gnus-group-select
912   :type 'hook)
913
914 (defcustom gnus-select-article-hook nil
915   "*A hook called when an article is selected."
916   :group 'gnus-summary-choose
917   :options '(gnus-agent-fetch-selected-article)
918   :type 'hook)
919
920 (defcustom gnus-visual-mark-article-hook
921   (list 'gnus-highlight-selected-summary)
922   "*Hook run after selecting an article in the summary buffer.
923 It is meant to be used for highlighting the article in some way.  It
924 is not run if `gnus-visual' is nil."
925   :group 'gnus-summary-visual
926   :type 'hook)
927
928 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
929   "*A hook called before parsing the headers."
930   :group 'gnus-various
931   :type 'hook)
932
933 (defcustom gnus-exit-group-hook nil
934   "*A hook called when exiting summary mode.
935 This hook is not called from the non-updating exit commands like `Q'."
936   :group 'gnus-various
937   :type 'hook)
938
939 (defcustom gnus-summary-update-hook
940   (list 'gnus-summary-highlight-line)
941   "*A hook called when a summary line is changed.
942 The hook will not be called if `gnus-visual' is nil.
943
944 The default function `gnus-summary-highlight-line' will
945 highlight the line according to the `gnus-summary-highlight'
946 variable."
947   :group 'gnus-summary-visual
948   :type 'hook)
949
950 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
951   "*A hook called when an article is selected for the first time.
952 The hook is intended to mark an article as read (or unread)
953 automatically when it is selected."
954   :group 'gnus-summary-choose
955   :type 'hook)
956
957 (defcustom gnus-group-no-more-groups-hook nil
958   "*A hook run when returning to group mode having no more (unread) groups."
959   :group 'gnus-group-select
960   :type 'hook)
961
962 (defcustom gnus-ps-print-hook nil
963   "*A hook run before ps-printing something from Gnus."
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-article-move-hook nil
968   "*A hook called after an article is moved, copied, respooled, or crossposted."
969   :group 'gnus-summary
970   :type 'hook)
971
972 (defcustom gnus-summary-article-delete-hook nil
973   "*A hook called after an article is deleted."
974   :group 'gnus-summary
975   :type 'hook)
976
977 (defcustom gnus-summary-article-expire-hook nil
978   "*A hook called after an article is expired."
979   :group 'gnus-summary
980   :type 'hook)
981
982 (defcustom gnus-summary-display-arrow
983   (and (fboundp 'display-graphic-p)
984        (display-graphic-p))
985   "*If non-nil, display an arrow highlighting the current article."
986   :version "21.4"
987   :group 'gnus-summary
988   :type 'boolean)
989
990 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
991   "Face used for highlighting the current article in the summary buffer."
992   :group 'gnus-summary-visual
993   :type 'face)
994
995 (defvar gnus-tmp-downloaded nil)
996
997 (defcustom gnus-summary-highlight
998   '(((eq mark gnus-canceled-mark)
999      . gnus-summary-cancelled-face)
1000     ((and uncached (> score default-high))
1001      . gnus-summary-high-undownloaded-face)
1002     ((and uncached (< score default-low))
1003      . gnus-summary-low-undownloaded-face)
1004     (uncached
1005      . gnus-summary-normal-undownloaded-face)
1006     ((and (> score default-high)
1007           (or (eq mark gnus-dormant-mark)
1008               (eq mark gnus-ticked-mark)))
1009      . gnus-summary-high-ticked-face)
1010     ((and (< score default-low)
1011           (or (eq mark gnus-dormant-mark)
1012               (eq mark gnus-ticked-mark)))
1013      . gnus-summary-low-ticked-face)
1014     ((or (eq mark gnus-dormant-mark)
1015          (eq mark gnus-ticked-mark))
1016      . gnus-summary-normal-ticked-face)
1017     ((and (> score default-high) (eq mark gnus-ancient-mark))
1018      . gnus-summary-high-ancient-face)
1019     ((and (< score default-low) (eq mark gnus-ancient-mark))
1020      . gnus-summary-low-ancient-face)
1021     ((eq mark gnus-ancient-mark)
1022      . gnus-summary-normal-ancient-face)
1023     ((and (> score default-high) (eq mark gnus-unread-mark))
1024      . gnus-summary-high-unread-face)
1025     ((and (< score default-low) (eq mark gnus-unread-mark))
1026      . gnus-summary-low-unread-face)
1027     ((eq mark gnus-unread-mark)
1028      . gnus-summary-normal-unread-face)
1029     ((> score default-high)
1030      . gnus-summary-high-read-face)
1031     ((< score default-low)
1032      . gnus-summary-low-read-face)
1033     (t
1034      . gnus-summary-normal-read-face))
1035   "*Controls the highlighting of summary buffer lines.
1036
1037 A list of (FORM . FACE) pairs.  When deciding how a a particular
1038 summary line should be displayed, each form is evaluated.  The content
1039 of the face field after the first true form is used.  You can change
1040 how those summary lines are displayed, by editing the face field.
1041
1042 You can use the following variables in the FORM field.
1043
1044 score:        The article's score
1045 default:      The default article score.
1046 default-high: The default score for high scored articles.
1047 default-low:  The default score for low scored articles.
1048 below:        The score below which articles are automatically marked as read.
1049 mark:         The article's mark.
1050 uncached:     Non-nil if the article is uncached."
1051   :group 'gnus-summary-visual
1052   :type '(repeat (cons (sexp :tag "Form" nil)
1053                        face)))
1054
1055 (defcustom gnus-alter-header-function nil
1056   "Function called to allow alteration of article header structures.
1057 The function is called with one parameter, the article header vector,
1058 which it may alter in any way."
1059   :type '(choice (const :tag "None" nil)
1060                  function)
1061   :group 'gnus-summary)
1062
1063 (defvar gnus-decode-encoded-word-function
1064   (mime-find-field-decoder 'From 'nov)
1065   "Variable that says which function should be used to decode a string with encoded words.")
1066
1067 (defcustom gnus-extra-headers '(To Newsgroups)
1068   "*Extra headers to parse."
1069   :version "21.1"
1070   :group 'gnus-summary
1071   :type '(repeat symbol))
1072
1073 (defcustom gnus-ignored-from-addresses
1074   (and user-mail-address (regexp-quote user-mail-address))
1075   "*Regexp of From headers that may be suppressed in favor of To headers."
1076   :version "21.1"
1077   :group 'gnus-summary
1078   :type 'regexp)
1079
1080 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1081   "List of charsets that should be ignored.
1082 When these charsets are used in the \"charset\" parameter, the
1083 default charset will be used instead."
1084   :version "21.1"
1085   :type '(repeat symbol)
1086   :group 'gnus-charset)
1087
1088 (gnus-define-group-parameter
1089  ignored-charsets
1090  :type list
1091  :function-document
1092  "Return the ignored charsets of GROUP."
1093  :variable gnus-group-ignored-charsets-alist
1094  :variable-default
1095  '(("alt\\.chinese\\.text" iso-8859-1))
1096  :variable-document
1097  "Alist of regexps (to match group names) and charsets that should be ignored.
1098 When these charsets are used in the \"charset\" parameter, the
1099 default charset will be used instead."
1100  :variable-group gnus-charset
1101  :variable-type '(repeat (cons (regexp :tag "Group")
1102                                (repeat symbol)))
1103  :parameter-type '(choice :tag "Ignored charsets"
1104                           :value nil
1105                           (repeat (symbol)))
1106  :parameter-document       "\
1107 List of charsets that should be ignored.
1108
1109 When these charsets are used in the \"charset\" parameter, the
1110 default charset will be used instead.")
1111
1112 (defcustom gnus-group-highlight-words-alist nil
1113   "Alist of group regexps and highlight regexps.
1114 This variable uses the same syntax as `gnus-emphasis-alist'."
1115   :version "21.1"
1116   :type '(repeat (cons (regexp :tag "Group")
1117                        (repeat (list (regexp :tag "Highlight regexp")
1118                                      (number :tag "Group for entire word" 0)
1119                                      (number :tag "Group for displayed part" 0)
1120                                      (symbol :tag "Face"
1121                                              gnus-emphasis-highlight-words)))))
1122   :group 'gnus-summary-visual)
1123
1124 (defcustom gnus-use-wheel nil
1125   "Use Intelli-mouse on summary movement"
1126   :type 'boolean
1127   :group 'gnus-summary-maneuvering)
1128
1129 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1130   "Amount to scroll messages by spinning the mouse wheel.
1131 This is actually a cons cell, where the first item is the amount to scroll
1132 on a normal wheel event, and the second is the amount to scroll when the
1133 wheel is moved with the shift key depressed."
1134   :type '(cons (integer :tag "Shift") integer)
1135   :group 'gnus-summary-maneuvering)
1136
1137 (defcustom gnus-wheel-edge-resistance 2
1138   "How hard it should be to change the current article
1139 by moving the mouse over the edge of the article window."
1140   :type 'integer
1141   :group 'gnus-summary-maneuvering)
1142
1143 (defcustom gnus-summary-show-article-charset-alist
1144   nil
1145   "Alist of number and charset.
1146 The article will be shown with the charset corresponding to the
1147 numbered argument.
1148 For example: ((1 . cn-gb-2312) (2 . big5))."
1149   :version "21.1"
1150   :type '(repeat (cons (number :tag "Argument" 1)
1151                        (symbol :tag "Charset")))
1152   :group 'gnus-charset)
1153
1154 (defcustom gnus-preserve-marks t
1155   "Whether marks are preserved when moving, copying and respooling messages."
1156   :version "21.1"
1157   :type 'boolean
1158   :group 'gnus-summary-marks)
1159
1160 (defcustom gnus-alter-articles-to-read-function nil
1161   "Function to be called to alter the list of articles to be selected."
1162   :type '(choice (const nil) function)
1163   :group 'gnus-summary)
1164
1165 (defcustom gnus-orphan-score nil
1166   "*All orphans get this score added.  Set in the score file."
1167   :group 'gnus-score-default
1168   :type '(choice (const nil)
1169                  integer))
1170
1171 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1172   "*A regexp to match MIME parts when saving multiple parts of a
1173 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1174 This regexp will be used by default when prompting the user for which
1175 type of files to save."
1176   :group 'gnus-summary
1177   :type 'regexp)
1178
1179 (defcustom gnus-read-all-available-headers nil
1180   "Whether Gnus should parse all headers made available to it.
1181 This is mostly relevant for slow back ends where the user may
1182 wish to widen the summary buffer to include all headers
1183 that were fetched.  Say, for nnultimate groups."
1184   :version "21.4"
1185   :group 'gnus-summary
1186   :type '(choice boolean regexp))
1187
1188 (defcustom gnus-summary-muttprint-program "muttprint"
1189   "Command (and optional arguments) used to run Muttprint."
1190   :version "21.4"
1191   :group 'gnus-summary
1192   :type 'string)
1193
1194 (defcustom gnus-article-loose-mime t
1195   "If non-nil, don't require MIME-Version header.
1196 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1197 supply the MIME-Version header or deliberately strip it from the mail.
1198 If non-nil (the default), Gnus will treat some articles as MIME
1199 even if the MIME-Version header is missing."
1200   :version "21.4"
1201   :type 'boolean
1202   :group 'gnus-article-mime)
1203
1204 (defcustom gnus-article-emulate-mime t
1205   "If non-nil, use MIME emulation for uuencode and the like.
1206 This means that Gnus will search message bodies for text that look
1207 like uuencoded bits, yEncoded bits, and so on, and present that using
1208 the normal Gnus MIME machinery."
1209   :version "21.4"
1210   :type 'boolean
1211   :group 'gnus-article-mime)
1212
1213 ;;; Internal variables
1214
1215 (defvar gnus-summary-display-cache nil)
1216 (defvar gnus-article-mime-handles nil)
1217 (defvar gnus-article-decoded-p nil)
1218 (defvar gnus-article-charset nil)
1219 (defvar gnus-article-ignored-charsets nil)
1220 (defvar gnus-scores-exclude-files nil)
1221 (defvar gnus-page-broken nil)
1222
1223 (defvar gnus-original-article nil)
1224 (defvar gnus-article-internal-prepare-hook nil)
1225 (defvar gnus-newsgroup-process-stack nil)
1226
1227 (defvar gnus-thread-indent-array nil)
1228 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1229 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1230   "Function called to sort the articles within a thread after it has been gathered together.")
1231
1232 (defvar gnus-summary-save-parts-type-history nil)
1233 (defvar gnus-summary-save-parts-last-directory nil)
1234
1235 ;; Avoid highlighting in kill files.
1236 (defvar gnus-summary-inhibit-highlight nil)
1237 (defvar gnus-newsgroup-selected-overlay nil)
1238 (defvar gnus-inhibit-limiting nil)
1239 (defvar gnus-newsgroup-adaptive-score-file nil)
1240 (defvar gnus-current-score-file nil)
1241 (defvar gnus-current-move-group nil)
1242 (defvar gnus-current-copy-group nil)
1243 (defvar gnus-current-crosspost-group nil)
1244 (defvar gnus-newsgroup-display nil)
1245
1246 (defvar gnus-newsgroup-dependencies nil)
1247 (defvar gnus-newsgroup-adaptive nil)
1248 (defvar gnus-summary-display-article-function nil)
1249 (defvar gnus-summary-highlight-line-function nil
1250   "Function called after highlighting a summary line.")
1251
1252 (defvar gnus-summary-line-format-alist
1253   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1254     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1255     (?s gnus-tmp-subject-or-nil ?s)
1256     (?n gnus-tmp-name ?s)
1257     (?A (std11-address-string
1258          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1259     (?a (or (std11-full-name-string
1260              (car (mime-entity-read-field gnus-tmp-header 'From)))
1261             gnus-tmp-from) ?s)
1262     (?F gnus-tmp-from ?s)
1263     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1264     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1265     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1266     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1267     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1268     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1269     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1270     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1271     (?L gnus-tmp-lines ?s)
1272     (?O gnus-tmp-downloaded ?c)
1273     (?I gnus-tmp-indentation ?s)
1274     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1275     (?R gnus-tmp-replied ?c)
1276     (?\[ gnus-tmp-opening-bracket ?c)
1277     (?\] gnus-tmp-closing-bracket ?c)
1278     (?\> (make-string gnus-tmp-level ? ) ?s)
1279     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1280     (?i gnus-tmp-score ?d)
1281     (?z gnus-tmp-score-char ?c)
1282     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1283     (?U gnus-tmp-unread ?c)
1284     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1285         ?s)
1286     (?t (gnus-summary-number-of-articles-in-thread
1287          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1288         ?d)
1289     (?e (gnus-summary-number-of-articles-in-thread
1290          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1291         ?c)
1292     (?u gnus-tmp-user-defined ?s)
1293     (?P (gnus-pick-line-number) ?d)
1294     (?B gnus-tmp-thread-tree-header-string ?s)
1295     (user-date (gnus-user-date
1296                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1297   "An alist of format specifications that can appear in summary lines.
1298 These are paired with what variables they correspond with, along with
1299 the type of the variable (string, integer, character, etc).")
1300
1301 (defvar gnus-summary-dummy-line-format-alist
1302   `((?S gnus-tmp-subject ?s)
1303     (?N gnus-tmp-number ?d)
1304     (?u gnus-tmp-user-defined ?s)))
1305
1306 (defvar gnus-summary-mode-line-format-alist
1307   `((?G gnus-tmp-group-name ?s)
1308     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1309     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1310     (?A gnus-tmp-article-number ?d)
1311     (?Z gnus-tmp-unread-and-unselected ?s)
1312     (?V gnus-version ?s)
1313     (?U gnus-tmp-unread-and-unticked ?d)
1314     (?S gnus-tmp-subject ?s)
1315     (?e gnus-tmp-unselected ?d)
1316     (?u gnus-tmp-user-defined ?s)
1317     (?d (length gnus-newsgroup-dormant) ?d)
1318     (?t (length gnus-newsgroup-marked) ?d)
1319     (?h (length gnus-newsgroup-spam-marked) ?d)
1320     (?r (length gnus-newsgroup-reads) ?d)
1321     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1322     (?E gnus-newsgroup-expunged-tally ?d)
1323     (?s (gnus-current-score-file-nondirectory) ?s)))
1324
1325 (defvar gnus-last-search-regexp nil
1326   "Default regexp for article search command.")
1327
1328 (defvar gnus-summary-search-article-matched-data nil
1329   "Last matched data of article search command.  It is the local variable
1330 in `gnus-article-buffer' which consists of the list of start position,
1331 end position and text.")
1332
1333 (defvar gnus-last-shell-command nil
1334   "Default shell command on article.")
1335
1336 (defvar gnus-newsgroup-agentized nil
1337   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1338 (defvar gnus-newsgroup-begin nil)
1339 (defvar gnus-newsgroup-end nil)
1340 (defvar gnus-newsgroup-last-rmail nil)
1341 (defvar gnus-newsgroup-last-mail nil)
1342 (defvar gnus-newsgroup-last-folder nil)
1343 (defvar gnus-newsgroup-last-file nil)
1344 (defvar gnus-newsgroup-auto-expire nil)
1345 (defvar gnus-newsgroup-active nil)
1346
1347 (defvar gnus-newsgroup-data nil)
1348 (defvar gnus-newsgroup-data-reverse nil)
1349 (defvar gnus-newsgroup-limit nil)
1350 (defvar gnus-newsgroup-limits nil)
1351 (defvar gnus-summary-use-undownloaded-faces nil)
1352
1353 (defvar gnus-newsgroup-unreads nil
1354   "Sorted list of unread articles in the current newsgroup.")
1355
1356 (defvar gnus-newsgroup-unselected nil
1357   "Sorted list of unselected unread articles in the current newsgroup.")
1358
1359 (defvar gnus-newsgroup-reads nil
1360   "Alist of read articles and article marks in the current newsgroup.")
1361
1362 (defvar gnus-newsgroup-expunged-tally nil)
1363
1364 (defvar gnus-newsgroup-marked nil
1365   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1366
1367 (defvar gnus-newsgroup-spam-marked nil
1368   "List of ranges of articles that have been marked as spam.")
1369
1370 (defvar gnus-newsgroup-killed nil
1371   "List of ranges of articles that have been through the scoring process.")
1372
1373 (defvar gnus-newsgroup-cached nil
1374   "Sorted list of articles that come from the article cache.")
1375
1376 (defvar gnus-newsgroup-saved nil
1377   "List of articles that have been saved.")
1378
1379 (defvar gnus-newsgroup-kill-headers nil)
1380
1381 (defvar gnus-newsgroup-replied nil
1382   "List of articles that have been replied to in the current newsgroup.")
1383
1384 (defvar gnus-newsgroup-forwarded nil
1385   "List of articles that have been forwarded in the current newsgroup.")
1386
1387 (defvar gnus-newsgroup-recent nil
1388   "List of articles that have are recent in the current newsgroup.")
1389
1390 (defvar gnus-newsgroup-expirable nil
1391   "Sorted list of articles in the current newsgroup that can be expired.")
1392
1393 (defvar gnus-newsgroup-processable nil
1394   "List of articles in the current newsgroup that can be processed.")
1395
1396 (defvar gnus-newsgroup-downloadable nil
1397   "Sorted list of articles in the current newsgroup that can be processed.")
1398
1399 (defvar gnus-newsgroup-unfetched nil
1400   "Sorted list of articles in the current newsgroup whose headers have
1401 not been fetched into the agent.
1402
1403 This list will always be a subset of gnus-newsgroup-undownloaded.")
1404
1405 (defvar gnus-newsgroup-undownloaded nil
1406   "List of articles in the current newsgroup that haven't been downloaded.")
1407
1408 (defvar gnus-newsgroup-unsendable nil
1409   "List of articles in the current newsgroup that won't be sent.")
1410
1411 (defvar gnus-newsgroup-bookmarks nil
1412   "List of articles in the current newsgroup that have bookmarks.")
1413
1414 (defvar gnus-newsgroup-dormant nil
1415   "Sorted list of dormant articles in the current newsgroup.")
1416
1417 (defvar gnus-newsgroup-unseen nil
1418   "List of unseen articles in the current newsgroup.")
1419
1420 (defvar gnus-newsgroup-seen nil
1421   "Range of seen articles in the current newsgroup.")
1422
1423 (defvar gnus-newsgroup-articles nil
1424   "List of articles in the current newsgroup.")
1425
1426 (defvar gnus-newsgroup-scored nil
1427   "List of scored articles in the current newsgroup.")
1428
1429 (defvar gnus-newsgroup-incorporated nil
1430   "List of incorporated articles in the current newsgroup.")
1431
1432 (defvar gnus-newsgroup-headers nil
1433   "List of article headers in the current newsgroup.")
1434
1435 (defvar gnus-newsgroup-threads nil)
1436
1437 (defvar gnus-newsgroup-prepared nil
1438   "Whether the current group has been prepared properly.")
1439
1440 (defvar gnus-newsgroup-ancient nil
1441   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1442
1443 (defvar gnus-newsgroup-sparse nil)
1444
1445 (defvar gnus-current-article nil)
1446 (defvar gnus-article-current nil)
1447 (defvar gnus-current-headers nil)
1448 (defvar gnus-have-all-headers nil)
1449 (defvar gnus-last-article nil)
1450 (defvar gnus-newsgroup-history nil)
1451 (defvar gnus-newsgroup-charset nil)
1452 (defvar gnus-newsgroup-ephemeral-charset nil)
1453 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1454
1455 (defvar gnus-article-before-search nil)
1456
1457 (defvar gnus-summary-local-variables
1458   '(gnus-newsgroup-name
1459     gnus-newsgroup-begin gnus-newsgroup-end
1460     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1461     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1462     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1463     gnus-newsgroup-unselected gnus-newsgroup-marked
1464     gnus-newsgroup-spam-marked
1465     gnus-newsgroup-reads gnus-newsgroup-saved
1466     gnus-newsgroup-replied gnus-newsgroup-forwarded
1467     gnus-newsgroup-recent
1468     gnus-newsgroup-expirable
1469     gnus-newsgroup-processable gnus-newsgroup-killed
1470     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1471     gnus-newsgroup-unfetched
1472     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1473     gnus-newsgroup-seen gnus-newsgroup-articles
1474     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1475     gnus-newsgroup-headers gnus-newsgroup-threads
1476     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1477     gnus-current-article gnus-current-headers gnus-have-all-headers
1478     gnus-last-article gnus-article-internal-prepare-hook
1479     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1480     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1481     gnus-thread-expunge-below
1482     gnus-score-alist gnus-current-score-file
1483     (gnus-summary-expunge-below . global)
1484     (gnus-summary-mark-below . global)
1485     (gnus-orphan-score . global)
1486     gnus-newsgroup-active gnus-scores-exclude-files
1487     gnus-newsgroup-history gnus-newsgroup-ancient
1488     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1489     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1490     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1491     (gnus-newsgroup-expunged-tally . 0)
1492     gnus-cache-removable-articles gnus-newsgroup-cached
1493     gnus-newsgroup-data gnus-newsgroup-data-reverse
1494     gnus-newsgroup-limit gnus-newsgroup-limits
1495     gnus-newsgroup-charset gnus-newsgroup-display
1496     gnus-summary-use-undownloaded-faces
1497     gnus-newsgroup-incorporated)
1498   "Variables that are buffer-local to the summary buffers.")
1499
1500 (defvar gnus-newsgroup-variables nil
1501   "A list of variables that have separate values in different newsgroups.
1502 A list of newsgroup (summary buffer) local variables, or cons of
1503 variables and their default expressions to be evalled (when the default
1504 values are not nil), that should be made global while the summary buffer
1505 is active.
1506
1507 Note: The default expressions will be evaluated (using function `eval')
1508 before assignment to the local variable rather than just assigned to it.
1509 If the default expression is the symbol `global', that symbol will not
1510 be evaluated but the global value of the local variable will be used
1511 instead.
1512
1513 These variables can be used to set variables in the group parameters
1514 while still allowing them to affect operations done in other buffers.
1515 For example:
1516
1517 \(setq gnus-newsgroup-variables
1518      '(message-use-followup-to
1519        (gnus-visible-headers .
1520          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1521 ")
1522
1523 ;; Byte-compiler warning.
1524 (eval-when-compile
1525   ;; Bind features so that require will believe that gnus-sum has
1526   ;; already been loaded (avoids infinite recursion)
1527   (let ((features (cons 'gnus-sum features)))
1528     ;; Several of the declarations in gnus-sum are needed to load the
1529     ;; following files. Right now, these definitions have been
1530     ;; compiled but not defined (evaluated).  We could either do a
1531     ;; eval-and-compile about all of the declarations or evaluate the
1532     ;; source file.
1533     (if (boundp 'gnus-newsgroup-variables)
1534         nil
1535       (load "gnus-sum.el" t t t))
1536     (require 'gnus)
1537     (require 'gnus-art)))
1538
1539 ;; Subject simplification.
1540
1541 (defun gnus-simplify-whitespace (str)
1542   "Remove excessive whitespace from STR."
1543   ;; Multiple spaces.
1544   (while (string-match "[ \t][ \t]+" str)
1545     (setq str (concat (substring str 0 (match-beginning 0))
1546                         " "
1547                         (substring str (match-end 0)))))
1548   ;; Leading spaces.
1549   (when (string-match "^[ \t]+" str)
1550     (setq str (substring str (match-end 0))))
1551   ;; Trailing spaces.
1552   (when (string-match "[ \t]+$" str)
1553     (setq str (substring str 0 (match-beginning 0))))
1554   str)
1555
1556 (defun gnus-simplify-all-whitespace (str)
1557   "Remove all whitespace from STR."
1558   (while (string-match "[ \t\n]+" str)
1559     (setq str (replace-match "" nil nil str)))
1560   str)
1561
1562 (defsubst gnus-simplify-subject-re (subject)
1563   "Remove \"Re:\" from subject lines."
1564   (if (string-match message-subject-re-regexp subject)
1565       (substring subject (match-end 0))
1566     subject))
1567
1568 (defun gnus-simplify-subject (subject &optional re-only)
1569   "Remove `Re:' and words in parentheses.
1570 If RE-ONLY is non-nil, strip leading `Re:'s only."
1571   (let ((case-fold-search t))           ;Ignore case.
1572     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1573     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1574       (setq subject (substring subject (match-end 0))))
1575     ;; Remove uninteresting prefixes.
1576     (when (and (not re-only)
1577                gnus-simplify-ignored-prefixes
1578                (string-match gnus-simplify-ignored-prefixes subject))
1579       (setq subject (substring subject (match-end 0))))
1580     ;; Remove words in parentheses from end.
1581     (unless re-only
1582       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1583         (setq subject (substring subject 0 (match-beginning 0)))))
1584     ;; Return subject string.
1585     subject))
1586
1587 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1588 ;; all whitespace.
1589 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1590   (goto-char (point-min))
1591   (while (re-search-forward regexp nil t)
1592     (replace-match (or newtext ""))))
1593
1594 (defun gnus-simplify-buffer-fuzzy ()
1595   "Simplify string in the buffer fuzzily.
1596 The string in the accessible portion of the current buffer is simplified.
1597 It is assumed to be a single-line subject.
1598 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1599 matter is removed.  Additional things can be deleted by setting
1600 `gnus-simplify-subject-fuzzy-regexp'."
1601   (let ((case-fold-search t)
1602         (modified-tick))
1603     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1604
1605     (while (not (eq modified-tick (buffer-modified-tick)))
1606       (setq modified-tick (buffer-modified-tick))
1607       (cond
1608        ((listp gnus-simplify-subject-fuzzy-regexp)
1609         (mapcar 'gnus-simplify-buffer-fuzzy-step
1610                 gnus-simplify-subject-fuzzy-regexp))
1611        (gnus-simplify-subject-fuzzy-regexp
1612         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1613       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1614       (gnus-simplify-buffer-fuzzy-step
1615        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1616       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1617
1618     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1619     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1620     (gnus-simplify-buffer-fuzzy-step " $")
1621     (gnus-simplify-buffer-fuzzy-step "^ +")))
1622
1623 (defun gnus-simplify-subject-fuzzy (subject)
1624   "Simplify a subject string fuzzily.
1625 See `gnus-simplify-buffer-fuzzy' for details."
1626   (save-excursion
1627     (gnus-set-work-buffer)
1628     (let ((case-fold-search t))
1629       ;; Remove uninteresting prefixes.
1630       (when (and gnus-simplify-ignored-prefixes
1631                  (string-match gnus-simplify-ignored-prefixes subject))
1632         (setq subject (substring subject (match-end 0))))
1633       (insert subject)
1634       (inline (gnus-simplify-buffer-fuzzy))
1635       (buffer-string))))
1636
1637 (defsubst gnus-simplify-subject-fully (subject)
1638   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1639   (cond
1640    (gnus-simplify-subject-functions
1641     (gnus-map-function gnus-simplify-subject-functions subject))
1642    ((null gnus-summary-gather-subject-limit)
1643     (gnus-simplify-subject-re subject))
1644    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1645     (gnus-simplify-subject-fuzzy subject))
1646    ((numberp gnus-summary-gather-subject-limit)
1647     (gnus-limit-string (gnus-simplify-subject-re subject)
1648                        gnus-summary-gather-subject-limit))
1649    (t
1650     subject)))
1651
1652 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1653   "Check whether two subjects are equal.
1654 If optional argument SIMPLE-FIRST is t, first argument is already
1655 simplified."
1656   (cond
1657    ((null simple-first)
1658     (equal (gnus-simplify-subject-fully s1)
1659            (gnus-simplify-subject-fully s2)))
1660    (t
1661     (equal s1
1662            (gnus-simplify-subject-fully s2)))))
1663
1664 (defun gnus-summary-bubble-group ()
1665   "Increase the score of the current group.
1666 This is a handy function to add to `gnus-summary-exit-hook' to
1667 increase the score of each group you read."
1668   (gnus-group-add-score gnus-newsgroup-name))
1669
1670 \f
1671 ;;;
1672 ;;; Gnus summary mode
1673 ;;;
1674
1675 (put 'gnus-summary-mode 'mode-class 'special)
1676
1677 (defvar gnus-article-commands-menu)
1678
1679 ;; Non-orthogonal keys
1680
1681 (gnus-define-keys gnus-summary-mode-map
1682   " " gnus-summary-next-page
1683   "\177" gnus-summary-prev-page
1684   [delete] gnus-summary-prev-page
1685   [backspace] gnus-summary-prev-page
1686   "\r" gnus-summary-scroll-up
1687   "\M-\r" gnus-summary-scroll-down
1688   "n" gnus-summary-next-unread-article
1689   "p" gnus-summary-prev-unread-article
1690   "N" gnus-summary-next-article
1691   "P" gnus-summary-prev-article
1692   "\M-\C-n" gnus-summary-next-same-subject
1693   "\M-\C-p" gnus-summary-prev-same-subject
1694   "\M-n" gnus-summary-next-unread-subject
1695   "\M-p" gnus-summary-prev-unread-subject
1696   "." gnus-summary-first-unread-article
1697   "," gnus-summary-best-unread-article
1698   "\M-s" gnus-summary-search-article-forward
1699   "\M-r" gnus-summary-search-article-backward
1700   "<" gnus-summary-beginning-of-article
1701   ">" gnus-summary-end-of-article
1702   "j" gnus-summary-goto-article
1703   "^" gnus-summary-refer-parent-article
1704   "\M-^" gnus-summary-refer-article
1705   "u" gnus-summary-tick-article-forward
1706   "!" gnus-summary-tick-article-forward
1707   "U" gnus-summary-tick-article-backward
1708   "d" gnus-summary-mark-as-read-forward
1709   "D" gnus-summary-mark-as-read-backward
1710   "E" gnus-summary-mark-as-expirable
1711   "\M-u" gnus-summary-clear-mark-forward
1712   "\M-U" gnus-summary-clear-mark-backward
1713   "k" gnus-summary-kill-same-subject-and-select
1714   "\C-k" gnus-summary-kill-same-subject
1715   "\M-\C-k" gnus-summary-kill-thread
1716   "\M-\C-l" gnus-summary-lower-thread
1717   "e" gnus-summary-edit-article
1718   "#" gnus-summary-mark-as-processable
1719   "\M-#" gnus-summary-unmark-as-processable
1720   "\M-\C-t" gnus-summary-toggle-threads
1721   "\M-\C-s" gnus-summary-show-thread
1722   "\M-\C-h" gnus-summary-hide-thread
1723   "\M-\C-f" gnus-summary-next-thread
1724   "\M-\C-b" gnus-summary-prev-thread
1725   [(meta down)] gnus-summary-next-thread
1726   [(meta up)] gnus-summary-prev-thread
1727   "\M-\C-u" gnus-summary-up-thread
1728   "\M-\C-d" gnus-summary-down-thread
1729   "&" gnus-summary-execute-command
1730   "c" gnus-summary-catchup-and-exit
1731   "\C-w" gnus-summary-mark-region-as-read
1732   "\C-t" gnus-summary-toggle-truncation
1733   "?" gnus-summary-mark-as-dormant
1734   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1735   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1736   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1737   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1738   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1739   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1740   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1741   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1742   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1743   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1744   "=" gnus-summary-expand-window
1745   "\C-x\C-s" gnus-summary-reselect-current-group
1746   "\M-g" gnus-summary-rescan-group
1747   "w" gnus-summary-stop-page-breaking
1748   "\C-c\C-r" gnus-summary-caesar-message
1749   "\M-t" gnus-summary-toggle-mime
1750   "f" gnus-summary-followup
1751   "F" gnus-summary-followup-with-original
1752   "C" gnus-summary-cancel-article
1753   "r" gnus-summary-reply
1754   "R" gnus-summary-reply-with-original
1755   "\C-c\C-f" gnus-summary-mail-forward
1756   "o" gnus-summary-save-article
1757   "\C-o" gnus-summary-save-article-mail
1758   "|" gnus-summary-pipe-output
1759   "\M-k" gnus-summary-edit-local-kill
1760   "\M-K" gnus-summary-edit-global-kill
1761   ;; "V" gnus-version
1762   "\C-c\C-d" gnus-summary-describe-group
1763   "q" gnus-summary-exit
1764   "Q" gnus-summary-exit-no-update
1765   "\C-c\C-i" gnus-info-find-node
1766   gnus-mouse-2 gnus-mouse-pick-article
1767   "m" gnus-summary-mail-other-window
1768   "a" gnus-summary-post-news
1769   "i" gnus-summary-news-other-window
1770   "x" gnus-summary-limit-to-unread
1771   "s" gnus-summary-isearch-article
1772   "t" gnus-summary-toggle-header
1773   "g" gnus-summary-show-article
1774   "l" gnus-summary-goto-last-article
1775   "v" gnus-summary-preview-mime-message
1776   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1777   "\C-d" gnus-summary-enter-digest-group
1778   "\M-\C-d" gnus-summary-read-document
1779   "\M-\C-e" gnus-summary-edit-parameters
1780   "\M-\C-a" gnus-summary-customize-parameters
1781   "\C-c\C-b" gnus-bug
1782   "\C-c\C-n" gnus-namazu-search
1783   "*" gnus-cache-enter-article
1784   "\M-*" gnus-cache-remove-article
1785   "\M-&" gnus-summary-universal-argument
1786   "\C-l" gnus-recenter
1787   "I" gnus-summary-increase-score
1788   "L" gnus-summary-lower-score
1789   "\M-i" gnus-symbolic-argument
1790   "h" gnus-summary-select-article-buffer
1791
1792   "V" gnus-summary-score-map
1793   "X" gnus-uu-extract-map
1794   "S" gnus-summary-send-map)
1795
1796   ;; Sort of orthogonal keymap
1797 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1798   "t" gnus-summary-tick-article-forward
1799   "!" gnus-summary-tick-article-forward
1800   "d" gnus-summary-mark-as-read-forward
1801   "r" gnus-summary-mark-as-read-forward
1802   "c" gnus-summary-clear-mark-forward
1803   " " gnus-summary-clear-mark-forward
1804   "e" gnus-summary-mark-as-expirable
1805   "x" gnus-summary-mark-as-expirable
1806   "?" gnus-summary-mark-as-dormant
1807   "b" gnus-summary-set-bookmark
1808   "B" gnus-summary-remove-bookmark
1809   "#" gnus-summary-mark-as-processable
1810   "\M-#" gnus-summary-unmark-as-processable
1811   "S" gnus-summary-limit-include-expunged
1812   "C" gnus-summary-catchup
1813   "H" gnus-summary-catchup-to-here
1814   "h" gnus-summary-catchup-from-here
1815   "\C-c" gnus-summary-catchup-all
1816   "k" gnus-summary-kill-same-subject-and-select
1817   "K" gnus-summary-kill-same-subject
1818   "P" gnus-uu-mark-map)
1819
1820 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1821   "c" gnus-summary-clear-above
1822   "u" gnus-summary-tick-above
1823   "m" gnus-summary-mark-above
1824   "k" gnus-summary-kill-below)
1825
1826 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1827   "/" gnus-summary-limit-to-subject
1828   "n" gnus-summary-limit-to-articles
1829   "w" gnus-summary-pop-limit
1830   "s" gnus-summary-limit-to-subject
1831   "a" gnus-summary-limit-to-author
1832   "u" gnus-summary-limit-to-unread
1833   "m" gnus-summary-limit-to-marks
1834   "M" gnus-summary-limit-exclude-marks
1835   "v" gnus-summary-limit-to-score
1836   "*" gnus-summary-limit-include-cached
1837   "D" gnus-summary-limit-include-dormant
1838   "T" gnus-summary-limit-include-thread
1839   "d" gnus-summary-limit-exclude-dormant
1840   "t" gnus-summary-limit-to-age
1841   "." gnus-summary-limit-to-unseen
1842   "x" gnus-summary-limit-to-extra
1843   "p" gnus-summary-limit-to-display-predicate
1844   "E" gnus-summary-limit-include-expunged
1845   "c" gnus-summary-limit-exclude-childless-dormant
1846   "C" gnus-summary-limit-mark-excluded-as-read
1847   "o" gnus-summary-insert-old-articles
1848   "N" gnus-summary-insert-new-articles
1849   "r" gnus-summary-limit-to-replied)
1850
1851 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1852   "n" gnus-summary-next-unread-article
1853   "p" gnus-summary-prev-unread-article
1854   "N" gnus-summary-next-article
1855   "P" gnus-summary-prev-article
1856   "\C-n" gnus-summary-next-same-subject
1857   "\C-p" gnus-summary-prev-same-subject
1858   "\M-n" gnus-summary-next-unread-subject
1859   "\M-p" gnus-summary-prev-unread-subject
1860   "f" gnus-summary-first-unread-article
1861   "b" gnus-summary-best-unread-article
1862   "j" gnus-summary-goto-article
1863   "g" gnus-summary-goto-subject
1864   "l" gnus-summary-goto-last-article
1865   "o" gnus-summary-pop-article)
1866
1867 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1868   "k" gnus-summary-kill-thread
1869   "l" gnus-summary-lower-thread
1870   "i" gnus-summary-raise-thread
1871   "T" gnus-summary-toggle-threads
1872   "t" gnus-summary-rethread-current
1873   "^" gnus-summary-reparent-thread
1874   "s" gnus-summary-show-thread
1875   "S" gnus-summary-show-all-threads
1876   "h" gnus-summary-hide-thread
1877   "H" gnus-summary-hide-all-threads
1878   "n" gnus-summary-next-thread
1879   "p" gnus-summary-prev-thread
1880   "u" gnus-summary-up-thread
1881   "o" gnus-summary-top-thread
1882   "d" gnus-summary-down-thread
1883   "#" gnus-uu-mark-thread
1884   "\M-#" gnus-uu-unmark-thread)
1885
1886 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1887   "g" gnus-summary-prepare
1888   "c" gnus-summary-insert-cached-articles
1889   "d" gnus-summary-insert-dormant-articles)
1890
1891 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1892   "c" gnus-summary-catchup-and-exit
1893   "C" gnus-summary-catchup-all-and-exit
1894   "E" gnus-summary-exit-no-update
1895   "J" gnus-summary-jump-to-other-group
1896   "Q" gnus-summary-exit
1897   "Z" gnus-summary-exit
1898   "n" gnus-summary-catchup-and-goto-next-group
1899   "R" gnus-summary-reselect-current-group
1900   "G" gnus-summary-rescan-group
1901   "N" gnus-summary-next-group
1902   "s" gnus-summary-save-newsrc
1903   "P" gnus-summary-prev-group)
1904
1905 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1906   " " gnus-summary-next-page
1907   "n" gnus-summary-next-page
1908   "\177" gnus-summary-prev-page
1909   [delete] gnus-summary-prev-page
1910   "p" gnus-summary-prev-page
1911   "\r" gnus-summary-scroll-up
1912   "\M-\r" gnus-summary-scroll-down
1913   "<" gnus-summary-beginning-of-article
1914   ">" gnus-summary-end-of-article
1915   "b" gnus-summary-beginning-of-article
1916   "e" gnus-summary-end-of-article
1917   "^" gnus-summary-refer-parent-article
1918   "r" gnus-summary-refer-parent-article
1919   "D" gnus-summary-enter-digest-group
1920   "R" gnus-summary-refer-references
1921   "T" gnus-summary-refer-thread
1922   "g" gnus-summary-show-article
1923   "s" gnus-summary-isearch-article
1924   "P" gnus-summary-print-article
1925   "M" gnus-mailing-list-insinuate
1926   "t" gnus-article-babel)
1927
1928 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1929   "b" gnus-article-add-buttons
1930   "B" gnus-article-add-buttons-to-head
1931   "o" gnus-article-treat-overstrike
1932   "e" gnus-article-emphasize
1933   "w" gnus-article-fill-cited-article
1934   "Q" gnus-article-fill-long-lines
1935   "C" gnus-article-capitalize-sentences
1936   "c" gnus-article-remove-cr
1937   "Z" gnus-article-decode-HZ
1938   "A" gnus-article-treat-ansi-sequences
1939   "h" gnus-article-wash-html
1940   "u" gnus-article-unsplit-urls
1941   "f" gnus-article-display-x-face
1942   "l" gnus-summary-stop-page-breaking
1943   "r" gnus-summary-caesar-message
1944   "m" gnus-summary-morse-message
1945   "t" gnus-summary-toggle-header
1946   "g" gnus-treat-smiley
1947   "v" gnus-summary-verbose-headers
1948   "m" gnus-summary-toggle-mime
1949   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1950   "p" gnus-article-verify-x-pgp-sig
1951   "d" gnus-article-treat-dumbquotes)
1952
1953 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1954   ;; mnemonic: deuglif*Y*
1955   "u" gnus-article-outlook-unwrap-lines
1956   "a" gnus-article-outlook-repair-attribution
1957   "c" gnus-article-outlook-rearrange-citation
1958   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1959
1960 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1961   "a" gnus-article-hide
1962   "h" gnus-article-hide-headers
1963   "b" gnus-article-hide-boring-headers
1964   "s" gnus-article-hide-signature
1965   "c" gnus-article-hide-citation
1966   "C" gnus-article-hide-citation-in-followups
1967   "l" gnus-article-hide-list-identifiers
1968   "B" gnus-article-strip-banner
1969   "P" gnus-article-hide-pem
1970   "\C-c" gnus-article-hide-citation-maybe)
1971
1972 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1973   "a" gnus-article-highlight
1974   "h" gnus-article-highlight-headers
1975   "c" gnus-article-highlight-citation
1976   "s" gnus-article-highlight-signature)
1977
1978 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1979   "f" gnus-article-treat-fold-headers
1980   "u" gnus-article-treat-unfold-headers
1981   "n" gnus-article-treat-fold-newsgroups)
1982
1983 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1984   "x" gnus-article-display-x-face
1985   "d" gnus-article-display-face
1986   "s" gnus-treat-smiley
1987   "D" gnus-article-remove-images
1988   "f" gnus-treat-from-picon
1989   "m" gnus-treat-mail-picon
1990   "n" gnus-treat-newsgroups-picon)
1991
1992 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1993   "z" gnus-article-date-ut
1994   "u" gnus-article-date-ut
1995   "l" gnus-article-date-local
1996   "p" gnus-article-date-english
1997   "e" gnus-article-date-lapsed
1998   "o" gnus-article-date-original
1999   "i" gnus-article-date-iso8601
2000   "s" gnus-article-date-user)
2001
2002 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2003   "t" gnus-article-remove-trailing-blank-lines
2004   "l" gnus-article-strip-leading-blank-lines
2005   "m" gnus-article-strip-multiple-blank-lines
2006   "a" gnus-article-strip-blank-lines
2007   "A" gnus-article-strip-all-blank-lines
2008   "s" gnus-article-strip-leading-space
2009   "e" gnus-article-strip-trailing-space
2010   "w" gnus-article-remove-leading-whitespace)
2011
2012 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2013   "v" gnus-version
2014   "f" gnus-summary-fetch-faq
2015   "d" gnus-summary-describe-group
2016   "h" gnus-summary-describe-briefly
2017   "i" gnus-info-find-node
2018   "c" gnus-group-fetch-charter
2019   "C" gnus-group-fetch-control)
2020
2021 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2022   "e" gnus-summary-expire-articles
2023   "\M-\C-e" gnus-summary-expire-articles-now
2024   "\177" gnus-summary-delete-article
2025   [delete] gnus-summary-delete-article
2026   [backspace] gnus-summary-delete-article
2027   "m" gnus-summary-move-article
2028   "r" gnus-summary-respool-article
2029   "w" gnus-summary-edit-article
2030   "c" gnus-summary-copy-article
2031   "B" gnus-summary-crosspost-article
2032   "q" gnus-summary-respool-query
2033   "t" gnus-summary-respool-trace
2034   "i" gnus-summary-import-article
2035   "I" gnus-summary-create-article
2036   "p" gnus-summary-article-posted-p)
2037
2038 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2039   "o" gnus-summary-save-article
2040   "m" gnus-summary-save-article-mail
2041   "F" gnus-summary-write-article-file
2042   "r" gnus-summary-save-article-rmail
2043   "f" gnus-summary-save-article-file
2044   "b" gnus-summary-save-article-body-file
2045   "h" gnus-summary-save-article-folder
2046   "v" gnus-summary-save-article-vm
2047   "p" gnus-summary-pipe-output
2048   "P" gnus-summary-muttprint
2049   "s" gnus-soup-add-article)
2050
2051 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2052   "b" gnus-summary-display-buttonized
2053   "m" gnus-summary-repair-multipart
2054   "v" gnus-article-view-part
2055   "o" gnus-article-save-part
2056   "c" gnus-article-copy-part
2057   "C" gnus-article-view-part-as-charset
2058   "e" gnus-article-view-part-externally
2059   "E" gnus-article-encrypt-body
2060   "i" gnus-article-inline-part
2061   "|" gnus-article-pipe-part)
2062
2063 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2064   "p" gnus-summary-mark-as-processable
2065   "u" gnus-summary-unmark-as-processable
2066   "U" gnus-summary-unmark-all-processable
2067   "v" gnus-uu-mark-over
2068   "s" gnus-uu-mark-series
2069   "r" gnus-uu-mark-region
2070   "g" gnus-uu-unmark-region
2071   "R" gnus-uu-mark-by-regexp
2072   "G" gnus-uu-unmark-by-regexp
2073   "t" gnus-uu-mark-thread
2074   "T" gnus-uu-unmark-thread
2075   "a" gnus-uu-mark-all
2076   "b" gnus-uu-mark-buffer
2077   "S" gnus-uu-mark-sparse
2078   "k" gnus-summary-kill-process-mark
2079   "y" gnus-summary-yank-process-mark
2080   "w" gnus-summary-save-process-mark
2081   "i" gnus-uu-invert-processable)
2082
2083 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2084   ;;"x" gnus-uu-extract-any
2085   "m" gnus-summary-save-parts
2086   "u" gnus-uu-decode-uu
2087   "U" gnus-uu-decode-uu-and-save
2088   "s" gnus-uu-decode-unshar
2089   "S" gnus-uu-decode-unshar-and-save
2090   "o" gnus-uu-decode-save
2091   "O" gnus-uu-decode-save
2092   "b" gnus-uu-decode-binhex
2093   "B" gnus-uu-decode-binhex
2094   "p" gnus-uu-decode-postscript
2095   "P" gnus-uu-decode-postscript-and-save)
2096
2097 (gnus-define-keys
2098     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2099   "u" gnus-uu-decode-uu-view
2100   "U" gnus-uu-decode-uu-and-save-view
2101   "s" gnus-uu-decode-unshar-view
2102   "S" gnus-uu-decode-unshar-and-save-view
2103   "o" gnus-uu-decode-save-view
2104   "O" gnus-uu-decode-save-view
2105   "b" gnus-uu-decode-binhex-view
2106   "B" gnus-uu-decode-binhex-view
2107   "p" gnus-uu-decode-postscript-view
2108   "P" gnus-uu-decode-postscript-and-save-view)
2109
2110 (defvar gnus-article-post-menu nil)
2111
2112 (defconst gnus-summary-menu-maxlen 20)
2113
2114 (defun gnus-summary-menu-split (menu)
2115   ;; If we have lots of elements, divide them into groups of 20
2116   ;; and make a pane (or submenu) for each one.
2117   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2118       (let ((menu menu) sublists next
2119             (i 1))
2120         (while menu
2121           ;; Pull off the next gnus-summary-menu-maxlen elements
2122           ;; and make them the next element of sublist.
2123           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2124           (if next
2125               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2126                       nil))
2127           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2128                                              (aref (car (last menu)) 0)) menu)
2129                                sublists))
2130           (setq i (1+ i))
2131           (setq menu next))
2132         (nreverse sublists))
2133     ;; Few elements--put them all in one pane.
2134     menu))
2135
2136 (defun gnus-summary-make-menu-bar ()
2137   (gnus-turn-off-edit-menu 'summary)
2138
2139   (unless (boundp 'gnus-summary-misc-menu)
2140
2141     (easy-menu-define
2142       gnus-summary-kill-menu gnus-summary-mode-map ""
2143       (cons
2144        "Score"
2145        (nconc
2146         (list
2147          ["Customize" gnus-score-customize t])
2148         (gnus-make-score-map 'increase)
2149         (gnus-make-score-map 'lower)
2150         '(("Mark"
2151            ["Kill below" gnus-summary-kill-below t]
2152            ["Mark above" gnus-summary-mark-above t]
2153            ["Tick above" gnus-summary-tick-above t]
2154            ["Clear above" gnus-summary-clear-above t])
2155           ["Current score" gnus-summary-current-score t]
2156           ["Set score" gnus-summary-set-score t]
2157           ["Switch current score file..." gnus-score-change-score-file t]
2158           ["Set mark below..." gnus-score-set-mark-below t]
2159           ["Set expunge below..." gnus-score-set-expunge-below t]
2160           ["Edit current score file" gnus-score-edit-current-scores t]
2161           ["Edit score file" gnus-score-edit-file t]
2162           ["Trace score" gnus-score-find-trace t]
2163           ["Find words" gnus-score-find-favourite-words t]
2164           ["Rescore buffer" gnus-summary-rescore t]
2165           ["Increase score..." gnus-summary-increase-score t]
2166           ["Lower score..." gnus-summary-lower-score t]))))
2167
2168     ;; Define both the Article menu in the summary buffer and the
2169     ;; equivalent Commands menu in the article buffer here for
2170     ;; consistency.
2171     (let ((innards
2172            `(("Hide"
2173               ["All" gnus-article-hide t]
2174               ["Headers" gnus-article-hide-headers t]
2175               ["Signature" gnus-article-hide-signature t]
2176               ["Citation" gnus-article-hide-citation t]
2177               ["List identifiers" gnus-article-hide-list-identifiers t]
2178               ["Banner" gnus-article-strip-banner t]
2179               ["Boring headers" gnus-article-hide-boring-headers t])
2180              ("Highlight"
2181               ["All" gnus-article-highlight t]
2182               ["Headers" gnus-article-highlight-headers t]
2183               ["Signature" gnus-article-highlight-signature t]
2184               ["Citation" gnus-article-highlight-citation t])
2185              ("Date"
2186               ["Local" gnus-article-date-local t]
2187               ["ISO8601" gnus-article-date-iso8601 t]
2188               ["UT" gnus-article-date-ut t]
2189               ["Original" gnus-article-date-original t]
2190               ["Lapsed" gnus-article-date-lapsed t]
2191               ["User-defined" gnus-article-date-user t])
2192              ("Display"
2193               ["Remove images" gnus-article-remove-images t]
2194               ["Toggle smiley" gnus-treat-smiley t]
2195               ["Show X-Face" gnus-article-display-x-face t]
2196               ["Show picons in From" gnus-treat-from-picon t]
2197               ["Show picons in mail headers" gnus-treat-mail-picon t]
2198               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2199               ("View as different encoding"
2200                ,@(gnus-summary-menu-split
2201                   (mapcar
2202                    (lambda (cs)
2203                      ;; Since easymenu under Emacs doesn't allow
2204                      ;; lambda forms for menu commands, we should
2205                      ;; provide intern'ed function symbols.
2206                      (let ((command (intern (format "\
2207 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2208                        (fset command
2209                              `(lambda ()
2210                                 (interactive)
2211                                 (let ((gnus-summary-show-article-charset-alist
2212                                        '((1 . ,cs))))
2213                                   (gnus-summary-show-article 1))))
2214                        `[,(symbol-name cs) ,command t]))
2215                    (sort (if (fboundp 'coding-system-list)
2216                              (coding-system-list)
2217                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2218                            )
2219                          'string<)))))
2220              ("Washing"
2221               ("Remove Blanks"
2222                ["Leading" gnus-article-strip-leading-blank-lines t]
2223                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2224                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2225                ["All of the above" gnus-article-strip-blank-lines t]
2226                ["All" gnus-article-strip-all-blank-lines t]
2227                ["Leading space" gnus-article-strip-leading-space t]
2228                ["Trailing space" gnus-article-strip-trailing-space t]
2229                ["Leading space in headers"
2230                 gnus-article-remove-leading-whitespace t])
2231               ["Overstrike" gnus-article-treat-overstrike t]
2232               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2233               ["Emphasis" gnus-article-emphasize t]
2234               ["Word wrap" gnus-article-fill-cited-article t]
2235               ["Fill long lines" gnus-article-fill-long-lines t]
2236               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2237               ["Remove CR" gnus-article-remove-cr t]
2238               ["Rot 13" gnus-summary-caesar-message
2239                ,@(if (featurep 'xemacs) '(t)
2240                    '(:help "\"Caesar rotate\" article by 13"))]
2241               ["Morse decode" gnus-summary-morse-message t]
2242               ["Unix pipe..." gnus-summary-pipe-message t]
2243               ["Add buttons" gnus-article-add-buttons t]
2244               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2245               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2246               ["Toggle MIME" gnus-summary-toggle-mime t]
2247               ["Verbose header" gnus-summary-verbose-headers t]
2248               ["Toggle header" gnus-summary-toggle-header t]
2249               ["Unfold headers" gnus-article-treat-unfold-headers t]
2250               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2251               ["Html" gnus-article-wash-html t]
2252               ["Unsplit URLs" gnus-article-unsplit-urls t]
2253               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2254               ["Decode HZ" gnus-article-decode-HZ t]
2255               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2256               ("(Outlook) Deuglify"
2257                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2258                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2259                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2260                ["Full (Outlook) deuglify"
2261                 gnus-article-outlook-deuglify-article t])
2262               )
2263              ("Output"
2264               ["Save in default format..." gnus-summary-save-article
2265                ,@(if (featurep 'xemacs) '(t)
2266                    '(:help "Save article using default method"))]
2267               ["Save in file..." gnus-summary-save-article-file
2268                ,@(if (featurep 'xemacs) '(t)
2269                    '(:help "Save article in file"))]
2270               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2271               ["Save in MH folder..." gnus-summary-save-article-folder t]
2272               ["Save in VM folder..." gnus-summary-save-article-vm t]
2273               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2274               ["Save body in file..." gnus-summary-save-article-body-file t]
2275               ["Pipe through a filter..." gnus-summary-pipe-output t]
2276               ["Add to SOUP packet" gnus-soup-add-article t]
2277               ["Print with Muttprint..." gnus-summary-muttprint t]
2278               ["Print" gnus-summary-print-article
2279                ,@(if (featurep 'xemacs) '(t)
2280                    '(:help "Generate and print a PostScript image"))])
2281              ("Copy, move,... (Backend)"
2282               ,@(if (featurep 'xemacs) nil
2283                   '(:help "Copying, moving, expiring articles..."))
2284               ["Respool article..." gnus-summary-respool-article t]
2285               ["Move article..." gnus-summary-move-article
2286                (gnus-check-backend-function
2287                 'request-move-article gnus-newsgroup-name)]
2288               ["Copy article..." gnus-summary-copy-article t]
2289               ["Crosspost article..." gnus-summary-crosspost-article
2290                (gnus-check-backend-function
2291                 'request-replace-article gnus-newsgroup-name)]
2292               ["Import file..." gnus-summary-import-article
2293                (gnus-check-backend-function
2294                 'request-accept-article gnus-newsgroup-name)]
2295               ["Create article..." gnus-summary-create-article
2296                (gnus-check-backend-function
2297                 'request-accept-article gnus-newsgroup-name)]
2298               ["Check if posted" gnus-summary-article-posted-p t]
2299               ["Edit article" gnus-summary-edit-article
2300                (not (gnus-group-read-only-p))]
2301               ["Delete article" gnus-summary-delete-article
2302                (gnus-check-backend-function
2303                 'request-expire-articles gnus-newsgroup-name)]
2304               ["Query respool" gnus-summary-respool-query t]
2305               ["Trace respool" gnus-summary-respool-trace t]
2306               ["Delete expirable articles" gnus-summary-expire-articles-now
2307                (gnus-check-backend-function
2308                 'request-expire-articles gnus-newsgroup-name)])
2309              ("Extract"
2310               ["Uudecode" gnus-uu-decode-uu
2311                ,@(if (featurep 'xemacs) '(t)
2312                    '(:help "Decode uuencoded article(s)"))]
2313               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2314               ["Unshar" gnus-uu-decode-unshar t]
2315               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2316               ["Save" gnus-uu-decode-save t]
2317               ["Binhex" gnus-uu-decode-binhex t]
2318               ["Postscript" gnus-uu-decode-postscript t])
2319              ("Cache"
2320               ["Enter article" gnus-cache-enter-article t]
2321               ["Remove article" gnus-cache-remove-article t])
2322              ["Translate" gnus-article-babel t]
2323              ["Select article buffer" gnus-summary-select-article-buffer t]
2324              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2325              ["Isearch article..." gnus-summary-isearch-article t]
2326              ["Beginning of the article" gnus-summary-beginning-of-article t]
2327              ["End of the article" gnus-summary-end-of-article t]
2328              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2329              ["Fetch referenced articles" gnus-summary-refer-references t]
2330              ["Fetch current thread" gnus-summary-refer-thread t]
2331              ["Fetch article with id..." gnus-summary-refer-article t]
2332              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2333              ["Redisplay" gnus-summary-show-article t]
2334              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2335       (easy-menu-define
2336         gnus-summary-article-menu gnus-summary-mode-map ""
2337         (cons "Article" innards))
2338
2339       (if (not (keymapp gnus-summary-article-menu))
2340           (easy-menu-define
2341             gnus-article-commands-menu gnus-article-mode-map ""
2342             (cons "Commands" innards))
2343         ;; in Emacs, don't share menu.
2344         (setq gnus-article-commands-menu
2345               (copy-keymap gnus-summary-article-menu))
2346         (define-key gnus-article-mode-map [menu-bar commands]
2347           (cons "Commands" gnus-article-commands-menu))))
2348
2349     (easy-menu-define
2350       gnus-summary-thread-menu gnus-summary-mode-map ""
2351       '("Threads"
2352         ["Find all messages in thread" gnus-summary-refer-thread t]
2353         ["Toggle threading" gnus-summary-toggle-threads t]
2354         ["Hide threads" gnus-summary-hide-all-threads t]
2355         ["Show threads" gnus-summary-show-all-threads t]
2356         ["Hide thread" gnus-summary-hide-thread t]
2357         ["Show thread" gnus-summary-show-thread t]
2358         ["Go to next thread" gnus-summary-next-thread t]
2359         ["Go to previous thread" gnus-summary-prev-thread t]
2360         ["Go down thread" gnus-summary-down-thread t]
2361         ["Go up thread" gnus-summary-up-thread t]
2362         ["Top of thread" gnus-summary-top-thread t]
2363         ["Mark thread as read" gnus-summary-kill-thread t]
2364         ["Lower thread score" gnus-summary-lower-thread t]
2365         ["Raise thread score" gnus-summary-raise-thread t]
2366         ["Rethread current" gnus-summary-rethread-current t]))
2367
2368     (easy-menu-define
2369       gnus-summary-post-menu gnus-summary-mode-map ""
2370       `("Post"
2371         ["Send a message (mail or news)" gnus-summary-post-news
2372          ,@(if (featurep 'xemacs) '(t)
2373              '(:help "Compose a new message (mail or news)"))]
2374         ["Followup" gnus-summary-followup
2375          ,@(if (featurep 'xemacs) '(t)
2376              '(:help "Post followup to this article"))]
2377         ["Followup and yank" gnus-summary-followup-with-original
2378          ,@(if (featurep 'xemacs) '(t)
2379              '(:help "Post followup to this article, quoting its contents"))]
2380         ["Supersede article" gnus-summary-supersede-article t]
2381         ["Cancel article" gnus-summary-cancel-article
2382          ,@(if (featurep 'xemacs) '(t)
2383              '(:help "Cancel an article you posted"))]
2384         ["Reply" gnus-summary-reply t]
2385         ["Reply and yank" gnus-summary-reply-with-original t]
2386         ["Wide reply" gnus-summary-wide-reply t]
2387         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2388          ,@(if (featurep 'xemacs) '(t)
2389              '(:help "Mail a reply, quoting this article"))]
2390         ["Very wide reply" gnus-summary-very-wide-reply t]
2391         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2392          ,@(if (featurep 'xemacs) '(t)
2393              '(:help "Mail a very wide reply, quoting this article"))]
2394         ["Mail forward" gnus-summary-mail-forward t]
2395         ["Post forward" gnus-summary-post-forward t]
2396         ["Digest and mail" gnus-summary-digest-mail-forward t]
2397         ["Digest and post" gnus-summary-digest-post-forward t]
2398         ["Resend message" gnus-summary-resend-message t]
2399         ["Resend message edit" gnus-summary-resend-message-edit t]
2400         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2401         ["Send a mail" gnus-summary-mail-other-window t]
2402         ["Create a local message" gnus-summary-news-other-window t]
2403         ["Uuencode and post" gnus-uu-post-news
2404          ,@(if (featurep 'xemacs) '(t)
2405              '(:help "Post a uuencoded article"))]
2406         ["Followup via news" gnus-summary-followup-to-mail t]
2407         ["Followup via news and yank"
2408          gnus-summary-followup-to-mail-with-original t]
2409         ;;("Draft"
2410         ;;["Send" gnus-summary-send-draft t]
2411         ;;["Send bounced" gnus-resend-bounced-mail t])
2412         ))
2413
2414     (cond
2415      ((not (keymapp gnus-summary-post-menu))
2416       (setq gnus-article-post-menu gnus-summary-post-menu))
2417      ((not gnus-article-post-menu)
2418       ;; Don't share post menu.
2419       (setq gnus-article-post-menu
2420             (copy-keymap gnus-summary-post-menu))))
2421     (define-key gnus-article-mode-map [menu-bar post]
2422       (cons "Post" gnus-article-post-menu))
2423
2424     (easy-menu-define
2425       gnus-summary-misc-menu gnus-summary-mode-map ""
2426       `("Gnus"
2427         ("Mark Read"
2428          ["Mark as read" gnus-summary-mark-as-read-forward t]
2429          ["Mark same subject and select"
2430           gnus-summary-kill-same-subject-and-select t]
2431          ["Mark same subject" gnus-summary-kill-same-subject t]
2432          ["Catchup" gnus-summary-catchup
2433           ,@(if (featurep 'xemacs) '(t)
2434               '(:help "Mark unread articles in this group as read"))]
2435          ["Catchup all" gnus-summary-catchup-all t]
2436          ["Catchup to here" gnus-summary-catchup-to-here t]
2437          ["Catchup from here" gnus-summary-catchup-from-here t]
2438          ["Catchup region" gnus-summary-mark-region-as-read
2439           (gnus-mark-active-p)]
2440          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2441         ("Mark Various"
2442          ["Tick" gnus-summary-tick-article-forward t]
2443          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2444          ["Remove marks" gnus-summary-clear-mark-forward t]
2445          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2446          ["Set bookmark" gnus-summary-set-bookmark t]
2447          ["Remove bookmark" gnus-summary-remove-bookmark t])
2448         ("Limit to"
2449          ["Marks..." gnus-summary-limit-to-marks t]
2450          ["Subject..." gnus-summary-limit-to-subject t]
2451          ["Author..." gnus-summary-limit-to-author t]
2452          ["Age..." gnus-summary-limit-to-age t]
2453          ["Extra..." gnus-summary-limit-to-extra t]
2454          ["Score..." gnus-summary-limit-to-score t]
2455          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2456          ["Unread" gnus-summary-limit-to-unread t]
2457          ["Unseen" gnus-summary-limit-to-unseen t]
2458          ["Replied" gnus-summary-limit-to-replied t]
2459          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2460          ["Next articles" gnus-summary-limit-to-articles t]
2461          ["Pop limit" gnus-summary-pop-limit t]
2462          ["Show dormant" gnus-summary-limit-include-dormant t]
2463          ["Hide childless dormant"
2464           gnus-summary-limit-exclude-childless-dormant t]
2465          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2466          ["Hide marked" gnus-summary-limit-exclude-marks t]
2467          ["Show expunged" gnus-summary-limit-include-expunged t])
2468         ("Process Mark"
2469          ["Set mark" gnus-summary-mark-as-processable t]
2470          ["Remove mark" gnus-summary-unmark-as-processable t]
2471          ["Remove all marks" gnus-summary-unmark-all-processable t]
2472          ["Invert marks" gnus-uu-invert-processable t]
2473          ["Mark above" gnus-uu-mark-over t]
2474          ["Mark series" gnus-uu-mark-series t]
2475          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2476          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2477          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2478          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2479          ["Mark all" gnus-uu-mark-all t]
2480          ["Mark buffer" gnus-uu-mark-buffer t]
2481          ["Mark sparse" gnus-uu-mark-sparse t]
2482          ["Mark thread" gnus-uu-mark-thread t]
2483          ["Unmark thread" gnus-uu-unmark-thread t]
2484          ("Process Mark Sets"
2485           ["Kill" gnus-summary-kill-process-mark t]
2486           ["Yank" gnus-summary-yank-process-mark
2487            gnus-newsgroup-process-stack]
2488           ["Save" gnus-summary-save-process-mark t]
2489           ["Run command on marked..." gnus-summary-universal-argument t]))
2490         ("Scroll article"
2491          ["Page forward" gnus-summary-next-page
2492           ,@(if (featurep 'xemacs) '(t)
2493               '(:help "Show next page of article"))]
2494          ["Page backward" gnus-summary-prev-page
2495           ,@(if (featurep 'xemacs) '(t)
2496               '(:help "Show previous page of article"))]
2497          ["Line forward" gnus-summary-scroll-up t])
2498         ("Move"
2499          ["Next unread article" gnus-summary-next-unread-article t]
2500          ["Previous unread article" gnus-summary-prev-unread-article t]
2501          ["Next article" gnus-summary-next-article t]
2502          ["Previous article" gnus-summary-prev-article t]
2503          ["Next unread subject" gnus-summary-next-unread-subject t]
2504          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2505          ["Next article same subject" gnus-summary-next-same-subject t]
2506          ["Previous article same subject" gnus-summary-prev-same-subject t]
2507          ["First unread article" gnus-summary-first-unread-article t]
2508          ["Best unread article" gnus-summary-best-unread-article t]
2509          ["Go to subject number..." gnus-summary-goto-subject t]
2510          ["Go to article number..." gnus-summary-goto-article t]
2511          ["Go to the last article" gnus-summary-goto-last-article t]
2512          ["Pop article off history" gnus-summary-pop-article t])
2513         ("Sort"
2514          ["Sort by number" gnus-summary-sort-by-number t]
2515          ["Sort by author" gnus-summary-sort-by-author t]
2516          ["Sort by subject" gnus-summary-sort-by-subject t]
2517          ["Sort by date" gnus-summary-sort-by-date t]
2518          ["Sort by score" gnus-summary-sort-by-score t]
2519          ["Sort by lines" gnus-summary-sort-by-lines t]
2520          ["Sort by characters" gnus-summary-sort-by-chars t]
2521          ["Randomize" gnus-summary-sort-by-random t]
2522          ["Original sort" gnus-summary-sort-by-original t])
2523         ("Help"
2524          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2525          ["Describe group" gnus-summary-describe-group t]
2526          ["Fetch charter" gnus-group-fetch-charter
2527           ,@(if (featurep 'xemacs) nil
2528               '(:help "Display the charter of the current group"))]
2529          ["Fetch control message" gnus-group-fetch-control
2530           ,@(if (featurep 'xemacs) nil
2531               '(:help "Display the archived control message for the current group"))]
2532          ["Read manual" gnus-info-find-node t])
2533         ("Modes"
2534          ["Pick and read" gnus-pick-mode t]
2535          ["Binary" gnus-binary-mode t])
2536         ("Regeneration"
2537          ["Regenerate" gnus-summary-prepare t]
2538          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2539          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2540          ["Toggle threading" gnus-summary-toggle-threads t])
2541         ["See old articles" gnus-summary-insert-old-articles t]
2542         ["See new articles" gnus-summary-insert-new-articles t]
2543         ["Filter articles..." gnus-summary-execute-command t]
2544         ["Run command on articles..." gnus-summary-universal-argument t]
2545         ["Search articles forward..." gnus-summary-search-article-forward t]
2546         ["Search articles backward..." gnus-summary-search-article-backward t]
2547         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2548         ["Expand window" gnus-summary-expand-window t]
2549         ["Expire expirable articles" gnus-summary-expire-articles
2550          (gnus-check-backend-function
2551           'request-expire-articles gnus-newsgroup-name)]
2552         ["Edit local kill file" gnus-summary-edit-local-kill t]
2553         ["Edit main kill file" gnus-summary-edit-global-kill t]
2554         ["Edit group parameters" gnus-summary-edit-parameters t]
2555         ["Customize group parameters" gnus-summary-customize-parameters t]
2556         ["Send a bug report" gnus-bug t]
2557         ("Exit"
2558          ["Catchup and exit" gnus-summary-catchup-and-exit
2559           ,@(if (featurep 'xemacs) '(t)
2560               '(:help "Mark unread articles in this group as read, then exit"))]
2561          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2562          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2563          ["Exit group" gnus-summary-exit
2564           ,@(if (featurep 'xemacs) '(t)
2565               '(:help "Exit current group, return to group selection mode"))]
2566          ["Exit group without updating" gnus-summary-exit-no-update t]
2567          ["Exit and goto next group" gnus-summary-next-group t]
2568          ["Exit and goto prev group" gnus-summary-prev-group t]
2569          ["Reselect group" gnus-summary-reselect-current-group t]
2570          ["Rescan group" gnus-summary-rescan-group t]
2571          ["Update dribble" gnus-summary-save-newsrc t])))
2572
2573     (gnus-run-hooks 'gnus-summary-menu-hook)))
2574
2575 (defvar gnus-summary-tool-bar-map nil)
2576
2577 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2578 (defun gnus-summary-make-tool-bar ()
2579   (if (and (fboundp 'tool-bar-add-item-from-menu)
2580            (default-value 'tool-bar-mode)
2581            (not gnus-summary-tool-bar-map))
2582       (setq gnus-summary-tool-bar-map
2583             (let ((tool-bar-map (make-sparse-keymap))
2584                   (load-path (mm-image-load-path)))
2585               (tool-bar-add-item-from-menu
2586                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2587               (tool-bar-add-item-from-menu
2588                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2589               (tool-bar-add-item-from-menu
2590                'gnus-summary-post-news "post" gnus-summary-mode-map)
2591               (tool-bar-add-item-from-menu
2592                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2593               (tool-bar-add-item-from-menu
2594                'gnus-summary-followup "followup" gnus-summary-mode-map)
2595               (tool-bar-add-item-from-menu
2596                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2597               (tool-bar-add-item-from-menu
2598                'gnus-summary-reply "reply" gnus-summary-mode-map)
2599               (tool-bar-add-item-from-menu
2600                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2601               (tool-bar-add-item-from-menu
2602                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2603               (tool-bar-add-item-from-menu
2604                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2605               (tool-bar-add-item-from-menu
2606                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2607               (tool-bar-add-item-from-menu
2608                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2609               (tool-bar-add-item-from-menu
2610                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2611               (tool-bar-add-item-from-menu
2612                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2613               (tool-bar-add-item-from-menu
2614                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2615               (tool-bar-add-item-from-menu
2616                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2617               tool-bar-map)))
2618   (if gnus-summary-tool-bar-map
2619       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2620
2621 (defun gnus-score-set-default (var value)
2622   "A version of set that updates the GNU Emacs menu-bar."
2623   (set var value)
2624   ;; It is the message that forces the active status to be updated.
2625   (message ""))
2626
2627 (defun gnus-make-score-map (type)
2628   "Make a summary score map of type TYPE."
2629   (if t
2630       nil
2631     (let ((headers '(("author" "from" string)
2632                      ("subject" "subject" string)
2633                      ("article body" "body" string)
2634                      ("article head" "head" string)
2635                      ("xref" "xref" string)
2636                      ("extra header" "extra" string)
2637                      ("lines" "lines" number)
2638                      ("followups to author" "followup" string)))
2639           (types '((number ("less than" <)
2640                            ("greater than" >)
2641                            ("equal" =))
2642                    (string ("substring" s)
2643                            ("exact string" e)
2644                            ("fuzzy string" f)
2645                            ("regexp" r))))
2646           (perms '(("temporary" (current-time-string))
2647                    ("permanent" nil)
2648                    ("immediate" now)))
2649           header)
2650       (list
2651        (apply
2652         'nconc
2653         (list
2654          (if (eq type 'lower)
2655              "Lower score"
2656            "Increase score"))
2657         (let (outh)
2658           (while headers
2659             (setq header (car headers))
2660             (setq outh
2661                   (cons
2662                    (apply
2663                     'nconc
2664                     (list (car header))
2665                     (let ((ts (cdr (assoc (nth 2 header) types)))
2666                           outt)
2667                       (while ts
2668                         (setq outt
2669                               (cons
2670                                (apply
2671                                 'nconc
2672                                 (list (caar ts))
2673                                 (let ((ps perms)
2674                                       outp)
2675                                   (while ps
2676                                     (setq outp
2677                                           (cons
2678                                            (vector
2679                                             (caar ps)
2680                                             (list
2681                                              'gnus-summary-score-entry
2682                                              (nth 1 header)
2683                                              (if (or (string= (nth 1 header)
2684                                                               "head")
2685                                                      (string= (nth 1 header)
2686                                                               "body"))
2687                                                  ""
2688                                                (list 'gnus-summary-header
2689                                                      (nth 1 header)))
2690                                              (list 'quote (nth 1 (car ts)))
2691                                              (list 'gnus-score-delta-default
2692                                                    nil)
2693                                              (nth 1 (car ps))
2694                                              t)
2695                                             t)
2696                                            outp))
2697                                     (setq ps (cdr ps)))
2698                                   (list (nreverse outp))))
2699                                outt))
2700                         (setq ts (cdr ts)))
2701                       (list (nreverse outt))))
2702                    outh))
2703             (setq headers (cdr headers)))
2704           (list (nreverse outh))))))))
2705
2706 \f
2707
2708 (defun gnus-summary-mode (&optional group)
2709   "Major mode for reading articles.
2710
2711 All normal editing commands are switched off.
2712 \\<gnus-summary-mode-map>
2713 Each line in this buffer represents one article.  To read an
2714 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2715 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2716 respectively.
2717
2718 You can also post articles and send mail from this buffer.  To
2719 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2720 of an article, type `\\[gnus-summary-reply]'.
2721
2722 There are approx. one gazillion commands you can execute in this
2723 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2724
2725 The following commands are available:
2726
2727 \\{gnus-summary-mode-map}"
2728   (interactive)
2729   (kill-all-local-variables)
2730   (when (gnus-visual-p 'summary-menu 'menu)
2731     (gnus-summary-make-menu-bar)
2732     (gnus-summary-make-tool-bar))
2733   (gnus-summary-make-local-variables)
2734   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2735     (gnus-summary-make-local-variables))
2736   (gnus-make-thread-indent-array)
2737   (gnus-simplify-mode-line)
2738   (setq major-mode 'gnus-summary-mode)
2739   (setq mode-name "Summary")
2740   (make-local-variable 'minor-mode-alist)
2741   (use-local-map gnus-summary-mode-map)
2742   (buffer-disable-undo)
2743   (setq buffer-read-only t              ;Disable modification
2744         show-trailing-whitespace nil)
2745   (setq truncate-lines t)
2746   (setq selective-display t)
2747   (setq selective-display-ellipses t)   ;Display `...'
2748   (gnus-summary-set-display-table)
2749   (gnus-set-default-directory)
2750   (setq gnus-newsgroup-name group)
2751   (unless (gnus-news-group-p group)
2752     (setq gnus-newsgroup-incorporated
2753           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2754   (make-local-variable 'gnus-summary-line-format)
2755   (make-local-variable 'gnus-summary-line-format-spec)
2756   (make-local-variable 'gnus-summary-dummy-line-format)
2757   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2758   (make-local-variable 'gnus-summary-mark-positions)
2759   (gnus-make-local-hook 'pre-command-hook)
2760   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2761   (gnus-run-hooks 'gnus-summary-mode-hook)
2762   (turn-on-gnus-mailing-list-mode)
2763   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2764   (gnus-update-summary-mark-positions))
2765
2766 (defun gnus-summary-make-local-variables ()
2767   "Make all the local summary buffer variables."
2768   (let (global)
2769     (dolist (local gnus-summary-local-variables)
2770       (if (consp local)
2771           (progn
2772             (if (eq (cdr local) 'global)
2773                 ;; Copy the global value of the variable.
2774                 (setq global (symbol-value (car local)))
2775               ;; Use the value from the list.
2776               (setq global (eval (cdr local))))
2777             (set (make-local-variable (car local)) global))
2778         ;; Simple nil-valued local variable.
2779         (set (make-local-variable local) nil)))))
2780
2781 (defun gnus-summary-clear-local-variables ()
2782   (let ((locals gnus-summary-local-variables))
2783     (while locals
2784       (if (consp (car locals))
2785           (and (vectorp (caar locals))
2786                (set (caar locals) nil))
2787         (and (vectorp (car locals))
2788              (set (car locals) nil)))
2789       (setq locals (cdr locals)))))
2790
2791 ;; Summary data functions.
2792
2793 (defmacro gnus-data-number (data)
2794   `(car ,data))
2795
2796 (defmacro gnus-data-set-number (data number)
2797   `(setcar ,data ,number))
2798
2799 (defmacro gnus-data-mark (data)
2800   `(nth 1 ,data))
2801
2802 (defmacro gnus-data-set-mark (data mark)
2803   `(setcar (nthcdr 1 ,data) ,mark))
2804
2805 (defmacro gnus-data-pos (data)
2806   `(nth 2 ,data))
2807
2808 (defmacro gnus-data-set-pos (data pos)
2809   `(setcar (nthcdr 2 ,data) ,pos))
2810
2811 (defmacro gnus-data-header (data)
2812   `(nth 3 ,data))
2813
2814 (defmacro gnus-data-set-header (data header)
2815   `(setcar (nthcdr 3 ,data) ,header))
2816
2817 (defmacro gnus-data-level (data)
2818   `(nth 4 ,data))
2819
2820 (defmacro gnus-data-unread-p (data)
2821   `(= (nth 1 ,data) gnus-unread-mark))
2822
2823 (defmacro gnus-data-read-p (data)
2824   `(/= (nth 1 ,data) gnus-unread-mark))
2825
2826 (defmacro gnus-data-pseudo-p (data)
2827   `(consp (nth 3 ,data)))
2828
2829 (defmacro gnus-data-find (number)
2830   `(assq ,number gnus-newsgroup-data))
2831
2832 (defmacro gnus-data-find-list (number &optional data)
2833   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2834      (memq (assq ,number bdata)
2835            bdata)))
2836
2837 (defmacro gnus-data-make (number mark pos header level)
2838   `(list ,number ,mark ,pos ,header ,level))
2839
2840 (defun gnus-data-enter (after-article number mark pos header level offset)
2841   (let ((data (gnus-data-find-list after-article)))
2842     (unless data
2843       (error "No such article: %d" after-article))
2844     (setcdr data (cons (gnus-data-make number mark pos header level)
2845                        (cdr data)))
2846     (setq gnus-newsgroup-data-reverse nil)
2847     (gnus-data-update-list (cddr data) offset)))
2848
2849 (defun gnus-data-enter-list (after-article list &optional offset)
2850   (when list
2851     (let ((data (and after-article (gnus-data-find-list after-article)))
2852           (ilist list))
2853       (if (not (or data
2854                    after-article))
2855           (let ((odata gnus-newsgroup-data))
2856             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2857             (when offset
2858               (gnus-data-update-list odata offset)))
2859         ;; Find the last element in the list to be spliced into the main
2860         ;; list.
2861         (setq list (last list))
2862         (if (not data)
2863             (progn
2864               (setcdr list gnus-newsgroup-data)
2865               (setq gnus-newsgroup-data ilist)
2866               (when offset
2867                 (gnus-data-update-list (cdr list) offset)))
2868           (setcdr list (cdr data))
2869           (setcdr data ilist)
2870           (when offset
2871             (gnus-data-update-list (cdr list) offset))))
2872       (setq gnus-newsgroup-data-reverse nil))))
2873
2874 (defun gnus-data-remove (article &optional offset)
2875   (let ((data gnus-newsgroup-data))
2876     (if (= (gnus-data-number (car data)) article)
2877         (progn
2878           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2879                 gnus-newsgroup-data-reverse nil)
2880           (when offset
2881             (gnus-data-update-list gnus-newsgroup-data offset)))
2882       (while (cdr data)
2883         (when (= (gnus-data-number (cadr data)) article)
2884           (setcdr data (cddr data))
2885           (when offset
2886             (gnus-data-update-list (cdr data) offset))
2887           (setq data nil
2888                 gnus-newsgroup-data-reverse nil))
2889         (setq data (cdr data))))))
2890
2891 (defmacro gnus-data-list (backward)
2892   `(if ,backward
2893        (or gnus-newsgroup-data-reverse
2894            (setq gnus-newsgroup-data-reverse
2895                  (reverse gnus-newsgroup-data)))
2896      gnus-newsgroup-data))
2897
2898 (defun gnus-data-update-list (data offset)
2899   "Add OFFSET to the POS of all data entries in DATA."
2900   (setq gnus-newsgroup-data-reverse nil)
2901   (while data
2902     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2903     (setq data (cdr data))))
2904
2905 (defun gnus-summary-article-pseudo-p (article)
2906   "Say whether this article is a pseudo article or not."
2907   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2908
2909 (defmacro gnus-summary-article-sparse-p (article)
2910   "Say whether this article is a sparse article or not."
2911   `(memq ,article gnus-newsgroup-sparse))
2912
2913 (defmacro gnus-summary-article-ancient-p (article)
2914   "Say whether this article is a sparse article or not."
2915   `(memq ,article gnus-newsgroup-ancient))
2916
2917 (defun gnus-article-parent-p (number)
2918   "Say whether this article is a parent or not."
2919   (let ((data (gnus-data-find-list number)))
2920     (and (cdr data)                     ; There has to be an article after...
2921          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2922             (gnus-data-level (nth 1 data))))))
2923
2924 (defun gnus-article-children (number)
2925   "Return a list of all children to NUMBER."
2926   (let* ((data (gnus-data-find-list number))
2927          (level (gnus-data-level (car data)))
2928          children)
2929     (setq data (cdr data))
2930     (while (and data
2931                 (= (gnus-data-level (car data)) (1+ level)))
2932       (push (gnus-data-number (car data)) children)
2933       (setq data (cdr data)))
2934     children))
2935
2936 (defmacro gnus-summary-skip-intangible ()
2937   "If the current article is intangible, then jump to a different article."
2938   '(let ((to (get-text-property (point) 'gnus-intangible)))
2939      (and to (gnus-summary-goto-subject to))))
2940
2941 (defmacro gnus-summary-article-intangible-p ()
2942   "Say whether this article is intangible or not."
2943   '(get-text-property (point) 'gnus-intangible))
2944
2945 (defun gnus-article-read-p (article)
2946   "Say whether ARTICLE is read or not."
2947   (not (or (memq article gnus-newsgroup-marked)
2948            (memq article gnus-newsgroup-spam-marked)
2949            (memq article gnus-newsgroup-unreads)
2950            (memq article gnus-newsgroup-unselected)
2951            (memq article gnus-newsgroup-dormant))))
2952
2953 ;; Some summary mode macros.
2954
2955 (defmacro gnus-summary-article-number ()
2956   "The article number of the article on the current line.
2957 If there isn't an article number here, then we return the current
2958 article number."
2959   '(progn
2960      (gnus-summary-skip-intangible)
2961      (or (get-text-property (point) 'gnus-number)
2962          (gnus-summary-last-subject))))
2963
2964 (defmacro gnus-summary-article-header (&optional number)
2965   "Return the header of article NUMBER."
2966   `(gnus-data-header (gnus-data-find
2967                       ,(or number '(gnus-summary-article-number)))))
2968
2969 (defmacro gnus-summary-thread-level (&optional number)
2970   "Return the level of thread that starts with article NUMBER."
2971   `(if (and (eq gnus-summary-make-false-root 'dummy)
2972             (get-text-property (point) 'gnus-intangible))
2973        0
2974      (gnus-data-level (gnus-data-find
2975                        ,(or number '(gnus-summary-article-number))))))
2976
2977 (defmacro gnus-summary-article-mark (&optional number)
2978   "Return the mark of article NUMBER."
2979   `(gnus-data-mark (gnus-data-find
2980                     ,(or number '(gnus-summary-article-number)))))
2981
2982 (defmacro gnus-summary-article-pos (&optional number)
2983   "Return the position of the line of article NUMBER."
2984   `(gnus-data-pos (gnus-data-find
2985                    ,(or number '(gnus-summary-article-number)))))
2986
2987 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2988 (defmacro gnus-summary-article-subject (&optional number)
2989   "Return current subject string or nil if nothing."
2990   `(let ((headers
2991           ,(if number
2992                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2993              '(gnus-data-header (assq (gnus-summary-article-number)
2994                                       gnus-newsgroup-data)))))
2995      (and headers
2996           (vectorp headers)
2997           (mail-header-subject headers))))
2998
2999 (defmacro gnus-summary-article-score (&optional number)
3000   "Return current article score."
3001   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3002                   gnus-newsgroup-scored))
3003        gnus-summary-default-score 0))
3004
3005 (defun gnus-summary-article-children (&optional number)
3006   "Return a list of article numbers that are children of article NUMBER."
3007   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3008          (level (gnus-data-level (car data)))
3009          l children)
3010     (while (and (setq data (cdr data))
3011                 (> (setq l (gnus-data-level (car data))) level))
3012       (and (= (1+ level) l)
3013            (push (gnus-data-number (car data))
3014                  children)))
3015     (nreverse children)))
3016
3017 (defun gnus-summary-article-parent (&optional number)
3018   "Return the article number of the parent of article NUMBER."
3019   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3020                                     (gnus-data-list t)))
3021          (level (gnus-data-level (car data))))
3022     (if (zerop level)
3023         ()                              ; This is a root.
3024       ;; We search until we find an article with a level less than
3025       ;; this one.  That function has to be the parent.
3026       (while (and (setq data (cdr data))
3027                   (not (< (gnus-data-level (car data)) level))))
3028       (and data (gnus-data-number (car data))))))
3029
3030 (defun gnus-unread-mark-p (mark)
3031   "Say whether MARK is the unread mark."
3032   (= mark gnus-unread-mark))
3033
3034 (defun gnus-read-mark-p (mark)
3035   "Say whether MARK is one of the marks that mark as read.
3036 This is all marks except unread, ticked, dormant, and expirable."
3037   (not (or (= mark gnus-unread-mark)
3038            (= mark gnus-ticked-mark)
3039            (= mark gnus-spam-mark)
3040            (= mark gnus-dormant-mark)
3041            (= mark gnus-expirable-mark))))
3042
3043 (defmacro gnus-article-mark (number)
3044   "Return the MARK of article NUMBER.
3045 This macro should only be used when computing the mark the \"first\"
3046 time; i.e., when generating the summary lines.  After that,
3047 `gnus-summary-article-mark' should be used to examine the
3048 marks of articles."
3049   `(cond
3050     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3051     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3052     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3053     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3054     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3055     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3056     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3057     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3058            gnus-ancient-mark))))
3059
3060 ;; Saving hidden threads.
3061
3062 (defmacro gnus-save-hidden-threads (&rest forms)
3063   "Save hidden threads, eval FORMS, and restore the hidden threads."
3064   (let ((config (make-symbol "config")))
3065     `(let ((,config (gnus-hidden-threads-configuration)))
3066        (unwind-protect
3067            (save-excursion
3068              ,@forms)
3069          (gnus-restore-hidden-threads-configuration ,config)))))
3070 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3071 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3072
3073 (defun gnus-data-compute-positions ()
3074   "Compute the positions of all articles."
3075   (setq gnus-newsgroup-data-reverse nil)
3076   (let ((data gnus-newsgroup-data))
3077     (save-excursion
3078       (gnus-save-hidden-threads
3079         (gnus-summary-show-all-threads)
3080         (goto-char (point-min))
3081         (while data
3082           (while (get-text-property (point) 'gnus-intangible)
3083             (forward-line 1))
3084           (gnus-data-set-pos (car data) (+ (point) 3))
3085           (setq data (cdr data))
3086           (forward-line 1))))))
3087
3088 (defun gnus-hidden-threads-configuration ()
3089   "Return the current hidden threads configuration."
3090   (save-excursion
3091     (let (config)
3092       (goto-char (point-min))
3093       (while (search-forward "\r" nil t)
3094         (push (1- (point)) config))
3095       config)))
3096
3097 (defun gnus-restore-hidden-threads-configuration (config)
3098   "Restore hidden threads configuration from CONFIG."
3099   (save-excursion
3100     (let (point buffer-read-only)
3101       (while (setq point (pop config))
3102         (when (and (< point (point-max))
3103                    (goto-char point)
3104                    (eq (char-after) ?\n))
3105           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3106
3107 ;; Various summary mode internalish functions.
3108
3109 (defun gnus-mouse-pick-article (e)
3110   (interactive "e")
3111   (mouse-set-point e)
3112   (gnus-summary-next-page nil t))
3113
3114 (defun gnus-summary-set-display-table ()
3115   "Change the display table.
3116 Odd characters have a tendency to mess
3117 up nicely formatted displays - we make all possible glyphs
3118 display only a single character."
3119
3120   ;; We start from the standard display table, if any.
3121   (let ((table (or (copy-sequence standard-display-table)
3122                    (make-display-table)))
3123         (i 32))
3124     ;; Nix out all the control chars...
3125     (while (>= (setq i (1- i)) 0)
3126       (aset table i [??]))
3127     ;; ... but not newline and cr, of course.  (cr is necessary for the
3128     ;; selective display).
3129     (aset table ?\n nil)
3130     (aset table ?\r nil)
3131     ;; We keep TAB as well.
3132     (aset table ?\t nil)
3133     ;; We nix out any glyphs over 126 that are not set already.
3134     (let ((i 256))
3135       (while (>= (setq i (1- i)) 127)
3136         ;; Only modify if the entry is nil.
3137         (unless (aref table i)
3138           (aset table i [??]))))
3139     (setq buffer-display-table table)))
3140
3141 (defun gnus-summary-set-article-display-arrow (pos)
3142   "Update the overlay arrow to point to line at position POS."
3143   (when (and gnus-summary-display-arrow
3144              (boundp 'overlay-arrow-position)
3145              (boundp 'overlay-arrow-string))
3146     (save-excursion
3147       (goto-char pos)
3148       (beginning-of-line)
3149       (unless overlay-arrow-position
3150         (setq overlay-arrow-position (make-marker)))
3151       (setq overlay-arrow-string "=>"
3152             overlay-arrow-position (set-marker overlay-arrow-position
3153                                                (point)
3154                                                (current-buffer))))))
3155
3156 (defun gnus-summary-setup-buffer (group)
3157   "Initialize summary buffer."
3158   (let ((buffer (gnus-summary-buffer-name group))
3159         (dead-name (concat "*Dead Summary "
3160                            (gnus-group-decoded-name group) "*")))
3161     ;; If a dead summary buffer exists, we kill it.
3162     (when (gnus-buffer-live-p dead-name)
3163       (gnus-kill-buffer dead-name))
3164     (if (get-buffer buffer)
3165         (progn
3166           (set-buffer buffer)
3167           (setq gnus-summary-buffer (current-buffer))
3168           (not gnus-newsgroup-prepared))
3169       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3170       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3171       (gnus-summary-mode group)
3172       (when gnus-carpal
3173         (gnus-carpal-setup-buffer 'summary))
3174       (unless gnus-single-article-buffer
3175         (make-local-variable 'gnus-article-buffer)
3176         (make-local-variable 'gnus-article-current)
3177         (make-local-variable 'gnus-original-article-buffer))
3178       (setq gnus-newsgroup-name group)
3179       ;; Set any local variables in the group parameters.
3180       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3181       t)))
3182
3183 (defun gnus-set-global-variables ()
3184   "Set the global equivalents of the buffer-local variables.
3185 They are set to the latest values they had.  These reflect the summary
3186 buffer that was in action when the last article was fetched."
3187   (when (eq major-mode 'gnus-summary-mode)
3188     (setq gnus-summary-buffer (current-buffer))
3189     (let ((name gnus-newsgroup-name)
3190           (marked gnus-newsgroup-marked)
3191           (spam gnus-newsgroup-spam-marked)
3192           (unread gnus-newsgroup-unreads)
3193           (headers gnus-current-headers)
3194           (data gnus-newsgroup-data)
3195           (summary gnus-summary-buffer)
3196           (article-buffer gnus-article-buffer)
3197           (original gnus-original-article-buffer)
3198           (gac gnus-article-current)
3199           (reffed gnus-reffed-article-number)
3200           (score-file gnus-current-score-file)
3201           (default-charset gnus-newsgroup-charset)
3202           vlist)
3203       (let ((locals gnus-newsgroup-variables))
3204         (while locals
3205           (if (consp (car locals))
3206               (push (eval (caar locals)) vlist)
3207             (push (eval (car locals)) vlist))
3208           (setq locals (cdr locals)))
3209         (setq vlist (nreverse vlist)))
3210       (with-current-buffer gnus-group-buffer
3211         (setq gnus-newsgroup-name name
3212               gnus-newsgroup-marked marked
3213               gnus-newsgroup-spam-marked spam
3214               gnus-newsgroup-unreads unread
3215               gnus-current-headers headers
3216               gnus-newsgroup-data data
3217               gnus-article-current gac
3218               gnus-summary-buffer summary
3219               gnus-article-buffer article-buffer
3220               gnus-original-article-buffer original
3221               gnus-reffed-article-number reffed
3222               gnus-current-score-file score-file
3223               gnus-newsgroup-charset default-charset)
3224         (let ((locals gnus-newsgroup-variables))
3225           (while locals
3226             (if (consp (car locals))
3227                 (set (caar locals) (pop vlist))
3228               (set (car locals) (pop vlist)))
3229             (setq locals (cdr locals))))
3230         ;; The article buffer also has local variables.
3231         (when (gnus-buffer-live-p gnus-article-buffer)
3232           (set-buffer gnus-article-buffer)
3233           (setq gnus-summary-buffer summary))))))
3234
3235 (defun gnus-summary-article-unread-p (article)
3236   "Say whether ARTICLE is unread or not."
3237   (memq article gnus-newsgroup-unreads))
3238
3239 (defun gnus-summary-first-article-p (&optional article)
3240   "Return whether ARTICLE is the first article in the buffer."
3241   (if (not (setq article (or article (gnus-summary-article-number))))
3242       nil
3243     (eq article (caar gnus-newsgroup-data))))
3244
3245 (defun gnus-summary-last-article-p (&optional article)
3246   "Return whether ARTICLE is the last article in the buffer."
3247   (if (not (setq article (or article (gnus-summary-article-number))))
3248       ;; All non-existent numbers are the last article.  :-)
3249       t
3250     (not (cdr (gnus-data-find-list article)))))
3251
3252 (defun gnus-make-thread-indent-array ()
3253   (let ((n 200))
3254     (unless (and gnus-thread-indent-array
3255                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3256       (setq gnus-thread-indent-array (make-vector 201 "")
3257             gnus-thread-indent-array-level gnus-thread-indent-level)
3258       (while (>= n 0)
3259         (aset gnus-thread-indent-array n
3260               (make-string (* n gnus-thread-indent-level) ? ))
3261         (setq n (1- n))))))
3262
3263 (defun gnus-update-summary-mark-positions ()
3264   "Compute where the summary marks are to go."
3265   (save-excursion
3266     (when (gnus-buffer-exists-p gnus-summary-buffer)
3267       (set-buffer gnus-summary-buffer))
3268     (let ((gnus-replied-mark 129)
3269           (gnus-score-below-mark 130)
3270           (gnus-score-over-mark 130)
3271           (gnus-undownloaded-mark 131)
3272           (spec gnus-summary-line-format-spec)
3273           gnus-visual pos)
3274       (save-excursion
3275         (gnus-set-work-buffer)
3276         (let ((gnus-summary-line-format-spec spec)
3277               (gnus-newsgroup-downloadable '(0)))
3278           (gnus-summary-insert-line
3279            (make-full-mail-header 0 "" "nobody"
3280                                   "05 Apr 2001 23:33:09 +0400"
3281                                   "" "" 0 0 "" nil)
3282            0 nil t 128 t nil "" nil 1)
3283           (goto-char (point-min))
3284           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3285                                              (- (point) (point-min) 1)))))
3286           (goto-char (point-min))
3287           (push (cons 'replied (and (search-forward "\201" nil t)
3288                                     (- (point) (point-min) 1)))
3289                 pos)
3290           (goto-char (point-min))
3291           (push (cons 'score (and (search-forward "\202" nil t)
3292                                   (- (point) (point-min) 1)))
3293                 pos)
3294           (goto-char (point-min))
3295           (push (cons 'download
3296                       (and (search-forward "\203" nil t)
3297                            (- (point) (point-min) 1)))
3298                 pos)))
3299       (setq gnus-summary-mark-positions pos))))
3300
3301 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3302   "Insert a dummy root in the summary buffer."
3303   (beginning-of-line)
3304   (gnus-add-text-properties
3305    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3306    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3307
3308 (defun gnus-summary-extract-address-component (from)
3309   (or (car (funcall gnus-extract-address-components from))
3310       from))
3311
3312 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3313   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3314                                 default-mime-charset)))
3315     ;; Is it really necessary to do this next part for each summary line?
3316     ;; Luckily, doesn't seem to slow things down much.
3317     (or
3318      (and gnus-ignored-from-addresses
3319           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3320           (let ((extra-headers (mail-header-extra header))
3321                 to
3322                 newsgroups)
3323             (cond
3324              ((setq to (cdr (assq 'To extra-headers)))
3325               (concat "-> "
3326                       (inline
3327                         (gnus-summary-extract-address-component
3328                          (funcall gnus-decode-encoded-word-function to)))))
3329              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3330               (concat "=> " newsgroups)))))
3331      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3332
3333 (defun gnus-summary-insert-line (gnus-tmp-header
3334                                  gnus-tmp-level gnus-tmp-current
3335                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3336                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3337                                  &optional gnus-tmp-dummy gnus-tmp-score
3338                                  gnus-tmp-process)
3339   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3340          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3341          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3342          (gnus-tmp-score-char
3343           (if (or (null gnus-summary-default-score)
3344                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3345                       gnus-summary-zcore-fuzz))
3346               ?\ ;;;Whitespace
3347             (if (< gnus-tmp-score gnus-summary-default-score)
3348                 gnus-score-below-mark gnus-score-over-mark)))
3349          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3350          (gnus-tmp-replied
3351           (cond (gnus-tmp-process gnus-process-mark)
3352                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3353                  gnus-cached-mark)
3354                 (gnus-tmp-replied gnus-replied-mark)
3355                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3356                  gnus-forwarded-mark)
3357                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3358                  gnus-saved-mark)
3359                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3360                  gnus-recent-mark)
3361                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3362                  gnus-unseen-mark)
3363                 (t gnus-no-mark)))
3364          (gnus-tmp-downloaded
3365           (cond (undownloaded
3366                  gnus-undownloaded-mark)
3367                 (gnus-newsgroup-agentized
3368                  gnus-downloaded-mark)
3369                 (t
3370                  gnus-no-mark)))
3371          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3372          (gnus-tmp-name
3373           (cond
3374            ((string-match "<[^>]+> *$" gnus-tmp-from)
3375             (let ((beg (match-beginning 0)))
3376               (or (and (string-match "^\".+\"" gnus-tmp-from)
3377                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3378                   (substring gnus-tmp-from 0 beg))))
3379            ((string-match "(.+)" gnus-tmp-from)
3380             (substring gnus-tmp-from
3381                        (1+ (match-beginning 0)) (1- (match-end 0))))
3382            (t gnus-tmp-from)))
3383          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3384          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3385          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3386          (buffer-read-only nil))
3387     (when (string= gnus-tmp-name "")
3388       (setq gnus-tmp-name gnus-tmp-from))
3389     (unless (numberp gnus-tmp-lines)
3390       (setq gnus-tmp-lines -1))
3391     (if (= gnus-tmp-lines -1)
3392         (setq gnus-tmp-lines "?")
3393       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3394     (gnus-put-text-property-excluding-characters-with-faces
3395      (point)
3396      (progn (eval gnus-summary-line-format-spec) (point))
3397      'gnus-number gnus-tmp-number)
3398     (when (gnus-visual-p 'summary-highlight 'highlight)
3399       (forward-line -1)
3400       (gnus-run-hooks 'gnus-summary-update-hook)
3401       (forward-line 1))))
3402
3403 (defun gnus-summary-update-line (&optional dont-update)
3404   "Update summary line after change."
3405   (when (and gnus-summary-default-score
3406              (not gnus-summary-inhibit-highlight))
3407     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3408            (article (gnus-summary-article-number))
3409            (score (gnus-summary-article-score article)))
3410       (unless dont-update
3411         (if (and gnus-summary-mark-below
3412                  (< (gnus-summary-article-score)
3413                     gnus-summary-mark-below))
3414             ;; This article has a low score, so we mark it as read.
3415             (when (memq article gnus-newsgroup-unreads)
3416               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3417           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3418             ;; This article was previously marked as read on account
3419             ;; of a low score, but now it has risen, so we mark it as
3420             ;; unread.
3421             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3422         (gnus-summary-update-mark
3423          (if (or (null gnus-summary-default-score)
3424                  (<= (abs (- score gnus-summary-default-score))
3425                      gnus-summary-zcore-fuzz))
3426              ?\ ;;;Whitespace
3427            (if (< score gnus-summary-default-score)
3428                gnus-score-below-mark gnus-score-over-mark))
3429          'score))
3430       ;; Do visual highlighting.
3431       (when (gnus-visual-p 'summary-highlight 'highlight)
3432         (gnus-run-hooks 'gnus-summary-update-hook)))))
3433
3434 (defvar gnus-tmp-new-adopts nil)
3435
3436 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3437   "Return the number of articles in THREAD.
3438 This may be 0 in some cases -- if none of the articles in
3439 the thread are to be displayed."
3440   (let* ((number
3441           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3442           (cond
3443            ((not (listp thread))
3444             1)
3445            ((and (consp thread) (cdr thread))
3446             (apply
3447              '+ 1 (mapcar
3448                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3449            ((null thread)
3450             1)
3451            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3452             1)
3453            (t 0))))
3454     (when (and level (zerop level) gnus-tmp-new-adopts)
3455       (incf number
3456             (apply '+ (mapcar
3457                        'gnus-summary-number-of-articles-in-thread
3458                        gnus-tmp-new-adopts))))
3459     (if char
3460         (if (> number 1) gnus-not-empty-thread-mark
3461           gnus-empty-thread-mark)
3462       number)))
3463
3464 (defsubst gnus-summary-line-message-size (head)
3465   "Return pretty-printed version of message size.
3466 This function is intended to be used in
3467 `gnus-summary-line-format-alist'."
3468   (let ((c (or (mail-header-chars head) -1)))
3469     (cond ((< c 0) "n/a")               ; chars not available
3470           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3471           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3472           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3473           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3474
3475
3476 (defun gnus-summary-set-local-parameters (group)
3477   "Go through the local params of GROUP and set all variable specs in that list."
3478   (let ((vars '(quit-config)))          ; Ignore quit-config.
3479     (dolist (elem (gnus-group-find-parameter group))
3480       (and (consp elem)                 ; Has to be a cons.
3481            (consp (cdr elem))           ; The cdr has to be a list.
3482            (symbolp (car elem))         ; Has to be a symbol in there.
3483            (not (memq (car elem) vars))
3484            (ignore-errors               ; So we set it.
3485              (push (car elem) vars)
3486              (make-local-variable (car elem))
3487              (set (car elem) (eval (nth 1 elem))))))))
3488
3489 (defun gnus-summary-read-group (group &optional show-all no-article
3490                                       kill-buffer no-display backward
3491                                       select-articles)
3492   "Start reading news in newsgroup GROUP.
3493 If SHOW-ALL is non-nil, already read articles are also listed.
3494 If NO-ARTICLE is non-nil, no article is selected initially.
3495 If NO-DISPLAY, don't generate a summary buffer."
3496   (let (result)
3497     (while (and group
3498                 (null (setq result
3499                             (let ((gnus-auto-select-next nil))
3500                               (or (gnus-summary-read-group-1
3501                                    group show-all no-article
3502                                    kill-buffer no-display
3503                                    select-articles)
3504                                   (setq show-all nil
3505                                         select-articles nil)))))
3506                 (eq gnus-auto-select-next 'quietly))
3507       (set-buffer gnus-group-buffer)
3508       ;; The entry function called above goes to the next
3509       ;; group automatically, so we go two groups back
3510       ;; if we are searching for the previous group.
3511       (when backward
3512         (gnus-group-prev-unread-group 2))
3513       (if (not (equal group (gnus-group-group-name)))
3514           (setq group (gnus-group-group-name))
3515         (setq group nil)))
3516     result))
3517
3518 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3519   "Directly jump to the other GROUP from summary buffer.
3520 If SHOW-ALL is non-nil, already read articles are also listed."
3521   (interactive
3522    (if (eq gnus-summary-buffer (current-buffer))
3523        (list (completing-read
3524               "Group: " gnus-active-hashtb nil t
3525               (when (and gnus-newsgroup-name
3526                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3527                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3528               'gnus-group-history)
3529              current-prefix-arg)
3530      (error "%s must be invoked from a gnus summary buffer." this-command)))
3531   (unless (or (zerop (length group))
3532               (and gnus-newsgroup-name
3533                    (string-equal gnus-newsgroup-name group)))
3534     (gnus-summary-exit)
3535     (gnus-summary-read-group group show-all
3536                              gnus-dont-select-after-jump-to-other-group)))
3537
3538 (defun gnus-summary-read-group-1 (group show-all no-article
3539                                         kill-buffer no-display
3540                                         &optional select-articles)
3541   ;; Killed foreign groups can't be entered.
3542   ;;  (when (and (not (gnus-group-native-p group))
3543   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3544   ;;    (error "Dead non-native groups can't be entered"))
3545   (gnus-message 5 "Retrieving newsgroup: %s..."
3546                 (gnus-group-decoded-name group))
3547   (let* ((new-group (gnus-summary-setup-buffer group))
3548          (quit-config (gnus-group-quit-config group))
3549          (did-select (and new-group (gnus-select-newsgroup
3550                                      group show-all select-articles))))
3551     (cond
3552      ;; This summary buffer exists already, so we just select it.
3553      ((not new-group)
3554       (gnus-set-global-variables)
3555       (when kill-buffer
3556         (gnus-kill-or-deaden-summary kill-buffer))
3557       (gnus-configure-windows 'summary 'force)
3558       (gnus-set-mode-line 'summary)
3559       (gnus-summary-position-point)
3560       (message "")
3561       t)
3562      ;; We couldn't select this group.
3563      ((null did-select)
3564       (when (and (eq major-mode 'gnus-summary-mode)
3565                  (not (equal (current-buffer) kill-buffer)))
3566         (kill-buffer (current-buffer))
3567         (if (not quit-config)
3568             (progn
3569               ;; Update the info -- marks might need to be removed,
3570               ;; for instance.
3571               (gnus-summary-update-info)
3572               (set-buffer gnus-group-buffer)
3573               (gnus-group-jump-to-group group)
3574               (gnus-group-next-unread-group 1))
3575           (gnus-handle-ephemeral-exit quit-config)))
3576       (let ((grpinfo (gnus-get-info group)))
3577         (if (null (gnus-info-read grpinfo))
3578             (gnus-message 3 "Group %s contains no messages"
3579                           (gnus-group-decoded-name group))
3580           (gnus-message 3 "Can't select group")))
3581       nil)
3582      ;; The user did a `C-g' while prompting for number of articles,
3583      ;; so we exit this group.
3584      ((eq did-select 'quit)
3585       (and (eq major-mode 'gnus-summary-mode)
3586            (not (equal (current-buffer) kill-buffer))
3587            (kill-buffer (current-buffer)))
3588       (when kill-buffer
3589         (gnus-kill-or-deaden-summary kill-buffer))
3590       (if (not quit-config)
3591           (progn
3592             (set-buffer gnus-group-buffer)
3593             (gnus-group-jump-to-group group)
3594             (gnus-group-next-unread-group 1)
3595             (gnus-configure-windows 'group 'force))
3596         (gnus-handle-ephemeral-exit quit-config))
3597       ;; Finally signal the quit.
3598       (signal 'quit nil))
3599      ;; The group was successfully selected.
3600      (t
3601       (gnus-set-global-variables)
3602       ;; Save the active value in effect when the group was entered.
3603       (setq gnus-newsgroup-active
3604             (gnus-copy-sequence
3605              (gnus-active gnus-newsgroup-name)))
3606       ;; You can change the summary buffer in some way with this hook.
3607       (gnus-run-hooks 'gnus-select-group-hook)
3608       (gnus-update-format-specifications
3609        nil 'summary 'summary-mode 'summary-dummy)
3610       (gnus-update-summary-mark-positions)
3611       ;; Do score processing.
3612       (when gnus-use-scoring
3613         (gnus-possibly-score-headers))
3614       ;; Check whether to fill in the gaps in the threads.
3615       (when gnus-build-sparse-threads
3616         (gnus-build-sparse-threads))
3617       ;; Find the initial limit.
3618       (if show-all
3619           (let ((gnus-newsgroup-dormant nil))
3620             (gnus-summary-initial-limit show-all))
3621         (gnus-summary-initial-limit show-all))
3622       ;; Generate the summary buffer.
3623       (unless no-display
3624         (gnus-summary-prepare))
3625       (when gnus-use-trees
3626         (gnus-tree-open group)
3627         (setq gnus-summary-highlight-line-function
3628               'gnus-tree-highlight-article))
3629       ;; If the summary buffer is empty, but there are some low-scored
3630       ;; articles or some excluded dormants, we include these in the
3631       ;; buffer.
3632       (when (and (zerop (buffer-size))
3633                  (not no-display))
3634         (cond (gnus-newsgroup-dormant
3635                (gnus-summary-limit-include-dormant))
3636               ((and gnus-newsgroup-scored show-all)
3637                (gnus-summary-limit-include-expunged t))))
3638       ;; Function `gnus-apply-kill-file' must be called in this hook.
3639       (gnus-run-hooks 'gnus-apply-kill-hook)
3640       (if (and (zerop (buffer-size))
3641                (not no-display))
3642           (progn
3643             ;; This newsgroup is empty.
3644             (gnus-summary-catchup-and-exit nil t)
3645             (gnus-message 6 "No unread news")
3646             (when kill-buffer
3647               (gnus-kill-or-deaden-summary kill-buffer))
3648             ;; Return nil from this function.
3649             nil)
3650         ;; Hide conversation thread subtrees.  We cannot do this in
3651         ;; gnus-summary-prepare-hook since kill processing may not
3652         ;; work with hidden articles.
3653         (gnus-summary-maybe-hide-threads)
3654         (when kill-buffer
3655           (gnus-kill-or-deaden-summary kill-buffer))
3656         (gnus-summary-auto-select-subject)
3657         ;; Show first unread article if requested.
3658         (if (and (not no-article)
3659                  (not no-display)
3660                  gnus-newsgroup-unreads
3661                  gnus-auto-select-first)
3662             (progn
3663               (gnus-configure-windows 'summary)
3664               (let ((art (gnus-summary-article-number)))
3665                 (unless (and (not gnus-plugged)
3666                              (or (memq art gnus-newsgroup-undownloaded)
3667                                  (memq art gnus-newsgroup-downloadable)))
3668                   (gnus-summary-goto-article art))))
3669           ;; Don't select any articles.
3670           (gnus-summary-position-point)
3671           (gnus-configure-windows 'summary 'force)
3672           (gnus-set-mode-line 'summary))
3673         (when (and gnus-auto-center-group
3674                    (get-buffer-window gnus-group-buffer t))
3675           ;; Gotta use windows, because recenter does weird stuff if
3676           ;; the current buffer ain't the displayed window.
3677           (let ((owin (selected-window)))
3678             (select-window (get-buffer-window gnus-group-buffer t))
3679             (when (gnus-group-goto-group group)
3680               (recenter))
3681             (select-window owin)))
3682         ;; Mark this buffer as "prepared".
3683         (setq gnus-newsgroup-prepared t)
3684         (gnus-run-hooks 'gnus-summary-prepared-hook)
3685         (unless (gnus-ephemeral-group-p group)
3686           (gnus-group-update-group group))
3687         t)))))
3688
3689 (defun gnus-summary-auto-select-subject ()
3690   "Select the subject line on initial group entry."
3691   (goto-char (point-min))
3692   (cond
3693    ((eq gnus-auto-select-subject 'best)
3694     (gnus-summary-best-unread-subject))
3695    ((eq gnus-auto-select-subject 'unread)
3696     (gnus-summary-first-unread-subject))
3697    ((eq gnus-auto-select-subject 'unseen)
3698     (gnus-summary-first-unseen-subject))
3699    ((eq gnus-auto-select-subject 'unseen-or-unread)
3700     (gnus-summary-first-unseen-or-unread-subject))
3701    ((eq gnus-auto-select-subject 'first)
3702     ;; Do nothing.
3703     )
3704    ((functionp gnus-auto-select-subject)
3705     (funcall gnus-auto-select-subject))))
3706
3707 (defun gnus-summary-prepare ()
3708   "Generate the summary buffer."
3709   (interactive)
3710   (let ((buffer-read-only nil))
3711     (erase-buffer)
3712     (setq gnus-newsgroup-data nil
3713           gnus-newsgroup-data-reverse nil)
3714     (gnus-run-hooks 'gnus-summary-generate-hook)
3715     ;; Generate the buffer, either with threads or without.
3716     (when gnus-newsgroup-headers
3717       (gnus-summary-prepare-threads
3718        (if gnus-show-threads
3719            (gnus-sort-gathered-threads
3720             (funcall gnus-summary-thread-gathering-function
3721                      (gnus-sort-threads
3722                       (gnus-cut-threads (gnus-make-threads)))))
3723          ;; Unthreaded display.
3724          (gnus-sort-articles gnus-newsgroup-headers))))
3725     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3726     ;; Call hooks for modifying summary buffer.
3727     (goto-char (point-min))
3728     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3729
3730 (defsubst gnus-general-simplify-subject (subject)
3731   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3732   (setq subject
3733         (cond
3734          ;; Truncate the subject.
3735          (gnus-simplify-subject-functions
3736           (gnus-map-function gnus-simplify-subject-functions subject))
3737          ((numberp gnus-summary-gather-subject-limit)
3738           (setq subject (gnus-simplify-subject-re subject))
3739           (if (> (length subject) gnus-summary-gather-subject-limit)
3740               (substring subject 0 gnus-summary-gather-subject-limit)
3741             subject))
3742          ;; Fuzzily simplify it.
3743          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3744           (gnus-simplify-subject-fuzzy subject))
3745          ;; Just remove the leading "Re:".
3746          (t
3747           (gnus-simplify-subject-re subject))))
3748
3749   (if (and gnus-summary-gather-exclude-subject
3750            (string-match gnus-summary-gather-exclude-subject subject))
3751       nil                               ; This article shouldn't be gathered
3752     subject))
3753
3754 (defun gnus-summary-simplify-subject-query ()
3755   "Query where the respool algorithm would put this article."
3756   (interactive)
3757   (gnus-summary-select-article)
3758   (message "%s"
3759            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3760
3761 (defun gnus-gather-threads-by-subject (threads)
3762   "Gather threads by looking at Subject headers."
3763   (if (not gnus-summary-make-false-root)
3764       threads
3765     (let ((hashtb (gnus-make-hashtable 1024))
3766           (prev threads)
3767           (result threads)
3768           subject hthread whole-subject)
3769       (while threads
3770         (setq subject (gnus-general-simplify-subject
3771                        (setq whole-subject (mail-header-subject
3772                                             (caar threads)))))
3773         (when subject
3774           (if (setq hthread (gnus-gethash subject hashtb))
3775               (progn
3776                 ;; We enter a dummy root into the thread, if we
3777                 ;; haven't done that already.
3778                 (unless (stringp (caar hthread))
3779                   (setcar hthread (list whole-subject (car hthread))))
3780                 ;; We add this new gathered thread to this gathered
3781                 ;; thread.
3782                 (setcdr (car hthread)
3783                         (nconc (cdar hthread) (list (car threads))))
3784                 ;; Remove it from the list of threads.
3785                 (setcdr prev (cdr threads))
3786                 (setq threads prev))
3787             ;; Enter this thread into the hash table.
3788             (gnus-sethash subject
3789                           (if gnus-summary-make-false-root-always
3790                               (progn
3791                                 ;; If you want a dummy root above all
3792                                 ;; threads...
3793                                 (setcar threads (list whole-subject
3794                                                       (car threads)))
3795                                 threads)
3796                             threads)
3797                           hashtb)))
3798         (setq prev threads)
3799         (setq threads (cdr threads)))
3800       result)))
3801
3802 (defun gnus-gather-threads-by-references (threads)
3803   "Gather threads by looking at References headers."
3804   (let ((idhashtb (gnus-make-hashtable 1024))
3805         (thhashtb (gnus-make-hashtable 1024))
3806         (prev threads)
3807         (result threads)
3808         ids references id gthread gid entered ref)
3809     (while threads
3810       (when (setq references (mail-header-references (caar threads)))
3811         (setq id (mail-header-id (caar threads))
3812               ids (inline (gnus-split-references references))
3813               entered nil)
3814         (while (setq ref (pop ids))
3815           (setq ids (delete ref ids))
3816           (if (not (setq gid (gnus-gethash ref idhashtb)))
3817               (progn
3818                 (gnus-sethash ref id idhashtb)
3819                 (gnus-sethash id threads thhashtb))
3820             (setq gthread (gnus-gethash gid thhashtb))
3821             (unless entered
3822               ;; We enter a dummy root into the thread, if we
3823               ;; haven't done that already.
3824               (unless (stringp (caar gthread))
3825                 (setcar gthread (list (mail-header-subject (caar gthread))
3826                                       (car gthread))))
3827               ;; We add this new gathered thread to this gathered
3828               ;; thread.
3829               (setcdr (car gthread)
3830                       (nconc (cdar gthread) (list (car threads)))))
3831             ;; Add it into the thread hash table.
3832             (gnus-sethash id gthread thhashtb)
3833             (setq entered t)
3834             ;; Remove it from the list of threads.
3835             (setcdr prev (cdr threads))
3836             (setq threads prev))))
3837       (setq prev threads)
3838       (setq threads (cdr threads)))
3839     result))
3840
3841 (defun gnus-sort-gathered-threads (threads)
3842   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3843   (let ((result threads))
3844     (while threads
3845       (when (stringp (caar threads))
3846         (setcdr (car threads)
3847                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3848       (setq threads (cdr threads)))
3849     result))
3850
3851 (defun gnus-thread-loop-p (root thread)
3852   "Say whether ROOT is in THREAD."
3853   (let ((stack (list thread))
3854         (infloop 0)
3855         th)
3856     (while (setq thread (pop stack))
3857       (setq th (cdr thread))
3858       (while (and th
3859                   (not (eq (caar th) root)))
3860         (pop th))
3861       (if th
3862           ;; We have found a loop.
3863           (let (ref-dep)
3864             (setcdr thread (delq (car th) (cdr thread)))
3865             (if (boundp (setq ref-dep (intern "none"
3866                                               gnus-newsgroup-dependencies)))
3867                 (setcdr (symbol-value ref-dep)
3868                         (nconc (cdr (symbol-value ref-dep))
3869                                (list (car th))))
3870               (set ref-dep (list nil (car th))))
3871             (setq infloop 1
3872                   stack nil))
3873         ;; Push all the subthreads onto the stack.
3874         (push (cdr thread) stack)))
3875     infloop))
3876
3877 (defun gnus-make-threads ()
3878   "Go through the dependency hashtb and find the roots.  Return all threads."
3879   (let (threads)
3880     (while (catch 'infloop
3881              (mapatoms
3882               (lambda (refs)
3883                 ;; Deal with self-referencing References loops.
3884                 (when (and (car (symbol-value refs))
3885                            (not (zerop
3886                                  (apply
3887                                   '+
3888                                   (mapcar
3889                                    (lambda (thread)
3890                                      (gnus-thread-loop-p
3891                                       (car (symbol-value refs)) thread))
3892                                    (cdr (symbol-value refs)))))))
3893                   (setq threads nil)
3894                   (throw 'infloop t))
3895                 (unless (car (symbol-value refs))
3896                   ;; These threads do not refer back to any other articles,
3897                   ;; so they're roots.
3898                   (setq threads (append (cdr (symbol-value refs)) threads))))
3899               gnus-newsgroup-dependencies)))
3900     threads))
3901
3902 ;; Build the thread tree.
3903 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3904   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3905
3906 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3907 if it was already present.
3908
3909 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3910 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3911 Message-IDs will be renamed to a unique Message-ID before being
3912 entered.
3913
3914 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3915   (let* ((id (mail-header-id header))
3916          (id-dep (and id (intern id dependencies)))
3917          parent-id ref ref-dep ref-header replaced)
3918     ;; Enter this `header' in the `dependencies' table.
3919     (cond
3920      ((not id-dep)
3921       (setq header nil))
3922      ;; The first two cases do the normal part: enter a new `header'
3923      ;; in the `dependencies' table.
3924      ((not (boundp id-dep))
3925       (set id-dep (list header)))
3926      ((null (car (symbol-value id-dep)))
3927       (setcar (symbol-value id-dep) header))
3928
3929      ;; From here the `header' was already present in the
3930      ;; `dependencies' table.
3931      (force-new
3932       ;; Overrides an existing entry;
3933       ;; just set the header part of the entry.
3934       (setcar (symbol-value id-dep) header)
3935       (setq replaced t))
3936
3937      ;; Renames the existing `header' to a unique Message-ID.
3938      ((not gnus-summary-ignore-duplicates)
3939       ;; An article with this Message-ID has already been seen.
3940       ;; We rename the Message-ID.
3941       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3942            (list header))
3943       (mail-header-set-id header id))
3944
3945      ;; The last case ignores an existing entry, except it adds any
3946      ;; additional Xrefs (in case the two articles came from different
3947      ;; servers.
3948      ;; Also sets `header' to `nil' meaning that the `dependencies'
3949      ;; table was *not* modified.
3950      (t
3951       (mail-header-set-xref
3952        (car (symbol-value id-dep))
3953        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3954                    "")
3955                (or (mail-header-xref header) "")))
3956       (setq header nil)))
3957
3958     (when (and header (not replaced))
3959       ;; First check that we are not creating a References loop.
3960       (setq parent-id (gnus-parent-id (mail-header-references header)))
3961       (setq ref parent-id)
3962       (while (and ref
3963                   (setq ref-dep (intern-soft ref dependencies))
3964                   (boundp ref-dep)
3965                   (setq ref-header (car (symbol-value ref-dep))))
3966         (if (string= id ref)
3967             ;; Yuk!  This is a reference loop.  Make the article be a
3968             ;; root article.
3969             (progn
3970               (mail-header-set-references (car (symbol-value id-dep)) "none")
3971               (setq ref nil)
3972               (setq parent-id nil))
3973           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3974       (setq ref-dep (intern (or parent-id "none") dependencies))
3975       (if (boundp ref-dep)
3976           (setcdr (symbol-value ref-dep)
3977                   (nconc (cdr (symbol-value ref-dep))
3978                          (list (symbol-value id-dep))))
3979         (set ref-dep (list nil (symbol-value id-dep)))))
3980     header))
3981
3982 (defun gnus-extract-message-id-from-in-reply-to (string)
3983   (if (string-match "<[^>]+>" string)
3984       (substring string (match-beginning 0) (match-end 0))
3985     nil))
3986
3987 (defun gnus-build-sparse-threads ()
3988   (let ((headers gnus-newsgroup-headers)
3989         (mail-parse-charset gnus-newsgroup-charset)
3990         (gnus-summary-ignore-duplicates t)
3991         header references generation relations
3992         subject child end new-child date)
3993     ;; First we create an alist of generations/relations, where
3994     ;; generations is how much we trust the relation, and the relation
3995     ;; is parent/child.
3996     (gnus-message 7 "Making sparse threads...")
3997     (save-excursion
3998       (nnheader-set-temp-buffer " *gnus sparse threads*")
3999       (while (setq header (pop headers))
4000         (when (and (setq references (mail-header-references header))
4001                    (not (string= references "")))
4002           (insert references)
4003           (setq child (mail-header-id header)
4004                 subject (mail-header-subject header)
4005                 date (mail-header-date header)
4006                 generation 0)
4007           (while (search-backward ">" nil t)
4008             (setq end (1+ (point)))
4009             (when (search-backward "<" nil t)
4010               (setq new-child (buffer-substring (point) end))
4011               (push (list (incf generation)
4012                           child (setq child new-child)
4013                           subject date)
4014                     relations)))
4015           (when child
4016             (push (list (1+ generation) child nil subject) relations))
4017           (erase-buffer)))
4018       (kill-buffer (current-buffer)))
4019     ;; Sort over trustworthiness.
4020     (mapcar
4021      (lambda (relation)
4022        (when (gnus-dependencies-add-header
4023               (make-full-mail-header-from-decoded-header
4024                gnus-reffed-article-number
4025                (nth 3 relation) "" (or (nth 4 relation) "")
4026                (nth 1 relation)
4027                (or (nth 2 relation) "") 0 0 "")
4028               gnus-newsgroup-dependencies nil)
4029          (push gnus-reffed-article-number gnus-newsgroup-limit)
4030          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4031          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4032                gnus-newsgroup-reads)
4033          (decf gnus-reffed-article-number)))
4034      (sort relations 'car-less-than-car))
4035     (gnus-message 7 "Making sparse threads...done")))
4036
4037 (defun gnus-build-old-threads ()
4038   ;; Look at all the articles that refer back to old articles, and
4039   ;; fetch the headers for the articles that aren't there.  This will
4040   ;; build complete threads - if the roots haven't been expired by the
4041   ;; server, that is.
4042   (let ((mail-parse-charset gnus-newsgroup-charset)
4043         id heads)
4044     (mapatoms
4045      (lambda (refs)
4046        (when (not (car (symbol-value refs)))
4047          (setq heads (cdr (symbol-value refs)))
4048          (while heads
4049            (if (memq (mail-header-number (caar heads))
4050                      gnus-newsgroup-dormant)
4051                (setq heads (cdr heads))
4052              (setq id (symbol-name refs))
4053              (while (and (setq id (gnus-build-get-header id))
4054                          (not (car (gnus-id-to-thread id)))))
4055              (setq heads nil)))))
4056      gnus-newsgroup-dependencies)))
4057
4058 (defsubst gnus-remove-odd-characters (string)
4059   "Translate STRING into something that doesn't contain weird characters."
4060   (mm-subst-char-in-string
4061    ?\r ?\-
4062    (mm-subst-char-in-string ?\n ?\- string t) t))
4063
4064 ;; This function has to be called with point after the article number
4065 ;; on the beginning of the line.
4066 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4067   (let ((eol (point-at-eol))
4068         (buffer (current-buffer))
4069         header references in-reply-to)
4070
4071     ;; overview: [num subject from date id refs chars lines misc]
4072     (unwind-protect
4073         (progn
4074           (narrow-to-region (point) eol)
4075           (unless (eobp)
4076             (forward-char))
4077
4078           (setq header
4079                 (make-full-mail-header
4080                  number                         ; number
4081                  (nnheader-nov-field)           ; subject
4082                  (nnheader-nov-field)           ; from
4083                  (nnheader-nov-field)           ; date
4084                  (nnheader-nov-read-message-id number)  ; id
4085                  (setq references (nnheader-nov-field)) ; refs
4086                  (nnheader-nov-read-integer)    ; chars
4087                  (nnheader-nov-read-integer)    ; lines
4088                  (unless (eobp)
4089                    (if (looking-at "Xref: ")
4090                        (goto-char (match-end 0)))
4091                    (nnheader-nov-field))        ; Xref
4092                  (nnheader-nov-parse-extra))))  ; extra
4093
4094       (widen))
4095
4096     (when (and (string= references "")
4097                (setq in-reply-to (mail-header-extra header))
4098                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4099       (mail-header-set-references
4100        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4101
4102     (when gnus-alter-header-function
4103       (funcall gnus-alter-header-function header))
4104     (gnus-dependencies-add-header header dependencies force-new)))
4105
4106 (defun gnus-build-get-header (id)
4107   "Look through the buffer of NOV lines and find the header to ID.
4108 Enter this line into the dependencies hash table, and return
4109 the id of the parent article (if any)."
4110   (let ((deps gnus-newsgroup-dependencies)
4111         found header)
4112     (prog1
4113         (save-excursion
4114           (set-buffer nntp-server-buffer)
4115           (let ((case-fold-search nil))
4116             (goto-char (point-min))
4117             (while (and (not found)
4118                         (search-forward id nil t))
4119               (beginning-of-line)
4120               (setq found (looking-at
4121                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4122                                    (regexp-quote id))))
4123               (or found (beginning-of-line 2)))
4124             (when found
4125               (beginning-of-line)
4126               (and
4127                (setq header (gnus-nov-parse-line
4128                              (read (current-buffer)) deps))
4129                (gnus-parent-id (mail-header-references header))))))
4130       (when header
4131         (let ((number (mail-header-number header)))
4132           (push number gnus-newsgroup-limit)
4133           (push header gnus-newsgroup-headers)
4134           (if (memq number gnus-newsgroup-unselected)
4135               (progn
4136                 (setq gnus-newsgroup-unreads
4137                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4138                                                number))
4139                 (setq gnus-newsgroup-unselected
4140                       (delq number gnus-newsgroup-unselected)))
4141             (push number gnus-newsgroup-ancient)))))))
4142
4143 (defun gnus-build-all-threads ()
4144   "Read all the headers."
4145   (let ((gnus-summary-ignore-duplicates t)
4146         (mail-parse-charset gnus-newsgroup-charset)
4147         (dependencies gnus-newsgroup-dependencies)
4148         header article)
4149     (save-excursion
4150       (set-buffer nntp-server-buffer)
4151       (let ((case-fold-search nil))
4152         (goto-char (point-min))
4153         (while (not (eobp))
4154           (ignore-errors
4155             (setq article (read (current-buffer))
4156                   header (gnus-nov-parse-line article dependencies)))
4157           (when header
4158             (with-current-buffer gnus-summary-buffer
4159               (push header gnus-newsgroup-headers)
4160               (if (memq (setq article (mail-header-number header))
4161                         gnus-newsgroup-unselected)
4162                   (progn
4163                     (setq gnus-newsgroup-unreads
4164                           (gnus-add-to-sorted-list
4165                            gnus-newsgroup-unreads article))
4166                     (setq gnus-newsgroup-unselected
4167                           (delq article gnus-newsgroup-unselected)))
4168                 (push article gnus-newsgroup-ancient)))
4169             (forward-line 1)))))))
4170
4171 (defun gnus-summary-update-article-line (article header)
4172   "Update the line for ARTICLE using HEADER."
4173   (let* ((id (mail-header-id header))
4174          (thread (gnus-id-to-thread id)))
4175     (unless thread
4176       (error "Article in no thread"))
4177     ;; Update the thread.
4178     (setcar thread header)
4179     (gnus-summary-goto-subject article)
4180     (let* ((datal (gnus-data-find-list article))
4181            (data (car datal))
4182            (buffer-read-only nil)
4183            (level (gnus-summary-thread-level)))
4184       (gnus-delete-line)
4185       (let ((inserted (- (point)
4186                          (progn
4187                            (gnus-summary-insert-line
4188                             header level nil
4189                             (memq article gnus-newsgroup-undownloaded)
4190                             (gnus-article-mark article)
4191                             (memq article gnus-newsgroup-replied)
4192                             (memq article gnus-newsgroup-expirable)
4193                             ;; Only insert the Subject string when it's different
4194                             ;; from the previous Subject string.
4195                             (if (and
4196                                  gnus-show-threads
4197                                  (gnus-subject-equal
4198                                   (condition-case ()
4199                                       (mail-header-subject
4200                                        (gnus-data-header
4201                                         (cadr
4202                                          (gnus-data-find-list
4203                                           article
4204                                           (gnus-data-list t)))))
4205                                     ;; Error on the side of excessive subjects.
4206                                     (error ""))
4207                                   (mail-header-subject header)))
4208                                 ""
4209                               (mail-header-subject header))
4210                             nil (cdr (assq article gnus-newsgroup-scored))
4211                             (memq article gnus-newsgroup-processable))
4212                            (point)))))
4213         (when (cdr datal)
4214           (gnus-data-update-list
4215            (cdr datal)
4216            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4217
4218 (defun gnus-summary-update-article (article &optional iheader)
4219   "Update ARTICLE in the summary buffer."
4220   (set-buffer gnus-summary-buffer)
4221   (let* ((header (gnus-summary-article-header article))
4222          (id (mail-header-id header))
4223          (data (gnus-data-find article))
4224          (thread (gnus-id-to-thread id))
4225          (references (mail-header-references header))
4226          (parent
4227           (gnus-id-to-thread
4228            (or (gnus-parent-id
4229                 (when (and references
4230                            (not (equal "" references)))
4231                   references))
4232                "none")))
4233          (buffer-read-only nil)
4234          (old (car thread)))
4235     (when thread
4236       (unless iheader
4237         (setcar thread nil)
4238         (when parent
4239           (delq thread parent)))
4240       (if (gnus-summary-insert-subject id header)
4241           ;; Set the (possibly) new article number in the data structure.
4242           (gnus-data-set-number data (gnus-id-to-article id))
4243         (setcar thread old)
4244         nil))))
4245
4246 (defun gnus-rebuild-thread (id &optional line)
4247   "Rebuild the thread containing ID.
4248 If LINE, insert the rebuilt thread starting on line LINE."
4249   (let ((buffer-read-only nil)
4250         old-pos current thread data)
4251     (if (not gnus-show-threads)
4252         (setq thread (list (car (gnus-id-to-thread id))))
4253       ;; Get the thread this article is part of.
4254       (setq thread (gnus-remove-thread id)))
4255     (setq old-pos (point-at-bol))
4256     (setq current (save-excursion
4257                     (and (re-search-backward "[\r\n]" nil t)
4258                          (gnus-summary-article-number))))
4259     ;; If this is a gathered thread, we have to go some re-gathering.
4260     (when (stringp (car thread))
4261       (let ((subject (car thread))
4262             roots thr)
4263         (setq thread (cdr thread))
4264         (while thread
4265           (unless (memq (setq thr (gnus-id-to-thread
4266                                    (gnus-root-id
4267                                     (mail-header-id (caar thread)))))
4268                         roots)
4269             (push thr roots))
4270           (setq thread (cdr thread)))
4271         ;; We now have all (unique) roots.
4272         (if (= (length roots) 1)
4273             ;; All the loose roots are now one solid root.
4274             (setq thread (car roots))
4275           (setq thread (cons subject (gnus-sort-threads roots))))))
4276     (let (threads)
4277       ;; We then insert this thread into the summary buffer.
4278       (when line
4279         (goto-char (point-min))
4280         (forward-line (1- line)))
4281       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4282         (if gnus-show-threads
4283             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4284           (gnus-summary-prepare-unthreaded thread))
4285         (setq data (nreverse gnus-newsgroup-data))
4286         (setq threads gnus-newsgroup-threads))
4287       ;; We splice the new data into the data structure.
4288       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4289       ;;!!! then we want to insert at the beginning of the buffer.
4290       ;;!!! That happens to be true with Gnus now, but that may
4291       ;;!!! change in the future.  Perhaps.
4292       (gnus-data-enter-list
4293        (if line nil current) data (- (point) old-pos))
4294       (setq gnus-newsgroup-threads
4295             (nconc threads gnus-newsgroup-threads))
4296       (gnus-data-compute-positions))))
4297
4298 (defun gnus-number-to-header (number)
4299   "Return the header for article NUMBER."
4300   (let ((headers gnus-newsgroup-headers))
4301     (while (and headers
4302                 (not (= number (mail-header-number (car headers)))))
4303       (pop headers))
4304     (when headers
4305       (car headers))))
4306
4307 (defun gnus-parent-headers (in-headers &optional generation)
4308   "Return the headers of the GENERATIONeth parent of HEADERS."
4309   (unless generation
4310     (setq generation 1))
4311   (let ((parent t)
4312         (headers in-headers)
4313         references)
4314     (while (and parent
4315                 (not (zerop generation))
4316                 (setq references (mail-header-references headers)))
4317       (setq headers (if (and references
4318                              (setq parent (gnus-parent-id references)))
4319                         (car (gnus-id-to-thread parent))
4320                       nil))
4321       (decf generation))
4322     (and (not (eq headers in-headers))
4323          headers)))
4324
4325 (defun gnus-id-to-thread (id)
4326   "Return the (sub-)thread where ID appears."
4327   (gnus-gethash id gnus-newsgroup-dependencies))
4328
4329 (defun gnus-id-to-article (id)
4330   "Return the article number of ID."
4331   (let ((thread (gnus-id-to-thread id)))
4332     (when (and thread
4333                (car thread))
4334       (mail-header-number (car thread)))))
4335
4336 (defun gnus-id-to-header (id)
4337   "Return the article headers of ID."
4338   (car (gnus-id-to-thread id)))
4339
4340 (defun gnus-article-displayed-root-p (article)
4341   "Say whether ARTICLE is a root(ish) article."
4342   (let ((level (gnus-summary-thread-level article))
4343         (refs (mail-header-references  (gnus-summary-article-header article)))
4344         particle)
4345     (cond
4346      ((null level) nil)
4347      ((zerop level) t)
4348      ((null refs) t)
4349      ((null (gnus-parent-id refs)) t)
4350      ((and (= 1 level)
4351            (null (setq particle (gnus-id-to-article
4352                                  (gnus-parent-id refs))))
4353            (null (gnus-summary-thread-level particle)))))))
4354
4355 (defun gnus-root-id (id)
4356   "Return the id of the root of the thread where ID appears."
4357   (let (last-id prev)
4358     (while (and id (setq prev (car (gnus-id-to-thread id))))
4359       (setq last-id id
4360             id (gnus-parent-id (mail-header-references prev))))
4361     last-id))
4362
4363 (defun gnus-articles-in-thread (thread)
4364   "Return the list of articles in THREAD."
4365   (cons (mail-header-number (car thread))
4366         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4367
4368 (defun gnus-remove-thread (id &optional dont-remove)
4369   "Remove the thread that has ID in it."
4370   (let (headers thread last-id)
4371     ;; First go up in this thread until we find the root.
4372     (setq last-id (gnus-root-id id)
4373           headers (message-flatten-list (gnus-id-to-thread last-id)))
4374     ;; We have now found the real root of this thread.  It might have
4375     ;; been gathered into some loose thread, so we have to search
4376     ;; through the threads to find the thread we wanted.
4377     (let ((threads gnus-newsgroup-threads)
4378           sub)
4379       (while threads
4380         (setq sub (car threads))
4381         (if (stringp (car sub))
4382             ;; This is a gathered thread, so we look at the roots
4383             ;; below it to find whether this article is in this
4384             ;; gathered root.
4385             (progn
4386               (setq sub (cdr sub))
4387               (while sub
4388                 (when (member (caar sub) headers)
4389                   (setq thread (car threads)
4390                         threads nil
4391                         sub nil))
4392                 (setq sub (cdr sub))))
4393           ;; It's an ordinary thread, so we check it.
4394           (when (eq (car sub) (car headers))
4395             (setq thread sub
4396                   threads nil)))
4397         (setq threads (cdr threads)))
4398       ;; If this article is in no thread, then it's a root.
4399       (if thread
4400           (unless dont-remove
4401             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4402         (setq thread (gnus-id-to-thread last-id)))
4403       (when thread
4404         (prog1
4405             thread                      ; We return this thread.
4406           (unless dont-remove
4407             (if (stringp (car thread))
4408                 (progn
4409                   ;; If we use dummy roots, then we have to remove the
4410                   ;; dummy root as well.
4411                   (when (eq gnus-summary-make-false-root 'dummy)
4412                     ;; We go to the dummy root by going to
4413                     ;; the first sub-"thread", and then one line up.
4414                     (gnus-summary-goto-article
4415                      (mail-header-number (caadr thread)))
4416                     (forward-line -1)
4417                     (gnus-delete-line)
4418                     (gnus-data-compute-positions))
4419                   (setq thread (cdr thread))
4420                   (while thread
4421                     (gnus-remove-thread-1 (car thread))
4422                     (setq thread (cdr thread))))
4423               (gnus-remove-thread-1 thread))))))))
4424
4425 (defun gnus-remove-thread-1 (thread)
4426   "Remove the thread THREAD recursively."
4427   (let ((number (mail-header-number (pop thread)))
4428         d)
4429     (setq thread (reverse thread))
4430     (while thread
4431       (gnus-remove-thread-1 (pop thread)))
4432     (when (setq d (gnus-data-find number))
4433       (goto-char (gnus-data-pos d))
4434       (gnus-summary-show-thread)
4435       (gnus-data-remove
4436        number
4437        (- (point-at-bol)
4438           (prog1
4439               (1+ (point-at-eol))
4440             (gnus-delete-line)))))))
4441
4442 (defun gnus-sort-threads-1 (threads func)
4443   (sort (mapcar (lambda (thread)
4444                   (cons (car thread)
4445                         (and (cdr thread)
4446                              (gnus-sort-threads-1 (cdr thread) func))))
4447                 threads) func))
4448
4449 (defun gnus-sort-threads (threads)
4450   "Sort THREADS."
4451   (if (not gnus-thread-sort-functions)
4452       threads
4453     (gnus-message 8 "Sorting threads...")
4454     (let ((max-lisp-eval-depth 5000))
4455       (prog1 (gnus-sort-threads-1
4456          threads
4457          (gnus-make-sort-function gnus-thread-sort-functions))
4458         (gnus-message 8 "Sorting threads...done")))))
4459
4460 (defun gnus-sort-articles (articles)
4461   "Sort ARTICLES."
4462   (when gnus-article-sort-functions
4463     (gnus-message 7 "Sorting articles...")
4464     (prog1
4465         (setq gnus-newsgroup-headers
4466               (sort articles (gnus-make-sort-function
4467                               gnus-article-sort-functions)))
4468       (gnus-message 7 "Sorting articles...done"))))
4469
4470 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4471 (defmacro gnus-thread-header (thread)
4472   "Return header of first article in THREAD.
4473 Note that THREAD must never, ever be anything else than a variable -
4474 using some other form will lead to serious barfage."
4475   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4476   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4477   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4478         (vector thread) 2))
4479
4480 (defsubst gnus-article-sort-by-number (h1 h2)
4481   "Sort articles by article number."
4482   (< (mail-header-number h1)
4483      (mail-header-number h2)))
4484
4485 (defun gnus-thread-sort-by-number (h1 h2)
4486   "Sort threads by root article number."
4487   (gnus-article-sort-by-number
4488    (gnus-thread-header h1) (gnus-thread-header h2)))
4489
4490 (defsubst gnus-article-sort-by-random (h1 h2)
4491   "Sort articles by article number."
4492   (zerop (random 2)))
4493
4494 (defun gnus-thread-sort-by-random (h1 h2)
4495   "Sort threads by root article number."
4496   (gnus-article-sort-by-random
4497    (gnus-thread-header h1) (gnus-thread-header h2)))
4498
4499 (defsubst gnus-article-sort-by-lines (h1 h2)
4500   "Sort articles by article Lines header."
4501   (< (mail-header-lines h1)
4502      (mail-header-lines h2)))
4503
4504 (defun gnus-thread-sort-by-lines (h1 h2)
4505   "Sort threads by root article Lines header."
4506   (gnus-article-sort-by-lines
4507    (gnus-thread-header h1) (gnus-thread-header h2)))
4508
4509 (defsubst gnus-article-sort-by-chars (h1 h2)
4510   "Sort articles by octet length."
4511   (< (mail-header-chars h1)
4512      (mail-header-chars h2)))
4513
4514 (defun gnus-thread-sort-by-chars (h1 h2)
4515   "Sort threads by root article octet length."
4516   (gnus-article-sort-by-chars
4517    (gnus-thread-header h1) (gnus-thread-header h2)))
4518
4519 (defsubst gnus-article-sort-by-author (h1 h2)
4520   "Sort articles by root author."
4521   (string-lessp
4522    (let ((addr (car (mime-entity-read-field h1 'From))))
4523      (or (std11-full-name-string addr)
4524          (std11-address-string addr)
4525          ""))
4526    (let ((addr (car (mime-entity-read-field h2 'From))))
4527      (or (std11-full-name-string addr)
4528          (std11-address-string addr)
4529          ""))
4530    ))
4531
4532 (defun gnus-thread-sort-by-author (h1 h2)
4533   "Sort threads by root author."
4534   (gnus-article-sort-by-author
4535    (gnus-thread-header h1)  (gnus-thread-header h2)))
4536
4537 (defsubst gnus-article-sort-by-subject (h1 h2)
4538   "Sort articles by root subject."
4539   (string-lessp
4540    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4541    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4542
4543 (defun gnus-thread-sort-by-subject (h1 h2)
4544   "Sort threads by root subject."
4545   (gnus-article-sort-by-subject
4546    (gnus-thread-header h1) (gnus-thread-header h2)))
4547
4548 (defsubst gnus-article-sort-by-date (h1 h2)
4549   "Sort articles by root article date."
4550   (time-less-p
4551    (gnus-date-get-time (mail-header-date h1))
4552    (gnus-date-get-time (mail-header-date h2))))
4553
4554 (defun gnus-thread-sort-by-date (h1 h2)
4555   "Sort threads by root article date."
4556   (gnus-article-sort-by-date
4557    (gnus-thread-header h1) (gnus-thread-header h2)))
4558
4559 (defsubst gnus-article-sort-by-score (h1 h2)
4560   "Sort articles by root article score.
4561 Unscored articles will be counted as having a score of zero."
4562   (> (or (cdr (assq (mail-header-number h1)
4563                     gnus-newsgroup-scored))
4564          gnus-summary-default-score 0)
4565      (or (cdr (assq (mail-header-number h2)
4566                     gnus-newsgroup-scored))
4567          gnus-summary-default-score 0)))
4568
4569 (defun gnus-thread-sort-by-score (h1 h2)
4570   "Sort threads by root article score."
4571   (gnus-article-sort-by-score
4572    (gnus-thread-header h1) (gnus-thread-header h2)))
4573
4574 (defun gnus-thread-sort-by-total-score (h1 h2)
4575   "Sort threads by the sum of all scores in the thread.
4576 Unscored articles will be counted as having a score of zero."
4577   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4578
4579 (defun gnus-thread-total-score (thread)
4580   ;; This function find the total score of THREAD.
4581   (cond
4582    ((null thread)
4583     0)
4584    ((consp thread)
4585     (if (stringp (car thread))
4586         (apply gnus-thread-score-function 0
4587                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4588       (gnus-thread-total-score-1 thread)))
4589    (t
4590     (gnus-thread-total-score-1 (list thread)))))
4591
4592 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4593   "Sort threads such that the thread with the most recently arrived article comes first."
4594   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4595
4596 (defun gnus-thread-highest-number (thread)
4597   "Return the highest article number in THREAD."
4598   (apply 'max (mapcar (lambda (header)
4599                         (mail-header-number header))
4600                       (message-flatten-list thread))))
4601
4602 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4603   "Sort threads such that the thread with the most recently dated article comes first."
4604   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4605
4606 (defun gnus-thread-latest-date (thread)
4607   "Return the highest article date in THREAD."
4608   (let ((previous-time 0))
4609     (apply 'max
4610            (mapcar
4611             (lambda (header)
4612               (setq previous-time
4613                     (condition-case ()
4614                         (time-to-seconds (mail-header-parse-date
4615                                           (mail-header-date header)))
4616                       (error previous-time))))
4617             (sort
4618              (message-flatten-list thread)
4619              (lambda (h1 h2)
4620                (< (mail-header-number h1)
4621                   (mail-header-number h2))))))))
4622
4623 (defun gnus-thread-total-score-1 (root)
4624   ;; This function find the total score of the thread below ROOT.
4625   (setq root (car root))
4626   (apply gnus-thread-score-function
4627          (or (append
4628               (mapcar 'gnus-thread-total-score
4629                       (cdr (gnus-id-to-thread (mail-header-id root))))
4630               (when (> (mail-header-number root) 0)
4631                 (list (or (cdr (assq (mail-header-number root)
4632                                      gnus-newsgroup-scored))
4633                           gnus-summary-default-score 0))))
4634              (list gnus-summary-default-score)
4635              '(0))))
4636
4637 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4638 (defvar gnus-tmp-prev-subject nil)
4639 (defvar gnus-tmp-false-parent nil)
4640 (defvar gnus-tmp-root-expunged nil)
4641 (defvar gnus-tmp-dummy-line nil)
4642
4643 (eval-when-compile (defvar gnus-tmp-header))
4644 (defun gnus-extra-header (type &optional header)
4645   "Return the extra header of TYPE."
4646   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4647       ""))
4648
4649 (defvar gnus-tmp-thread-tree-header-string "")
4650
4651 (defcustom gnus-sum-thread-tree-root "> "
4652   "With %B spec, used for the root of a thread.
4653 If nil, use subject instead."
4654   :version "21.4"
4655   :type '(radio (const :format "%v  " nil) (string :size 0))
4656   :group 'gnus-thread)
4657 (defcustom gnus-sum-thread-tree-false-root "> "
4658   "With %B spec, used for a false root of a thread.
4659 If nil, use subject instead."
4660   :version "21.4"
4661   :type '(radio (const :format "%v  " nil) (string :size 0))
4662   :group 'gnus-thread)
4663 (defcustom gnus-sum-thread-tree-single-indent ""
4664   "With %B spec, used for a thread with just one message.
4665 If nil, use subject instead."
4666   :version "21.4"
4667   :type '(radio (const :format "%v  " nil) (string :size 0))
4668   :group 'gnus-thread)
4669 (defcustom gnus-sum-thread-tree-vertical "| "
4670   "With %B spec, used for drawing a vertical line."
4671   :version "21.4"
4672   :type 'string
4673   :group 'gnus-thread)
4674 (defcustom gnus-sum-thread-tree-indent "  "
4675   "With %B spec, used for indenting."
4676   :version "21.4"
4677   :type 'string
4678   :group 'gnus-thread)
4679 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4680   "With %B spec, used for a leaf with brothers."
4681   :version "21.4"
4682   :type 'string
4683   :group 'gnus-thread)
4684 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4685   "With %B spec, used for a leaf without brothers."
4686   :version "21.4"
4687   :type 'string
4688   :group 'gnus-thread)
4689
4690 (defun gnus-summary-prepare-threads (threads)
4691   "Prepare summary buffer from THREADS and indentation LEVEL.
4692 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4693 or a straight list of headers."
4694   (gnus-message 7 "Generating summary...")
4695
4696   (setq gnus-newsgroup-threads threads)
4697   (beginning-of-line)
4698
4699   (let ((gnus-tmp-level 0)
4700         (default-score (or gnus-summary-default-score 0))
4701         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4702         (building-line-count gnus-summary-display-while-building)
4703         (building-count (integerp gnus-summary-display-while-building))
4704         thread number subject stack state gnus-tmp-gathered beg-match
4705         new-roots gnus-tmp-new-adopts thread-end simp-subject
4706         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4707         gnus-tmp-replied gnus-tmp-subject-or-nil
4708         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4709         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4710         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4711         tree-stack)
4712
4713     (setq gnus-tmp-prev-subject nil
4714           gnus-tmp-thread-tree-header-string "")
4715
4716     (if (vectorp (car threads))
4717         ;; If this is a straight (sic) list of headers, then a
4718         ;; threaded summary display isn't required, so we just create
4719         ;; an unthreaded one.
4720         (gnus-summary-prepare-unthreaded threads)
4721
4722       ;; Do the threaded display.
4723
4724       (if gnus-summary-display-while-building
4725           (switch-to-buffer (buffer-name)))
4726       (while (or threads stack gnus-tmp-new-adopts new-roots)
4727
4728         (if (and (= gnus-tmp-level 0)
4729                  (or (not stack)
4730                      (= (caar stack) 0))
4731                  (not gnus-tmp-false-parent)
4732                  (or gnus-tmp-new-adopts new-roots))
4733             (if gnus-tmp-new-adopts
4734                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4735                       thread (list (car gnus-tmp-new-adopts))
4736                       gnus-tmp-header (caar thread)
4737                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4738               (when new-roots
4739                 (setq thread (list (car new-roots))
4740                       gnus-tmp-header (caar thread)
4741                       new-roots (cdr new-roots))))
4742
4743           (if threads
4744               ;; If there are some threads, we do them before the
4745               ;; threads on the stack.
4746               (setq thread threads
4747                     gnus-tmp-header (caar thread))
4748             ;; There were no current threads, so we pop something off
4749             ;; the stack.
4750             (setq state (car stack)
4751                   gnus-tmp-level (car state)
4752                   tree-stack (cadr state)
4753                   thread (caddr state)
4754                   stack (cdr stack)
4755                   gnus-tmp-header (caar thread))))
4756
4757         (setq gnus-tmp-false-parent nil)
4758         (setq gnus-tmp-root-expunged nil)
4759         (setq thread-end nil)
4760
4761         (if (stringp gnus-tmp-header)
4762             ;; The header is a dummy root.
4763             (cond
4764              ((eq gnus-summary-make-false-root 'adopt)
4765               ;; We let the first article adopt the rest.
4766               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4767                                                (cddar thread)))
4768               (setq gnus-tmp-gathered
4769                     (nconc (mapcar
4770                             (lambda (h) (mail-header-number (car h)))
4771                             (cddar thread))
4772                            gnus-tmp-gathered))
4773               (setq thread (cons (list (caar thread)
4774                                        (cadar thread))
4775                                  (cdr thread)))
4776               (setq gnus-tmp-level -1
4777                     gnus-tmp-false-parent t))
4778              ((eq gnus-summary-make-false-root 'empty)
4779               ;; We print adopted articles with empty subject fields.
4780               (setq gnus-tmp-gathered
4781                     (nconc (mapcar
4782                             (lambda (h) (mail-header-number (car h)))
4783                             (cddar thread))
4784                            gnus-tmp-gathered))
4785               (setq gnus-tmp-level -1))
4786              ((eq gnus-summary-make-false-root 'dummy)
4787               ;; We remember that we probably want to output a dummy
4788               ;; root.
4789               (setq gnus-tmp-dummy-line gnus-tmp-header)
4790               (setq gnus-tmp-prev-subject gnus-tmp-header))
4791              (t
4792               ;; We do not make a root for the gathered
4793               ;; sub-threads at all.
4794               (setq gnus-tmp-level -1)))
4795
4796           (setq number (mail-header-number gnus-tmp-header)
4797                 subject (mail-header-subject gnus-tmp-header)
4798                 simp-subject (gnus-simplify-subject-fully subject))
4799
4800           (cond
4801            ;; If the thread has changed subject, we might want to make
4802            ;; this subthread into a root.
4803            ((and (null gnus-thread-ignore-subject)
4804                  (not (zerop gnus-tmp-level))
4805                  gnus-tmp-prev-subject
4806                  (not (string= gnus-tmp-prev-subject simp-subject)))
4807             (setq new-roots (nconc new-roots (list (car thread)))
4808                   thread-end t
4809                   gnus-tmp-header nil))
4810            ;; If the article lies outside the current limit,
4811            ;; then we do not display it.
4812            ((not (memq number gnus-newsgroup-limit))
4813             (setq gnus-tmp-gathered
4814                   (nconc (mapcar
4815                           (lambda (h) (mail-header-number (car h)))
4816                           (cdar thread))
4817                          gnus-tmp-gathered))
4818             (setq gnus-tmp-new-adopts (if (cdar thread)
4819                                           (append gnus-tmp-new-adopts
4820                                                   (cdar thread))
4821                                         gnus-tmp-new-adopts)
4822                   thread-end t
4823                   gnus-tmp-header nil)
4824             (when (zerop gnus-tmp-level)
4825               (setq gnus-tmp-root-expunged t)))
4826            ;; Perhaps this article is to be marked as read?
4827            ((and gnus-summary-mark-below
4828                  (< (or (cdr (assq number gnus-newsgroup-scored))
4829                         default-score)
4830                     gnus-summary-mark-below)
4831                  ;; Don't touch sparse articles.
4832                  (not (gnus-summary-article-sparse-p number))
4833                  (not (gnus-summary-article-ancient-p number)))
4834             (setq gnus-newsgroup-unreads
4835                   (delq number gnus-newsgroup-unreads))
4836             (if gnus-newsgroup-auto-expire
4837                 (setq gnus-newsgroup-expirable
4838                       (gnus-add-to-sorted-list
4839                        gnus-newsgroup-expirable number))
4840               (push (cons number gnus-low-score-mark)
4841                     gnus-newsgroup-reads))))
4842
4843           (when gnus-tmp-header
4844             ;; We may have an old dummy line to output before this
4845             ;; article.
4846             (when (and gnus-tmp-dummy-line
4847                        (gnus-subject-equal
4848                         gnus-tmp-dummy-line
4849                         (mail-header-subject gnus-tmp-header)))
4850               (gnus-summary-insert-dummy-line
4851                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4852               (setq gnus-tmp-dummy-line nil))
4853
4854             ;; Compute the mark.
4855             (setq gnus-tmp-unread (gnus-article-mark number))
4856
4857             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4858                                   gnus-tmp-header gnus-tmp-level)
4859                   gnus-newsgroup-data)
4860
4861             ;; Actually insert the line.
4862             (setq
4863              gnus-tmp-subject-or-nil
4864              (cond
4865               ((and gnus-thread-ignore-subject
4866                     gnus-tmp-prev-subject
4867                     (not (string= gnus-tmp-prev-subject simp-subject)))
4868                subject)
4869               ((zerop gnus-tmp-level)
4870                (if (and (eq gnus-summary-make-false-root 'empty)
4871                         (memq number gnus-tmp-gathered)
4872                         gnus-tmp-prev-subject
4873                         (string= gnus-tmp-prev-subject simp-subject))
4874                    gnus-summary-same-subject
4875                  subject))
4876               (t gnus-summary-same-subject)))
4877             (if (and (eq gnus-summary-make-false-root 'adopt)
4878                      (= gnus-tmp-level 1)
4879                      (memq number gnus-tmp-gathered))
4880                 (setq gnus-tmp-opening-bracket ?\<
4881                       gnus-tmp-closing-bracket ?\>)
4882               (setq gnus-tmp-opening-bracket ?\[
4883                     gnus-tmp-closing-bracket ?\]))
4884             (setq
4885              gnus-tmp-indentation
4886              (aref gnus-thread-indent-array gnus-tmp-level)
4887              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4888              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4889                                 gnus-summary-default-score 0)
4890              gnus-tmp-score-char
4891              (if (or (null gnus-summary-default-score)
4892                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4893                          gnus-summary-zcore-fuzz))
4894                  ?\ ;;;Whitespace
4895                (if (< gnus-tmp-score gnus-summary-default-score)
4896                    gnus-score-below-mark gnus-score-over-mark))
4897              gnus-tmp-replied
4898              (cond ((memq number gnus-newsgroup-processable)
4899                     gnus-process-mark)
4900                    ((memq number gnus-newsgroup-cached)
4901                     gnus-cached-mark)
4902                    ((memq number gnus-newsgroup-replied)
4903                     gnus-replied-mark)
4904                    ((memq number gnus-newsgroup-forwarded)
4905                     gnus-forwarded-mark)
4906                    ((memq number gnus-newsgroup-saved)
4907                     gnus-saved-mark)
4908                    ((memq number gnus-newsgroup-recent)
4909                     gnus-recent-mark)
4910                    ((memq number gnus-newsgroup-unseen)
4911                     gnus-unseen-mark)
4912                    (t gnus-no-mark))
4913              gnus-tmp-downloaded
4914              (cond ((memq number gnus-newsgroup-undownloaded)
4915                     gnus-undownloaded-mark)
4916                    (gnus-newsgroup-agentized
4917                     gnus-downloaded-mark)
4918                    (t
4919                     gnus-no-mark))
4920              gnus-tmp-from (mail-header-from gnus-tmp-header)
4921              gnus-tmp-name
4922              (cond
4923               ((string-match "<[^>]+> *$" gnus-tmp-from)
4924                (setq beg-match (match-beginning 0))
4925                (or (and (string-match "^\".+\"" gnus-tmp-from)
4926                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4927                    (substring gnus-tmp-from 0 beg-match)))
4928               ((string-match "(.+)" gnus-tmp-from)
4929                (substring gnus-tmp-from
4930                           (1+ (match-beginning 0)) (1- (match-end 0))))
4931               (t gnus-tmp-from))
4932
4933              ;; Do the %B string
4934              gnus-tmp-thread-tree-header-string
4935              (cond
4936               ((not gnus-show-threads) "")
4937               ((zerop gnus-tmp-level)
4938                (cond ((cdar thread)
4939                       (or gnus-sum-thread-tree-root subject))
4940                      (gnus-tmp-new-adopts
4941                       (or gnus-sum-thread-tree-false-root subject))
4942                      (t
4943                       (or gnus-sum-thread-tree-single-indent subject))))
4944               (t
4945                (concat (apply 'concat
4946                               (mapcar (lambda (item)
4947                                         (if (= item 1)
4948                                             gnus-sum-thread-tree-vertical
4949                                           gnus-sum-thread-tree-indent))
4950                                       (cdr (reverse tree-stack))))
4951                        (if (nth 1 thread)
4952                            gnus-sum-thread-tree-leaf-with-other
4953                          gnus-sum-thread-tree-single-leaf)))))
4954             (when (string= gnus-tmp-name "")
4955               (setq gnus-tmp-name gnus-tmp-from))
4956             (unless (numberp gnus-tmp-lines)
4957               (setq gnus-tmp-lines -1))
4958             (if (= gnus-tmp-lines -1)
4959                 (setq gnus-tmp-lines "?")
4960               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4961               (gnus-put-text-property
4962              (point)
4963              (progn (eval gnus-summary-line-format-spec) (point))
4964                'gnus-number number)
4965             (when gnus-visual-p
4966               (forward-line -1)
4967               (gnus-run-hooks 'gnus-summary-update-hook)
4968               (forward-line 1))
4969
4970             (setq gnus-tmp-prev-subject simp-subject)))
4971
4972         (when (nth 1 thread)
4973           (push (list (max 0 gnus-tmp-level)
4974                       (copy-sequence tree-stack)
4975                       (nthcdr 1 thread))
4976                 stack))
4977         (push (if (nth 1 thread) 1 0) tree-stack)
4978         (incf gnus-tmp-level)
4979         (setq threads (if thread-end nil (cdar thread)))
4980         (if gnus-summary-display-while-building
4981             (if building-count
4982                 (progn
4983                   ;; use a set frequency
4984                   (setq building-line-count (1- building-line-count))
4985                   (when (= building-line-count 0)
4986                     (sit-for 0)
4987                     (setq building-line-count
4988                           gnus-summary-display-while-building)))
4989               ;; always
4990               (sit-for 0)))
4991         (unless threads
4992           (setq gnus-tmp-level 0)))))
4993   (gnus-message 7 "Generating summary...done"))
4994
4995 (defun gnus-summary-prepare-unthreaded (headers)
4996   "Generate an unthreaded summary buffer based on HEADERS."
4997   (let (header number mark)
4998
4999     (beginning-of-line)
5000
5001     (while headers
5002       ;; We may have to root out some bad articles...
5003       (when (memq (setq number (mail-header-number
5004                                 (setq header (pop headers))))
5005                   gnus-newsgroup-limit)
5006         ;; Mark article as read when it has a low score.
5007         (when (and gnus-summary-mark-below
5008                    (< (or (cdr (assq number gnus-newsgroup-scored))
5009                           gnus-summary-default-score 0)
5010                       gnus-summary-mark-below)
5011                    (not (gnus-summary-article-ancient-p number)))
5012           (setq gnus-newsgroup-unreads
5013                 (delq number gnus-newsgroup-unreads))
5014           (if gnus-newsgroup-auto-expire
5015               (push number gnus-newsgroup-expirable)
5016             (push (cons number gnus-low-score-mark)
5017                   gnus-newsgroup-reads)))
5018
5019         (setq mark (gnus-article-mark number))
5020         (push (gnus-data-make number mark (1+ (point)) header 0)
5021               gnus-newsgroup-data)
5022         (gnus-summary-insert-line
5023          header 0 number
5024          (memq number gnus-newsgroup-undownloaded)
5025          mark (memq number gnus-newsgroup-replied)
5026          (memq number gnus-newsgroup-expirable)
5027          (mail-header-subject header) nil
5028          (cdr (assq number gnus-newsgroup-scored))
5029          (memq number gnus-newsgroup-processable))))))
5030
5031 (defun gnus-summary-remove-list-identifiers ()
5032   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5033   (let ((regexp (if (consp gnus-list-identifiers)
5034                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5035                   gnus-list-identifiers))
5036         changed subject)
5037     (when regexp
5038       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5039       (dolist (header gnus-newsgroup-headers)
5040         (setq subject (mail-header-subject header)
5041               changed nil)
5042         (while (string-match regexp subject)
5043           (setq subject
5044                 (concat (substring subject 0 (match-beginning 1))
5045                         (substring subject (match-end 0)))
5046                 changed t))
5047         (when changed
5048           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5049             (setq subject
5050                   (concat (substring subject 0 (match-beginning 1))
5051                           (substring subject (match-end 1)))))
5052           (mail-header-set-subject header subject))))))
5053
5054 (defun gnus-fetch-headers (articles)
5055   "Fetch headers of ARTICLES."
5056   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5057     (gnus-message 5 "Fetching headers for %s..." name)
5058     (prog1
5059         (if (eq 'nov
5060                 (setq gnus-headers-retrieved-by
5061                       (gnus-retrieve-headers
5062                        articles gnus-newsgroup-name
5063                        ;; We might want to fetch old headers, but
5064                        ;; not if there is only 1 article.
5065                        (and (or (and
5066                                  (not (eq gnus-fetch-old-headers 'some))
5067                                  (not (numberp gnus-fetch-old-headers)))
5068                                 (> (length articles) 1))
5069                             gnus-fetch-old-headers))))
5070             (gnus-get-newsgroup-headers-xover
5071              articles nil nil gnus-newsgroup-name t)
5072           (gnus-get-newsgroup-headers))
5073       (gnus-message 5 "Fetching headers for %s...done" name))))
5074
5075 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5076   "Select newsgroup GROUP.
5077 If READ-ALL is non-nil, all articles in the group are selected.
5078 If SELECT-ARTICLES, only select those articles from GROUP."
5079   (let* ((entry (gnus-group-entry group))
5080          ;;!!! Dirty hack; should be removed.
5081          (gnus-summary-ignore-duplicates
5082           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5083               t
5084             gnus-summary-ignore-duplicates))
5085          (info (nth 2 entry))
5086          articles fetched-articles cached)
5087
5088     (unless (gnus-check-server
5089              (set (make-local-variable 'gnus-current-select-method)
5090                   (gnus-find-method-for-group group)))
5091       (error "Couldn't open server"))
5092
5093     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5094         (gnus-activate-group group)     ; Or we can activate it...
5095         (progn                          ; Or we bug out.
5096           (when (equal major-mode 'gnus-summary-mode)
5097             (gnus-kill-buffer (current-buffer)))
5098           (error "Couldn't activate group %s: %s"
5099                  group (gnus-status-message group))))
5100
5101     (unless (gnus-request-group group t)
5102       (when (equal major-mode 'gnus-summary-mode)
5103         (gnus-kill-buffer (current-buffer)))
5104       (error "Couldn't request group %s: %s"
5105              group (gnus-status-message group)))
5106
5107     (when gnus-agent
5108       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5109       
5110       (setq gnus-summary-use-undownloaded-faces
5111             (gnus-agent-find-parameter
5112              group
5113              'agent-enable-undownloaded-faces)))
5114
5115     (setq gnus-newsgroup-name group
5116           gnus-newsgroup-unselected nil
5117           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5118
5119     (let ((display (gnus-group-find-parameter group 'display)))
5120       (setq gnus-newsgroup-display
5121             (cond
5122              ((not (zerop (or (car-safe read-all) 0)))
5123               ;; The user entered the group with C-u SPC/RET, let's show
5124               ;; all articles.
5125               'gnus-not-ignore)
5126              ((eq display 'all)
5127               'gnus-not-ignore)
5128              ((arrayp display)
5129               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5130              ((numberp display)
5131               ;; The following is probably the "correct" solution, but
5132               ;; it makes Gnus fetch all headers and then limit the
5133               ;; articles (which is slow), so instead we hack the
5134               ;; select-articles parameter instead. -- Simon Josefsson
5135               ;; <jas@kth.se>
5136               ;;
5137               ;; (gnus-byte-compile
5138               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5139               ;;                         display)))))
5140               (setq select-articles
5141                     (gnus-uncompress-range
5142                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5143                              (if (> tmp 0)
5144                                  tmp
5145                                1))
5146                            (cdr (gnus-active group)))))
5147               nil)
5148              (t
5149               nil))))
5150
5151     (gnus-summary-setup-default-charset)
5152
5153     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5154     (when (gnus-virtual-group-p group)
5155       (setq cached gnus-newsgroup-cached))
5156
5157     (setq gnus-newsgroup-unreads
5158           (gnus-sorted-ndifference
5159            (gnus-sorted-ndifference gnus-newsgroup-unreads
5160                                     gnus-newsgroup-marked)
5161            gnus-newsgroup-dormant))
5162
5163     (setq gnus-newsgroup-processable nil)
5164
5165     (gnus-update-read-articles group gnus-newsgroup-unreads)
5166
5167     ;; Adjust and set lists of article marks.
5168     (when info
5169       (gnus-adjust-marked-articles info))
5170     (if (setq articles select-articles)
5171         (setq gnus-newsgroup-unselected
5172               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5173       (setq articles (gnus-articles-to-read group read-all)))
5174
5175     (cond
5176      ((null articles)
5177       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5178       'quit)
5179      ((eq articles 0) nil)
5180      (t
5181       ;; Init the dependencies hash table.
5182       (setq gnus-newsgroup-dependencies
5183             (gnus-make-hashtable (length articles)))
5184       (gnus-set-global-variables)
5185       ;; Retrieve the headers and read them in.
5186
5187       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5188
5189       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5190       (when cached
5191         (setq gnus-newsgroup-cached cached))
5192
5193       ;; Suppress duplicates?
5194       (when gnus-suppress-duplicates
5195         (gnus-dup-suppress-articles))
5196
5197       ;; Set the initial limit.
5198       (setq gnus-newsgroup-limit (copy-sequence articles))
5199       ;; Remove canceled articles from the list of unread articles.
5200       (setq fetched-articles
5201             (mapcar (lambda (headers) (mail-header-number headers))
5202                     gnus-newsgroup-headers))
5203       (setq gnus-newsgroup-articles fetched-articles)
5204       (setq gnus-newsgroup-unreads
5205             (gnus-sorted-nintersection
5206              gnus-newsgroup-unreads fetched-articles))
5207       (gnus-compute-unseen-list)
5208
5209       ;; Removed marked articles that do not exist.
5210       (gnus-update-missing-marks
5211        (gnus-sorted-difference articles fetched-articles))
5212       ;; We might want to build some more threads first.
5213       (when (and gnus-fetch-old-headers
5214                  (eq gnus-headers-retrieved-by 'nov))
5215         (if (eq gnus-fetch-old-headers 'invisible)
5216             (gnus-build-all-threads)
5217           (gnus-build-old-threads)))
5218       ;; Let the Gnus agent mark articles as read.
5219       (when gnus-agent
5220         (gnus-agent-get-undownloaded-list))
5221       ;; Remove list identifiers from subject
5222       (when gnus-list-identifiers
5223         (gnus-summary-remove-list-identifiers))
5224       ;; Check whether auto-expire is to be done in this group.
5225       (setq gnus-newsgroup-auto-expire
5226             (gnus-group-auto-expirable-p group))
5227       ;; Set up the article buffer now, if necessary.
5228       (unless gnus-single-article-buffer
5229         (gnus-article-setup-buffer))
5230       ;; First and last article in this newsgroup.
5231       (when gnus-newsgroup-headers
5232         (setq gnus-newsgroup-begin
5233               (mail-header-number (car gnus-newsgroup-headers))
5234               gnus-newsgroup-end
5235               (mail-header-number
5236                (gnus-last-element gnus-newsgroup-headers))))
5237       ;; GROUP is successfully selected.
5238       (or gnus-newsgroup-headers t)))))
5239
5240 (defun gnus-compute-unseen-list ()
5241   ;; The `seen' marks are treated specially.
5242   (if (not gnus-newsgroup-seen)
5243       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5244     (setq gnus-newsgroup-unseen
5245           (gnus-inverse-list-range-intersection
5246            gnus-newsgroup-articles gnus-newsgroup-seen))))
5247
5248 (defun gnus-summary-display-make-predicate (display)
5249   (require 'gnus-agent)
5250   (when (= (length display) 1)
5251     (setq display (car display)))
5252   (unless gnus-summary-display-cache
5253     (dolist (elem (append '((unread . unread)
5254                             (read . read)
5255                             (unseen . unseen))
5256                           gnus-article-mark-lists))
5257       (push (cons (cdr elem)
5258                   (gnus-byte-compile
5259                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5260             gnus-summary-display-cache)))
5261   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5262         (gnus-category-predicate-cache gnus-summary-display-cache))
5263     (gnus-get-predicate display)))
5264
5265 ;; Uses the dynamically bound `number' variable.
5266 (eval-when-compile
5267   (defvar number))
5268 (defun gnus-article-marked-p (type &optional article)
5269   (let ((article (or article number)))
5270     (cond
5271      ((eq type 'tick)
5272       (memq article gnus-newsgroup-marked))
5273      ((eq type 'spam)
5274       (memq article gnus-newsgroup-spam-marked))
5275      ((eq type 'unsend)
5276       (memq article gnus-newsgroup-unsendable))
5277      ((eq type 'undownload)
5278       (memq article gnus-newsgroup-undownloaded))
5279      ((eq type 'download)
5280       (memq article gnus-newsgroup-downloadable))
5281      ((eq type 'unread)
5282       (memq article gnus-newsgroup-unreads))
5283      ((eq type 'read)
5284       (memq article gnus-newsgroup-reads))
5285      ((eq type 'dormant)
5286       (memq article gnus-newsgroup-dormant) )
5287      ((eq type 'expire)
5288       (memq article gnus-newsgroup-expirable))
5289      ((eq type 'reply)
5290       (memq article gnus-newsgroup-replied))
5291      ((eq type 'killed)
5292       (memq article gnus-newsgroup-killed))
5293      ((eq type 'bookmark)
5294       (assq article gnus-newsgroup-bookmarks))
5295      ((eq type 'score)
5296       (assq article gnus-newsgroup-scored))
5297      ((eq type 'save)
5298       (memq article gnus-newsgroup-saved))
5299      ((eq type 'cache)
5300       (memq article gnus-newsgroup-cached))
5301      ((eq type 'forward)
5302       (memq article gnus-newsgroup-forwarded))
5303      ((eq type 'seen)
5304       (not (memq article gnus-newsgroup-unseen)))
5305      ((eq type 'recent)
5306       (memq article gnus-newsgroup-recent))
5307      (t t))))
5308
5309 (defun gnus-articles-to-read (group &optional read-all)
5310   "Find out what articles the user wants to read."
5311   (let* ((articles
5312           ;; Select all articles if `read-all' is non-nil, or if there
5313           ;; are no unread articles.
5314           (if (or read-all
5315                   (and (zerop (length gnus-newsgroup-marked))
5316                        (zerop (length gnus-newsgroup-unreads)))
5317                   ;; Fetch all if the predicate is non-nil.
5318                   gnus-newsgroup-display)
5319               ;; We want to select the headers for all the articles in
5320               ;; the group, so we select either all the active
5321               ;; articles in the group, or (if that's nil), the
5322               ;; articles in the cache.
5323               (or
5324                (gnus-uncompress-range (gnus-active group))
5325                (gnus-cache-articles-in-group group))
5326             ;; Select only the "normal" subset of articles.
5327             (gnus-sorted-nunion
5328              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5329              gnus-newsgroup-unreads)))
5330          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5331          (scored (length scored-list))
5332          (number (length articles))
5333          (marked (+ (length gnus-newsgroup-marked)
5334                     (length gnus-newsgroup-dormant)))
5335          (select
5336           (cond
5337            ((numberp read-all)
5338             read-all)
5339            ((numberp gnus-newsgroup-display)
5340             gnus-newsgroup-display)
5341            (t
5342             (condition-case ()
5343                 (cond
5344                  ((and (or (<= scored marked) (= scored number))
5345                        (numberp gnus-large-newsgroup)
5346                        (> number gnus-large-newsgroup))
5347                   (let* ((cursor-in-echo-area nil)
5348                          (initial (gnus-parameter-large-newsgroup-initial
5349                                    gnus-newsgroup-name))
5350                          (input
5351                           (read-string
5352                            (format
5353                             "How many articles from %s (%s %d): "
5354                             (gnus-limit-string
5355                              (gnus-group-decoded-name gnus-newsgroup-name)
5356                              35)
5357                             (if initial "max" "default")
5358                             number)
5359                            (if initial
5360                                (cons (number-to-string initial)
5361                                      0)))))
5362                     (if (string-match "^[ \t]*$" input) number input)))
5363                  ((and (> scored marked) (< scored number)
5364                        (> (- scored number) 20))
5365                   (let ((input
5366                          (read-string
5367                           (format "%s %s (%d scored, %d total): "
5368                                   "How many articles from"
5369                                   (gnus-group-decoded-name group)
5370                                   scored number))))
5371                     (if (string-match "^[ \t]*$" input)
5372                         number input)))
5373                  (t number))
5374               (quit
5375                (message "Quit getting the articles to read")
5376                nil))))))
5377     (setq select (if (stringp select) (string-to-number select) select))
5378     (if (or (null select) (zerop select))
5379         select
5380       (if (and (not (zerop scored)) (<= (abs select) scored))
5381           (progn
5382             (setq articles (sort scored-list '<))
5383             (setq number (length articles)))
5384         (setq articles (copy-sequence articles)))
5385
5386       (when (< (abs select) number)
5387         (if (< select 0)
5388             ;; Select the N oldest articles.
5389             (setcdr (nthcdr (1- (abs select)) articles) nil)
5390           ;; Select the N most recent articles.
5391           (setq articles (nthcdr (- number select) articles))))
5392       (setq gnus-newsgroup-unselected
5393             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5394       (when gnus-alter-articles-to-read-function
5395         (setq articles
5396               (sort
5397                (funcall gnus-alter-articles-to-read-function
5398                         gnus-newsgroup-name articles)
5399                '<)))
5400       articles)))
5401
5402 (defun gnus-killed-articles (killed articles)
5403   (let (out)
5404     (while articles
5405       (when (inline (gnus-member-of-range (car articles) killed))
5406         (push (car articles) out))
5407       (setq articles (cdr articles)))
5408     out))
5409
5410 (defun gnus-uncompress-marks (marks)
5411   "Uncompress the mark ranges in MARKS."
5412   (let ((uncompressed '(score bookmark))
5413         out)
5414     (while marks
5415       (if (memq (caar marks) uncompressed)
5416           (push (car marks) out)
5417         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5418       (setq marks (cdr marks)))
5419     out))
5420
5421 (defun gnus-article-mark-to-type (mark)
5422   "Return the type of MARK."
5423   (or (cadr (assq mark gnus-article-special-mark-lists))
5424       'list))
5425
5426 (defun gnus-article-unpropagatable-p (mark)
5427   "Return whether MARK should be propagated to back end."
5428   (memq mark gnus-article-unpropagated-mark-lists))
5429
5430 (defun gnus-adjust-marked-articles (info)
5431   "Set all article lists and remove all marks that are no longer valid."
5432   (let* ((marked-lists (gnus-info-marks info))
5433          (active (gnus-active (gnus-info-group info)))
5434          (min (car active))
5435          (max (cdr active))
5436          (types gnus-article-mark-lists)
5437          marks var articles article mark mark-type
5438          bgn end)
5439
5440     (dolist (marks marked-lists)
5441       (setq mark (car marks)
5442             mark-type (gnus-article-mark-to-type mark)
5443             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5444
5445       ;; We set the variable according to the type of the marks list,
5446       ;; and then adjust the marks to a subset of the active articles.
5447       (cond
5448        ;; Adjust "simple" lists - compressed yet unsorted
5449        ((eq mark-type 'list)
5450         ;; Simultaneously uncompress and clip to active range
5451         ;; See gnus-uncompress-range for a description of possible marks
5452         (let (l lh)
5453           (if (not (cadr marks))
5454               (set var nil)
5455             (setq articles (if (numberp (cddr marks))
5456                                (list (cdr marks))
5457                              (cdr marks))
5458                   lh (cons nil nil)
5459                   l lh)
5460
5461             (while (setq article (pop articles))
5462               (cond ((consp article)
5463                      (setq bgn (max (car article) min)
5464                            end (min (cdr article) max))
5465                      (while (<= bgn end)
5466                        (setq l (setcdr l (cons bgn nil))
5467                              bgn (1+ bgn))))
5468                     ((and (<= min article)
5469                           (>= max article))
5470                      (setq l (setcdr l (cons article nil))))))
5471             (set var (cdr lh)))))
5472        ;; Adjust assocs.
5473        ((eq mark-type 'tuple)
5474         (set var (setq articles (cdr marks)))
5475         (when (not (listp (cdr (symbol-value var))))
5476           (set var (list (symbol-value var))))
5477         (when (not (listp (cdr articles)))
5478           (setq articles (list articles)))
5479         (while articles
5480           (when (or (not (consp (setq article (pop articles))))
5481                     (< (car article) min)
5482                     (> (car article) max))
5483             (set var (delq article (symbol-value var))))))
5484        ;; Adjust ranges (sloppily).
5485        ((eq mark-type 'range)
5486         (cond
5487          ((eq mark 'seen)
5488           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5489           ;; It should be (seen (NUM1 . NUM2)).
5490           (when (numberp (cddr marks))
5491             (setcdr marks (list (cdr marks))))
5492           (setq articles (cdr marks))
5493           (while (and articles
5494                       (or (and (consp (car articles))
5495                                (> min (cdar articles)))
5496                           (and (numberp (car articles))
5497                                (> min (car articles)))))
5498             (pop articles))
5499           (set var articles))))))))
5500
5501 (defun gnus-update-missing-marks (missing)
5502   "Go through the list of MISSING articles and remove them from the mark lists."
5503   (when missing
5504     (let (var m)
5505       ;; Go through all types.
5506       (dolist (elem gnus-article-mark-lists)
5507         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5508           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5509           (when (symbol-value var)
5510             ;; This list has articles.  So we delete all missing
5511             ;; articles from it.
5512             (setq m missing)
5513             (while m
5514               (set var (delq (pop m) (symbol-value var))))))))))
5515
5516 (defun gnus-update-marks ()
5517   "Enter the various lists of marked articles into the newsgroup info list."
5518   (let ((types gnus-article-mark-lists)
5519         (info (gnus-get-info gnus-newsgroup-name))
5520         type list newmarked symbol delta-marks)
5521     (when info
5522       ;; Add all marks lists to the list of marks lists.
5523       (while (setq type (pop types))
5524         (setq list (symbol-value
5525                     (setq symbol
5526                           (intern (format "gnus-newsgroup-%s" (car type))))))
5527
5528         (when list
5529           ;; Get rid of the entries of the articles that have the
5530           ;; default score.
5531           (when (and (eq (cdr type) 'score)
5532                      gnus-save-score
5533                      list)
5534             (let* ((arts list)
5535                    (prev (cons nil list))
5536                    (all prev))
5537               (while arts
5538                 (if (or (not (consp (car arts)))
5539                         (= (cdar arts) gnus-summary-default-score))
5540                     (setcdr prev (cdr arts))
5541                   (setq prev arts))
5542                 (setq arts (cdr arts)))
5543               (setq list (cdr all)))))
5544
5545         (when (eq (cdr type) 'seen)
5546           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5547
5548         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5549           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5550
5551         (when (and (gnus-check-backend-function
5552                     'request-set-mark gnus-newsgroup-name)
5553                    (not (gnus-article-unpropagatable-p (cdr type))))
5554           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5555                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5556                  (add (gnus-remove-from-range
5557                        (gnus-copy-sequence list) old)))
5558             (when add
5559               (push (list add 'add (list (cdr type))) delta-marks))
5560             (when del
5561               (push (list del 'del (list (cdr type))) delta-marks))))
5562
5563         (when list
5564           (push (cons (cdr type) list) newmarked)))
5565
5566       (when delta-marks
5567         (unless (gnus-check-group gnus-newsgroup-name)
5568           (error "Can't open server for %s" gnus-newsgroup-name))
5569         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5570
5571       ;; Enter these new marks into the info of the group.
5572       (if (nthcdr 3 info)
5573           (setcar (nthcdr 3 info) newmarked)
5574         ;; Add the marks lists to the end of the info.
5575         (when newmarked
5576           (setcdr (nthcdr 2 info) (list newmarked))))
5577
5578       ;; Cut off the end of the info if there's nothing else there.
5579       (let ((i 5))
5580         (while (and (> i 2)
5581                     (not (nth i info)))
5582           (when (nthcdr (decf i) info)
5583             (setcdr (nthcdr i info) nil)))))))
5584
5585 (defun gnus-set-mode-line (where)
5586   "Set the mode line of the article or summary buffers.
5587 If WHERE is `summary', the summary mode line format will be used."
5588   ;; Is this mode line one we keep updated?
5589   (when (and (memq where gnus-updated-mode-lines)
5590              (symbol-value
5591               (intern (format "gnus-%s-mode-line-format-spec" where))))
5592     (let (mode-string)
5593       (save-excursion
5594         ;; We evaluate this in the summary buffer since these
5595         ;; variables are buffer-local to that buffer.
5596         (set-buffer gnus-summary-buffer)
5597         ;; We bind all these variables that are used in the `eval' form
5598         ;; below.
5599         (let* ((mformat (symbol-value
5600                          (intern
5601                           (format "gnus-%s-mode-line-format-spec" where))))
5602                (gnus-tmp-group-name (gnus-group-decoded-name
5603                                      gnus-newsgroup-name))
5604                (gnus-tmp-article-number (or gnus-current-article 0))
5605                (gnus-tmp-unread gnus-newsgroup-unreads)
5606                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5607                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5608                (gnus-tmp-unread-and-unselected
5609                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5610                             (zerop gnus-tmp-unselected))
5611                        "")
5612                       ((zerop gnus-tmp-unselected)
5613                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5614                       (t (format "{%d(+%d) more}"
5615                                  gnus-tmp-unread-and-unticked
5616                                  gnus-tmp-unselected))))
5617                (gnus-tmp-subject
5618                 (if (and gnus-current-headers
5619                          (vectorp gnus-current-headers))
5620                     (gnus-mode-string-quote
5621                      (mail-header-subject gnus-current-headers))
5622                   ""))
5623                bufname-length max-len
5624                gnus-tmp-header);; passed as argument to any user-format-funcs
5625           (setq mode-string (eval mformat))
5626           (setq bufname-length (if (string-match "%b" mode-string)
5627                                    (- (length
5628                                        (buffer-name
5629                                         (if (eq where 'summary)
5630                                             nil
5631                                           (get-buffer gnus-article-buffer))))
5632                                       2)
5633                                  0))
5634           (setq max-len (max 4 (if gnus-mode-non-string-length
5635                                    (- (window-width)
5636                                       gnus-mode-non-string-length
5637                                       bufname-length)
5638                                  (length mode-string))))
5639           ;; We might have to chop a bit of the string off...
5640           (when (> (length mode-string) max-len)
5641             (setq mode-string
5642                   (concat (gnus-truncate-string mode-string (- max-len 3))
5643                           "...")))
5644           ;; Pad the mode string a bit.
5645           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5646       ;; Update the mode line.
5647       (setq mode-line-buffer-identification
5648             (gnus-mode-line-buffer-identification (list mode-string)))
5649       (set-buffer-modified-p t))))
5650
5651 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5652   "Go through the HEADERS list and add all Xrefs to a hash table.
5653 The resulting hash table is returned, or nil if no Xrefs were found."
5654   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5655          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5656          (xref-hashtb (gnus-make-hashtable))
5657          start group entry number xrefs header)
5658     (while headers
5659       (setq header (pop headers))
5660       (when (and (setq xrefs (mail-header-xref header))
5661                  (not (memq (setq number (mail-header-number header))
5662                             unreads)))
5663         (setq start 0)
5664         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5665           (setq start (match-end 0))
5666           (setq group (if prefix
5667                           (concat prefix (substring xrefs (match-beginning 1)
5668                                                     (match-end 1)))
5669                         (substring xrefs (match-beginning 1) (match-end 1))))
5670           (setq number
5671                 (string-to-int (substring xrefs (match-beginning 2)
5672                                           (match-end 2))))
5673           (if (setq entry (gnus-gethash group xref-hashtb))
5674               (setcdr entry (cons number (cdr entry)))
5675             (gnus-sethash group (cons number nil) xref-hashtb)))))
5676     (and start xref-hashtb)))
5677
5678 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5679   "Look through all the headers and mark the Xrefs as read."
5680   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5681         name info xref-hashtb idlist method nth4)
5682     (save-excursion
5683       (set-buffer gnus-group-buffer)
5684       (when (setq xref-hashtb
5685                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5686         (mapatoms
5687          (lambda (group)
5688            (unless (string= from-newsgroup (setq name (symbol-name group)))
5689              (setq idlist (symbol-value group))
5690              ;; Dead groups are not updated.
5691              (and (prog1
5692                       (setq info (gnus-get-info name))
5693                     (when (stringp (setq nth4 (gnus-info-method info)))
5694                       (setq nth4 (gnus-server-to-method nth4))))
5695                   ;; Only do the xrefs if the group has the same
5696                   ;; select method as the group we have just read.
5697                   (or (gnus-methods-equal-p
5698                        nth4 (gnus-find-method-for-group from-newsgroup))
5699                       virtual
5700                       (equal nth4 (setq method (gnus-find-method-for-group
5701                                                 from-newsgroup)))
5702                       (and (equal (car nth4) (car method))
5703                            (equal (nth 1 nth4) (nth 1 method))))
5704                   gnus-use-cross-reference
5705                   (or (not (eq gnus-use-cross-reference t))
5706                       virtual
5707                       ;; Only do cross-references on subscribed
5708                       ;; groups, if that is what is wanted.
5709                       (<= (gnus-info-level info) gnus-level-subscribed))
5710                   (gnus-group-make-articles-read name idlist))))
5711          xref-hashtb)))))
5712
5713 (defun gnus-compute-read-articles (group articles)
5714   (let* ((entry (gnus-group-entry group))
5715          (info (nth 2 entry))
5716          (active (gnus-active group))
5717          ninfo)
5718     (when entry
5719       ;; First peel off all invalid article numbers.
5720       (when active
5721         (let ((ids articles)
5722               id first)
5723           (while (setq id (pop ids))
5724             (when (and first (> id (cdr active)))
5725               ;; We'll end up in this situation in one particular
5726               ;; obscure situation.  If you re-scan a group and get
5727               ;; a new article that is cross-posted to a different
5728               ;; group that has not been re-scanned, you might get
5729               ;; crossposted article that has a higher number than
5730               ;; Gnus believes possible.  So we re-activate this
5731               ;; group as well.  This might mean doing the
5732               ;; crossposting thingy will *increase* the number
5733               ;; of articles in some groups.  Tsk, tsk.
5734               (setq active (or (gnus-activate-group group) active)))
5735             (when (or (> id (cdr active))
5736                       (< id (car active)))
5737               (setq articles (delq id articles))))))
5738       ;; If the read list is nil, we init it.
5739       (if (and active
5740                (null (gnus-info-read info))
5741                (> (car active) 1))
5742           (setq ninfo (cons 1 (1- (car active))))
5743         (setq ninfo (gnus-info-read info)))
5744       ;; Then we add the read articles to the range.
5745       (gnus-add-to-range
5746        ninfo (setq articles (sort articles '<))))))
5747
5748 (defun gnus-group-make-articles-read (group articles)
5749   "Update the info of GROUP to say that ARTICLES are read."
5750   (let* ((num 0)
5751          (entry (gnus-group-entry group))
5752          (info (nth 2 entry))
5753          (active (gnus-active group))
5754          range)
5755     (when entry
5756       (setq range (gnus-compute-read-articles group articles))
5757       (with-current-buffer gnus-group-buffer
5758         (gnus-undo-register
5759           `(progn
5760              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5761              (gnus-info-set-read ',info ',(gnus-info-read info))
5762              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5763              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5764              (gnus-group-update-group ,group t))))
5765       ;; Add the read articles to the range.
5766       (gnus-info-set-read info range)
5767       (gnus-request-set-mark group (list (list range 'add '(read))))
5768       ;; Then we have to re-compute how many unread
5769       ;; articles there are in this group.
5770       (when active
5771         (cond
5772          ((not range)
5773           (setq num (- (1+ (cdr active)) (car active))))
5774          ((not (listp (cdr range)))
5775           (setq num (- (cdr active) (- (1+ (cdr range))
5776                                        (car range)))))
5777          (t
5778           (while range
5779             (if (numberp (car range))
5780                 (setq num (1+ num))
5781               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5782             (setq range (cdr range)))
5783           (setq num (- (cdr active) num))))
5784         ;; Update the number of unread articles.
5785         (setcar entry num)
5786         ;; Update the group buffer.
5787         (unless (gnus-ephemeral-group-p group)
5788           (gnus-group-update-group group t))))))
5789
5790 (defvar gnus-newsgroup-none-id 0)
5791
5792 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5793   (let ((cur nntp-server-buffer)
5794         (dependencies
5795          (or dependencies
5796              (with-current-buffer gnus-summary-buffer
5797                gnus-newsgroup-dependencies)))
5798         headers id end ref number
5799         (mail-parse-charset gnus-newsgroup-charset)
5800         (mail-parse-ignored-charsets
5801          (save-excursion (condition-case nil
5802                              (set-buffer gnus-summary-buffer)
5803                            (error))
5804                          gnus-newsgroup-ignored-charsets)))
5805     (save-excursion
5806       (set-buffer nntp-server-buffer)
5807       ;; Translate all TAB characters into SPACE characters.
5808       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5809       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5810       (ietf-drums-unfold-fws)
5811       (gnus-run-hooks 'gnus-parse-headers-hook)
5812       (let ((case-fold-search t)
5813             in-reply-to header p lines chars ctype)
5814         (goto-char (point-min))
5815         ;; Search to the beginning of the next header.  Error messages
5816         ;; do not begin with 2 or 3.
5817         (while (re-search-forward "^[23][0-9]+ " nil t)
5818           (setq id nil
5819                 ref nil)
5820           ;; This implementation of this function, with nine
5821           ;; search-forwards instead of the one re-search-forward and
5822           ;; a case (which basically was the old function) is actually
5823           ;; about twice as fast, even though it looks messier.  You
5824           ;; can't have everything, I guess.  Speed and elegance
5825           ;; doesn't always go hand in hand.
5826           (setq
5827            header
5828            (make-full-mail-header
5829             ;; Number.
5830             (prog1
5831                 (setq number (read cur))
5832               (end-of-line)
5833               (setq p (point))
5834               (narrow-to-region (point)
5835                                 (or (and (search-forward "\n.\n" nil t)
5836                                          (- (point) 2))
5837                                     (point))))
5838             ;; Subject.
5839             (progn
5840               (goto-char p)
5841               (if (search-forward "\nsubject:" nil t)
5842                   (nnheader-header-value)
5843                 "(none)"))
5844             ;; From.
5845             (progn
5846               (goto-char p)
5847               (if (search-forward "\nfrom:" nil t)
5848                   (nnheader-header-value)
5849                 "(nobody)"))
5850             ;; Date.
5851             (progn
5852               (goto-char p)
5853               (if (search-forward "\ndate:" nil t)
5854                   (nnheader-header-value) ""))
5855             ;; Message-ID.
5856             (progn
5857               (goto-char p)
5858               (setq id (if (re-search-forward
5859                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5860                            ;; We do it this way to make sure the Message-ID
5861                            ;; is (somewhat) syntactically valid.
5862                            (buffer-substring (match-beginning 1)
5863                                              (match-end 1))
5864                          ;; If there was no message-id, we just fake one
5865                          ;; to make subsequent routines simpler.
5866                          (nnheader-generate-fake-message-id number))))
5867             ;; References.
5868             (progn
5869               (goto-char p)
5870               (if (search-forward "\nreferences:" nil t)
5871                   (progn
5872                     (setq end (point))
5873                     (prog1
5874                         (nnheader-header-value)
5875                       (setq ref
5876                             (buffer-substring
5877                              (progn
5878                                ;; (end-of-line)
5879                                (search-backward ">" end t)
5880                                (1+ (point)))
5881                              (progn
5882                                (search-backward "<" end t)
5883                                (point))))))
5884                 ;; Get the references from the in-reply-to header if there
5885                 ;; were no references and the in-reply-to header looks
5886                 ;; promising.
5887                 (if (and (search-forward "\nin-reply-to:" nil t)
5888                          (setq in-reply-to (nnheader-header-value))
5889                          (string-match "<[^>]+>" in-reply-to))
5890                     (let (ref2)
5891                       (setq ref (substring in-reply-to (match-beginning 0)
5892                                            (match-end 0)))
5893                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5894                         (setq ref2 (substring in-reply-to (match-beginning 0)
5895                                               (match-end 0)))
5896                         (when (> (length ref2) (length ref))
5897                           (setq ref ref2)))
5898                       ref)
5899                   (setq ref nil))))
5900             ;; Chars.
5901             (progn
5902               (goto-char p)
5903               (if (search-forward "\nchars: " nil t)
5904                   (if (numberp (setq chars (ignore-errors (read cur))))
5905                       chars -1)
5906                 -1))
5907             ;; Lines.
5908             (progn
5909               (goto-char p)
5910               (if (search-forward "\nlines: " nil t)
5911                   (if (numberp (setq lines (ignore-errors (read cur))))
5912                       lines -1)
5913                 -1))
5914             ;; Xref.
5915             (progn
5916               (goto-char p)
5917               (and (search-forward "\nxref:" nil t)
5918                    (nnheader-header-value)))
5919             ;; Extra.
5920             (when gnus-extra-headers
5921               (let ((extra gnus-extra-headers)
5922                     out)
5923                 (while extra
5924                   (goto-char p)
5925                   (when (search-forward
5926                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5927                     (push (cons (car extra) (nnheader-header-value)) out))
5928                   (pop extra))
5929                 out))))
5930           (goto-char p)
5931           (if (and (search-forward "\ncontent-type: " nil t)
5932                    (setq ctype (nnheader-header-value)))
5933               (mime-entity-set-content-type-internal
5934                header (mime-parse-Content-Type ctype)))
5935           (when (equal id ref)
5936             (setq ref nil))
5937
5938           (when gnus-alter-header-function
5939             (funcall gnus-alter-header-function header)
5940             (setq id (mail-header-id header)
5941                   ref (gnus-parent-id (mail-header-references header))))
5942
5943           (when (setq header
5944                       (gnus-dependencies-add-header
5945                        header dependencies force-new))
5946             (push header headers))
5947           (goto-char (point-max))
5948           (widen))
5949         (nreverse headers)))))
5950
5951 ;; Goes through the xover lines and returns a list of vectors
5952 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5953                                                   force-new dependencies
5954                                                   group also-fetch-heads)
5955   "Parse the news overview data in the server buffer.
5956 Return a list of headers that match SEQUENCE (see
5957 `nntp-retrieve-headers')."
5958   ;; Get the Xref when the users reads the articles since most/some
5959   ;; NNTP servers do not include Xrefs when using XOVER.
5960   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5961   (let ((mail-parse-charset gnus-newsgroup-charset)
5962         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5963         (cur nntp-server-buffer)
5964         (dependencies (or dependencies gnus-newsgroup-dependencies))
5965         (allp (cond
5966                ((eq gnus-read-all-available-headers t)
5967                 t)
5968                ((stringp gnus-read-all-available-headers)
5969                 (string-match gnus-read-all-available-headers group))
5970                (t
5971                 nil)))
5972         number headers header)
5973     (save-excursion
5974       (set-buffer nntp-server-buffer)
5975       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5976       ;; Allow the user to mangle the headers before parsing them.
5977       (gnus-run-hooks 'gnus-parse-headers-hook)
5978       (goto-char (point-min))
5979       (gnus-parse-without-error
5980         (while (and (or sequence allp)
5981                     (not (eobp)))
5982           (setq number (read cur))
5983           (when (not allp)
5984             (while (and sequence
5985                         (< (car sequence) number))
5986               (setq sequence (cdr sequence))))
5987           (when (and (or allp
5988                          (and sequence
5989                               (eq number (car sequence))))
5990                      (progn
5991                        (setq sequence (cdr sequence))
5992                        (setq header (inline
5993                                       (gnus-nov-parse-line
5994                                        number dependencies force-new)))))
5995             (push header headers))
5996           (forward-line 1)))
5997       ;; A common bug in inn is that if you have posted an article and
5998       ;; then retrieves the active file, it will answer correctly --
5999       ;; the new article is included.  However, a NOV entry for the
6000       ;; article may not have been generated yet, so this may fail.
6001       ;; We work around this problem by retrieving the last few
6002       ;; headers using HEAD.
6003       (if (or (not also-fetch-heads)
6004               (not sequence))
6005           ;; We (probably) got all the headers.
6006           (nreverse headers)
6007         (let ((gnus-nov-is-evil t))
6008           (nconc
6009            (nreverse headers)
6010            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6011              (gnus-get-newsgroup-headers))))))))
6012
6013 (defun gnus-article-get-xrefs ()
6014   "Fill in the Xref value in `gnus-current-headers', if necessary.
6015 This is meant to be called in `gnus-article-internal-prepare-hook'."
6016   (let ((headers (with-current-buffer gnus-summary-buffer
6017                    gnus-current-headers)))
6018     (or (not gnus-use-cross-reference)
6019         (not headers)
6020         (and (mail-header-xref headers)
6021              (not (string= (mail-header-xref headers) "")))
6022         (let ((case-fold-search t)
6023               xref)
6024           (save-restriction
6025             (nnheader-narrow-to-headers)
6026             (goto-char (point-min))
6027             (when (or (and (not (eobp))
6028                            (eq (downcase (char-after)) ?x)
6029                            (looking-at "Xref:"))
6030                       (search-forward "\nXref:" nil t))
6031               (goto-char (1+ (match-end 0)))
6032               (setq xref (buffer-substring (point) (point-at-eol)))
6033               (mail-header-set-xref headers xref)))))))
6034
6035 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6036   "Find article ID and insert the summary line for that article.
6037 OLD-HEADER can either be a header or a line number to insert
6038 the subject line on."
6039   (let* ((line (and (numberp old-header) old-header))
6040          (old-header (and (vectorp old-header) old-header))
6041          (header (cond ((and old-header use-old-header)
6042                         old-header)
6043                        ((and (numberp id)
6044                              (gnus-number-to-header id))
6045                         (gnus-number-to-header id))
6046                        (t
6047                         (gnus-read-header id))))
6048          (number (and (numberp id) id))
6049          d)
6050     (when header
6051       ;; Rebuild the thread that this article is part of and go to the
6052       ;; article we have fetched.
6053       (when (and (not gnus-show-threads)
6054                  old-header)
6055         (when (and number
6056                    (setq d (gnus-data-find (mail-header-number old-header))))
6057           (goto-char (gnus-data-pos d))
6058           (gnus-data-remove
6059            number
6060            (- (point-at-bol)
6061               (prog1
6062                   (1+ (point-at-eol))
6063                 (gnus-delete-line))))))
6064       ;; Remove list identifiers from subject.
6065       (when gnus-list-identifiers
6066         (let ((gnus-newsgroup-headers (list header)))
6067           (gnus-summary-remove-list-identifiers)))
6068       (when old-header
6069         (mail-header-set-number header (mail-header-number old-header)))
6070       (setq gnus-newsgroup-sparse
6071             (delq (setq number (mail-header-number header))
6072                   gnus-newsgroup-sparse))
6073       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6074       (push number gnus-newsgroup-limit)
6075       (gnus-rebuild-thread (mail-header-id header) line)
6076       (gnus-summary-goto-subject number nil t))
6077     (when (and (numberp number)
6078                (> number 0))
6079       ;; We have to update the boundaries even if we can't fetch the
6080       ;; article if ID is a number -- so that the next `P' or `N'
6081       ;; command will fetch the previous (or next) article even
6082       ;; if the one we tried to fetch this time has been canceled.
6083       (when (> number gnus-newsgroup-end)
6084         (setq gnus-newsgroup-end number))
6085       (when (< number gnus-newsgroup-begin)
6086         (setq gnus-newsgroup-begin number))
6087       (setq gnus-newsgroup-unselected
6088             (delq number gnus-newsgroup-unselected)))
6089     ;; Report back a success?
6090     (and header (mail-header-number header))))
6091
6092 ;;; Process/prefix in the summary buffer
6093
6094 (defun gnus-summary-work-articles (n)
6095   "Return a list of articles to be worked upon.
6096 The prefix argument, the list of process marked articles, and the
6097 current article will be taken into consideration."
6098   (save-excursion
6099     (set-buffer gnus-summary-buffer)
6100     (cond
6101      (n
6102       ;; A numerical prefix has been given.
6103       (setq n (prefix-numeric-value n))
6104       (let ((backward (< n 0))
6105             (n (abs (prefix-numeric-value n)))
6106             articles article)
6107         (save-excursion
6108           (while
6109               (and (> n 0)
6110                    (push (setq article (gnus-summary-article-number))
6111                          articles)
6112                    (if backward
6113                        (gnus-summary-find-prev nil article)
6114                      (gnus-summary-find-next nil article)))
6115             (decf n)))
6116         (nreverse articles)))
6117      ((and (gnus-region-active-p) (mark))
6118       (message "region active")
6119       ;; Work on the region between point and mark.
6120       (let ((max (max (point) (mark)))
6121             articles article)
6122         (save-excursion
6123           (goto-char (min (point) (mark)))
6124           (while
6125               (and
6126                (push (setq article (gnus-summary-article-number)) articles)
6127                (gnus-summary-find-next nil article)
6128                (< (point) max)))
6129           (nreverse articles))))
6130      (gnus-newsgroup-processable
6131       ;; There are process-marked articles present.
6132       ;; Save current state.
6133       (gnus-summary-save-process-mark)
6134       ;; Return the list.
6135       (reverse gnus-newsgroup-processable))
6136      (t
6137       ;; Just return the current article.
6138       (list (gnus-summary-article-number))))))
6139
6140 (defmacro gnus-summary-iterate (arg &rest forms)
6141   "Iterate over the process/prefixed articles and do FORMS.
6142 ARG is the interactive prefix given to the command.  FORMS will be
6143 executed with point over the summary line of the articles."
6144   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6145     `(let ((,articles (gnus-summary-work-articles ,arg)))
6146        (while ,articles
6147          (gnus-summary-goto-subject (car ,articles))
6148          ,@forms
6149          (pop ,articles)))))
6150
6151 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6152 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6153
6154 (defun gnus-summary-save-process-mark ()
6155   "Push the current set of process marked articles on the stack."
6156   (interactive)
6157   (push (copy-sequence gnus-newsgroup-processable)
6158         gnus-newsgroup-process-stack))
6159
6160 (defun gnus-summary-kill-process-mark ()
6161   "Push the current set of process marked articles on the stack and unmark."
6162   (interactive)
6163   (gnus-summary-save-process-mark)
6164   (gnus-summary-unmark-all-processable))
6165
6166 (defun gnus-summary-yank-process-mark ()
6167   "Pop the last process mark state off the stack and restore it."
6168   (interactive)
6169   (unless gnus-newsgroup-process-stack
6170     (error "Empty mark stack"))
6171   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6172
6173 (defun gnus-summary-process-mark-set (set)
6174   "Make SET into the current process marked articles."
6175   (gnus-summary-unmark-all-processable)
6176   (mapc 'gnus-summary-set-process-mark set))
6177
6178 ;;; Searching and stuff
6179
6180 (defun gnus-summary-search-group (&optional backward use-level)
6181   "Search for next unread newsgroup.
6182 If optional argument BACKWARD is non-nil, search backward instead."
6183   (save-excursion
6184     (set-buffer gnus-group-buffer)
6185     (when (gnus-group-search-forward
6186            backward nil (if use-level (gnus-group-group-level) nil))
6187       (gnus-group-group-name))))
6188
6189 (defun gnus-summary-best-group (&optional exclude-group)
6190   "Find the name of the best unread group.
6191 If EXCLUDE-GROUP, do not go to this group."
6192   (with-current-buffer gnus-group-buffer
6193     (save-excursion
6194       (gnus-group-best-unread-group exclude-group))))
6195
6196 (defun gnus-summary-find-next (&optional unread article backward)
6197   (if backward
6198       (gnus-summary-find-prev unread article)
6199     (let* ((dummy (gnus-summary-article-intangible-p))
6200            (article (or article (gnus-summary-article-number)))
6201            (data (gnus-data-find-list article))
6202            result)
6203       (when (and (not dummy)
6204                  (or (not gnus-summary-check-current)
6205                      (not unread)
6206                      (not (gnus-data-unread-p (car data)))))
6207         (setq data (cdr data)))
6208       (when (setq result
6209                   (if unread
6210                       (progn
6211                         (while data
6212                           (unless (memq (gnus-data-number (car data))
6213                                         (cond
6214                                          ((eq gnus-auto-goto-ignores
6215                                               'always-undownloaded)
6216                                           gnus-newsgroup-undownloaded)
6217                                          (gnus-plugged
6218                                           nil)
6219                                          ((eq gnus-auto-goto-ignores
6220                                               'unfetched)
6221                                           gnus-newsgroup-unfetched)
6222                                          ((eq gnus-auto-goto-ignores
6223                                               'undownloaded)
6224                                           gnus-newsgroup-undownloaded)))
6225                             (when (gnus-data-unread-p (car data))
6226                               (setq result (car data)
6227                                     data nil)))
6228                           (setq data (cdr data)))
6229                         result)
6230                     (car data)))
6231         (goto-char (gnus-data-pos result))
6232         (gnus-data-number result)))))
6233
6234 (defun gnus-summary-find-prev (&optional unread article)
6235   (let* ((eobp (eobp))
6236          (article (or article (gnus-summary-article-number)))
6237          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6238          result)
6239     (when (and (not eobp)
6240                (or (not gnus-summary-check-current)
6241                    (not unread)
6242                    (not (gnus-data-unread-p (car data)))))
6243       (setq data (cdr data)))
6244     (when (setq result
6245                 (if unread
6246                     (progn
6247                       (while data
6248                         (unless (memq (gnus-data-number (car data))
6249                                       (cond
6250                                        ((eq gnus-auto-goto-ignores
6251                                             'always-undownloaded)
6252                                         gnus-newsgroup-undownloaded)
6253                                        (gnus-plugged
6254                                         nil)
6255                                        ((eq gnus-auto-goto-ignores
6256                                             'unfetched)
6257                                         gnus-newsgroup-unfetched)
6258                                        ((eq gnus-auto-goto-ignores
6259                                             'undownloaded)
6260                                         gnus-newsgroup-undownloaded)))
6261                           (when (gnus-data-unread-p (car data))
6262                             (setq result (car data)
6263                                   data nil)))
6264                         (setq data (cdr data)))
6265                       result)
6266                   (car data)))
6267       (goto-char (gnus-data-pos result))
6268       (gnus-data-number result))))
6269
6270 (defun gnus-summary-find-subject (subject &optional unread backward article)
6271   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6272          (article (or article (gnus-summary-article-number)))
6273          (articles (gnus-data-list backward))
6274          (arts (gnus-data-find-list article articles))
6275          result)
6276     (when (or (not gnus-summary-check-current)
6277               (not unread)
6278               (not (gnus-data-unread-p (car arts))))
6279       (setq arts (cdr arts)))
6280     (while arts
6281       (and (or (not unread)
6282                (gnus-data-unread-p (car arts)))
6283            (vectorp (gnus-data-header (car arts)))
6284            (gnus-subject-equal
6285             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6286            (setq result (car arts)
6287                  arts nil))
6288       (setq arts (cdr arts)))
6289     (and result
6290          (goto-char (gnus-data-pos result))
6291          (gnus-data-number result))))
6292
6293 (defun gnus-summary-search-forward (&optional unread subject backward)
6294   "Search forward for an article.
6295 If UNREAD, look for unread articles.  If SUBJECT, look for
6296 articles with that subject.  If BACKWARD, search backward instead."
6297   (cond (subject (gnus-summary-find-subject subject unread backward))
6298         (backward (gnus-summary-find-prev unread))
6299         (t (gnus-summary-find-next unread))))
6300
6301 (defun gnus-recenter (&optional n)
6302   "Center point in window and redisplay frame.
6303 Also do horizontal recentering."
6304   (interactive "P")
6305   (when (and gnus-auto-center-summary
6306              (not (eq gnus-auto-center-summary 'vertical)))
6307     (gnus-horizontal-recenter))
6308   (recenter n))
6309
6310 (defun gnus-summary-recenter ()
6311   "Center point in the summary window.
6312 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6313 displayed, no centering will be performed."
6314   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6315   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6316   (interactive)
6317   ;; The user has to want it.
6318   (when gnus-auto-center-summary
6319     (let* ((top (cond ((< (window-height) 4) 0)
6320                       ((< (window-height) 7) 1)
6321                       (t (if (numberp gnus-auto-center-summary)
6322                              gnus-auto-center-summary
6323                            (/ (1- (window-height)) 2)))))
6324            (height (1- (window-height)))
6325            (bottom (save-excursion (goto-char (point-max))
6326                                    (forward-line (- height))
6327                                    (point)))
6328            (window (get-buffer-window (current-buffer))))
6329       (when (get-buffer-window gnus-article-buffer)
6330         ;; Only do recentering when the article buffer is displayed,
6331         ;; Set the window start to either `bottom', which is the biggest
6332         ;; possible valid number, or the second line from the top,
6333         ;; whichever is the least.
6334         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6335           (if (> bottom top-pos)
6336               ;; Keep the second line from the top visible
6337               (set-window-start window top-pos t)
6338             ;; Try to keep the bottom line visible; if it's partially
6339             ;; obscured, either scroll one more line to make it fully
6340             ;; visible, or revert to using TOP-POS.
6341             (save-excursion
6342               (goto-char (point-max))
6343               (forward-line -1)
6344               (let ((last-line-start (point)))
6345                 (goto-char bottom)
6346                 (set-window-start window (point) t)
6347                 (when (not (pos-visible-in-window-p last-line-start window))
6348                   (forward-line 1)
6349                   (set-window-start window (min (point) top-pos) t)))))))
6350       ;; Do horizontal recentering while we're at it.
6351       (when (and (get-buffer-window (current-buffer) t)
6352                  (not (eq gnus-auto-center-summary 'vertical)))
6353         (let ((selected (selected-window)))
6354           (select-window (get-buffer-window (current-buffer) t))
6355           (gnus-summary-position-point)
6356           (gnus-horizontal-recenter)
6357           (select-window selected))))))
6358
6359 (defun gnus-summary-jump-to-group (newsgroup)
6360   "Move point to NEWSGROUP in group mode buffer."
6361   ;; Keep update point of group mode buffer if visible.
6362   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6363       (save-window-excursion
6364         ;; Take care of tree window mode.
6365         (when (get-buffer-window gnus-group-buffer)
6366           (pop-to-buffer gnus-group-buffer))
6367         (gnus-group-jump-to-group newsgroup))
6368     (save-excursion
6369       ;; Take care of tree window mode.
6370       (if (get-buffer-window gnus-group-buffer)
6371           (pop-to-buffer gnus-group-buffer)
6372         (set-buffer gnus-group-buffer))
6373       (gnus-group-jump-to-group newsgroup))))
6374
6375 ;; This function returns a list of article numbers based on the
6376 ;; difference between the ranges of read articles in this group and
6377 ;; the range of active articles.
6378 (defun gnus-list-of-unread-articles (group)
6379   (let* ((read (gnus-info-read (gnus-get-info group)))
6380          (active (or (gnus-active group) (gnus-activate-group group)))
6381          (last (cdr active))
6382          first nlast unread)
6383     ;; If none are read, then all are unread.
6384     (if (not read)
6385         (setq first (car active))
6386       ;; If the range of read articles is a single range, then the
6387       ;; first unread article is the article after the last read
6388       ;; article.  Sounds logical, doesn't it?
6389       (if (and (not (listp (cdr read)))
6390                (or (< (car read) (car active))
6391                    (progn (setq read (list read))
6392                           nil)))
6393           (setq first (max (car active) (1+ (cdr read))))
6394         ;; `read' is a list of ranges.
6395         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6396                                   (caar read)))
6397                   1)
6398           (setq first (car active)))
6399         (while read
6400           (when first
6401             (while (< first nlast)
6402               (setq unread (cons first unread)
6403                     first (1+ first))))
6404           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6405           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6406           (setq read (cdr read)))))
6407     ;; And add the last unread articles.
6408     (while (<= first last)
6409       (setq unread (cons first unread)
6410             first (1+ first)))
6411     ;; Return the list of unread articles.
6412     (delq 0 (nreverse unread))))
6413
6414 (defun gnus-list-of-read-articles (group)
6415   "Return a list of unread, unticked and non-dormant articles."
6416   (let* ((info (gnus-get-info group))
6417          (marked (gnus-info-marks info))
6418          (active (gnus-active group)))
6419     (and info active
6420          (gnus-list-range-difference
6421           (gnus-list-range-difference
6422            (gnus-sorted-complement
6423             (gnus-uncompress-range active)
6424             (gnus-list-of-unread-articles group))
6425            (cdr (assq 'dormant marked)))
6426           (cdr (assq 'tick marked))))))
6427
6428 ;; This function returns a sequence of article numbers based on the
6429 ;; difference between the ranges of read articles in this group and
6430 ;; the range of active articles.
6431 (defun gnus-sequence-of-unread-articles (group)
6432   (let* ((read (gnus-info-read (gnus-get-info group)))
6433          (active (or (gnus-active group) (gnus-activate-group group)))
6434          (last (cdr active))
6435          first nlast unread)
6436     ;; If none are read, then all are unread.
6437     (if (not read)
6438         (setq first (car active))
6439       ;; If the range of read articles is a single range, then the
6440       ;; first unread article is the article after the last read
6441       ;; article.  Sounds logical, doesn't it?
6442       (if (and (not (listp (cdr read)))
6443                (or (< (car read) (car active))
6444                    (progn (setq read (list read))
6445                           nil)))
6446           (setq first (max (car active) (1+ (cdr read))))
6447         ;; `read' is a list of ranges.
6448         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6449                                   (caar read)))
6450                   1)
6451           (setq first (car active)))
6452         (while read
6453           (when first
6454             (push (cons first nlast) unread))
6455           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6456           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6457           (setq read (cdr read)))))
6458     ;; And add the last unread articles.
6459     (cond ((< first last)
6460            (push (cons first last) unread))
6461           ((= first last)
6462            (push first unread)))
6463     ;; Return the sequence of unread articles.
6464     (delq 0 (nreverse unread))))
6465
6466 ;; Various summary commands
6467
6468 (defun gnus-summary-select-article-buffer ()
6469   "Reconfigure windows to show article buffer."
6470   (interactive)
6471   (if (not (gnus-buffer-live-p gnus-article-buffer))
6472       (error "There is no article buffer for this summary buffer")
6473     (gnus-configure-windows 'article)
6474     (select-window (get-buffer-window gnus-article-buffer))))
6475
6476 (defun gnus-summary-universal-argument (arg)
6477   "Perform any operation on all articles that are process/prefixed."
6478   (interactive "P")
6479   (let ((articles (gnus-summary-work-articles arg))
6480         func article)
6481     (if (eq
6482          (setq
6483           func
6484           (key-binding
6485            (read-key-sequence
6486             (substitute-command-keys
6487              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6488          'undefined)
6489         (gnus-error 1 "Undefined key")
6490       (save-excursion
6491         (while articles
6492           (gnus-summary-goto-subject (setq article (pop articles)))
6493           (let (gnus-newsgroup-processable)
6494             (command-execute func))
6495           (gnus-summary-remove-process-mark article)))))
6496   (gnus-summary-position-point))
6497
6498 (defun gnus-summary-toggle-truncation (&optional arg)
6499   "Toggle truncation of summary lines.
6500 With ARG, turn line truncation on if ARG is positive."
6501   (interactive "P")
6502   (setq truncate-lines
6503         (if (null arg) (not truncate-lines)
6504           (> (prefix-numeric-value arg) 0)))
6505   (redraw-display))
6506
6507 (defun gnus-summary-find-for-reselect ()
6508   "Return the number of an article to stay on across a reselect.
6509 The current article is considered, then following articles, then previous
6510 articles.  An article is sought which is not cancelled and isn't a temporary
6511 insertion from another group.  If there's no such then return a dummy 0."
6512   (let (found)
6513     (dolist (rev '(nil t))
6514       (unless found      ; don't demand the reverse list if we don't need it
6515         (let ((data (gnus-data-find-list
6516                      (gnus-summary-article-number) (gnus-data-list rev))))
6517           (while (and data (not found))
6518             (if (and (< 0 (gnus-data-number (car data)))
6519                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6520                 (setq found (gnus-data-number (car data))))
6521             (setq data (cdr data))))))
6522     (or found 0)))
6523
6524 (defun gnus-summary-reselect-current-group (&optional all rescan)
6525   "Exit and then reselect the current newsgroup.
6526 The prefix argument ALL means to select all articles."
6527   (interactive "P")
6528   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6529     (error "Ephemeral groups can't be reselected"))
6530   (let ((current-subject (gnus-summary-find-for-reselect))
6531         (group gnus-newsgroup-name))
6532     (setq gnus-newsgroup-begin nil)
6533     (gnus-summary-exit nil 'leave-hidden)
6534     ;; We have to adjust the point of group mode buffer because
6535     ;; point was moved to the next unread newsgroup by exiting.
6536     (gnus-summary-jump-to-group group)
6537     (when rescan
6538       (save-excursion
6539         (save-window-excursion
6540           ;; Don't show group contents.
6541           (set-window-start (selected-window) (point-max))
6542           (gnus-group-get-new-news-this-group 1))))
6543     (gnus-group-read-group all t)
6544     (gnus-summary-goto-subject current-subject nil t)))
6545
6546 (defun gnus-summary-rescan-group (&optional all)
6547   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6548   (interactive "P")
6549   (gnus-summary-reselect-current-group all t))
6550
6551 (defun gnus-summary-update-info (&optional non-destructive)
6552   (save-excursion
6553     (let ((group gnus-newsgroup-name))
6554       (when group
6555         (when gnus-newsgroup-kill-headers
6556           (setq gnus-newsgroup-killed
6557                 (gnus-compress-sequence
6558                  (gnus-sorted-union
6559                   (gnus-list-range-intersection
6560                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6561                   gnus-newsgroup-unreads)
6562                  t)))
6563         (unless (listp (cdr gnus-newsgroup-killed))
6564           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6565         (let ((headers gnus-newsgroup-headers))
6566           ;; Set the new ranges of read articles.
6567           (with-current-buffer gnus-group-buffer
6568             (gnus-undo-force-boundary))
6569           (gnus-update-read-articles
6570            group (gnus-sorted-union
6571                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6572           ;; Set the current article marks.
6573           (let ((gnus-newsgroup-scored
6574                  (if (and (not gnus-save-score)
6575                           (not non-destructive))
6576                      nil
6577                    gnus-newsgroup-scored)))
6578             (save-excursion
6579               (gnus-update-marks)))
6580           ;; Do the cross-ref thing.
6581           (when gnus-use-cross-reference
6582             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6583           ;; Do not switch windows but change the buffer to work.
6584           (set-buffer gnus-group-buffer)
6585           (unless (gnus-ephemeral-group-p group)
6586             (gnus-group-update-group group)))))))
6587
6588 (defun gnus-summary-save-newsrc (&optional force)
6589   "Save the current number of read/marked articles in the dribble buffer.
6590 The dribble buffer will then be saved.
6591 If FORCE (the prefix), also save the .newsrc file(s)."
6592   (interactive "P")
6593   (gnus-summary-update-info t)
6594   (if force
6595       (gnus-save-newsrc-file)
6596     (gnus-dribble-save)))
6597
6598 (defun gnus-summary-exit (&optional temporary leave-hidden)
6599   "Exit reading current newsgroup, and then return to group selection mode.
6600 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6601   (interactive)
6602   (gnus-set-global-variables)
6603   (gnus-kill-save-kill-buffer)
6604   (gnus-async-halt-prefetch)
6605   (let* ((group gnus-newsgroup-name)
6606          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6607          (gnus-group-is-exiting-p t)
6608          (mode major-mode)
6609          (group-point nil)
6610          (buf (current-buffer)))
6611     (unless quit-config
6612       ;; Do adaptive scoring, and possibly save score files.
6613       (when gnus-newsgroup-adaptive
6614         (gnus-score-adaptive))
6615       (when gnus-use-scoring
6616         (gnus-score-save)))
6617     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6618     ;; If we have several article buffers, we kill them at exit.
6619     (unless gnus-single-article-buffer
6620       (gnus-kill-buffer gnus-original-article-buffer)
6621       (setq gnus-article-current nil))
6622     (when gnus-use-cache
6623       (gnus-cache-possibly-remove-articles)
6624       (gnus-cache-save-buffers))
6625     (gnus-async-prefetch-remove-group group)
6626     (when gnus-suppress-duplicates
6627       (gnus-dup-enter-articles))
6628     (when gnus-use-trees
6629       (gnus-tree-close group))
6630     (when gnus-use-cache
6631       (gnus-cache-write-active))
6632     ;; Remove entries for this group.
6633     (nnmail-purge-split-history (gnus-group-real-name group))
6634     ;; Make all changes in this group permanent.
6635     (unless quit-config
6636       (gnus-run-hooks 'gnus-exit-group-hook)
6637       (gnus-summary-update-info))
6638     (gnus-close-group group)
6639     ;; Make sure where we were, and go to next newsgroup.
6640     (set-buffer gnus-group-buffer)
6641     (unless quit-config
6642       (gnus-group-jump-to-group group))
6643     (gnus-run-hooks 'gnus-summary-exit-hook)
6644     (unless (or quit-config
6645                 ;; If this group has disappeared from the summary
6646                 ;; buffer, don't skip forwards.
6647                 (not (string= group (gnus-group-group-name))))
6648       (gnus-group-next-unread-group 1))
6649     (setq group-point (point))
6650     (if temporary
6651         nil                             ;Nothing to do.
6652       ;; If we have several article buffers, we kill them at exit.
6653       (unless gnus-single-article-buffer
6654         (gnus-kill-buffer gnus-article-buffer)
6655         (gnus-kill-buffer gnus-original-article-buffer)
6656         (setq gnus-article-current nil))
6657       (set-buffer buf)
6658       (if (not gnus-kill-summary-on-exit)
6659           (progn
6660             (gnus-deaden-summary)
6661             (setq mode nil))
6662         ;; We set all buffer-local variables to nil.  It is unclear why
6663         ;; this is needed, but if we don't, buffer-local variables are
6664         ;; not garbage-collected, it seems.  This would the lead to en
6665         ;; ever-growing Emacs.
6666         (gnus-summary-clear-local-variables)
6667         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6668           (gnus-summary-clear-local-variables))
6669         (when (get-buffer gnus-article-buffer)
6670           (bury-buffer gnus-article-buffer))
6671         ;; We clear the global counterparts of the buffer-local
6672         ;; variables as well, just to be on the safe side.
6673         (set-buffer gnus-group-buffer)
6674         (gnus-summary-clear-local-variables)
6675         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6676           (gnus-summary-clear-local-variables))
6677         ;; Return to group mode buffer.
6678         (when (eq mode 'gnus-summary-mode)
6679           (gnus-kill-buffer buf)))
6680       (setq gnus-current-select-method gnus-select-method)
6681       (if leave-hidden
6682           (set-buffer gnus-group-buffer)
6683         (pop-to-buffer gnus-group-buffer))
6684       (if (not quit-config)
6685           (progn
6686             (goto-char group-point)
6687             (unless leave-hidden
6688               (gnus-configure-windows 'group 'force))
6689             (unless (pos-visible-in-window-p)
6690               (forward-line (/ (static-if (featurep 'xemacs)
6691                                    (window-displayed-height)
6692                                  (1- (window-height)))
6693                                -2))
6694               (set-window-start (selected-window) (point))
6695               (goto-char group-point)))
6696         (gnus-handle-ephemeral-exit quit-config))
6697       ;; Clear the current group name.
6698       (unless quit-config
6699         (setq gnus-newsgroup-name nil)))))
6700
6701 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6702 (defun gnus-summary-exit-no-update (&optional no-questions)
6703   "Quit reading current newsgroup without updating read article info."
6704   (interactive)
6705   (let* ((group gnus-newsgroup-name)
6706          (gnus-group-is-exiting-p t)
6707          (gnus-group-is-exiting-without-update-p t)
6708          (quit-config (gnus-group-quit-config group)))
6709     (when (or no-questions
6710               gnus-expert-user
6711               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6712       (gnus-async-halt-prefetch)
6713       (run-hooks 'gnus-summary-prepare-exit-hook)
6714       ;; If we have several article buffers, we kill them at exit.
6715       (unless gnus-single-article-buffer
6716         (gnus-kill-buffer gnus-article-buffer)
6717         (gnus-kill-buffer gnus-original-article-buffer)
6718         (setq gnus-article-current nil))
6719       (if (not gnus-kill-summary-on-exit)
6720           (gnus-deaden-summary)
6721         (gnus-close-group group)
6722         (gnus-summary-clear-local-variables)
6723         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6724           (gnus-summary-clear-local-variables))
6725         (set-buffer gnus-group-buffer)
6726         (gnus-summary-clear-local-variables)
6727         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6728           (gnus-summary-clear-local-variables))
6729         (gnus-kill-buffer gnus-summary-buffer))
6730       (unless gnus-single-article-buffer
6731         (setq gnus-article-current nil))
6732       (when gnus-use-trees
6733         (gnus-tree-close group))
6734       (gnus-async-prefetch-remove-group group)
6735       (when (get-buffer gnus-article-buffer)
6736         (bury-buffer gnus-article-buffer))
6737       ;; Return to the group buffer.
6738       (gnus-configure-windows 'group 'force)
6739       ;; Clear the current group name.
6740       (setq gnus-newsgroup-name nil)
6741       (unless (gnus-ephemeral-group-p group)
6742         (gnus-group-update-group group))
6743       (when (equal (gnus-group-group-name) group)
6744         (gnus-group-next-unread-group 1))
6745       (when quit-config
6746         (gnus-handle-ephemeral-exit quit-config)))))
6747
6748 (defun gnus-handle-ephemeral-exit (quit-config)
6749   "Handle movement when leaving an ephemeral group.
6750 The state which existed when entering the ephemeral is reset."
6751   (if (not (buffer-name (car quit-config)))
6752       (gnus-configure-windows 'group 'force)
6753     (set-buffer (car quit-config))
6754     (cond ((eq major-mode 'gnus-summary-mode)
6755            (gnus-set-global-variables))
6756           ((eq major-mode 'gnus-article-mode)
6757            (save-excursion
6758              ;; The `gnus-summary-buffer' variable may point
6759              ;; to the old summary buffer when using a single
6760              ;; article buffer.
6761              (unless (gnus-buffer-live-p gnus-summary-buffer)
6762                (set-buffer gnus-group-buffer))
6763              (set-buffer gnus-summary-buffer)
6764              (gnus-set-global-variables))))
6765     (if (or (eq (cdr quit-config) 'article)
6766             (eq (cdr quit-config) 'pick))
6767         (progn
6768           ;; The current article may be from the ephemeral group
6769           ;; thus it is best that we reload this article
6770           ;;
6771           ;; If we're exiting from a large digest, this can be
6772           ;; extremely slow.  So, it's better not to reload it. -- jh.
6773           ;;(gnus-summary-show-article)
6774           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6775               (gnus-configure-windows 'pick 'force)
6776             (gnus-configure-windows (cdr quit-config) 'force)))
6777       (gnus-configure-windows (cdr quit-config) 'force))
6778     (when (eq major-mode 'gnus-summary-mode)
6779       (gnus-summary-next-subject 1 nil t)
6780       (gnus-summary-recenter)
6781       (gnus-summary-position-point))))
6782
6783 (defun gnus-summary-preview-mime-message ()
6784   "MIME decode and play this message."
6785   (interactive)
6786   (let ((gnus-break-pages nil)
6787         (gnus-show-mime t))
6788     (gnus-summary-select-article gnus-show-all-headers t))
6789   (let ((w (get-buffer-window gnus-article-buffer)))
6790     (when w
6791       (select-window (get-buffer-window gnus-article-buffer)))))
6792
6793 ;;; Dead summaries.
6794
6795 (defvar gnus-dead-summary-mode-map nil)
6796
6797 (unless gnus-dead-summary-mode-map
6798   (setq gnus-dead-summary-mode-map (make-keymap))
6799   (suppress-keymap gnus-dead-summary-mode-map)
6800   (substitute-key-definition
6801    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6802   (dolist (key '("\C-d" "\r" "\177" [delete]))
6803     (define-key gnus-dead-summary-mode-map
6804       key 'gnus-summary-wake-up-the-dead))
6805   (dolist (key '("q" "Q"))
6806     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6807
6808 (defvar gnus-dead-summary-mode nil
6809   "Minor mode for Gnus summary buffers.")
6810
6811 (defun gnus-dead-summary-mode (&optional arg)
6812   "Minor mode for Gnus summary buffers."
6813   (interactive "P")
6814   (when (eq major-mode 'gnus-summary-mode)
6815     (make-local-variable 'gnus-dead-summary-mode)
6816     (setq gnus-dead-summary-mode
6817           (if (null arg) (not gnus-dead-summary-mode)
6818             (> (prefix-numeric-value arg) 0)))
6819     (when gnus-dead-summary-mode
6820       (add-minor-mode
6821        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6822
6823 (defun gnus-deaden-summary ()
6824   "Make the current summary buffer into a dead summary buffer."
6825   ;; Kill any previous dead summary buffer.
6826   (when (and gnus-dead-summary
6827              (buffer-name gnus-dead-summary))
6828     (with-current-buffer gnus-dead-summary
6829       (when gnus-dead-summary-mode
6830         (kill-buffer (current-buffer)))))
6831   ;; Make this the current dead summary.
6832   (setq gnus-dead-summary (current-buffer))
6833   (gnus-dead-summary-mode 1)
6834   (let ((name (buffer-name)))
6835     (when (string-match "Summary" name)
6836       (rename-buffer
6837        (concat (substring name 0 (match-beginning 0)) "Dead "
6838                (substring name (match-beginning 0)))
6839        t)
6840       (bury-buffer))))
6841
6842 (defun gnus-kill-or-deaden-summary (buffer)
6843   "Kill or deaden the summary BUFFER."
6844   (save-excursion
6845     (when (and (buffer-name buffer)
6846                (not gnus-single-article-buffer))
6847       (with-current-buffer buffer
6848         (gnus-kill-buffer gnus-article-buffer)
6849         (gnus-kill-buffer gnus-original-article-buffer)))
6850     (cond
6851      ;; Kill the buffer.
6852      (gnus-kill-summary-on-exit
6853       (when (and gnus-use-trees
6854                  (gnus-buffer-exists-p buffer))
6855         (save-excursion
6856           (set-buffer buffer)
6857           (gnus-tree-close gnus-newsgroup-name)))
6858       (gnus-kill-buffer buffer))
6859      ;; Deaden the buffer.
6860      ((gnus-buffer-exists-p buffer)
6861       (save-excursion
6862         (set-buffer buffer)
6863         (gnus-deaden-summary))))))
6864
6865 (defun gnus-summary-wake-up-the-dead (&rest args)
6866   "Wake up the dead summary buffer."
6867   (interactive)
6868   (gnus-dead-summary-mode -1)
6869   (let ((name (buffer-name)))
6870     (when (string-match "Dead " name)
6871       (rename-buffer
6872        (concat (substring name 0 (match-beginning 0))
6873                (substring name (match-end 0)))
6874        t)))
6875   (gnus-message 3 "This dead summary is now alive again"))
6876
6877 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6878 (defun gnus-summary-fetch-faq (&optional faq-dir)
6879   "Fetch the FAQ for the current group.
6880 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6881 in."
6882   (interactive
6883    (list
6884     (when current-prefix-arg
6885       (completing-read
6886        "FAQ dir: " (and (listp gnus-group-faq-directory)
6887                         (mapcar 'list
6888                                 gnus-group-faq-directory))))))
6889   (let (gnus-faq-buffer)
6890     (when (setq gnus-faq-buffer
6891                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6892       (gnus-configure-windows 'summary-faq))))
6893
6894 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6895 (defun gnus-summary-describe-group (&optional force)
6896   "Describe the current newsgroup."
6897   (interactive "P")
6898   (gnus-group-describe-group force gnus-newsgroup-name))
6899
6900 (defun gnus-summary-describe-briefly ()
6901   "Describe summary mode commands briefly."
6902   (interactive)
6903   (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")))
6904
6905 ;; Walking around group mode buffer from summary mode.
6906
6907 (defun gnus-summary-next-group (&optional no-article target-group backward)
6908   "Exit current newsgroup and then select next unread newsgroup.
6909 If prefix argument NO-ARTICLE is non-nil, no article is selected
6910 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6911 previous group instead."
6912   (interactive "P")
6913   ;; Stop pre-fetching.
6914   (gnus-async-halt-prefetch)
6915   (let ((current-group gnus-newsgroup-name)
6916         (current-buffer (current-buffer))
6917         entered)
6918     ;; First we semi-exit this group to update Xrefs and all variables.
6919     ;; We can't do a real exit, because the window conf must remain
6920     ;; the same in case the user is prompted for info, and we don't
6921     ;; want the window conf to change before that...
6922     (gnus-summary-exit t)
6923     (while (not entered)
6924       ;; Then we find what group we are supposed to enter.
6925       (set-buffer gnus-group-buffer)
6926       (gnus-group-jump-to-group current-group)
6927       (setq target-group
6928             (or target-group
6929                 (if (eq gnus-keep-same-level 'best)
6930                     (gnus-summary-best-group gnus-newsgroup-name)
6931                   (gnus-summary-search-group backward gnus-keep-same-level))))
6932       (if (not target-group)
6933           ;; There are no further groups, so we return to the group
6934           ;; buffer.
6935           (progn
6936             (gnus-message 5 "Returning to the group buffer")
6937             (setq entered t)
6938             (when (gnus-buffer-live-p current-buffer)
6939               (set-buffer current-buffer)
6940               (gnus-summary-exit))
6941             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6942         ;; We try to enter the target group.
6943         (gnus-group-jump-to-group target-group)
6944         (let ((unreads (gnus-group-group-unread)))
6945           (if (and (or (eq t unreads)
6946                        (and unreads (not (zerop unreads))))
6947                    (gnus-summary-read-group
6948                     target-group nil no-article
6949                     (and (buffer-name current-buffer) current-buffer)
6950                     nil backward))
6951               (setq entered t)
6952             (setq current-group target-group
6953                   target-group nil)))))))
6954
6955 (defun gnus-summary-prev-group (&optional no-article)
6956   "Exit current newsgroup and then select previous unread newsgroup.
6957 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6958   (interactive "P")
6959   (gnus-summary-next-group no-article nil t))
6960
6961 ;; Walking around summary lines.
6962
6963 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6964   "Go to the first subject satisfying any non-nil constraint.
6965 If UNREAD is non-nil, the article should be unread.
6966 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6967 If UNSEEN is non-nil, the article should be unseen.
6968 Returns the article selected or nil if there are no matching articles."
6969   (interactive "P")
6970   (cond
6971    ;; Empty summary.
6972    ((null gnus-newsgroup-data)
6973     (gnus-message 3 "No articles in the group")
6974     nil)
6975    ;; Pick the first article.
6976    ((not (or unread undownloaded unseen))
6977     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6978     (gnus-data-number (car gnus-newsgroup-data)))
6979    ;; Find the first unread article.
6980    (t
6981     (let ((data gnus-newsgroup-data))
6982       (while (and data
6983                   (let ((num (gnus-data-number (car data))))
6984                     (or (memq num gnus-newsgroup-unfetched)
6985                         (not (or (and unread
6986                                       (memq num gnus-newsgroup-unreads))
6987                                  (and undownloaded
6988                                       (memq num gnus-newsgroup-undownloaded))
6989                                  (and unseen
6990                                       (memq num gnus-newsgroup-unseen)))))))
6991         (setq data (cdr data)))
6992       (prog1
6993           (if data
6994               (progn
6995                 (goto-char (gnus-data-pos (car data)))
6996                 (gnus-data-number (car data)))
6997             (gnus-message 3 "No more%s articles"
6998                           (let* ((r (when unread " unread"))
6999                                  (d (when undownloaded " undownloaded"))
7000                                  (s (when unseen " unseen"))
7001                                  (l (delq nil (list r d s))))
7002                             (cond ((= 3 (length l))
7003                                    (concat r "," d ", or" s))
7004                                   ((= 2 (length l))
7005                                    (concat (car l) ", or" (cadr l)))
7006                                   ((= 1 (length l))
7007                                    (car l))
7008                                   (t
7009                                    ""))))
7010             nil
7011             )
7012         (gnus-summary-position-point))))))
7013
7014 (defun gnus-summary-next-subject (n &optional unread dont-display)
7015   "Go to next N'th summary line.
7016 If N is negative, go to the previous N'th subject line.
7017 If UNREAD is non-nil, only unread articles are selected.
7018 The difference between N and the actual number of steps taken is
7019 returned."
7020   (interactive "p")
7021   (let ((backward (< n 0))
7022         (n (abs n)))
7023     (while (and (> n 0)
7024                 (if backward
7025                     (gnus-summary-find-prev unread)
7026                   (gnus-summary-find-next unread)))
7027       (unless (zerop (setq n (1- n)))
7028         (gnus-summary-show-thread)))
7029     (when (/= 0 n)
7030       (gnus-message 7 "No more%s articles"
7031                     (if unread " unread" "")))
7032     (unless dont-display
7033       (gnus-summary-recenter)
7034       (gnus-summary-position-point))
7035     n))
7036
7037 (defun gnus-summary-next-unread-subject (n)
7038   "Go to next N'th unread summary line."
7039   (interactive "p")
7040   (gnus-summary-next-subject n t))
7041
7042 (defun gnus-summary-prev-subject (n &optional unread)
7043   "Go to previous N'th summary line.
7044 If optional argument UNREAD is non-nil, only unread article is selected."
7045   (interactive "p")
7046   (gnus-summary-next-subject (- n) unread))
7047
7048 (defun gnus-summary-prev-unread-subject (n)
7049   "Go to previous N'th unread summary line."
7050   (interactive "p")
7051   (gnus-summary-next-subject (- n) t))
7052
7053 (defun gnus-summary-goto-subjects (articles)
7054   "Insert the subject header for ARTICLES in the current buffer."
7055   (save-excursion
7056     (dolist (article articles)
7057       (gnus-summary-goto-subject article t)))
7058   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7059   (gnus-summary-position-point))
7060  
7061 (defun gnus-summary-goto-subject (article &optional force silent)
7062   "Go the subject line of ARTICLE.
7063 If FORCE, also allow jumping to articles not currently shown."
7064   (interactive "nArticle number: ")
7065   (unless (numberp article)
7066     (error "Article %s is not a number" article))
7067   (let ((b (point))
7068         (data (gnus-data-find article)))
7069     ;; We read in the article if we have to.
7070     (and (not data)
7071          force
7072          (gnus-summary-insert-subject
7073           article
7074           (if (or (numberp force) (vectorp force)) force)
7075           t)
7076          (setq data (gnus-data-find article)))
7077     (goto-char b)
7078     (if (not data)
7079         (progn
7080           (unless silent
7081             (gnus-message 3 "Can't find article %d" article))
7082           nil)
7083       (let ((pt (gnus-data-pos data)))
7084         (goto-char pt)
7085         (gnus-summary-set-article-display-arrow pt))
7086       (gnus-summary-position-point)
7087       article)))
7088
7089 ;; Walking around summary lines with displaying articles.
7090
7091 (defun gnus-summary-expand-window (&optional arg)
7092   "Make the summary buffer take up the entire Emacs frame.
7093 Given a prefix, will force an `article' buffer configuration."
7094   (interactive "P")
7095   (if arg
7096       (gnus-configure-windows 'article 'force)
7097     (gnus-configure-windows 'summary 'force)))
7098
7099 (defun gnus-summary-display-article (article &optional all-header)
7100   "Display ARTICLE in article buffer."
7101   (when (gnus-buffer-live-p gnus-article-buffer)
7102     (with-current-buffer gnus-article-buffer
7103       (set-buffer-multibyte t)))
7104   (gnus-set-global-variables)
7105   (when (gnus-buffer-live-p gnus-article-buffer)
7106     (with-current-buffer gnus-article-buffer
7107       (setq gnus-article-charset gnus-newsgroup-charset)
7108       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7109       (set-buffer-multibyte t)))
7110   (if (null article)
7111       nil
7112     (prog1
7113         (if gnus-summary-display-article-function
7114             (funcall gnus-summary-display-article-function article all-header)
7115           (gnus-article-prepare article all-header))
7116       (with-current-buffer gnus-article-buffer
7117         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7118              nil))
7119       (gnus-run-hooks 'gnus-select-article-hook)
7120       (when (and gnus-current-article
7121                  (not (zerop gnus-current-article)))
7122         (gnus-summary-goto-subject gnus-current-article))
7123       (gnus-summary-recenter)
7124       (when (and gnus-use-trees gnus-show-threads)
7125         (gnus-possibly-generate-tree article)
7126         (gnus-highlight-selected-tree article))
7127       ;; Successfully display article.
7128       (gnus-article-set-window-start
7129        (cdr (assq article gnus-newsgroup-bookmarks))))))
7130
7131 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7132   "Select the current article.
7133 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7134 non-nil, the article will be re-fetched even if it already present in
7135 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7136 be displayed."
7137   ;; Make sure we are in the summary buffer to work around bbdb bug.
7138   (unless (eq major-mode 'gnus-summary-mode)
7139     (set-buffer gnus-summary-buffer))
7140   (let ((article (or article (gnus-summary-article-number)))
7141         (all-headers (not (not all-headers))) ;Must be T or NIL.
7142         gnus-summary-display-article-function)
7143     (and (not pseudo)
7144          (gnus-summary-article-pseudo-p article)
7145          (error "This is a pseudo-article"))
7146     (save-excursion
7147       (set-buffer gnus-summary-buffer)
7148       (if (or (and gnus-single-article-buffer
7149                    (or (null gnus-current-article)
7150                        (null gnus-article-current)
7151                        (null (get-buffer gnus-article-buffer))
7152                        (not (eq article (cdr gnus-article-current)))
7153                        (not (equal (car gnus-article-current)
7154                                    gnus-newsgroup-name))))
7155               (and (not gnus-single-article-buffer)
7156                    (or (null gnus-current-article)
7157                        (not (eq gnus-current-article article))))
7158               force)
7159           ;; The requested article is different from the current article.
7160           (progn
7161             (gnus-summary-display-article article all-headers)
7162             (gnus-article-set-window-start
7163              (cdr (assq article gnus-newsgroup-bookmarks)))
7164             article)
7165         'old))))
7166
7167 (defun gnus-summary-force-verify-and-decrypt ()
7168   "Display buttons for signed/encrypted parts and verify/decrypt them."
7169   (interactive)
7170   (let ((mm-verify-option 'known)
7171         (mm-decrypt-option 'known)
7172         (gnus-article-emulate-mime t)
7173         (gnus-buttonized-mime-types (append (list "multipart/signed"
7174                                                   "multipart/encrypted")
7175                                             gnus-buttonized-mime-types)))
7176     (gnus-summary-select-article nil 'force)))
7177
7178 (defun gnus-summary-set-current-mark (&optional current-mark)
7179   "Obsolete function."
7180   nil)
7181
7182 (defun gnus-summary-next-article (&optional unread subject backward push)
7183   "Select the next article.
7184 If UNREAD, only unread articles are selected.
7185 If SUBJECT, only articles with SUBJECT are selected.
7186 If BACKWARD, the previous article is selected instead of the next."
7187   (interactive "P")
7188   (cond
7189    ;; Is there such an article?
7190    ((and (gnus-summary-search-forward unread subject backward)
7191          (or (gnus-summary-display-article (gnus-summary-article-number))
7192              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7193     (gnus-summary-position-point))
7194    ;; If not, we try the first unread, if that is wanted.
7195    ((and subject
7196          gnus-auto-select-same
7197          (gnus-summary-first-unread-article))
7198     (gnus-summary-position-point)
7199     (gnus-message 6 "Wrapped"))
7200    ;; Try to get next/previous article not displayed in this group.
7201    ((and gnus-auto-extend-newsgroup
7202          (not unread) (not subject))
7203     (gnus-summary-goto-article
7204      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7205      nil (count-lines (point-min) (point))))
7206    ;; Go to next/previous group.
7207    (t
7208     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7209       (gnus-summary-jump-to-group gnus-newsgroup-name))
7210     (let ((cmd last-command-char)
7211           (point
7212            (with-current-buffer gnus-group-buffer
7213              (point)))
7214           (group
7215            (if (eq gnus-keep-same-level 'best)
7216                (gnus-summary-best-group gnus-newsgroup-name)
7217              (gnus-summary-search-group backward gnus-keep-same-level))))
7218       ;; For some reason, the group window gets selected.  We change
7219       ;; it back.
7220       (select-window (get-buffer-window (current-buffer)))
7221       ;; Select next unread newsgroup automagically.
7222       (cond
7223        ((or (not gnus-auto-select-next)
7224             (not cmd))
7225         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7226        ((or (eq gnus-auto-select-next 'quietly)
7227             (and (eq gnus-auto-select-next 'slightly-quietly)
7228                  push)
7229             (and (eq gnus-auto-select-next 'almost-quietly)
7230                  (gnus-summary-last-article-p)))
7231         ;; Select quietly.
7232         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7233             (gnus-summary-exit)
7234           (gnus-message 7 "No more%s articles (%s)..."
7235                         (if unread " unread" "")
7236                         (if group (concat "selecting " group)
7237                           "exiting"))
7238           (gnus-summary-next-group nil group backward)))
7239        (t
7240         (when (gnus-key-press-event-p last-input-event)
7241           (gnus-summary-walk-group-buffer
7242            gnus-newsgroup-name cmd unread backward point))))))))
7243
7244 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7245   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7246                       (?\C-p (gnus-group-prev-unread-group 1))))
7247         (cursor-in-echo-area t)
7248         keve key group ended prompt)
7249     (save-excursion
7250       (set-buffer gnus-group-buffer)
7251       (goto-char start)
7252       (setq group
7253             (if (eq gnus-keep-same-level 'best)
7254                 (gnus-summary-best-group gnus-newsgroup-name)
7255               (gnus-summary-search-group backward gnus-keep-same-level))))
7256     (while (not ended)
7257       (setq prompt
7258             (format
7259              "No more%s articles%s " (if unread " unread" "")
7260              (if (and group
7261                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7262                  (format " (Type %s for %s [%s])"
7263                          (single-key-description cmd) group
7264                          (gnus-group-unread group))
7265                (format " (Type %s to exit %s)"
7266                        (single-key-description cmd)
7267                        gnus-newsgroup-name))))
7268       ;; Confirm auto selection.
7269       (setq key (car (setq keve (gnus-read-event-char prompt)))
7270             ended t)
7271       (cond
7272        ((assq key keystrokes)
7273         (let ((obuf (current-buffer)))
7274           (switch-to-buffer gnus-group-buffer)
7275           (when group
7276             (gnus-group-jump-to-group group))
7277           (eval (cadr (assq key keystrokes)))
7278           (setq group (gnus-group-group-name))
7279           (switch-to-buffer obuf))
7280         (setq ended nil))
7281        ((equal key cmd)
7282         (if (or (not group)
7283                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7284             (gnus-summary-exit)
7285           (gnus-summary-next-group nil group backward)))
7286        (t
7287         (push (cdr keve) unread-command-events))))))
7288
7289 (defun gnus-summary-next-unread-article ()
7290   "Select unread article after current one."
7291   (interactive)
7292   (gnus-summary-next-article
7293    (or (not (eq gnus-summary-goto-unread 'never))
7294        (gnus-summary-last-article-p (gnus-summary-article-number)))
7295    (and gnus-auto-select-same
7296         (gnus-summary-article-subject))))
7297
7298 (defun gnus-summary-prev-article (&optional unread subject)
7299   "Select the article after the current one.
7300 If UNREAD is non-nil, only unread articles are selected."
7301   (interactive "P")
7302   (gnus-summary-next-article unread subject t))
7303
7304 (defun gnus-summary-prev-unread-article ()
7305   "Select unread article before current one."
7306   (interactive)
7307   (gnus-summary-prev-article
7308    (or (not (eq gnus-summary-goto-unread 'never))
7309        (gnus-summary-first-article-p (gnus-summary-article-number)))
7310    (and gnus-auto-select-same
7311         (gnus-summary-article-subject))))
7312
7313 (defun gnus-summary-next-page (&optional lines circular stop)
7314   "Show next page of the selected article.
7315 If at the end of the current article, select the next article.
7316 LINES says how many lines should be scrolled up.
7317
7318 If CIRCULAR is non-nil, go to the start of the article instead of
7319 selecting the next article when reaching the end of the current
7320 article.
7321
7322 If STOP is non-nil, just stop when reaching the end of the message.
7323
7324 Also see the variable `gnus-article-skip-boring'."
7325   (interactive "P")
7326   (setq gnus-summary-buffer (current-buffer))
7327   (gnus-set-global-variables)
7328   (let ((article (gnus-summary-article-number))
7329         (article-window (get-buffer-window gnus-article-buffer t))
7330         endp)
7331     ;; If the buffer is empty, we have no article.
7332     (unless article
7333       (error "No article to select"))
7334     (gnus-configure-windows 'article)
7335     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7336         (if (and (eq gnus-summary-goto-unread 'never)
7337                  (not (gnus-summary-last-article-p article)))
7338             (gnus-summary-next-article)
7339           (gnus-summary-next-unread-article))
7340       (if (or (null gnus-current-article)
7341               (null gnus-article-current)
7342               (/= article (cdr gnus-article-current))
7343               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7344           ;; Selected subject is different from current article's.
7345           (gnus-summary-display-article article)
7346         (when article-window
7347           (gnus-eval-in-buffer-window gnus-article-buffer
7348             (setq endp (or (gnus-article-next-page lines)
7349                            (gnus-article-only-boring-p))))
7350           (when endp
7351             (cond (stop
7352                    (gnus-message 3 "End of message"))
7353                   (circular
7354                    (gnus-summary-beginning-of-article))
7355                   (lines
7356                    (gnus-message 3 "End of message"))
7357                   ((null lines)
7358                    (if (and (eq gnus-summary-goto-unread 'never)
7359                             (not (gnus-summary-last-article-p article)))
7360                        (gnus-summary-next-article)
7361                      (gnus-summary-next-unread-article))))))))
7362     (gnus-summary-recenter)
7363     (gnus-summary-position-point)))
7364
7365 (defun gnus-summary-prev-page (&optional lines move)
7366   "Show previous page of selected article.
7367 Argument LINES specifies lines to be scrolled down.
7368 If MOVE, move to the previous unread article if point is at
7369 the beginning of the buffer."
7370   (interactive "P")
7371   (let ((article (gnus-summary-article-number))
7372         (article-window (get-buffer-window gnus-article-buffer t))
7373         endp)
7374     (gnus-configure-windows 'article)
7375     (if (or (null gnus-current-article)
7376             (null gnus-article-current)
7377             (/= article (cdr gnus-article-current))
7378             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7379         ;; Selected subject is different from current article's.
7380         (gnus-summary-display-article article)
7381       (gnus-summary-recenter)
7382       (when article-window
7383         (gnus-eval-in-buffer-window gnus-article-buffer
7384           (setq endp (gnus-article-prev-page lines)))
7385         (when (and move endp)
7386           (cond (lines
7387                  (gnus-message 3 "Beginning of message"))
7388                 ((null lines)
7389                  (if (and (eq gnus-summary-goto-unread 'never)
7390                           (not (gnus-summary-first-article-p article)))
7391                      (gnus-summary-prev-article)
7392                    (gnus-summary-prev-unread-article))))))))
7393   (gnus-summary-position-point))
7394
7395 (defun gnus-summary-prev-page-or-article (&optional lines)
7396   "Show previous page of selected article.
7397 Argument LINES specifies lines to be scrolled down.
7398 If at the beginning of the article, go to the next article."
7399   (interactive "P")
7400   (gnus-summary-prev-page lines t))
7401
7402 (defun gnus-summary-scroll-up (lines)
7403   "Scroll up (or down) one line current article.
7404 Argument LINES specifies lines to be scrolled up (or down if negative)."
7405   (interactive "p")
7406   (gnus-configure-windows 'article)
7407   (gnus-summary-show-thread)
7408   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7409     (gnus-eval-in-buffer-window gnus-article-buffer
7410       (cond ((> lines 0)
7411              (when (gnus-article-next-page lines)
7412                (gnus-message 3 "End of message")))
7413             ((< lines 0)
7414              (gnus-article-prev-page (- lines))))))
7415   (gnus-summary-recenter)
7416   (gnus-summary-position-point))
7417
7418 (defun gnus-summary-scroll-down (lines)
7419   "Scroll down (or up) one line current article.
7420 Argument LINES specifies lines to be scrolled down (or up if negative)."
7421   (interactive "p")
7422   (gnus-summary-scroll-up (- lines)))
7423
7424 (defun gnus-summary-next-same-subject ()
7425   "Select next article which has the same subject as current one."
7426   (interactive)
7427   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7428
7429 (defun gnus-summary-prev-same-subject ()
7430   "Select previous article which has the same subject as current one."
7431   (interactive)
7432   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7433
7434 (defun gnus-summary-next-unread-same-subject ()
7435   "Select next unread article which has the same subject as current one."
7436   (interactive)
7437   (gnus-summary-next-article t (gnus-summary-article-subject)))
7438
7439 (defun gnus-summary-prev-unread-same-subject ()
7440   "Select previous unread article which has the same subject as current one."
7441   (interactive)
7442   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7443
7444 (defun gnus-summary-first-unread-article ()
7445   "Select the first unread article.
7446 Return nil if there are no unread articles."
7447   (interactive)
7448   (prog1
7449       (when (gnus-summary-first-subject t)
7450         (gnus-summary-show-thread)
7451         (gnus-summary-first-subject t)
7452         (gnus-summary-display-article (gnus-summary-article-number)))
7453     (gnus-summary-position-point)))
7454
7455 (defun gnus-summary-first-unread-subject ()
7456   "Place the point on the subject line of the first unread article.
7457 Return nil if there are no unread articles."
7458   (interactive)
7459   (prog1
7460       (when (gnus-summary-first-subject t)
7461         (gnus-summary-show-thread)
7462         (gnus-summary-first-subject t))
7463     (gnus-summary-position-point)))
7464
7465 (defun gnus-summary-first-unseen-subject ()
7466   "Place the point on the subject line of the first unseen article.
7467 Return nil if there are no unseen articles."
7468   (interactive)
7469   (prog1
7470       (when (gnus-summary-first-subject nil nil t)
7471         (gnus-summary-show-thread)
7472         (gnus-summary-first-subject nil nil t))
7473     (gnus-summary-position-point)))
7474
7475 (defun gnus-summary-first-unseen-or-unread-subject ()
7476   "Place the point on the subject line of the first unseen article or,
7477 if all article have been seen, on the subject line of the first unread
7478 article."
7479   (interactive)
7480   (prog1
7481       (unless (when (gnus-summary-first-subject nil nil t)
7482                 (gnus-summary-show-thread)
7483                 (gnus-summary-first-subject nil nil t))
7484         (when (gnus-summary-first-subject t)
7485           (gnus-summary-show-thread)
7486           (gnus-summary-first-subject t)))
7487     (gnus-summary-position-point)))
7488
7489 (defun gnus-summary-first-article ()
7490   "Select the first article.
7491 Return nil if there are no articles."
7492   (interactive)
7493   (prog1
7494       (when (gnus-summary-first-subject)
7495         (gnus-summary-show-thread)
7496         (gnus-summary-first-subject)
7497         (gnus-summary-display-article (gnus-summary-article-number)))
7498     (gnus-summary-position-point)))
7499
7500 (defun gnus-summary-best-unread-article (&optional arg)
7501   "Select the unread article with the highest score.
7502 If given a prefix argument, select the next unread article that has a
7503 score higher than the default score."
7504   (interactive "P")
7505   (let ((article (if arg
7506                      (gnus-summary-better-unread-subject)
7507                    (gnus-summary-best-unread-subject))))
7508     (if article
7509         (gnus-summary-goto-article article)
7510       (error "No unread articles"))))
7511
7512 (defun gnus-summary-best-unread-subject ()
7513   "Select the unread subject with the highest score."
7514   (interactive)
7515   (let ((best -1000000)
7516         (data gnus-newsgroup-data)
7517         article score)
7518     (while data
7519       (and (gnus-data-unread-p (car data))
7520            (> (setq score
7521                     (gnus-summary-article-score (gnus-data-number (car data))))
7522               best)
7523            (setq best score
7524                  article (gnus-data-number (car data))))
7525       (setq data (cdr data)))
7526     (when article
7527       (gnus-summary-goto-subject article))
7528     (gnus-summary-position-point)
7529     article))
7530
7531 (defun gnus-summary-better-unread-subject ()
7532   "Select the first unread subject that has a score over the default score."
7533   (interactive)
7534   (let ((data gnus-newsgroup-data)
7535         article score)
7536     (while (and (setq article (gnus-data-number (car data)))
7537                 (or (gnus-data-read-p (car data))
7538                     (not (> (gnus-summary-article-score article)
7539                             gnus-summary-default-score))))
7540       (setq data (cdr data)))
7541     (when article
7542       (gnus-summary-goto-subject article))
7543     (gnus-summary-position-point)
7544     article))
7545
7546 (defun gnus-summary-last-subject ()
7547   "Go to the last displayed subject line in the group."
7548   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7549     (when article
7550       (gnus-summary-goto-subject article))))
7551
7552 (defun gnus-summary-goto-article (article &optional all-headers force)
7553   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7554 If ALL-HEADERS is non-nil, no header lines are hidden.
7555 If FORCE, go to the article even if it isn't displayed.  If FORCE
7556 is a number, it is the line the article is to be displayed on."
7557   (interactive
7558    (list
7559     (completing-read
7560      "Article number or Message-ID: "
7561      (mapcar (lambda (number) (list (int-to-string number)))
7562              gnus-newsgroup-limit))
7563     current-prefix-arg
7564     t))
7565   (prog1
7566       (if (and (stringp article)
7567                (string-match "@\\|%40" article))
7568           (gnus-summary-refer-article article)
7569         (when (stringp article)
7570           (setq article (string-to-number article)))
7571         (if (gnus-summary-goto-subject article force)
7572             (gnus-summary-display-article article all-headers)
7573           (gnus-message 4 "Couldn't go to article %s" article) nil))
7574     (gnus-summary-position-point)))
7575
7576 (defun gnus-summary-goto-last-article ()
7577   "Go to the previously read article."
7578   (interactive)
7579   (prog1
7580       (when gnus-last-article
7581         (gnus-summary-goto-article gnus-last-article nil t))
7582     (gnus-summary-position-point)))
7583
7584 (defun gnus-summary-pop-article (number)
7585   "Pop one article off the history and go to the previous.
7586 NUMBER articles will be popped off."
7587   (interactive "p")
7588   (let (to)
7589     (setq gnus-newsgroup-history
7590           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7591     (if to
7592         (gnus-summary-goto-article (car to) nil t)
7593       (error "Article history empty")))
7594   (gnus-summary-position-point))
7595
7596 ;; Summary commands and functions for limiting the summary buffer.
7597
7598 (defun gnus-summary-limit-to-articles (n)
7599   "Limit the summary buffer to the next N articles.
7600 If not given a prefix, use the process marked articles instead."
7601   (interactive "P")
7602   (prog1
7603       (let ((articles (gnus-summary-work-articles n)))
7604         (setq gnus-newsgroup-processable nil)
7605         (gnus-summary-limit articles))
7606     (gnus-summary-position-point)))
7607
7608 (defun gnus-summary-pop-limit (&optional total)
7609   "Restore the previous limit.
7610 If given a prefix, remove all limits."
7611   (interactive "P")
7612   (when total
7613     (setq gnus-newsgroup-limits
7614           (list (mapcar (lambda (h) (mail-header-number h))
7615                         gnus-newsgroup-headers))))
7616   (unless gnus-newsgroup-limits
7617     (error "No limit to pop"))
7618   (prog1
7619       (gnus-summary-limit nil 'pop)
7620     (gnus-summary-position-point)))
7621
7622 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7623   "Limit the summary buffer to articles that have subjects that match a regexp.
7624 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7625   (interactive
7626    (list (read-string (if current-prefix-arg
7627                           "Exclude subject (regexp): "
7628                         "Limit to subject (regexp): "))
7629          nil current-prefix-arg))
7630   (unless header
7631     (setq header "subject"))
7632   (when (not (equal "" subject))
7633     (prog1
7634         (let ((articles (gnus-summary-find-matching
7635                          (or header "subject") subject 'all nil nil
7636                          not-matching)))
7637           (unless articles
7638             (error "Found no matches for \"%s\"" subject))
7639           (gnus-summary-limit articles))
7640       (gnus-summary-position-point))))
7641
7642 (defun gnus-summary-limit-to-author (from &optional not-matching)
7643   "Limit the summary buffer to articles that have authors that match a regexp.
7644 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7645   (interactive
7646    (list (read-string (if current-prefix-arg
7647                           "Exclude author (regexp): "
7648                         "Limit to author (regexp): "))
7649          current-prefix-arg))
7650   (gnus-summary-limit-to-subject from "from" not-matching))
7651
7652 (defun gnus-summary-limit-to-age (age &optional younger-p)
7653   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7654 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7655 articles that are younger than AGE days."
7656   (interactive
7657    (let ((younger current-prefix-arg)
7658          (days-got nil)
7659          days)
7660      (while (not days-got)
7661        (setq days (if younger
7662                       (read-string "Limit to articles younger than (in days, older when negative): ")
7663                     (read-string
7664                      "Limit to articles older than (in days, younger when negative): ")))
7665        (when (> (length days) 0)
7666          (setq days (read days)))
7667        (if (numberp days)
7668            (progn
7669              (setq days-got t)
7670              (when (< days 0)
7671                (setq younger (not younger))
7672                (setq days (* days -1))))
7673          (message "Please enter a number.")
7674          (sleep-for 1)))
7675      (list days younger)))
7676   (prog1
7677       (let ((data gnus-newsgroup-data)
7678             (cutoff (days-to-time age))
7679             articles d date is-younger)
7680         (while (setq d (pop data))
7681           (when (and (vectorp (gnus-data-header d))
7682                      (setq date (mail-header-date (gnus-data-header d))))
7683             (setq is-younger (time-less-p
7684                               (time-since (condition-case ()
7685                                               (date-to-time date)
7686                                             (error '(0 0))))
7687                               cutoff))
7688             (when (if younger-p
7689                       is-younger
7690                     (not is-younger))
7691               (push (gnus-data-number d) articles))))
7692         (gnus-summary-limit (nreverse articles)))
7693     (gnus-summary-position-point)))
7694
7695 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7696   "Limit the summary buffer to articles that match an 'extra' header."
7697   (interactive
7698    (let ((header
7699           (intern
7700            (gnus-completing-read-with-default
7701             (symbol-name (car gnus-extra-headers))
7702             (if current-prefix-arg
7703                 "Exclude extra header:"
7704               "Limit extra header:")
7705             (mapcar (lambda (x)
7706                       (cons (symbol-name x) x))
7707                     gnus-extra-headers)
7708             nil
7709             t))))
7710      (list header
7711            (read-string (format "%s header %s (regexp): "
7712                                 (if current-prefix-arg "Exclude" "Limit to")
7713                                 header))
7714            current-prefix-arg)))
7715   (when (not (equal "" regexp))
7716     (prog1
7717         (let ((articles (gnus-summary-find-matching
7718                          (cons 'extra header) regexp 'all nil nil
7719                          not-matching)))
7720           (unless articles
7721             (error "Found no matches for \"%s\"" regexp))
7722           (gnus-summary-limit articles))
7723       (gnus-summary-position-point))))
7724
7725 (defun gnus-summary-limit-to-display-predicate ()
7726   "Limit the summary buffer to the predicated in the `display' group parameter."
7727   (interactive)
7728   (unless gnus-newsgroup-display
7729     (error "There is no `display' group parameter"))
7730   (let (articles)
7731     (dolist (number gnus-newsgroup-articles)
7732       (when (funcall gnus-newsgroup-display)
7733         (push number articles)))
7734     (gnus-summary-limit articles))
7735   (gnus-summary-position-point))
7736
7737 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7738 (make-obsolete
7739  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7740
7741 (defun gnus-summary-limit-to-unread (&optional all)
7742   "Limit the summary buffer to articles that are not marked as read.
7743 If ALL is non-nil, limit strictly to unread articles."
7744   (interactive "P")
7745   (if all
7746       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7747     (gnus-summary-limit-to-marks
7748      ;; Concat all the marks that say that an article is read and have
7749      ;; those removed.
7750      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7751            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7752            gnus-low-score-mark gnus-expirable-mark
7753            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7754            gnus-duplicate-mark gnus-souped-mark)
7755      'reverse)))
7756
7757 (defun gnus-summary-limit-to-replied (&optional unreplied)
7758   "Limit the summary buffer to replied articles.
7759 If UNREPLIED (the prefix), limit to unreplied articles."
7760   (interactive "P")
7761   (if unreplied
7762       (gnus-summary-limit
7763        (gnus-set-difference gnus-newsgroup-articles
7764         gnus-newsgroup-replied))
7765     (gnus-summary-limit gnus-newsgroup-replied))
7766   (gnus-summary-position-point))
7767
7768 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7769 (make-obsolete 'gnus-summary-delete-marked-with
7770                'gnus-summary-limit-exclude-marks)
7771
7772 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7773   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7774 If REVERSE, limit the summary buffer to articles that are marked
7775 with MARKS.  MARKS can either be a string of marks or a list of marks.
7776 Returns how many articles were removed."
7777   (interactive "sMarks: ")
7778   (gnus-summary-limit-to-marks marks t))
7779
7780 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7781   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7782 If REVERSE (the prefix), limit the summary buffer to articles that are
7783 not marked with MARKS.  MARKS can either be a string of marks or a
7784 list of marks.
7785 Returns how many articles were removed."
7786   (interactive "sMarks: \nP")
7787   (prog1
7788       (let ((data gnus-newsgroup-data)
7789             (marks (if (listp marks) marks
7790                      (append marks nil))) ; Transform to list.
7791             articles)
7792         (while data
7793           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7794                   (memq (gnus-data-mark (car data)) marks))
7795             (push (gnus-data-number (car data)) articles))
7796           (setq data (cdr data)))
7797         (gnus-summary-limit articles))
7798     (gnus-summary-position-point)))
7799
7800 (defun gnus-summary-limit-to-score (score)
7801   "Limit to articles with score at or above SCORE."
7802   (interactive "NLimit to articles with score of at least: ")
7803   (let ((data gnus-newsgroup-data)
7804         articles)
7805     (while data
7806       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7807                 score)
7808         (push (gnus-data-number (car data)) articles))
7809       (setq data (cdr data)))
7810     (prog1
7811         (gnus-summary-limit articles)
7812       (gnus-summary-position-point))))
7813
7814 (defun gnus-summary-limit-to-unseen ()
7815   "Limit to unseen articles."
7816   (interactive)
7817   (prog1
7818       (gnus-summary-limit gnus-newsgroup-unseen)
7819     (gnus-summary-position-point)))
7820
7821 (defun gnus-summary-limit-include-thread (id)
7822   "Display all the hidden articles that is in the thread with ID in it.
7823 When called interactively, ID is the Message-ID of the current
7824 article."
7825   (interactive (list (mail-header-id (gnus-summary-article-header))))
7826   (let ((articles (gnus-articles-in-thread
7827                    (gnus-id-to-thread (gnus-root-id id)))))
7828     (prog1
7829         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7830       (gnus-summary-limit-include-matching-articles
7831        "subject"
7832        (regexp-quote (gnus-simplify-subject-re
7833                       (mail-header-subject (gnus-id-to-header id)))))
7834       (gnus-summary-position-point))))
7835
7836 (defun gnus-summary-limit-include-matching-articles (header regexp)
7837   "Display all the hidden articles that have HEADERs that match REGEXP."
7838   (interactive (list (read-string "Match on header: ")
7839                      (read-string "Regexp: ")))
7840   (let ((articles (gnus-find-matching-articles header regexp)))
7841     (prog1
7842         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7843       (gnus-summary-position-point))))
7844
7845 (defun gnus-summary-insert-dormant-articles ()
7846   "Insert all the dormant articles for this group into the current buffer."
7847   (interactive)
7848   (let ((gnus-verbose (max 6 gnus-verbose)))
7849     (if (not gnus-newsgroup-dormant)
7850         (gnus-message 3 "No cached articles for this group")
7851       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7852
7853 (defun gnus-summary-limit-include-dormant ()
7854   "Display all the hidden articles that are marked as dormant.
7855 Note that this command only works on a subset of the articles currently
7856 fetched for this group."
7857   (interactive)
7858   (unless gnus-newsgroup-dormant
7859     (error "There are no dormant articles in this group"))
7860   (prog1
7861       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7862     (gnus-summary-position-point)))
7863
7864 (defun gnus-summary-limit-exclude-dormant ()
7865   "Hide all dormant articles."
7866   (interactive)
7867   (prog1
7868       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7869     (gnus-summary-position-point)))
7870
7871 (defun gnus-summary-limit-exclude-childless-dormant ()
7872   "Hide all dormant articles that have no children."
7873   (interactive)
7874   (let ((data (gnus-data-list t))
7875         articles d children)
7876     ;; Find all articles that are either not dormant or have
7877     ;; children.
7878     (while (setq d (pop data))
7879       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7880                 (and (setq children
7881                            (gnus-article-children (gnus-data-number d)))
7882                      (let (found)
7883                        (while children
7884                          (when (memq (car children) articles)
7885                            (setq children nil
7886                                  found t))
7887                          (pop children))
7888                        found)))
7889         (push (gnus-data-number d) articles)))
7890     ;; Do the limiting.
7891     (prog1
7892         (gnus-summary-limit articles)
7893       (gnus-summary-position-point))))
7894
7895 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7896   "Mark all unread excluded articles as read.
7897 If ALL, mark even excluded ticked and dormants as read."
7898   (interactive "P")
7899   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7900   (let ((articles (gnus-sorted-ndifference
7901                    (sort
7902                     (mapcar (lambda (h) (mail-header-number h))
7903                             gnus-newsgroup-headers)
7904                     '<)
7905                    gnus-newsgroup-limit))
7906         article)
7907     (setq gnus-newsgroup-unreads
7908           (gnus-sorted-intersection gnus-newsgroup-unreads
7909                                     gnus-newsgroup-limit))
7910     (if all
7911         (setq gnus-newsgroup-dormant nil
7912               gnus-newsgroup-marked nil
7913               gnus-newsgroup-reads
7914               (nconc
7915                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7916                gnus-newsgroup-reads))
7917       (while (setq article (pop articles))
7918         (unless (or (memq article gnus-newsgroup-dormant)
7919                     (memq article gnus-newsgroup-marked))
7920           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7921
7922 (defun gnus-summary-limit (articles &optional pop)
7923   (if pop
7924       ;; We pop the previous limit off the stack and use that.
7925       (setq articles (car gnus-newsgroup-limits)
7926             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7927     ;; We use the new limit, so we push the old limit on the stack.
7928     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7929   ;; Set the limit.
7930   (setq gnus-newsgroup-limit articles)
7931   (let ((total (length gnus-newsgroup-data))
7932         (data (gnus-data-find-list (gnus-summary-article-number)))
7933         (gnus-summary-mark-below nil)   ; Inhibit this.
7934         found)
7935     ;; This will do all the work of generating the new summary buffer
7936     ;; according to the new limit.
7937     (gnus-summary-prepare)
7938     ;; Hide any threads, possibly.
7939     (gnus-summary-maybe-hide-threads)
7940     ;; Try to return to the article you were at, or one in the
7941     ;; neighborhood.
7942     (when data
7943       ;; We try to find some article after the current one.
7944       (while data
7945         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7946           (setq data nil
7947                 found t))
7948         (setq data (cdr data))))
7949     (unless found
7950       ;; If there is no data, that means that we were after the last
7951       ;; article.  The same goes when we can't find any articles
7952       ;; after the current one.
7953       (goto-char (point-max))
7954       (gnus-summary-find-prev))
7955     (gnus-set-mode-line 'summary)
7956     ;; We return how many articles were removed from the summary
7957     ;; buffer as a result of the new limit.
7958     (- total (length gnus-newsgroup-data))))
7959
7960 (defsubst gnus-invisible-cut-children (threads)
7961   (let ((num 0))
7962     (while threads
7963       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7964         (incf num))
7965       (pop threads))
7966     (< num 2)))
7967
7968 (defsubst gnus-cut-thread (thread)
7969   "Go forwards in the thread until we find an article that we want to display."
7970   (when (or (eq gnus-fetch-old-headers 'some)
7971             (eq gnus-fetch-old-headers 'invisible)
7972             (numberp gnus-fetch-old-headers)
7973             (eq gnus-build-sparse-threads 'some)
7974             (eq gnus-build-sparse-threads 'more))
7975     ;; Deal with old-fetched headers and sparse threads.
7976     (while (and
7977             thread
7978             (or
7979              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7980              (gnus-summary-article-ancient-p
7981               (mail-header-number (car thread))))
7982             (if (or (<= (length (cdr thread)) 1)
7983                     (eq gnus-fetch-old-headers 'invisible))
7984                 (setq gnus-newsgroup-limit
7985                       (delq (mail-header-number (car thread))
7986                             gnus-newsgroup-limit)
7987                       thread (cadr thread))
7988               (when (gnus-invisible-cut-children (cdr thread))
7989                 (let ((th (cdr thread)))
7990                   (while th
7991                     (if (memq (mail-header-number (caar th))
7992                               gnus-newsgroup-limit)
7993                         (setq thread (car th)
7994                               th nil)
7995                       (setq th (cdr th))))))))))
7996   thread)
7997
7998 (defun gnus-cut-threads (threads)
7999   "Cut off all uninteresting articles from the beginning of THREADS."
8000   (when (or (eq gnus-fetch-old-headers 'some)
8001             (eq gnus-fetch-old-headers 'invisible)
8002             (numberp gnus-fetch-old-headers)
8003             (eq gnus-build-sparse-threads 'some)
8004             (eq gnus-build-sparse-threads 'more))
8005     (let ((th threads))
8006       (while th
8007         (setcar th (gnus-cut-thread (car th)))
8008         (setq th (cdr th)))))
8009   ;; Remove nixed out threads.
8010   (delq nil threads))
8011
8012 (defun gnus-summary-initial-limit (&optional show-if-empty)
8013   "Figure out what the initial limit is supposed to be on group entry.
8014 This entails weeding out unwanted dormants, low-scored articles,
8015 fetch-old-headers verbiage, and so on."
8016   ;; Most groups have nothing to remove.
8017   (if (or gnus-inhibit-limiting
8018           (and (null gnus-newsgroup-dormant)
8019                (eq gnus-newsgroup-display 'gnus-not-ignore)
8020                (not (eq gnus-fetch-old-headers 'some))
8021                (not (numberp gnus-fetch-old-headers))
8022                (not (eq gnus-fetch-old-headers 'invisible))
8023                (null gnus-summary-expunge-below)
8024                (not (eq gnus-build-sparse-threads 'some))
8025                (not (eq gnus-build-sparse-threads 'more))
8026                (null gnus-thread-expunge-below)
8027                (not gnus-use-nocem)))
8028       ()                                ; Do nothing.
8029     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8030     (setq gnus-newsgroup-limit nil)
8031     (mapatoms
8032      (lambda (node)
8033        (unless (car (symbol-value node))
8034          ;; These threads have no parents -- they are roots.
8035          (let ((nodes (cdr (symbol-value node)))
8036                thread)
8037            (while nodes
8038              (if (and gnus-thread-expunge-below
8039                       (< (gnus-thread-total-score (car nodes))
8040                          gnus-thread-expunge-below))
8041                  (gnus-expunge-thread (pop nodes))
8042                (setq thread (pop nodes))
8043                (gnus-summary-limit-children thread))))))
8044      gnus-newsgroup-dependencies)
8045     ;; If this limitation resulted in an empty group, we might
8046     ;; pop the previous limit and use it instead.
8047     (when (and (not gnus-newsgroup-limit)
8048                show-if-empty)
8049       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8050     gnus-newsgroup-limit))
8051
8052 (defun gnus-summary-limit-children (thread)
8053   "Return 1 if this subthread is visible and 0 if it is not."
8054   ;; First we get the number of visible children to this thread.  This
8055   ;; is done by recursing down the thread using this function, so this
8056   ;; will really go down to a leaf article first, before slowly
8057   ;; working its way up towards the root.
8058   (when thread
8059     (let* ((max-lisp-eval-depth 5000)
8060            (children
8061            (if (cdr thread)
8062                (apply '+ (mapcar 'gnus-summary-limit-children
8063                                  (cdr thread)))
8064              0))
8065           (number (mail-header-number (car thread)))
8066           score)
8067       (if (and
8068            (not (memq number gnus-newsgroup-marked))
8069            (or
8070             ;; If this article is dormant and has absolutely no visible
8071             ;; children, then this article isn't visible.
8072             (and (memq number gnus-newsgroup-dormant)
8073                  (zerop children))
8074             ;; If this is "fetch-old-headered" and there is no
8075             ;; visible children, then we don't want this article.
8076             (and (or (eq gnus-fetch-old-headers 'some)
8077                      (numberp gnus-fetch-old-headers))
8078                  (gnus-summary-article-ancient-p number)
8079                  (zerop children))
8080             ;; If this is "fetch-old-headered" and `invisible', then
8081             ;; we don't want this article.
8082             (and (eq gnus-fetch-old-headers 'invisible)
8083                  (gnus-summary-article-ancient-p number))
8084             ;; If this is a sparsely inserted article with no children,
8085             ;; we don't want it.
8086             (and (eq gnus-build-sparse-threads 'some)
8087                  (gnus-summary-article-sparse-p number)
8088                  (zerop children))
8089             ;; If we use expunging, and this article is really
8090             ;; low-scored, then we don't want this article.
8091             (when (and gnus-summary-expunge-below
8092                        (< (setq score
8093                                 (or (cdr (assq number gnus-newsgroup-scored))
8094                                     gnus-summary-default-score))
8095                           gnus-summary-expunge-below))
8096               ;; We increase the expunge-tally here, but that has
8097               ;; nothing to do with the limits, really.
8098               (incf gnus-newsgroup-expunged-tally)
8099               ;; We also mark as read here, if that's wanted.
8100               (when (and gnus-summary-mark-below
8101                          (< score gnus-summary-mark-below))
8102                 (setq gnus-newsgroup-unreads
8103                       (delq number gnus-newsgroup-unreads))
8104                 (if gnus-newsgroup-auto-expire
8105                     (push number gnus-newsgroup-expirable)
8106                   (push (cons number gnus-low-score-mark)
8107                         gnus-newsgroup-reads)))
8108               t)
8109             ;; Do the `display' group parameter.
8110             (and gnus-newsgroup-display
8111                  (not (funcall gnus-newsgroup-display)))
8112             ;; Check NoCeM things.
8113             (when (and gnus-use-nocem
8114                        (gnus-nocem-unwanted-article-p
8115                         (mail-header-id (car thread))))
8116               (setq gnus-newsgroup-unreads
8117                     (delq number gnus-newsgroup-unreads))
8118               t)))
8119           ;; Nope, invisible article.
8120           0
8121         ;; Ok, this article is to be visible, so we add it to the limit
8122         ;; and return 1.
8123         (push number gnus-newsgroup-limit)
8124         1))))
8125
8126 (defun gnus-expunge-thread (thread)
8127   "Mark all articles in THREAD as read."
8128   (let* ((number (mail-header-number (car thread))))
8129     (incf gnus-newsgroup-expunged-tally)
8130     ;; We also mark as read here, if that's wanted.
8131     (setq gnus-newsgroup-unreads
8132           (delq number gnus-newsgroup-unreads))
8133     (if gnus-newsgroup-auto-expire
8134         (push number gnus-newsgroup-expirable)
8135       (push (cons number gnus-low-score-mark)
8136             gnus-newsgroup-reads)))
8137   ;; Go recursively through all subthreads.
8138   (mapcar 'gnus-expunge-thread (cdr thread)))
8139
8140 ;; Summary article oriented commands
8141
8142 (defun gnus-summary-refer-parent-article (n)
8143   "Refer parent article N times.
8144 If N is negative, go to ancestor -N instead.
8145 The difference between N and the number of articles fetched is returned."
8146   (interactive "p")
8147   (let ((skip 1)
8148         error header ref)
8149     (when (not (natnump n))
8150       (setq skip (abs n)
8151             n 1))
8152     (while (and (> n 0)
8153                 (not error))
8154       (setq header (gnus-summary-article-header))
8155       (if (and (eq (mail-header-number header)
8156                    (cdr gnus-article-current))
8157                (equal gnus-newsgroup-name
8158                       (car gnus-article-current)))
8159           ;; If we try to find the parent of the currently
8160           ;; displayed article, then we take a look at the actual
8161           ;; References header, since this is slightly more
8162           ;; reliable than the References field we got from the
8163           ;; server.
8164           (save-excursion
8165             (set-buffer gnus-original-article-buffer)
8166             (nnheader-narrow-to-headers)
8167             (unless (setq ref (message-fetch-field "references"))
8168               (when (setq ref (message-fetch-field "in-reply-to"))
8169                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8170             (widen))
8171         (setq ref
8172               ;; It's not the current article, so we take a bet on
8173               ;; the value we got from the server.
8174               (mail-header-references header)))
8175       (if (and ref
8176                (not (equal ref "")))
8177           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8178             (gnus-message 1 "Couldn't find parent"))
8179         (gnus-message 1 "No references in article %d"
8180                       (gnus-summary-article-number))
8181         (setq error t))
8182       (decf n))
8183     (gnus-summary-position-point)
8184     n))
8185
8186 (defun gnus-summary-refer-references ()
8187   "Fetch all articles mentioned in the References header.
8188 Return the number of articles fetched."
8189   (interactive)
8190   (let ((ref (mail-header-references (gnus-summary-article-header)))
8191         (current (gnus-summary-article-number))
8192         (n 0))
8193     (if (or (not ref)
8194             (equal ref ""))
8195         (error "No References in the current article")
8196       ;; For each Message-ID in the References header...
8197       (while (string-match "<[^>]*>" ref)
8198         (incf n)
8199         ;; ... fetch that article.
8200         (gnus-summary-refer-article
8201          (prog1 (match-string 0 ref)
8202            (setq ref (substring ref (match-end 0))))))
8203       (gnus-summary-goto-subject current)
8204       (gnus-summary-position-point)
8205       n)))
8206
8207 (defun gnus-summary-refer-thread (&optional limit)
8208   "Fetch all articles in the current thread.
8209 If LIMIT (the numerical prefix), fetch that many old headers instead
8210 of what's specified by the `gnus-refer-thread-limit' variable."
8211   (interactive "P")
8212   (let ((id (mail-header-id (gnus-summary-article-header)))
8213         (limit (if limit (prefix-numeric-value limit)
8214                  gnus-refer-thread-limit)))
8215     (unless (eq gnus-fetch-old-headers 'invisible)
8216       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8217       ;; Retrieve the headers and read them in.
8218       (if (eq (if (numberp limit)
8219                   (gnus-retrieve-headers
8220                    (list (min
8221                           (+ (mail-header-number
8222                               (gnus-summary-article-header))
8223                              limit)
8224                           gnus-newsgroup-end))
8225                    gnus-newsgroup-name (* limit 2))
8226                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8227                 ;; headers.
8228                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8229                                        gnus-newsgroup-name limit))
8230               'nov)
8231           (gnus-build-all-threads)
8232         (error "Can't fetch thread from back ends that don't support NOV"))
8233       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8234     (gnus-summary-limit-include-thread id)))
8235
8236 (defun gnus-summary-refer-article (message-id)
8237   "Fetch an article specified by MESSAGE-ID."
8238   (interactive "sMessage-ID: ")
8239   (when (and (stringp message-id)
8240              (not (zerop (length message-id))))
8241     (setq message-id (gnus-replace-in-string message-id " " ""))
8242     ;; Construct the correct Message-ID if necessary.
8243     ;; Suggested by tale@pawl.rpi.edu.
8244     (unless (string-match "^<" message-id)
8245       (setq message-id (concat "<" message-id)))
8246     (unless (string-match ">$" message-id)
8247       (setq message-id (concat message-id ">")))
8248     ;; People often post MIDs from URLs, so unhex it:
8249     (unless (string-match "@" message-id)
8250       (setq message-id (gnus-url-unhex-string message-id)))
8251     (let* ((header (gnus-id-to-header message-id))
8252            (sparse (and header
8253                         (gnus-summary-article-sparse-p
8254                          (mail-header-number header))
8255                         (memq (mail-header-number header)
8256                               gnus-newsgroup-limit)))
8257            number)
8258       (cond
8259        ;; If the article is present in the buffer we just go to it.
8260        ((and header
8261              (or (not (gnus-summary-article-sparse-p
8262                        (mail-header-number header)))
8263                  sparse))
8264         (prog1
8265             (gnus-summary-goto-article
8266              (mail-header-number header) nil t)
8267           (when sparse
8268             (gnus-summary-update-article (mail-header-number header)))))
8269        (t
8270         ;; We fetch the article.
8271         (catch 'found
8272           (dolist (gnus-override-method (gnus-refer-article-methods))
8273             (when (and (gnus-check-server gnus-override-method)
8274                        ;; Fetch the header,
8275                        (setq number (gnus-summary-insert-subject message-id)))
8276               ;; and display the article.
8277               (gnus-summary-select-article nil nil nil number)
8278               (throw 'found t)))
8279           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8280
8281 (defun gnus-refer-article-methods ()
8282   "Return a list of referable methods."
8283   (cond
8284    ;; No method, so we default to current and native.
8285    ((null gnus-refer-article-method)
8286     (list gnus-current-select-method gnus-select-method))
8287    ;; Current.
8288    ((eq 'current gnus-refer-article-method)
8289     (list gnus-current-select-method))
8290    ;; List of select methods.
8291    ((not (and (symbolp (car gnus-refer-article-method))
8292               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8293     (let (out)
8294       (dolist (method gnus-refer-article-method)
8295         (push (if (eq 'current method)
8296                   gnus-current-select-method
8297                 method)
8298               out))
8299       (nreverse out)))
8300    ;; One single select method.
8301    (t
8302     (list gnus-refer-article-method))))
8303
8304 (defun gnus-summary-edit-parameters ()
8305   "Edit the group parameters of the current group."
8306   (interactive)
8307   (gnus-group-edit-group gnus-newsgroup-name 'params))
8308
8309 (defun gnus-summary-customize-parameters ()
8310   "Customize the group parameters of the current group."
8311   (interactive)
8312   (gnus-group-customize gnus-newsgroup-name))
8313
8314 (defun gnus-summary-enter-digest-group (&optional force)
8315   "Enter an nndoc group based on the current article.
8316 If FORCE, force a digest interpretation.  If not, try
8317 to guess what the document format is."
8318   (interactive "P")
8319   (let ((conf gnus-current-window-configuration))
8320     (save-window-excursion
8321       (save-excursion
8322         (let (gnus-article-prepare-hook
8323               gnus-display-mime-function
8324               gnus-break-pages)
8325           (gnus-summary-select-article))))
8326     (setq gnus-current-window-configuration conf)
8327     (let* ((name (format "%s-%d"
8328                          (gnus-group-prefixed-name
8329                           gnus-newsgroup-name (list 'nndoc ""))
8330                          (with-current-buffer gnus-summary-buffer
8331                            gnus-current-article)))
8332            (ogroup gnus-newsgroup-name)
8333            (params (append (gnus-info-params (gnus-get-info ogroup))
8334                            (list (cons 'to-group ogroup))
8335                            (list (cons 'parent-group ogroup))
8336                            (list (cons 'save-article-group ogroup))))
8337            (case-fold-search t)
8338            (buf (current-buffer))
8339            dig to-address)
8340       (save-excursion
8341         (set-buffer gnus-original-article-buffer)
8342         ;; Have the digest group inherit the main mail address of
8343         ;; the parent article.
8344         (when (setq to-address (or (gnus-fetch-field "reply-to")
8345                                    (gnus-fetch-field "from")))
8346           (setq params (append
8347                         (list (cons 'to-address
8348                                     (funcall gnus-decode-encoded-word-function
8349                                              to-address))))))
8350         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8351         (insert-buffer-substring gnus-original-article-buffer)
8352         ;; Remove lines that may lead nndoc to misinterpret the
8353         ;; document type.
8354         (narrow-to-region
8355          (goto-char (point-min))
8356          (or (search-forward "\n\n" nil t) (point)))
8357         (goto-char (point-min))
8358         (delete-matching-lines "^Path:\\|^From ")
8359         (widen))
8360       (unwind-protect
8361           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8362                     (gnus-newsgroup-ephemeral-ignored-charsets
8363                      gnus-newsgroup-ignored-charsets))
8364                 (gnus-group-read-ephemeral-group
8365                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8366                               (nndoc-article-type
8367                                ,(if force 'mbox 'guess)))
8368                  t nil nil nil
8369                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8370                                                         "ADAPT")))))
8371               ;; Make all postings to this group go to the parent group.
8372               (nconc (gnus-info-params (gnus-get-info name))
8373                      params)
8374             ;; Couldn't select this doc group.
8375             (switch-to-buffer buf)
8376             (gnus-set-global-variables)
8377             (gnus-configure-windows 'summary)
8378             (gnus-message 3 "Article couldn't be entered?"))
8379         (kill-buffer dig)))))
8380
8381 (defun gnus-summary-read-document (n)
8382   "Open a new group based on the current article(s).
8383 This will allow you to read digests and other similar
8384 documents as newsgroups.
8385 Obeys the standard process/prefix convention."
8386   (interactive "P")
8387   (let* ((ogroup gnus-newsgroup-name)
8388          (params (append (gnus-info-params (gnus-get-info ogroup))
8389                          (list (cons 'to-group ogroup))))
8390          group egroup groups vgroup)
8391     (dolist (article (gnus-summary-work-articles n))
8392       (setq group (format "%s-%d" gnus-newsgroup-name article))
8393       (gnus-summary-remove-process-mark article)
8394       (when (gnus-summary-display-article article)
8395         (save-excursion
8396           (with-temp-buffer
8397             (insert-buffer-substring gnus-original-article-buffer)
8398             ;; Remove some headers that may lead nndoc to make
8399             ;; the wrong guess.
8400             (message-narrow-to-head)
8401             (goto-char (point-min))
8402             (delete-matching-lines "^Path:\\|^From ")
8403             (widen)
8404             (if (setq egroup
8405                       (gnus-group-read-ephemeral-group
8406                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8407                                      (nndoc-article-type guess))
8408                        t nil t))
8409                 (progn
8410                   ;; Make all postings to this group go to the parent group.
8411                   (nconc (gnus-info-params (gnus-get-info egroup))
8412                          params)
8413                   (push egroup groups))
8414               ;; Couldn't select this doc group.
8415               (gnus-error 3 "Article couldn't be entered"))))))
8416     ;; Now we have selected all the documents.
8417     (cond
8418      ((not groups)
8419       (error "None of the articles could be interpreted as documents"))
8420      ((gnus-group-read-ephemeral-group
8421        (setq vgroup (format
8422                      "nnvirtual:%s-%s" gnus-newsgroup-name
8423                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8424        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8425        t
8426        (cons (current-buffer) 'summary)))
8427      (t
8428       (error "Couldn't select virtual nndoc group")))))
8429
8430 (defun gnus-summary-isearch-article (&optional regexp-p)
8431   "Do incremental search forward on the current article.
8432 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8433   (interactive "P")
8434   (let* ((gnus-inhibit-treatment t)
8435          (old (gnus-summary-select-article)))
8436     (gnus-configure-windows 'article)
8437     (gnus-eval-in-buffer-window gnus-article-buffer
8438       (save-restriction
8439         (widen)
8440         (when (eq 'old old)
8441           (gnus-article-show-all-headers))
8442         (goto-char (point-min))
8443         (isearch-forward regexp-p)))))
8444
8445 (defun gnus-summary-search-article-forward (regexp &optional backward)
8446   "Search for an article containing REGEXP forward.
8447 If BACKWARD, search backward instead."
8448   (interactive
8449    (list (read-string
8450           (format "Search article %s (regexp%s): "
8451                   (if current-prefix-arg "backward" "forward")
8452                   (if gnus-last-search-regexp
8453                       (concat ", default " gnus-last-search-regexp)
8454                     "")))
8455          current-prefix-arg))
8456   (if (string-equal regexp "")
8457       (setq regexp (or gnus-last-search-regexp ""))
8458     (setq gnus-last-search-regexp regexp)
8459     (setq gnus-article-before-search gnus-current-article))
8460   ;; Intentionally set gnus-last-article.
8461   (setq gnus-last-article gnus-article-before-search)
8462   (let ((gnus-last-article gnus-last-article))
8463     (if (gnus-summary-search-article regexp backward)
8464         (gnus-summary-show-thread)
8465       (signal 'search-failed (list regexp)))))
8466
8467 (defun gnus-summary-search-article-backward (regexp)
8468   "Search for an article containing REGEXP backward."
8469   (interactive
8470    (list (read-string
8471           (format "Search article backward (regexp%s): "
8472                   (if gnus-last-search-regexp
8473                       (concat ", default " gnus-last-search-regexp)
8474                     "")))))
8475   (gnus-summary-search-article-forward regexp 'backward))
8476
8477 (eval-when-compile
8478   (defmacro gnus-summary-search-article-position-point (regexp backward)
8479     "Dehighlight the last matched text and goto the beginning position."
8480     (` (if (and gnus-summary-search-article-matched-data
8481                 (let ((text (caddr gnus-summary-search-article-matched-data))
8482                       (inhibit-read-only t)
8483                       buffer-read-only)
8484                   (delete-region
8485                    (goto-char (car gnus-summary-search-article-matched-data))
8486                    (cadr gnus-summary-search-article-matched-data))
8487                   (insert text)
8488                   (string-match (, regexp) text)))
8489            (if (, backward) (beginning-of-line) (end-of-line))
8490          (goto-char (if (, backward) (point-max) (point-min))))))
8491
8492   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8493     "Place point where X-Face image is displayed."
8494     (if (featurep 'xemacs)
8495         (` (let ((end (if (search-forward "\n\n" nil t)
8496                           (goto-char (1- (point)))
8497                         (point-min)))
8498                  extent)
8499              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8500              (unless (and (re-search-forward "^From:" end t)
8501                           (setq extent (extent-at (point)))
8502                           (extent-begin-glyph extent))
8503                (goto-char (, opoint)))))
8504       (` (let ((end (if (search-forward "\n\n" nil t)
8505                         (goto-char (1- (point)))
8506                       (point-min)))
8507                (start (or (search-backward "\n\n" nil t) (point-min))))
8508            (goto-char
8509             (or (text-property-any start end 'x-face-image t);; x-face-e21
8510                 (text-property-any start end 'x-face-mule-bitmap-image t)
8511                 (, opoint)))))))
8512
8513   (defmacro gnus-summary-search-article-highlight-matched-text
8514     (backward treated x-face)
8515     "Highlight matched text in the function `gnus-summary-search-article'."
8516     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8517              (end (set-marker (make-marker) (match-end 0)))
8518              (inhibit-read-only t)
8519              buffer-read-only)
8520          (unless treated
8521            (let ((,@
8522                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8523                     (mapcar
8524                      (lambda (item) (setq items (delq item items)))
8525                      '(gnus-treat-buttonize
8526                        gnus-treat-fill-article
8527                        gnus-treat-fill-long-lines
8528                        gnus-treat-emphasize
8529                        gnus-treat-highlight-headers
8530                        gnus-treat-highlight-citation
8531                        gnus-treat-highlight-signature
8532                        gnus-treat-overstrike
8533                        gnus-treat-display-x-face
8534                        gnus-treat-buttonize-head
8535                        gnus-treat-decode-article-as-default-mime-charset))
8536                     (static-if (featurep 'xemacs)
8537                         items
8538                       (cons '(x-face-mule-delete-x-face-field
8539                               (quote never))
8540                             items))))
8541                  (gnus-treat-display-x-face
8542                   (when (, x-face) gnus-treat-display-x-face)))
8543              (gnus-article-prepare-mime-display)))
8544          (goto-char (if (, backward) start end))
8545          (when (, x-face)
8546            (gnus-summary-search-article-highlight-goto-x-face (point)))
8547          (setq gnus-summary-search-article-matched-data
8548                (list start end (buffer-substring start end)))
8549          (unless (eq start end);; matched text has been deleted. :-<
8550            (put-text-property start end 'face
8551                               (or (find-face 'isearch)
8552                                   'secondary-selection))))))
8553   )
8554
8555 (defun gnus-summary-search-article (regexp &optional backward)
8556   "Search for an article containing REGEXP.
8557 Optional argument BACKWARD means do search for backward.
8558 `gnus-select-article-hook' is not called during the search."
8559   ;; We have to require this here to make sure that the following
8560   ;; dynamic binding isn't shadowed by autoloading.
8561   (require 'gnus-async)
8562   (require 'gnus-art)
8563   (let ((gnus-select-article-hook nil)  ;Disable hook.
8564         (gnus-article-prepare-hook nil)
8565         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8566         (gnus-use-article-prefetch nil)
8567         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8568         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8569         (gnus-visual nil)
8570         (gnus-keep-backlog nil)
8571         (gnus-break-pages nil)
8572         (gnus-summary-display-arrow nil)
8573         (gnus-updated-mode-lines nil)
8574         (gnus-auto-center-summary nil)
8575         (sum (current-buffer))
8576         (found nil)
8577         point treated)
8578     (gnus-save-hidden-threads
8579       (static-if (featurep 'xemacs)
8580           (let ((gnus-inhibit-treatment t))
8581             (setq treated (eq 'old (gnus-summary-select-article)))
8582             (when (and treated
8583                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8584                                  (window-live-p (get-buffer-window
8585                                                  gnus-article-buffer t)))))
8586               (gnus-summary-select-article nil t)
8587               (setq treated nil)))
8588         (let ((gnus-inhibit-treatment t)
8589               (x-face-mule-delete-x-face-field 'never))
8590           (setq treated (eq 'old (gnus-summary-select-article)))
8591           (when (and treated
8592                      (not
8593                       (and (gnus-buffer-live-p gnus-article-buffer)
8594                            (window-live-p (get-buffer-window
8595                                            gnus-article-buffer t))
8596                            (or (not (string-match "^\\^X-Face:" regexp))
8597                                (with-current-buffer gnus-article-buffer
8598                                  gnus-summary-search-article-matched-data)))))
8599             (gnus-summary-select-article nil t)
8600             (setq treated nil))))
8601       (set-buffer gnus-article-buffer)
8602       (widen)
8603       (if treated
8604           (progn
8605             (gnus-article-show-all-headers)
8606             (gnus-summary-search-article-position-point regexp backward))
8607         (goto-char (if backward (point-max) (point-min))))
8608       (while (not found)
8609         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8610         (if (if backward
8611                 (re-search-backward regexp nil t)
8612               (re-search-forward regexp nil t))
8613             ;; We found the regexp.
8614             (progn
8615               (gnus-summary-search-article-highlight-matched-text
8616                backward treated (string-match "^\\^X-Face:" regexp))
8617               (setq found 'found)
8618               (forward-line
8619                (/ (- 2 (window-height
8620                         (get-buffer-window gnus-article-buffer t)))
8621                   2))
8622               (set-window-start
8623                (get-buffer-window (current-buffer))
8624                (point))
8625               (set-buffer sum)
8626               (setq point (point)))
8627           ;; We didn't find it, so we go to the next article.
8628           (set-buffer sum)
8629           (setq found 'not)
8630           (while (eq found 'not)
8631             (if (not (if backward (gnus-summary-find-prev)
8632                        (gnus-summary-find-next)))
8633                 ;; No more articles.
8634                 (setq found t)
8635               ;; Select the next article and adjust point.
8636               (unless (gnus-summary-article-sparse-p
8637                        (gnus-summary-article-number))
8638                 (setq found nil)
8639                 (let ((gnus-inhibit-treatment t))
8640                   (gnus-summary-select-article))
8641                 (setq treated nil)
8642                 (set-buffer gnus-article-buffer)
8643                 (widen)
8644                 (goto-char (if backward (point-max) (point-min))))))))
8645       (gnus-message 7 ""))
8646     ;; Return whether we found the regexp.
8647     (when (eq found 'found)
8648       (goto-char point)
8649       (gnus-summary-show-thread)
8650       (gnus-summary-goto-subject gnus-current-article)
8651       (gnus-summary-position-point)
8652       t)))
8653
8654 (defun gnus-find-matching-articles (header regexp)
8655   "Return a list of all articles that match REGEXP on HEADER.
8656 This search includes all articles in the current group that Gnus has
8657 fetched headers for, whether they are displayed or not."
8658   (let ((articles nil)
8659         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8660         (case-fold-search t))
8661     (dolist (header gnus-newsgroup-headers)
8662       (when (string-match regexp (funcall func header))
8663         (push (mail-header-number header) articles)))
8664     (nreverse articles)))
8665
8666 (defun gnus-summary-find-matching (header regexp &optional backward unread
8667                                           not-case-fold not-matching)
8668   "Return a list of all articles that match REGEXP on HEADER.
8669 The search stars on the current article and goes forwards unless
8670 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8671 If UNREAD is non-nil, only unread articles will
8672 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8673 in the comparisons. If NOT-MATCHING, return a list of all articles that
8674 not match REGEXP on HEADER."
8675   (let ((case-fold-search (not not-case-fold))
8676         articles d func)
8677     (if (consp header)
8678         (if (eq (car header) 'extra)
8679             (setq func
8680                   `(lambda (h)
8681                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8682                          "")))
8683           (error "%s is an invalid header" header))
8684       (unless (fboundp (intern (concat "mail-header-" header)))
8685         (error "%s is not a valid header" header))
8686       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8687     (dolist (d (if (eq backward 'all)
8688                    gnus-newsgroup-data
8689                  (gnus-data-find-list
8690                   (gnus-summary-article-number)
8691                   (gnus-data-list backward))))
8692       (when (and (or (not unread)       ; We want all articles...
8693                      (gnus-data-unread-p d)) ; Or just unreads.
8694                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8695                  (if not-matching
8696                      (not (string-match
8697                            regexp
8698                            (funcall func (gnus-data-header d))))
8699                    (string-match regexp
8700                                  (funcall func (gnus-data-header d)))))
8701         (push (gnus-data-number d) articles))) ; Success!
8702     (nreverse articles)))
8703
8704 (defun gnus-summary-execute-command (header regexp command &optional backward)
8705   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8706 If HEADER is an empty string (or nil), the match is done on the entire
8707 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8708   (interactive
8709    (list (let ((completion-ignore-case t))
8710            (completing-read
8711             "Header name: "
8712             (mapcar (lambda (header) (list (format "%s" header)))
8713                     (append
8714                      '("Number" "Subject" "From" "Lines" "Date"
8715                        "Message-ID" "Xref" "References" "Body")
8716                      gnus-extra-headers))
8717             nil 'require-match))
8718          (read-string "Regexp: ")
8719          (read-key-sequence "Command: ")
8720          current-prefix-arg))
8721   (when (equal header "Body")
8722     (setq header ""))
8723   ;; Hidden thread subtrees must be searched as well.
8724   (gnus-summary-show-all-threads)
8725   ;; We don't want to change current point nor window configuration.
8726   (save-excursion
8727     (save-window-excursion
8728       (let (gnus-visual
8729             gnus-treat-strip-trailing-blank-lines
8730             gnus-treat-strip-leading-blank-lines
8731             gnus-treat-strip-multiple-blank-lines
8732             gnus-treat-hide-boring-headers
8733             gnus-treat-fold-newsgroups
8734             gnus-article-prepare-hook)
8735         (gnus-message 6 "Executing %s..." (key-description command))
8736         ;; We'd like to execute COMMAND interactively so as to give arguments.
8737         (gnus-execute header regexp
8738                       `(call-interactively ',(key-binding command))
8739                       backward)
8740         (gnus-message 6 "Executing %s...done" (key-description command))))))
8741
8742 (defun gnus-summary-beginning-of-article ()
8743   "Scroll the article back to the beginning."
8744   (interactive)
8745   (gnus-summary-select-article)
8746   (gnus-configure-windows 'article)
8747   (gnus-eval-in-buffer-window gnus-article-buffer
8748     (widen)
8749     (goto-char (point-min))
8750     (when gnus-break-pages
8751       (gnus-narrow-to-page))))
8752
8753 (defun gnus-summary-end-of-article ()
8754   "Scroll to the end of the article."
8755   (interactive)
8756   (gnus-summary-select-article)
8757   (gnus-configure-windows 'article)
8758   (gnus-eval-in-buffer-window gnus-article-buffer
8759     (widen)
8760     (goto-char (point-max))
8761     (recenter -3)
8762     (when gnus-break-pages
8763       (when (re-search-backward page-delimiter nil t)
8764         (narrow-to-region (match-end 0) (point-max)))
8765       (gnus-narrow-to-page))))
8766
8767 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8768   "Truncate to LEN and quote all \"(\"'s in STRING."
8769   (gnus-replace-in-string (if (and len (> (length string) len))
8770                               (substring string 0 len)
8771                             string)
8772                           "[()]" "\\\\\\&"))
8773
8774 (defun gnus-summary-print-article (&optional filename n)
8775   "Generate and print a PostScript image of the process-marked (mail) articles.
8776
8777 If used interactively, print the current article if none are
8778 process-marked.  With prefix arg, prompt the user for the name of the
8779 file to save in.
8780
8781 When used from Lisp, accept two optional args FILENAME and N.  N means
8782 to print the next N articles.  If N is negative, print the N previous
8783 articles.  If N is nil and articles have been marked with the process
8784 mark, print these instead.
8785
8786 If the optional first argument FILENAME is nil, send the image to the
8787 printer.  If FILENAME is a string, save the PostScript image in a file with
8788 that name.  If FILENAME is a number, prompt the user for the name of the file
8789 to save in."
8790   (interactive (list (ps-print-preprint current-prefix-arg)))
8791   (dolist (article (gnus-summary-work-articles n))
8792     (gnus-summary-select-article nil nil 'pseudo article)
8793     (gnus-eval-in-buffer-window gnus-article-buffer
8794       (gnus-print-buffer))
8795     (gnus-summary-remove-process-mark article))
8796   (ps-despool filename))
8797
8798 (defun gnus-print-buffer ()
8799   (let ((buffer (generate-new-buffer " *print*")))
8800     (unwind-protect
8801         (progn
8802           (copy-to-buffer buffer (point-min) (point-max))
8803           (set-buffer buffer)
8804           (gnus-remove-text-with-property 'gnus-decoration)
8805           (when (gnus-visual-p 'article-highlight 'highlight)
8806             ;; Copy-to-buffer doesn't copy overlay.  So redo
8807             ;; highlight.
8808             (let ((gnus-article-buffer buffer))
8809               (gnus-article-highlight-citation t)
8810               (gnus-article-highlight-signature)
8811               (gnus-article-emphasize)
8812               (gnus-article-delete-invisible-text)))
8813           (let ((ps-left-header
8814                  (list
8815                   (concat "("
8816                           (gnus-summary-print-truncate-and-quote
8817                            (mail-header-subject gnus-current-headers)
8818                            66) ")")
8819                   (concat "("
8820                           (gnus-summary-print-truncate-and-quote
8821                            (mail-header-from gnus-current-headers)
8822                            45) ")")))
8823                 (ps-right-header
8824                  (list
8825                   "/pagenumberstring load"
8826                   (concat "("
8827                           (mail-header-date gnus-current-headers) ")"))))
8828             (gnus-run-hooks 'gnus-ps-print-hook)
8829             (save-excursion
8830               (if window-system
8831                   (ps-spool-buffer-with-faces)
8832                 (ps-spool-buffer)))))
8833       (kill-buffer buffer))))
8834
8835 (defun gnus-summary-show-article (&optional arg)
8836   "Force redisplaying of the current article.
8837 If ARG (the prefix) is a number, show the article with the charset
8838 defined in `gnus-summary-show-article-charset-alist', or the charset
8839 input.
8840 If ARG (the prefix) is non-nil and not a number, show the raw article
8841 without any article massaging functions being run.  Normally, the key
8842 strokes are `C-u g'."
8843   (interactive "P")
8844   (cond
8845    ((numberp arg)
8846     (gnus-summary-show-article t)
8847     (let* ((gnus-newsgroup-charset
8848             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8849                 (mm-read-coding-system
8850                  "View as charset: " ;; actually it is coding system.
8851                  (with-current-buffer gnus-article-buffer
8852                    (mm-detect-coding-region (point) (point-max))))))
8853            (default-mime-charset gnus-newsgroup-charset)
8854            (gnus-newsgroup-ignored-charsets 'gnus-all))
8855       (gnus-summary-select-article nil 'force)
8856       (let ((deps gnus-newsgroup-dependencies)
8857             head header lines)
8858         (save-excursion
8859           (set-buffer gnus-original-article-buffer)
8860           (save-restriction
8861             (message-narrow-to-head)
8862             (setq head (buffer-string))
8863             (goto-char (point-min))
8864             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8865               (goto-char (point-max))
8866               (widen)
8867               (setq lines (1- (count-lines (point) (point-max))))))
8868           (with-temp-buffer
8869             (insert (format "211 %d Article retrieved.\n"
8870                             (cdr gnus-article-current)))
8871             (insert head)
8872             (if lines (insert (format "Lines: %d\n" lines)))
8873             (insert ".\n")
8874             (let ((nntp-server-buffer (current-buffer)))
8875               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8876         (gnus-data-set-header
8877          (gnus-data-find (cdr gnus-article-current))
8878          header)
8879         (gnus-summary-update-article-line
8880          (cdr gnus-article-current) header)
8881         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8882           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8883    ((not arg)
8884     ;; Select the article the normal way.
8885     (gnus-summary-select-article nil 'force))
8886    (t
8887     ;; We have to require this here to make sure that the following
8888     ;; dynamic binding isn't shadowed by autoloading.
8889     (require 'gnus-async)
8890     (require 'gnus-art)
8891     ;; Bind the article treatment functions to nil.
8892     (let ((gnus-have-all-headers t)
8893           gnus-article-prepare-hook
8894           gnus-article-decode-hook
8895           gnus-break-pages
8896           gnus-show-mime
8897           (gnus-inhibit-treatment t))
8898       (gnus-summary-select-article nil 'force))))
8899   (gnus-summary-goto-subject gnus-current-article)
8900   (gnus-summary-position-point))
8901
8902 (defun gnus-summary-show-raw-article ()
8903   "Show the raw article without any article massaging functions being run."
8904   (interactive)
8905   (gnus-summary-show-article t))
8906
8907 (defun gnus-summary-verbose-headers (&optional arg)
8908   "Toggle permanent full header display.
8909 If ARG is a positive number, turn header display on.
8910 If ARG is a negative number, turn header display off."
8911   (interactive "P")
8912   (setq gnus-show-all-headers
8913         (cond ((or (not (numberp arg))
8914                    (zerop arg))
8915                (not gnus-show-all-headers))
8916               ((natnump arg)
8917                t)))
8918   (gnus-summary-show-article))
8919
8920 (defun gnus-summary-toggle-header (&optional arg)
8921   "Show the headers if they are hidden, or hide them if they are shown.
8922 If ARG is a positive number, show the entire header.
8923 If ARG is a negative number, hide the unwanted header lines."
8924   (interactive "P")
8925   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8926                      (get-buffer-window gnus-article-buffer t))))
8927     (with-current-buffer gnus-article-buffer
8928       (widen)
8929       (article-narrow-to-head)
8930       (let* ((buffer-read-only nil)
8931              (inhibit-point-motion-hooks t)
8932              (hidden (if (numberp arg)
8933                          (>= arg 0)
8934                        (or (not (looking-at "[^ \t\n]+:"))
8935                            (gnus-article-hidden-text-p 'headers))))
8936              s e)
8937         (delete-region (point-min) (point-max))
8938         (with-current-buffer gnus-original-article-buffer
8939           (goto-char (setq s (point-min)))
8940           (setq e (if (search-forward "\n\n" nil t)
8941                       (1- (point))
8942                     (point-max))))
8943         (insert-buffer-substring gnus-original-article-buffer s e)
8944         ;; In T-gnus, gnus-article-decode-hook doesn't contain
8945         ;; article-decode-encoded-words by default.
8946         (article-decode-encoded-words)
8947         (run-hooks 'gnus-article-decode-hook)
8948         (if hidden
8949             (let ((gnus-treat-hide-headers nil)
8950                   (gnus-treat-hide-boring-headers nil))
8951               (gnus-delete-wash-type 'headers)
8952               (gnus-treat-article 'head))
8953           (gnus-treat-article 'head))
8954         (widen)
8955         (if window
8956             (set-window-start window (goto-char (point-min))))
8957         (if gnus-break-pages
8958             (gnus-narrow-to-page)
8959           (when (gnus-visual-p 'page-marker)
8960             (let ((buffer-read-only nil))
8961               (gnus-remove-text-with-property 'gnus-prev)
8962               (gnus-remove-text-with-property 'gnus-next))))
8963         (gnus-set-mode-line 'article)))))
8964
8965 (defun gnus-summary-show-all-headers ()
8966   "Make all header lines visible."
8967   (interactive)
8968   (gnus-summary-toggle-header 1))
8969
8970 (defun gnus-summary-toggle-mime (&optional arg)
8971   "Toggle MIME processing.
8972 If ARG is a positive number, turn MIME processing on."
8973   (interactive "P")
8974   (setq gnus-show-mime
8975         (if (null arg)
8976             (not gnus-show-mime)
8977           (> (prefix-numeric-value arg) 0)))
8978   (gnus-summary-select-article t 'force))
8979
8980 (defun gnus-summary-caesar-message (&optional arg)
8981   "Caesar rotate the current article by 13.
8982 The numerical prefix specifies how many places to rotate each letter
8983 forward."
8984   (interactive "P")
8985   (gnus-summary-select-article)
8986   (let ((mail-header-separator ""))
8987     (gnus-eval-in-buffer-window gnus-article-buffer
8988       (save-restriction
8989         (widen)
8990         (let ((start (window-start))
8991               buffer-read-only)
8992           (message-caesar-buffer-body arg)
8993           (set-window-start (get-buffer-window (current-buffer)) start))))))
8994
8995 (autoload 'unmorse-region "morse"
8996   "Convert morse coded text in region to ordinary ASCII text."
8997   t)
8998
8999 (defun gnus-summary-morse-message (&optional arg)
9000   "Morse decode the current article."
9001   (interactive "P")
9002   (gnus-summary-select-article)
9003   (let ((mail-header-separator ""))
9004     (gnus-eval-in-buffer-window gnus-article-buffer
9005       (save-excursion
9006         (save-restriction
9007           (widen)
9008           (let ((pos (window-start))
9009                 buffer-read-only)
9010             (goto-char (point-min))
9011             (when (message-goto-body)
9012               (gnus-narrow-to-body))
9013             (goto-char (point-min))
9014             (while (search-forward "·" (point-max) t)
9015               (replace-match "."))
9016             (unmorse-region (point-min) (point-max))
9017             (widen)
9018             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9019
9020 (defun gnus-summary-stop-page-breaking ()
9021   "Stop page breaking in the current article."
9022   (interactive)
9023   (gnus-summary-select-article)
9024   (gnus-eval-in-buffer-window gnus-article-buffer
9025     (widen)
9026     (when (gnus-visual-p 'page-marker)
9027       (let ((buffer-read-only nil))
9028         (gnus-remove-text-with-property 'gnus-prev)
9029         (gnus-remove-text-with-property 'gnus-next))
9030       (setq gnus-page-broken nil))))
9031
9032 (defun gnus-summary-move-article (&optional n to-newsgroup
9033                                             select-method action)
9034   "Move the current article to a different newsgroup.
9035 If N is a positive number, move the N next articles.
9036 If N is a negative number, move the N previous articles.
9037 If N is nil and any articles have been marked with the process mark,
9038 move those articles instead.
9039 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9040 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9041 re-spool using this method.
9042
9043 When called interactively with TO-NEWSGROUP being nil, the value of
9044 the variable `gnus-move-split-methods' is used for finding a default
9045 for the target newsgroup.
9046
9047 For this function to work, both the current newsgroup and the
9048 newsgroup that you want to move to have to support the `request-move'
9049 and `request-accept' functions.
9050
9051 ACTION can be either `move' (the default), `crosspost' or `copy'."
9052   (interactive "P")
9053   (unless action
9054     (setq action 'move))
9055   ;; Check whether the source group supports the required functions.
9056   (cond ((and (eq action 'move)
9057               (not (gnus-check-backend-function
9058                     'request-move-article gnus-newsgroup-name)))
9059          (error "The current group does not support article moving"))
9060         ((and (eq action 'crosspost)
9061               (not (gnus-check-backend-function
9062                     'request-replace-article gnus-newsgroup-name)))
9063          (error "The current group does not support article editing")))
9064   (let ((articles (gnus-summary-work-articles n))
9065         (prefix (if (gnus-check-backend-function
9066                      'request-move-article gnus-newsgroup-name)
9067                     (funcall gnus-move-group-prefix-function
9068                              gnus-newsgroup-name)
9069                   ""))
9070         (names '((move "Move" "Moving")
9071                  (copy "Copy" "Copying")
9072                  (crosspost "Crosspost" "Crossposting")))
9073         (copy-buf (save-excursion
9074                     (nnheader-set-temp-buffer " *copy article*")))
9075         art-group to-method new-xref article to-groups)
9076     (unless (assq action names)
9077       (error "Unknown action %s" action))
9078     ;; Read the newsgroup name.
9079     (when (and (not to-newsgroup)
9080                (not select-method))
9081       (if (and gnus-move-split-methods
9082                (not
9083                 (and (memq gnus-current-article articles)
9084                      (gnus-buffer-live-p gnus-original-article-buffer))))
9085           ;; When `gnus-move-split-methods' is non-nil, we have to
9086           ;; select an article to give `gnus-read-move-group-name' an
9087           ;; opportunity to suggest an appropriate default.  However,
9088           ;; we needn't render or mark the article.
9089           (let ((gnus-display-mime-function nil)
9090                 (gnus-article-prepare-hook nil)
9091                 (gnus-mark-article-hook nil))
9092             (gnus-summary-select-article nil nil nil (car articles))))
9093       (setq to-newsgroup
9094             (gnus-read-move-group-name
9095              (cadr (assq action names))
9096              (symbol-value (intern (format "gnus-current-%s-group" action)))
9097              articles prefix))
9098       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9099     (setq to-method (or select-method
9100                         (gnus-server-to-method
9101                          (gnus-group-method to-newsgroup))))
9102     ;; Check the method we are to move this article to...
9103     (unless (gnus-check-backend-function
9104              'request-accept-article (car to-method))
9105       (error "%s does not support article copying" (car to-method)))
9106     (unless (gnus-check-server to-method)
9107       (error "Can't open server %s" (car to-method)))
9108     (gnus-message 6 "%s to %s: %s..."
9109                   (caddr (assq action names))
9110                   (or (car select-method) to-newsgroup) articles)
9111     (while articles
9112       (setq article (pop articles))
9113       (setq
9114        art-group
9115        (cond
9116         ;; Move the article.
9117         ((eq action 'move)
9118          ;; Remove this article from future suppression.
9119          (gnus-dup-unsuppress-article article)
9120          (gnus-request-move-article
9121           article                       ; Article to move
9122           gnus-newsgroup-name           ; From newsgroup
9123           (nth 1 (gnus-find-method-for-group
9124                   gnus-newsgroup-name)) ; Server
9125           (list 'gnus-request-accept-article
9126                 to-newsgroup (list 'quote select-method)
9127                 (not articles) t)       ; Accept form
9128           (not articles)))              ; Only save nov last time
9129         ;; Copy the article.
9130         ((eq action 'copy)
9131          (save-excursion
9132            (set-buffer copy-buf)
9133            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9134              (gnus-request-accept-article
9135               to-newsgroup select-method (not articles) t))))
9136         ;; Crosspost the article.
9137         ((eq action 'crosspost)
9138          (let ((xref (message-tokenize-header
9139                       (mail-header-xref (gnus-summary-article-header article))
9140                       " ")))
9141            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9142                                   ":" (number-to-string article)))
9143            (unless xref
9144              (setq xref (list (system-name))))
9145            (setq new-xref
9146                  (concat
9147                   (mapconcat 'identity
9148                              (delete "Xref:" (delete new-xref xref))
9149                              " ")
9150                   " " new-xref))
9151            (save-excursion
9152              (set-buffer copy-buf)
9153              ;; First put the article in the destination group.
9154              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9155              (when (consp (setq art-group
9156                                 (gnus-request-accept-article
9157                                  to-newsgroup select-method (not articles))))
9158                (setq new-xref (concat new-xref " " (car art-group)
9159                                       ":"
9160                                       (number-to-string (cdr art-group))))
9161                ;; Now we have the new Xrefs header, so we insert
9162                ;; it and replace the new article.
9163                (nnheader-replace-header "Xref" new-xref)
9164                (gnus-request-replace-article
9165                 (cdr art-group) to-newsgroup (current-buffer))
9166                art-group))))))
9167       (cond
9168        ((not art-group)
9169         (gnus-message 1 "Couldn't %s article %s: %s"
9170                       (cadr (assq action names)) article
9171                       (nnheader-get-report (car to-method))))
9172        ((eq art-group 'junk)
9173         (when (eq action 'move)
9174           (gnus-summary-mark-article article gnus-canceled-mark)
9175           (gnus-message 4 "Deleted article %s" article)
9176           ;; run the delete hook
9177           (run-hook-with-args 'gnus-summary-article-delete-hook
9178                               action
9179                               (gnus-data-header
9180                                (assoc article (gnus-data-list nil)))
9181                               gnus-newsgroup-name nil
9182                               select-method)))
9183        (t
9184         (let* ((pto-group (gnus-group-prefixed-name
9185                            (car art-group) to-method))
9186                (info (gnus-get-info pto-group))
9187                (to-group (gnus-info-group info))
9188                to-marks)
9189           ;; Update the group that has been moved to.
9190           (when (and info
9191                      (memq action '(move copy)))
9192             (unless (member to-group to-groups)
9193               (push to-group to-groups))
9194
9195             (unless (memq article gnus-newsgroup-unreads)
9196               (push 'read to-marks)
9197               (gnus-info-set-read
9198                info (gnus-add-to-range (gnus-info-read info)
9199                                        (list (cdr art-group)))))
9200
9201             ;; See whether the article is to be put in the cache.
9202             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9203                              gnus-article-mark-lists
9204                            (delete '(expirable . expire)
9205                                    (copy-sequence gnus-article-mark-lists))))
9206                   (to-article (cdr art-group)))
9207
9208               ;; Enter the article into the cache in the new group,
9209               ;; if that is required.
9210               (when gnus-use-cache
9211                 (gnus-cache-possibly-enter-article
9212                  to-group to-article
9213                  (let ((header (copy-sequence
9214                                 (gnus-summary-article-header article))))
9215                    (mail-header-set-number header to-article)
9216                    header)
9217                  (memq article gnus-newsgroup-marked)
9218                  (memq article gnus-newsgroup-dormant)
9219                  (memq article gnus-newsgroup-unreads)))
9220
9221               (when gnus-preserve-marks
9222                 ;; Copy any marks over to the new group.
9223                 (when (and (equal to-group gnus-newsgroup-name)
9224                            (not (memq article gnus-newsgroup-unreads)))
9225                   ;; Mark this article as read in this group.
9226                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9227                   (setcdr (gnus-active to-group) to-article)
9228                   (setcdr gnus-newsgroup-active to-article))
9229
9230                 (while marks
9231                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9232                     (when (memq article (symbol-value
9233                                          (intern (format "gnus-newsgroup-%s"
9234                                                          (caar marks)))))
9235                       (push (cdar marks) to-marks)
9236                       ;; If the other group is the same as this group,
9237                       ;; then we have to add the mark to the list.
9238                       (when (equal to-group gnus-newsgroup-name)
9239                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9240                              (cons to-article
9241                                    (symbol-value
9242                                     (intern (format "gnus-newsgroup-%s"
9243                                                     (caar marks)))))))
9244                       ;; Copy the marks to other group.
9245                       (gnus-add-marked-articles
9246                        to-group (cdar marks) (list to-article) info)))
9247                   (setq marks (cdr marks)))
9248
9249                 (gnus-request-set-mark
9250                  to-group (list (list (list to-article) 'add to-marks))))
9251
9252               (gnus-dribble-enter
9253                (concat "(gnus-group-set-info '"
9254                        (gnus-prin1-to-string (gnus-get-info to-group))
9255                        ")"))))
9256
9257           ;; Update the Xref header in this article to point to
9258           ;; the new crossposted article we have just created.
9259           (when (eq action 'crosspost)
9260             (save-excursion
9261               (set-buffer copy-buf)
9262               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9263               (nnheader-replace-header "Xref" new-xref)
9264               (gnus-request-replace-article
9265                article gnus-newsgroup-name (current-buffer))))
9266
9267           ;; run the move/copy/crosspost/respool hook
9268           (run-hook-with-args 'gnus-summary-article-move-hook
9269                               action
9270                               (gnus-data-header
9271                                (assoc article (gnus-data-list nil)))
9272                               gnus-newsgroup-name
9273                               to-newsgroup
9274                               select-method))
9275
9276         ;;;!!!Why is this necessary?
9277         (set-buffer gnus-summary-buffer)
9278         
9279         (gnus-summary-goto-subject article)
9280         (when (eq action 'move)
9281           (gnus-summary-mark-article article gnus-canceled-mark))))
9282       (gnus-summary-remove-process-mark article))
9283     ;; Re-activate all groups that have been moved to.
9284     (save-excursion
9285       (set-buffer gnus-group-buffer)
9286       (let ((gnus-group-marked to-groups))
9287         (gnus-group-get-new-news-this-group nil t)))
9288
9289     (gnus-kill-buffer copy-buf)
9290     (gnus-summary-position-point)
9291     (gnus-set-mode-line 'summary)))
9292
9293 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9294   "Copy the current article to some other group.
9295 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9296 When called interactively, if TO-NEWSGROUP is nil, use the value of
9297 the variable `gnus-move-split-methods' for finding a default target
9298 newsgroup.
9299 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9300 re-spool using this method."
9301   (interactive "P")
9302   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9303
9304 (defun gnus-summary-crosspost-article (&optional n)
9305   "Crosspost the current article to some other group."
9306   (interactive "P")
9307   (gnus-summary-move-article n nil nil 'crosspost))
9308
9309 (defcustom gnus-summary-respool-default-method nil
9310   "Default method type for respooling an article.
9311 If nil, use to the current newsgroup method."
9312   :type 'symbol
9313   :group 'gnus-summary-mail)
9314
9315 (defcustom gnus-summary-display-while-building nil
9316   "If non-nil, show and update the summary buffer as it's being built.
9317 If the value is t, update the buffer after every line is inserted.  If
9318 the value is an integer (N), update the display every N lines."
9319   :group 'gnus-thread
9320   :type '(choice (const :tag "off" nil)
9321                  number
9322                  (const :tag "frequently" t)))
9323
9324 (defun gnus-summary-respool-article (&optional n method)
9325   "Respool the current article.
9326 The article will be squeezed through the mail spooling process again,
9327 which means that it will be put in some mail newsgroup or other
9328 depending on `nnmail-split-methods'.
9329 If N is a positive number, respool the N next articles.
9330 If N is a negative number, respool the N previous articles.
9331 If N is nil and any articles have been marked with the process mark,
9332 respool those articles instead.
9333
9334 Respooling can be done both from mail groups and \"real\" newsgroups.
9335 In the former case, the articles in question will be moved from the
9336 current group into whatever groups they are destined to.  In the
9337 latter case, they will be copied into the relevant groups."
9338   (interactive
9339    (list current-prefix-arg
9340          (let* ((methods (gnus-methods-using 'respool))
9341                 (methname
9342                  (symbol-name (or gnus-summary-respool-default-method
9343                                   (car (gnus-find-method-for-group
9344                                         gnus-newsgroup-name)))))
9345                 (method
9346                  (gnus-completing-read-with-default
9347                   methname "What backend do you want to use when respooling?"
9348                   methods nil t nil 'gnus-mail-method-history))
9349                 ms)
9350            (cond
9351             ((zerop (length (setq ms (gnus-servers-using-backend
9352                                       (intern method)))))
9353              (list (intern method) ""))
9354             ((= 1 (length ms))
9355              (car ms))
9356             (t
9357              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9358                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9359                            ms-alist))))))))
9360   (unless method
9361     (error "No method given for respooling"))
9362   (if (assoc (symbol-name
9363               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9364              (gnus-methods-using 'respool))
9365       (gnus-summary-move-article n nil method)
9366     (gnus-summary-copy-article n nil method)))
9367
9368 (defun gnus-summary-import-article (file &optional edit)
9369   "Import an arbitrary file into a mail newsgroup."
9370   (interactive "fImport file: \nP")
9371   (let ((group gnus-newsgroup-name)
9372         (now (current-time))
9373         atts lines group-art)
9374     (unless (gnus-check-backend-function 'request-accept-article group)
9375       (error "%s does not support article importing" group))
9376     (or (file-readable-p file)
9377         (not (file-regular-p file))
9378         (error "Can't read %s" file))
9379     (save-excursion
9380       (set-buffer (gnus-get-buffer-create " *import file*"))
9381       (erase-buffer)
9382       (nnheader-insert-file-contents file)
9383       (goto-char (point-min))
9384       (if (nnheader-article-p)
9385           (save-restriction
9386             (goto-char (point-min))
9387             (search-forward "\n\n" nil t)
9388             (narrow-to-region (point-min) (1- (point)))
9389             (goto-char (point-min))
9390             (unless (re-search-forward "^date:" nil t)
9391               (goto-char (point-max))
9392               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9393         ;; This doesn't look like an article, so we fudge some headers.
9394         (setq atts (file-attributes file)
9395               lines (count-lines (point-min) (point-max)))
9396         (insert "From: " (read-string "From: ") "\n"
9397                 "Subject: " (read-string "Subject: ") "\n"
9398                 "Date: " (message-make-date (nth 5 atts)) "\n"
9399                 "Message-ID: " (message-make-message-id) "\n"
9400                 "Lines: " (int-to-string lines) "\n"
9401                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9402       (setq group-art (gnus-request-accept-article group nil t))
9403       (kill-buffer (current-buffer)))
9404     (setq gnus-newsgroup-active (gnus-activate-group group))
9405     (forward-line 1)
9406     (gnus-summary-goto-article (cdr group-art) nil t)
9407     (when edit
9408       (gnus-summary-edit-article))))
9409
9410 (defun gnus-summary-create-article ()
9411   "Create an article in a mail newsgroup."
9412   (interactive)
9413   (let ((group gnus-newsgroup-name)
9414         (now (current-time))
9415         group-art)
9416     (unless (gnus-check-backend-function 'request-accept-article group)
9417       (error "%s does not support article importing" group))
9418     (save-excursion
9419       (set-buffer (gnus-get-buffer-create " *import file*"))
9420       (erase-buffer)
9421       (goto-char (point-min))
9422       ;; This doesn't look like an article, so we fudge some headers.
9423       (insert "From: " (read-string "From: ") "\n"
9424               "Subject: " (read-string "Subject: ") "\n"
9425               "Date: " (message-make-date now) "\n"
9426               "Message-ID: " (message-make-message-id) "\n")
9427       (setq group-art (gnus-request-accept-article group nil t))
9428       (kill-buffer (current-buffer)))
9429     (setq gnus-newsgroup-active (gnus-activate-group group))
9430     (forward-line 1)
9431     (gnus-summary-goto-article (cdr group-art) nil t)
9432     (gnus-summary-edit-article)))
9433
9434 (defun gnus-summary-article-posted-p ()
9435   "Say whether the current (mail) article is available from news as well.
9436 This will be the case if the article has both been mailed and posted."
9437   (interactive)
9438   (let ((id (mail-header-references (gnus-summary-article-header)))
9439         (gnus-override-method (car (gnus-refer-article-methods))))
9440     (if (gnus-request-head id "")
9441         (gnus-message 2 "The current message was found on %s"
9442                       gnus-override-method)
9443       (gnus-message 2 "The current message couldn't be found on %s"
9444                     gnus-override-method)
9445       nil)))
9446
9447 (defun gnus-summary-expire-articles (&optional now)
9448   "Expire all articles that are marked as expirable in the current group."
9449   (interactive)
9450   (when (and (not gnus-group-is-exiting-without-update-p)
9451              (gnus-check-backend-function
9452               'request-expire-articles gnus-newsgroup-name))
9453     ;; This backend supports expiry.
9454     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9455            (expirable (if total
9456                           (progn
9457                             ;; We need to update the info for
9458                             ;; this group for `gnus-list-of-read-articles'
9459                             ;; to give us the right answer.
9460                             (gnus-run-hooks 'gnus-exit-group-hook)
9461                             (gnus-summary-update-info)
9462                             (gnus-list-of-read-articles gnus-newsgroup-name))
9463                         (setq gnus-newsgroup-expirable
9464                               (sort gnus-newsgroup-expirable '<))))
9465            (expiry-wait (if now 'immediate
9466                           (gnus-group-find-parameter
9467                            gnus-newsgroup-name 'expiry-wait)))
9468            (nnmail-expiry-target
9469             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9470                 nnmail-expiry-target))
9471            es)
9472       (when expirable
9473         ;; There are expirable articles in this group, so we run them
9474         ;; through the expiry process.
9475         (gnus-message 6 "Expiring articles...")
9476         (unless (gnus-check-group gnus-newsgroup-name)
9477           (error "Can't open server for %s" gnus-newsgroup-name))
9478         ;; The list of articles that weren't expired is returned.
9479         (save-excursion
9480           (if expiry-wait
9481               (let ((nnmail-expiry-wait-function nil)
9482                     (nnmail-expiry-wait expiry-wait))
9483                 (setq es (gnus-request-expire-articles
9484                           expirable gnus-newsgroup-name)))
9485             (setq es (gnus-request-expire-articles
9486                       expirable gnus-newsgroup-name)))
9487           (unless total
9488             (setq gnus-newsgroup-expirable es))
9489           ;; We go through the old list of expirable, and mark all
9490           ;; really expired articles as nonexistent.
9491           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9492             (let ((gnus-use-cache nil))
9493               (dolist (article expirable)
9494                 (when (and (not (memq article es))
9495                            (gnus-data-find article))
9496                   (gnus-summary-mark-article article gnus-canceled-mark)
9497                   (run-hook-with-args 'gnus-summary-article-expire-hook
9498                                       'delete
9499                                       (gnus-data-header
9500                                        (assoc article (gnus-data-list nil)))
9501                                       gnus-newsgroup-name
9502                                       nil
9503                                       nil))))))
9504         (gnus-message 6 "Expiring articles...done")))))
9505
9506 (defun gnus-summary-expire-articles-now ()
9507   "Expunge all expirable articles in the current group.
9508 This means that *all* articles that are marked as expirable will be
9509 deleted forever, right now."
9510   (interactive)
9511   (or gnus-expert-user
9512       (gnus-yes-or-no-p
9513        "Are you really, really, really sure you want to delete all these messages? ")
9514       (error "Phew!"))
9515   (gnus-summary-expire-articles t))
9516
9517 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9518 (defun gnus-summary-delete-article (&optional n)
9519   "Delete the N next (mail) articles.
9520 This command actually deletes articles.  This is not a marking
9521 command.  The article will disappear forever from your life, never to
9522 return.
9523
9524 If N is negative, delete backwards.
9525 If N is nil and articles have been marked with the process mark,
9526 delete these instead.
9527
9528 If `gnus-novice-user' is non-nil you will be asked for
9529 confirmation before the articles are deleted."
9530   (interactive "P")
9531   (unless (gnus-check-backend-function 'request-expire-articles
9532                                        gnus-newsgroup-name)
9533     (error "The current newsgroup does not support article deletion"))
9534   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9535     (error "Couldn't open server"))
9536   ;; Compute the list of articles to delete.
9537   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9538         (nnmail-expiry-target 'delete)
9539         not-deleted)
9540     (if (and gnus-novice-user
9541              (not (gnus-yes-or-no-p
9542                    (format "Do you really want to delete %s forever? "
9543                            (if (> (length articles) 1)
9544                                (format "these %s articles" (length articles))
9545                              "this article")))))
9546         ()
9547       ;; Delete the articles.
9548       (setq not-deleted (gnus-request-expire-articles
9549                          articles gnus-newsgroup-name 'force))
9550       (while articles
9551         (gnus-summary-remove-process-mark (car articles))
9552         ;; The backend might not have been able to delete the article
9553         ;; after all.
9554         (unless (memq (car articles) not-deleted)
9555           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9556         (let* ((article (car articles))
9557                (ghead  (gnus-data-header
9558                                     (assoc article (gnus-data-list nil)))))
9559           (run-hook-with-args 'gnus-summary-article-delete-hook
9560                               'delete ghead gnus-newsgroup-name nil
9561                               nil))
9562         (setq articles (cdr articles)))
9563       (when not-deleted
9564         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9565     (gnus-summary-position-point)
9566     (gnus-set-mode-line 'summary)
9567     not-deleted))
9568
9569 (defun gnus-summary-edit-article (&optional force)
9570   "Edit the current article.
9571 This will have permanent effect only in mail groups.
9572 If FORCE is non-nil, allow editing of articles even in read-only
9573 groups."
9574   (interactive "P")
9575   (save-excursion
9576     (set-buffer gnus-summary-buffer)
9577     (let ((mail-parse-charset gnus-newsgroup-charset)
9578           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9579       (gnus-set-global-variables)
9580       (when (and (not force)
9581                  (gnus-group-read-only-p))
9582         (error "The current newsgroup does not support article editing"))
9583       (gnus-summary-show-article t)
9584       (gnus-article-edit-article
9585        'ignore
9586        `(lambda (no-highlight)
9587           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9588                 (message-options message-options)
9589                 (message-options-set-recipient)
9590                 (mail-parse-ignored-charsets
9591                  ',gnus-newsgroup-ignored-charsets))
9592             (gnus-summary-edit-article-done
9593              ,(or (mail-header-references gnus-current-headers) "")
9594              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9595
9596 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9597
9598 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9599                                                  no-highlight)
9600   "Make edits to the current article permanent."
9601   (interactive)
9602   (save-excursion
9603     ;; The buffer restriction contains the entire article if it exists.
9604     (when (article-goto-body)
9605       (let ((lines (count-lines (point) (point-max)))
9606             (length (- (point-max) (point)))
9607             (case-fold-search t)
9608             (body (copy-marker (point))))
9609         (goto-char (point-min))
9610         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9611           (delete-region (match-beginning 1) (match-end 1))
9612           (insert (number-to-string length)))
9613         (goto-char (point-min))
9614         (when (re-search-forward
9615                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9616           (delete-region (match-beginning 1) (match-end 1))
9617           (insert (number-to-string length)))
9618         (goto-char (point-min))
9619         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9620           (delete-region (match-beginning 1) (match-end 1))
9621           (insert (number-to-string lines))))))
9622   ;; Replace the article.
9623   (let ((buf (current-buffer)))
9624     (with-temp-buffer
9625       (insert-buffer-substring buf)
9626
9627       (if (and (not read-only)
9628                (not (gnus-request-replace-article
9629                      (cdr gnus-article-current) (car gnus-article-current)
9630                      (current-buffer) t)))
9631           (error "Couldn't replace article")
9632         ;; Update the summary buffer.
9633         (if (and references
9634                  (equal (message-tokenize-header references " ")
9635                         (message-tokenize-header
9636                          (or (message-fetch-field "references") "") " ")))
9637             ;; We only have to update this line.
9638             (save-excursion
9639               (save-restriction
9640                 (message-narrow-to-head)
9641                 (let ((head (buffer-string))
9642                       header)
9643                   (with-temp-buffer
9644                     (insert (format "211 %d Article retrieved.\n"
9645                                     (cdr gnus-article-current)))
9646                     (insert head)
9647                     (insert ".\n")
9648                     (let ((nntp-server-buffer (current-buffer)))
9649                       (setq header (car (gnus-get-newsgroup-headers
9650                                          nil t))))
9651                     (save-excursion
9652                       (set-buffer gnus-summary-buffer)
9653                       (gnus-data-set-header
9654                        (gnus-data-find (cdr gnus-article-current))
9655                        header)
9656                       (gnus-summary-update-article-line
9657                        (cdr gnus-article-current) header)
9658                       (if (gnus-summary-goto-subject
9659                            (cdr gnus-article-current) nil t)
9660                           (gnus-summary-update-secondary-mark
9661                            (cdr gnus-article-current))))))))
9662           ;; Update threads.
9663           (set-buffer (or buffer gnus-summary-buffer))
9664           (gnus-summary-update-article (cdr gnus-article-current))
9665           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9666               (gnus-summary-update-secondary-mark
9667                (cdr gnus-article-current))))
9668         ;; Prettify the article buffer again.
9669         (unless no-highlight
9670           (save-excursion
9671             (set-buffer gnus-article-buffer)
9672             ;;;!!! Fix this -- article should be rehighlighted.
9673             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9674             (set-buffer gnus-original-article-buffer)
9675             (gnus-request-article
9676              (cdr gnus-article-current)
9677              (car gnus-article-current) (current-buffer))))
9678         ;; Prettify the summary buffer line.
9679         (when (gnus-visual-p 'summary-highlight 'highlight)
9680           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9681
9682 (defun gnus-summary-edit-wash (key)
9683   "Perform editing command KEY in the article buffer."
9684   (interactive
9685    (list
9686     (progn
9687       (message "%s" (concat (this-command-keys) "- "))
9688       (read-char))))
9689   (message "")
9690   (gnus-summary-edit-article)
9691   (execute-kbd-macro (concat (this-command-keys) key))
9692   (gnus-article-edit-done))
9693
9694 ;;; Respooling
9695
9696 (defun gnus-summary-respool-query (&optional silent trace)
9697   "Query where the respool algorithm would put this article."
9698   (interactive)
9699   (let (gnus-mark-article-hook)
9700     (gnus-summary-select-article)
9701     (save-excursion
9702       (set-buffer gnus-original-article-buffer)
9703       (let ((groups (nnmail-article-group 'identity trace)))
9704         (unless silent
9705           (if groups
9706               (message "This message would go to %s"
9707                        (mapconcat 'car groups ", "))
9708             (message "This message would go to no groups"))
9709           groups)))))
9710
9711 (defun gnus-summary-respool-trace ()
9712   "Trace where the respool algorithm would put this article.
9713 Display a buffer showing all fancy splitting patterns which matched."
9714   (interactive)
9715   (gnus-summary-respool-query nil t))
9716
9717 ;; Summary marking commands.
9718
9719 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9720   "Mark articles which has the same subject as read, and then select the next.
9721 If UNMARK is positive, remove any kind of mark.
9722 If UNMARK is negative, tick articles."
9723   (interactive "P")
9724   (when unmark
9725     (setq unmark (prefix-numeric-value unmark)))
9726   (let ((count
9727          (gnus-summary-mark-same-subject
9728           (gnus-summary-article-subject) unmark)))
9729     ;; Select next unread article.  If auto-select-same mode, should
9730     ;; select the first unread article.
9731     (gnus-summary-next-article t (and gnus-auto-select-same
9732                                       (gnus-summary-article-subject)))
9733     (gnus-message 7 "%d article%s marked as %s"
9734                   count (if (= count 1) " is" "s are")
9735                   (if unmark "unread" "read"))))
9736
9737 (defun gnus-summary-kill-same-subject (&optional unmark)
9738   "Mark articles which has the same subject as read.
9739 If UNMARK is positive, remove any kind of mark.
9740 If UNMARK is negative, tick articles."
9741   (interactive "P")
9742   (when unmark
9743     (setq unmark (prefix-numeric-value unmark)))
9744   (let ((count
9745          (gnus-summary-mark-same-subject
9746           (gnus-summary-article-subject) unmark)))
9747     ;; If marked as read, go to next unread subject.
9748     (when (null unmark)
9749       ;; Go to next unread subject.
9750       (gnus-summary-next-subject 1 t))
9751     (gnus-message 7 "%d articles are marked as %s"
9752                   count (if unmark "unread" "read"))))
9753
9754 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9755   "Mark articles with same SUBJECT as read, and return marked number.
9756 If optional argument UNMARK is positive, remove any kinds of marks.
9757 If optional argument UNMARK is negative, mark articles as unread instead."
9758   (let ((count 1))
9759     (save-excursion
9760       (cond
9761        ((null unmark)                   ; Mark as read.
9762         (while (and
9763                 (progn
9764                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9765                   (gnus-summary-show-thread) t)
9766                 (gnus-summary-find-subject subject))
9767           (setq count (1+ count))))
9768        ((> unmark 0)                    ; Tick.
9769         (while (and
9770                 (progn
9771                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9772                   (gnus-summary-show-thread) t)
9773                 (gnus-summary-find-subject subject))
9774           (setq count (1+ count))))
9775        (t                               ; Mark as unread.
9776         (while (and
9777                 (progn
9778                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9779                   (gnus-summary-show-thread) t)
9780                 (gnus-summary-find-subject subject))
9781           (setq count (1+ count)))))
9782       (gnus-set-mode-line 'summary)
9783       ;; Return the number of marked articles.
9784       count)))
9785
9786 (defun gnus-summary-mark-as-processable (n &optional unmark)
9787   "Set the process mark on the next N articles.
9788 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9789 the process mark instead.  The difference between N and the actual
9790 number of articles marked is returned."
9791   (interactive "P")
9792   (if (and (null n) (gnus-region-active-p))
9793       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9794     (setq n (prefix-numeric-value n))
9795     (let ((backward (< n 0))
9796           (n (abs n)))
9797       (while (and
9798               (> n 0)
9799               (if unmark
9800                   (gnus-summary-remove-process-mark
9801                    (gnus-summary-article-number))
9802                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9803               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9804         (setq n (1- n)))
9805       (when (/= 0 n)
9806         (gnus-message 7 "No more articles"))
9807       (gnus-summary-recenter)
9808       (gnus-summary-position-point)
9809       n)))
9810
9811 (defun gnus-summary-unmark-as-processable (n)
9812   "Remove the process mark from the next N articles.
9813 If N is negative, unmark backward instead.  The difference between N and
9814 the actual number of articles unmarked is returned."
9815   (interactive "P")
9816   (gnus-summary-mark-as-processable n t))
9817
9818 (defun gnus-summary-unmark-all-processable ()
9819   "Remove the process mark from all articles."
9820   (interactive)
9821   (save-excursion
9822     (while gnus-newsgroup-processable
9823       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9824   (gnus-summary-position-point))
9825
9826 (defun gnus-summary-add-mark (article type)
9827   "Mark ARTICLE with a mark of TYPE."
9828   (let ((vtype (car (assq type gnus-article-mark-lists)))
9829         var)
9830     (if (not vtype)
9831         (error "No such mark type: %s" type)
9832       (setq var (intern (format "gnus-newsgroup-%s" type)))
9833       (set var (cons article (symbol-value var)))
9834       (if (memq type '(processable cached replied forwarded recent saved))
9835           (gnus-summary-update-secondary-mark article)
9836         ;;; !!! This is bogus.  We should find out what primary
9837         ;;; !!! mark we want to set.
9838         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9839
9840 (defun gnus-summary-mark-as-expirable (n)
9841   "Mark N articles forward as expirable.
9842 If N is negative, mark backward instead.  The difference between N and
9843 the actual number of articles marked is returned."
9844   (interactive "p")
9845   (gnus-summary-mark-forward n gnus-expirable-mark))
9846
9847 (defun gnus-summary-mark-as-spam (n)
9848   "Mark N articles forward as spam.
9849 If N is negative, mark backward instead.  The difference between N and
9850 the actual number of articles marked is returned."
9851   (interactive "p")
9852   (gnus-summary-mark-forward n gnus-spam-mark))
9853
9854 (defun gnus-summary-mark-article-as-replied (article)
9855   "Mark ARTICLE as replied to and update the summary line.
9856 ARTICLE can also be a list of articles."
9857   (interactive (list (gnus-summary-article-number)))
9858   (let ((articles (if (listp article) article (list article))))
9859     (dolist (article articles)
9860       (unless (numberp article)
9861         (error "%s is not a number" article))
9862       (push article gnus-newsgroup-replied)
9863       (let ((buffer-read-only nil))
9864         (when (gnus-summary-goto-subject article nil t)
9865           (gnus-summary-update-secondary-mark article))))))
9866
9867 (defun gnus-summary-mark-article-as-forwarded (article)
9868   "Mark ARTICLE as forwarded and update the summary line.
9869 ARTICLE can also be a list of articles."
9870   (let ((articles (if (listp article) article (list article))))
9871     (dolist (article articles)
9872       (push article gnus-newsgroup-forwarded)
9873       (let ((buffer-read-only nil))
9874         (when (gnus-summary-goto-subject article nil t)
9875           (gnus-summary-update-secondary-mark article))))))
9876
9877 (defun gnus-summary-set-bookmark (article)
9878   "Set a bookmark in current article."
9879   (interactive (list (gnus-summary-article-number)))
9880   (when (or (not (get-buffer gnus-article-buffer))
9881             (not gnus-current-article)
9882             (not gnus-article-current)
9883             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9884     (error "No current article selected"))
9885   ;; Remove old bookmark, if one exists.
9886   (gnus-pull article gnus-newsgroup-bookmarks)
9887   ;; Set the new bookmark, which is on the form
9888   ;; (article-number . line-number-in-body).
9889   (push
9890    (cons article
9891          (with-current-buffer gnus-article-buffer
9892            (count-lines
9893             (min (point)
9894                  (save-excursion
9895                    (article-goto-body)
9896                    (point)))
9897             (point))))
9898    gnus-newsgroup-bookmarks)
9899   (gnus-message 6 "A bookmark has been added to the current article."))
9900
9901 (defun gnus-summary-remove-bookmark (article)
9902   "Remove the bookmark from the current article."
9903   (interactive (list (gnus-summary-article-number)))
9904   ;; Remove old bookmark, if one exists.
9905   (if (not (assq article gnus-newsgroup-bookmarks))
9906       (gnus-message 6 "No bookmark in current article.")
9907     (gnus-pull article gnus-newsgroup-bookmarks)
9908     (gnus-message 6 "Removed bookmark.")))
9909
9910 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9911 (defun gnus-summary-mark-as-dormant (n)
9912   "Mark N articles forward as dormant.
9913 If N is negative, mark backward instead.  The difference between N and
9914 the actual number of articles marked is returned."
9915   (interactive "p")
9916   (gnus-summary-mark-forward n gnus-dormant-mark))
9917
9918 (defun gnus-summary-set-process-mark (article)
9919   "Set the process mark on ARTICLE and update the summary line."
9920   (setq gnus-newsgroup-processable
9921         (cons article
9922               (delq article gnus-newsgroup-processable)))
9923   (when (gnus-summary-goto-subject article)
9924     (gnus-summary-show-thread)
9925     (gnus-summary-goto-subject article)
9926     (gnus-summary-update-secondary-mark article)))
9927
9928 (defun gnus-summary-remove-process-mark (article)
9929   "Remove the process mark from ARTICLE and update the summary line."
9930   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9931   (when (gnus-summary-goto-subject article)
9932     (gnus-summary-show-thread)
9933     (gnus-summary-goto-subject article)
9934     (gnus-summary-update-secondary-mark article)))
9935
9936 (defun gnus-summary-set-saved-mark (article)
9937   "Set the process mark on ARTICLE and update the summary line."
9938   (push article gnus-newsgroup-saved)
9939   (when (gnus-summary-goto-subject article)
9940     (gnus-summary-update-secondary-mark article)))
9941
9942 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9943   "Mark N articles as read forwards.
9944 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9945 The difference between N and the actual number of articles marked is
9946 returned.
9947 If NO-EXPIRE, auto-expiry will be inhibited."
9948   (interactive "p")
9949   (gnus-summary-show-thread)
9950   (let ((backward (< n 0))
9951         (gnus-summary-goto-unread
9952          (and gnus-summary-goto-unread
9953               (not (eq gnus-summary-goto-unread 'never))
9954               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9955                                     gnus-ticked-mark gnus-dormant-mark)))))
9956         (n (abs n))
9957         (mark (or mark gnus-del-mark)))
9958     (while (and (> n 0)
9959                 (gnus-summary-mark-article nil mark no-expire)
9960                 (zerop (gnus-summary-next-subject
9961                         (if backward -1 1)
9962                         (and gnus-summary-goto-unread
9963                              (not (eq gnus-summary-goto-unread 'never)))
9964                         t)))
9965       (setq n (1- n)))
9966     (when (/= 0 n)
9967       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9968     (gnus-summary-recenter)
9969     (gnus-summary-position-point)
9970     (gnus-set-mode-line 'summary)
9971     n))
9972
9973 (defun gnus-summary-mark-article-as-read (mark)
9974   "Mark the current article quickly as read with MARK."
9975   (let ((article (gnus-summary-article-number)))
9976     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9977     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9978     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9979     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9980     (push (cons article mark) gnus-newsgroup-reads)
9981     ;; Possibly remove from cache, if that is used.
9982     (when gnus-use-cache
9983       (gnus-cache-enter-remove-article article))
9984     ;; Allow the backend to change the mark.
9985     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9986     ;; Check for auto-expiry.
9987     (when (and gnus-newsgroup-auto-expire
9988                (memq mark gnus-auto-expirable-marks))
9989       (setq mark gnus-expirable-mark)
9990       ;; Let the backend know about the mark change.
9991       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9992       (push article gnus-newsgroup-expirable))
9993     ;; Set the mark in the buffer.
9994     (gnus-summary-update-mark mark 'unread)
9995     t))
9996
9997 (defun gnus-summary-mark-article-as-unread (mark)
9998   "Mark the current article quickly as unread with MARK."
9999   (let* ((article (gnus-summary-article-number))
10000          (old-mark (gnus-summary-article-mark article)))
10001     ;; Allow the backend to change the mark.
10002     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10003     (if (eq mark old-mark)
10004         t
10005       (if (<= article 0)
10006           (progn
10007             (gnus-error 1 "Can't mark negative article numbers")
10008             nil)
10009         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10010         (setq gnus-newsgroup-spam-marked
10011               (delq article gnus-newsgroup-spam-marked))
10012         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10013         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10014         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10015         (cond ((= mark gnus-ticked-mark)
10016                (setq gnus-newsgroup-marked
10017                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10018                                               article)))
10019               ((= mark gnus-spam-mark)
10020                (setq gnus-newsgroup-spam-marked
10021                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10022                                               article)))
10023               ((= mark gnus-dormant-mark)
10024                (setq gnus-newsgroup-dormant
10025                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10026                                               article)))
10027               (t
10028                (setq gnus-newsgroup-unreads
10029                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10030                                               article))))
10031         (gnus-pull article gnus-newsgroup-reads)
10032
10033         ;; See whether the article is to be put in the cache.
10034         (and gnus-use-cache
10035              (vectorp (gnus-summary-article-header article))
10036              (save-excursion
10037                (gnus-cache-possibly-enter-article
10038                 gnus-newsgroup-name article
10039                 (gnus-summary-article-header article)
10040                 (= mark gnus-ticked-mark)
10041                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10042
10043         ;; Fix the mark.
10044         (gnus-summary-update-mark mark 'unread)
10045         t))))
10046
10047 (defun gnus-summary-mark-article (&optional article mark no-expire)
10048   "Mark ARTICLE with MARK.  MARK can be any character.
10049 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10050 `??' (dormant) and `?E' (expirable).
10051 If MARK is nil, then the default character `?r' is used.
10052 If ARTICLE is nil, then the article on the current line will be
10053 marked.
10054 If NO-EXPIRE, auto-expiry will be inhibited."
10055   ;; The mark might be a string.
10056   (when (stringp mark)
10057     (setq mark (aref mark 0)))
10058   ;; If no mark is given, then we check auto-expiring.
10059   (when (null mark)
10060     (setq mark gnus-del-mark))
10061   (when (and (not no-expire)
10062              gnus-newsgroup-auto-expire
10063              (memq mark gnus-auto-expirable-marks))
10064     (setq mark gnus-expirable-mark))
10065   (let ((article (or article (gnus-summary-article-number)))
10066         (old-mark (gnus-summary-article-mark article)))
10067     ;; Allow the backend to change the mark.
10068     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10069     (if (eq mark old-mark)
10070         t
10071       (unless article
10072         (error "No article on current line"))
10073       (if (not (if (or (= mark gnus-unread-mark)
10074                        (= mark gnus-ticked-mark)
10075                        (= mark gnus-spam-mark)
10076                        (= mark gnus-dormant-mark))
10077                    (gnus-mark-article-as-unread article mark)
10078                  (gnus-mark-article-as-read article mark)))
10079           t
10080         ;; See whether the article is to be put in the cache.
10081         (and gnus-use-cache
10082              (not (= mark gnus-canceled-mark))
10083              (vectorp (gnus-summary-article-header article))
10084              (save-excursion
10085                (gnus-cache-possibly-enter-article
10086                 gnus-newsgroup-name article
10087                 (gnus-summary-article-header article)
10088                 (= mark gnus-ticked-mark)
10089                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10090
10091         (when (gnus-summary-goto-subject article nil t)
10092           (let ((buffer-read-only nil))
10093             (gnus-summary-show-thread)
10094             ;; Fix the mark.
10095             (gnus-summary-update-mark mark 'unread)
10096             t))))))
10097
10098 (defun gnus-summary-update-secondary-mark (article)
10099   "Update the secondary (read, process, cache) mark."
10100   (gnus-summary-update-mark
10101    (cond ((memq article gnus-newsgroup-processable)
10102           gnus-process-mark)
10103          ((memq article gnus-newsgroup-cached)
10104           gnus-cached-mark)
10105          ((memq article gnus-newsgroup-replied)
10106           gnus-replied-mark)
10107          ((memq article gnus-newsgroup-forwarded)
10108           gnus-forwarded-mark)
10109          ((memq article gnus-newsgroup-saved)
10110           gnus-saved-mark)
10111          ((memq article gnus-newsgroup-recent)
10112           gnus-recent-mark)
10113          ((memq article gnus-newsgroup-unseen)
10114           gnus-unseen-mark)
10115          (t gnus-no-mark))
10116    'replied)
10117   (when (gnus-visual-p 'summary-highlight 'highlight)
10118     (gnus-run-hooks 'gnus-summary-update-hook))
10119   t)
10120
10121 (defun gnus-summary-update-download-mark (article)
10122   "Update the download mark."
10123   (gnus-summary-update-mark
10124    (cond ((memq article gnus-newsgroup-undownloaded)
10125           gnus-undownloaded-mark)
10126          (gnus-newsgroup-agentized
10127           gnus-downloaded-mark)
10128          (t
10129           gnus-no-mark))
10130    'download)
10131   (gnus-summary-update-line t)
10132   t)
10133
10134 (defun gnus-summary-update-mark (mark type)
10135   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10136         (buffer-read-only nil))
10137     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10138     (when forward
10139       (when (looking-at "\r")
10140         (incf forward))
10141       (when (<= (+ forward (point)) (point-max))
10142         ;; Go to the right position on the line.
10143         (goto-char (+ forward (point)))
10144         ;; Replace the old mark with the new mark.
10145         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10146         ;; Optionally update the marks by some user rule.
10147         (when (eq type 'unread)
10148           (gnus-data-set-mark
10149            (gnus-data-find (gnus-summary-article-number)) mark)
10150           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10151
10152 (defun gnus-mark-article-as-read (article &optional mark)
10153   "Enter ARTICLE in the pertinent lists and remove it from others."
10154   ;; Make the article expirable.
10155   (let ((mark (or mark gnus-del-mark)))
10156     (setq gnus-newsgroup-expirable
10157           (if (= mark gnus-expirable-mark)
10158               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10159             (delq article gnus-newsgroup-expirable)))
10160     ;; Remove from unread and marked lists.
10161     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10162     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10163     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10164     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10165     (push (cons article mark) gnus-newsgroup-reads)
10166     ;; Possibly remove from cache, if that is used.
10167     (when gnus-use-cache
10168       (gnus-cache-enter-remove-article article))
10169     t))
10170
10171 (defun gnus-mark-article-as-unread (article &optional mark)
10172   "Enter ARTICLE in the pertinent lists and remove it from others."
10173   (let ((mark (or mark gnus-ticked-mark)))
10174     (if (<= article 0)
10175         (progn
10176           (gnus-error 1 "Can't mark negative article numbers")
10177           nil)
10178       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10179             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10180             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10181             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10182             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10183
10184       ;; Unsuppress duplicates?
10185       (when gnus-suppress-duplicates
10186         (gnus-dup-unsuppress-article article))
10187
10188       (cond ((= mark gnus-ticked-mark)
10189              (setq gnus-newsgroup-marked
10190                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10191             ((= mark gnus-spam-mark)
10192              (setq gnus-newsgroup-spam-marked
10193                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10194                                             article)))
10195             ((= mark gnus-dormant-mark)
10196              (setq gnus-newsgroup-dormant
10197                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10198             (t
10199              (setq gnus-newsgroup-unreads
10200                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10201       (gnus-pull article gnus-newsgroup-reads)
10202       t)))
10203
10204 (defalias 'gnus-summary-mark-as-unread-forward
10205   'gnus-summary-tick-article-forward)
10206 (make-obsolete 'gnus-summary-mark-as-unread-forward
10207                'gnus-summary-tick-article-forward)
10208 (defun gnus-summary-tick-article-forward (n)
10209   "Tick N articles forwards.
10210 If N is negative, tick backwards instead.
10211 The difference between N and the number of articles ticked is returned."
10212   (interactive "p")
10213   (gnus-summary-mark-forward n gnus-ticked-mark))
10214
10215 (defalias 'gnus-summary-mark-as-unread-backward
10216   'gnus-summary-tick-article-backward)
10217 (make-obsolete 'gnus-summary-mark-as-unread-backward
10218                'gnus-summary-tick-article-backward)
10219 (defun gnus-summary-tick-article-backward (n)
10220   "Tick N articles backwards.
10221 The difference between N and the number of articles ticked is returned."
10222   (interactive "p")
10223   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10224
10225 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10226 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10227 (defun gnus-summary-tick-article (&optional article clear-mark)
10228   "Mark current article as unread.
10229 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10230 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10231   (interactive)
10232   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10233                                        gnus-ticked-mark)))
10234
10235 (defun gnus-summary-mark-as-read-forward (n)
10236   "Mark N articles as read forwards.
10237 If N is negative, mark backwards instead.
10238 The difference between N and the actual number of articles marked is
10239 returned."
10240   (interactive "p")
10241   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10242
10243 (defun gnus-summary-mark-as-read-backward (n)
10244   "Mark the N articles as read backwards.
10245 The difference between N and the actual number of articles marked is
10246 returned."
10247   (interactive "p")
10248   (gnus-summary-mark-forward
10249    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10250
10251 (defun gnus-summary-mark-as-read (&optional article mark)
10252   "Mark current article as read.
10253 ARTICLE specifies the article to be marked as read.
10254 MARK specifies a string to be inserted at the beginning of the line."
10255   (gnus-summary-mark-article article mark))
10256
10257 (defun gnus-summary-clear-mark-forward (n)
10258   "Clear marks from N articles forward.
10259 If N is negative, clear backward instead.
10260 The difference between N and the number of marks cleared is returned."
10261   (interactive "p")
10262   (gnus-summary-mark-forward n gnus-unread-mark))
10263
10264 (defun gnus-summary-clear-mark-backward (n)
10265   "Clear marks from N articles backward.
10266 The difference between N and the number of marks cleared is returned."
10267   (interactive "p")
10268   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10269
10270 (defun gnus-summary-mark-unread-as-read ()
10271   "Intended to be used by `gnus-summary-mark-article-hook'."
10272   (when (memq gnus-current-article gnus-newsgroup-unreads)
10273     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10274
10275 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10276   "Intended to be used by `gnus-summary-mark-article-hook'."
10277   (let ((mark (gnus-summary-article-mark)))
10278     (when (or (gnus-unread-mark-p mark)
10279               (gnus-read-mark-p mark))
10280       (gnus-summary-mark-article gnus-current-article
10281                                  (or new-mark gnus-read-mark)))))
10282
10283 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10284   "Intended to be used by `gnus-summary-mark-article-hook'."
10285   (let ((mark (gnus-summary-article-mark)))
10286     (when (or (gnus-unread-mark-p mark)
10287               (gnus-read-mark-p mark))
10288       (gnus-summary-mark-article (gnus-summary-article-number)
10289                                  (or new-mark gnus-read-mark)))))
10290
10291 (defun gnus-summary-mark-unread-as-ticked ()
10292   "Intended to be used by `gnus-summary-mark-article-hook'."
10293   (when (memq gnus-current-article gnus-newsgroup-unreads)
10294     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10295
10296 (defun gnus-summary-mark-region-as-read (point mark all)
10297   "Mark all unread articles between point and mark as read.
10298 If given a prefix, mark all articles between point and mark as read,
10299 even ticked and dormant ones."
10300   (interactive "r\nP")
10301   (save-excursion
10302     (let (article)
10303       (goto-char point)
10304       (beginning-of-line)
10305       (while (and
10306               (< (point) mark)
10307               (progn
10308                 (when (or all
10309                           (memq (setq article (gnus-summary-article-number))
10310                                 gnus-newsgroup-unreads))
10311                   (gnus-summary-mark-article article gnus-del-mark))
10312                 t)
10313               (gnus-summary-find-next))))))
10314
10315 (defun gnus-summary-mark-below (score mark)
10316   "Mark articles with score less than SCORE with MARK."
10317   (interactive "P\ncMark: ")
10318   (setq score (if score
10319                   (prefix-numeric-value score)
10320                 (or gnus-summary-default-score 0)))
10321   (save-excursion
10322     (set-buffer gnus-summary-buffer)
10323     (goto-char (point-min))
10324     (while
10325         (progn
10326           (and (< (gnus-summary-article-score) score)
10327                (gnus-summary-mark-article nil mark))
10328           (gnus-summary-find-next)))))
10329
10330 (defun gnus-summary-kill-below (&optional score)
10331   "Mark articles with score below SCORE as read."
10332   (interactive "P")
10333   (gnus-summary-mark-below score gnus-killed-mark))
10334
10335 (defun gnus-summary-clear-above (&optional score)
10336   "Clear all marks from articles with score above SCORE."
10337   (interactive "P")
10338   (gnus-summary-mark-above score gnus-unread-mark))
10339
10340 (defun gnus-summary-tick-above (&optional score)
10341   "Tick all articles with score above SCORE."
10342   (interactive "P")
10343   (gnus-summary-mark-above score gnus-ticked-mark))
10344
10345 (defun gnus-summary-mark-above (score mark)
10346   "Mark articles with score over SCORE with MARK."
10347   (interactive "P\ncMark: ")
10348   (setq score (if score
10349                   (prefix-numeric-value score)
10350                 (or gnus-summary-default-score 0)))
10351   (save-excursion
10352     (set-buffer gnus-summary-buffer)
10353     (goto-char (point-min))
10354     (while (and (progn
10355                   (when (> (gnus-summary-article-score) score)
10356                     (gnus-summary-mark-article nil mark))
10357                   t)
10358                 (gnus-summary-find-next)))))
10359
10360 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10361 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10362 (defun gnus-summary-limit-include-expunged (&optional no-error)
10363   "Display all the hidden articles that were expunged for low scores."
10364   (interactive)
10365   (let ((buffer-read-only nil))
10366     (let ((scored gnus-newsgroup-scored)
10367           headers h)
10368       (while scored
10369         (unless (gnus-summary-article-header (caar scored))
10370           (and (setq h (gnus-number-to-header (caar scored)))
10371                (< (cdar scored) gnus-summary-expunge-below)
10372                (push h headers)))
10373         (setq scored (cdr scored)))
10374       (if (not headers)
10375           (when (not no-error)
10376             (error "No expunged articles hidden"))
10377         (goto-char (point-min))
10378         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10379         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10380         (mapcar (lambda (x) (push (mail-header-number x)
10381                                   gnus-newsgroup-limit))
10382                 headers)
10383         (gnus-summary-prepare-unthreaded (nreverse headers))
10384         (goto-char (point-min))
10385         (gnus-summary-position-point)
10386         t))))
10387
10388 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10389   "Mark all unread articles in this newsgroup as read.
10390 If prefix argument ALL is non-nil, ticked and dormant articles will
10391 also be marked as read.
10392 If QUIETLY is non-nil, no questions will be asked.
10393
10394 If TO-HERE is non-nil, it should be a point in the buffer.  All
10395 articles before (after, if REVERSE is set) this point will be marked
10396 as read.
10397
10398 Note that this function will only catch up the unread article
10399 in the current summary buffer limitation.
10400
10401 The number of articles marked as read is returned."
10402   (interactive "P")
10403   (prog1
10404       (save-excursion
10405         (when (or quietly
10406                   (not gnus-interactive-catchup) ;Without confirmation?
10407                   gnus-expert-user
10408                   (gnus-y-or-n-p
10409                    (if all
10410                        "Mark absolutely all articles as read? "
10411                      "Mark all unread articles as read? ")))
10412           (if (and not-mark
10413                    (not gnus-newsgroup-adaptive)
10414                    (not gnus-newsgroup-auto-expire)
10415                    (not gnus-suppress-duplicates)
10416                    (or (not gnus-use-cache)
10417                        (eq gnus-use-cache 'passive)))
10418               (progn
10419                 (when all
10420                   (setq gnus-newsgroup-marked nil
10421                         gnus-newsgroup-spam-marked nil
10422                         gnus-newsgroup-dormant nil))
10423                 (setq gnus-newsgroup-unreads
10424                       (gnus-sorted-nunion
10425                        (gnus-intersection gnus-newsgroup-unreads
10426                                           gnus-newsgroup-downloadable)
10427                        gnus-newsgroup-unfetched)))
10428             ;; We actually mark all articles as canceled, which we
10429             ;; have to do when using auto-expiry or adaptive scoring.
10430             (gnus-summary-show-all-threads)
10431             (if (and to-here reverse)
10432                 (progn
10433                   (goto-char to-here)
10434                   (gnus-summary-mark-current-read-and-unread-as-read
10435                    gnus-catchup-mark)
10436                   (while (gnus-summary-find-next (not all))
10437                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10438               (when (gnus-summary-first-subject (not all))
10439                 (while (and
10440                         (if to-here (< (point) to-here) t)
10441                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10442                         (gnus-summary-find-next (not all))))))
10443             (gnus-set-mode-line 'summary))
10444           t))
10445     (gnus-summary-position-point)))
10446
10447 (defun gnus-summary-catchup-to-here (&optional all)
10448   "Mark all unticked articles before the current one as read.
10449 If ALL is non-nil, also mark ticked and dormant articles as read."
10450   (interactive "P")
10451   (save-excursion
10452     (gnus-save-hidden-threads
10453       (let ((beg (point)))
10454         ;; We check that there are unread articles.
10455         (when (or all (gnus-summary-find-prev))
10456           (gnus-summary-catchup all t beg)))))
10457   (gnus-summary-position-point))
10458
10459 (defun gnus-summary-catchup-from-here (&optional all)
10460   "Mark all unticked articles after (and including) the current one as read.
10461 If ALL is non-nil, also mark ticked and dormant articles as read."
10462   (interactive "P")
10463   (save-excursion
10464     (gnus-save-hidden-threads
10465       (let ((beg (point)))
10466         ;; We check that there are unread articles.
10467         (when (or all (gnus-summary-find-next))
10468           (gnus-summary-catchup all t beg nil t)))))
10469   (gnus-summary-position-point))
10470
10471 (defun gnus-summary-catchup-all (&optional quietly)
10472   "Mark all articles in this newsgroup as read.
10473 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10474 instead, which marks only unread articles as read."
10475   (interactive "P")
10476   (gnus-summary-catchup t quietly))
10477
10478 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10479   "Mark all unread articles in this group as read, then exit.
10480 If prefix argument ALL is non-nil, all articles are marked as read.
10481 If QUIETLY is non-nil, no questions will be asked."
10482   (interactive "P")
10483   (when (gnus-summary-catchup all quietly nil 'fast)
10484     ;; Select next newsgroup or exit.
10485     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10486              (eq gnus-auto-select-next 'quietly))
10487         (gnus-summary-next-group nil)
10488       (gnus-summary-exit))))
10489
10490 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10491   "Mark all articles in this newsgroup as read, and then exit.
10492 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10493 instead, which marks only unread articles as read."
10494   (interactive "P")
10495   (gnus-summary-catchup-and-exit t quietly))
10496
10497 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10498   "Mark all articles in this group as read and select the next group.
10499 If given a prefix, mark all articles, unread as well as ticked, as
10500 read."
10501   (interactive "P")
10502   (save-excursion
10503     (gnus-summary-catchup all))
10504   (gnus-summary-next-group))
10505
10506 ;;;
10507 ;;; with article
10508 ;;;
10509
10510 (defmacro gnus-with-article (article &rest forms)
10511   "Select ARTICLE and perform FORMS in the original article buffer.
10512 Then replace the article with the result."
10513   `(progn
10514      ;; We don't want the article to be marked as read.
10515      (let (gnus-mark-article-hook)
10516        (gnus-summary-select-article t t nil ,article))
10517      (set-buffer gnus-original-article-buffer)
10518      ,@forms
10519      (if (not (gnus-check-backend-function
10520                'request-replace-article (car gnus-article-current)))
10521          (gnus-message 5 "Read-only group; not replacing")
10522        (unless (gnus-request-replace-article
10523                 ,article (car gnus-article-current)
10524                 (current-buffer) t)
10525          (error "Couldn't replace article")))
10526      ;; The cache and backlog have to be flushed somewhat.
10527      (when gnus-keep-backlog
10528        (gnus-backlog-remove-article
10529         (car gnus-article-current) (cdr gnus-article-current)))
10530      (when gnus-use-cache
10531        (gnus-cache-update-article
10532         (car gnus-article-current) (cdr gnus-article-current)))))
10533
10534 (put 'gnus-with-article 'lisp-indent-function 1)
10535 (put 'gnus-with-article 'edebug-form-spec '(form body))
10536
10537 ;; Thread-based commands.
10538
10539 (defun gnus-summary-articles-in-thread (&optional article)
10540   "Return a list of all articles in the current thread.
10541 If ARTICLE is non-nil, return all articles in the thread that starts
10542 with that article."
10543   (let* ((article (or article (gnus-summary-article-number)))
10544          (data (gnus-data-find-list article))
10545          (top-level (gnus-data-level (car data)))
10546          (top-subject
10547           (cond ((null gnus-thread-operation-ignore-subject)
10548                  (gnus-simplify-subject-re
10549                   (mail-header-subject (gnus-data-header (car data)))))
10550                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10551                  (gnus-simplify-subject-fuzzy
10552                   (mail-header-subject (gnus-data-header (car data)))))
10553                 (t nil)))
10554          (end-point (save-excursion
10555                       (if (gnus-summary-go-to-next-thread)
10556                           (point) (point-max))))
10557          articles)
10558     (while (and data
10559                 (< (gnus-data-pos (car data)) end-point))
10560       (when (or (not top-subject)
10561                 (string= top-subject
10562                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10563                              (gnus-simplify-subject-fuzzy
10564                               (mail-header-subject
10565                                (gnus-data-header (car data))))
10566                            (gnus-simplify-subject-re
10567                             (mail-header-subject
10568                              (gnus-data-header (car data)))))))
10569         (push (gnus-data-number (car data)) articles))
10570       (unless (and (setq data (cdr data))
10571                    (> (gnus-data-level (car data)) top-level))
10572         (setq data nil)))
10573     ;; Return the list of articles.
10574     (nreverse articles)))
10575
10576 (defun gnus-summary-rethread-current ()
10577   "Rethread the thread the current article is part of."
10578   (interactive)
10579   (let* ((gnus-show-threads t)
10580          (article (gnus-summary-article-number))
10581          (id (mail-header-id (gnus-summary-article-header)))
10582          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10583     (unless id
10584       (error "No article on the current line"))
10585     (gnus-rebuild-thread id)
10586     (gnus-summary-goto-subject article)))
10587
10588 (defun gnus-summary-reparent-thread ()
10589   "Make the current article child of the marked (or previous) article.
10590
10591 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10592 is non-nil or the Subject: of both articles are the same."
10593   (interactive)
10594   (unless (not (gnus-group-read-only-p))
10595     (error "The current newsgroup does not support article editing"))
10596   (unless (<= (length gnus-newsgroup-processable) 1)
10597     (error "No more than one article may be marked"))
10598   (save-window-excursion
10599     (let ((gnus-article-buffer " *reparent*")
10600           (current-article (gnus-summary-article-number))
10601           ;; First grab the marked article, otherwise one line up.
10602           (parent-article (if (not (null gnus-newsgroup-processable))
10603                               (car gnus-newsgroup-processable)
10604                             (save-excursion
10605                               (if (eq (forward-line -1) 0)
10606                                   (gnus-summary-article-number)
10607                                 (error "Beginning of summary buffer"))))))
10608       (unless (not (eq current-article parent-article))
10609         (error "An article may not be self-referential"))
10610       (let ((message-id (mail-header-id
10611                          (gnus-summary-article-header parent-article))))
10612         (unless (and message-id (not (equal message-id "")))
10613           (error "No message-id in desired parent"))
10614         (gnus-with-article current-article
10615           (save-restriction
10616             (goto-char (point-min))
10617             (message-narrow-to-head)
10618             (if (re-search-forward "^References: " nil t)
10619                 (progn
10620                   (re-search-forward "^[^ \t]" nil t)
10621                   (forward-line -1)
10622                   (end-of-line)
10623                   (insert " " message-id))
10624               (insert "References: " message-id "\n"))))
10625         (set-buffer gnus-summary-buffer)
10626         (gnus-summary-unmark-all-processable)
10627         (gnus-summary-update-article current-article)
10628         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10629             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10630         (gnus-summary-rethread-current)
10631         (gnus-message 3 "Article %d is now the child of article %d"
10632                       current-article parent-article)))))
10633
10634 (defun gnus-summary-toggle-threads (&optional arg)
10635   "Toggle showing conversation threads.
10636 If ARG is positive number, turn showing conversation threads on."
10637   (interactive "P")
10638   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10639     (setq gnus-show-threads
10640           (if (null arg) (not gnus-show-threads)
10641             (> (prefix-numeric-value arg) 0)))
10642     (gnus-summary-prepare)
10643     (gnus-summary-goto-subject current)
10644     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10645     (gnus-summary-position-point)))
10646
10647 (defun gnus-summary-show-all-threads ()
10648   "Show all threads."
10649   (interactive)
10650   (save-excursion
10651     (let ((buffer-read-only nil))
10652       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10653   (gnus-summary-position-point))
10654
10655 (defun gnus-summary-show-thread ()
10656   "Show thread subtrees.
10657 Returns nil if no thread was there to be shown."
10658   (interactive)
10659   (let ((buffer-read-only nil)
10660         (orig (point))
10661         (end (point-at-eol))
10662         ;; Leave point at bol
10663         (beg (progn (beginning-of-line) (point))))
10664     (prog1
10665         ;; Any hidden lines here?
10666         (search-forward "\r" end t)
10667       (subst-char-in-region beg end ?\^M ?\n t)
10668       (goto-char orig)
10669       (gnus-summary-position-point))))
10670
10671 (defun gnus-summary-maybe-hide-threads ()
10672   "If requested, hide the threads that should be hidden."
10673   (when (and gnus-show-threads
10674              gnus-thread-hide-subtree)
10675     (gnus-summary-hide-all-threads
10676      (if (or (consp gnus-thread-hide-subtree)
10677              (functionp gnus-thread-hide-subtree))
10678          (gnus-make-predicate gnus-thread-hide-subtree)
10679        nil))))
10680
10681 ;;; Hiding predicates.
10682
10683 (defun gnus-article-unread-p (header)
10684   (memq (mail-header-number header) gnus-newsgroup-unreads))
10685
10686 (defun gnus-article-unseen-p (header)
10687   (memq (mail-header-number header) gnus-newsgroup-unseen))
10688
10689 (defun gnus-map-articles (predicate articles)
10690   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10691   (apply 'gnus-or (mapcar predicate
10692                           (mapcar 'gnus-summary-article-header articles))))
10693
10694 (defun gnus-summary-hide-all-threads (&optional predicate)
10695   "Hide all thread subtrees.
10696 If PREDICATE is supplied, threads that satisfy this predicate
10697 will not be hidden."
10698   (interactive)
10699   (save-excursion
10700     (goto-char (point-min))
10701     (let ((end nil))
10702       (while (not end)
10703         (when (or (not predicate)
10704                   (gnus-map-articles
10705                    predicate (gnus-summary-article-children)))
10706             (gnus-summary-hide-thread))
10707         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10708   (gnus-summary-position-point))
10709
10710 (defun gnus-summary-hide-thread ()
10711   "Hide thread subtrees.
10712 If PREDICATE is supplied, threads that satisfy this predicate
10713 will not be hidden.
10714 Returns nil if no threads were there to be hidden."
10715   (interactive)
10716   (let ((buffer-read-only nil)
10717         (start (point))
10718         (article (gnus-summary-article-number)))
10719     (goto-char start)
10720     ;; Go forward until either the buffer ends or the subthread
10721     ;; ends.
10722     (when (and (not (eobp))
10723                (or (zerop (gnus-summary-next-thread 1 t))
10724                    (goto-char (point-max))))
10725       (prog1
10726           (if (and (> (point) start)
10727                    (search-backward "\n" start t))
10728               (progn
10729                 (subst-char-in-region start (point) ?\n ?\^M)
10730                 (gnus-summary-goto-subject article))
10731             (goto-char start)
10732             nil)))))
10733
10734 (defun gnus-summary-go-to-next-thread (&optional previous)
10735   "Go to the same level (or less) next thread.
10736 If PREVIOUS is non-nil, go to previous thread instead.
10737 Return the article number moved to, or nil if moving was impossible."
10738   (let ((level (gnus-summary-thread-level))
10739         (way (if previous -1 1))
10740         (beg (point)))
10741     (forward-line way)
10742     (while (and (not (eobp))
10743                 (< level (gnus-summary-thread-level)))
10744       (forward-line way))
10745     (if (eobp)
10746         (progn
10747           (goto-char beg)
10748           nil)
10749       (setq beg (point))
10750       (prog1
10751           (gnus-summary-article-number)
10752         (goto-char beg)))))
10753
10754 (defun gnus-summary-next-thread (n &optional silent)
10755   "Go to the same level next N'th thread.
10756 If N is negative, search backward instead.
10757 Returns the difference between N and the number of skips actually
10758 done.
10759
10760 If SILENT, don't output messages."
10761   (interactive "p")
10762   (let ((backward (< n 0))
10763         (n (abs n)))
10764     (while (and (> n 0)
10765                 (gnus-summary-go-to-next-thread backward))
10766       (decf n))
10767     (unless silent
10768       (gnus-summary-position-point))
10769     (when (and (not silent) (/= 0 n))
10770       (gnus-message 7 "No more threads"))
10771     n))
10772
10773 (defun gnus-summary-prev-thread (n)
10774   "Go to the same level previous N'th thread.
10775 Returns the difference between N and the number of skips actually
10776 done."
10777   (interactive "p")
10778   (gnus-summary-next-thread (- n)))
10779
10780 (defun gnus-summary-go-down-thread ()
10781   "Go down one level in the current thread."
10782   (let ((children (gnus-summary-article-children)))
10783     (when children
10784       (gnus-summary-goto-subject (car children)))))
10785
10786 (defun gnus-summary-go-up-thread ()
10787   "Go up one level in the current thread."
10788   (let ((parent (gnus-summary-article-parent)))
10789     (when parent
10790       (gnus-summary-goto-subject parent))))
10791
10792 (defun gnus-summary-down-thread (n)
10793   "Go down thread N steps.
10794 If N is negative, go up instead.
10795 Returns the difference between N and how many steps down that were
10796 taken."
10797   (interactive "p")
10798   (let ((up (< n 0))
10799         (n (abs n)))
10800     (while (and (> n 0)
10801                 (if up (gnus-summary-go-up-thread)
10802                   (gnus-summary-go-down-thread)))
10803       (setq n (1- n)))
10804     (gnus-summary-position-point)
10805     (when (/= 0 n)
10806       (gnus-message 7 "Can't go further"))
10807     n))
10808
10809 (defun gnus-summary-up-thread (n)
10810   "Go up thread N steps.
10811 If N is negative, go down instead.
10812 Returns the difference between N and how many steps down that were
10813 taken."
10814   (interactive "p")
10815   (gnus-summary-down-thread (- n)))
10816
10817 (defun gnus-summary-top-thread ()
10818   "Go to the top of the thread."
10819   (interactive)
10820   (while (gnus-summary-go-up-thread))
10821   (gnus-summary-article-number))
10822
10823 (defun gnus-summary-kill-thread (&optional unmark)
10824   "Mark articles under current thread as read.
10825 If the prefix argument is positive, remove any kinds of marks.
10826 If the prefix argument is negative, tick articles instead."
10827   (interactive "P")
10828   (when unmark
10829     (setq unmark (prefix-numeric-value unmark)))
10830   (let ((articles (gnus-summary-articles-in-thread)))
10831     (save-excursion
10832       ;; Expand the thread.
10833       (gnus-summary-show-thread)
10834       ;; Mark all the articles.
10835       (while articles
10836         (gnus-summary-goto-subject (car articles))
10837         (cond ((null unmark)
10838                (gnus-summary-mark-article-as-read gnus-killed-mark))
10839               ((> unmark 0)
10840                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10841               (t
10842                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10843         (setq articles (cdr articles))))
10844     ;; Hide killed subtrees.
10845     (and (null unmark)
10846          gnus-thread-hide-killed
10847          (gnus-summary-hide-thread))
10848     ;; If marked as read, go to next unread subject.
10849     (when (null unmark)
10850       ;; Go to next unread subject.
10851       (gnus-summary-next-subject 1 t)))
10852   (gnus-set-mode-line 'summary))
10853
10854 ;; Summary sorting commands
10855
10856 (defun gnus-summary-sort-by-number (&optional reverse)
10857   "Sort the summary buffer by article number.
10858 Argument REVERSE means reverse order."
10859   (interactive "P")
10860   (gnus-summary-sort 'number reverse))
10861
10862 (defun gnus-summary-sort-by-random (&optional reverse)
10863   "Randomize the order in the summary buffer.
10864 Argument REVERSE means to randomize in reverse order."
10865   (interactive "P")
10866   (gnus-summary-sort 'random reverse))
10867
10868 (defun gnus-summary-sort-by-author (&optional reverse)
10869   "Sort the summary buffer by author name alphabetically.
10870 If `case-fold-search' is non-nil, case of letters is ignored.
10871 Argument REVERSE means reverse order."
10872   (interactive "P")
10873   (gnus-summary-sort 'author reverse))
10874
10875 (defun gnus-summary-sort-by-subject (&optional reverse)
10876   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10877 If `case-fold-search' is non-nil, case of letters is ignored.
10878 Argument REVERSE means reverse order."
10879   (interactive "P")
10880   (gnus-summary-sort 'subject reverse))
10881
10882 (defun gnus-summary-sort-by-date (&optional reverse)
10883   "Sort the summary buffer by date.
10884 Argument REVERSE means reverse order."
10885   (interactive "P")
10886   (gnus-summary-sort 'date reverse))
10887
10888 (defun gnus-summary-sort-by-score (&optional reverse)
10889   "Sort the summary buffer by score.
10890 Argument REVERSE means reverse order."
10891   (interactive "P")
10892   (gnus-summary-sort 'score reverse))
10893
10894 (defun gnus-summary-sort-by-lines (&optional reverse)
10895   "Sort the summary buffer by the number of lines.
10896 Argument REVERSE means reverse order."
10897   (interactive "P")
10898   (gnus-summary-sort 'lines reverse))
10899
10900 (defun gnus-summary-sort-by-chars (&optional reverse)
10901   "Sort the summary buffer by article length.
10902 Argument REVERSE means reverse order."
10903   (interactive "P")
10904   (gnus-summary-sort 'chars reverse))
10905
10906 (defun gnus-summary-sort-by-original (&optional reverse)
10907   "Sort the summary buffer using the default sorting method.
10908 Argument REVERSE means reverse order."
10909   (interactive "P")
10910   (let* ((buffer-read-only)
10911          (gnus-summary-prepare-hook nil))
10912     ;; We do the sorting by regenerating the threads.
10913     (gnus-summary-prepare)
10914     ;; Hide subthreads if needed.
10915     (gnus-summary-maybe-hide-threads)))
10916
10917 (defun gnus-summary-sort (predicate reverse)
10918   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10919   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10920          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10921          (gnus-thread-sort-functions
10922           (if (not reverse)
10923               thread
10924             `(lambda (t1 t2)
10925                (,thread t2 t1))))
10926          (gnus-sort-gathered-threads-function
10927           gnus-thread-sort-functions)
10928          (gnus-article-sort-functions
10929           (if (not reverse)
10930               article
10931             `(lambda (t1 t2)
10932                (,article t2 t1))))
10933          (buffer-read-only)
10934          (gnus-summary-prepare-hook nil))
10935     ;; We do the sorting by regenerating the threads.
10936     (gnus-summary-prepare)
10937     ;; Hide subthreads if needed.
10938     (gnus-summary-maybe-hide-threads)))
10939
10940 ;; Summary saving commands.
10941
10942 (defun gnus-summary-save-article (&optional n not-saved)
10943   "Save the current article using the default saver function.
10944 If N is a positive number, save the N next articles.
10945 If N is a negative number, save the N previous articles.
10946 If N is nil and any articles have been marked with the process mark,
10947 save those articles instead.
10948 The variable `gnus-default-article-saver' specifies the saver function."
10949   (interactive "P")
10950   (let* ((articles (gnus-summary-work-articles n))
10951          (save-buffer (save-excursion
10952                         (nnheader-set-temp-buffer " *Gnus Save*")))
10953          (num (length articles))
10954          header file)
10955     (dolist (article articles)
10956       (setq header (gnus-summary-article-header article))
10957       (if (not (vectorp header))
10958           ;; This is a pseudo-article.
10959           (if (assq 'name header)
10960               (gnus-copy-file (cdr (assq 'name header)))
10961             (gnus-message 1 "Article %d is unsaveable" article))
10962         ;; This is a real article.
10963         (save-window-excursion
10964           (let ((gnus-display-mime-function nil)
10965                 (gnus-article-prepare-hook nil))
10966             (gnus-summary-select-article t nil nil article)))
10967         (save-excursion
10968           (set-buffer save-buffer)
10969           (erase-buffer)
10970           (insert-buffer-substring gnus-original-article-buffer))
10971         (setq file (gnus-article-save save-buffer file num))
10972         (gnus-summary-remove-process-mark article)
10973         (unless not-saved
10974           (gnus-summary-set-saved-mark article))))
10975     (gnus-kill-buffer save-buffer)
10976     (gnus-summary-position-point)
10977     (gnus-set-mode-line 'summary)
10978     n))
10979
10980 (defun gnus-summary-pipe-output (&optional arg headers)
10981   "Pipe the current article to a subprocess.
10982 If N is a positive number, pipe the N next articles.
10983 If N is a negative number, pipe the N previous articles.
10984 If N is nil and any articles have been marked with the process mark,
10985 pipe those articles instead.
10986 If HEADERS (the symbolic prefix), include the headers, too."
10987   (interactive (gnus-interactive "P\ny"))
10988   (require 'gnus-art)
10989   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10990         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10991     (gnus-summary-save-article arg t))
10992   (let ((buffer (get-buffer "*Shell Command Output*")))
10993     (when (and buffer
10994                (not (zerop (buffer-size buffer))))
10995       (gnus-configure-windows 'pipe))))
10996
10997 (defun gnus-summary-save-article-mail (&optional arg)
10998   "Append the current article to an mail file.
10999 If N is a positive number, save the N next articles.
11000 If N is a negative number, save the N previous articles.
11001 If N is nil and any articles have been marked with the process mark,
11002 save those articles instead."
11003   (interactive "P")
11004   (require 'gnus-art)
11005   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11006     (gnus-summary-save-article arg)))
11007
11008 (defun gnus-summary-save-article-rmail (&optional arg)
11009   "Append the current article to an rmail file.
11010 If N is a positive number, save the N next articles.
11011 If N is a negative number, save the N previous articles.
11012 If N is nil and any articles have been marked with the process mark,
11013 save those articles instead."
11014   (interactive "P")
11015   (require 'gnus-art)
11016   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11017     (gnus-summary-save-article arg)))
11018
11019 (defun gnus-summary-save-article-file (&optional arg)
11020   "Append the current article to a file.
11021 If N is a positive number, save the N next articles.
11022 If N is a negative number, save the N previous articles.
11023 If N is nil and any articles have been marked with the process mark,
11024 save those articles instead."
11025   (interactive "P")
11026   (require 'gnus-art)
11027   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11028     (gnus-summary-save-article arg)))
11029
11030 (defun gnus-summary-write-article-file (&optional arg)
11031   "Write the current article to a file, deleting the previous file.
11032 If N is a positive number, save the N next articles.
11033 If N is a negative number, save the N previous articles.
11034 If N is nil and any articles have been marked with the process mark,
11035 save those articles instead."
11036   (interactive "P")
11037   (require 'gnus-art)
11038   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11039     (gnus-summary-save-article arg)))
11040
11041 (defun gnus-summary-save-article-body-file (&optional arg)
11042   "Append the current article body to a file.
11043 If N is a positive number, save the N next articles.
11044 If N is a negative number, save the N previous articles.
11045 If N is nil and any articles have been marked with the process mark,
11046 save those articles instead."
11047   (interactive "P")
11048   (require 'gnus-art)
11049   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11050     (gnus-summary-save-article arg)))
11051
11052 (defun gnus-summary-muttprint (&optional arg)
11053   "Print the current article using Muttprint.
11054 If N is a positive number, save the N next articles.
11055 If N is a negative number, save the N previous articles.
11056 If N is nil and any articles have been marked with the process mark,
11057 save those articles instead."
11058   (interactive "P")
11059   (require 'gnus-art)
11060   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11061     (gnus-summary-save-article arg t)))
11062
11063 (defun gnus-summary-pipe-message (program)
11064   "Pipe the current article through PROGRAM."
11065   (interactive "sProgram: ")
11066   (gnus-summary-select-article)
11067   (let ((mail-header-separator ""))
11068     (gnus-eval-in-buffer-window gnus-article-buffer
11069       (save-restriction
11070         (widen)
11071         (let ((start (window-start))
11072               buffer-read-only)
11073           (message-pipe-buffer-body program)
11074           (set-window-start (get-buffer-window (current-buffer)) start))))))
11075
11076 (defun gnus-get-split-value (methods)
11077   "Return a value based on the split METHODS."
11078   (let (split-name method result match)
11079     (when methods
11080       (save-excursion
11081         (set-buffer gnus-original-article-buffer)
11082         (save-restriction
11083           (nnheader-narrow-to-headers)
11084           (while (and methods (not split-name))
11085             (goto-char (point-min))
11086             (setq method (pop methods))
11087             (setq match (car method))
11088             (when (cond
11089                    ((stringp match)
11090                     ;; Regular expression.
11091                     (ignore-errors
11092                       (re-search-forward match nil t)))
11093                    ((functionp match)
11094                     ;; Function.
11095                     (save-restriction
11096                       (widen)
11097                       (setq result (funcall match gnus-newsgroup-name))))
11098                    ((consp match)
11099                     ;; Form.
11100                     (save-restriction
11101                       (widen)
11102                       (setq result (eval match)))))
11103               (setq split-name (cdr method))
11104               (cond ((stringp result)
11105                      (push (expand-file-name
11106                             result gnus-article-save-directory)
11107                            split-name))
11108                     ((consp result)
11109                      (setq split-name (append result split-name)))))))))
11110     (nreverse split-name)))
11111
11112 (defun gnus-valid-move-group-p (group)
11113   (and (boundp group)
11114        (symbol-name group)
11115        (symbol-value group)
11116        (gnus-get-function (gnus-find-method-for-group
11117                            (symbol-name group)) 'request-accept-article t)))
11118
11119 (defun gnus-read-move-group-name (prompt default articles prefix)
11120   "Read a group name."
11121   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11122          (minibuffer-confirm-incomplete nil) ; XEmacs
11123          (prom
11124           (format "%s %s to:"
11125                   prompt
11126                   (if (> (length articles) 1)
11127                       (format "these %d articles" (length articles))
11128                     "this article")))
11129          (to-newsgroup
11130           (cond
11131            ((null split-name)
11132             (gnus-completing-read-with-default
11133              default prom
11134              gnus-active-hashtb
11135              'gnus-valid-move-group-p
11136              nil prefix
11137              'gnus-group-history))
11138            ((= 1 (length split-name))
11139             (gnus-completing-read-with-default
11140              (car split-name) prom
11141              gnus-active-hashtb
11142              'gnus-valid-move-group-p
11143              nil nil
11144              'gnus-group-history))
11145            (t
11146             (gnus-completing-read-with-default
11147              nil prom
11148              (mapcar 'list (nreverse split-name))
11149              nil nil nil
11150              'gnus-group-history))))
11151          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11152     (when to-newsgroup
11153       (if (or (string= to-newsgroup "")
11154               (string= to-newsgroup prefix))
11155           (setq to-newsgroup default))
11156       (unless to-newsgroup
11157         (error "No group name entered"))
11158       (or (gnus-active to-newsgroup)
11159           (gnus-activate-group to-newsgroup nil nil to-method)
11160           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11161                                      to-newsgroup))
11162               (or (and (gnus-request-create-group to-newsgroup to-method)
11163                        (gnus-activate-group
11164                         to-newsgroup nil nil to-method)
11165                        (gnus-subscribe-group to-newsgroup))
11166                   (error "Couldn't create group %s" to-newsgroup)))
11167           (error "No such group: %s" to-newsgroup)))
11168     to-newsgroup))
11169
11170 (defun gnus-summary-save-parts (type dir n &optional reverse)
11171   "Save parts matching TYPE to DIR.
11172 If REVERSE, save parts that do not match TYPE."
11173   (interactive
11174    (list (read-string "Save parts of type: "
11175                       (or (car gnus-summary-save-parts-type-history)
11176                           gnus-summary-save-parts-default-mime)
11177                       'gnus-summary-save-parts-type-history)
11178          (setq gnus-summary-save-parts-last-directory
11179                (read-file-name "Save to directory: "
11180                                gnus-summary-save-parts-last-directory
11181                                nil t))
11182          current-prefix-arg))
11183   (gnus-summary-iterate n
11184     (let ((gnus-display-mime-function nil)
11185           (gnus-inhibit-treatment t))
11186       (gnus-summary-select-article))
11187     (save-excursion
11188       (set-buffer gnus-article-buffer)
11189       (let ((handles (or gnus-article-mime-handles
11190                          (mm-dissect-buffer nil gnus-article-loose-mime)
11191                          (and gnus-article-emulate-mime
11192                               (mm-uu-dissect)))))
11193         (when handles
11194           (gnus-summary-save-parts-1 type dir handles reverse)
11195           (unless gnus-article-mime-handles ;; Don't destroy this case.
11196             (mm-destroy-parts handles)))))))
11197
11198 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11199   (if (stringp (car handle))
11200       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11201               (cdr handle))
11202     (when (if reverse
11203               (not (string-match type (mm-handle-media-type handle)))
11204             (string-match type (mm-handle-media-type handle)))
11205       (let ((file (expand-file-name
11206                    (gnus-map-function
11207                     mm-file-name-rewrite-functions
11208                     (file-name-nondirectory
11209                      (or
11210                       (mail-content-type-get
11211                        (mm-handle-disposition handle) 'filename)
11212                       (mail-content-type-get
11213                        (mm-handle-type handle) 'name)
11214                       (concat gnus-newsgroup-name
11215                               "." (number-to-string
11216                                    (cdr gnus-article-current))))))
11217                    dir)))
11218         (unless (file-exists-p file)
11219           (mm-save-part-to-file handle file))))))
11220
11221 ;; Summary extract commands
11222
11223 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11224   (let ((buffer-read-only nil)
11225         (article (gnus-summary-article-number))
11226         after-article b e)
11227     (unless (gnus-summary-goto-subject article)
11228       (error "No such article: %d" article))
11229     (gnus-summary-position-point)
11230     ;; If all commands are to be bunched up on one line, we collect
11231     ;; them here.
11232     (unless gnus-view-pseudos-separately
11233       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11234             files action)
11235         (while ps
11236           (setq action (cdr (assq 'action (car ps))))
11237           (setq files (list (cdr (assq 'name (car ps)))))
11238           (while (and ps (cdr ps)
11239                       (string= (or action "1")
11240                                (or (cdr (assq 'action (cadr ps))) "2")))
11241             (push (cdr (assq 'name (cadr ps))) files)
11242             (setcdr ps (cddr ps)))
11243           (when files
11244             (when (not (string-match "%s" action))
11245               (push " " files))
11246             (push " " files)
11247             (when (assq 'execute (car ps))
11248               (setcdr (assq 'execute (car ps))
11249                       (funcall (if (string-match "%s" action)
11250                                    'format 'concat)
11251                                action
11252                                (mapconcat
11253                                 (lambda (f)
11254                                   (if (equal f " ")
11255                                       f
11256                                     (shell-quote-argument f)))
11257                                 files " ")))))
11258           (setq ps (cdr ps)))))
11259     (if (and gnus-view-pseudos (not not-view))
11260         (while pslist
11261           (when (assq 'execute (car pslist))
11262             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11263                                   (eq gnus-view-pseudos 'not-confirm)))
11264           (setq pslist (cdr pslist)))
11265       (save-excursion
11266         (while pslist
11267           (setq after-article (or (cdr (assq 'article (car pslist)))
11268                                   (gnus-summary-article-number)))
11269           (gnus-summary-goto-subject after-article)
11270           (forward-line 1)
11271           (setq b (point))
11272           (insert "    " (file-name-nondirectory
11273                           (cdr (assq 'name (car pslist))))
11274                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11275           (setq e (point))
11276           (forward-line -1)             ; back to `b'
11277           (gnus-add-text-properties
11278            b (1- e) (list 'gnus-number gnus-reffed-article-number
11279                           gnus-mouse-face-prop gnus-mouse-face))
11280           (gnus-data-enter
11281            after-article gnus-reffed-article-number
11282            gnus-unread-mark b (car pslist) 0 (- e b))
11283           (setq gnus-newsgroup-unreads
11284                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11285                                          gnus-reffed-article-number))
11286           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11287           (setq pslist (cdr pslist)))))))
11288
11289 (defun gnus-pseudos< (p1 p2)
11290   (let ((c1 (cdr (assq 'action p1)))
11291         (c2 (cdr (assq 'action p2))))
11292     (and c1 c2 (string< c1 c2))))
11293
11294 (defun gnus-request-pseudo-article (props)
11295   (cond ((assq 'execute props)
11296          (gnus-execute-command (cdr (assq 'execute props)))))
11297   (let ((gnus-current-article (gnus-summary-article-number)))
11298     (gnus-run-hooks 'gnus-mark-article-hook)))
11299
11300 (defun gnus-execute-command (command &optional automatic)
11301   (save-excursion
11302     (gnus-article-setup-buffer)
11303     (set-buffer gnus-article-buffer)
11304     (setq buffer-read-only nil)
11305     (let ((command (if automatic command
11306                      (read-string "Command: " (cons command 0)))))
11307       (erase-buffer)
11308       (insert "$ " command "\n\n")
11309       (if gnus-view-pseudo-asynchronously
11310           (start-process "gnus-execute" (current-buffer) shell-file-name
11311                          shell-command-switch command)
11312         (call-process shell-file-name nil t nil
11313                       shell-command-switch command)))))
11314
11315 ;; Summary kill commands.
11316
11317 (defun gnus-summary-edit-global-kill (article)
11318   "Edit the \"global\" kill file."
11319   (interactive (list (gnus-summary-article-number)))
11320   (gnus-group-edit-global-kill article))
11321
11322 (defun gnus-summary-edit-local-kill ()
11323   "Edit a local kill file applied to the current newsgroup."
11324   (interactive)
11325   (setq gnus-current-headers (gnus-summary-article-header))
11326   (gnus-group-edit-local-kill
11327    (gnus-summary-article-number) gnus-newsgroup-name))
11328
11329 ;;; Header reading.
11330
11331 (defun gnus-read-header (id &optional header)
11332   "Read the headers of article ID and enter them into the Gnus system."
11333   (let ((group gnus-newsgroup-name)
11334         (gnus-override-method
11335          (or
11336           gnus-override-method
11337           (and (gnus-news-group-p gnus-newsgroup-name)
11338                (car (gnus-refer-article-methods)))))
11339         where)
11340     ;; First we check to see whether the header in question is already
11341     ;; fetched.
11342     (if (stringp id)
11343         ;; This is a Message-ID.
11344         (setq header (or header (gnus-id-to-header id)))
11345       ;; This is an article number.
11346       (setq header (or header (gnus-summary-article-header id))))
11347     (if (and header
11348              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11349         ;; We have found the header.
11350         header
11351       ;; We have to really fetch the header to this article.
11352       (save-excursion
11353         (set-buffer nntp-server-buffer)
11354         (when (setq where (gnus-request-head id group))
11355           (nnheader-fold-continuation-lines)
11356           (goto-char (point-max))
11357           (insert ".\n")
11358           (goto-char (point-min))
11359           (insert "211 ")
11360           (princ (cond
11361                   ((numberp id) id)
11362                   ((cdr where) (cdr where))
11363                   (header (mail-header-number header))
11364                   (t gnus-reffed-article-number))
11365                  (current-buffer))
11366           (insert " Article retrieved.\n"))
11367         (if (or (not where)
11368                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11369             ()                          ; Malformed head.
11370           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11371             (when (and (stringp id)
11372                        (not (string= (gnus-group-real-name group)
11373                                      (car where))))
11374               ;; If we fetched by Message-ID and the article came
11375               ;; from a different group, we fudge some bogus article
11376               ;; numbers for this article.
11377               (mail-header-set-number header gnus-reffed-article-number))
11378             (save-excursion
11379               (set-buffer gnus-summary-buffer)
11380               (decf gnus-reffed-article-number)
11381               (gnus-remove-header (mail-header-number header))
11382               (push header gnus-newsgroup-headers)
11383               (setq gnus-current-headers header)
11384               (push (mail-header-number header) gnus-newsgroup-limit)))
11385           header)))))
11386
11387 (defun gnus-remove-header (number)
11388   "Remove header NUMBER from `gnus-newsgroup-headers'."
11389   (if (and gnus-newsgroup-headers
11390            (= number (mail-header-number (car gnus-newsgroup-headers))))
11391       (pop gnus-newsgroup-headers)
11392     (let ((headers gnus-newsgroup-headers))
11393       (while (and (cdr headers)
11394                   (not (= number (mail-header-number (cadr headers)))))
11395         (pop headers))
11396       (when (cdr headers)
11397         (setcdr headers (cddr headers))))))
11398
11399 ;;;
11400 ;;; summary highlights
11401 ;;;
11402
11403 (defun gnus-highlight-selected-summary ()
11404   "Highlight selected article in summary buffer."
11405   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11406   (when gnus-summary-selected-face
11407     (save-excursion
11408       (let* ((beg (point-at-bol))
11409              (end (point-at-eol))
11410              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11411              (from (if (get-text-property beg gnus-mouse-face-prop)
11412                        beg
11413                      (or (next-single-property-change
11414                           beg gnus-mouse-face-prop nil end)
11415                          beg)))
11416              (to
11417               (if (= from end)
11418                   (- from 2)
11419                 (or (next-single-property-change
11420                      from gnus-mouse-face-prop nil end)
11421                     end))))
11422         ;; If no mouse-face prop on line we will have to = from = end,
11423         ;; so we highlight the entire line instead.
11424         (when (= (+ to 2) from)
11425           (setq from beg)
11426           (setq to end))
11427         (if gnus-newsgroup-selected-overlay
11428             ;; Move old overlay.
11429             (gnus-move-overlay
11430              gnus-newsgroup-selected-overlay from to (current-buffer))
11431           ;; Create new overlay.
11432           (gnus-overlay-put
11433            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11434            'face gnus-summary-selected-face))))))
11435
11436 (defvar gnus-summary-highlight-line-cached nil)
11437 (defvar gnus-summary-highlight-line-trigger nil)
11438
11439 (defun gnus-summary-highlight-line-0 ()
11440   (if (and (eq gnus-summary-highlight-line-trigger
11441                gnus-summary-highlight)
11442            gnus-summary-highlight-line-cached)
11443       gnus-summary-highlight-line-cached
11444     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11445           gnus-summary-highlight-line-cached
11446           (let* ((cond (list 'cond))
11447                  (c cond)
11448                  (list gnus-summary-highlight))
11449             (while list
11450               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11451                               nil))
11452               (setq c (cdr c)
11453                     list (cdr list)))
11454             (gnus-byte-compile (list 'lambda nil cond))))))
11455
11456 (defun gnus-summary-highlight-line ()
11457   "Highlight current line according to `gnus-summary-highlight'."
11458   (let* ((beg (point-at-bol))
11459          (article (or (gnus-summary-article-number) gnus-current-article))
11460          (score (or (cdr (assq article
11461                                gnus-newsgroup-scored))
11462                     gnus-summary-default-score 0))
11463          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11464          (inhibit-read-only t)
11465          (default gnus-summary-default-score)
11466          (default-high gnus-summary-default-high-score)
11467          (default-low gnus-summary-default-low-score)
11468          (uncached (and gnus-summary-use-undownloaded-faces
11469                         (memq article gnus-newsgroup-undownloaded)
11470                         (not (memq article gnus-newsgroup-cached)))))
11471     (let ((face (funcall (gnus-summary-highlight-line-0))))
11472       (unless (eq face (get-text-property beg 'face))
11473         (gnus-put-text-property-excluding-characters-with-faces
11474          beg (point-at-eol) 'face
11475          (setq face (if (boundp face) (symbol-value face) face)))
11476         (when gnus-summary-highlight-line-function
11477           (funcall gnus-summary-highlight-line-function article face))))))
11478
11479 (defun gnus-update-read-articles (group unread &optional compute)
11480   "Update the list of read articles in GROUP.
11481 UNREAD is a sorted list."
11482   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11483         (info (gnus-get-info group))
11484         (prev 1)
11485         read)
11486     (if (or (not info) (not active))
11487         ;; There is no info on this group if it was, in fact,
11488         ;; killed.  Gnus stores no information on killed groups, so
11489         ;; there's nothing to be done.
11490         ;; One could store the information somewhere temporarily,
11491         ;; perhaps...  Hmmm...
11492         ()
11493       ;; Remove any negative articles numbers.
11494       (while (and unread (< (car unread) 0))
11495         (setq unread (cdr unread)))
11496       ;; Remove any expired article numbers
11497       (while (and unread (< (car unread) (car active)))
11498         (setq unread (cdr unread)))
11499       ;; Compute the ranges of read articles by looking at the list of
11500       ;; unread articles.
11501       (while unread
11502         (when (/= (car unread) prev)
11503           (push (if (= prev (1- (car unread))) prev
11504                   (cons prev (1- (car unread))))
11505                 read))
11506         (setq prev (1+ (car unread)))
11507         (setq unread (cdr unread)))
11508       (when (<= prev (cdr active))
11509         (push (cons prev (cdr active)) read))
11510       (setq read (if (> (length read) 1) (nreverse read) read))
11511       (if compute
11512           read
11513         (save-excursion
11514           (let (setmarkundo)
11515             ;; Propagate the read marks to the backend.
11516             (when (gnus-check-backend-function 'request-set-mark group)
11517               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11518                     (add (gnus-remove-from-range read (gnus-info-read info))))
11519                 (when (or add del)
11520                   (unless (gnus-check-group group)
11521                     (error "Can't open server for %s" group))
11522                   (gnus-request-set-mark
11523                    group (delq nil (list (if add (list add 'add '(read)))
11524                                          (if del (list del 'del '(read))))))
11525                   (setq setmarkundo
11526                         `(gnus-request-set-mark
11527                           ,group
11528                           ',(delq nil (list
11529                                        (if del (list del 'add '(read)))
11530                                        (if add (list add 'del '(read))))))))))
11531             (set-buffer gnus-group-buffer)
11532             (gnus-undo-register
11533               `(progn
11534                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11535                  (gnus-info-set-read ',info ',(gnus-info-read info))
11536                  (gnus-get-unread-articles-in-group ',info
11537                                                     (gnus-active ,group))
11538                  (gnus-group-update-group ,group t)
11539                  ,setmarkundo))))
11540         ;; Enter this list into the group info.
11541         (gnus-info-set-read info read)
11542         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11543         (gnus-get-unread-articles-in-group info (gnus-active group))
11544         t))))
11545
11546 (defun gnus-offer-save-summaries ()
11547   "Offer to save all active summary buffers."
11548   (let (buffers)
11549     ;; Go through all buffers and find all summaries.
11550     (dolist (buffer (buffer-list))
11551       (when (and (setq buffer (buffer-name buffer))
11552                  (string-match "Summary" buffer)
11553                  (with-current-buffer buffer
11554                    ;; We check that this is, indeed, a summary buffer.
11555                    (and (eq major-mode 'gnus-summary-mode)
11556                         ;; Also make sure this isn't bogus.
11557                         gnus-newsgroup-prepared
11558                         ;; Also make sure that this isn't a
11559                         ;; dead summary buffer.
11560                         (not gnus-dead-summary-mode))))
11561         (push buffer buffers)))
11562     ;; Go through all these summary buffers and offer to save them.
11563     (when buffers
11564       (save-excursion
11565         (map-y-or-n-p
11566          "Update summary buffer %s? "
11567          (lambda (buf)
11568            (switch-to-buffer buf)
11569            (gnus-summary-exit))
11570          buffers)))))
11571
11572
11573 ;;; @ for mime-partial
11574 ;;;
11575
11576 (defun gnus-request-partial-message ()
11577   (save-excursion
11578     (let ((number (gnus-summary-article-number))
11579           (group gnus-newsgroup-name)
11580           (mother gnus-article-buffer))
11581       (set-buffer (get-buffer-create " *Partial Article*"))
11582       (erase-buffer)
11583       (setq mime-preview-buffer mother)
11584       (gnus-request-article-this-buffer number group)
11585       (mime-parse-buffer)
11586       )))
11587
11588 (autoload 'mime-combine-message/partial-pieces-automatically
11589   "mime-partial"
11590   "Internal method to combine message/partial messages automatically.")
11591
11592 (mime-add-condition
11593  'action '((type . message)(subtype . partial)
11594            (major-mode . gnus-original-article-mode)
11595            (method . mime-combine-message/partial-pieces-automatically)
11596            (summary-buffer-exp . gnus-summary-buffer)
11597            (request-partial-message-method . gnus-request-partial-message)
11598            ))
11599
11600
11601 ;;; @ for message/rfc822
11602 ;;;
11603
11604 (defun gnus-mime-extract-message/rfc822 (entity situation)
11605   "Burst a forwarded article."
11606   (save-excursion
11607     (set-buffer gnus-summary-buffer)
11608     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11609                                    gnus-newsgroup-name 'gnus-group-history))
11610            (gnus-group-marked (list group))
11611            article info)
11612       (with-temp-buffer
11613         (mime-insert-entity-content entity)
11614         (setq article (gnus-request-accept-article group)))
11615       (when (and (consp article)
11616                  (numberp (setq article (cdr article))))
11617         (setq info (gnus-get-info group))
11618         (gnus-info-set-read info
11619                             (gnus-remove-from-range (gnus-info-read info)
11620                                                     (list article)))
11621         (when (string-equal group gnus-newsgroup-name)
11622           (forward-line 1)
11623           (let (gnus-show-threads)
11624             (gnus-summary-goto-subject article t))
11625           (gnus-summary-clear-mark-forward 1))
11626         (set-buffer gnus-group-buffer)
11627         (gnus-group-get-new-news-this-group nil t)))))
11628
11629 (mime-add-condition
11630  'action '((type . message)(subtype . rfc822)
11631            (major-mode . gnus-original-article-mode)
11632            (method . gnus-mime-extract-message/rfc822)
11633            (mode . "extract")
11634            ))
11635
11636 (mime-add-condition
11637  'action '((type . message)(subtype . news)
11638            (major-mode . gnus-original-article-mode)
11639            (method . gnus-mime-extract-message/rfc822)
11640            (mode . "extract")
11641            ))
11642
11643 (defun gnus-mime-extract-multipart (entity situation)
11644   (let ((children (mime-entity-children entity))
11645         mime-acting-situation-to-override
11646         f)
11647     (while children
11648       (mime-play-entity (car children)
11649                         (cons (assq 'mode situation)
11650                               mime-acting-situation-to-override))
11651       (setq children (cdr children)))
11652     (if (setq f (cdr (assq 'after-method
11653                            mime-acting-situation-to-override)))
11654         (eval f)
11655       )))
11656
11657 (mime-add-condition
11658  'action '((type . multipart)
11659            (method . gnus-mime-extract-multipart)
11660            (mode . "extract")
11661            )
11662  'with-default)
11663
11664
11665 ;;; @ end
11666 ;;;
11667
11668 (defun gnus-summary-inherit-default-charset ()
11669   "Import `default-mime-charset' from summary buffer.
11670 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11671 of FLIM is used."
11672   (if (buffer-live-p gnus-summary-buffer)
11673       (let (d-m-c d-m-c-u)
11674         (with-current-buffer gnus-summary-buffer
11675           (setq d-m-c (if (local-variable-p 'default-mime-charset
11676                                             gnus-summary-buffer)
11677                           default-mime-charset
11678                         t)
11679                 ;; LIMIT
11680                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11681                                               gnus-summary-buffer)
11682                             (symbol-value 'default-mime-charset-unlimited)
11683                           t)))
11684         (if (eq t d-m-c)
11685             (kill-local-variable 'default-mime-charset)
11686           (set (make-local-variable 'default-mime-charset) d-m-c))
11687         (if (eq t d-m-c-u)
11688             (kill-local-variable 'default-mime-charset-unlimited)
11689           (set (make-local-variable 'default-mime-charset-unlimited)
11690                d-m-c-u)))))
11691
11692 (defun gnus-summary-setup-default-charset ()
11693   "Setup newsgroup default charset."
11694   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11695       (progn
11696         (setq gnus-newsgroup-charset nil)
11697         (set (make-local-variable 'default-mime-charset) nil)
11698         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11699           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11700     (let ((ignored-charsets
11701            (or gnus-newsgroup-ephemeral-ignored-charsets
11702                (append
11703                 (and gnus-newsgroup-name
11704                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11705                 gnus-newsgroup-ignored-charsets)))
11706           charset)
11707       (setq gnus-newsgroup-charset
11708             (or gnus-newsgroup-ephemeral-charset
11709                 (when (and gnus-newsgroup-name
11710                            (setq charset (gnus-parameter-charset
11711                                           gnus-newsgroup-name)))
11712                   (make-local-variable 'default-mime-charset)
11713                   (setq default-mime-charset charset))
11714                 gnus-default-charset))
11715       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11716            ignored-charsets))))
11717
11718 ;;;
11719 ;;; Mime Commands
11720 ;;;
11721
11722 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11723   "Display the current article buffer fully MIME-buttonized.
11724 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11725 treated as multipart/mixed."
11726   (interactive "P")
11727   (require 'gnus-art)
11728   (let ((gnus-unbuttonized-mime-types nil)
11729         (gnus-mime-display-multipart-as-mixed show-all-parts))
11730     (gnus-summary-show-article)))
11731
11732 (defun gnus-summary-repair-multipart (article)
11733   "Add a Content-Type header to a multipart article without one."
11734   (interactive (list (gnus-summary-article-number)))
11735   (gnus-with-article article
11736     (message-narrow-to-head)
11737     (message-remove-header "Mime-Version")
11738     (goto-char (point-max))
11739     (insert "Mime-Version: 1.0\n")
11740     (widen)
11741     (when (search-forward "\n--" nil t)
11742       (let ((separator (buffer-substring (point) (point-at-eol))))
11743         (message-narrow-to-head)
11744         (message-remove-header "Content-Type")
11745         (goto-char (point-max))
11746         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11747                         separator))
11748         (widen))))
11749   (let (gnus-mark-article-hook)
11750     (gnus-summary-select-article t t nil article)))
11751
11752 (defun gnus-summary-toggle-display-buttonized ()
11753   "Toggle the buttonizing of the article buffer."
11754   (interactive)
11755   (require 'gnus-art)
11756   (if (setq gnus-inhibit-mime-unbuttonizing
11757             (not gnus-inhibit-mime-unbuttonizing))
11758       (let ((gnus-unbuttonized-mime-types nil))
11759         (gnus-summary-show-article))
11760     (gnus-summary-show-article)))
11761
11762 ;;;
11763 ;;; Intelli-mouse commmands
11764 ;;;
11765
11766 (defun gnus-wheel-summary-scroll (event)
11767   (interactive "e")
11768   (let ((amount (if (memq 'shift (event-modifiers event))
11769                     (car gnus-wheel-scroll-amount)
11770                   (cdr gnus-wheel-scroll-amount)))
11771         (direction (- (* (static-if (featurep 'xemacs)
11772                              (event-button event)
11773                            (cond ((eq 'mouse-4 (event-basic-type event))
11774                                   4)
11775                                  ((eq 'mouse-5 (event-basic-type event))
11776                                   5)))
11777                          2) 9))
11778         edge)
11779     (gnus-summary-scroll-up (* amount direction))
11780     (when (gnus-eval-in-buffer-window gnus-article-buffer
11781             (save-restriction
11782               (widen)
11783               (and (if (< 0 direction)
11784                        (gnus-article-next-page 0)
11785                      (gnus-article-prev-page 0)
11786                      (bobp))
11787                    (if (setq edge (get-text-property
11788                                    (point-min) 'gnus-wheel-edge))
11789                        (setq edge (* edge direction))
11790                      (setq edge -1))
11791                    (or (plusp edge)
11792                        (let ((buffer-read-only nil)
11793                              (inhibit-read-only t))
11794                          (put-text-property (point-min) (point-max)
11795                                             'gnus-wheel-edge direction)
11796                          nil))
11797                    (or (> edge gnus-wheel-edge-resistance)
11798                        (let ((buffer-read-only nil)
11799                              (inhibit-read-only t))
11800                          (put-text-property (point-min) (point-max)
11801                                             'gnus-wheel-edge
11802                                             (* (1+ edge) direction))
11803                          nil))
11804                    (eq last-command 'gnus-wheel-summary-scroll))))
11805       (gnus-summary-next-article nil nil (minusp direction)))))
11806
11807 (defun gnus-wheel-install ()
11808   "Enable mouse wheel support on summary window."
11809   (when gnus-use-wheel
11810     (let ((keys
11811            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11812       (dolist (key keys)
11813         (define-key gnus-summary-mode-map key
11814           'gnus-wheel-summary-scroll)))))
11815
11816 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11817
11818 ;;;
11819 ;;; Traditional PGP commmands
11820 ;;;
11821
11822 (defun gnus-summary-decrypt-article (&optional force)
11823   "Decrypt the current article in traditional PGP way.
11824 This will have permanent effect only in mail groups.
11825 If FORCE is non-nil, allow editing of articles even in read-only
11826 groups."
11827   (interactive "P")
11828   (gnus-summary-select-article t)
11829   (gnus-eval-in-buffer-window gnus-article-buffer
11830     (save-excursion
11831       (save-restriction
11832         (widen)
11833         (goto-char (point-min))
11834         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11835           (error "Not a traditional PGP message!"))
11836         (let ((armor-start (match-beginning 0)))
11837           (if (and (pgg-decrypt-region armor-start (point-max))
11838                    (or force (not (gnus-group-read-only-p))))
11839               (let ((inhibit-read-only t)
11840                     buffer-read-only)
11841                 (delete-region armor-start
11842                                (progn
11843                                  (re-search-forward "^-+END PGP" nil t)
11844                                  (beginning-of-line 2)
11845                                  (point)))
11846                 (insert-buffer-substring pgg-output-buffer))))))))
11847
11848 (defun gnus-summary-verify-article ()
11849   "Verify the current article in traditional PGP way."
11850   (interactive)
11851   (save-excursion
11852     (set-buffer gnus-original-article-buffer)
11853     (goto-char (point-min))
11854     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11855       (error "Not a traditional PGP message!"))
11856     (re-search-forward "^-+END PGP" nil t)
11857     (beginning-of-line 2)
11858     (call-interactively (function pgg-verify-region))))
11859
11860 ;;;
11861 ;;; Generic summary marking commands
11862 ;;;
11863
11864 (defvar gnus-summary-marking-alist
11865   '((read gnus-del-mark "d")
11866     (unread gnus-unread-mark "u")
11867     (ticked gnus-ticked-mark "!")
11868     (dormant gnus-dormant-mark "?")
11869     (expirable gnus-expirable-mark "e"))
11870   "An alist of names/marks/keystrokes.")
11871
11872 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11873 (defvar gnus-summary-mark-map)
11874
11875 (defun gnus-summary-make-all-marking-commands ()
11876   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11877   (dolist (elem gnus-summary-marking-alist)
11878     (apply 'gnus-summary-make-marking-command elem)))
11879
11880 (defun gnus-summary-make-marking-command (name mark keystroke)
11881   (let ((map (make-sparse-keymap)))
11882     (define-key gnus-summary-generic-mark-map keystroke map)
11883     (dolist (lway `((next "next" next nil "n")
11884                     (next-unread "next unread" next t "N")
11885                     (prev "previous" prev nil "p")
11886                     (prev-unread "previous unread" prev t "P")
11887                     (nomove "" nil nil ,keystroke)))
11888       (let ((func (gnus-summary-make-marking-command-1
11889                    mark (car lway) lway name)))
11890         (setq func (eval func))
11891         (define-key map (nth 4 lway) func)))))
11892
11893 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11894   `(defun ,(intern
11895             (format "gnus-summary-put-mark-as-%s%s"
11896                     name (if (eq way 'nomove)
11897                              ""
11898                            (concat "-" (symbol-name way)))))
11899      (n)
11900      ,(format
11901        "Mark the current article as %s%s.
11902 If N, the prefix, then repeat N times.
11903 If N is negative, move in reverse order.
11904 The difference between N and the actual number of articles marked is
11905 returned."
11906        name (car (cdr lway)))
11907      (interactive "p")
11908      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11909
11910 (defun gnus-summary-generic-mark (n mark move unread)
11911   "Mark N articles with MARK."
11912   (unless (eq major-mode 'gnus-summary-mode)
11913     (error "This command can only be used in the summary buffer"))
11914   (gnus-summary-show-thread)
11915   (let ((nummove
11916          (cond
11917           ((eq move 'next) 1)
11918           ((eq move 'prev) -1)
11919           (t 0))))
11920     (if (zerop nummove)
11921         (setq n 1)
11922       (when (< n 0)
11923         (setq n (abs n)
11924               nummove (* -1 nummove))))
11925     (while (and (> n 0)
11926                 (gnus-summary-mark-article nil mark)
11927                 (zerop (gnus-summary-next-subject nummove unread t)))
11928       (setq n (1- n)))
11929     (when (/= 0 n)
11930       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11931     (gnus-summary-recenter)
11932     (gnus-summary-position-point)
11933     (gnus-set-mode-line 'summary)
11934     n))
11935
11936 (defun gnus-summary-insert-articles (articles)
11937   (when (setq articles
11938               (gnus-sorted-difference articles
11939                                       (mapcar (lambda (h)
11940                                                 (mail-header-number h))
11941                                               gnus-newsgroup-headers)))
11942     (setq gnus-newsgroup-headers
11943           (gnus-merge 'list
11944                       gnus-newsgroup-headers
11945                       (gnus-fetch-headers articles)
11946                       'gnus-article-sort-by-number))
11947     ;; Suppress duplicates?
11948     (when gnus-suppress-duplicates
11949       (gnus-dup-suppress-articles))
11950
11951     ;; We might want to build some more threads first.
11952     (when (and gnus-fetch-old-headers
11953                (eq gnus-headers-retrieved-by 'nov))
11954       (if (eq gnus-fetch-old-headers 'invisible)
11955           (gnus-build-all-threads)
11956         (gnus-build-old-threads)))
11957     ;; Let the Gnus agent mark articles as read.
11958     (when gnus-agent
11959       (gnus-agent-get-undownloaded-list))
11960     ;; Remove list identifiers from subject
11961     (when gnus-list-identifiers
11962       (gnus-summary-remove-list-identifiers))
11963     ;; First and last article in this newsgroup.
11964     (when gnus-newsgroup-headers
11965       (setq gnus-newsgroup-begin
11966             (mail-header-number (car gnus-newsgroup-headers))
11967             gnus-newsgroup-end
11968             (mail-header-number
11969              (gnus-last-element gnus-newsgroup-headers))))
11970     (when gnus-use-scoring
11971       (gnus-possibly-score-headers))))
11972
11973 (defun gnus-summary-insert-old-articles (&optional all)
11974   "Insert all old articles in this group.
11975 If ALL is non-nil, already read articles become readable.
11976 If ALL is a number, fetch this number of articles."
11977   (interactive "P")
11978   (prog1
11979       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11980             older len)
11981         (setq older
11982               ;; Some nntp servers lie about their active range.  When
11983               ;; this happens, the active range can be in the millions.
11984               ;; Use a compressed range to avoid creating a huge list.
11985               (gnus-range-difference (list gnus-newsgroup-active) old))
11986         (setq len (gnus-range-length older))
11987         (cond
11988          ((null older) nil)
11989          ((numberp all)
11990           (if (< all len)
11991               (let ((older-range (nreverse older)))
11992                 (setq older nil)
11993
11994                 (while (> all 0)
11995                   (let* ((r (pop older-range))
11996                          (min (if (numberp r) r (car r)))
11997                          (max (if (numberp r) r (cdr r))))
11998                     (while (and (<= min max)
11999                                 (> all 0))
12000                       (push max older)
12001                       (setq all (1- all)
12002                             max (1- max))))))
12003             (setq older (gnus-uncompress-range older))))
12004          (all
12005           (setq older (gnus-uncompress-range older)))
12006          (t
12007           (when (and (numberp gnus-large-newsgroup)
12008                    (> len gnus-large-newsgroup))
12009               (let* ((cursor-in-echo-area nil)
12010                      (initial (gnus-parameter-large-newsgroup-initial
12011                                gnus-newsgroup-name))
12012                      (input
12013                       (read-string
12014                        (format
12015                         "How many articles from %s (%s %d): "
12016                         (gnus-limit-string
12017                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12018                         (if initial "max" "default")
12019                         len)
12020                        (if initial
12021                            (cons (number-to-string initial)
12022                                  0)))))
12023                 (unless (string-match "^[ \t]*$" input)
12024                   (setq all (string-to-number input))
12025                   (if (< all len)
12026                       (let ((older-range (nreverse older)))
12027                         (setq older nil)
12028
12029                         (while (> all 0)
12030                           (let* ((r (pop older-range))
12031                                  (min (if (numberp r) r (car r)))
12032                                  (max (if (numberp r) r (cdr r))))
12033                             (while (and (<= min max)
12034                                         (> all 0))
12035                               (push max older)
12036                               (setq all (1- all)
12037                                     max (1- max))))))))))
12038           (setq older (gnus-uncompress-range older))))
12039         (if (not older)
12040             (message "No old news.")
12041           (gnus-summary-insert-articles older)
12042           (gnus-summary-limit (gnus-sorted-nunion old older))))
12043     (gnus-summary-position-point)))
12044
12045 (defun gnus-summary-insert-new-articles ()
12046   "Insert all new articles in this group."
12047   (interactive)
12048   (prog1
12049       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12050             (old-active gnus-newsgroup-active)
12051             (nnmail-fetched-sources (list t))
12052             i new)
12053         (setq gnus-newsgroup-active
12054               (gnus-activate-group gnus-newsgroup-name 'scan))
12055         (setq i (cdr gnus-newsgroup-active))
12056         (while (> i (cdr old-active))
12057           (push i new)
12058           (decf i))
12059         (if (not new)
12060             (message "No gnus is bad news")
12061           (gnus-summary-insert-articles new)
12062           (setq gnus-newsgroup-unreads
12063                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12064           (gnus-summary-limit (gnus-sorted-nunion old new))))
12065     (gnus-summary-position-point)))
12066
12067 (gnus-summary-make-all-marking-commands)
12068
12069 (gnus-ems-redefine)
12070
12071 (provide 'gnus-sum)
12072
12073 (run-hooks 'gnus-sum-load-hook)
12074
12075 ;; Local Variables:
12076 ;; coding: iso-8859-1
12077 ;; End:
12078
12079 ;;; gnus-sum.el ends here