6c39ee2961a1df13430425a9f5752a47bb5ecbf0
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-mode))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'gmm-utils)
42 (require 'mm-decode)
43 (require 'nnoo)
44
45 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
46 (autoload 'gnus-cache-write-active "gnus-cache")
47 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
48 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
49 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
50 (autoload 'mm-uu-dissect "mm-uu")
51 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
52   "Deuglify broken Outlook (Express) articles and redisplay."
53   t)
54 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
55 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
56 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
57
58 (defcustom gnus-kill-summary-on-exit t
59   "*If non-nil, kill the summary buffer when you exit from it.
60 If nil, the summary will become a \"*Dead Summary*\" buffer, and
61 it will be killed sometime later."
62   :group 'gnus-summary-exit
63   :type 'boolean)
64
65 (defcustom gnus-fetch-old-headers nil
66   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
67 If an unread article in the group refers to an older, already
68 read (or just marked as read) article, the old article will not
69 normally be displayed in the Summary buffer.  If this variable is
70 t, Gnus will attempt to grab the headers to the old articles, and
71 thereby build complete threads.  If it has the value `some', all
72 old headers will be fetched but only enough headers to connect
73 otherwise loose threads will be displayed.  This variable can
74 also be a number.  In that case, no more than that number of old
75 headers will be fetched.  If it has the value `invisible', all
76 old headers will be fetched, but none will be displayed.
77
78 The server has to support NOV for any of this to work.
79
80 This feature can seriously impact performance it ignores all
81 locally cached header entries."
82   :group 'gnus-thread
83   :type '(choice (const :tag "off" nil)
84                  (const :tag "on" t)
85                  (const some)
86                  (const invisible)
87                  number
88                  (sexp :menu-tag "other" t)))
89
90 (defcustom gnus-refer-thread-limit 200
91   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
92 If t, fetch all the available old headers."
93   :group 'gnus-thread
94   :type '(choice number
95                  (sexp :menu-tag "other" t)))
96
97 (defcustom gnus-summary-make-false-root 'adopt
98   "*nil means that Gnus won't gather loose threads.
99 If the root of a thread has expired or been read in a previous
100 session, the information necessary to build a complete thread has been
101 lost.  Instead of having many small sub-threads from this original thread
102 scattered all over the summary buffer, Gnus can gather them.
103
104 If non-nil, Gnus will try to gather all loose sub-threads from an
105 original thread into one large thread.
106
107 If this variable is non-nil, it should be one of `none', `adopt',
108 `dummy' or `empty'.
109
110 If this variable is `none', Gnus will not make a false root, but just
111 present the sub-threads after another.
112 If this variable is `dummy', Gnus will create a dummy root that will
113 have all the sub-threads as children.
114 If this variable is `adopt', Gnus will make one of the \"children\"
115 the parent and mark all the step-children as such.
116 If this variable is `empty', the \"children\" are printed with empty
117 subject fields.  (Or rather, they will be printed with a string
118 given by the `gnus-summary-same-subject' variable.)"
119   :group 'gnus-thread
120   :type '(choice (const :tag "off" nil)
121                  (const none)
122                  (const dummy)
123                  (const adopt)
124                  (const empty)))
125
126 (defcustom gnus-summary-make-false-root-always nil
127   "Always make a false dummy root."
128   :version "22.1"
129   :group 'gnus-thread
130   :type 'boolean)
131
132 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
133   "*A regexp to match subjects to be excluded from loose thread gathering.
134 As loose thread gathering is done on subjects only, that means that
135 there can be many false gatherings performed.  By rooting out certain
136 common subjects, gathering might become saner."
137   :group 'gnus-thread
138   :type 'regexp)
139
140 (defcustom gnus-summary-gather-subject-limit nil
141   "*Maximum length of subject comparisons when gathering loose threads.
142 Use nil to compare full subjects.  Setting this variable to a low
143 number will help gather threads that have been corrupted by
144 newsreaders chopping off subject lines, but it might also mean that
145 unrelated articles that have subject that happen to begin with the
146 same few characters will be incorrectly gathered.
147
148 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
149 comparing subjects."
150   :group 'gnus-thread
151   :type '(choice (const :tag "off" nil)
152                  (const fuzzy)
153                  (sexp :menu-tag "on" t)))
154
155 (defcustom gnus-simplify-subject-functions nil
156   "List of functions taking a string argument that simplify subjects.
157 The functions are applied recursively.
158
159 Useful functions to put in this list include:
160 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
161 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
162   :group 'gnus-thread
163   :type '(repeat function))
164
165 (defcustom gnus-simplify-ignored-prefixes nil
166   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  regexp))
170
171 (defcustom gnus-build-sparse-threads nil
172   "*If non-nil, fill in the gaps in threads.
173 If `some', only fill in the gaps that are needed to tie loose threads
174 together.  If `more', fill in all leaf nodes that Gnus can find.  If
175 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
176   :group 'gnus-thread
177   :type '(choice (const :tag "off" nil)
178                  (const some)
179                  (const more)
180                  (sexp :menu-tag "all" t)))
181
182 (defcustom gnus-summary-thread-gathering-function
183   'gnus-gather-threads-by-subject
184   "*Function used for gathering loose threads.
185 There are two pre-defined functions: `gnus-gather-threads-by-subject',
186 which only takes Subjects into consideration; and
187 `gnus-gather-threads-by-references', which compared the References
188 headers of the articles to find matches."
189   :group 'gnus-thread
190   :type '(radio (function-item gnus-gather-threads-by-subject)
191                 (function-item gnus-gather-threads-by-references)
192                 (function :tag "other")))
193
194 (defcustom gnus-summary-same-subject ""
195   "*String indicating that the current article has the same subject as the previous.
196 This variable will only be used if the value of
197 `gnus-summary-make-false-root' is `empty'."
198   :group 'gnus-summary-format
199   :type 'string)
200
201 (defcustom gnus-summary-goto-unread t
202   "*If t, many commands will go to the next unread article.
203 This applies to marking commands as well as other commands that
204 \"naturally\" select the next article, like, for instance, `SPC' at
205 the end of an article.
206
207 If nil, the marking commands do NOT go to the next unread article
208 \(they go to the next article instead).  If `never', commands that
209 usually go to the next unread article, will go to the next article,
210 whether it is read or not."
211   :group 'gnus-summary-marks
212   :link '(custom-manual "(gnus)Setting Marks")
213   :type '(choice (const :tag "off" nil)
214                  (const never)
215                  (sexp :menu-tag "on" t)))
216
217 (defcustom gnus-summary-default-score 0
218   "*Default article score level.
219 All scores generated by the score files will be added to this score.
220 If this variable is nil, scoring will be disabled."
221   :group 'gnus-score-default
222   :type '(choice (const :tag "disable")
223                  integer))
224
225 (defcustom gnus-summary-default-high-score 0
226   "*Default threshold for a high scored article.
227 An article will be highlighted as high scored if its score is greater
228 than this score."
229   :version "22.1"
230   :group 'gnus-score-default
231   :type 'integer)
232
233 (defcustom gnus-summary-default-low-score 0
234   "*Default threshold for a low scored article.
235 An article will be highlighted as low scored if its score is smaller
236 than this score."
237   :version "22.1"
238   :group 'gnus-score-default
239   :type 'integer)
240
241 (defcustom gnus-summary-zcore-fuzz 0
242   "*Fuzziness factor for the zcore in the summary buffer.
243 Articles with scores closer than this to `gnus-summary-default-score'
244 will not be marked."
245   :group 'gnus-summary-format
246   :type 'integer)
247
248 (defcustom gnus-simplify-subject-fuzzy-regexp nil
249   "*Strings to be removed when doing fuzzy matches.
250 This can either be a regular expression or list of regular expressions
251 that will be removed from subject strings if fuzzy subject
252 simplification is selected."
253   :group 'gnus-thread
254   :type '(repeat regexp))
255
256 (defcustom gnus-show-threads t
257   "*If non-nil, display threads in summary mode."
258   :group 'gnus-thread
259   :type 'boolean)
260
261 (defcustom gnus-thread-hide-subtree nil
262   "*If non-nil, hide all threads initially.
263 This can be a predicate specifier which says which threads to hide.
264 If threads are hidden, you have to run the command
265 `gnus-summary-show-thread' by hand or select an article."
266   :group 'gnus-thread
267   :type '(radio (sexp :format "Non-nil\n"
268                       :match (lambda (widget value)
269                                (not (or (consp value) (functionp value))))
270                       :value t)
271                 (const nil)
272                 (sexp :tag "Predicate specifier")))
273
274 (defcustom gnus-thread-hide-killed t
275   "*If non-nil, hide killed threads automatically."
276   :group 'gnus-thread
277   :type 'boolean)
278
279 (defcustom gnus-thread-ignore-subject t
280   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
281 If nil, articles that have different subjects from their parents will
282 start separate threads."
283   :group 'gnus-thread
284   :type 'boolean)
285
286 (defcustom gnus-thread-operation-ignore-subject t
287   "*If non-nil, subjects will be ignored when doing thread commands.
288 This affects commands like `gnus-summary-kill-thread' and
289 `gnus-summary-lower-thread'.
290
291 If this variable is nil, articles in the same thread with different
292 subjects will not be included in the operation in question.  If this
293 variable is `fuzzy', only articles that have subjects that are fuzzily
294 equal will be included."
295   :group 'gnus-thread
296   :type '(choice (const :tag "off" nil)
297                  (const fuzzy)
298                  (sexp :tag "on" t)))
299
300 (defcustom gnus-thread-indent-level 4
301   "*Number that says how much each sub-thread should be indented."
302   :group 'gnus-thread
303   :type 'integer)
304
305 (defcustom gnus-auto-extend-newsgroup t
306   "*If non-nil, extend newsgroup forward and backward when requested."
307   :group 'gnus-summary-choose
308   :type 'boolean)
309
310 (defcustom gnus-auto-select-first t
311   "*If non-nil, select the article under point.
312 Which article this is is controlled by the `gnus-auto-select-subject'
313 variable.
314
315 If you want to prevent automatic selection of articles in some
316 newsgroups, set the variable to nil in `gnus-select-group-hook'."
317   :group 'gnus-group-select
318   :type '(choice (const :tag "none" nil)
319                  (sexp :menu-tag "first" t)))
320
321 (defcustom gnus-auto-select-subject 'unread
322   "*Says what subject to place under point when entering a group.
323
324 This variable can either be the symbols `first' (place point on the
325 first subject), `unread' (place point on the subject line of the first
326 unread article), `best' (place point on the subject line of the
327 higest-scored article), `unseen' (place point on the subject line of
328 the first unseen article), `unseen-or-unread' (place point on the subject
329 line of the first unseen article or, if all article have been seen, on the
330 subject line of the first unread article), or a function to be called to
331 place point on some subject line."
332   :version "22.1"
333   :group 'gnus-group-select
334   :type '(choice (const best)
335                  (const unread)
336                  (const first)
337                  (const unseen)
338                  (const unseen-or-unread)))
339
340 (defcustom gnus-auto-select-next t
341   "*If non-nil, offer to go to the next group from the end of the previous.
342 If the value is t and the next newsgroup is empty, Gnus will exit
343 summary mode and go back to group mode.  If the value is neither nil
344 nor t, Gnus will select the following unread newsgroup.  In
345 particular, if the value is the symbol `quietly', the next unread
346 newsgroup will be selected without any confirmation, and if it is
347 `almost-quietly', the next group will be selected without any
348 confirmation if you are located on the last article in the group.
349 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
350 will go to the next group without confirmation."
351   :group 'gnus-summary-maneuvering
352   :type '(choice (const :tag "off" nil)
353                  (const quietly)
354                  (const almost-quietly)
355                  (const slightly-quietly)
356                  (sexp :menu-tag "on" t)))
357
358 (defcustom gnus-auto-select-same nil
359   "*If non-nil, select the next article with the same subject.
360 If there are no more articles with the same subject, go to
361 the first unread article."
362   :group 'gnus-summary-maneuvering
363   :type 'boolean)
364
365 (defcustom gnus-auto-goto-ignores 'unfetched
366   "*Says how to handle unfetched articles when maneuvering.
367
368 This variable can either be the symbols nil (maneuver to any
369 article), `undownloaded' (maneuvering while unplugged ignores articles
370 that have not been fetched), `always-undownloaded' (maneuvering always
371 ignores articles that have not been fetched), `unfetched' (maneuvering
372 ignores articles whose headers have not been fetched).
373
374 NOTE: The list of unfetched articles will always be nil when plugged
375 and, when unplugged, a subset of the undownloaded article list."
376   :version "22.1"
377   :group 'gnus-summary-maneuvering
378   :type '(choice (const :tag "None" nil)
379                  (const :tag "Undownloaded when unplugged" undownloaded)
380                  (const :tag "Undownloaded" always-undownloaded)
381                  (const :tag "Unfetched" unfetched)))
382
383 (defcustom gnus-summary-check-current nil
384   "*If non-nil, consider the current article when moving.
385 The \"unread\" movement commands will stay on the same line if the
386 current article is unread."
387   :group 'gnus-summary-maneuvering
388   :type 'boolean)
389
390 (defcustom gnus-auto-center-summary 2
391   "*If non-nil, always center the current summary buffer.
392 In particular, if `vertical' do only vertical recentering.  If non-nil
393 and non-`vertical', do both horizontal and vertical recentering."
394   :group 'gnus-summary-maneuvering
395   :type '(choice (const :tag "none" nil)
396                  (const vertical)
397                  (integer :tag "height")
398                  (sexp :menu-tag "both" t)))
399
400 (defvar gnus-auto-center-group t
401   "*If non-nil, always center the group buffer.")
402
403 (defcustom gnus-show-all-headers nil
404   "*If non-nil, don't hide any headers."
405   :group 'gnus-article-hiding
406   :group 'gnus-article-headers
407   :type 'boolean)
408
409 (defcustom gnus-summary-ignore-duplicates nil
410   "*If non-nil, ignore articles with identical Message-ID headers."
411   :group 'gnus-summary
412   :type 'boolean)
413
414 (defcustom gnus-single-article-buffer t
415   "*If non-nil, display all articles in the same buffer.
416 If nil, each group will get its own article buffer."
417   :group 'gnus-article-various
418   :type 'boolean)
419
420 (defcustom gnus-break-pages t
421   "*If non-nil, do page breaking on articles.
422 The page delimiter is specified by the `gnus-page-delimiter'
423 variable."
424   :group 'gnus-article-various
425   :type 'boolean)
426
427 (defcustom gnus-move-split-methods nil
428   "*Variable used to suggest where articles are to be moved to.
429 It uses the same syntax as the `gnus-split-methods' variable.
430 However, whereas `gnus-split-methods' specifies file names as targets,
431 this variable specifies group names."
432   :group 'gnus-summary-mail
433   :type '(repeat (choice (list :value (fun) function)
434                          (cons :value ("" "") regexp (repeat string))
435                          (sexp :value nil))))
436
437 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
438   "Function used to compute default prefix for article move/copy/etc prompts.
439 The function should take one argument, a group name, and return a
440 string with the suggested prefix."
441   :group 'gnus-summary-mail
442   :type 'function)
443
444 ;; FIXME: Although the custom type is `character' for the following variables,
445 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
446
447 (defcustom gnus-unread-mark ?           ;Whitespace
448   "*Mark used for unread articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-ticked-mark ?!
453   "*Mark used for ticked articles."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-dormant-mark ??
458   "*Mark used for dormant articles."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-del-mark ?r
463   "*Mark used for del'd articles."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-read-mark ?R
468   "*Mark used for read articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-expirable-mark ?E
473   "*Mark used for expirable articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-killed-mark ?K
478   "*Mark used for killed articles."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-spam-mark ?$
483   "*Mark used for spam articles."
484   :version "22.1"
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-souped-mark ?F
489   "*Mark used for souped articles."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-kill-file-mark ?X
494   "*Mark used for articles killed by kill files."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-low-score-mark ?Y
499   "*Mark used for articles with a low score."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-catchup-mark ?C
504   "*Mark used for articles that are caught up."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-replied-mark ?A
509   "*Mark used for articles that have been replied to."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-forwarded-mark ?F
514   "*Mark used for articles that have been forwarded."
515   :version "22.1"
516   :group 'gnus-summary-marks
517   :type 'character)
518
519 (defcustom gnus-recent-mark ?N
520   "*Mark used for articles that are recent."
521   :version "22.1"
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-cached-mark ?*
526   "*Mark used for articles that are in the cache."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-saved-mark ?S
531   "*Mark used for articles that have been saved."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-unseen-mark ?.
536   "*Mark used for articles that haven't been seen."
537   :version "22.1"
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-no-mark ?               ;Whitespace
542   "*Mark used for articles that have no other secondary mark."
543   :version "22.1"
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-ancient-mark ?O
548   "*Mark used for ancient articles."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-sparse-mark ?Q
553   "*Mark used for sparsely reffed articles."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-canceled-mark ?G
558   "*Mark used for canceled articles."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-duplicate-mark ?M
563   "*Mark used for duplicate articles."
564   :group 'gnus-summary-marks
565   :type 'character)
566
567 (defcustom gnus-undownloaded-mark ?-
568   "*Mark used for articles that weren't downloaded."
569   :version "22.1"
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-downloaded-mark ?+
574   "*Mark used for articles that were downloaded."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-downloadable-mark ?%
579   "*Mark used for articles that are to be downloaded."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-unsendable-mark ?=
584   "*Mark used for articles that won't be sent."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-score-over-mark ?+
589   "*Score mark used for articles with high scores."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-score-below-mark ?-
594   "*Score mark used for articles with low scores."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-empty-thread-mark ?     ;Whitespace
599   "*There is no thread under the article."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-not-empty-thread-mark ?=
604   "*There is a thread under the article."
605   :group 'gnus-summary-marks
606   :type 'character)
607
608 (defcustom gnus-view-pseudo-asynchronously nil
609   "*If non-nil, Gnus will view pseudo-articles asynchronously."
610   :group 'gnus-extract-view
611   :type 'boolean)
612
613 (defcustom gnus-auto-expirable-marks
614   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
615         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
616         gnus-souped-mark gnus-duplicate-mark)
617   "*The list of marks converted into expiration if a group is auto-expirable."
618   :version "21.1"
619   :group 'gnus-summary
620   :type '(repeat character))
621
622 (defcustom gnus-inhibit-user-auto-expire t
623   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
624   :version "21.1"
625   :group 'gnus-summary
626   :type 'boolean)
627
628 (defcustom gnus-view-pseudos nil
629   "*If `automatic', pseudo-articles will be viewed automatically.
630 If `not-confirm', pseudos will be viewed automatically, and the user
631 will not be asked to confirm the command."
632   :group 'gnus-extract-view
633   :type '(choice (const :tag "off" nil)
634                  (const automatic)
635                  (const not-confirm)))
636
637 (defcustom gnus-view-pseudos-separately t
638   "*If non-nil, one pseudo-article will be created for each file to be viewed.
639 If nil, all files that use the same viewing command will be given as a
640 list of parameters to that command."
641   :group 'gnus-extract-view
642   :type 'boolean)
643
644 (defcustom gnus-insert-pseudo-articles t
645   "*If non-nil, insert pseudo-articles when decoding articles."
646   :group 'gnus-extract-view
647   :type 'boolean)
648
649 (defcustom gnus-summary-dummy-line-format
650   "   %(:                             :%) %S\n"
651   "*The format specification for the dummy roots in the summary buffer.
652 It works along the same lines as a normal formatting string,
653 with some simple extensions.
654
655 %S  The subject
656
657 General format specifiers can also be used.
658 See `(gnus)Formatting Variables'."
659   :link '(custom-manual "(gnus)Formatting Variables")
660   :group 'gnus-threading
661   :type 'string)
662
663 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
664   "*The format specification for the summary mode line.
665 It works along the same lines as a normal formatting string,
666 with some simple extensions:
667
668 %G  Group name
669 %p  Unprefixed group name
670 %A  Current article number
671 %z  Current article score
672 %V  Gnus version
673 %U  Number of unread articles in the group
674 %e  Number of unselected articles in the group
675 %Z  A string with unread/unselected article counts
676 %g  Shortish group name
677 %S  Subject of the current article
678 %u  User-defined spec
679 %s  Current score file name
680 %d  Number of dormant articles
681 %r  Number of articles that have been marked as read in this session
682 %E  Number of articles expunged by the score files"
683   :group 'gnus-summary-format
684   :type 'string)
685
686 (defcustom gnus-list-identifiers nil
687   "Regexp that matches list identifiers to be removed from subject.
688 This can also be a list of regexps."
689   :version "21.1"
690   :group 'gnus-summary-format
691   :group 'gnus-article-hiding
692   :type '(choice (const :tag "none" nil)
693                  (regexp :value ".*")
694                  (repeat :value (".*") regexp)))
695
696 (defcustom gnus-summary-mark-below 0
697   "*Mark all articles with a score below this variable as read.
698 This variable is local to each summary buffer and usually set by the
699 score file."
700   :group 'gnus-score-default
701   :type 'integer)
702
703 (defun gnus-widget-reversible-match (widget value)
704   "Ignoring WIDGET, convert VALUE to internal form.
705 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
706   ;; (debug value)
707   (or (symbolp value)
708       (and (listp value)
709            (eq (length value) 2)
710            (eq (nth 0 value) 'not)
711            (symbolp (nth 1 value)))))
712
713 (defun gnus-widget-reversible-to-internal (widget value)
714   "Ignoring WIDGET, convert VALUE to internal form.
715 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
716 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
717   ;; (debug value)
718   (if (atom value)
719       (list value nil)
720     (list (nth 1 value) t)))
721
722 (defun gnus-widget-reversible-to-external (widget value)
723   "Ignoring WIDGET, convert VALUE to external form.
724 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
725 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
726   ;; (debug value)
727   (if (nth 1 value)
728       (list 'not (nth 0 value))
729     (nth 0 value)))
730
731 (define-widget 'gnus-widget-reversible 'group
732   "A `group' that convert values."
733   :match 'gnus-widget-reversible-match
734   :value-to-internal 'gnus-widget-reversible-to-internal
735   :value-to-external 'gnus-widget-reversible-to-external)
736
737 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
738   "*List of functions used for sorting articles in the summary buffer.
739
740 Each function takes two articles and returns non-nil if the first
741 article should be sorted before the other.  If you use more than one
742 function, the primary sort function should be the last.  You should
743 probably always include `gnus-article-sort-by-number' in the list of
744 sorting functions -- preferably first.  Also note that sorting by date
745 is often much slower than sorting by number, and the sorting order is
746 very similar.  (Sorting by date means sorting by the time the message
747 was sent, sorting by number means sorting by arrival time.)
748
749 Each item can also be a list `(not F)' where F is a function;
750 this reverses the sort order.
751
752 Ready-made functions include `gnus-article-sort-by-number',
753 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
754 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
755 and `gnus-article-sort-by-score'.
756
757 When threading is turned on, the variable `gnus-thread-sort-functions'
758 controls how articles are sorted."
759   :group 'gnus-summary-sort
760   :type '(repeat (gnus-widget-reversible
761                   (choice (function-item gnus-article-sort-by-number)
762                           (function-item gnus-article-sort-by-author)
763                           (function-item gnus-article-sort-by-subject)
764                           (function-item gnus-article-sort-by-date)
765                           (function-item gnus-article-sort-by-score)
766                           (function-item gnus-article-sort-by-random)
767                           (function :tag "other"))
768                   (boolean :tag "Reverse order"))))
769
770
771 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
772   "*List of functions used for sorting threads in the summary buffer.
773 By default, threads are sorted by article number.
774
775 Each function takes two threads and returns non-nil if the first
776 thread should be sorted before the other.  If you use more than one
777 function, the primary sort function should be the last.  You should
778 probably always include `gnus-thread-sort-by-number' in the list of
779 sorting functions -- preferably first.  Also note that sorting by date
780 is often much slower than sorting by number, and the sorting order is
781 very similar.  (Sorting by date means sorting by the time the message
782 was sent, sorting by number means sorting by arrival time.)
783
784 Each list item can also be a list `(not F)' where F is a
785 function; this specifies reversed sort order.
786
787 Ready-made functions include `gnus-thread-sort-by-number',
788 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
789 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
790 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
791 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
792 and `gnus-thread-sort-by-total-score' (see
793 `gnus-thread-score-function').
794
795 When threading is turned off, the variable
796 `gnus-article-sort-functions' controls how articles are sorted."
797   :group 'gnus-summary-sort
798   :type '(repeat
799           (gnus-widget-reversible
800            (choice (function-item gnus-thread-sort-by-number)
801                    (function-item gnus-thread-sort-by-author)
802                    (function-item gnus-thread-sort-by-recipient)
803                    (function-item gnus-thread-sort-by-subject)
804                    (function-item gnus-thread-sort-by-date)
805                    (function-item gnus-thread-sort-by-score)
806                    (function-item gnus-thread-sort-by-most-recent-number)
807                    (function-item gnus-thread-sort-by-most-recent-date)
808                    (function-item gnus-thread-sort-by-random)
809                    (function-item gnus-thread-sort-by-total-score)
810                    (function :tag "other"))
811            (boolean :tag "Reverse order"))))
812
813 (defcustom gnus-thread-score-function '+
814   "*Function used for calculating the total score of a thread.
815
816 The function is called with the scores of the article and each
817 subthread and should then return the score of the thread.
818
819 Some functions you can use are `+', `max', or `min'."
820   :group 'gnus-summary-sort
821   :type 'function)
822
823 (defcustom gnus-summary-expunge-below nil
824   "All articles that have a score less than this variable will be expunged.
825 This variable is local to the summary buffers."
826   :group 'gnus-score-default
827   :type '(choice (const :tag "off" nil)
828                  integer))
829
830 (defcustom gnus-thread-expunge-below nil
831   "All threads that have a total score less than this variable will be expunged.
832 See `gnus-thread-score-function' for en explanation of what a
833 \"thread score\" is.
834
835 This variable is local to the summary buffers."
836   :group 'gnus-threading
837   :group 'gnus-score-default
838   :type '(choice (const :tag "off" nil)
839                  integer))
840
841 (defcustom gnus-summary-mode-hook nil
842   "*A hook for Gnus summary mode.
843 This hook is run before any variables are set in the summary buffer."
844   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
845   :group 'gnus-summary-various
846   :type 'hook)
847
848 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
849 (when (featurep 'xemacs)
850   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
851   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
852   (add-hook 'gnus-summary-mode-hook
853             'gnus-xmas-switch-horizontal-scrollbar-off))
854
855 (defcustom gnus-summary-menu-hook nil
856   "*Hook run after the creation of the summary mode menu."
857   :group 'gnus-summary-visual
858   :type 'hook)
859
860 (defcustom gnus-summary-exit-hook nil
861   "*A hook called on exit from the summary buffer.
862 It will be called with point in the group buffer."
863   :group 'gnus-summary-exit
864   :type 'hook)
865
866 (defcustom gnus-summary-prepare-hook nil
867   "*A hook called after the summary buffer has been generated.
868 If you want to modify the summary buffer, you can use this hook."
869   :group 'gnus-summary-various
870   :type 'hook)
871
872 (defcustom gnus-summary-prepared-hook nil
873   "*A hook called as the last thing after the summary buffer has been generated."
874   :group 'gnus-summary-various
875   :type 'hook)
876
877 (defcustom gnus-summary-generate-hook nil
878   "*A hook run just before generating the summary buffer.
879 This hook is commonly used to customize threading variables and the
880 like."
881   :group 'gnus-summary-various
882   :type 'hook)
883
884 (defcustom gnus-select-group-hook nil
885   "*A hook called when a newsgroup is selected.
886
887 If you'd like to simplify subjects like the
888 `gnus-summary-next-same-subject' command does, you can use the
889 following hook:
890
891  (add-hook gnus-select-group-hook
892            (lambda ()
893              (mapcar (lambda (header)
894                        (mail-header-set-subject
895                         header
896                         (gnus-simplify-subject
897                          (mail-header-subject header) 're-only)))
898                      gnus-newsgroup-headers)))"
899   :group 'gnus-group-select
900   :type 'hook)
901
902 (defcustom gnus-select-article-hook nil
903   "*A hook called when an article is selected."
904   :group 'gnus-summary-choose
905   :options '(gnus-agent-fetch-selected-article)
906   :type 'hook)
907
908 (defcustom gnus-visual-mark-article-hook
909   (list 'gnus-highlight-selected-summary)
910   "*Hook run after selecting an article in the summary buffer.
911 It is meant to be used for highlighting the article in some way.  It
912 is not run if `gnus-visual' is nil."
913   :group 'gnus-summary-visual
914   :type 'hook)
915
916 (defcustom gnus-parse-headers-hook nil
917   "*A hook called before parsing the headers."
918   :group 'gnus-various
919   :type 'hook)
920
921 (defcustom gnus-exit-group-hook nil
922   "*A hook called when exiting summary mode.
923 This hook is not called from the non-updating exit commands like `Q'."
924   :group 'gnus-various
925   :type 'hook)
926
927 (defcustom gnus-summary-update-hook
928   (list 'gnus-summary-highlight-line)
929   "*A hook called when a summary line is changed.
930 The hook will not be called if `gnus-visual' is nil.
931
932 The default function `gnus-summary-highlight-line' will
933 highlight the line according to the `gnus-summary-highlight'
934 variable."
935   :group 'gnus-summary-visual
936   :type 'hook)
937
938 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
939   "*A hook called when an article is selected for the first time.
940 The hook is intended to mark an article as read (or unread)
941 automatically when it is selected."
942   :group 'gnus-summary-choose
943   :type 'hook)
944
945 (defcustom gnus-group-no-more-groups-hook nil
946   "*A hook run when returning to group mode having no more (unread) groups."
947   :group 'gnus-group-select
948   :type 'hook)
949
950 (defcustom gnus-ps-print-hook nil
951   "*A hook run before ps-printing something from Gnus."
952   :group 'gnus-summary
953   :type 'hook)
954
955 (defcustom gnus-summary-article-move-hook nil
956   "*A hook called after an article is moved, copied, respooled, or crossposted."
957   :version "22.1"
958   :group 'gnus-summary
959   :type 'hook)
960
961 (defcustom gnus-summary-article-delete-hook nil
962   "*A hook called after an article is deleted."
963   :version "22.1"
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-article-expire-hook nil
968   "*A hook called after an article is expired."
969   :version "22.1"
970   :group 'gnus-summary
971   :type 'hook)
972
973 (defcustom gnus-summary-display-arrow
974   (and (fboundp 'display-graphic-p)
975        (display-graphic-p))
976   "*If non-nil, display an arrow highlighting the current article."
977   :version "22.1"
978   :group 'gnus-summary
979   :type 'boolean)
980
981 (defcustom gnus-summary-selected-face 'gnus-summary-selected
982   "Face used for highlighting the current article in the summary buffer."
983   :group 'gnus-summary-visual
984   :type 'face)
985
986 (defvar gnus-tmp-downloaded nil)
987
988 (defcustom gnus-summary-highlight
989   '(((eq mark gnus-canceled-mark)
990      . gnus-summary-cancelled)
991     ((and uncached (> score default-high))
992      . gnus-summary-high-undownloaded)
993     ((and uncached (< score default-low))
994      . gnus-summary-low-undownloaded)
995     (uncached
996      . gnus-summary-normal-undownloaded)
997     ((and (> score default-high)
998           (or (eq mark gnus-dormant-mark)
999               (eq mark gnus-ticked-mark)))
1000      . gnus-summary-high-ticked)
1001     ((and (< score default-low)
1002           (or (eq mark gnus-dormant-mark)
1003               (eq mark gnus-ticked-mark)))
1004      . gnus-summary-low-ticked)
1005     ((or (eq mark gnus-dormant-mark)
1006          (eq mark gnus-ticked-mark))
1007      . gnus-summary-normal-ticked)
1008     ((and (> score default-high) (eq mark gnus-ancient-mark))
1009      . gnus-summary-high-ancient)
1010     ((and (< score default-low) (eq mark gnus-ancient-mark))
1011      . gnus-summary-low-ancient)
1012     ((eq mark gnus-ancient-mark)
1013      . gnus-summary-normal-ancient)
1014     ((and (> score default-high) (eq mark gnus-unread-mark))
1015      . gnus-summary-high-unread)
1016     ((and (< score default-low) (eq mark gnus-unread-mark))
1017      . gnus-summary-low-unread)
1018     ((eq mark gnus-unread-mark)
1019      . gnus-summary-normal-unread)
1020     ((> score default-high)
1021      . gnus-summary-high-read)
1022     ((< score default-low)
1023      . gnus-summary-low-read)
1024     (t
1025      . gnus-summary-normal-read))
1026   "*Controls the highlighting of summary buffer lines.
1027
1028 A list of (FORM . FACE) pairs.  When deciding how a a particular
1029 summary line should be displayed, each form is evaluated.  The content
1030 of the face field after the first true form is used.  You can change
1031 how those summary lines are displayed, by editing the face field.
1032
1033 You can use the following variables in the FORM field.
1034
1035 score:        The article's score
1036 default:      The default article score.
1037 default-high: The default score for high scored articles.
1038 default-low:  The default score for low scored articles.
1039 below:        The score below which articles are automatically marked as read.
1040 mark:         The article's mark.
1041 uncached:     Non-nil if the article is uncached."
1042   :group 'gnus-summary-visual
1043   :type '(repeat (cons (sexp :tag "Form" nil)
1044                        face)))
1045
1046 (defcustom gnus-alter-header-function nil
1047   "Function called to allow alteration of article header structures.
1048 The function is called with one parameter, the article header vector,
1049 which it may alter in any way."
1050   :type '(choice (const :tag "None" nil)
1051                  function)
1052   :group 'gnus-summary)
1053
1054 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1055   "Variable that says which function should be used to decode a string with encoded words.")
1056
1057 (defcustom gnus-extra-headers '(To Newsgroups)
1058   "*Extra headers to parse."
1059   :version "21.1"
1060   :group 'gnus-summary
1061   :type '(repeat symbol))
1062
1063 (defcustom gnus-ignored-from-addresses
1064   (and user-mail-address  
1065        (not (string= user-mail-address ""))
1066        (regexp-quote user-mail-address))
1067   "*Regexp of From headers that may be suppressed in favor of To headers."
1068   :version "21.1"
1069   :group 'gnus-summary
1070   :type 'regexp)
1071
1072 (defcustom gnus-summary-to-prefix "-> "
1073   "*String prefixed to the To field in the summary line when
1074 using `gnus-ignored-from-addresses'."
1075   :version "22.1"
1076   :group 'gnus-summary
1077   :type 'string)
1078
1079 (defcustom gnus-summary-newsgroup-prefix "=> "
1080   "*String prefixed to the Newsgroup field in the summary
1081 line when using `gnus-ignored-from-addresses'."
1082   :version "22.1"
1083   :group 'gnus-summary
1084   :type 'string)
1085
1086 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1087   "List of charsets that should be ignored.
1088 When these charsets are used in the \"charset\" parameter, the
1089 default charset will be used instead."
1090   :version "21.1"
1091   :type '(repeat symbol)
1092   :group 'gnus-charset)
1093
1094 (gnus-define-group-parameter
1095  ignored-charsets
1096  :type list
1097  :function-document
1098  "Return the ignored charsets of GROUP."
1099  :variable gnus-group-ignored-charsets-alist
1100  :variable-default
1101  '(("alt\\.chinese\\.text" iso-8859-1))
1102  :variable-document
1103  "Alist of regexps (to match group names) and charsets that should be ignored.
1104 When these charsets are used in the \"charset\" parameter, the
1105 default charset will be used instead."
1106  :variable-group gnus-charset
1107  :variable-type '(repeat (cons (regexp :tag "Group")
1108                                (repeat symbol)))
1109  :parameter-type '(choice :tag "Ignored charsets"
1110                           :value nil
1111                           (repeat (symbol)))
1112  :parameter-document       "\
1113 List of charsets that should be ignored.
1114
1115 When these charsets are used in the \"charset\" parameter, the
1116 default charset will be used instead.")
1117
1118 (defcustom gnus-group-highlight-words-alist nil
1119   "Alist of group regexps and highlight regexps.
1120 This variable uses the same syntax as `gnus-emphasis-alist'."
1121   :version "21.1"
1122   :type '(repeat (cons (regexp :tag "Group")
1123                        (repeat (list (regexp :tag "Highlight regexp")
1124                                      (number :tag "Group for entire word" 0)
1125                                      (number :tag "Group for displayed part" 0)
1126                                      (symbol :tag "Face"
1127                                              gnus-emphasis-highlight-words)))))
1128   :group 'gnus-summary-visual)
1129
1130 (defcustom gnus-summary-show-article-charset-alist
1131   nil
1132   "Alist of number and charset.
1133 The article will be shown with the charset corresponding to the
1134 numbered argument.
1135 For example: ((1 . cn-gb-2312) (2 . big5))."
1136   :version "21.1"
1137   :type '(repeat (cons (number :tag "Argument" 1)
1138                        (symbol :tag "Charset")))
1139   :group 'gnus-charset)
1140
1141 (defcustom gnus-preserve-marks t
1142   "Whether marks are preserved when moving, copying and respooling messages."
1143   :version "21.1"
1144   :type 'boolean
1145   :group 'gnus-summary-marks)
1146
1147 (defcustom gnus-alter-articles-to-read-function nil
1148   "Function to be called to alter the list of articles to be selected."
1149   :type '(choice (const nil) function)
1150   :group 'gnus-summary)
1151
1152 (defcustom gnus-orphan-score nil
1153   "*All orphans get this score added.  Set in the score file."
1154   :group 'gnus-score-default
1155   :type '(choice (const nil)
1156                  integer))
1157
1158 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1159   "*A regexp to match MIME parts when saving multiple parts of a
1160 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1161 This regexp will be used by default when prompting the user for which
1162 type of files to save."
1163   :group 'gnus-summary
1164   :type 'regexp)
1165
1166 (defcustom gnus-read-all-available-headers nil
1167   "Whether Gnus should parse all headers made available to it.
1168 This is mostly relevant for slow back ends where the user may
1169 wish to widen the summary buffer to include all headers
1170 that were fetched.  Say, for nnultimate groups."
1171   :version "22.1"
1172   :group 'gnus-summary
1173   :type '(choice boolean regexp))
1174
1175 (defcustom gnus-summary-muttprint-program "muttprint"
1176   "Command (and optional arguments) used to run Muttprint."
1177   :version "22.1"
1178   :group 'gnus-summary
1179   :type 'string)
1180
1181 (defcustom gnus-article-loose-mime t
1182   "If non-nil, don't require MIME-Version header.
1183 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1184 supply the MIME-Version header or deliberately strip it from the mail.
1185 If non-nil (the default), Gnus will treat some articles as MIME
1186 even if the MIME-Version header is missing."
1187   :version "22.1"
1188   :type 'boolean
1189   :group 'gnus-article-mime)
1190
1191 (defcustom gnus-article-emulate-mime t
1192   "If non-nil, use MIME emulation for uuencode and the like.
1193 This means that Gnus will search message bodies for text that look
1194 like uuencoded bits, yEncoded bits, and so on, and present that using
1195 the normal Gnus MIME machinery."
1196   :version "22.1"
1197   :type 'boolean
1198   :group 'gnus-article-mime)
1199
1200 ;;; Internal variables
1201
1202 (defvar gnus-summary-display-cache nil)
1203 (defvar gnus-article-mime-handles nil)
1204 (defvar gnus-article-decoded-p nil)
1205 (defvar gnus-article-charset nil)
1206 (defvar gnus-article-ignored-charsets nil)
1207 (defvar gnus-scores-exclude-files nil)
1208 (defvar gnus-page-broken nil)
1209
1210 (defvar gnus-original-article nil)
1211 (defvar gnus-article-internal-prepare-hook nil)
1212 (defvar gnus-newsgroup-process-stack nil)
1213
1214 (defvar gnus-thread-indent-array nil)
1215 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1216 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1217   "Function called to sort the articles within a thread after it has been gathered together.")
1218
1219 (defvar gnus-summary-save-parts-type-history nil)
1220 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1221
1222 ;; Avoid highlighting in kill files.
1223 (defvar gnus-summary-inhibit-highlight nil)
1224 (defvar gnus-newsgroup-selected-overlay nil)
1225 (defvar gnus-inhibit-limiting nil)
1226 (defvar gnus-newsgroup-adaptive-score-file nil)
1227 (defvar gnus-current-score-file nil)
1228 (defvar gnus-current-move-group nil)
1229 (defvar gnus-current-copy-group nil)
1230 (defvar gnus-current-crosspost-group nil)
1231 (defvar gnus-newsgroup-display nil)
1232
1233 (defvar gnus-newsgroup-dependencies nil)
1234 (defvar gnus-newsgroup-adaptive nil)
1235 (defvar gnus-summary-display-article-function nil)
1236 (defvar gnus-summary-highlight-line-function nil
1237   "Function called after highlighting a summary line.")
1238
1239 (defvar gnus-summary-line-format-alist
1240   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1241     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1242     (?s gnus-tmp-subject-or-nil ?s)
1243     (?n gnus-tmp-name ?s)
1244     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1245         ?s)
1246     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1247             gnus-tmp-from) ?s)
1248     (?F gnus-tmp-from ?s)
1249     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1250     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1251     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1252     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1253     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1254     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1255     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1256     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1257     (?L gnus-tmp-lines ?s)
1258     (?O gnus-tmp-downloaded ?c)
1259     (?I gnus-tmp-indentation ?s)
1260     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1261     (?R gnus-tmp-replied ?c)
1262     (?\[ gnus-tmp-opening-bracket ?c)
1263     (?\] gnus-tmp-closing-bracket ?c)
1264     (?\> (make-string gnus-tmp-level ? ) ?s)
1265     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1266     (?i gnus-tmp-score ?d)
1267     (?z gnus-tmp-score-char ?c)
1268     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1269     (?U gnus-tmp-unread ?c)
1270     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1271         ?s)
1272     (?t (gnus-summary-number-of-articles-in-thread
1273          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1274         ?d)
1275     (?e (gnus-summary-number-of-articles-in-thread
1276          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1277         ?c)
1278     (?u gnus-tmp-user-defined ?s)
1279     (?P (gnus-pick-line-number) ?d)
1280     (?B gnus-tmp-thread-tree-header-string ?s)
1281     (user-date (gnus-user-date
1282                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1283   "An alist of format specifications that can appear in summary lines.
1284 These are paired with what variables they correspond with, along with
1285 the type of the variable (string, integer, character, etc).")
1286
1287 (defvar gnus-summary-dummy-line-format-alist
1288   `((?S gnus-tmp-subject ?s)
1289     (?N gnus-tmp-number ?d)
1290     (?u gnus-tmp-user-defined ?s)))
1291
1292 (defvar gnus-summary-mode-line-format-alist
1293   `((?G gnus-tmp-group-name ?s)
1294     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1295     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1296     (?A gnus-tmp-article-number ?d)
1297     (?Z gnus-tmp-unread-and-unselected ?s)
1298     (?V gnus-version ?s)
1299     (?U gnus-tmp-unread-and-unticked ?d)
1300     (?S gnus-tmp-subject ?s)
1301     (?e gnus-tmp-unselected ?d)
1302     (?u gnus-tmp-user-defined ?s)
1303     (?d (length gnus-newsgroup-dormant) ?d)
1304     (?t (length gnus-newsgroup-marked) ?d)
1305     (?h (length gnus-newsgroup-spam-marked) ?d)
1306     (?r (length gnus-newsgroup-reads) ?d)
1307     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1308     (?E gnus-newsgroup-expunged-tally ?d)
1309     (?s (gnus-current-score-file-nondirectory) ?s)))
1310
1311 (defvar gnus-last-search-regexp nil
1312   "Default regexp for article search command.")
1313
1314 (defvar gnus-last-shell-command nil
1315   "Default shell command on article.")
1316
1317 (defvar gnus-newsgroup-agentized nil
1318   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1319 (defvar gnus-newsgroup-begin nil)
1320 (defvar gnus-newsgroup-end nil)
1321 (defvar gnus-newsgroup-last-rmail nil)
1322 (defvar gnus-newsgroup-last-mail nil)
1323 (defvar gnus-newsgroup-last-folder nil)
1324 (defvar gnus-newsgroup-last-file nil)
1325 (defvar gnus-newsgroup-auto-expire nil)
1326 (defvar gnus-newsgroup-active nil)
1327
1328 (defvar gnus-newsgroup-data nil)
1329 (defvar gnus-newsgroup-data-reverse nil)
1330 (defvar gnus-newsgroup-limit nil)
1331 (defvar gnus-newsgroup-limits nil)
1332 (defvar gnus-summary-use-undownloaded-faces nil)
1333
1334 (defvar gnus-newsgroup-unreads nil
1335   "Sorted list of unread articles in the current newsgroup.")
1336
1337 (defvar gnus-newsgroup-unselected nil
1338   "Sorted list of unselected unread articles in the current newsgroup.")
1339
1340 (defvar gnus-newsgroup-reads nil
1341   "Alist of read articles and article marks in the current newsgroup.")
1342
1343 (defvar gnus-newsgroup-expunged-tally nil)
1344
1345 (defvar gnus-newsgroup-marked nil
1346   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1347
1348 (defvar gnus-newsgroup-spam-marked nil
1349   "List of ranges of articles that have been marked as spam.")
1350
1351 (defvar gnus-newsgroup-killed nil
1352   "List of ranges of articles that have been through the scoring process.")
1353
1354 (defvar gnus-newsgroup-cached nil
1355   "Sorted list of articles that come from the article cache.")
1356
1357 (defvar gnus-newsgroup-saved nil
1358   "List of articles that have been saved.")
1359
1360 (defvar gnus-newsgroup-kill-headers nil)
1361
1362 (defvar gnus-newsgroup-replied nil
1363   "List of articles that have been replied to in the current newsgroup.")
1364
1365 (defvar gnus-newsgroup-forwarded nil
1366   "List of articles that have been forwarded in the current newsgroup.")
1367
1368 (defvar gnus-newsgroup-recent nil
1369   "List of articles that have are recent in the current newsgroup.")
1370
1371 (defvar gnus-newsgroup-expirable nil
1372   "Sorted list of articles in the current newsgroup that can be expired.")
1373
1374 (defvar gnus-newsgroup-processable nil
1375   "List of articles in the current newsgroup that can be processed.")
1376
1377 (defvar gnus-newsgroup-downloadable nil
1378   "Sorted list of articles in the current newsgroup that can be processed.")
1379
1380 (defvar gnus-newsgroup-unfetched nil
1381   "Sorted list of articles in the current newsgroup whose headers have
1382 not been fetched into the agent.
1383
1384 This list will always be a subset of gnus-newsgroup-undownloaded.")
1385
1386 (defvar gnus-newsgroup-undownloaded nil
1387   "List of articles in the current newsgroup that haven't been downloaded.")
1388
1389 (defvar gnus-newsgroup-unsendable nil
1390   "List of articles in the current newsgroup that won't be sent.")
1391
1392 (defvar gnus-newsgroup-bookmarks nil
1393   "List of articles in the current newsgroup that have bookmarks.")
1394
1395 (defvar gnus-newsgroup-dormant nil
1396   "Sorted list of dormant articles in the current newsgroup.")
1397
1398 (defvar gnus-newsgroup-unseen nil
1399   "List of unseen articles in the current newsgroup.")
1400
1401 (defvar gnus-newsgroup-seen nil
1402   "Range of seen articles in the current newsgroup.")
1403
1404 (defvar gnus-newsgroup-articles nil
1405   "List of articles in the current newsgroup.")
1406
1407 (defvar gnus-newsgroup-scored nil
1408   "List of scored articles in the current newsgroup.")
1409
1410 (defvar gnus-newsgroup-headers nil
1411   "List of article headers in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-threads nil)
1414
1415 (defvar gnus-newsgroup-prepared nil
1416   "Whether the current group has been prepared properly.")
1417
1418 (defvar gnus-newsgroup-ancient nil
1419   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1420
1421 (defvar gnus-newsgroup-sparse nil)
1422
1423 (defvar gnus-current-article nil)
1424 (defvar gnus-article-current nil)
1425 (defvar gnus-current-headers nil)
1426 (defvar gnus-have-all-headers nil)
1427 (defvar gnus-last-article nil)
1428 (defvar gnus-newsgroup-history nil)
1429 (defvar gnus-newsgroup-charset nil)
1430 (defvar gnus-newsgroup-ephemeral-charset nil)
1431 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1432
1433 (defvar gnus-article-before-search nil)
1434
1435 (defvar gnus-summary-local-variables
1436   '(gnus-newsgroup-name
1437     gnus-newsgroup-begin gnus-newsgroup-end
1438     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1439     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1440     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1441     gnus-newsgroup-unselected gnus-newsgroup-marked
1442     gnus-newsgroup-spam-marked
1443     gnus-newsgroup-reads gnus-newsgroup-saved
1444     gnus-newsgroup-replied gnus-newsgroup-forwarded
1445     gnus-newsgroup-recent
1446     gnus-newsgroup-expirable
1447     gnus-newsgroup-processable gnus-newsgroup-killed
1448     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1449     gnus-newsgroup-unfetched
1450     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1451     gnus-newsgroup-seen gnus-newsgroup-articles
1452     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1453     gnus-newsgroup-headers gnus-newsgroup-threads
1454     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1455     gnus-current-article gnus-current-headers gnus-have-all-headers
1456     gnus-last-article gnus-article-internal-prepare-hook
1457     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1458     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1459     gnus-thread-expunge-below
1460     gnus-score-alist gnus-current-score-file
1461     (gnus-summary-expunge-below . global)
1462     (gnus-summary-mark-below . global)
1463     (gnus-orphan-score . global)
1464     gnus-newsgroup-active gnus-scores-exclude-files
1465     gnus-newsgroup-history gnus-newsgroup-ancient
1466     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1467     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1468     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1469     (gnus-newsgroup-expunged-tally . 0)
1470     gnus-cache-removable-articles gnus-newsgroup-cached
1471     gnus-newsgroup-data gnus-newsgroup-data-reverse
1472     gnus-newsgroup-limit gnus-newsgroup-limits
1473     gnus-newsgroup-charset gnus-newsgroup-display
1474     gnus-summary-use-undownloaded-faces)
1475   "Variables that are buffer-local to the summary buffers.")
1476
1477 (defvar gnus-newsgroup-variables nil
1478   "A list of variables that have separate values in different newsgroups.
1479 A list of newsgroup (summary buffer) local variables, or cons of
1480 variables and their default expressions to be evalled (when the default
1481 values are not nil), that should be made global while the summary buffer
1482 is active.
1483
1484 Note: The default expressions will be evaluated (using function `eval')
1485 before assignment to the local variable rather than just assigned to it.
1486 If the default expression is the symbol `global', that symbol will not
1487 be evaluated but the global value of the local variable will be used
1488 instead.
1489
1490 These variables can be used to set variables in the group parameters
1491 while still allowing them to affect operations done in other buffers.
1492 For example:
1493
1494 \(setq gnus-newsgroup-variables
1495      '(message-use-followup-to
1496        (gnus-visible-headers .
1497          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1498 ")
1499
1500 ;; Byte-compiler warning.
1501 (eval-when-compile
1502   ;; Bind features so that require will believe that gnus-sum has
1503   ;; already been loaded (avoids infinite recursion)
1504   (let ((features (cons 'gnus-sum features)))
1505     ;; Several of the declarations in gnus-sum are needed to load the
1506     ;; following files. Right now, these definitions have been
1507     ;; compiled but not defined (evaluated).  We could either do a
1508     ;; eval-and-compile about all of the declarations or evaluate the
1509     ;; source file.
1510     (if (boundp 'gnus-newsgroup-variables)
1511         nil
1512       (load "gnus-sum.el" t t t))
1513     (require 'gnus)
1514     (require 'gnus-art)))
1515
1516 ;; MIME stuff.
1517
1518 (defvar gnus-decode-encoded-word-methods
1519   '(mail-decode-encoded-word-string)
1520   "List of methods used to decode encoded words.
1521
1522 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1523 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1524 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1525 whose names match REGEXP.
1526
1527 For example:
1528 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1529  mail-decode-encoded-word-string
1530  (\"chinese\" . rfc1843-decode-string))")
1531
1532 (defvar gnus-decode-encoded-word-methods-cache nil)
1533
1534 (defun gnus-multi-decode-encoded-word-string (string)
1535   "Apply the functions from `gnus-encoded-word-methods' that match."
1536   (unless (and gnus-decode-encoded-word-methods-cache
1537                (eq gnus-newsgroup-name
1538                    (car gnus-decode-encoded-word-methods-cache)))
1539     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1540     (mapcar (lambda (x)
1541               (if (symbolp x)
1542                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1543                 (if (and gnus-newsgroup-name
1544                          (string-match (car x) gnus-newsgroup-name))
1545                     (nconc gnus-decode-encoded-word-methods-cache
1546                            (list (cdr x))))))
1547             gnus-decode-encoded-word-methods))
1548   (let ((xlist gnus-decode-encoded-word-methods-cache))
1549     (pop xlist)
1550     (while xlist
1551       (setq string (funcall (pop xlist) string))))
1552   string)
1553
1554 ;; Subject simplification.
1555
1556 (defun gnus-simplify-whitespace (str)
1557   "Remove excessive whitespace from STR."
1558   ;; Multiple spaces.
1559   (while (string-match "[ \t][ \t]+" str)
1560     (setq str (concat (substring str 0 (match-beginning 0))
1561                         " "
1562                         (substring str (match-end 0)))))
1563   ;; Leading spaces.
1564   (when (string-match "^[ \t]+" str)
1565     (setq str (substring str (match-end 0))))
1566   ;; Trailing spaces.
1567   (when (string-match "[ \t]+$" str)
1568     (setq str (substring str 0 (match-beginning 0))))
1569   str)
1570
1571 (defun gnus-simplify-all-whitespace (str)
1572   "Remove all whitespace from STR."
1573   (while (string-match "[ \t\n]+" str)
1574     (setq str (replace-match "" nil nil str)))
1575   str)
1576
1577 (defsubst gnus-simplify-subject-re (subject)
1578   "Remove \"Re:\" from subject lines."
1579   (if (string-match message-subject-re-regexp subject)
1580       (substring subject (match-end 0))
1581     subject))
1582
1583 (defun gnus-simplify-subject (subject &optional re-only)
1584   "Remove `Re:' and words in parentheses.
1585 If RE-ONLY is non-nil, strip leading `Re:'s only."
1586   (let ((case-fold-search t))           ;Ignore case.
1587     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1588     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1589       (setq subject (substring subject (match-end 0))))
1590     ;; Remove uninteresting prefixes.
1591     (when (and (not re-only)
1592                gnus-simplify-ignored-prefixes
1593                (string-match gnus-simplify-ignored-prefixes subject))
1594       (setq subject (substring subject (match-end 0))))
1595     ;; Remove words in parentheses from end.
1596     (unless re-only
1597       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1598         (setq subject (substring subject 0 (match-beginning 0)))))
1599     ;; Return subject string.
1600     subject))
1601
1602 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1603 ;; all whitespace.
1604 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1605   (goto-char (point-min))
1606   (while (re-search-forward regexp nil t)
1607     (replace-match (or newtext ""))))
1608
1609 (defun gnus-simplify-buffer-fuzzy ()
1610   "Simplify string in the buffer fuzzily.
1611 The string in the accessible portion of the current buffer is simplified.
1612 It is assumed to be a single-line subject.
1613 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1614 matter is removed.  Additional things can be deleted by setting
1615 `gnus-simplify-subject-fuzzy-regexp'."
1616   (let ((case-fold-search t)
1617         (modified-tick))
1618     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1619
1620     (while (not (eq modified-tick (buffer-modified-tick)))
1621       (setq modified-tick (buffer-modified-tick))
1622       (cond
1623        ((listp gnus-simplify-subject-fuzzy-regexp)
1624         (mapcar 'gnus-simplify-buffer-fuzzy-step
1625                 gnus-simplify-subject-fuzzy-regexp))
1626        (gnus-simplify-subject-fuzzy-regexp
1627         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1628       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1629       (gnus-simplify-buffer-fuzzy-step
1630        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1631       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1632
1633     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1634     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1635     (gnus-simplify-buffer-fuzzy-step " $")
1636     (gnus-simplify-buffer-fuzzy-step "^ +")))
1637
1638 (defun gnus-simplify-subject-fuzzy (subject)
1639   "Simplify a subject string fuzzily.
1640 See `gnus-simplify-buffer-fuzzy' for details."
1641   (save-excursion
1642     (gnus-set-work-buffer)
1643     (let ((case-fold-search t))
1644       ;; Remove uninteresting prefixes.
1645       (when (and gnus-simplify-ignored-prefixes
1646                  (string-match gnus-simplify-ignored-prefixes subject))
1647         (setq subject (substring subject (match-end 0))))
1648       (insert subject)
1649       (inline (gnus-simplify-buffer-fuzzy))
1650       (buffer-string))))
1651
1652 (defsubst gnus-simplify-subject-fully (subject)
1653   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1654   (cond
1655    (gnus-simplify-subject-functions
1656     (gnus-map-function gnus-simplify-subject-functions subject))
1657    ((null gnus-summary-gather-subject-limit)
1658     (gnus-simplify-subject-re subject))
1659    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1660     (gnus-simplify-subject-fuzzy subject))
1661    ((numberp gnus-summary-gather-subject-limit)
1662     (gnus-limit-string (gnus-simplify-subject-re subject)
1663                        gnus-summary-gather-subject-limit))
1664    (t
1665     subject)))
1666
1667 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1668   "Check whether two subjects are equal.
1669 If optional argument SIMPLE-FIRST is t, first argument is already
1670 simplified."
1671   (cond
1672    ((null simple-first)
1673     (equal (gnus-simplify-subject-fully s1)
1674            (gnus-simplify-subject-fully s2)))
1675    (t
1676     (equal s1
1677            (gnus-simplify-subject-fully s2)))))
1678
1679 (defun gnus-summary-bubble-group ()
1680   "Increase the score of the current group.
1681 This is a handy function to add to `gnus-summary-exit-hook' to
1682 increase the score of each group you read."
1683   (gnus-group-add-score gnus-newsgroup-name))
1684
1685 \f
1686 ;;;
1687 ;;; Gnus summary mode
1688 ;;;
1689
1690 (put 'gnus-summary-mode 'mode-class 'special)
1691
1692 (defvar gnus-article-commands-menu)
1693
1694 ;; Non-orthogonal keys
1695
1696 (gnus-define-keys gnus-summary-mode-map
1697   " " gnus-summary-next-page
1698   "\177" gnus-summary-prev-page
1699   [delete] gnus-summary-prev-page
1700   [backspace] gnus-summary-prev-page
1701   "\r" gnus-summary-scroll-up
1702   "\M-\r" gnus-summary-scroll-down
1703   "n" gnus-summary-next-unread-article
1704   "p" gnus-summary-prev-unread-article
1705   "N" gnus-summary-next-article
1706   "P" gnus-summary-prev-article
1707   "\M-\C-n" gnus-summary-next-same-subject
1708   "\M-\C-p" gnus-summary-prev-same-subject
1709   "\M-n" gnus-summary-next-unread-subject
1710   "\M-p" gnus-summary-prev-unread-subject
1711   "." gnus-summary-first-unread-article
1712   "," gnus-summary-best-unread-article
1713   "\M-s" gnus-summary-search-article-forward
1714   "\M-r" gnus-summary-search-article-backward
1715   "<" gnus-summary-beginning-of-article
1716   ">" gnus-summary-end-of-article
1717   "j" gnus-summary-goto-article
1718   "^" gnus-summary-refer-parent-article
1719   "\M-^" gnus-summary-refer-article
1720   "u" gnus-summary-tick-article-forward
1721   "!" gnus-summary-tick-article-forward
1722   "U" gnus-summary-tick-article-backward
1723   "d" gnus-summary-mark-as-read-forward
1724   "D" gnus-summary-mark-as-read-backward
1725   "E" gnus-summary-mark-as-expirable
1726   "\M-u" gnus-summary-clear-mark-forward
1727   "\M-U" gnus-summary-clear-mark-backward
1728   "k" gnus-summary-kill-same-subject-and-select
1729   "\C-k" gnus-summary-kill-same-subject
1730   "\M-\C-k" gnus-summary-kill-thread
1731   "\M-\C-l" gnus-summary-lower-thread
1732   "e" gnus-summary-edit-article
1733   "#" gnus-summary-mark-as-processable
1734   "\M-#" gnus-summary-unmark-as-processable
1735   "\M-\C-t" gnus-summary-toggle-threads
1736   "\M-\C-s" gnus-summary-show-thread
1737   "\M-\C-h" gnus-summary-hide-thread
1738   "\M-\C-f" gnus-summary-next-thread
1739   "\M-\C-b" gnus-summary-prev-thread
1740   [(meta down)] gnus-summary-next-thread
1741   [(meta up)] gnus-summary-prev-thread
1742   "\M-\C-u" gnus-summary-up-thread
1743   "\M-\C-d" gnus-summary-down-thread
1744   "&" gnus-summary-execute-command
1745   "c" gnus-summary-catchup-and-exit
1746   "\C-w" gnus-summary-mark-region-as-read
1747   "\C-t" gnus-summary-toggle-truncation
1748   "?" gnus-summary-mark-as-dormant
1749   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1750   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1751   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1752   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1753   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1754   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1755   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1756   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1757   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1758   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1759   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1760   "=" gnus-summary-expand-window
1761   "\C-x\C-s" gnus-summary-reselect-current-group
1762   "\M-g" gnus-summary-rescan-group
1763   "w" gnus-summary-stop-page-breaking
1764   "\C-c\C-r" gnus-summary-caesar-message
1765   "f" gnus-summary-followup
1766   "F" gnus-summary-followup-with-original
1767   "C" gnus-summary-cancel-article
1768   "r" gnus-summary-reply
1769   "R" gnus-summary-reply-with-original
1770   "\C-c\C-f" gnus-summary-mail-forward
1771   "o" gnus-summary-save-article
1772   "\C-o" gnus-summary-save-article-mail
1773   "|" gnus-summary-pipe-output
1774   "\M-k" gnus-summary-edit-local-kill
1775   "\M-K" gnus-summary-edit-global-kill
1776   ;; "V" gnus-version
1777   "\C-c\C-d" gnus-summary-describe-group
1778   "q" gnus-summary-exit
1779   "Q" gnus-summary-exit-no-update
1780   "\C-c\C-i" gnus-info-find-node
1781   gnus-mouse-2 gnus-mouse-pick-article
1782   [follow-link] mouse-face
1783   "m" gnus-summary-mail-other-window
1784   "a" gnus-summary-post-news
1785   "i" gnus-summary-news-other-window
1786   "x" gnus-summary-limit-to-unread
1787   "s" gnus-summary-isearch-article
1788   "t" gnus-summary-toggle-header
1789   "g" gnus-summary-show-article
1790   "l" gnus-summary-goto-last-article
1791   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1792   "\C-d" gnus-summary-enter-digest-group
1793   "\M-\C-d" gnus-summary-read-document
1794   "\M-\C-e" gnus-summary-edit-parameters
1795   "\M-\C-a" gnus-summary-customize-parameters
1796   "\C-c\C-b" gnus-bug
1797   "*" gnus-cache-enter-article
1798   "\M-*" gnus-cache-remove-article
1799   "\M-&" gnus-summary-universal-argument
1800   "\C-l" gnus-recenter
1801   "I" gnus-summary-increase-score
1802   "L" gnus-summary-lower-score
1803   "\M-i" gnus-symbolic-argument
1804   "h" gnus-summary-select-article-buffer
1805
1806   "b" gnus-article-view-part
1807   "\M-t" gnus-summary-toggle-display-buttonized
1808
1809   "V" gnus-summary-score-map
1810   "X" gnus-uu-extract-map
1811   "S" gnus-summary-send-map)
1812
1813 ;; Sort of orthogonal keymap
1814 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1815   "t" gnus-summary-tick-article-forward
1816   "!" gnus-summary-tick-article-forward
1817   "d" gnus-summary-mark-as-read-forward
1818   "r" gnus-summary-mark-as-read-forward
1819   "c" gnus-summary-clear-mark-forward
1820   " " gnus-summary-clear-mark-forward
1821   "e" gnus-summary-mark-as-expirable
1822   "x" gnus-summary-mark-as-expirable
1823   "?" gnus-summary-mark-as-dormant
1824   "b" gnus-summary-set-bookmark
1825   "B" gnus-summary-remove-bookmark
1826   "#" gnus-summary-mark-as-processable
1827   "\M-#" gnus-summary-unmark-as-processable
1828   "S" gnus-summary-limit-include-expunged
1829   "C" gnus-summary-catchup
1830   "H" gnus-summary-catchup-to-here
1831   "h" gnus-summary-catchup-from-here
1832   "\C-c" gnus-summary-catchup-all
1833   "k" gnus-summary-kill-same-subject-and-select
1834   "K" gnus-summary-kill-same-subject
1835   "P" gnus-uu-mark-map)
1836
1837 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1838   "c" gnus-summary-clear-above
1839   "u" gnus-summary-tick-above
1840   "m" gnus-summary-mark-above
1841   "k" gnus-summary-kill-below)
1842
1843 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1844   "/" gnus-summary-limit-to-subject
1845   "n" gnus-summary-limit-to-articles
1846   "w" gnus-summary-pop-limit
1847   "s" gnus-summary-limit-to-subject
1848   "a" gnus-summary-limit-to-author
1849   "u" gnus-summary-limit-to-unread
1850   "m" gnus-summary-limit-to-marks
1851   "M" gnus-summary-limit-exclude-marks
1852   "v" gnus-summary-limit-to-score
1853   "*" gnus-summary-limit-include-cached
1854   "D" gnus-summary-limit-include-dormant
1855   "T" gnus-summary-limit-include-thread
1856   "d" gnus-summary-limit-exclude-dormant
1857   "t" gnus-summary-limit-to-age
1858   "." gnus-summary-limit-to-unseen
1859   "x" gnus-summary-limit-to-extra
1860   "p" gnus-summary-limit-to-display-predicate
1861   "E" gnus-summary-limit-include-expunged
1862   "c" gnus-summary-limit-exclude-childless-dormant
1863   "C" gnus-summary-limit-mark-excluded-as-read
1864   "o" gnus-summary-insert-old-articles
1865   "N" gnus-summary-insert-new-articles
1866   "r" gnus-summary-limit-to-replied
1867   "R" gnus-summary-limit-to-recipient)
1868
1869 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1870   "n" gnus-summary-next-unread-article
1871   "p" gnus-summary-prev-unread-article
1872   "N" gnus-summary-next-article
1873   "P" gnus-summary-prev-article
1874   "\C-n" gnus-summary-next-same-subject
1875   "\C-p" gnus-summary-prev-same-subject
1876   "\M-n" gnus-summary-next-unread-subject
1877   "\M-p" gnus-summary-prev-unread-subject
1878   "f" gnus-summary-first-unread-article
1879   "b" gnus-summary-best-unread-article
1880   "j" gnus-summary-goto-article
1881   "g" gnus-summary-goto-subject
1882   "l" gnus-summary-goto-last-article
1883   "o" gnus-summary-pop-article)
1884
1885 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1886   "k" gnus-summary-kill-thread
1887   "l" gnus-summary-lower-thread
1888   "i" gnus-summary-raise-thread
1889   "T" gnus-summary-toggle-threads
1890   "t" gnus-summary-rethread-current
1891   "^" gnus-summary-reparent-thread
1892   "s" gnus-summary-show-thread
1893   "S" gnus-summary-show-all-threads
1894   "h" gnus-summary-hide-thread
1895   "H" gnus-summary-hide-all-threads
1896   "n" gnus-summary-next-thread
1897   "p" gnus-summary-prev-thread
1898   "u" gnus-summary-up-thread
1899   "o" gnus-summary-top-thread
1900   "d" gnus-summary-down-thread
1901   "#" gnus-uu-mark-thread
1902   "\M-#" gnus-uu-unmark-thread)
1903
1904 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1905   "g" gnus-summary-prepare
1906   "c" gnus-summary-insert-cached-articles
1907   "d" gnus-summary-insert-dormant-articles)
1908
1909 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1910   "c" gnus-summary-catchup-and-exit
1911   "C" gnus-summary-catchup-all-and-exit
1912   "E" gnus-summary-exit-no-update
1913   "Q" gnus-summary-exit
1914   "Z" gnus-summary-exit
1915   "n" gnus-summary-catchup-and-goto-next-group
1916   "p" gnus-summary-catchup-and-goto-prev-group
1917   "R" gnus-summary-reselect-current-group
1918   "G" gnus-summary-rescan-group
1919   "N" gnus-summary-next-group
1920   "s" gnus-summary-save-newsrc
1921   "P" gnus-summary-prev-group)
1922
1923 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1924   " " gnus-summary-next-page
1925   "n" gnus-summary-next-page
1926   "\177" gnus-summary-prev-page
1927   [delete] gnus-summary-prev-page
1928   "p" gnus-summary-prev-page
1929   "\r" gnus-summary-scroll-up
1930   "\M-\r" gnus-summary-scroll-down
1931   "<" gnus-summary-beginning-of-article
1932   ">" gnus-summary-end-of-article
1933   "b" gnus-summary-beginning-of-article
1934   "e" gnus-summary-end-of-article
1935   "^" gnus-summary-refer-parent-article
1936   "r" gnus-summary-refer-parent-article
1937   "D" gnus-summary-enter-digest-group
1938   "R" gnus-summary-refer-references
1939   "T" gnus-summary-refer-thread
1940   "g" gnus-summary-show-article
1941   "s" gnus-summary-isearch-article
1942   "P" gnus-summary-print-article
1943   "M" gnus-mailing-list-insinuate
1944   "t" gnus-article-babel)
1945
1946 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1947   "b" gnus-article-add-buttons
1948   "B" gnus-article-add-buttons-to-head
1949   "o" gnus-article-treat-overstrike
1950   "e" gnus-article-emphasize
1951   "w" gnus-article-fill-cited-article
1952   "Q" gnus-article-fill-long-lines
1953   "C" gnus-article-capitalize-sentences
1954   "c" gnus-article-remove-cr
1955   "q" gnus-article-de-quoted-unreadable
1956   "6" gnus-article-de-base64-unreadable
1957   "Z" gnus-article-decode-HZ
1958   "A" gnus-article-treat-ansi-sequences
1959   "h" gnus-article-wash-html
1960   "u" gnus-article-unsplit-urls
1961   "s" gnus-summary-force-verify-and-decrypt
1962   "f" gnus-article-display-x-face
1963   "l" gnus-summary-stop-page-breaking
1964   "r" gnus-summary-caesar-message
1965   "m" gnus-summary-morse-message
1966   "t" gnus-summary-toggle-header
1967   "g" gnus-treat-smiley
1968   "v" gnus-summary-verbose-headers
1969   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1970   "p" gnus-article-verify-x-pgp-sig
1971   "d" gnus-article-treat-dumbquotes
1972   "i" gnus-summary-idna-message)
1973
1974 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1975   ;; mnemonic: deuglif*Y*
1976   "u" gnus-article-outlook-unwrap-lines
1977   "a" gnus-article-outlook-repair-attribution
1978   "c" gnus-article-outlook-rearrange-citation
1979   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1980
1981 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1982   "a" gnus-article-hide
1983   "h" gnus-article-hide-headers
1984   "b" gnus-article-hide-boring-headers
1985   "s" gnus-article-hide-signature
1986   "c" gnus-article-hide-citation
1987   "C" gnus-article-hide-citation-in-followups
1988   "l" gnus-article-hide-list-identifiers
1989   "B" gnus-article-strip-banner
1990   "P" gnus-article-hide-pem
1991   "\C-c" gnus-article-hide-citation-maybe)
1992
1993 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1994   "a" gnus-article-highlight
1995   "h" gnus-article-highlight-headers
1996   "c" gnus-article-highlight-citation
1997   "s" gnus-article-highlight-signature)
1998
1999 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2000   "f" gnus-article-treat-fold-headers
2001   "u" gnus-article-treat-unfold-headers
2002   "n" gnus-article-treat-fold-newsgroups)
2003
2004 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2005   "x" gnus-article-display-x-face
2006   "d" gnus-article-display-face
2007   "s" gnus-treat-smiley
2008   "D" gnus-article-remove-images
2009   "f" gnus-treat-from-picon
2010   "m" gnus-treat-mail-picon
2011   "n" gnus-treat-newsgroups-picon)
2012
2013 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2014   "w" gnus-article-decode-mime-words
2015   "c" gnus-article-decode-charset
2016   "v" gnus-mime-view-all-parts
2017   "b" gnus-article-view-part)
2018
2019 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2020   "z" gnus-article-date-ut
2021   "u" gnus-article-date-ut
2022   "l" gnus-article-date-local
2023   "p" gnus-article-date-english
2024   "e" gnus-article-date-lapsed
2025   "o" gnus-article-date-original
2026   "i" gnus-article-date-iso8601
2027   "s" gnus-article-date-user)
2028
2029 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2030   "t" gnus-article-remove-trailing-blank-lines
2031   "l" gnus-article-strip-leading-blank-lines
2032   "m" gnus-article-strip-multiple-blank-lines
2033   "a" gnus-article-strip-blank-lines
2034   "A" gnus-article-strip-all-blank-lines
2035   "s" gnus-article-strip-leading-space
2036   "e" gnus-article-strip-trailing-space
2037   "w" gnus-article-remove-leading-whitespace)
2038
2039 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2040   "v" gnus-version
2041   "f" gnus-summary-fetch-faq
2042   "d" gnus-summary-describe-group
2043   "h" gnus-summary-describe-briefly
2044   "i" gnus-info-find-node
2045   "c" gnus-group-fetch-charter
2046   "C" gnus-group-fetch-control)
2047
2048 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2049   "e" gnus-summary-expire-articles
2050   "\M-\C-e" gnus-summary-expire-articles-now
2051   "\177" gnus-summary-delete-article
2052   [delete] gnus-summary-delete-article
2053   [backspace] gnus-summary-delete-article
2054   "m" gnus-summary-move-article
2055   "r" gnus-summary-respool-article
2056   "w" gnus-summary-edit-article
2057   "c" gnus-summary-copy-article
2058   "B" gnus-summary-crosspost-article
2059   "q" gnus-summary-respool-query
2060   "t" gnus-summary-respool-trace
2061   "i" gnus-summary-import-article
2062   "I" gnus-summary-create-article
2063   "p" gnus-summary-article-posted-p)
2064
2065 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2066   "o" gnus-summary-save-article
2067   "m" gnus-summary-save-article-mail
2068   "F" gnus-summary-write-article-file
2069   "r" gnus-summary-save-article-rmail
2070   "f" gnus-summary-save-article-file
2071   "b" gnus-summary-save-article-body-file
2072   "h" gnus-summary-save-article-folder
2073   "v" gnus-summary-save-article-vm
2074   "p" gnus-summary-pipe-output
2075   "P" gnus-summary-muttprint
2076   "s" gnus-soup-add-article)
2077
2078 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2079   "b" gnus-summary-display-buttonized
2080   "m" gnus-summary-repair-multipart
2081   "v" gnus-article-view-part
2082   "o" gnus-article-save-part
2083   "O" gnus-article-save-part-and-strip
2084   "r" gnus-article-replace-part
2085   "d" gnus-article-delete-part
2086   "j" gnus-article-jump-to-part
2087   "c" gnus-article-copy-part
2088   "C" gnus-article-view-part-as-charset
2089   "e" gnus-article-view-part-externally
2090   "E" gnus-article-encrypt-body
2091   "i" gnus-article-inline-part
2092   "|" gnus-article-pipe-part)
2093
2094 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2095   "p" gnus-summary-mark-as-processable
2096   "u" gnus-summary-unmark-as-processable
2097   "U" gnus-summary-unmark-all-processable
2098   "v" gnus-uu-mark-over
2099   "s" gnus-uu-mark-series
2100   "r" gnus-uu-mark-region
2101   "g" gnus-uu-unmark-region
2102   "R" gnus-uu-mark-by-regexp
2103   "G" gnus-uu-unmark-by-regexp
2104   "t" gnus-uu-mark-thread
2105   "T" gnus-uu-unmark-thread
2106   "a" gnus-uu-mark-all
2107   "b" gnus-uu-mark-buffer
2108   "S" gnus-uu-mark-sparse
2109   "k" gnus-summary-kill-process-mark
2110   "y" gnus-summary-yank-process-mark
2111   "w" gnus-summary-save-process-mark
2112   "i" gnus-uu-invert-processable)
2113
2114 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2115   ;;"x" gnus-uu-extract-any
2116   "m" gnus-summary-save-parts
2117   "u" gnus-uu-decode-uu
2118   "U" gnus-uu-decode-uu-and-save
2119   "s" gnus-uu-decode-unshar
2120   "S" gnus-uu-decode-unshar-and-save
2121   "o" gnus-uu-decode-save
2122   "O" gnus-uu-decode-save
2123   "b" gnus-uu-decode-binhex
2124   "B" gnus-uu-decode-binhex
2125   "p" gnus-uu-decode-postscript
2126   "P" gnus-uu-decode-postscript-and-save)
2127
2128 (gnus-define-keys
2129     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2130   "u" gnus-uu-decode-uu-view
2131   "U" gnus-uu-decode-uu-and-save-view
2132   "s" gnus-uu-decode-unshar-view
2133   "S" gnus-uu-decode-unshar-and-save-view
2134   "o" gnus-uu-decode-save-view
2135   "O" gnus-uu-decode-save-view
2136   "b" gnus-uu-decode-binhex-view
2137   "B" gnus-uu-decode-binhex-view
2138   "p" gnus-uu-decode-postscript-view
2139   "P" gnus-uu-decode-postscript-and-save-view)
2140
2141 (defvar gnus-article-post-menu nil)
2142
2143 (defconst gnus-summary-menu-maxlen 20)
2144
2145 (defun gnus-summary-menu-split (menu)
2146   ;; If we have lots of elements, divide them into groups of 20
2147   ;; and make a pane (or submenu) for each one.
2148   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2149       (let ((menu menu) sublists next
2150             (i 1))
2151         (while menu
2152           ;; Pull off the next gnus-summary-menu-maxlen elements
2153           ;; and make them the next element of sublist.
2154           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2155           (if next
2156               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2157                       nil))
2158           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2159                                              (aref (car (last menu)) 0)) menu)
2160                                sublists))
2161           (setq i (1+ i))
2162           (setq menu next))
2163         (nreverse sublists))
2164     ;; Few elements--put them all in one pane.
2165     menu))
2166
2167 (defun gnus-summary-make-menu-bar ()
2168   (gnus-turn-off-edit-menu 'summary)
2169
2170   (unless (boundp 'gnus-summary-misc-menu)
2171
2172     (easy-menu-define
2173       gnus-summary-kill-menu gnus-summary-mode-map ""
2174       (cons
2175        "Score"
2176        (nconc
2177         (list
2178          ["Customize" gnus-score-customize t])
2179         (gnus-make-score-map 'increase)
2180         (gnus-make-score-map 'lower)
2181         '(("Mark"
2182            ["Kill below" gnus-summary-kill-below t]
2183            ["Mark above" gnus-summary-mark-above t]
2184            ["Tick above" gnus-summary-tick-above t]
2185            ["Clear above" gnus-summary-clear-above t])
2186           ["Current score" gnus-summary-current-score t]
2187           ["Set score" gnus-summary-set-score t]
2188           ["Switch current score file..." gnus-score-change-score-file t]
2189           ["Set mark below..." gnus-score-set-mark-below t]
2190           ["Set expunge below..." gnus-score-set-expunge-below t]
2191           ["Edit current score file" gnus-score-edit-current-scores t]
2192           ["Edit score file" gnus-score-edit-file t]
2193           ["Trace score" gnus-score-find-trace t]
2194           ["Find words" gnus-score-find-favourite-words t]
2195           ["Rescore buffer" gnus-summary-rescore t]
2196           ["Increase score..." gnus-summary-increase-score t]
2197           ["Lower score..." gnus-summary-lower-score t]))))
2198
2199     ;; Define both the Article menu in the summary buffer and the
2200     ;; equivalent Commands menu in the article buffer here for
2201     ;; consistency.
2202     (let ((innards
2203            `(("Hide"
2204               ["All" gnus-article-hide t]
2205               ["Headers" gnus-article-hide-headers t]
2206               ["Signature" gnus-article-hide-signature t]
2207               ["Citation" gnus-article-hide-citation t]
2208               ["List identifiers" gnus-article-hide-list-identifiers t]
2209               ["Banner" gnus-article-strip-banner t]
2210               ["Boring headers" gnus-article-hide-boring-headers t])
2211              ("Highlight"
2212               ["All" gnus-article-highlight t]
2213               ["Headers" gnus-article-highlight-headers t]
2214               ["Signature" gnus-article-highlight-signature t]
2215               ["Citation" gnus-article-highlight-citation t])
2216              ("MIME"
2217               ["Words" gnus-article-decode-mime-words t]
2218               ["Charset" gnus-article-decode-charset t]
2219               ["QP" gnus-article-de-quoted-unreadable t]
2220               ["Base64" gnus-article-de-base64-unreadable t]
2221               ["View MIME buttons" gnus-summary-display-buttonized t]
2222               ["View all" gnus-mime-view-all-parts t]
2223               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2224               ["Encrypt body" gnus-article-encrypt-body
2225                :active (not (gnus-group-read-only-p))
2226                ,@(if (featurep 'xemacs) nil
2227                    '(:help "Encrypt the message body on disk"))]
2228               ["Extract all parts..." gnus-summary-save-parts t]
2229               ("Multipart"
2230                ["Repair multipart" gnus-summary-repair-multipart t]
2231                ["Pipe part..." gnus-article-pipe-part t]
2232                ["Inline part" gnus-article-inline-part t]
2233                ["Encrypt body" gnus-article-encrypt-body
2234                 :active (not (gnus-group-read-only-p))
2235                ,@(if (featurep 'xemacs) nil
2236                    '(:help "Encrypt the message body on disk"))]
2237                ["View part externally" gnus-article-view-part-externally t]
2238                ["View part with charset..." gnus-article-view-part-as-charset t]
2239                ["Copy part" gnus-article-copy-part t]
2240                ["Save part..." gnus-article-save-part t]
2241                ["View part" gnus-article-view-part t]))
2242              ("Date"
2243               ["Local" gnus-article-date-local t]
2244               ["ISO8601" gnus-article-date-iso8601 t]
2245               ["UT" gnus-article-date-ut t]
2246               ["Original" gnus-article-date-original t]
2247               ["Lapsed" gnus-article-date-lapsed t]
2248               ["User-defined" gnus-article-date-user t])
2249              ("Display"
2250               ["Remove images" gnus-article-remove-images t]
2251               ["Toggle smiley" gnus-treat-smiley t]
2252               ["Show X-Face" gnus-article-display-x-face t]
2253               ["Show picons in From" gnus-treat-from-picon t]
2254               ["Show picons in mail headers" gnus-treat-mail-picon t]
2255               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2256               ("View as different encoding"
2257                ,@(gnus-summary-menu-split
2258                   (mapcar
2259                    (lambda (cs)
2260                      ;; Since easymenu under Emacs doesn't allow
2261                      ;; lambda forms for menu commands, we should
2262                      ;; provide intern'ed function symbols.
2263                      (let ((command (intern (format "\
2264 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2265                        (fset command
2266                              `(lambda ()
2267                                 (interactive)
2268                                 (let ((gnus-summary-show-article-charset-alist
2269                                        '((1 . ,cs))))
2270                                   (gnus-summary-show-article 1))))
2271                        `[,(symbol-name cs) ,command t]))
2272                    (sort (if (fboundp 'coding-system-list)
2273                              (coding-system-list)
2274                            (mapcar 'car mm-mime-mule-charset-alist))
2275                          'string<)))))
2276              ("Washing"
2277               ("Remove Blanks"
2278                ["Leading" gnus-article-strip-leading-blank-lines t]
2279                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2280                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2281                ["All of the above" gnus-article-strip-blank-lines t]
2282                ["All" gnus-article-strip-all-blank-lines t]
2283                ["Leading space" gnus-article-strip-leading-space t]
2284                ["Trailing space" gnus-article-strip-trailing-space t]
2285                ["Leading space in headers"
2286                 gnus-article-remove-leading-whitespace t])
2287               ["Overstrike" gnus-article-treat-overstrike t]
2288               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2289               ["Emphasis" gnus-article-emphasize t]
2290               ["Word wrap" gnus-article-fill-cited-article t]
2291               ["Fill long lines" gnus-article-fill-long-lines t]
2292               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2293               ["Remove CR" gnus-article-remove-cr t]
2294               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2295               ["Base64" gnus-article-de-base64-unreadable t]
2296               ["Rot 13" gnus-summary-caesar-message
2297                ,@(if (featurep 'xemacs) '(t)
2298                    '(:help "\"Caesar rotate\" article by 13"))]
2299               ["De-IDNA" gnus-summary-idna-message t]
2300               ["Morse decode" gnus-summary-morse-message t]
2301               ["Unix pipe..." gnus-summary-pipe-message t]
2302               ["Add buttons" gnus-article-add-buttons t]
2303               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2304               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2305               ["Verbose header" gnus-summary-verbose-headers t]
2306               ["Toggle header" gnus-summary-toggle-header t]
2307               ["Unfold headers" gnus-article-treat-unfold-headers t]
2308               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2309               ["Html" gnus-article-wash-html t]
2310               ["Unsplit URLs" gnus-article-unsplit-urls t]
2311               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2312               ["Decode HZ" gnus-article-decode-HZ t]
2313               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2314               ("(Outlook) Deuglify"
2315                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2316                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2317                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2318                ["Full (Outlook) deuglify"
2319                 gnus-article-outlook-deuglify-article t])
2320               )
2321              ("Output"
2322               ["Save in default format..." gnus-summary-save-article
2323                ,@(if (featurep 'xemacs) '(t)
2324                    '(:help "Save article using default method"))]
2325               ["Save in file..." gnus-summary-save-article-file
2326                ,@(if (featurep 'xemacs) '(t)
2327                    '(:help "Save article in file"))]
2328               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2329               ["Save in MH folder..." gnus-summary-save-article-folder t]
2330               ["Save in VM folder..." gnus-summary-save-article-vm t]
2331               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2332               ["Save body in file..." gnus-summary-save-article-body-file t]
2333               ["Pipe through a filter..." gnus-summary-pipe-output t]
2334               ["Add to SOUP packet" gnus-soup-add-article t]
2335               ["Print with Muttprint..." gnus-summary-muttprint t]
2336               ["Print" gnus-summary-print-article
2337                ,@(if (featurep 'xemacs) '(t)
2338                    '(:help "Generate and print a PostScript image"))])
2339              ("Copy, move,... (Backend)"
2340               ,@(if (featurep 'xemacs) nil
2341                   '(:help "Copying, moving, expiring articles..."))
2342               ["Respool article..." gnus-summary-respool-article t]
2343               ["Move article..." gnus-summary-move-article
2344                (gnus-check-backend-function
2345                 'request-move-article gnus-newsgroup-name)]
2346               ["Copy article..." gnus-summary-copy-article t]
2347               ["Crosspost article..." gnus-summary-crosspost-article
2348                (gnus-check-backend-function
2349                 'request-replace-article gnus-newsgroup-name)]
2350               ["Import file..." gnus-summary-import-article
2351                (gnus-check-backend-function
2352                 'request-accept-article gnus-newsgroup-name)]
2353               ["Create article..." gnus-summary-create-article
2354                (gnus-check-backend-function
2355                 'request-accept-article gnus-newsgroup-name)]
2356               ["Check if posted" gnus-summary-article-posted-p t]
2357               ["Edit article" gnus-summary-edit-article
2358                (not (gnus-group-read-only-p))]
2359               ["Delete article" gnus-summary-delete-article
2360                (gnus-check-backend-function
2361                 'request-expire-articles gnus-newsgroup-name)]
2362               ["Query respool" gnus-summary-respool-query t]
2363               ["Trace respool" gnus-summary-respool-trace t]
2364               ["Delete expirable articles" gnus-summary-expire-articles-now
2365                (gnus-check-backend-function
2366                 'request-expire-articles gnus-newsgroup-name)])
2367              ("Extract"
2368               ["Uudecode" gnus-uu-decode-uu
2369                ,@(if (featurep 'xemacs) '(t)
2370                    '(:help "Decode uuencoded article(s)"))]
2371               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2372               ["Unshar" gnus-uu-decode-unshar t]
2373               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2374               ["Save" gnus-uu-decode-save t]
2375               ["Binhex" gnus-uu-decode-binhex t]
2376               ["Postscript" gnus-uu-decode-postscript t]
2377               ["All MIME parts" gnus-summary-save-parts t])
2378              ("Cache"
2379               ["Enter article" gnus-cache-enter-article t]
2380               ["Remove article" gnus-cache-remove-article t])
2381              ["Translate" gnus-article-babel t]
2382              ["Select article buffer" gnus-summary-select-article-buffer t]
2383              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2384              ["Isearch article..." gnus-summary-isearch-article t]
2385              ["Beginning of the article" gnus-summary-beginning-of-article t]
2386              ["End of the article" gnus-summary-end-of-article t]
2387              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2388              ["Fetch referenced articles" gnus-summary-refer-references t]
2389              ["Fetch current thread" gnus-summary-refer-thread t]
2390              ["Fetch article with id..." gnus-summary-refer-article t]
2391              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2392              ["Redisplay" gnus-summary-show-article t]
2393              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2394       (easy-menu-define
2395         gnus-summary-article-menu gnus-summary-mode-map ""
2396         (cons "Article" innards))
2397
2398       (if (not (keymapp gnus-summary-article-menu))
2399           (easy-menu-define
2400             gnus-article-commands-menu gnus-article-mode-map ""
2401             (cons "Commands" innards))
2402         ;; in Emacs, don't share menu.
2403         (setq gnus-article-commands-menu
2404               (copy-keymap gnus-summary-article-menu))
2405         (define-key gnus-article-mode-map [menu-bar commands]
2406           (cons "Commands" gnus-article-commands-menu))))
2407
2408     (easy-menu-define
2409       gnus-summary-thread-menu gnus-summary-mode-map ""
2410       '("Threads"
2411         ["Find all messages in thread" gnus-summary-refer-thread t]
2412         ["Toggle threading" gnus-summary-toggle-threads t]
2413         ["Hide threads" gnus-summary-hide-all-threads t]
2414         ["Show threads" gnus-summary-show-all-threads t]
2415         ["Hide thread" gnus-summary-hide-thread t]
2416         ["Show thread" gnus-summary-show-thread t]
2417         ["Go to next thread" gnus-summary-next-thread t]
2418         ["Go to previous thread" gnus-summary-prev-thread t]
2419         ["Go down thread" gnus-summary-down-thread t]
2420         ["Go up thread" gnus-summary-up-thread t]
2421         ["Top of thread" gnus-summary-top-thread t]
2422         ["Mark thread as read" gnus-summary-kill-thread t]
2423         ["Lower thread score" gnus-summary-lower-thread t]
2424         ["Raise thread score" gnus-summary-raise-thread t]
2425         ["Rethread current" gnus-summary-rethread-current t]))
2426
2427     (easy-menu-define
2428       gnus-summary-post-menu gnus-summary-mode-map ""
2429       `("Post"
2430         ["Send a message (mail or news)" gnus-summary-post-news
2431          ,@(if (featurep 'xemacs) '(t)
2432              '(:help "Compose a new message (mail or news)"))]
2433         ["Followup" gnus-summary-followup
2434          ,@(if (featurep 'xemacs) '(t)
2435              '(:help "Post followup to this article"))]
2436         ["Followup and yank" gnus-summary-followup-with-original
2437          ,@(if (featurep 'xemacs) '(t)
2438              '(:help "Post followup to this article, quoting its contents"))]
2439         ["Supersede article" gnus-summary-supersede-article t]
2440         ["Cancel article" gnus-summary-cancel-article
2441          ,@(if (featurep 'xemacs) '(t)
2442              '(:help "Cancel an article you posted"))]
2443         ["Reply" gnus-summary-reply t]
2444         ["Reply and yank" gnus-summary-reply-with-original t]
2445         ["Wide reply" gnus-summary-wide-reply t]
2446         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2447          ,@(if (featurep 'xemacs) '(t)
2448              '(:help "Mail a reply, quoting this article"))]
2449         ["Very wide reply" gnus-summary-very-wide-reply t]
2450         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2451          ,@(if (featurep 'xemacs) '(t)
2452              '(:help "Mail a very wide reply, quoting this article"))]
2453         ["Mail forward" gnus-summary-mail-forward t]
2454         ["Post forward" gnus-summary-post-forward t]
2455         ["Digest and mail" gnus-uu-digest-mail-forward t]
2456         ["Digest and post" gnus-uu-digest-post-forward t]
2457         ["Resend message" gnus-summary-resend-message t]
2458         ["Resend message edit" gnus-summary-resend-message-edit t]
2459         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2460         ["Send a mail" gnus-summary-mail-other-window t]
2461         ["Create a local message" gnus-summary-news-other-window t]
2462         ["Uuencode and post" gnus-uu-post-news
2463          ,@(if (featurep 'xemacs) '(t)
2464              '(:help "Post a uuencoded article"))]
2465         ["Followup via news" gnus-summary-followup-to-mail t]
2466         ["Followup via news and yank"
2467          gnus-summary-followup-to-mail-with-original t]
2468         ;;("Draft"
2469         ;;["Send" gnus-summary-send-draft t]
2470         ;;["Send bounced" gnus-resend-bounced-mail t])
2471         ))
2472
2473     (cond
2474      ((not (keymapp gnus-summary-post-menu))
2475       (setq gnus-article-post-menu gnus-summary-post-menu))
2476      ((not gnus-article-post-menu)
2477       ;; Don't share post menu.
2478       (setq gnus-article-post-menu
2479             (copy-keymap gnus-summary-post-menu))))
2480     (define-key gnus-article-mode-map [menu-bar post]
2481       (cons "Post" gnus-article-post-menu))
2482
2483     (easy-menu-define
2484       gnus-summary-misc-menu gnus-summary-mode-map ""
2485       `("Gnus"
2486         ("Mark Read"
2487          ["Mark as read" gnus-summary-mark-as-read-forward t]
2488          ["Mark same subject and select"
2489           gnus-summary-kill-same-subject-and-select t]
2490          ["Mark same subject" gnus-summary-kill-same-subject t]
2491          ["Catchup" gnus-summary-catchup
2492           ,@(if (featurep 'xemacs) '(t)
2493               '(:help "Mark unread articles in this group as read"))]
2494          ["Catchup all" gnus-summary-catchup-all t]
2495          ["Catchup to here" gnus-summary-catchup-to-here t]
2496          ["Catchup from here" gnus-summary-catchup-from-here t]
2497          ["Catchup region" gnus-summary-mark-region-as-read
2498           (gnus-mark-active-p)]
2499          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2500         ("Mark Various"
2501          ["Tick" gnus-summary-tick-article-forward t]
2502          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2503          ["Remove marks" gnus-summary-clear-mark-forward t]
2504          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2505          ["Set bookmark" gnus-summary-set-bookmark t]
2506          ["Remove bookmark" gnus-summary-remove-bookmark t])
2507         ("Limit to"
2508          ["Marks..." gnus-summary-limit-to-marks t]
2509          ["Subject..." gnus-summary-limit-to-subject t]
2510          ["Author..." gnus-summary-limit-to-author t]
2511          ["Recipient..." gnus-summary-limit-to-recipient t]
2512          ["Age..." gnus-summary-limit-to-age t]
2513          ["Extra..." gnus-summary-limit-to-extra t]
2514          ["Score..." gnus-summary-limit-to-score t]
2515          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2516          ["Unread" gnus-summary-limit-to-unread t]
2517          ["Unseen" gnus-summary-limit-to-unseen t]
2518          ["Replied" gnus-summary-limit-to-replied t]
2519          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2520          ["Next articles" gnus-summary-limit-to-articles t]
2521          ["Pop limit" gnus-summary-pop-limit t]
2522          ["Show dormant" gnus-summary-limit-include-dormant t]
2523          ["Hide childless dormant"
2524           gnus-summary-limit-exclude-childless-dormant t]
2525          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2526          ["Hide marked" gnus-summary-limit-exclude-marks t]
2527          ["Show expunged" gnus-summary-limit-include-expunged t])
2528         ("Process Mark"
2529          ["Set mark" gnus-summary-mark-as-processable t]
2530          ["Remove mark" gnus-summary-unmark-as-processable t]
2531          ["Remove all marks" gnus-summary-unmark-all-processable t]
2532          ["Invert marks" gnus-uu-invert-processable t]
2533          ["Mark above" gnus-uu-mark-over t]
2534          ["Mark series" gnus-uu-mark-series t]
2535          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2536          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2537          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2538          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2539          ["Mark all" gnus-uu-mark-all t]
2540          ["Mark buffer" gnus-uu-mark-buffer t]
2541          ["Mark sparse" gnus-uu-mark-sparse t]
2542          ["Mark thread" gnus-uu-mark-thread t]
2543          ["Unmark thread" gnus-uu-unmark-thread t]
2544          ("Process Mark Sets"
2545           ["Kill" gnus-summary-kill-process-mark t]
2546           ["Yank" gnus-summary-yank-process-mark
2547            gnus-newsgroup-process-stack]
2548           ["Save" gnus-summary-save-process-mark t]
2549           ["Run command on marked..." gnus-summary-universal-argument t]))
2550         ("Scroll article"
2551          ["Page forward" gnus-summary-next-page
2552           ,@(if (featurep 'xemacs) '(t)
2553               '(:help "Show next page of article"))]
2554          ["Page backward" gnus-summary-prev-page
2555           ,@(if (featurep 'xemacs) '(t)
2556               '(:help "Show previous page of article"))]
2557          ["Line forward" gnus-summary-scroll-up t])
2558         ("Move"
2559          ["Next unread article" gnus-summary-next-unread-article t]
2560          ["Previous unread article" gnus-summary-prev-unread-article t]
2561          ["Next article" gnus-summary-next-article t]
2562          ["Previous article" gnus-summary-prev-article t]
2563          ["Next unread subject" gnus-summary-next-unread-subject t]
2564          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2565          ["Next article same subject" gnus-summary-next-same-subject t]
2566          ["Previous article same subject" gnus-summary-prev-same-subject t]
2567          ["First unread article" gnus-summary-first-unread-article t]
2568          ["Best unread article" gnus-summary-best-unread-article t]
2569          ["Go to subject number..." gnus-summary-goto-subject t]
2570          ["Go to article number..." gnus-summary-goto-article t]
2571          ["Go to the last article" gnus-summary-goto-last-article t]
2572          ["Pop article off history" gnus-summary-pop-article t])
2573         ("Sort"
2574          ["Sort by number" gnus-summary-sort-by-number t]
2575          ["Sort by author" gnus-summary-sort-by-author t]
2576          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2577          ["Sort by subject" gnus-summary-sort-by-subject t]
2578          ["Sort by date" gnus-summary-sort-by-date t]
2579          ["Sort by score" gnus-summary-sort-by-score t]
2580          ["Sort by lines" gnus-summary-sort-by-lines t]
2581          ["Sort by characters" gnus-summary-sort-by-chars t]
2582          ["Randomize" gnus-summary-sort-by-random t]
2583          ["Original sort" gnus-summary-sort-by-original t])
2584         ("Help"
2585          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2586          ["Describe group" gnus-summary-describe-group t]
2587          ["Fetch charter" gnus-group-fetch-charter
2588           ,@(if (featurep 'xemacs) nil
2589               '(:help "Display the charter of the current group"))]
2590          ["Fetch control message" gnus-group-fetch-control
2591           ,@(if (featurep 'xemacs) nil
2592               '(:help "Display the archived control message for the current group"))]
2593          ["Read manual" gnus-info-find-node t])
2594         ("Modes"
2595          ["Pick and read" gnus-pick-mode t]
2596          ["Binary" gnus-binary-mode t])
2597         ("Regeneration"
2598          ["Regenerate" gnus-summary-prepare t]
2599          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2600          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2601          ["Toggle threading" gnus-summary-toggle-threads t])
2602         ["See old articles" gnus-summary-insert-old-articles t]
2603         ["See new articles" gnus-summary-insert-new-articles t]
2604         ["Filter articles..." gnus-summary-execute-command t]
2605         ["Run command on articles..." gnus-summary-universal-argument t]
2606         ["Search articles forward..." gnus-summary-search-article-forward t]
2607         ["Search articles backward..." gnus-summary-search-article-backward t]
2608         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2609         ["Expand window" gnus-summary-expand-window t]
2610         ["Expire expirable articles" gnus-summary-expire-articles
2611          (gnus-check-backend-function
2612           'request-expire-articles gnus-newsgroup-name)]
2613         ["Edit local kill file" gnus-summary-edit-local-kill t]
2614         ["Edit main kill file" gnus-summary-edit-global-kill t]
2615         ["Edit group parameters" gnus-summary-edit-parameters t]
2616         ["Customize group parameters" gnus-summary-customize-parameters t]
2617         ["Send a bug report" gnus-bug t]
2618         ("Exit"
2619          ["Catchup and exit" gnus-summary-catchup-and-exit
2620           ,@(if (featurep 'xemacs) '(t)
2621               '(:help "Mark unread articles in this group as read, then exit"))]
2622          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2623          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2624          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2625          ["Exit group" gnus-summary-exit
2626           ,@(if (featurep 'xemacs) '(t)
2627               '(:help "Exit current group, return to group selection mode"))]
2628          ["Exit group without updating" gnus-summary-exit-no-update t]
2629          ["Exit and goto next group" gnus-summary-next-group t]
2630          ["Exit and goto prev group" gnus-summary-prev-group t]
2631          ["Reselect group" gnus-summary-reselect-current-group t]
2632          ["Rescan group" gnus-summary-rescan-group t]
2633          ["Update dribble" gnus-summary-save-newsrc t])))
2634
2635     (gnus-run-hooks 'gnus-summary-menu-hook)))
2636
2637 (defvar gnus-summary-tool-bar-map nil)
2638
2639 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2640 ;; affect _new_ message buffers.  We might add a function that walks thru all
2641 ;; summary-mode buffers and force the update.
2642 (defun gnus-summary-tool-bar-update (&optional symbol value)
2643   "Update summary mode toolbar.
2644 Setter function for custom variables."
2645   (setq-default gnus-summary-tool-bar-map nil)
2646   (when symbol
2647     ;; When used as ":set" function:
2648     (set-default symbol value))
2649   (when (gnus-buffer-live-p gnus-summary-buffer)
2650     (with-current-buffer gnus-summary-buffer
2651       (gnus-summary-make-tool-bar))))
2652
2653 ;; The default will be changed when the new icons have been checked in:
2654 (defcustom gnus-summary-tool-bar 'gnus-summary-tool-bar-retro
2655   "Specifies the Gnus summary tool bar.
2656
2657 It can be either a list or a symbol refering to a list.  See
2658 `gmm-tool-bar-from-list' for the format of the list.  The
2659 default key map is `gnus-summary-mode-map'.
2660
2661 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2662 `gnus-summary-tool-bar-retro'."
2663   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2664                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2665                  (repeat :tag "User defined list" gmm-tool-bar-item)
2666                  (symbol))
2667   :version "23.0" ;; No Gnus
2668   :initialize 'custom-initialize-default
2669   :set 'gnus-summary-tool-bar-update
2670   :group 'gnus-summary)
2671
2672 (defcustom gnus-summary-tool-bar-gnome
2673   '((gnus-summary-post-news "mail/compose" nil)
2674     (gnus-summary-reply-with-original "mail/reply")
2675     (gnus-summary-reply "mail/reply" nil :visible nil)
2676     (gnus-summary-followup-with-original "mail/reply-all")
2677     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2678     (gnus-summary-mail-forward "mail/forward")
2679     (gnus-summary-save-article "mail/save")
2680     (gnus-summary-search-article-forward "search")
2681     (gnus-summary-print-article "print")
2682     (gnus-summary-mark-as-expirable
2683      "delete" nil
2684      :visible (gnus-check-backend-function 'request-expire-articles
2685                                            gnus-newsgroup-name))
2686     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2687     (gnus-summary-mark-as-spam
2688      "mail/spam" t :visible (spam-group-ham-contents-p gnus-newsgroup-name)
2689      :help "Mark as spam")
2690     (gnus-summary-mark-as-read-forward
2691      "mail/not-spam" nil :visible (spam-group-spam-contents-p gnus-newsgroup-name))
2692     ;; Some new commands that may need more suitable icons:
2693     (gnus-summary-save-newsrc "save" nil :visible nil)
2694     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2695     (gnus-summary-prev-article "left-arrow" nil :visible nil)  ;; Emacs 22
2696     (gnus-summary-next-article "right-arrow" nil :visible nil) ;; Emacs 22
2697     (gnus-summary-prev-unread-article "prev-node") ;; Emacs 22
2698     (gnus-summary-next-unread-article "next-node") ;; Emacs 22
2699     (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2700     ;;
2701     ;; Maybe some sort-by-... could be added:
2702     (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2703     (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2704     ;;
2705     (gnus-summary-insert-new-articles "mail/inbox")
2706     ;;
2707     (gnus-summary-exit "exit")
2708     ;; (customize-group 'gnus-summary) "preferences"
2709     (gnus-info-find-node "help"))
2710   "List of functions for the summary tool bar (GNOME style).
2711
2712 See `gmm-tool-bar-from-list' for the format of the list."
2713   :type '(repeat gmm-tool-bar-item)
2714   :version "23.0" ;; No Gnus
2715   :initialize 'custom-initialize-default
2716   :set 'gnus-summary-tool-bar-update
2717   :group 'gnus-summary)
2718
2719 (defcustom gnus-summary-tool-bar-retro
2720   '((gnus-summary-prev-unread-article "prev-ur")
2721     (gnus-summary-next-unread-article "next-ur")
2722     (gnus-summary-post-news "post")
2723     (gnus-summary-followup-with-original "fuwo")
2724     (gnus-summary-followup "followup")
2725     (gnus-summary-reply-with-original "reply-wo")
2726     (gnus-summary-reply "reply")
2727     (gnus-summary-caesar-message "rot13")
2728     (gnus-uu-decode-uu "uu-decode")
2729     (gnus-summary-save-article-file "save-aif")
2730     (gnus-summary-save-article "save-art")
2731     (gnus-uu-post-news "uu-post")
2732     (gnus-summary-catchup "catchup")
2733     (gnus-summary-catchup-and-exit "cu-exit")
2734     (gnus-summary-exit "exit-summ")
2735     ;; Some new command that may need more suitable icons:
2736     (gnus-summary-print-article "print" nil :visible nil)
2737     (gnus-summary-mark-as-expirable "close" nil :visible nil)
2738     (gnus-summary-save-newsrc "save" nil :visible nil)
2739     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2740     (gnus-summary-search-article-forward "search" nil :visible nil)
2741     ;; (gnus-summary-insert-new-articles "paste" nil :visible nil)
2742     ;; (gnus-summary-toggle-threads "open" nil :visible nil)
2743     ;;
2744     (gnus-info-find-node "help" nil :visible nil))
2745   "List of functions for the summary tool bar (retro look).
2746
2747 See `gmm-tool-bar-from-list' for the format of the list."
2748   :type '(repeat gmm-tool-bar-item)
2749   :version "23.0" ;; No Gnus
2750   :initialize 'custom-initialize-default
2751   :set 'gnus-summary-tool-bar-update
2752   :group 'gnus-summary)
2753
2754 (defcustom gnus-summary-tool-bar-zap-list t
2755   "List of icon items from the global tool bar.
2756 These items are not displayed in the Gnus summary mode tool bar.
2757
2758 See `gmm-tool-bar-from-list' for the format of the list."
2759   :type 'gmm-tool-bar-zap-list
2760   :version "23.0" ;; No Gnus
2761   :initialize 'custom-initialize-default
2762   :set 'gnus-summary-tool-bar-update
2763   :group 'gnus-summary)
2764
2765 (defun gnus-summary-make-tool-bar (&optional force)
2766   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2767 When FORCE, rebuild the tool bar."
2768   (when (and (not (featurep 'xemacs))
2769              (boundp 'tool-bar-mode)
2770              tool-bar-mode
2771              (or (not gnus-summary-tool-bar-map) force))
2772     (let* ((load-path (gmm-image-load-path "gnus" nil 'load-path))
2773            (image-load-path (gmm-image-load-path "gnus" nil 'image-load-path))
2774            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2775                                         gnus-summary-tool-bar-zap-list
2776                                         'gnus-summary-mode-map)))
2777       (when map
2778         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2779         ;; uses it's value.
2780         (setq gnus-summary-tool-bar-map map))))
2781   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2782
2783 (defun gnus-score-set-default (var value)
2784   "A version of set that updates the GNU Emacs menu-bar."
2785   (set var value)
2786   ;; It is the message that forces the active status to be updated.
2787   (message ""))
2788
2789 (defun gnus-make-score-map (type)
2790   "Make a summary score map of type TYPE."
2791   (if t
2792       nil
2793     (let ((headers '(("author" "from" string)
2794                      ("subject" "subject" string)
2795                      ("article body" "body" string)
2796                      ("article head" "head" string)
2797                      ("xref" "xref" string)
2798                      ("extra header" "extra" string)
2799                      ("lines" "lines" number)
2800                      ("followups to author" "followup" string)))
2801           (types '((number ("less than" <)
2802                            ("greater than" >)
2803                            ("equal" =))
2804                    (string ("substring" s)
2805                            ("exact string" e)
2806                            ("fuzzy string" f)
2807                            ("regexp" r))))
2808           (perms '(("temporary" (current-time-string))
2809                    ("permanent" nil)
2810                    ("immediate" now)))
2811           header)
2812       (list
2813        (apply
2814         'nconc
2815         (list
2816          (if (eq type 'lower)
2817              "Lower score"
2818            "Increase score"))
2819         (let (outh)
2820           (while headers
2821             (setq header (car headers))
2822             (setq outh
2823                   (cons
2824                    (apply
2825                     'nconc
2826                     (list (car header))
2827                     (let ((ts (cdr (assoc (nth 2 header) types)))
2828                           outt)
2829                       (while ts
2830                         (setq outt
2831                               (cons
2832                                (apply
2833                                 'nconc
2834                                 (list (caar ts))
2835                                 (let ((ps perms)
2836                                       outp)
2837                                   (while ps
2838                                     (setq outp
2839                                           (cons
2840                                            (vector
2841                                             (caar ps)
2842                                             (list
2843                                              'gnus-summary-score-entry
2844                                              (nth 1 header)
2845                                              (if (or (string= (nth 1 header)
2846                                                               "head")
2847                                                      (string= (nth 1 header)
2848                                                               "body"))
2849                                                  ""
2850                                                (list 'gnus-summary-header
2851                                                      (nth 1 header)))
2852                                              (list 'quote (nth 1 (car ts)))
2853                                              (list 'gnus-score-delta-default
2854                                                    nil)
2855                                              (nth 1 (car ps))
2856                                              t)
2857                                             t)
2858                                            outp))
2859                                     (setq ps (cdr ps)))
2860                                   (list (nreverse outp))))
2861                                outt))
2862                         (setq ts (cdr ts)))
2863                       (list (nreverse outt))))
2864                    outh))
2865             (setq headers (cdr headers)))
2866           (list (nreverse outh))))))))
2867
2868 \f
2869
2870 (defun gnus-summary-mode (&optional group)
2871   "Major mode for reading articles.
2872
2873 All normal editing commands are switched off.
2874 \\<gnus-summary-mode-map>
2875 Each line in this buffer represents one article.  To read an
2876 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2877 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2878 respectively.
2879
2880 You can also post articles and send mail from this buffer.  To
2881 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2882 of an article, type `\\[gnus-summary-reply]'.
2883
2884 There are approx. one gazillion commands you can execute in this
2885 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2886
2887 The following commands are available:
2888
2889 \\{gnus-summary-mode-map}"
2890   (interactive)
2891   (kill-all-local-variables)
2892   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2893     (gnus-summary-make-local-variables))
2894   (gnus-summary-make-local-variables)
2895   (setq gnus-newsgroup-name group)
2896   (when (gnus-visual-p 'summary-menu 'menu)
2897     (gnus-summary-make-menu-bar)
2898     (gnus-summary-make-tool-bar))
2899   (gnus-make-thread-indent-array)
2900   (gnus-simplify-mode-line)
2901   (setq major-mode 'gnus-summary-mode)
2902   (setq mode-name "Summary")
2903   (make-local-variable 'minor-mode-alist)
2904   (use-local-map gnus-summary-mode-map)
2905   (buffer-disable-undo)
2906   (setq buffer-read-only t              ;Disable modification
2907         show-trailing-whitespace nil)
2908   (setq truncate-lines t)
2909   (setq selective-display t)
2910   (setq selective-display-ellipses t)   ;Display `...'
2911   (gnus-summary-set-display-table)
2912   (gnus-set-default-directory)
2913   (make-local-variable 'gnus-summary-line-format)
2914   (make-local-variable 'gnus-summary-line-format-spec)
2915   (make-local-variable 'gnus-summary-dummy-line-format)
2916   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2917   (make-local-variable 'gnus-summary-mark-positions)
2918   (gnus-make-local-hook 'pre-command-hook)
2919   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2920   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2921   (turn-on-gnus-mailing-list-mode)
2922   (mm-enable-multibyte)
2923   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2924   (gnus-update-summary-mark-positions))
2925
2926 (defun gnus-summary-make-local-variables ()
2927   "Make all the local summary buffer variables."
2928   (let (global)
2929     (dolist (local gnus-summary-local-variables)
2930       (if (consp local)
2931           (progn
2932             (if (eq (cdr local) 'global)
2933                 ;; Copy the global value of the variable.
2934                 (setq global (symbol-value (car local)))
2935               ;; Use the value from the list.
2936               (setq global (eval (cdr local))))
2937             (set (make-local-variable (car local)) global))
2938         ;; Simple nil-valued local variable.
2939         (set (make-local-variable local) nil)))))
2940
2941 (defun gnus-summary-clear-local-variables ()
2942   (let ((locals gnus-summary-local-variables))
2943     (while locals
2944       (if (consp (car locals))
2945           (and (symbolp (caar locals))
2946                (set (caar locals) nil))
2947         (and (symbolp (car locals))
2948              (set (car locals) nil)))
2949       (setq locals (cdr locals)))))
2950
2951 ;; Summary data functions.
2952
2953 (defmacro gnus-data-number (data)
2954   `(car ,data))
2955
2956 (defmacro gnus-data-set-number (data number)
2957   `(setcar ,data ,number))
2958
2959 (defmacro gnus-data-mark (data)
2960   `(nth 1 ,data))
2961
2962 (defmacro gnus-data-set-mark (data mark)
2963   `(setcar (nthcdr 1 ,data) ,mark))
2964
2965 (defmacro gnus-data-pos (data)
2966   `(nth 2 ,data))
2967
2968 (defmacro gnus-data-set-pos (data pos)
2969   `(setcar (nthcdr 2 ,data) ,pos))
2970
2971 (defmacro gnus-data-header (data)
2972   `(nth 3 ,data))
2973
2974 (defmacro gnus-data-set-header (data header)
2975   `(setf (nth 3 ,data) ,header))
2976
2977 (defmacro gnus-data-level (data)
2978   `(nth 4 ,data))
2979
2980 (defmacro gnus-data-unread-p (data)
2981   `(= (nth 1 ,data) gnus-unread-mark))
2982
2983 (defmacro gnus-data-read-p (data)
2984   `(/= (nth 1 ,data) gnus-unread-mark))
2985
2986 (defmacro gnus-data-pseudo-p (data)
2987   `(consp (nth 3 ,data)))
2988
2989 (defmacro gnus-data-find (number)
2990   `(assq ,number gnus-newsgroup-data))
2991
2992 (defmacro gnus-data-find-list (number &optional data)
2993   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2994      (memq (assq ,number bdata)
2995            bdata)))
2996
2997 (defmacro gnus-data-make (number mark pos header level)
2998   `(list ,number ,mark ,pos ,header ,level))
2999
3000 (defun gnus-data-enter (after-article number mark pos header level offset)
3001   (let ((data (gnus-data-find-list after-article)))
3002     (unless data
3003       (error "No such article: %d" after-article))
3004     (setcdr data (cons (gnus-data-make number mark pos header level)
3005                        (cdr data)))
3006     (setq gnus-newsgroup-data-reverse nil)
3007     (gnus-data-update-list (cddr data) offset)))
3008
3009 (defun gnus-data-enter-list (after-article list &optional offset)
3010   (when list
3011     (let ((data (and after-article (gnus-data-find-list after-article)))
3012           (ilist list))
3013       (if (not (or data
3014                    after-article))
3015           (let ((odata gnus-newsgroup-data))
3016             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3017             (when offset
3018               (gnus-data-update-list odata offset)))
3019         ;; Find the last element in the list to be spliced into the main
3020         ;; list.
3021         (setq list (last list))
3022         (if (not data)
3023             (progn
3024               (setcdr list gnus-newsgroup-data)
3025               (setq gnus-newsgroup-data ilist)
3026               (when offset
3027                 (gnus-data-update-list (cdr list) offset)))
3028           (setcdr list (cdr data))
3029           (setcdr data ilist)
3030           (when offset
3031             (gnus-data-update-list (cdr list) offset))))
3032       (setq gnus-newsgroup-data-reverse nil))))
3033
3034 (defun gnus-data-remove (article &optional offset)
3035   (let ((data gnus-newsgroup-data))
3036     (if (= (gnus-data-number (car data)) article)
3037         (progn
3038           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3039                 gnus-newsgroup-data-reverse nil)
3040           (when offset
3041             (gnus-data-update-list gnus-newsgroup-data offset)))
3042       (while (cdr data)
3043         (when (= (gnus-data-number (cadr data)) article)
3044           (setcdr data (cddr data))
3045           (when offset
3046             (gnus-data-update-list (cdr data) offset))
3047           (setq data nil
3048                 gnus-newsgroup-data-reverse nil))
3049         (setq data (cdr data))))))
3050
3051 (defmacro gnus-data-list (backward)
3052   `(if ,backward
3053        (or gnus-newsgroup-data-reverse
3054            (setq gnus-newsgroup-data-reverse
3055                  (reverse gnus-newsgroup-data)))
3056      gnus-newsgroup-data))
3057
3058 (defun gnus-data-update-list (data offset)
3059   "Add OFFSET to the POS of all data entries in DATA."
3060   (setq gnus-newsgroup-data-reverse nil)
3061   (while data
3062     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3063     (setq data (cdr data))))
3064
3065 (defun gnus-summary-article-pseudo-p (article)
3066   "Say whether this article is a pseudo article or not."
3067   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3068
3069 (defmacro gnus-summary-article-sparse-p (article)
3070   "Say whether this article is a sparse article or not."
3071   `(memq ,article gnus-newsgroup-sparse))
3072
3073 (defmacro gnus-summary-article-ancient-p (article)
3074   "Say whether this article is a sparse article or not."
3075   `(memq ,article gnus-newsgroup-ancient))
3076
3077 (defun gnus-article-parent-p (number)
3078   "Say whether this article is a parent or not."
3079   (let ((data (gnus-data-find-list number)))
3080     (and (cdr data)              ; There has to be an article after...
3081          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3082             (gnus-data-level (nth 1 data))))))
3083
3084 (defun gnus-article-children (number)
3085   "Return a list of all children to NUMBER."
3086   (let* ((data (gnus-data-find-list number))
3087          (level (gnus-data-level (car data)))
3088          children)
3089     (setq data (cdr data))
3090     (while (and data
3091                 (= (gnus-data-level (car data)) (1+ level)))
3092       (push (gnus-data-number (car data)) children)
3093       (setq data (cdr data)))
3094     children))
3095
3096 (defmacro gnus-summary-skip-intangible ()
3097   "If the current article is intangible, then jump to a different article."
3098   '(let ((to (get-text-property (point) 'gnus-intangible)))
3099      (and to (gnus-summary-goto-subject to))))
3100
3101 (defmacro gnus-summary-article-intangible-p ()
3102   "Say whether this article is intangible or not."
3103   '(get-text-property (point) 'gnus-intangible))
3104
3105 (defun gnus-article-read-p (article)
3106   "Say whether ARTICLE is read or not."
3107   (not (or (memq article gnus-newsgroup-marked)
3108            (memq article gnus-newsgroup-spam-marked)
3109            (memq article gnus-newsgroup-unreads)
3110            (memq article gnus-newsgroup-unselected)
3111            (memq article gnus-newsgroup-dormant))))
3112
3113 ;; Some summary mode macros.
3114
3115 (defmacro gnus-summary-article-number ()
3116   "The article number of the article on the current line.
3117 If there isn't an article number here, then we return the current
3118 article number."
3119   '(progn
3120      (gnus-summary-skip-intangible)
3121      (or (get-text-property (point) 'gnus-number)
3122          (gnus-summary-last-subject))))
3123
3124 (defmacro gnus-summary-article-header (&optional number)
3125   "Return the header of article NUMBER."
3126   `(gnus-data-header (gnus-data-find
3127                       ,(or number '(gnus-summary-article-number)))))
3128
3129 (defmacro gnus-summary-thread-level (&optional number)
3130   "Return the level of thread that starts with article NUMBER."
3131   `(if (and (eq gnus-summary-make-false-root 'dummy)
3132             (get-text-property (point) 'gnus-intangible))
3133        0
3134      (gnus-data-level (gnus-data-find
3135                        ,(or number '(gnus-summary-article-number))))))
3136
3137 (defmacro gnus-summary-article-mark (&optional number)
3138   "Return the mark of article NUMBER."
3139   `(gnus-data-mark (gnus-data-find
3140                     ,(or number '(gnus-summary-article-number)))))
3141
3142 (defmacro gnus-summary-article-pos (&optional number)
3143   "Return the position of the line of article NUMBER."
3144   `(gnus-data-pos (gnus-data-find
3145                    ,(or number '(gnus-summary-article-number)))))
3146
3147 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3148 (defmacro gnus-summary-article-subject (&optional number)
3149   "Return current subject string or nil if nothing."
3150   `(let ((headers
3151           ,(if number
3152                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3153              '(gnus-data-header (assq (gnus-summary-article-number)
3154                                       gnus-newsgroup-data)))))
3155      (and headers
3156           (vectorp headers)
3157           (mail-header-subject headers))))
3158
3159 (defmacro gnus-summary-article-score (&optional number)
3160   "Return current article score."
3161   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3162                   gnus-newsgroup-scored))
3163        gnus-summary-default-score 0))
3164
3165 (defun gnus-summary-article-children (&optional number)
3166   "Return a list of article numbers that are children of article NUMBER."
3167   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3168          (level (gnus-data-level (car data)))
3169          l children)
3170     (while (and (setq data (cdr data))
3171                 (> (setq l (gnus-data-level (car data))) level))
3172       (and (= (1+ level) l)
3173            (push (gnus-data-number (car data))
3174                  children)))
3175     (nreverse children)))
3176
3177 (defun gnus-summary-article-parent (&optional number)
3178   "Return the article number of the parent of article NUMBER."
3179   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3180                                     (gnus-data-list t)))
3181          (level (gnus-data-level (car data))))
3182     (if (zerop level)
3183         ()                              ; This is a root.
3184       ;; We search until we find an article with a level less than
3185       ;; this one.  That function has to be the parent.
3186       (while (and (setq data (cdr data))
3187                   (not (< (gnus-data-level (car data)) level))))
3188       (and data (gnus-data-number (car data))))))
3189
3190 (defun gnus-unread-mark-p (mark)
3191   "Say whether MARK is the unread mark."
3192   (= mark gnus-unread-mark))
3193
3194 (defun gnus-read-mark-p (mark)
3195   "Say whether MARK is one of the marks that mark as read.
3196 This is all marks except unread, ticked, dormant, and expirable."
3197   (not (or (= mark gnus-unread-mark)
3198            (= mark gnus-ticked-mark)
3199            (= mark gnus-spam-mark)
3200            (= mark gnus-dormant-mark)
3201            (= mark gnus-expirable-mark))))
3202
3203 (defmacro gnus-article-mark (number)
3204   "Return the MARK of article NUMBER.
3205 This macro should only be used when computing the mark the \"first\"
3206 time; i.e., when generating the summary lines.  After that,
3207 `gnus-summary-article-mark' should be used to examine the
3208 marks of articles."
3209   `(cond
3210     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3211     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3212     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3213     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3214     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3215     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3216     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3217     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3218            gnus-ancient-mark))))
3219
3220 ;; Saving hidden threads.
3221
3222 (defmacro gnus-save-hidden-threads (&rest forms)
3223   "Save hidden threads, eval FORMS, and restore the hidden threads."
3224   (let ((config (make-symbol "config")))
3225     `(let ((,config (gnus-hidden-threads-configuration)))
3226        (unwind-protect
3227            (save-excursion
3228              ,@forms)
3229          (gnus-restore-hidden-threads-configuration ,config)))))
3230 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3231 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3232
3233 (defun gnus-data-compute-positions ()
3234   "Compute the positions of all articles."
3235   (setq gnus-newsgroup-data-reverse nil)
3236   (let ((data gnus-newsgroup-data))
3237     (save-excursion
3238       (gnus-save-hidden-threads
3239         (gnus-summary-show-all-threads)
3240         (goto-char (point-min))
3241         (while data
3242           (while (get-text-property (point) 'gnus-intangible)
3243             (forward-line 1))
3244           (gnus-data-set-pos (car data) (+ (point) 3))
3245           (setq data (cdr data))
3246           (forward-line 1))))))
3247
3248 (defun gnus-hidden-threads-configuration ()
3249   "Return the current hidden threads configuration."
3250   (save-excursion
3251     (let (config)
3252       (goto-char (point-min))
3253       (while (search-forward "\r" nil t)
3254         (push (1- (point)) config))
3255       config)))
3256
3257 (defun gnus-restore-hidden-threads-configuration (config)
3258   "Restore hidden threads configuration from CONFIG."
3259   (save-excursion
3260     (let (point buffer-read-only)
3261       (while (setq point (pop config))
3262         (when (and (< point (point-max))
3263                    (goto-char point)
3264                    (eq (char-after) ?\n))
3265           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3266
3267 ;; Various summary mode internalish functions.
3268
3269 (defun gnus-mouse-pick-article (e)
3270   (interactive "e")
3271   (mouse-set-point e)
3272   (gnus-summary-next-page nil t))
3273
3274 (defun gnus-summary-set-display-table ()
3275   "Change the display table.
3276 Odd characters have a tendency to mess
3277 up nicely formatted displays - we make all possible glyphs
3278 display only a single character."
3279
3280   ;; We start from the standard display table, if any.
3281   (let ((table (or (copy-sequence standard-display-table)
3282                    (make-display-table)))
3283         (i 32))
3284     ;; Nix out all the control chars...
3285     (while (>= (setq i (1- i)) 0)
3286       (aset table i [??]))
3287    ;; ... but not newline and cr, of course.  (cr is necessary for the
3288     ;; selective display).
3289     (aset table ?\n nil)
3290     (aset table ?\r nil)
3291     ;; We keep TAB as well.
3292     (aset table ?\t nil)
3293     ;; We nix out any glyphs over 126 that are not set already.
3294     (let ((i 256))
3295       (while (>= (setq i (1- i)) 127)
3296         ;; Only modify if the entry is nil.
3297         (unless (aref table i)
3298           (aset table i [??]))))
3299     (setq buffer-display-table table)))
3300
3301 (defun gnus-summary-set-article-display-arrow (pos)
3302   "Update the overlay arrow to point to line at position POS."
3303   (when (and gnus-summary-display-arrow
3304              (boundp 'overlay-arrow-position)
3305              (boundp 'overlay-arrow-string))
3306     (save-excursion
3307       (goto-char pos)
3308       (beginning-of-line)
3309       (unless overlay-arrow-position
3310         (setq overlay-arrow-position (make-marker)))
3311       (setq overlay-arrow-string "=>"
3312             overlay-arrow-position (set-marker overlay-arrow-position
3313                                                (point)
3314                                                (current-buffer))))))
3315
3316 (defun gnus-summary-setup-buffer (group)
3317   "Initialize summary buffer."
3318   (let ((buffer (gnus-summary-buffer-name group))
3319         (dead-name (concat "*Dead Summary "
3320                            (gnus-group-decoded-name group) "*")))
3321     ;; If a dead summary buffer exists, we kill it.
3322     (when (gnus-buffer-live-p dead-name)
3323       (gnus-kill-buffer dead-name))
3324     (if (get-buffer buffer)
3325         (progn
3326           (set-buffer buffer)
3327           (setq gnus-summary-buffer (current-buffer))
3328           (not gnus-newsgroup-prepared))
3329       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3330       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3331       (gnus-summary-mode group)
3332       (when gnus-carpal
3333         (gnus-carpal-setup-buffer 'summary))
3334       (unless gnus-single-article-buffer
3335         (make-local-variable 'gnus-article-buffer)
3336         (make-local-variable 'gnus-article-current)
3337         (make-local-variable 'gnus-original-article-buffer))
3338       (setq gnus-newsgroup-name group)
3339       ;; Set any local variables in the group parameters.
3340       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3341       t)))
3342
3343 (defun gnus-set-global-variables ()
3344   "Set the global equivalents of the buffer-local variables.
3345 They are set to the latest values they had.  These reflect the summary
3346 buffer that was in action when the last article was fetched."
3347   (when (eq major-mode 'gnus-summary-mode)
3348     (setq gnus-summary-buffer (current-buffer))
3349     (let ((name gnus-newsgroup-name)
3350           (marked gnus-newsgroup-marked)
3351           (spam gnus-newsgroup-spam-marked)
3352           (unread gnus-newsgroup-unreads)
3353           (headers gnus-current-headers)
3354           (data gnus-newsgroup-data)
3355           (summary gnus-summary-buffer)
3356           (article-buffer gnus-article-buffer)
3357           (original gnus-original-article-buffer)
3358           (gac gnus-article-current)
3359           (reffed gnus-reffed-article-number)
3360           (score-file gnus-current-score-file)
3361           (default-charset gnus-newsgroup-charset)
3362           vlist)
3363       (let ((locals gnus-newsgroup-variables))
3364         (while locals
3365           (if (consp (car locals))
3366               (push (eval (caar locals)) vlist)
3367             (push (eval (car locals)) vlist))
3368           (setq locals (cdr locals)))
3369         (setq vlist (nreverse vlist)))
3370       (with-current-buffer gnus-group-buffer
3371         (setq gnus-newsgroup-name name
3372               gnus-newsgroup-marked marked
3373               gnus-newsgroup-spam-marked spam
3374               gnus-newsgroup-unreads unread
3375               gnus-current-headers headers
3376               gnus-newsgroup-data data
3377               gnus-article-current gac
3378               gnus-summary-buffer summary
3379               gnus-article-buffer article-buffer
3380               gnus-original-article-buffer original
3381               gnus-reffed-article-number reffed
3382               gnus-current-score-file score-file
3383               gnus-newsgroup-charset default-charset)
3384         (let ((locals gnus-newsgroup-variables))
3385           (while locals
3386             (if (consp (car locals))
3387                 (set (caar locals) (pop vlist))
3388               (set (car locals) (pop vlist)))
3389             (setq locals (cdr locals))))
3390         ;; The article buffer also has local variables.
3391         (when (gnus-buffer-live-p gnus-article-buffer)
3392           (set-buffer gnus-article-buffer)
3393           (setq gnus-summary-buffer summary))))))
3394
3395 (defun gnus-summary-article-unread-p (article)
3396   "Say whether ARTICLE is unread or not."
3397   (memq article gnus-newsgroup-unreads))
3398
3399 (defun gnus-summary-first-article-p (&optional article)
3400   "Return whether ARTICLE is the first article in the buffer."
3401   (if (not (setq article (or article (gnus-summary-article-number))))
3402       nil
3403     (eq article (caar gnus-newsgroup-data))))
3404
3405 (defun gnus-summary-last-article-p (&optional article)
3406   "Return whether ARTICLE is the last article in the buffer."
3407   (if (not (setq article (or article (gnus-summary-article-number))))
3408       ;; All non-existent numbers are the last article.  :-)
3409       t
3410     (not (cdr (gnus-data-find-list article)))))
3411
3412 (defun gnus-make-thread-indent-array ()
3413   (let ((n 200))
3414     (unless (and gnus-thread-indent-array
3415                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3416       (setq gnus-thread-indent-array (make-vector 201 "")
3417             gnus-thread-indent-array-level gnus-thread-indent-level)
3418       (while (>= n 0)
3419         (aset gnus-thread-indent-array n
3420               (make-string (* n gnus-thread-indent-level) ? ))
3421         (setq n (1- n))))))
3422
3423 (defun gnus-update-summary-mark-positions ()
3424   "Compute where the summary marks are to go."
3425   (save-excursion
3426     (when (gnus-buffer-exists-p gnus-summary-buffer)
3427       (set-buffer gnus-summary-buffer))
3428     (let ((spec gnus-summary-line-format-spec)
3429           pos)
3430       (save-excursion
3431         (gnus-set-work-buffer)
3432         (let ((gnus-tmp-unread ?Z)
3433               (gnus-replied-mark ?Z)
3434               (gnus-score-below-mark ?Z)
3435               (gnus-score-over-mark ?Z)
3436               (gnus-undownloaded-mark ?Z)
3437               (gnus-summary-line-format-spec spec)
3438               (gnus-newsgroup-downloadable '(0))
3439               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3440               case-fold-search ignores)
3441           ;; Here, all marks are bound to Z.
3442           (gnus-summary-insert-line header
3443                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3444           (goto-char (point-min))
3445           ;; Memorize the positions of the same characters as dummy marks.
3446           (while (re-search-forward "[A-D]" nil t)
3447             (push (point) ignores))
3448           (erase-buffer)
3449           ;; We use A-D as dummy marks in order to know column positions
3450           ;; where marks should be inserted.
3451           (setq gnus-tmp-unread ?A
3452                 gnus-replied-mark ?B
3453                 gnus-score-below-mark ?C
3454                 gnus-score-over-mark ?C
3455                 gnus-undownloaded-mark ?D)
3456           (gnus-summary-insert-line header
3457                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3458           ;; Ignore characters which aren't dummy marks.
3459           (dolist (p ignores)
3460             (delete-region (goto-char (1- p)) p)
3461             (insert ?Z))
3462           (goto-char (point-min))
3463           (setq pos (list (cons 'unread
3464                                 (and (search-forward "A" nil t)
3465                                      (- (point) (point-min) 1)))))
3466           (goto-char (point-min))
3467           (push (cons 'replied (and (search-forward "B" nil t)
3468                                     (- (point) (point-min) 1)))
3469                 pos)
3470           (goto-char (point-min))
3471           (push (cons 'score (and (search-forward "C" nil t)
3472                                   (- (point) (point-min) 1)))
3473                 pos)
3474           (goto-char (point-min))
3475           (push (cons 'download (and (search-forward "D" nil t)
3476                                      (- (point) (point-min) 1)))
3477                 pos)))
3478       (setq gnus-summary-mark-positions pos))))
3479
3480 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3481   "Insert a dummy root in the summary buffer."
3482   (beginning-of-line)
3483   (gnus-add-text-properties
3484    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3485    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3486
3487 (defun gnus-summary-extract-address-component (from)
3488   (or (car (funcall gnus-extract-address-components from))
3489       from))
3490
3491 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3492   (let ((mail-parse-charset gnus-newsgroup-charset)
3493         ; Is it really necessary to do this next part for each summary line?
3494         ; Luckily, doesn't seem to slow things down much.
3495         (mail-parse-ignored-charsets
3496          (with-current-buffer gnus-summary-buffer
3497            gnus-newsgroup-ignored-charsets)))
3498     (or
3499      (and gnus-ignored-from-addresses
3500           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3501           (let ((extra-headers (mail-header-extra header))
3502                 to
3503                 newsgroups)
3504             (cond
3505              ((setq to (cdr (assq 'To extra-headers)))
3506               (concat gnus-summary-to-prefix
3507                       (inline
3508                         (gnus-summary-extract-address-component
3509                          (funcall gnus-decode-encoded-word-function to)))))
3510              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3511               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3512      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3513
3514 (defun gnus-summary-insert-line (gnus-tmp-header
3515                                  gnus-tmp-level gnus-tmp-current
3516                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3517                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3518                                  &optional gnus-tmp-dummy gnus-tmp-score
3519                                  gnus-tmp-process)
3520   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3521          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3522          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3523          (gnus-tmp-score-char
3524           (if (or (null gnus-summary-default-score)
3525                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3526                       gnus-summary-zcore-fuzz))
3527               ?                         ;Whitespace
3528             (if (< gnus-tmp-score gnus-summary-default-score)
3529                 gnus-score-below-mark gnus-score-over-mark)))
3530          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3531          (gnus-tmp-replied
3532           (cond (gnus-tmp-process gnus-process-mark)
3533                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3534                  gnus-cached-mark)
3535                 (gnus-tmp-replied gnus-replied-mark)
3536                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3537                  gnus-forwarded-mark)
3538                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3539                  gnus-saved-mark)
3540                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3541                  gnus-recent-mark)
3542                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3543                  gnus-unseen-mark)
3544                 (t gnus-no-mark)))
3545          (gnus-tmp-downloaded
3546           (cond (undownloaded
3547                  gnus-undownloaded-mark)
3548                 (gnus-newsgroup-agentized
3549                  gnus-downloaded-mark)
3550                 (t
3551                  gnus-no-mark)))
3552          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3553          (gnus-tmp-name
3554           (cond
3555            ((string-match "<[^>]+> *$" gnus-tmp-from)
3556             (let ((beg (match-beginning 0)))
3557               (or (and (string-match "^\".+\"" gnus-tmp-from)
3558                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3559                   (substring gnus-tmp-from 0 beg))))
3560            ((string-match "(.+)" gnus-tmp-from)
3561             (substring gnus-tmp-from
3562                        (1+ (match-beginning 0)) (1- (match-end 0))))
3563            (t gnus-tmp-from)))
3564          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3565          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3566          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3567          (buffer-read-only nil))
3568     (when (string= gnus-tmp-name "")
3569       (setq gnus-tmp-name gnus-tmp-from))
3570     (unless (numberp gnus-tmp-lines)
3571       (setq gnus-tmp-lines -1))
3572     (if (= gnus-tmp-lines -1)
3573         (setq gnus-tmp-lines "?")
3574       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3575       (gnus-put-text-property
3576      (point)
3577      (progn (eval gnus-summary-line-format-spec) (point))
3578        'gnus-number gnus-tmp-number)
3579     (when (gnus-visual-p 'summary-highlight 'highlight)
3580       (forward-line -1)
3581       (gnus-run-hooks 'gnus-summary-update-hook)
3582       (forward-line 1))))
3583
3584 (defun gnus-summary-update-line (&optional dont-update)
3585   "Update summary line after change."
3586   (when (and gnus-summary-default-score
3587              (not gnus-summary-inhibit-highlight))
3588     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3589            (article (gnus-summary-article-number))
3590            (score (gnus-summary-article-score article)))
3591       (unless dont-update
3592         (if (and gnus-summary-mark-below
3593                  (< (gnus-summary-article-score)
3594                     gnus-summary-mark-below))
3595             ;; This article has a low score, so we mark it as read.
3596             (when (memq article gnus-newsgroup-unreads)
3597               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3598           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3599             ;; This article was previously marked as read on account
3600             ;; of a low score, but now it has risen, so we mark it as
3601             ;; unread.
3602             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3603         (gnus-summary-update-mark
3604          (if (or (null gnus-summary-default-score)
3605                  (<= (abs (- score gnus-summary-default-score))
3606                      gnus-summary-zcore-fuzz))
3607              ?                          ;Whitespace
3608            (if (< score gnus-summary-default-score)
3609                gnus-score-below-mark gnus-score-over-mark))
3610          'score))
3611       ;; Do visual highlighting.
3612       (when (gnus-visual-p 'summary-highlight 'highlight)
3613         (gnus-run-hooks 'gnus-summary-update-hook)))))
3614
3615 (defvar gnus-tmp-new-adopts nil)
3616
3617 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3618   "Return the number of articles in THREAD.
3619 This may be 0 in some cases -- if none of the articles in
3620 the thread are to be displayed."
3621   (let* ((number
3622          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3623           (cond
3624            ((not (listp thread))
3625             1)
3626            ((and (consp thread) (cdr thread))
3627             (apply
3628              '+ 1 (mapcar
3629                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3630            ((null thread)
3631             1)
3632            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3633             1)
3634            (t 0))))
3635     (when (and level (zerop level) gnus-tmp-new-adopts)
3636       (incf number
3637             (apply '+ (mapcar
3638                        'gnus-summary-number-of-articles-in-thread
3639                        gnus-tmp-new-adopts))))
3640     (if char
3641         (if (> number 1) gnus-not-empty-thread-mark
3642           gnus-empty-thread-mark)
3643       number)))
3644
3645 (defsubst gnus-summary-line-message-size (head)
3646   "Return pretty-printed version of message size.
3647 This function is intended to be used in
3648 `gnus-summary-line-format-alist'."
3649   (let ((c (or (mail-header-chars head) -1)))
3650     (cond ((< c 0) "n/a")               ; chars not available
3651           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3652           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3653           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3654           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3655
3656
3657 (defun gnus-summary-set-local-parameters (group)
3658   "Go through the local params of GROUP and set all variable specs in that list."
3659   (let ((vars '(quit-config)))          ; Ignore quit-config.
3660     (dolist (elem (gnus-group-find-parameter group))
3661       (and (consp elem)                 ; Has to be a cons.
3662            (consp (cdr elem))           ; The cdr has to be a list.
3663            (symbolp (car elem))         ; Has to be a symbol in there.
3664            (not (memq (car elem) vars))
3665            (ignore-errors               ; So we set it.
3666              (push (car elem) vars)
3667              (make-local-variable (car elem))
3668              (set (car elem) (eval (nth 1 elem))))))))
3669
3670 (defun gnus-summary-read-group (group &optional show-all no-article
3671                                       kill-buffer no-display backward
3672                                       select-articles)
3673   "Start reading news in newsgroup GROUP.
3674 If SHOW-ALL is non-nil, already read articles are also listed.
3675 If NO-ARTICLE is non-nil, no article is selected initially.
3676 If NO-DISPLAY, don't generate a summary buffer."
3677   (let (result)
3678     (while (and group
3679                 (null (setq result
3680                             (let ((gnus-auto-select-next nil))
3681                               (or (gnus-summary-read-group-1
3682                                    group show-all no-article
3683                                    kill-buffer no-display
3684                                    select-articles)
3685                                   (setq show-all nil
3686                                         select-articles nil)))))
3687                 (eq gnus-auto-select-next 'quietly))
3688       (set-buffer gnus-group-buffer)
3689       ;; The entry function called above goes to the next
3690       ;; group automatically, so we go two groups back
3691       ;; if we are searching for the previous group.
3692       (when backward
3693         (gnus-group-prev-unread-group 2))
3694       (if (not (equal group (gnus-group-group-name)))
3695           (setq group (gnus-group-group-name))
3696         (setq group nil)))
3697     result))
3698
3699 (defun gnus-summary-read-group-1 (group show-all no-article
3700                                         kill-buffer no-display
3701                                         &optional select-articles)
3702   ;; Killed foreign groups can't be entered.
3703   ;;  (when (and (not (gnus-group-native-p group))
3704   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3705   ;;    (error "Dead non-native groups can't be entered"))
3706   (gnus-message 5 "Retrieving newsgroup: %s..."
3707                 (gnus-group-decoded-name group))
3708   (let* ((new-group (gnus-summary-setup-buffer group))
3709          (quit-config (gnus-group-quit-config group))
3710          (did-select (and new-group (gnus-select-newsgroup
3711                                      group show-all select-articles))))
3712     (cond
3713      ;; This summary buffer exists already, so we just select it.
3714      ((not new-group)
3715       (gnus-set-global-variables)
3716       (when kill-buffer
3717         (gnus-kill-or-deaden-summary kill-buffer))
3718       (gnus-configure-windows 'summary 'force)
3719       (gnus-set-mode-line 'summary)
3720       (gnus-summary-position-point)
3721       (message "")
3722       t)
3723      ;; We couldn't select this group.
3724      ((null did-select)
3725       (when (and (eq major-mode 'gnus-summary-mode)
3726                  (not (equal (current-buffer) kill-buffer)))
3727         (kill-buffer (current-buffer))
3728         (if (not quit-config)
3729             (progn
3730               ;; Update the info -- marks might need to be removed,
3731               ;; for instance.
3732               (gnus-summary-update-info)
3733               (set-buffer gnus-group-buffer)
3734               (gnus-group-jump-to-group group)
3735               (gnus-group-next-unread-group 1))
3736           (gnus-handle-ephemeral-exit quit-config)))
3737       (let ((grpinfo (gnus-get-info group)))
3738         (if (null (gnus-info-read grpinfo))
3739             (gnus-message 3 "Group %s contains no messages"
3740                           (gnus-group-decoded-name group))
3741           (gnus-message 3 "Can't select group")))
3742       nil)
3743      ;; The user did a `C-g' while prompting for number of articles,
3744      ;; so we exit this group.
3745      ((eq did-select 'quit)
3746       (and (eq major-mode 'gnus-summary-mode)
3747            (not (equal (current-buffer) kill-buffer))
3748            (kill-buffer (current-buffer)))
3749       (when kill-buffer
3750         (gnus-kill-or-deaden-summary kill-buffer))
3751       (if (not quit-config)
3752           (progn
3753             (set-buffer gnus-group-buffer)
3754             (gnus-group-jump-to-group group)
3755             (gnus-group-next-unread-group 1)
3756             (gnus-configure-windows 'group 'force))
3757         (gnus-handle-ephemeral-exit quit-config))
3758       ;; Finally signal the quit.
3759       (signal 'quit nil))
3760      ;; The group was successfully selected.
3761      (t
3762       (gnus-set-global-variables)
3763       ;; Save the active value in effect when the group was entered.
3764       (setq gnus-newsgroup-active
3765             (gnus-copy-sequence
3766              (gnus-active gnus-newsgroup-name)))
3767       ;; You can change the summary buffer in some way with this hook.
3768       (gnus-run-hooks 'gnus-select-group-hook)
3769       (when (memq 'summary (gnus-update-format-specifications
3770                             nil 'summary 'summary-mode 'summary-dummy))
3771         ;; The format specification for the summary line was updated,
3772         ;; so we need to update the mark positions as well.
3773         (gnus-update-summary-mark-positions))
3774       ;; Do score processing.
3775       (when gnus-use-scoring
3776         (gnus-possibly-score-headers))
3777       ;; Check whether to fill in the gaps in the threads.
3778       (when gnus-build-sparse-threads
3779         (gnus-build-sparse-threads))
3780       ;; Find the initial limit.
3781       (if show-all
3782           (let ((gnus-newsgroup-dormant nil))
3783             (gnus-summary-initial-limit show-all))
3784         (gnus-summary-initial-limit show-all))
3785       ;; Generate the summary buffer.
3786       (unless no-display
3787         (gnus-summary-prepare))
3788       (when gnus-use-trees
3789         (gnus-tree-open group)
3790         (setq gnus-summary-highlight-line-function
3791               'gnus-tree-highlight-article))
3792       ;; If the summary buffer is empty, but there are some low-scored
3793       ;; articles or some excluded dormants, we include these in the
3794       ;; buffer.
3795       (when (and (zerop (buffer-size))
3796                  (not no-display))
3797         (cond (gnus-newsgroup-dormant
3798                (gnus-summary-limit-include-dormant))
3799               ((and gnus-newsgroup-scored show-all)
3800                (gnus-summary-limit-include-expunged t))))
3801       ;; Function `gnus-apply-kill-file' must be called in this hook.
3802       (gnus-run-hooks 'gnus-apply-kill-hook)
3803       (if (and (zerop (buffer-size))
3804                (not no-display))
3805           (progn
3806             ;; This newsgroup is empty.
3807             (gnus-summary-catchup-and-exit nil t)
3808             (gnus-message 6 "No unread news")
3809             (when kill-buffer
3810               (gnus-kill-or-deaden-summary kill-buffer))
3811             ;; Return nil from this function.
3812             nil)
3813         ;; Hide conversation thread subtrees.  We cannot do this in
3814         ;; gnus-summary-prepare-hook since kill processing may not
3815         ;; work with hidden articles.
3816         (gnus-summary-maybe-hide-threads)
3817         (when kill-buffer
3818           (gnus-kill-or-deaden-summary kill-buffer))
3819         (gnus-summary-auto-select-subject)
3820         ;; Show first unread article if requested.
3821         (if (and (not no-article)
3822                  (not no-display)
3823                  gnus-newsgroup-unreads
3824                  gnus-auto-select-first)
3825             (progn
3826               (gnus-configure-windows 'summary)
3827               (let ((art (gnus-summary-article-number)))
3828                 (unless (and (not gnus-plugged)
3829                              (or (memq art gnus-newsgroup-undownloaded)
3830                                  (memq art gnus-newsgroup-downloadable)))
3831                   (gnus-summary-goto-article art))))
3832           ;; Don't select any articles.
3833           (gnus-summary-position-point)
3834           (gnus-configure-windows 'summary 'force)
3835           (gnus-set-mode-line 'summary))
3836         (when (and gnus-auto-center-group
3837                    (get-buffer-window gnus-group-buffer t))
3838           ;; Gotta use windows, because recenter does weird stuff if
3839           ;; the current buffer ain't the displayed window.
3840           (let ((owin (selected-window)))
3841             (select-window (get-buffer-window gnus-group-buffer t))
3842             (when (gnus-group-goto-group group)
3843               (recenter))
3844             (select-window owin)))
3845         ;; Mark this buffer as "prepared".
3846         (setq gnus-newsgroup-prepared t)
3847         (gnus-run-hooks 'gnus-summary-prepared-hook)
3848         (unless (gnus-ephemeral-group-p group)
3849           (gnus-group-update-group group))
3850         t)))))
3851
3852 (defun gnus-summary-auto-select-subject ()
3853   "Select the subject line on initial group entry."
3854   (goto-char (point-min))
3855   (cond
3856    ((eq gnus-auto-select-subject 'best)
3857     (gnus-summary-best-unread-subject))
3858    ((eq gnus-auto-select-subject 'unread)
3859     (gnus-summary-first-unread-subject))
3860    ((eq gnus-auto-select-subject 'unseen)
3861     (gnus-summary-first-unseen-subject))
3862    ((eq gnus-auto-select-subject 'unseen-or-unread)
3863     (gnus-summary-first-unseen-or-unread-subject))
3864    ((eq gnus-auto-select-subject 'first)
3865     ;; Do nothing.
3866     )
3867    ((functionp gnus-auto-select-subject)
3868     (funcall gnus-auto-select-subject))))
3869
3870 (defun gnus-summary-prepare ()
3871   "Generate the summary buffer."
3872   (interactive)
3873   (let ((buffer-read-only nil))
3874     (erase-buffer)
3875     (setq gnus-newsgroup-data nil
3876           gnus-newsgroup-data-reverse nil)
3877     (gnus-run-hooks 'gnus-summary-generate-hook)
3878     ;; Generate the buffer, either with threads or without.
3879     (when gnus-newsgroup-headers
3880       (gnus-summary-prepare-threads
3881        (if gnus-show-threads
3882            (gnus-sort-gathered-threads
3883             (funcall gnus-summary-thread-gathering-function
3884                      (gnus-sort-threads
3885                       (gnus-cut-threads (gnus-make-threads)))))
3886          ;; Unthreaded display.
3887          (gnus-sort-articles gnus-newsgroup-headers))))
3888     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3889     ;; Call hooks for modifying summary buffer.
3890     (goto-char (point-min))
3891     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3892
3893 (defsubst gnus-general-simplify-subject (subject)
3894   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3895   (setq subject
3896         (cond
3897          ;; Truncate the subject.
3898          (gnus-simplify-subject-functions
3899           (gnus-map-function gnus-simplify-subject-functions subject))
3900          ((numberp gnus-summary-gather-subject-limit)
3901           (setq subject (gnus-simplify-subject-re subject))
3902           (if (> (length subject) gnus-summary-gather-subject-limit)
3903               (substring subject 0 gnus-summary-gather-subject-limit)
3904             subject))
3905          ;; Fuzzily simplify it.
3906          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3907           (gnus-simplify-subject-fuzzy subject))
3908          ;; Just remove the leading "Re:".
3909          (t
3910           (gnus-simplify-subject-re subject))))
3911
3912   (if (and gnus-summary-gather-exclude-subject
3913            (string-match gnus-summary-gather-exclude-subject subject))
3914       nil                         ; This article shouldn't be gathered
3915     subject))
3916
3917 (defun gnus-summary-simplify-subject-query ()
3918   "Query where the respool algorithm would put this article."
3919   (interactive)
3920   (gnus-summary-select-article)
3921   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3922
3923 (defun gnus-gather-threads-by-subject (threads)
3924   "Gather threads by looking at Subject headers."
3925   (if (not gnus-summary-make-false-root)
3926       threads
3927     (let ((hashtb (gnus-make-hashtable 1024))
3928           (prev threads)
3929           (result threads)
3930           subject hthread whole-subject)
3931       (while threads
3932         (setq subject (gnus-general-simplify-subject
3933                        (setq whole-subject (mail-header-subject
3934                                             (caar threads)))))
3935         (when subject
3936           (if (setq hthread (gnus-gethash subject hashtb))
3937               (progn
3938                 ;; We enter a dummy root into the thread, if we
3939                 ;; haven't done that already.
3940                 (unless (stringp (caar hthread))
3941                   (setcar hthread (list whole-subject (car hthread))))
3942                 ;; We add this new gathered thread to this gathered
3943                 ;; thread.
3944                 (setcdr (car hthread)
3945                         (nconc (cdar hthread) (list (car threads))))
3946                 ;; Remove it from the list of threads.
3947                 (setcdr prev (cdr threads))
3948                 (setq threads prev))
3949             ;; Enter this thread into the hash table.
3950             (gnus-sethash subject
3951                           (if gnus-summary-make-false-root-always
3952                               (progn
3953                                 ;; If you want a dummy root above all
3954                                 ;; threads...
3955                                 (setcar threads (list whole-subject
3956                                                       (car threads)))
3957                                 threads)
3958                             threads)
3959                           hashtb)))
3960         (setq prev threads)
3961         (setq threads (cdr threads)))
3962       result)))
3963
3964 (defun gnus-gather-threads-by-references (threads)
3965   "Gather threads by looking at References headers."
3966   (let ((idhashtb (gnus-make-hashtable 1024))
3967         (thhashtb (gnus-make-hashtable 1024))
3968         (prev threads)
3969         (result threads)
3970         ids references id gthread gid entered ref)
3971     (while threads
3972       (when (setq references (mail-header-references (caar threads)))
3973         (setq id (mail-header-id (caar threads))
3974               ids (inline (gnus-split-references references))
3975               entered nil)
3976         (while (setq ref (pop ids))
3977           (setq ids (delete ref ids))
3978           (if (not (setq gid (gnus-gethash ref idhashtb)))
3979               (progn
3980                 (gnus-sethash ref id idhashtb)
3981                 (gnus-sethash id threads thhashtb))
3982             (setq gthread (gnus-gethash gid thhashtb))
3983             (unless entered
3984               ;; We enter a dummy root into the thread, if we
3985               ;; haven't done that already.
3986               (unless (stringp (caar gthread))
3987                 (setcar gthread (list (mail-header-subject (caar gthread))
3988                                       (car gthread))))
3989               ;; We add this new gathered thread to this gathered
3990               ;; thread.
3991               (setcdr (car gthread)
3992                       (nconc (cdar gthread) (list (car threads)))))
3993             ;; Add it into the thread hash table.
3994             (gnus-sethash id gthread thhashtb)
3995             (setq entered t)
3996             ;; Remove it from the list of threads.
3997             (setcdr prev (cdr threads))
3998             (setq threads prev))))
3999       (setq prev threads)
4000       (setq threads (cdr threads)))
4001     result))
4002
4003 (defun gnus-sort-gathered-threads (threads)
4004   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4005   (let ((result threads))
4006     (while threads
4007       (when (stringp (caar threads))
4008         (setcdr (car threads)
4009                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4010       (setq threads (cdr threads)))
4011     result))
4012
4013 (defun gnus-thread-loop-p (root thread)
4014   "Say whether ROOT is in THREAD."
4015   (let ((stack (list thread))
4016         (infloop 0)
4017         th)
4018     (while (setq thread (pop stack))
4019       (setq th (cdr thread))
4020       (while (and th
4021                   (not (eq (caar th) root)))
4022         (pop th))
4023       (if th
4024           ;; We have found a loop.
4025           (let (ref-dep)
4026             (setcdr thread (delq (car th) (cdr thread)))
4027             (if (boundp (setq ref-dep (intern "none"
4028                                               gnus-newsgroup-dependencies)))
4029                 (setcdr (symbol-value ref-dep)
4030                         (nconc (cdr (symbol-value ref-dep))
4031                                (list (car th))))
4032               (set ref-dep (list nil (car th))))
4033             (setq infloop 1
4034                   stack nil))
4035         ;; Push all the subthreads onto the stack.
4036         (push (cdr thread) stack)))
4037     infloop))
4038
4039 (defun gnus-make-threads ()
4040   "Go through the dependency hashtb and find the roots.  Return all threads."
4041   (let (threads)
4042     (while (catch 'infloop
4043              (mapatoms
4044               (lambda (refs)
4045                 ;; Deal with self-referencing References loops.
4046                 (when (and (car (symbol-value refs))
4047                            (not (zerop
4048                                  (apply
4049                                   '+
4050                                   (mapcar
4051                                    (lambda (thread)
4052                                      (gnus-thread-loop-p
4053                                       (car (symbol-value refs)) thread))
4054                                    (cdr (symbol-value refs)))))))
4055                   (setq threads nil)
4056                   (throw 'infloop t))
4057                 (unless (car (symbol-value refs))
4058                   ;; These threads do not refer back to any other
4059                   ;; articles, so they're roots.
4060                   (setq threads (append (cdr (symbol-value refs)) threads))))
4061               gnus-newsgroup-dependencies)))
4062     threads))
4063
4064 ;; Build the thread tree.
4065 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4066   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4067
4068 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4069 if it was already present.
4070
4071 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4072 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4073 Message-IDs will be renamed to a unique Message-ID before being
4074 entered.
4075
4076 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4077   (let* ((id (mail-header-id header))
4078          (id-dep (and id (intern id dependencies)))
4079          parent-id ref ref-dep ref-header replaced)
4080     ;; Enter this `header' in the `dependencies' table.
4081     (cond
4082      ((not id-dep)
4083       (setq header nil))
4084      ;; The first two cases do the normal part: enter a new `header'
4085      ;; in the `dependencies' table.
4086      ((not (boundp id-dep))
4087       (set id-dep (list header)))
4088      ((null (car (symbol-value id-dep)))
4089       (setcar (symbol-value id-dep) header))
4090
4091      ;; From here the `header' was already present in the
4092      ;; `dependencies' table.
4093      (force-new
4094       ;; Overrides an existing entry;
4095       ;; just set the header part of the entry.
4096       (setcar (symbol-value id-dep) header)
4097       (setq replaced t))
4098
4099      ;; Renames the existing `header' to a unique Message-ID.
4100      ((not gnus-summary-ignore-duplicates)
4101       ;; An article with this Message-ID has already been seen.
4102       ;; We rename the Message-ID.
4103       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4104            (list header))
4105       (mail-header-set-id header id))
4106
4107      ;; The last case ignores an existing entry, except it adds any
4108      ;; additional Xrefs (in case the two articles came from different
4109      ;; servers.
4110      ;; Also sets `header' to `nil' meaning that the `dependencies'
4111      ;; table was *not* modified.
4112      (t
4113       (mail-header-set-xref
4114        (car (symbol-value id-dep))
4115        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4116                    "")
4117                (or (mail-header-xref header) "")))
4118       (setq header nil)))
4119
4120     (when (and header (not replaced))
4121       ;; First check that we are not creating a References loop.
4122       (setq parent-id (gnus-parent-id (mail-header-references header)))
4123       (setq ref parent-id)
4124       (while (and ref
4125                   (setq ref-dep (intern-soft ref dependencies))
4126                   (boundp ref-dep)
4127                   (setq ref-header (car (symbol-value ref-dep))))
4128         (if (string= id ref)
4129             ;; Yuk!  This is a reference loop.  Make the article be a
4130             ;; root article.
4131             (progn
4132               (mail-header-set-references (car (symbol-value id-dep)) "none")
4133               (setq ref nil)
4134               (setq parent-id nil))
4135           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4136       (setq ref-dep (intern (or parent-id "none") dependencies))
4137       (if (boundp ref-dep)
4138           (setcdr (symbol-value ref-dep)
4139                   (nconc (cdr (symbol-value ref-dep))
4140                          (list (symbol-value id-dep))))
4141         (set ref-dep (list nil (symbol-value id-dep)))))
4142     header))
4143
4144 (defun gnus-extract-message-id-from-in-reply-to (string)
4145   (if (string-match "<[^>]+>" string)
4146       (substring string (match-beginning 0) (match-end 0))
4147     nil))
4148
4149 (defun gnus-build-sparse-threads ()
4150   (let ((headers gnus-newsgroup-headers)
4151         (mail-parse-charset gnus-newsgroup-charset)
4152         (gnus-summary-ignore-duplicates t)
4153         header references generation relations
4154         subject child end new-child date)
4155     ;; First we create an alist of generations/relations, where
4156     ;; generations is how much we trust the relation, and the relation
4157     ;; is parent/child.
4158     (gnus-message 7 "Making sparse threads...")
4159     (save-excursion
4160       (nnheader-set-temp-buffer " *gnus sparse threads*")
4161       (while (setq header (pop headers))
4162         (when (and (setq references (mail-header-references header))
4163                    (not (string= references "")))
4164           (insert references)
4165           (setq child (mail-header-id header)
4166                 subject (mail-header-subject header)
4167                 date (mail-header-date header)
4168                 generation 0)
4169           (while (search-backward ">" nil t)
4170             (setq end (1+ (point)))
4171             (when (search-backward "<" nil t)
4172               (setq new-child (buffer-substring (point) end))
4173               (push (list (incf generation)
4174                           child (setq child new-child)
4175                           subject date)
4176                     relations)))
4177           (when child
4178             (push (list (1+ generation) child nil subject) relations))
4179           (erase-buffer)))
4180       (kill-buffer (current-buffer)))
4181     ;; Sort over trustworthiness.
4182     (mapcar
4183      (lambda (relation)
4184        (when (gnus-dependencies-add-header
4185               (make-full-mail-header
4186                gnus-reffed-article-number
4187                (nth 3 relation) "" (or (nth 4 relation) "")
4188                (nth 1 relation)
4189                (or (nth 2 relation) "") 0 0 "")
4190               gnus-newsgroup-dependencies nil)
4191          (push gnus-reffed-article-number gnus-newsgroup-limit)
4192          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4193          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4194                gnus-newsgroup-reads)
4195          (decf gnus-reffed-article-number)))
4196      (sort relations 'car-less-than-car))
4197     (gnus-message 7 "Making sparse threads...done")))
4198
4199 (defun gnus-build-old-threads ()
4200   ;; Look at all the articles that refer back to old articles, and
4201   ;; fetch the headers for the articles that aren't there.  This will
4202   ;; build complete threads - if the roots haven't been expired by the
4203   ;; server, that is.
4204   (let ((mail-parse-charset gnus-newsgroup-charset)
4205         id heads)
4206     (mapatoms
4207      (lambda (refs)
4208        (when (not (car (symbol-value refs)))
4209          (setq heads (cdr (symbol-value refs)))
4210          (while heads
4211            (if (memq (mail-header-number (caar heads))
4212                      gnus-newsgroup-dormant)
4213                (setq heads (cdr heads))
4214              (setq id (symbol-name refs))
4215              (while (and (setq id (gnus-build-get-header id))
4216                          (not (car (gnus-id-to-thread id)))))
4217              (setq heads nil)))))
4218      gnus-newsgroup-dependencies)))
4219
4220 (defsubst gnus-remove-odd-characters (string)
4221   "Translate STRING into something that doesn't contain weird characters."
4222   (mm-subst-char-in-string
4223    ?\r ?\-
4224    (mm-subst-char-in-string ?\n ?\- string t) t))
4225
4226 ;; This function has to be called with point after the article number
4227 ;; on the beginning of the line.
4228 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4229   (let ((eol (point-at-eol))
4230         (buffer (current-buffer))
4231         header references in-reply-to)
4232
4233     ;; overview: [num subject from date id refs chars lines misc]
4234     (unwind-protect
4235         (let (x)
4236           (narrow-to-region (point) eol)
4237           (unless (eobp)
4238             (forward-char))
4239
4240           (setq header
4241                 (make-full-mail-header
4242                  number                 ; number
4243                  (condition-case ()     ; subject
4244                      (gnus-remove-odd-characters
4245                       (funcall gnus-decode-encoded-word-function
4246                                (setq x (nnheader-nov-field))))
4247                    (error x))
4248                  (condition-case ()     ; from
4249                      (gnus-remove-odd-characters
4250                       (funcall gnus-decode-encoded-word-function
4251                                (setq x (nnheader-nov-field))))
4252                    (error x))
4253                  (nnheader-nov-field)   ; date
4254                  (nnheader-nov-read-message-id number)  ; id
4255                  (setq references (nnheader-nov-field)) ; refs
4256                  (nnheader-nov-read-integer) ; chars
4257                  (nnheader-nov-read-integer) ; lines
4258                  (unless (eobp)
4259                    (if (looking-at "Xref: ")
4260                        (goto-char (match-end 0)))
4261                    (nnheader-nov-field)) ; Xref
4262                  (nnheader-nov-parse-extra)))) ; extra
4263
4264       (widen))
4265
4266     (when (and (string= references "")
4267                (setq in-reply-to (mail-header-extra header))
4268                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4269       (mail-header-set-references
4270        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4271
4272     (when gnus-alter-header-function
4273       (funcall gnus-alter-header-function header))
4274     (gnus-dependencies-add-header header dependencies force-new)))
4275
4276 (defun gnus-build-get-header (id)
4277   "Look through the buffer of NOV lines and find the header to ID.
4278 Enter this line into the dependencies hash table, and return
4279 the id of the parent article (if any)."
4280   (let ((deps gnus-newsgroup-dependencies)
4281         found header)
4282     (prog1
4283         (save-excursion
4284           (set-buffer nntp-server-buffer)
4285           (let ((case-fold-search nil))
4286             (goto-char (point-min))
4287             (while (and (not found)
4288                         (search-forward id nil t))
4289               (beginning-of-line)
4290               (setq found (looking-at
4291                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4292                                    (regexp-quote id))))
4293               (or found (beginning-of-line 2)))
4294             (when found
4295               (beginning-of-line)
4296               (and
4297                (setq header (gnus-nov-parse-line
4298                              (read (current-buffer)) deps))
4299                (gnus-parent-id (mail-header-references header))))))
4300       (when header
4301         (let ((number (mail-header-number header)))
4302           (push number gnus-newsgroup-limit)
4303           (push header gnus-newsgroup-headers)
4304           (if (memq number gnus-newsgroup-unselected)
4305               (progn
4306                 (setq gnus-newsgroup-unreads
4307                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4308                                                number))
4309                 (setq gnus-newsgroup-unselected
4310                       (delq number gnus-newsgroup-unselected)))
4311             (push number gnus-newsgroup-ancient)))))))
4312
4313 (defun gnus-build-all-threads ()
4314   "Read all the headers."
4315   (let ((gnus-summary-ignore-duplicates t)
4316         (mail-parse-charset gnus-newsgroup-charset)
4317         (dependencies gnus-newsgroup-dependencies)
4318         header article)
4319     (save-excursion
4320       (set-buffer nntp-server-buffer)
4321       (let ((case-fold-search nil))
4322         (goto-char (point-min))
4323         (while (not (eobp))
4324           (ignore-errors
4325             (setq article (read (current-buffer))
4326                   header (gnus-nov-parse-line article dependencies)))
4327           (when header
4328             (with-current-buffer gnus-summary-buffer
4329               (push header gnus-newsgroup-headers)
4330               (if (memq (setq article (mail-header-number header))
4331                         gnus-newsgroup-unselected)
4332                   (progn
4333                     (setq gnus-newsgroup-unreads
4334                           (gnus-add-to-sorted-list
4335                            gnus-newsgroup-unreads article))
4336                     (setq gnus-newsgroup-unselected
4337                           (delq article gnus-newsgroup-unselected)))
4338                 (push article gnus-newsgroup-ancient)))
4339             (forward-line 1)))))))
4340
4341 (defun gnus-summary-update-article-line (article header)
4342   "Update the line for ARTICLE using HEADER."
4343   (let* ((id (mail-header-id header))
4344          (thread (gnus-id-to-thread id)))
4345     (unless thread
4346       (error "Article in no thread"))
4347     ;; Update the thread.
4348     (setcar thread header)
4349     (gnus-summary-goto-subject article)
4350     (let* ((datal (gnus-data-find-list article))
4351            (data (car datal))
4352            (buffer-read-only nil)
4353            (level (gnus-summary-thread-level)))
4354       (gnus-delete-line)
4355       (let ((inserted (- (point)
4356                          (progn
4357                            (gnus-summary-insert-line
4358                             header level nil
4359                             (memq article gnus-newsgroup-undownloaded)
4360                             (gnus-article-mark article)
4361                             (memq article gnus-newsgroup-replied)
4362                             (memq article gnus-newsgroup-expirable)
4363                             ;; Only insert the Subject string when it's different
4364                             ;; from the previous Subject string.
4365                             (if (and
4366                                  gnus-show-threads
4367                                  (gnus-subject-equal
4368                                   (condition-case ()
4369                                       (mail-header-subject
4370                                        (gnus-data-header
4371                                         (cadr
4372                                          (gnus-data-find-list
4373                                           article
4374                                           (gnus-data-list t)))))
4375                                     ;; Error on the side of excessive subjects.
4376                                     (error ""))
4377                                   (mail-header-subject header)))
4378                                 ""
4379                               (mail-header-subject header))
4380                             nil (cdr (assq article gnus-newsgroup-scored))
4381                             (memq article gnus-newsgroup-processable))
4382                            (point)))))
4383         (when (cdr datal)
4384           (gnus-data-update-list
4385            (cdr datal)
4386            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4387
4388 (defun gnus-summary-update-article (article &optional iheader)
4389   "Update ARTICLE in the summary buffer."
4390   (set-buffer gnus-summary-buffer)
4391   (let* ((header (gnus-summary-article-header article))
4392          (id (mail-header-id header))
4393          (data (gnus-data-find article))
4394          (thread (gnus-id-to-thread id))
4395          (references (mail-header-references header))
4396          (parent
4397           (gnus-id-to-thread
4398            (or (gnus-parent-id
4399                 (when (and references
4400                            (not (equal "" references)))
4401                   references))
4402                "none")))
4403          (buffer-read-only nil)
4404          (old (car thread)))
4405     (when thread
4406       (unless iheader
4407         (setcar thread nil)
4408         (when parent
4409           (delq thread parent)))
4410       (if (gnus-summary-insert-subject id header)
4411           ;; Set the (possibly) new article number in the data structure.
4412           (gnus-data-set-number data (gnus-id-to-article id))
4413         (setcar thread old)
4414         nil))))
4415
4416 (defun gnus-rebuild-thread (id &optional line)
4417   "Rebuild the thread containing ID.
4418 If LINE, insert the rebuilt thread starting on line LINE."
4419   (let ((buffer-read-only nil)
4420         old-pos current thread data)
4421     (if (not gnus-show-threads)
4422         (setq thread (list (car (gnus-id-to-thread id))))
4423       ;; Get the thread this article is part of.
4424       (setq thread (gnus-remove-thread id)))
4425     (setq old-pos (point-at-bol))
4426     (setq current (save-excursion
4427                     (and (re-search-backward "[\r\n]" nil t)
4428                          (gnus-summary-article-number))))
4429     ;; If this is a gathered thread, we have to go some re-gathering.
4430     (when (stringp (car thread))
4431       (let ((subject (car thread))
4432             roots thr)
4433         (setq thread (cdr thread))
4434         (while thread
4435           (unless (memq (setq thr (gnus-id-to-thread
4436                                    (gnus-root-id
4437                                     (mail-header-id (caar thread)))))
4438                         roots)
4439             (push thr roots))
4440           (setq thread (cdr thread)))
4441         ;; We now have all (unique) roots.
4442         (if (= (length roots) 1)
4443             ;; All the loose roots are now one solid root.
4444             (setq thread (car roots))
4445           (setq thread (cons subject (gnus-sort-threads roots))))))
4446     (let (threads)
4447       ;; We then insert this thread into the summary buffer.
4448       (when line
4449         (goto-char (point-min))
4450         (forward-line (1- line)))
4451       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4452         (if gnus-show-threads
4453             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4454           (gnus-summary-prepare-unthreaded thread))
4455         (setq data (nreverse gnus-newsgroup-data))
4456         (setq threads gnus-newsgroup-threads))
4457       ;; We splice the new data into the data structure.
4458       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4459       ;;!!! then we want to insert at the beginning of the buffer.
4460       ;;!!! That happens to be true with Gnus now, but that may
4461       ;;!!! change in the future.  Perhaps.
4462       (gnus-data-enter-list
4463        (if line nil current) data (- (point) old-pos))
4464       (setq gnus-newsgroup-threads
4465             (nconc threads gnus-newsgroup-threads))
4466       (gnus-data-compute-positions))))
4467
4468 (defun gnus-number-to-header (number)
4469   "Return the header for article NUMBER."
4470   (let ((headers gnus-newsgroup-headers))
4471     (while (and headers
4472                 (not (= number (mail-header-number (car headers)))))
4473       (pop headers))
4474     (when headers
4475       (car headers))))
4476
4477 (defun gnus-parent-headers (in-headers &optional generation)
4478   "Return the headers of the GENERATIONeth parent of HEADERS."
4479   (unless generation
4480     (setq generation 1))
4481   (let ((parent t)
4482         (headers in-headers)
4483         references)
4484     (while (and parent
4485                 (not (zerop generation))
4486                 (setq references (mail-header-references headers)))
4487       (setq headers (if (and references
4488                              (setq parent (gnus-parent-id references)))
4489                         (car (gnus-id-to-thread parent))
4490                       nil))
4491       (decf generation))
4492     (and (not (eq headers in-headers))
4493          headers)))
4494
4495 (defun gnus-id-to-thread (id)
4496   "Return the (sub-)thread where ID appears."
4497   (gnus-gethash id gnus-newsgroup-dependencies))
4498
4499 (defun gnus-id-to-article (id)
4500   "Return the article number of ID."
4501   (let ((thread (gnus-id-to-thread id)))
4502     (when (and thread
4503                (car thread))
4504       (mail-header-number (car thread)))))
4505
4506 (defun gnus-id-to-header (id)
4507   "Return the article headers of ID."
4508   (car (gnus-id-to-thread id)))
4509
4510 (defun gnus-article-displayed-root-p (article)
4511   "Say whether ARTICLE is a root(ish) article."
4512   (let ((level (gnus-summary-thread-level article))
4513         (refs (mail-header-references  (gnus-summary-article-header article)))
4514         particle)
4515     (cond
4516      ((null level) nil)
4517      ((zerop level) t)
4518      ((null refs) t)
4519      ((null (gnus-parent-id refs)) t)
4520      ((and (= 1 level)
4521            (null (setq particle (gnus-id-to-article
4522                                  (gnus-parent-id refs))))
4523            (null (gnus-summary-thread-level particle)))))))
4524
4525 (defun gnus-root-id (id)
4526   "Return the id of the root of the thread where ID appears."
4527   (let (last-id prev)
4528     (while (and id (setq prev (car (gnus-id-to-thread id))))
4529       (setq last-id id
4530             id (gnus-parent-id (mail-header-references prev))))
4531     last-id))
4532
4533 (defun gnus-articles-in-thread (thread)
4534   "Return the list of articles in THREAD."
4535   (cons (mail-header-number (car thread))
4536         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4537
4538 (defun gnus-remove-thread (id &optional dont-remove)
4539   "Remove the thread that has ID in it."
4540   (let (headers thread last-id)
4541     ;; First go up in this thread until we find the root.
4542     (setq last-id (gnus-root-id id)
4543           headers (message-flatten-list (gnus-id-to-thread last-id)))
4544     ;; We have now found the real root of this thread.  It might have
4545     ;; been gathered into some loose thread, so we have to search
4546     ;; through the threads to find the thread we wanted.
4547     (let ((threads gnus-newsgroup-threads)
4548           sub)
4549       (while threads
4550         (setq sub (car threads))
4551         (if (stringp (car sub))
4552             ;; This is a gathered thread, so we look at the roots
4553             ;; below it to find whether this article is in this
4554             ;; gathered root.
4555             (progn
4556               (setq sub (cdr sub))
4557               (while sub
4558                 (when (member (caar sub) headers)
4559                   (setq thread (car threads)
4560                         threads nil
4561                         sub nil))
4562                 (setq sub (cdr sub))))
4563           ;; It's an ordinary thread, so we check it.
4564           (when (eq (car sub) (car headers))
4565             (setq thread sub
4566                   threads nil)))
4567         (setq threads (cdr threads)))
4568       ;; If this article is in no thread, then it's a root.
4569       (if thread
4570           (unless dont-remove
4571             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4572         (setq thread (gnus-id-to-thread last-id)))
4573       (when thread
4574         (prog1
4575             thread                      ; We return this thread.
4576           (unless dont-remove
4577             (if (stringp (car thread))
4578                 (progn
4579                   ;; If we use dummy roots, then we have to remove the
4580                   ;; dummy root as well.
4581                   (when (eq gnus-summary-make-false-root 'dummy)
4582                     ;; We go to the dummy root by going to
4583                     ;; the first sub-"thread", and then one line up.
4584                     (gnus-summary-goto-article
4585                      (mail-header-number (caadr thread)))
4586                     (forward-line -1)
4587                     (gnus-delete-line)
4588                     (gnus-data-compute-positions))
4589                   (setq thread (cdr thread))
4590                   (while thread
4591                     (gnus-remove-thread-1 (car thread))
4592                     (setq thread (cdr thread))))
4593               (gnus-remove-thread-1 thread))))))))
4594
4595 (defun gnus-remove-thread-1 (thread)
4596   "Remove the thread THREAD recursively."
4597   (let ((number (mail-header-number (pop thread)))
4598         d)
4599     (setq thread (reverse thread))
4600     (while thread
4601       (gnus-remove-thread-1 (pop thread)))
4602     (when (setq d (gnus-data-find number))
4603       (goto-char (gnus-data-pos d))
4604       (gnus-summary-show-thread)
4605       (gnus-data-remove
4606        number
4607        (- (point-at-bol)
4608           (prog1
4609               (1+ (point-at-eol))
4610             (gnus-delete-line)))))))
4611
4612 (defun gnus-sort-threads-1 (threads func)
4613   (sort (mapcar (lambda (thread)
4614                   (cons (car thread)
4615                         (and (cdr thread)
4616                              (gnus-sort-threads-1 (cdr thread) func))))
4617                 threads) func))
4618
4619 (defun gnus-sort-threads (threads)
4620   "Sort THREADS."
4621   (if (not gnus-thread-sort-functions)
4622       threads
4623     (gnus-message 8 "Sorting threads...")
4624     (let ((max-lisp-eval-depth 5000))
4625       (prog1 (gnus-sort-threads-1
4626          threads
4627          (gnus-make-sort-function gnus-thread-sort-functions))
4628         (gnus-message 8 "Sorting threads...done")))))
4629
4630 (defun gnus-sort-articles (articles)
4631   "Sort ARTICLES."
4632   (when gnus-article-sort-functions
4633     (gnus-message 7 "Sorting articles...")
4634     (prog1
4635         (setq gnus-newsgroup-headers
4636               (sort articles (gnus-make-sort-function
4637                               gnus-article-sort-functions)))
4638       (gnus-message 7 "Sorting articles...done"))))
4639
4640 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4641 (defmacro gnus-thread-header (thread)
4642   "Return header of first article in THREAD.
4643 Note that THREAD must never, ever be anything else than a variable -
4644 using some other form will lead to serious barfage."
4645   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4646   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4647   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4648         (vector thread) 2))
4649
4650 (defsubst gnus-article-sort-by-number (h1 h2)
4651   "Sort articles by article number."
4652   (< (mail-header-number h1)
4653      (mail-header-number h2)))
4654
4655 (defun gnus-thread-sort-by-number (h1 h2)
4656   "Sort threads by root article number."
4657   (gnus-article-sort-by-number
4658    (gnus-thread-header h1) (gnus-thread-header h2)))
4659
4660 (defsubst gnus-article-sort-by-random (h1 h2)
4661   "Sort articles by article number."
4662   (zerop (random 2)))
4663
4664 (defun gnus-thread-sort-by-random (h1 h2)
4665   "Sort threads by root article number."
4666   (gnus-article-sort-by-random
4667    (gnus-thread-header h1) (gnus-thread-header h2)))
4668
4669 (defsubst gnus-article-sort-by-lines (h1 h2)
4670   "Sort articles by article Lines header."
4671   (< (mail-header-lines h1)
4672      (mail-header-lines h2)))
4673
4674 (defun gnus-thread-sort-by-lines (h1 h2)
4675   "Sort threads by root article Lines header."
4676   (gnus-article-sort-by-lines
4677    (gnus-thread-header h1) (gnus-thread-header h2)))
4678
4679 (defsubst gnus-article-sort-by-chars (h1 h2)
4680   "Sort articles by octet length."
4681   (< (mail-header-chars h1)
4682      (mail-header-chars h2)))
4683
4684 (defun gnus-thread-sort-by-chars (h1 h2)
4685   "Sort threads by root article octet length."
4686   (gnus-article-sort-by-chars
4687    (gnus-thread-header h1) (gnus-thread-header h2)))
4688
4689 (defsubst gnus-article-sort-by-author (h1 h2)
4690   "Sort articles by root author."
4691   (string-lessp
4692    (let ((extract (funcall
4693                    gnus-extract-address-components
4694                    (mail-header-from h1))))
4695      (or (car extract) (cadr extract) ""))
4696    (let ((extract (funcall
4697                    gnus-extract-address-components
4698                    (mail-header-from h2))))
4699      (or (car extract) (cadr extract) ""))))
4700
4701 (defun gnus-thread-sort-by-author (h1 h2)
4702   "Sort threads by root author."
4703   (gnus-article-sort-by-author
4704    (gnus-thread-header h1)  (gnus-thread-header h2)))
4705
4706 (defsubst gnus-article-sort-by-recipient (h1 h2)
4707   "Sort articles by recipient."
4708   (string-lessp
4709    (let ((extract (funcall
4710                    gnus-extract-address-components
4711                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4712      (or (car extract) (cadr extract)))
4713    (let ((extract (funcall
4714                    gnus-extract-address-components
4715                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4716      (or (car extract) (cadr extract)))))
4717
4718 (defun gnus-thread-sort-by-recipient (h1 h2)
4719   "Sort threads by root recipient."
4720   (gnus-article-sort-by-recipient
4721    (gnus-thread-header h1) (gnus-thread-header h2)))
4722
4723 (defsubst gnus-article-sort-by-subject (h1 h2)
4724   "Sort articles by root subject."
4725   (string-lessp
4726    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4727    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4728
4729 (defun gnus-thread-sort-by-subject (h1 h2)
4730   "Sort threads by root subject."
4731   (gnus-article-sort-by-subject
4732    (gnus-thread-header h1) (gnus-thread-header h2)))
4733
4734 (defsubst gnus-article-sort-by-date (h1 h2)
4735   "Sort articles by root article date."
4736   (time-less-p
4737    (gnus-date-get-time (mail-header-date h1))
4738    (gnus-date-get-time (mail-header-date h2))))
4739
4740 (defun gnus-thread-sort-by-date (h1 h2)
4741   "Sort threads by root article date."
4742   (gnus-article-sort-by-date
4743    (gnus-thread-header h1) (gnus-thread-header h2)))
4744
4745 (defsubst gnus-article-sort-by-score (h1 h2)
4746   "Sort articles by root article score.
4747 Unscored articles will be counted as having a score of zero."
4748   (> (or (cdr (assq (mail-header-number h1)
4749                     gnus-newsgroup-scored))
4750          gnus-summary-default-score 0)
4751      (or (cdr (assq (mail-header-number h2)
4752                     gnus-newsgroup-scored))
4753          gnus-summary-default-score 0)))
4754
4755 (defun gnus-thread-sort-by-score (h1 h2)
4756   "Sort threads by root article score."
4757   (gnus-article-sort-by-score
4758    (gnus-thread-header h1) (gnus-thread-header h2)))
4759
4760 (defun gnus-thread-sort-by-total-score (h1 h2)
4761   "Sort threads by the sum of all scores in the thread.
4762 Unscored articles will be counted as having a score of zero."
4763   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4764
4765 (defun gnus-thread-total-score (thread)
4766   ;; This function find the total score of THREAD.
4767   (cond
4768    ((null thread)
4769     0)
4770    ((consp thread)
4771     (if (stringp (car thread))
4772         (apply gnus-thread-score-function 0
4773                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4774       (gnus-thread-total-score-1 thread)))
4775    (t
4776     (gnus-thread-total-score-1 (list thread)))))
4777
4778 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4779   "Sort threads such that the thread with the most recently arrived article comes first."
4780   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4781
4782 (defun gnus-thread-highest-number (thread)
4783   "Return the highest article number in THREAD."
4784   (apply 'max (mapcar (lambda (header)
4785                         (mail-header-number header))
4786                       (message-flatten-list thread))))
4787
4788 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4789   "Sort threads such that the thread with the most recently dated article comes first."
4790   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4791
4792 (defun gnus-thread-latest-date (thread)
4793   "Return the highest article date in THREAD."
4794   (let ((previous-time 0))
4795     (apply 'max
4796            (mapcar
4797             (lambda (header)
4798               (setq previous-time
4799                     (condition-case ()
4800                         (time-to-seconds (mail-header-parse-date
4801                                           (mail-header-date header)))
4802                       (error previous-time))))
4803             (sort
4804              (message-flatten-list thread)
4805              (lambda (h1 h2)
4806                (< (mail-header-number h1)
4807                   (mail-header-number h2))))))))
4808
4809 (defun gnus-thread-total-score-1 (root)
4810   ;; This function find the total score of the thread below ROOT.
4811   (setq root (car root))
4812   (apply gnus-thread-score-function
4813          (or (append
4814               (mapcar 'gnus-thread-total-score
4815                       (cdr (gnus-id-to-thread (mail-header-id root))))
4816               (when (> (mail-header-number root) 0)
4817                 (list (or (cdr (assq (mail-header-number root)
4818                                      gnus-newsgroup-scored))
4819                           gnus-summary-default-score 0))))
4820              (list gnus-summary-default-score)
4821              '(0))))
4822
4823 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4824 (defvar gnus-tmp-prev-subject nil)
4825 (defvar gnus-tmp-false-parent nil)
4826 (defvar gnus-tmp-root-expunged nil)
4827 (defvar gnus-tmp-dummy-line nil)
4828
4829 (eval-when-compile (defvar gnus-tmp-header))
4830 (defun gnus-extra-header (type &optional header)
4831   "Return the extra header of TYPE."
4832   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4833       ""))
4834
4835 (defvar gnus-tmp-thread-tree-header-string "")
4836
4837 (defcustom gnus-sum-thread-tree-root "> "
4838   "With %B spec, used for the root of a thread.
4839 If nil, use subject instead."
4840   :version "22.1"
4841   :type '(radio (const :format "%v  " nil) string)
4842   :group 'gnus-thread)
4843
4844 (defcustom gnus-sum-thread-tree-false-root "> "
4845   "With %B spec, used for a false root of a thread.
4846 If nil, use subject instead."
4847   :version "22.1"
4848   :type '(radio (const :format "%v  " nil) string)
4849   :group 'gnus-thread)
4850
4851 (defcustom gnus-sum-thread-tree-single-indent ""
4852   "With %B spec, used for a thread with just one message.
4853 If nil, use subject instead."
4854   :version "22.1"
4855   :type '(radio (const :format "%v  " nil) string)
4856   :group 'gnus-thread)
4857
4858 (defcustom gnus-sum-thread-tree-vertical "| "
4859   "With %B spec, used for drawing a vertical line."
4860   :version "22.1"
4861   :type 'string
4862   :group 'gnus-thread)
4863
4864 (defcustom gnus-sum-thread-tree-indent "  "
4865   "With %B spec, used for indenting."
4866   :version "22.1"
4867   :type 'string
4868   :group 'gnus-thread)
4869
4870 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4871   "With %B spec, used for a leaf with brothers."
4872   :version "22.1"
4873   :type 'string
4874   :group 'gnus-thread)
4875
4876 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4877   "With %B spec, used for a leaf without brothers."
4878   :version "22.1"
4879   :type 'string
4880   :group 'gnus-thread)
4881
4882 (defun gnus-summary-prepare-threads (threads)
4883   "Prepare summary buffer from THREADS and indentation LEVEL.
4884 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4885 or a straight list of headers."
4886   (gnus-message 7 "Generating summary...")
4887
4888   (setq gnus-newsgroup-threads threads)
4889   (beginning-of-line)
4890
4891   (let ((gnus-tmp-level 0)
4892         (default-score (or gnus-summary-default-score 0))
4893         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4894         (building-line-count gnus-summary-display-while-building)
4895         (building-count (integerp gnus-summary-display-while-building))
4896         thread number subject stack state gnus-tmp-gathered beg-match
4897         new-roots gnus-tmp-new-adopts thread-end simp-subject
4898         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4899         gnus-tmp-replied gnus-tmp-subject-or-nil
4900         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4901         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4902         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4903         tree-stack)
4904
4905     (setq gnus-tmp-prev-subject nil
4906           gnus-tmp-thread-tree-header-string "")
4907
4908     (if (vectorp (car threads))
4909         ;; If this is a straight (sic) list of headers, then a
4910         ;; threaded summary display isn't required, so we just create
4911         ;; an unthreaded one.
4912         (gnus-summary-prepare-unthreaded threads)
4913
4914       ;; Do the threaded display.
4915
4916       (if gnus-summary-display-while-building
4917           (switch-to-buffer (buffer-name)))
4918       (while (or threads stack gnus-tmp-new-adopts new-roots)
4919
4920         (if (and (= gnus-tmp-level 0)
4921                  (or (not stack)
4922                      (= (caar stack) 0))
4923                  (not gnus-tmp-false-parent)
4924                  (or gnus-tmp-new-adopts new-roots))
4925             (if gnus-tmp-new-adopts
4926                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4927                       thread (list (car gnus-tmp-new-adopts))
4928                       gnus-tmp-header (caar thread)
4929                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4930               (when new-roots
4931                 (setq thread (list (car new-roots))
4932                       gnus-tmp-header (caar thread)
4933                       new-roots (cdr new-roots))))
4934
4935           (if threads
4936               ;; If there are some threads, we do them before the
4937               ;; threads on the stack.
4938               (setq thread threads
4939                     gnus-tmp-header (caar thread))
4940             ;; There were no current threads, so we pop something off
4941             ;; the stack.
4942             (setq state (car stack)
4943                   gnus-tmp-level (car state)
4944                   tree-stack (cadr state)
4945                   thread (caddr state)
4946                   stack (cdr stack)
4947                   gnus-tmp-header (caar thread))))
4948
4949         (setq gnus-tmp-false-parent nil)
4950         (setq gnus-tmp-root-expunged nil)
4951         (setq thread-end nil)
4952
4953         (if (stringp gnus-tmp-header)
4954             ;; The header is a dummy root.
4955             (cond
4956              ((eq gnus-summary-make-false-root 'adopt)
4957               ;; We let the first article adopt the rest.
4958               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4959                                                (cddar thread)))
4960               (setq gnus-tmp-gathered
4961                     (nconc (mapcar
4962                             (lambda (h) (mail-header-number (car h)))
4963                             (cddar thread))
4964                            gnus-tmp-gathered))
4965               (setq thread (cons (list (caar thread)
4966                                        (cadar thread))
4967                                  (cdr thread)))
4968               (setq gnus-tmp-level -1
4969                     gnus-tmp-false-parent t))
4970              ((eq gnus-summary-make-false-root 'empty)
4971               ;; We print adopted articles with empty subject fields.
4972               (setq gnus-tmp-gathered
4973                     (nconc (mapcar
4974                             (lambda (h) (mail-header-number (car h)))
4975                             (cddar thread))
4976                            gnus-tmp-gathered))
4977               (setq gnus-tmp-level -1))
4978              ((eq gnus-summary-make-false-root 'dummy)
4979               ;; We remember that we probably want to output a dummy
4980               ;; root.
4981               (setq gnus-tmp-dummy-line gnus-tmp-header)
4982               (setq gnus-tmp-prev-subject gnus-tmp-header))
4983              (t
4984               ;; We do not make a root for the gathered
4985               ;; sub-threads at all.
4986               (setq gnus-tmp-level -1)))
4987
4988           (setq number (mail-header-number gnus-tmp-header)
4989                 subject (mail-header-subject gnus-tmp-header)
4990                 simp-subject (gnus-simplify-subject-fully subject))
4991
4992           (cond
4993            ;; If the thread has changed subject, we might want to make
4994            ;; this subthread into a root.
4995            ((and (null gnus-thread-ignore-subject)
4996                  (not (zerop gnus-tmp-level))
4997                  gnus-tmp-prev-subject
4998                  (not (string= gnus-tmp-prev-subject simp-subject)))
4999             (setq new-roots (nconc new-roots (list (car thread)))
5000                   thread-end t
5001                   gnus-tmp-header nil))
5002            ;; If the article lies outside the current limit,
5003            ;; then we do not display it.
5004            ((not (memq number gnus-newsgroup-limit))
5005             (setq gnus-tmp-gathered
5006                   (nconc (mapcar
5007                           (lambda (h) (mail-header-number (car h)))
5008                           (cdar thread))
5009                          gnus-tmp-gathered))
5010             (setq gnus-tmp-new-adopts (if (cdar thread)
5011                                           (append gnus-tmp-new-adopts
5012                                                   (cdar thread))
5013                                         gnus-tmp-new-adopts)
5014                   thread-end t
5015                   gnus-tmp-header nil)
5016             (when (zerop gnus-tmp-level)
5017               (setq gnus-tmp-root-expunged t)))
5018            ;; Perhaps this article is to be marked as read?
5019            ((and gnus-summary-mark-below
5020                  (< (or (cdr (assq number gnus-newsgroup-scored))
5021                         default-score)
5022                     gnus-summary-mark-below)
5023                  ;; Don't touch sparse articles.
5024                  (not (gnus-summary-article-sparse-p number))
5025                  (not (gnus-summary-article-ancient-p number)))
5026             (setq gnus-newsgroup-unreads
5027                   (delq number gnus-newsgroup-unreads))
5028             (if gnus-newsgroup-auto-expire
5029                 (setq gnus-newsgroup-expirable
5030                       (gnus-add-to-sorted-list
5031                        gnus-newsgroup-expirable number))
5032               (push (cons number gnus-low-score-mark)
5033                     gnus-newsgroup-reads))))
5034
5035           (when gnus-tmp-header
5036             ;; We may have an old dummy line to output before this
5037             ;; article.
5038             (when (and gnus-tmp-dummy-line
5039                        (gnus-subject-equal
5040                         gnus-tmp-dummy-line
5041                         (mail-header-subject gnus-tmp-header)))
5042               (gnus-summary-insert-dummy-line
5043                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5044               (setq gnus-tmp-dummy-line nil))
5045
5046             ;; Compute the mark.
5047             (setq gnus-tmp-unread (gnus-article-mark number))
5048
5049             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5050                                   gnus-tmp-header gnus-tmp-level)
5051                   gnus-newsgroup-data)
5052
5053             ;; Actually insert the line.
5054             (setq
5055              gnus-tmp-subject-or-nil
5056              (cond
5057               ((and gnus-thread-ignore-subject
5058                     gnus-tmp-prev-subject
5059                     (not (string= gnus-tmp-prev-subject simp-subject)))
5060                subject)
5061               ((zerop gnus-tmp-level)
5062                (if (and (eq gnus-summary-make-false-root 'empty)
5063                         (memq number gnus-tmp-gathered)
5064                         gnus-tmp-prev-subject
5065                         (string= gnus-tmp-prev-subject simp-subject))
5066                    gnus-summary-same-subject
5067                  subject))
5068               (t gnus-summary-same-subject)))
5069             (if (and (eq gnus-summary-make-false-root 'adopt)
5070                      (= gnus-tmp-level 1)
5071                      (memq number gnus-tmp-gathered))
5072                 (setq gnus-tmp-opening-bracket ?\<
5073                       gnus-tmp-closing-bracket ?\>)
5074               (setq gnus-tmp-opening-bracket ?\[
5075                     gnus-tmp-closing-bracket ?\]))
5076             (setq
5077              gnus-tmp-indentation
5078              (aref gnus-thread-indent-array gnus-tmp-level)
5079              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5080              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5081                                 gnus-summary-default-score 0)
5082              gnus-tmp-score-char
5083              (if (or (null gnus-summary-default-score)
5084                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5085                          gnus-summary-zcore-fuzz))
5086                  ?                      ;Whitespace
5087                (if (< gnus-tmp-score gnus-summary-default-score)
5088                    gnus-score-below-mark gnus-score-over-mark))
5089              gnus-tmp-replied
5090              (cond ((memq number gnus-newsgroup-processable)
5091                     gnus-process-mark)
5092                    ((memq number gnus-newsgroup-cached)
5093                     gnus-cached-mark)
5094                    ((memq number gnus-newsgroup-replied)
5095                     gnus-replied-mark)
5096                    ((memq number gnus-newsgroup-forwarded)
5097                     gnus-forwarded-mark)
5098                    ((memq number gnus-newsgroup-saved)
5099                     gnus-saved-mark)
5100                    ((memq number gnus-newsgroup-recent)
5101                     gnus-recent-mark)
5102                    ((memq number gnus-newsgroup-unseen)
5103                     gnus-unseen-mark)
5104                    (t gnus-no-mark))
5105              gnus-tmp-downloaded
5106              (cond ((memq number gnus-newsgroup-undownloaded)
5107                     gnus-undownloaded-mark)
5108                    (gnus-newsgroup-agentized
5109                     gnus-downloaded-mark)
5110                    (t
5111                     gnus-no-mark))
5112              gnus-tmp-from (mail-header-from gnus-tmp-header)
5113              gnus-tmp-name
5114              (cond
5115               ((string-match "<[^>]+> *$" gnus-tmp-from)
5116                (setq beg-match (match-beginning 0))
5117                (or (and (string-match "^\".+\"" gnus-tmp-from)
5118                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5119                    (substring gnus-tmp-from 0 beg-match)))
5120               ((string-match "(.+)" gnus-tmp-from)
5121                (substring gnus-tmp-from
5122                           (1+ (match-beginning 0)) (1- (match-end 0))))
5123               (t gnus-tmp-from))
5124
5125              ;; Do the %B string
5126              gnus-tmp-thread-tree-header-string
5127              (cond
5128               ((not gnus-show-threads) "")
5129               ((zerop gnus-tmp-level)
5130                (cond ((cdar thread)
5131                       (or gnus-sum-thread-tree-root subject))
5132                      (gnus-tmp-new-adopts
5133                       (or gnus-sum-thread-tree-false-root subject))
5134                      (t
5135                       (or gnus-sum-thread-tree-single-indent subject))))
5136               (t
5137                (concat (apply 'concat
5138                               (mapcar (lambda (item)
5139                                         (if (= item 1)
5140                                             gnus-sum-thread-tree-vertical
5141                                           gnus-sum-thread-tree-indent))
5142                                       (cdr (reverse tree-stack))))
5143                        (if (nth 1 thread)
5144                            gnus-sum-thread-tree-leaf-with-other
5145                          gnus-sum-thread-tree-single-leaf)))))
5146             (when (string= gnus-tmp-name "")
5147               (setq gnus-tmp-name gnus-tmp-from))
5148             (unless (numberp gnus-tmp-lines)
5149               (setq gnus-tmp-lines -1))
5150             (if (= gnus-tmp-lines -1)
5151                 (setq gnus-tmp-lines "?")
5152               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5153               (gnus-put-text-property
5154              (point)
5155              (progn (eval gnus-summary-line-format-spec) (point))
5156                'gnus-number number)
5157             (when gnus-visual-p
5158               (forward-line -1)
5159               (gnus-run-hooks 'gnus-summary-update-hook)
5160               (forward-line 1))
5161
5162             (setq gnus-tmp-prev-subject simp-subject)))
5163
5164         (when (nth 1 thread)
5165           (push (list (max 0 gnus-tmp-level)
5166                       (copy-sequence tree-stack)
5167                       (nthcdr 1 thread))
5168                 stack))
5169         (push (if (nth 1 thread) 1 0) tree-stack)
5170         (incf gnus-tmp-level)
5171         (setq threads (if thread-end nil (cdar thread)))
5172         (if gnus-summary-display-while-building
5173             (if building-count
5174                 (progn
5175                   ;; use a set frequency
5176                   (setq building-line-count (1- building-line-count))
5177                   (when (= building-line-count 0)
5178                     (sit-for 0)
5179                     (setq building-line-count
5180                           gnus-summary-display-while-building)))
5181               ;; always
5182               (sit-for 0)))
5183         (unless threads
5184           (setq gnus-tmp-level 0)))))
5185   (gnus-message 7 "Generating summary...done"))
5186
5187 (defun gnus-summary-prepare-unthreaded (headers)
5188   "Generate an unthreaded summary buffer based on HEADERS."
5189   (let (header number mark)
5190
5191     (beginning-of-line)
5192
5193     (while headers
5194       ;; We may have to root out some bad articles...
5195       (when (memq (setq number (mail-header-number
5196                                 (setq header (pop headers))))
5197                   gnus-newsgroup-limit)
5198         ;; Mark article as read when it has a low score.
5199         (when (and gnus-summary-mark-below
5200                    (< (or (cdr (assq number gnus-newsgroup-scored))
5201                           gnus-summary-default-score 0)
5202                       gnus-summary-mark-below)
5203                    (not (gnus-summary-article-ancient-p number)))
5204           (setq gnus-newsgroup-unreads
5205                 (delq number gnus-newsgroup-unreads))
5206           (if gnus-newsgroup-auto-expire
5207               (push number gnus-newsgroup-expirable)
5208             (push (cons number gnus-low-score-mark)
5209                   gnus-newsgroup-reads)))
5210
5211         (setq mark (gnus-article-mark number))
5212         (push (gnus-data-make number mark (1+ (point)) header 0)
5213               gnus-newsgroup-data)
5214         (gnus-summary-insert-line
5215          header 0 number
5216          (memq number gnus-newsgroup-undownloaded)
5217          mark (memq number gnus-newsgroup-replied)
5218          (memq number gnus-newsgroup-expirable)
5219          (mail-header-subject header) nil
5220          (cdr (assq number gnus-newsgroup-scored))
5221          (memq number gnus-newsgroup-processable))))))
5222
5223 (defun gnus-summary-remove-list-identifiers ()
5224   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5225   (let ((regexp (if (consp gnus-list-identifiers)
5226                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5227                   gnus-list-identifiers))
5228         changed subject)
5229     (when regexp
5230       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5231       (dolist (header gnus-newsgroup-headers)
5232         (setq subject (mail-header-subject header)
5233               changed nil)
5234         (while (string-match regexp subject)
5235           (setq subject
5236                 (concat (substring subject 0 (match-beginning 1))
5237                         (substring subject (match-end 0)))
5238                 changed t))
5239         (when changed
5240           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5241             (setq subject
5242                   (concat (substring subject 0 (match-beginning 1))
5243                           (substring subject (match-end 1)))))
5244           (mail-header-set-subject header subject))))))
5245
5246 (defun gnus-fetch-headers (articles)
5247   "Fetch headers of ARTICLES."
5248   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5249     (gnus-message 5 "Fetching headers for %s..." name)
5250     (prog1
5251         (if (eq 'nov
5252                 (setq gnus-headers-retrieved-by
5253                       (gnus-retrieve-headers
5254                        articles gnus-newsgroup-name
5255                        ;; We might want to fetch old headers, but
5256                        ;; not if there is only 1 article.
5257                        (and (or (and
5258                                  (not (eq gnus-fetch-old-headers 'some))
5259                                  (not (numberp gnus-fetch-old-headers)))
5260                                 (> (length articles) 1))
5261                             gnus-fetch-old-headers))))
5262             (gnus-get-newsgroup-headers-xover
5263              articles nil nil gnus-newsgroup-name t)
5264           (gnus-get-newsgroup-headers))
5265       (gnus-message 5 "Fetching headers for %s...done" name))))
5266
5267 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5268   "Select newsgroup GROUP.
5269 If READ-ALL is non-nil, all articles in the group are selected.
5270 If SELECT-ARTICLES, only select those articles from GROUP."
5271   (let* ((entry (gnus-group-entry group))
5272          ;;!!! Dirty hack; should be removed.
5273          (gnus-summary-ignore-duplicates
5274           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5275               t
5276             gnus-summary-ignore-duplicates))
5277          (info (nth 2 entry))
5278          articles fetched-articles cached)
5279
5280     (unless (gnus-check-server
5281              (set (make-local-variable 'gnus-current-select-method)
5282                   (gnus-find-method-for-group group)))
5283       (error "Couldn't open server"))
5284
5285     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5286         (gnus-activate-group group)     ; Or we can activate it...
5287         (progn                          ; Or we bug out.
5288           (when (equal major-mode 'gnus-summary-mode)
5289             (gnus-kill-buffer (current-buffer)))
5290           (error "Couldn't activate group %s: %s"
5291                  group (gnus-status-message group))))
5292
5293     (unless (gnus-request-group group t)
5294       (when (equal major-mode 'gnus-summary-mode)
5295         (gnus-kill-buffer (current-buffer)))
5296       (error "Couldn't request group %s: %s"
5297              group (gnus-status-message group)))
5298
5299     (when gnus-agent
5300       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5301
5302       (setq gnus-summary-use-undownloaded-faces
5303             (gnus-agent-find-parameter
5304              group
5305              'agent-enable-undownloaded-faces)))
5306
5307     (setq gnus-newsgroup-name group
5308           gnus-newsgroup-unselected nil
5309           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5310
5311     (let ((display (gnus-group-find-parameter group 'display)))
5312       (setq gnus-newsgroup-display
5313             (cond
5314              ((not (zerop (or (car-safe read-all) 0)))
5315               ;; The user entered the group with C-u SPC/RET, let's show
5316               ;; all articles.
5317               'gnus-not-ignore)
5318              ((eq display 'all)
5319               'gnus-not-ignore)
5320              ((arrayp display)
5321               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5322              ((numberp display)
5323               ;; The following is probably the "correct" solution, but
5324               ;; it makes Gnus fetch all headers and then limit the
5325               ;; articles (which is slow), so instead we hack the
5326               ;; select-articles parameter instead. -- Simon Josefsson
5327               ;; <jas@kth.se>
5328               ;;
5329               ;; (gnus-byte-compile
5330               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5331               ;;                         display)))))
5332               (setq select-articles
5333                     (gnus-uncompress-range
5334                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5335                              (if (> tmp 0)
5336                                  tmp
5337                                1))
5338                            (cdr (gnus-active group)))))
5339               nil)
5340              (t
5341               nil))))
5342
5343     (gnus-summary-setup-default-charset)
5344
5345     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5346     (when (gnus-virtual-group-p group)
5347       (setq cached gnus-newsgroup-cached))
5348
5349     (setq gnus-newsgroup-unreads
5350           (gnus-sorted-ndifference
5351            (gnus-sorted-ndifference gnus-newsgroup-unreads
5352                                     gnus-newsgroup-marked)
5353            gnus-newsgroup-dormant))
5354
5355     (setq gnus-newsgroup-processable nil)
5356
5357     (gnus-update-read-articles group gnus-newsgroup-unreads)
5358
5359     ;; Adjust and set lists of article marks.
5360     (when info
5361       (gnus-adjust-marked-articles info))
5362     (if (setq articles select-articles)
5363         (setq gnus-newsgroup-unselected
5364               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5365       (setq articles (gnus-articles-to-read group read-all)))
5366
5367     (cond
5368      ((null articles)
5369       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5370       'quit)
5371      ((eq articles 0) nil)
5372      (t
5373       ;; Init the dependencies hash table.
5374       (setq gnus-newsgroup-dependencies
5375             (gnus-make-hashtable (length articles)))
5376       (gnus-set-global-variables)
5377       ;; Retrieve the headers and read them in.
5378
5379       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5380
5381       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5382       (when cached
5383         (setq gnus-newsgroup-cached cached))
5384
5385       ;; Suppress duplicates?
5386       (when gnus-suppress-duplicates
5387         (gnus-dup-suppress-articles))
5388
5389       ;; Set the initial limit.
5390       (setq gnus-newsgroup-limit (copy-sequence articles))
5391       ;; Remove canceled articles from the list of unread articles.
5392       (setq fetched-articles
5393             (mapcar (lambda (headers) (mail-header-number headers))
5394                     gnus-newsgroup-headers))
5395       (setq gnus-newsgroup-articles fetched-articles)
5396       (setq gnus-newsgroup-unreads
5397             (gnus-sorted-nintersection
5398              gnus-newsgroup-unreads fetched-articles))
5399       (gnus-compute-unseen-list)
5400
5401       ;; Removed marked articles that do not exist.
5402       (gnus-update-missing-marks
5403        (gnus-sorted-difference articles fetched-articles))
5404       ;; We might want to build some more threads first.
5405       (when (and gnus-fetch-old-headers
5406                  (eq gnus-headers-retrieved-by 'nov))
5407         (if (eq gnus-fetch-old-headers 'invisible)
5408             (gnus-build-all-threads)
5409           (gnus-build-old-threads)))
5410       ;; Let the Gnus agent mark articles as read.
5411       (when gnus-agent
5412         (gnus-agent-get-undownloaded-list))
5413       ;; Remove list identifiers from subject
5414       (when gnus-list-identifiers
5415         (gnus-summary-remove-list-identifiers))
5416       ;; Check whether auto-expire is to be done in this group.
5417       (setq gnus-newsgroup-auto-expire
5418             (gnus-group-auto-expirable-p group))
5419       ;; Set up the article buffer now, if necessary.
5420       (unless gnus-single-article-buffer
5421         (gnus-article-setup-buffer))
5422       ;; First and last article in this newsgroup.
5423       (when gnus-newsgroup-headers
5424         (setq gnus-newsgroup-begin
5425               (mail-header-number (car gnus-newsgroup-headers))
5426               gnus-newsgroup-end
5427               (mail-header-number
5428                (gnus-last-element gnus-newsgroup-headers))))
5429       ;; GROUP is successfully selected.
5430       (or gnus-newsgroup-headers t)))))
5431
5432 (defun gnus-compute-unseen-list ()
5433   ;; The `seen' marks are treated specially.
5434   (if (not gnus-newsgroup-seen)
5435       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5436     (setq gnus-newsgroup-unseen
5437           (gnus-inverse-list-range-intersection
5438            gnus-newsgroup-articles gnus-newsgroup-seen))))
5439
5440 (defun gnus-summary-display-make-predicate (display)
5441   (require 'gnus-agent)
5442   (when (= (length display) 1)
5443     (setq display (car display)))
5444   (unless gnus-summary-display-cache
5445     (dolist (elem (append '((unread . unread)
5446                             (read . read)
5447                             (unseen . unseen))
5448                           gnus-article-mark-lists))
5449       (push (cons (cdr elem)
5450                   (gnus-byte-compile
5451                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5452             gnus-summary-display-cache)))
5453   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5454         (gnus-category-predicate-cache gnus-summary-display-cache))
5455     (gnus-get-predicate display)))
5456
5457 ;; Uses the dynamically bound `number' variable.
5458 (eval-when-compile
5459   (defvar number))
5460 (defun gnus-article-marked-p (type &optional article)
5461   (let ((article (or article number)))
5462     (cond
5463      ((eq type 'tick)
5464       (memq article gnus-newsgroup-marked))
5465      ((eq type 'spam)
5466       (memq article gnus-newsgroup-spam-marked))
5467      ((eq type 'unsend)
5468       (memq article gnus-newsgroup-unsendable))
5469      ((eq type 'undownload)
5470       (memq article gnus-newsgroup-undownloaded))
5471      ((eq type 'download)
5472       (memq article gnus-newsgroup-downloadable))
5473      ((eq type 'unread)
5474       (memq article gnus-newsgroup-unreads))
5475      ((eq type 'read)
5476       (memq article gnus-newsgroup-reads))
5477      ((eq type 'dormant)
5478       (memq article gnus-newsgroup-dormant) )
5479      ((eq type 'expire)
5480       (memq article gnus-newsgroup-expirable))
5481      ((eq type 'reply)
5482       (memq article gnus-newsgroup-replied))
5483      ((eq type 'killed)
5484       (memq article gnus-newsgroup-killed))
5485      ((eq type 'bookmark)
5486       (assq article gnus-newsgroup-bookmarks))
5487      ((eq type 'score)
5488       (assq article gnus-newsgroup-scored))
5489      ((eq type 'save)
5490       (memq article gnus-newsgroup-saved))
5491      ((eq type 'cache)
5492       (memq article gnus-newsgroup-cached))
5493      ((eq type 'forward)
5494       (memq article gnus-newsgroup-forwarded))
5495      ((eq type 'seen)
5496       (not (memq article gnus-newsgroup-unseen)))
5497      ((eq type 'recent)
5498       (memq article gnus-newsgroup-recent))
5499      (t t))))
5500
5501 (defun gnus-articles-to-read (group &optional read-all)
5502   "Find out what articles the user wants to read."
5503   (let* ((articles
5504           ;; Select all articles if `read-all' is non-nil, or if there
5505           ;; are no unread articles.
5506           (if (or read-all
5507                   (and (zerop (length gnus-newsgroup-marked))
5508                        (zerop (length gnus-newsgroup-unreads)))
5509                   ;; Fetch all if the predicate is non-nil.
5510                   gnus-newsgroup-display)
5511               ;; We want to select the headers for all the articles in
5512               ;; the group, so we select either all the active
5513               ;; articles in the group, or (if that's nil), the
5514               ;; articles in the cache.
5515               (or
5516                (gnus-uncompress-range (gnus-active group))
5517                (gnus-cache-articles-in-group group))
5518             ;; Select only the "normal" subset of articles.
5519             (gnus-sorted-nunion
5520              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5521              gnus-newsgroup-unreads)))
5522          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5523          (scored (length scored-list))
5524          (number (length articles))
5525          (marked (+ (length gnus-newsgroup-marked)
5526                     (length gnus-newsgroup-dormant)))
5527          (select
5528           (cond
5529            ((numberp read-all)
5530             read-all)
5531            ((numberp gnus-newsgroup-display)
5532             gnus-newsgroup-display)
5533            (t
5534             (condition-case ()
5535                 (cond
5536                  ((and (or (<= scored marked) (= scored number))
5537                        (numberp gnus-large-newsgroup)
5538                        (> number gnus-large-newsgroup))
5539                   (let* ((cursor-in-echo-area nil)
5540                          (initial (gnus-parameter-large-newsgroup-initial
5541                                    gnus-newsgroup-name))
5542                          (input
5543                           (read-string
5544                            (format
5545                             "How many articles from %s (%s %d): "
5546                             (gnus-limit-string
5547                              (gnus-group-decoded-name gnus-newsgroup-name)
5548                              35)
5549                             (if initial "max" "default")
5550                             number)
5551                            (if initial
5552                                (cons (number-to-string initial)
5553                                      0)))))
5554                     (if (string-match "^[ \t]*$" input) number input)))
5555                  ((and (> scored marked) (< scored number)
5556                        (> (- scored number) 20))
5557                   (let ((input
5558                          (read-string
5559                           (format "%s %s (%d scored, %d total): "
5560                                   "How many articles from"
5561                                   (gnus-group-decoded-name group)
5562                                   scored number))))
5563                     (if (string-match "^[ \t]*$" input)
5564                         number input)))
5565                  (t number))
5566               (quit
5567                (message "Quit getting the articles to read")
5568                nil))))))
5569     (setq select (if (stringp select) (string-to-number select) select))
5570     (if (or (null select) (zerop select))
5571         select
5572       (if (and (not (zerop scored)) (<= (abs select) scored))
5573           (progn
5574             (setq articles (sort scored-list '<))
5575             (setq number (length articles)))
5576         (setq articles (copy-sequence articles)))
5577
5578       (when (< (abs select) number)
5579         (if (< select 0)
5580             ;; Select the N oldest articles.
5581             (setcdr (nthcdr (1- (abs select)) articles) nil)
5582           ;; Select the N most recent articles.
5583           (setq articles (nthcdr (- number select) articles))))
5584       (setq gnus-newsgroup-unselected
5585             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5586       (when gnus-alter-articles-to-read-function
5587         (setq articles
5588               (sort
5589                (funcall gnus-alter-articles-to-read-function
5590                         gnus-newsgroup-name articles)
5591                '<)))
5592       articles)))
5593
5594 (defun gnus-killed-articles (killed articles)
5595   (let (out)
5596     (while articles
5597       (when (inline (gnus-member-of-range (car articles) killed))
5598         (push (car articles) out))
5599       (setq articles (cdr articles)))
5600     out))
5601
5602 (defun gnus-uncompress-marks (marks)
5603   "Uncompress the mark ranges in MARKS."
5604   (let ((uncompressed '(score bookmark))
5605         out)
5606     (while marks
5607       (if (memq (caar marks) uncompressed)
5608           (push (car marks) out)
5609         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5610       (setq marks (cdr marks)))
5611     out))
5612
5613 (defun gnus-article-mark-to-type (mark)
5614   "Return the type of MARK."
5615   (or (cadr (assq mark gnus-article-special-mark-lists))
5616       'list))
5617
5618 (defun gnus-article-unpropagatable-p (mark)
5619   "Return whether MARK should be propagated to back end."
5620   (memq mark gnus-article-unpropagated-mark-lists))
5621
5622 (defun gnus-adjust-marked-articles (info)
5623   "Set all article lists and remove all marks that are no longer valid."
5624   (let* ((marked-lists (gnus-info-marks info))
5625          (active (gnus-active (gnus-info-group info)))
5626          (min (car active))
5627          (max (cdr active))
5628          (types gnus-article-mark-lists)
5629          marks var articles article mark mark-type
5630          bgn end)
5631
5632     (dolist (marks marked-lists)
5633       (setq mark (car marks)
5634             mark-type (gnus-article-mark-to-type mark)
5635             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5636
5637       ;; We set the variable according to the type of the marks list,
5638       ;; and then adjust the marks to a subset of the active articles.
5639       (cond
5640        ;; Adjust "simple" lists - compressed yet unsorted
5641        ((eq mark-type 'list)
5642         ;; Simultaneously uncompress and clip to active range
5643         ;; See gnus-uncompress-range for a description of possible marks
5644         (let (l lh)
5645           (if (not (cadr marks))
5646               (set var nil)
5647             (setq articles (if (numberp (cddr marks))
5648                                (list (cdr marks))
5649                              (cdr marks))
5650                   lh (cons nil nil)
5651                   l lh)
5652
5653             (while (setq article (pop articles))
5654               (cond ((consp article)
5655                      (setq bgn (max (car article) min)
5656                            end (min (cdr article) max))
5657                      (while (<= bgn end)
5658                        (setq l (setcdr l (cons bgn nil))
5659                              bgn (1+ bgn))))
5660                     ((and (<= min article)
5661                           (>= max article))
5662                      (setq l (setcdr l (cons article nil))))))
5663             (set var (cdr lh)))))
5664        ;; Adjust assocs.
5665        ((eq mark-type 'tuple)
5666         (set var (setq articles (cdr marks)))
5667         (when (not (listp (cdr (symbol-value var))))
5668           (set var (list (symbol-value var))))
5669         (when (not (listp (cdr articles)))
5670           (setq articles (list articles)))
5671         (while articles
5672           (when (or (not (consp (setq article (pop articles))))
5673                     (< (car article) min)
5674                     (> (car article) max))
5675             (set var (delq article (symbol-value var))))))
5676        ;; Adjust ranges (sloppily).
5677        ((eq mark-type 'range)
5678         (cond
5679          ((eq mark 'seen)
5680           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5681           ;; It should be (seen (NUM1 . NUM2)).
5682           (when (numberp (cddr marks))
5683             (setcdr marks (list (cdr marks))))
5684           (setq articles (cdr marks))
5685           (while (and articles
5686                       (or (and (consp (car articles))
5687                                (> min (cdar articles)))
5688                           (and (numberp (car articles))
5689                                (> min (car articles)))))
5690             (pop articles))
5691           (set var articles))))))))
5692
5693 (defun gnus-update-missing-marks (missing)
5694   "Go through the list of MISSING articles and remove them from the mark lists."
5695   (when missing
5696     (let (var m)
5697       ;; Go through all types.
5698       (dolist (elem gnus-article-mark-lists)
5699         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5700           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5701           (when (symbol-value var)
5702             ;; This list has articles.  So we delete all missing
5703             ;; articles from it.
5704             (setq m missing)
5705             (while m
5706               (set var (delq (pop m) (symbol-value var))))))))))
5707
5708 (defun gnus-update-marks ()
5709   "Enter the various lists of marked articles into the newsgroup info list."
5710   (let ((types gnus-article-mark-lists)
5711         (info (gnus-get-info gnus-newsgroup-name))
5712         type list newmarked symbol delta-marks)
5713     (when info
5714       ;; Add all marks lists to the list of marks lists.
5715       (while (setq type (pop types))
5716         (setq list (symbol-value
5717                     (setq symbol
5718                           (intern (format "gnus-newsgroup-%s" (car type))))))
5719
5720         (when list
5721           ;; Get rid of the entries of the articles that have the
5722           ;; default score.
5723           (when (and (eq (cdr type) 'score)
5724                      gnus-save-score
5725                      list)
5726             (let* ((arts list)
5727                    (prev (cons nil list))
5728                    (all prev))
5729               (while arts
5730                 (if (or (not (consp (car arts)))
5731                         (= (cdar arts) gnus-summary-default-score))
5732                     (setcdr prev (cdr arts))
5733                   (setq prev arts))
5734                 (setq arts (cdr arts)))
5735               (setq list (cdr all)))))
5736
5737         (when (eq (cdr type) 'seen)
5738           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5739
5740         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5741           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5742
5743         (when (and (gnus-check-backend-function
5744                     'request-set-mark gnus-newsgroup-name)
5745                    (not (gnus-article-unpropagatable-p (cdr type))))
5746           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5747                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5748                  (add (gnus-remove-from-range
5749                        (gnus-copy-sequence list) old)))
5750             (when add
5751               (push (list add 'add (list (cdr type))) delta-marks))
5752             (when del
5753               (push (list del 'del (list (cdr type))) delta-marks))))
5754
5755         (when list
5756           (push (cons (cdr type) list) newmarked)))
5757
5758       (when delta-marks
5759         (unless (gnus-check-group gnus-newsgroup-name)
5760           (error "Can't open server for %s" gnus-newsgroup-name))
5761         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5762
5763       ;; Enter these new marks into the info of the group.
5764       (if (nthcdr 3 info)
5765           (setcar (nthcdr 3 info) newmarked)
5766         ;; Add the marks lists to the end of the info.
5767         (when newmarked
5768           (setcdr (nthcdr 2 info) (list newmarked))))
5769
5770       ;; Cut off the end of the info if there's nothing else there.
5771       (let ((i 5))
5772         (while (and (> i 2)
5773                     (not (nth i info)))
5774           (when (nthcdr (decf i) info)
5775             (setcdr (nthcdr i info) nil)))))))
5776
5777 (defun gnus-set-mode-line (where)
5778   "Set the mode line of the article or summary buffers.
5779 If WHERE is `summary', the summary mode line format will be used."
5780   ;; Is this mode line one we keep updated?
5781   (when (and (memq where gnus-updated-mode-lines)
5782              (symbol-value
5783               (intern (format "gnus-%s-mode-line-format-spec" where))))
5784     (let (mode-string)
5785       (save-excursion
5786         ;; We evaluate this in the summary buffer since these
5787         ;; variables are buffer-local to that buffer.
5788         (set-buffer gnus-summary-buffer)
5789        ;; We bind all these variables that are used in the `eval' form
5790         ;; below.
5791         (let* ((mformat (symbol-value
5792                          (intern
5793                           (format "gnus-%s-mode-line-format-spec" where))))
5794                (gnus-tmp-group-name (gnus-group-decoded-name
5795                                      gnus-newsgroup-name))
5796                (gnus-tmp-article-number (or gnus-current-article 0))
5797                (gnus-tmp-unread gnus-newsgroup-unreads)
5798                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5799                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5800                (gnus-tmp-unread-and-unselected
5801                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5802                             (zerop gnus-tmp-unselected))
5803                        "")
5804                       ((zerop gnus-tmp-unselected)
5805                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5806                       (t (format "{%d(+%d) more}"
5807                                  gnus-tmp-unread-and-unticked
5808                                  gnus-tmp-unselected))))
5809                (gnus-tmp-subject
5810                 (if (and gnus-current-headers
5811                          (vectorp gnus-current-headers))
5812                     (gnus-mode-string-quote
5813                      (mail-header-subject gnus-current-headers))
5814                   ""))
5815                bufname-length max-len
5816                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5817           (setq mode-string (eval mformat))
5818           (setq bufname-length (if (string-match "%b" mode-string)
5819                                    (- (length
5820                                        (buffer-name
5821                                         (if (eq where 'summary)
5822                                             nil
5823                                           (get-buffer gnus-article-buffer))))
5824                                       2)
5825                                  0))
5826           (setq max-len (max 4 (if gnus-mode-non-string-length
5827                                    (- (window-width)
5828                                       gnus-mode-non-string-length
5829                                       bufname-length)
5830                                  (length mode-string))))
5831           ;; We might have to chop a bit of the string off...
5832           (when (> (length mode-string) max-len)
5833             (setq mode-string
5834                   (concat (truncate-string-to-width mode-string (- max-len 3))
5835                           "...")))
5836           ;; Pad the mode string a bit.
5837           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5838       ;; Update the mode line.
5839       (setq mode-line-buffer-identification
5840             (gnus-mode-line-buffer-identification (list mode-string)))
5841       (set-buffer-modified-p t))))
5842
5843 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5844   "Go through the HEADERS list and add all Xrefs to a hash table.
5845 The resulting hash table is returned, or nil if no Xrefs were found."
5846   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5847          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5848          (xref-hashtb (gnus-make-hashtable))
5849          start group entry number xrefs header)
5850     (while headers
5851       (setq header (pop headers))
5852       (when (and (setq xrefs (mail-header-xref header))
5853                  (not (memq (setq number (mail-header-number header))
5854                             unreads)))
5855         (setq start 0)
5856         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5857           (setq start (match-end 0))
5858           (setq group (if prefix
5859                           (concat prefix (substring xrefs (match-beginning 1)
5860                                                     (match-end 1)))
5861                         (substring xrefs (match-beginning 1) (match-end 1))))
5862           (setq number
5863                 (string-to-number (substring xrefs (match-beginning 2)
5864                                           (match-end 2))))
5865           (if (setq entry (gnus-gethash group xref-hashtb))
5866               (setcdr entry (cons number (cdr entry)))
5867             (gnus-sethash group (cons number nil) xref-hashtb)))))
5868     (and start xref-hashtb)))
5869
5870 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5871   "Look through all the headers and mark the Xrefs as read."
5872   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5873         name info xref-hashtb idlist method nth4)
5874     (save-excursion
5875       (set-buffer gnus-group-buffer)
5876       (when (setq xref-hashtb
5877                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5878         (mapatoms
5879          (lambda (group)
5880            (unless (string= from-newsgroup (setq name (symbol-name group)))
5881              (setq idlist (symbol-value group))
5882              ;; Dead groups are not updated.
5883              (and (prog1
5884                       (setq info (gnus-get-info name))
5885                     (when (stringp (setq nth4 (gnus-info-method info)))
5886                       (setq nth4 (gnus-server-to-method nth4))))
5887                   ;; Only do the xrefs if the group has the same
5888                   ;; select method as the group we have just read.
5889                   (or (gnus-methods-equal-p
5890                        nth4 (gnus-find-method-for-group from-newsgroup))
5891                       virtual
5892                       (equal nth4 (setq method (gnus-find-method-for-group
5893                                                 from-newsgroup)))
5894                       (and (equal (car nth4) (car method))
5895                            (equal (nth 1 nth4) (nth 1 method))))
5896                   gnus-use-cross-reference
5897                   (or (not (eq gnus-use-cross-reference t))
5898                       virtual
5899                       ;; Only do cross-references on subscribed
5900                       ;; groups, if that is what is wanted.
5901                       (<= (gnus-info-level info) gnus-level-subscribed))
5902                   (gnus-group-make-articles-read name idlist))))
5903          xref-hashtb)))))
5904
5905 (defun gnus-compute-read-articles (group articles)
5906   (let* ((entry (gnus-group-entry group))
5907          (info (nth 2 entry))
5908          (active (gnus-active group))
5909          ninfo)
5910     (when entry
5911       ;; First peel off all invalid article numbers.
5912       (when active
5913         (let ((ids articles)
5914               id first)
5915           (while (setq id (pop ids))
5916             (when (and first (> id (cdr active)))
5917               ;; We'll end up in this situation in one particular
5918               ;; obscure situation.  If you re-scan a group and get
5919               ;; a new article that is cross-posted to a different
5920               ;; group that has not been re-scanned, you might get
5921               ;; crossposted article that has a higher number than
5922               ;; Gnus believes possible.  So we re-activate this
5923               ;; group as well.  This might mean doing the
5924               ;; crossposting thingy will *increase* the number
5925               ;; of articles in some groups.  Tsk, tsk.
5926               (setq active (or (gnus-activate-group group) active)))
5927             (when (or (> id (cdr active))
5928                       (< id (car active)))
5929               (setq articles (delq id articles))))))
5930       ;; If the read list is nil, we init it.
5931       (if (and active
5932                (null (gnus-info-read info))
5933                (> (car active) 1))
5934           (setq ninfo (cons 1 (1- (car active))))
5935         (setq ninfo (gnus-info-read info)))
5936       ;; Then we add the read articles to the range.
5937       (gnus-add-to-range
5938        ninfo (setq articles (sort articles '<))))))
5939
5940 (defun gnus-group-make-articles-read (group articles)
5941   "Update the info of GROUP to say that ARTICLES are read."
5942   (let* ((num 0)
5943          (entry (gnus-group-entry group))
5944          (info (nth 2 entry))
5945          (active (gnus-active group))
5946          range)
5947     (when entry
5948       (setq range (gnus-compute-read-articles group articles))
5949       (with-current-buffer gnus-group-buffer
5950         (gnus-undo-register
5951           `(progn
5952              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5953              (gnus-info-set-read ',info ',(gnus-info-read info))
5954              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5955              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5956              (gnus-group-update-group ,group t))))
5957       ;; Add the read articles to the range.
5958       (gnus-info-set-read info range)
5959       (gnus-request-set-mark group (list (list range 'add '(read))))
5960       ;; Then we have to re-compute how many unread
5961       ;; articles there are in this group.
5962       (when active
5963         (cond
5964          ((not range)
5965           (setq num (- (1+ (cdr active)) (car active))))
5966          ((not (listp (cdr range)))
5967           (setq num (- (cdr active) (- (1+ (cdr range))
5968                                        (car range)))))
5969          (t
5970           (while range
5971             (if (numberp (car range))
5972                 (setq num (1+ num))
5973               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5974             (setq range (cdr range)))
5975           (setq num (- (cdr active) num))))
5976         ;; Update the number of unread articles.
5977         (setcar entry num)
5978         ;; Update the group buffer.
5979         (unless (gnus-ephemeral-group-p group)
5980           (gnus-group-update-group group t))))))
5981
5982 (defvar gnus-newsgroup-none-id 0)
5983
5984 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5985   (let ((cur nntp-server-buffer)
5986         (dependencies
5987          (or dependencies
5988              (with-current-buffer gnus-summary-buffer
5989                gnus-newsgroup-dependencies)))
5990         headers id end ref number
5991         (mail-parse-charset gnus-newsgroup-charset)
5992         (mail-parse-ignored-charsets
5993          (save-excursion (condition-case nil
5994                              (set-buffer gnus-summary-buffer)
5995                            (error))
5996                          gnus-newsgroup-ignored-charsets)))
5997     (save-excursion
5998       (set-buffer nntp-server-buffer)
5999       ;; Translate all TAB characters into SPACE characters.
6000       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6001       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6002       (ietf-drums-unfold-fws)
6003       (gnus-run-hooks 'gnus-parse-headers-hook)
6004       (let ((case-fold-search t)
6005             in-reply-to header p lines chars)
6006         (goto-char (point-min))
6007         ;; Search to the beginning of the next header.  Error messages
6008         ;; do not begin with 2 or 3.
6009         (while (re-search-forward "^[23][0-9]+ " nil t)
6010           (setq id nil
6011                 ref nil)
6012           ;; This implementation of this function, with nine
6013           ;; search-forwards instead of the one re-search-forward and
6014           ;; a case (which basically was the old function) is actually
6015           ;; about twice as fast, even though it looks messier.  You
6016           ;; can't have everything, I guess.  Speed and elegance
6017           ;; doesn't always go hand in hand.
6018           (setq
6019            header
6020            (vector
6021             ;; Number.
6022             (prog1
6023                 (setq number (read cur))
6024               (end-of-line)
6025               (setq p (point))
6026               (narrow-to-region (point)
6027                                 (or (and (search-forward "\n.\n" nil t)
6028                                          (- (point) 2))
6029                                     (point))))
6030             ;; Subject.
6031             (progn
6032               (goto-char p)
6033               (if (search-forward "\nsubject:" nil t)
6034                   (funcall gnus-decode-encoded-word-function
6035                            (nnheader-header-value))
6036                 "(none)"))
6037             ;; From.
6038             (progn
6039               (goto-char p)
6040               (if (search-forward "\nfrom:" nil t)
6041                   (funcall gnus-decode-encoded-word-function
6042                            (nnheader-header-value))
6043                 "(nobody)"))
6044             ;; Date.
6045             (progn
6046               (goto-char p)
6047               (if (search-forward "\ndate:" nil t)
6048                   (nnheader-header-value) ""))
6049             ;; Message-ID.
6050             (progn
6051               (goto-char p)
6052               (setq id (if (re-search-forward
6053                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6054                            ;; We do it this way to make sure the Message-ID
6055                            ;; is (somewhat) syntactically valid.
6056                            (buffer-substring (match-beginning 1)
6057                                              (match-end 1))
6058                          ;; If there was no message-id, we just fake one
6059                          ;; to make subsequent routines simpler.
6060                          (nnheader-generate-fake-message-id number))))
6061             ;; References.
6062             (progn
6063               (goto-char p)
6064               (if (search-forward "\nreferences:" nil t)
6065                   (progn
6066                     (setq end (point))
6067                     (prog1
6068                         (nnheader-header-value)
6069                       (setq ref
6070                             (buffer-substring
6071                              (progn
6072                                (end-of-line)
6073                                (search-backward ">" end t)
6074                                (1+ (point)))
6075                              (progn
6076                                (search-backward "<" end t)
6077                                (point))))))
6078                 ;; Get the references from the in-reply-to header if there
6079                 ;; were no references and the in-reply-to header looks
6080                 ;; promising.
6081                 (if (and (search-forward "\nin-reply-to:" nil t)
6082                          (setq in-reply-to (nnheader-header-value))
6083                          (string-match "<[^>]+>" in-reply-to))
6084                     (let (ref2)
6085                       (setq ref (substring in-reply-to (match-beginning 0)
6086                                            (match-end 0)))
6087                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6088                         (setq ref2 (substring in-reply-to (match-beginning 0)
6089                                               (match-end 0)))
6090                         (when (> (length ref2) (length ref))
6091                           (setq ref ref2)))
6092                       ref)
6093                   (setq ref nil))))
6094             ;; Chars.
6095             (progn
6096               (goto-char p)
6097               (if (search-forward "\nchars: " nil t)
6098                   (if (numberp (setq chars (ignore-errors (read cur))))
6099                       chars -1)
6100                 -1))
6101             ;; Lines.
6102             (progn
6103               (goto-char p)
6104               (if (search-forward "\nlines: " nil t)
6105                   (if (numberp (setq lines (ignore-errors (read cur))))
6106                       lines -1)
6107                 -1))
6108             ;; Xref.
6109             (progn
6110               (goto-char p)
6111               (and (search-forward "\nxref:" nil t)
6112                    (nnheader-header-value)))
6113             ;; Extra.
6114             (when gnus-extra-headers
6115               (let ((extra gnus-extra-headers)
6116                     out)
6117                 (while extra
6118                   (goto-char p)
6119                   (when (search-forward
6120                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6121                     (push (cons (car extra) (nnheader-header-value))
6122                           out))
6123                   (pop extra))
6124                 out))))
6125           (when (equal id ref)
6126             (setq ref nil))
6127
6128           (when gnus-alter-header-function
6129             (funcall gnus-alter-header-function header)
6130             (setq id (mail-header-id header)
6131                   ref (gnus-parent-id (mail-header-references header))))
6132
6133           (when (setq header
6134                       (gnus-dependencies-add-header
6135                        header dependencies force-new))
6136             (push header headers))
6137           (goto-char (point-max))
6138           (widen))
6139         (nreverse headers)))))
6140
6141 ;; Goes through the xover lines and returns a list of vectors
6142 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6143                                                   force-new dependencies
6144                                                   group also-fetch-heads)
6145   "Parse the news overview data in the server buffer.
6146 Return a list of headers that match SEQUENCE (see
6147 `nntp-retrieve-headers')."
6148   ;; Get the Xref when the users reads the articles since most/some
6149   ;; NNTP servers do not include Xrefs when using XOVER.
6150   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6151   (let ((mail-parse-charset gnus-newsgroup-charset)
6152         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6153         (cur nntp-server-buffer)
6154         (dependencies (or dependencies gnus-newsgroup-dependencies))
6155         (allp (cond
6156                ((eq gnus-read-all-available-headers t)
6157                 t)
6158                ((stringp gnus-read-all-available-headers)
6159                 (string-match gnus-read-all-available-headers group))
6160                (t
6161                 nil)))
6162         number headers header)
6163     (save-excursion
6164       (set-buffer nntp-server-buffer)
6165       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6166       ;; Allow the user to mangle the headers before parsing them.
6167       (gnus-run-hooks 'gnus-parse-headers-hook)
6168       (goto-char (point-min))
6169       (gnus-parse-without-error
6170         (while (and (or sequence allp)
6171                     (not (eobp)))
6172           (setq number (read cur))
6173           (when (not allp)
6174             (while (and sequence
6175                         (< (car sequence) number))
6176               (setq sequence (cdr sequence))))
6177           (when (and (or allp
6178                          (and sequence
6179                               (eq number (car sequence))))
6180                      (progn
6181                        (setq sequence (cdr sequence))
6182                        (setq header (inline
6183                                       (gnus-nov-parse-line
6184                                        number dependencies force-new)))))
6185             (push header headers))
6186           (forward-line 1)))
6187       ;; A common bug in inn is that if you have posted an article and
6188       ;; then retrieves the active file, it will answer correctly --
6189       ;; the new article is included.  However, a NOV entry for the
6190       ;; article may not have been generated yet, so this may fail.
6191       ;; We work around this problem by retrieving the last few
6192       ;; headers using HEAD.
6193       (if (or (not also-fetch-heads)
6194               (not sequence))
6195           ;; We (probably) got all the headers.
6196           (nreverse headers)
6197         (let ((gnus-nov-is-evil t))
6198           (nconc
6199            (nreverse headers)
6200            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6201              (gnus-get-newsgroup-headers))))))))
6202
6203 (defun gnus-article-get-xrefs ()
6204   "Fill in the Xref value in `gnus-current-headers', if necessary.
6205 This is meant to be called in `gnus-article-internal-prepare-hook'."
6206   (let ((headers (with-current-buffer gnus-summary-buffer
6207                    gnus-current-headers)))
6208     (or (not gnus-use-cross-reference)
6209         (not headers)
6210         (and (mail-header-xref headers)
6211              (not (string= (mail-header-xref headers) "")))
6212         (let ((case-fold-search t)
6213               xref)
6214           (save-restriction
6215             (nnheader-narrow-to-headers)
6216             (goto-char (point-min))
6217             (when (or (and (not (eobp))
6218                            (eq (downcase (char-after)) ?x)
6219                            (looking-at "Xref:"))
6220                       (search-forward "\nXref:" nil t))
6221               (goto-char (1+ (match-end 0)))
6222               (setq xref (buffer-substring (point) (point-at-eol)))
6223               (mail-header-set-xref headers xref)))))))
6224
6225 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6226   "Find article ID and insert the summary line for that article.
6227 OLD-HEADER can either be a header or a line number to insert
6228 the subject line on."
6229   (let* ((line (and (numberp old-header) old-header))
6230          (old-header (and (vectorp old-header) old-header))
6231          (header (cond ((and old-header use-old-header)
6232                         old-header)
6233                        ((and (numberp id)
6234                              (gnus-number-to-header id))
6235                         (gnus-number-to-header id))
6236                        (t
6237                         (gnus-read-header id))))
6238          (number (and (numberp id) id))
6239          d)
6240     (when header
6241       ;; Rebuild the thread that this article is part of and go to the
6242       ;; article we have fetched.
6243       (when (and (not gnus-show-threads)
6244                  old-header)
6245         (when (and number
6246                    (setq d (gnus-data-find (mail-header-number old-header))))
6247           (goto-char (gnus-data-pos d))
6248           (gnus-data-remove
6249            number
6250            (- (point-at-bol)
6251               (prog1
6252                   (1+ (point-at-eol))
6253                 (gnus-delete-line))))))
6254       ;; Remove list identifiers from subject.
6255       (when gnus-list-identifiers
6256         (let ((gnus-newsgroup-headers (list header)))
6257           (gnus-summary-remove-list-identifiers)))
6258       (when old-header
6259         (mail-header-set-number header (mail-header-number old-header)))
6260       (setq gnus-newsgroup-sparse
6261             (delq (setq number (mail-header-number header))
6262                   gnus-newsgroup-sparse))
6263       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6264       (push number gnus-newsgroup-limit)
6265       (gnus-rebuild-thread (mail-header-id header) line)
6266       (gnus-summary-goto-subject number nil t))
6267     (when (and (numberp number)
6268                (> number 0))
6269       ;; We have to update the boundaries even if we can't fetch the
6270       ;; article if ID is a number -- so that the next `P' or `N'
6271       ;; command will fetch the previous (or next) article even
6272       ;; if the one we tried to fetch this time has been canceled.
6273       (when (> number gnus-newsgroup-end)
6274         (setq gnus-newsgroup-end number))
6275       (when (< number gnus-newsgroup-begin)
6276         (setq gnus-newsgroup-begin number))
6277       (setq gnus-newsgroup-unselected
6278             (delq number gnus-newsgroup-unselected)))
6279     ;; Report back a success?
6280     (and header (mail-header-number header))))
6281
6282 ;;; Process/prefix in the summary buffer
6283
6284 (defun gnus-summary-work-articles (n)
6285   "Return a list of articles to be worked upon.
6286 The prefix argument, the list of process marked articles, and the
6287 current article will be taken into consideration."
6288   (save-excursion
6289     (set-buffer gnus-summary-buffer)
6290     (cond
6291      (n
6292       ;; A numerical prefix has been given.
6293       (setq n (prefix-numeric-value n))
6294       (let ((backward (< n 0))
6295             (n (abs (prefix-numeric-value n)))
6296             articles article)
6297         (save-excursion
6298           (while
6299               (and (> n 0)
6300                    (push (setq article (gnus-summary-article-number))
6301                          articles)
6302                    (if backward
6303                        (gnus-summary-find-prev nil article)
6304                      (gnus-summary-find-next nil article)))
6305             (decf n)))
6306         (nreverse articles)))
6307      ((and (gnus-region-active-p) (mark))
6308       (message "region active")
6309       ;; Work on the region between point and mark.
6310       (let ((max (max (point) (mark)))
6311             articles article)
6312         (save-excursion
6313           (goto-char (min (point) (mark)))
6314           (while
6315               (and
6316                (push (setq article (gnus-summary-article-number)) articles)
6317                (gnus-summary-find-next nil article)
6318                (< (point) max)))
6319           (nreverse articles))))
6320      (gnus-newsgroup-processable
6321       ;; There are process-marked articles present.
6322       ;; Save current state.
6323       (gnus-summary-save-process-mark)
6324       ;; Return the list.
6325       (reverse gnus-newsgroup-processable))
6326      (t
6327       ;; Just return the current article.
6328       (list (gnus-summary-article-number))))))
6329
6330 (defmacro gnus-summary-iterate (arg &rest forms)
6331   "Iterate over the process/prefixed articles and do FORMS.
6332 ARG is the interactive prefix given to the command.  FORMS will be
6333 executed with point over the summary line of the articles."
6334   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6335     `(let ((,articles (gnus-summary-work-articles ,arg)))
6336        (while ,articles
6337          (gnus-summary-goto-subject (car ,articles))
6338          ,@forms
6339          (pop ,articles)))))
6340
6341 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6342 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6343
6344 (defun gnus-summary-save-process-mark ()
6345   "Push the current set of process marked articles on the stack."
6346   (interactive)
6347   (push (copy-sequence gnus-newsgroup-processable)
6348         gnus-newsgroup-process-stack))
6349
6350 (defun gnus-summary-kill-process-mark ()
6351   "Push the current set of process marked articles on the stack and unmark."
6352   (interactive)
6353   (gnus-summary-save-process-mark)
6354   (gnus-summary-unmark-all-processable))
6355
6356 (defun gnus-summary-yank-process-mark ()
6357   "Pop the last process mark state off the stack and restore it."
6358   (interactive)
6359   (unless gnus-newsgroup-process-stack
6360     (error "Empty mark stack"))
6361   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6362
6363 (defun gnus-summary-process-mark-set (set)
6364   "Make SET into the current process marked articles."
6365   (gnus-summary-unmark-all-processable)
6366   (mapc 'gnus-summary-set-process-mark set))
6367
6368 ;;; Searching and stuff
6369
6370 (defun gnus-summary-search-group (&optional backward use-level)
6371   "Search for next unread newsgroup.
6372 If optional argument BACKWARD is non-nil, search backward instead."
6373   (save-excursion
6374     (set-buffer gnus-group-buffer)
6375     (when (gnus-group-search-forward
6376            backward nil (if use-level (gnus-group-group-level) nil))
6377       (gnus-group-group-name))))
6378
6379 (defun gnus-summary-best-group (&optional exclude-group)
6380   "Find the name of the best unread group.
6381 If EXCLUDE-GROUP, do not go to this group."
6382   (with-current-buffer gnus-group-buffer
6383     (save-excursion
6384       (gnus-group-best-unread-group exclude-group))))
6385
6386 (defun gnus-summary-find-next (&optional unread article backward)
6387   (if backward
6388       (gnus-summary-find-prev unread article)
6389     (let* ((dummy (gnus-summary-article-intangible-p))
6390            (article (or article (gnus-summary-article-number)))
6391            (data (gnus-data-find-list article))
6392            result)
6393       (when (and (not dummy)
6394                  (or (not gnus-summary-check-current)
6395                      (not unread)
6396                      (not (gnus-data-unread-p (car data)))))
6397         (setq data (cdr data)))
6398       (when (setq result
6399                   (if unread
6400                       (progn
6401                         (while data
6402                           (unless (memq (gnus-data-number (car data))
6403                                         (cond
6404                                          ((eq gnus-auto-goto-ignores
6405                                               'always-undownloaded)
6406                                           gnus-newsgroup-undownloaded)
6407                                          (gnus-plugged
6408                                           nil)
6409                                          ((eq gnus-auto-goto-ignores
6410                                               'unfetched)
6411                                           gnus-newsgroup-unfetched)
6412                                          ((eq gnus-auto-goto-ignores
6413                                               'undownloaded)
6414                                           gnus-newsgroup-undownloaded)))
6415                             (when (gnus-data-unread-p (car data))
6416                               (setq result (car data)
6417                                     data nil)))
6418                           (setq data (cdr data)))
6419                         result)
6420                     (car data)))
6421         (goto-char (gnus-data-pos result))
6422         (gnus-data-number result)))))
6423
6424 (defun gnus-summary-find-prev (&optional unread article)
6425   (let* ((eobp (eobp))
6426          (article (or article (gnus-summary-article-number)))
6427          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6428          result)
6429     (when (and (not eobp)
6430                (or (not gnus-summary-check-current)
6431                    (not unread)
6432                    (not (gnus-data-unread-p (car data)))))
6433       (setq data (cdr data)))
6434     (when (setq result
6435                 (if unread
6436                     (progn
6437                       (while data
6438                         (unless (memq (gnus-data-number (car data))
6439                                       (cond
6440                                        ((eq gnus-auto-goto-ignores
6441                                             'always-undownloaded)
6442                                         gnus-newsgroup-undownloaded)
6443                                        (gnus-plugged
6444                                         nil)
6445                                        ((eq gnus-auto-goto-ignores
6446                                             'unfetched)
6447                                         gnus-newsgroup-unfetched)
6448                                        ((eq gnus-auto-goto-ignores
6449                                             'undownloaded)
6450                                         gnus-newsgroup-undownloaded)))
6451                           (when (gnus-data-unread-p (car data))
6452                             (setq result (car data)
6453                                   data nil)))
6454                         (setq data (cdr data)))
6455                       result)
6456                   (car data)))
6457       (goto-char (gnus-data-pos result))
6458       (gnus-data-number result))))
6459
6460 (defun gnus-summary-find-subject (subject &optional unread backward article)
6461   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6462          (article (or article (gnus-summary-article-number)))
6463          (articles (gnus-data-list backward))
6464          (arts (gnus-data-find-list article articles))
6465          result)
6466     (when (or (not gnus-summary-check-current)
6467               (not unread)
6468               (not (gnus-data-unread-p (car arts))))
6469       (setq arts (cdr arts)))
6470     (while arts
6471       (and (or (not unread)
6472                (gnus-data-unread-p (car arts)))
6473            (vectorp (gnus-data-header (car arts)))
6474            (gnus-subject-equal
6475             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6476            (setq result (car arts)
6477                  arts nil))
6478       (setq arts (cdr arts)))
6479     (and result
6480          (goto-char (gnus-data-pos result))
6481          (gnus-data-number result))))
6482
6483 (defun gnus-summary-search-forward (&optional unread subject backward)
6484   "Search forward for an article.
6485 If UNREAD, look for unread articles.  If SUBJECT, look for
6486 articles with that subject.  If BACKWARD, search backward instead."
6487   (cond (subject (gnus-summary-find-subject subject unread backward))
6488         (backward (gnus-summary-find-prev unread))
6489         (t (gnus-summary-find-next unread))))
6490
6491 (defun gnus-recenter (&optional n)
6492   "Center point in window and redisplay frame.
6493 Also do horizontal recentering."
6494   (interactive "P")
6495   (when (and gnus-auto-center-summary
6496              (not (eq gnus-auto-center-summary 'vertical)))
6497     (gnus-horizontal-recenter))
6498   (recenter n))
6499
6500 (defun gnus-summary-recenter ()
6501   "Center point in the summary window.
6502 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6503 displayed, no centering will be performed."
6504   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6505   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6506   (interactive)
6507   ;; The user has to want it.
6508   (when gnus-auto-center-summary
6509     (let* ((top (cond ((< (window-height) 4) 0)
6510                       ((< (window-height) 7) 1)
6511                       (t (if (numberp gnus-auto-center-summary)
6512                              gnus-auto-center-summary
6513                            (/ (1- (window-height)) 2)))))
6514            (height (1- (window-height)))
6515            (bottom (save-excursion (goto-char (point-max))
6516                                    (forward-line (- height))
6517                                    (point)))
6518            (window (get-buffer-window (current-buffer))))
6519       (when (get-buffer-window gnus-article-buffer)
6520         ;; Only do recentering when the article buffer is displayed,
6521         ;; Set the window start to either `bottom', which is the biggest
6522         ;; possible valid number, or the second line from the top,
6523         ;; whichever is the least.
6524         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6525           (if (> bottom top-pos)
6526               ;; Keep the second line from the top visible
6527               (set-window-start window top-pos t)
6528             ;; Try to keep the bottom line visible; if it's partially
6529             ;; obscured, either scroll one more line to make it fully
6530             ;; visible, or revert to using TOP-POS.
6531             (save-excursion
6532               (goto-char (point-max))
6533               (forward-line -1)
6534               (let ((last-line-start (point)))
6535                 (goto-char bottom)
6536                 (set-window-start window (point) t)
6537                 (when (not (pos-visible-in-window-p last-line-start window))
6538                   (forward-line 1)
6539                   (set-window-start window (min (point) top-pos) t)))))))
6540       ;; Do horizontal recentering while we're at it.
6541       (when (and (get-buffer-window (current-buffer) t)
6542                  (not (eq gnus-auto-center-summary 'vertical)))
6543         (let ((selected (selected-window)))
6544           (select-window (get-buffer-window (current-buffer) t))
6545           (gnus-summary-position-point)
6546           (gnus-horizontal-recenter)
6547           (select-window selected))))))
6548
6549 (defun gnus-summary-jump-to-group (newsgroup)
6550   "Move point to NEWSGROUP in group mode buffer."
6551   ;; Keep update point of group mode buffer if visible.
6552   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6553       (save-window-excursion
6554         ;; Take care of tree window mode.
6555         (when (get-buffer-window gnus-group-buffer)
6556           (pop-to-buffer gnus-group-buffer))
6557         (gnus-group-jump-to-group newsgroup))
6558     (save-excursion
6559       ;; Take care of tree window mode.
6560       (if (get-buffer-window gnus-group-buffer)
6561           (pop-to-buffer gnus-group-buffer)
6562         (set-buffer gnus-group-buffer))
6563       (gnus-group-jump-to-group newsgroup))))
6564
6565 ;; This function returns a list of article numbers based on the
6566 ;; difference between the ranges of read articles in this group and
6567 ;; the range of active articles.
6568 (defun gnus-list-of-unread-articles (group)
6569   (let* ((read (gnus-info-read (gnus-get-info group)))
6570          (active (or (gnus-active group) (gnus-activate-group group)))
6571          (last (or (cdr active)
6572                    (error "Group %s couldn't be activated " group)))
6573          first nlast unread)
6574     ;; If none are read, then all are unread.
6575     (if (not read)
6576         (setq first (car active))
6577       ;; If the range of read articles is a single range, then the
6578       ;; first unread article is the article after the last read
6579       ;; article.  Sounds logical, doesn't it?
6580       (if (and (not (listp (cdr read)))
6581                (or (< (car read) (car active))
6582                    (progn (setq read (list read))
6583                           nil)))
6584           (setq first (max (car active) (1+ (cdr read))))
6585         ;; `read' is a list of ranges.
6586         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6587                                   (caar read)))
6588                   1)
6589           (setq first (car active)))
6590         (while read
6591           (when first
6592             (while (< first nlast)
6593               (setq unread (cons first unread)
6594                     first (1+ first))))
6595           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6596           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6597           (setq read (cdr read)))))
6598     ;; And add the last unread articles.
6599     (while (<= first last)
6600       (setq unread (cons first unread)
6601             first (1+ first)))
6602     ;; Return the list of unread articles.
6603     (delq 0 (nreverse unread))))
6604
6605 (defun gnus-list-of-read-articles (group)
6606   "Return a list of unread, unticked and non-dormant articles."
6607   (let* ((info (gnus-get-info group))
6608          (marked (gnus-info-marks info))
6609          (active (gnus-active group)))
6610     (and info active
6611          (gnus-list-range-difference
6612           (gnus-list-range-difference
6613            (gnus-sorted-complement
6614             (gnus-uncompress-range active)
6615             (gnus-list-of-unread-articles group))
6616            (cdr (assq 'dormant marked)))
6617           (cdr (assq 'tick marked))))))
6618
6619 ;; This function returns a sequence of article numbers based on the
6620 ;; difference between the ranges of read articles in this group and
6621 ;; the range of active articles.
6622 (defun gnus-sequence-of-unread-articles (group)
6623   (let* ((read (gnus-info-read (gnus-get-info group)))
6624          (active (or (gnus-active group) (gnus-activate-group group)))
6625          (last (cdr active))
6626          first nlast unread)
6627     ;; If none are read, then all are unread.
6628     (if (not read)
6629         (setq first (car active))
6630       ;; If the range of read articles is a single range, then the
6631       ;; first unread article is the article after the last read
6632       ;; article.  Sounds logical, doesn't it?
6633       (if (and (not (listp (cdr read)))
6634                (or (< (car read) (car active))
6635                    (progn (setq read (list read))
6636                           nil)))
6637           (setq first (max (car active) (1+ (cdr read))))
6638         ;; `read' is a list of ranges.
6639         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6640                                   (caar read)))
6641                   1)
6642           (setq first (car active)))
6643         (while read
6644           (when first
6645             (push (cons first nlast) unread))
6646           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6647           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6648           (setq read (cdr read)))))
6649     ;; And add the last unread articles.
6650     (cond ((< first last)
6651            (push (cons first last) unread))
6652           ((= first last)
6653            (push first unread)))
6654     ;; Return the sequence of unread articles.
6655     (delq 0 (nreverse unread))))
6656
6657 ;; Various summary commands
6658
6659 (defun gnus-summary-select-article-buffer ()
6660   "Reconfigure windows to show article buffer."
6661   (interactive)
6662   (if (not (gnus-buffer-live-p gnus-article-buffer))
6663       (error "There is no article buffer for this summary buffer")
6664     (gnus-configure-windows 'article)
6665     (select-window (get-buffer-window gnus-article-buffer))))
6666
6667 (defun gnus-summary-universal-argument (arg)
6668   "Perform any operation on all articles that are process/prefixed."
6669   (interactive "P")
6670   (let ((articles (gnus-summary-work-articles arg))
6671         func article)
6672     (if (eq
6673          (setq
6674           func
6675           (key-binding
6676            (read-key-sequence
6677             (substitute-command-keys
6678              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6679          'undefined)
6680         (gnus-error 1 "Undefined key")
6681       (save-excursion
6682         (while articles
6683           (gnus-summary-goto-subject (setq article (pop articles)))
6684           (let (gnus-newsgroup-processable)
6685             (command-execute func))
6686           (gnus-summary-remove-process-mark article)))))
6687   (gnus-summary-position-point))
6688
6689 (defun gnus-summary-toggle-truncation (&optional arg)
6690   "Toggle truncation of summary lines.
6691 With ARG, turn line truncation on if ARG is positive."
6692   (interactive "P")
6693   (setq truncate-lines
6694         (if (null arg) (not truncate-lines)
6695           (> (prefix-numeric-value arg) 0)))
6696   (redraw-display))
6697
6698 (defun gnus-summary-find-for-reselect ()
6699   "Return the number of an article to stay on across a reselect.
6700 The current article is considered, then following articles, then previous
6701 articles.  An article is sought which is not cancelled and isn't a temporary
6702 insertion from another group.  If there's no such then return a dummy 0."
6703   (let (found)
6704     (dolist (rev '(nil t))
6705       (unless found      ; don't demand the reverse list if we don't need it
6706         (let ((data (gnus-data-find-list
6707                      (gnus-summary-article-number) (gnus-data-list rev))))
6708           (while (and data (not found))
6709             (if (and (< 0 (gnus-data-number (car data)))
6710                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6711                 (setq found (gnus-data-number (car data))))
6712             (setq data (cdr data))))))
6713     (or found 0)))
6714
6715 (defun gnus-summary-reselect-current-group (&optional all rescan)
6716   "Exit and then reselect the current newsgroup.
6717 The prefix argument ALL means to select all articles."
6718   (interactive "P")
6719   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6720     (error "Ephemeral groups can't be reselected"))
6721   (let ((current-subject (gnus-summary-find-for-reselect))
6722         (group gnus-newsgroup-name))
6723     (setq gnus-newsgroup-begin nil)
6724     (gnus-summary-exit nil 'leave-hidden)
6725     ;; We have to adjust the point of group mode buffer because
6726     ;; point was moved to the next unread newsgroup by exiting.
6727     (gnus-summary-jump-to-group group)
6728     (when rescan
6729       (save-excursion
6730         (gnus-group-get-new-news-this-group 1)))
6731     (gnus-group-read-group all t)
6732     (gnus-summary-goto-subject current-subject nil t)))
6733
6734 (defun gnus-summary-rescan-group (&optional all)
6735   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6736   (interactive "P")
6737   (gnus-summary-reselect-current-group all t))
6738
6739 (defun gnus-summary-update-info (&optional non-destructive)
6740   (save-excursion
6741     (let ((group gnus-newsgroup-name))
6742       (when group
6743         (when gnus-newsgroup-kill-headers
6744           (setq gnus-newsgroup-killed
6745                 (gnus-compress-sequence
6746                  (gnus-sorted-union
6747                   (gnus-list-range-intersection
6748                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6749                   gnus-newsgroup-unreads)
6750                  t)))
6751         (unless (listp (cdr gnus-newsgroup-killed))
6752           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6753         (let ((headers gnus-newsgroup-headers))
6754           ;; Set the new ranges of read articles.
6755           (with-current-buffer gnus-group-buffer
6756             (gnus-undo-force-boundary))
6757           (gnus-update-read-articles
6758            group (gnus-sorted-union
6759                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6760           ;; Set the current article marks.
6761           (let ((gnus-newsgroup-scored
6762                  (if (and (not gnus-save-score)
6763                           (not non-destructive))
6764                      nil
6765                    gnus-newsgroup-scored)))
6766             (save-excursion
6767               (gnus-update-marks)))
6768           ;; Do the cross-ref thing.
6769           (when gnus-use-cross-reference
6770             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6771           ;; Do not switch windows but change the buffer to work.
6772           (set-buffer gnus-group-buffer)
6773           (unless (gnus-ephemeral-group-p group)
6774             (gnus-group-update-group group)))))))
6775
6776 (defun gnus-summary-save-newsrc (&optional force)
6777   "Save the current number of read/marked articles in the dribble buffer.
6778 The dribble buffer will then be saved.
6779 If FORCE (the prefix), also save the .newsrc file(s)."
6780   (interactive "P")
6781   (gnus-summary-update-info t)
6782   (if force
6783       (gnus-save-newsrc-file)
6784     (gnus-dribble-save)))
6785
6786 (defun gnus-summary-exit (&optional temporary leave-hidden)
6787   "Exit reading current newsgroup, and then return to group selection mode.
6788 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6789   (interactive)
6790   (gnus-set-global-variables)
6791   (when (gnus-buffer-live-p gnus-article-buffer)
6792     (save-excursion
6793       (set-buffer gnus-article-buffer)
6794       (mm-destroy-parts gnus-article-mime-handles)
6795       ;; Set it to nil for safety reason.
6796       (setq gnus-article-mime-handle-alist nil)
6797       (setq gnus-article-mime-handles nil)))
6798   (gnus-kill-save-kill-buffer)
6799   (gnus-async-halt-prefetch)
6800   (let* ((group gnus-newsgroup-name)
6801          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6802          (gnus-group-is-exiting-p t)
6803          (mode major-mode)
6804          (group-point nil)
6805          (buf (current-buffer)))
6806     (unless quit-config
6807       ;; Do adaptive scoring, and possibly save score files.
6808       (when gnus-newsgroup-adaptive
6809         (gnus-score-adaptive))
6810       (when gnus-use-scoring
6811         (gnus-score-save)))
6812     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6813     ;; If we have several article buffers, we kill them at exit.
6814     (unless gnus-single-article-buffer
6815       (gnus-kill-buffer gnus-original-article-buffer)
6816       (setq gnus-article-current nil))
6817     (when gnus-use-cache
6818       (gnus-cache-possibly-remove-articles)
6819       (gnus-cache-save-buffers))
6820     (gnus-async-prefetch-remove-group group)
6821     (when gnus-suppress-duplicates
6822       (gnus-dup-enter-articles))
6823     (when gnus-use-trees
6824       (gnus-tree-close group))
6825     (when gnus-use-cache
6826       (gnus-cache-write-active))
6827     ;; Remove entries for this group.
6828     (nnmail-purge-split-history (gnus-group-real-name group))
6829     ;; Make all changes in this group permanent.
6830     (unless quit-config
6831       (gnus-run-hooks 'gnus-exit-group-hook)
6832       (gnus-summary-update-info))
6833     (gnus-close-group group)
6834     ;; Make sure where we were, and go to next newsgroup.
6835     (set-buffer gnus-group-buffer)
6836     (unless quit-config
6837       (gnus-group-jump-to-group group))
6838     (gnus-run-hooks 'gnus-summary-exit-hook)
6839     (unless (or quit-config
6840                 ;; If this group has disappeared from the summary
6841                 ;; buffer, don't skip forwards.
6842                 (not (string= group (gnus-group-group-name))))
6843       (gnus-group-next-unread-group 1))
6844     (setq group-point (point))
6845     (if temporary
6846         nil                             ;Nothing to do.
6847       ;; If we have several article buffers, we kill them at exit.
6848       (unless gnus-single-article-buffer
6849         (gnus-kill-buffer gnus-article-buffer)
6850         (gnus-kill-buffer gnus-original-article-buffer)
6851         (setq gnus-article-current nil))
6852       (set-buffer buf)
6853       (if (not gnus-kill-summary-on-exit)
6854           (progn
6855             (gnus-deaden-summary)
6856             (setq mode nil))
6857         ;; We set all buffer-local variables to nil.  It is unclear why
6858         ;; this is needed, but if we don't, buffer-local variables are
6859         ;; not garbage-collected, it seems.  This would the lead to en
6860         ;; ever-growing Emacs.
6861         (gnus-summary-clear-local-variables)
6862         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6863           (gnus-summary-clear-local-variables))
6864         (when (get-buffer gnus-article-buffer)
6865           (bury-buffer gnus-article-buffer))
6866         ;; Return to group mode buffer.
6867         (when (eq mode 'gnus-summary-mode)
6868           (gnus-kill-buffer buf)))
6869       (setq gnus-current-select-method gnus-select-method)
6870       (set-buffer gnus-group-buffer)
6871       (if quit-config
6872           (gnus-handle-ephemeral-exit quit-config)
6873         (goto-char group-point)
6874         ;; If gnus-group-buffer is already displayed, make sure we also move
6875         ;; the cursor in the window that displays it.
6876         (let ((win (get-buffer-window (current-buffer) 0)))
6877           (if win (set-window-point win (point))))
6878         (unless leave-hidden
6879           (gnus-configure-windows 'group 'force)))
6880       ;; Clear the current group name.
6881       (unless quit-config
6882         (setq gnus-newsgroup-name nil)))))
6883
6884 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6885 (defun gnus-summary-exit-no-update (&optional no-questions)
6886   "Quit reading current newsgroup without updating read article info."
6887   (interactive)
6888   (let* ((group gnus-newsgroup-name)
6889          (gnus-group-is-exiting-p t)
6890          (gnus-group-is-exiting-without-update-p t)
6891          (quit-config (gnus-group-quit-config group)))
6892     (when (or no-questions
6893               gnus-expert-user
6894               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6895       (gnus-async-halt-prefetch)
6896       (run-hooks 'gnus-summary-prepare-exit-hook)
6897       (when (gnus-buffer-live-p gnus-article-buffer)
6898         (save-excursion
6899           (set-buffer gnus-article-buffer)
6900           (mm-destroy-parts gnus-article-mime-handles)
6901           ;; Set it to nil for safety reason.
6902           (setq gnus-article-mime-handle-alist nil)
6903           (setq gnus-article-mime-handles nil)))
6904       ;; If we have several article buffers, we kill them at exit.
6905       (unless gnus-single-article-buffer
6906         (gnus-kill-buffer gnus-article-buffer)
6907         (gnus-kill-buffer gnus-original-article-buffer)
6908         (setq gnus-article-current nil))
6909       (if (not gnus-kill-summary-on-exit)
6910           (gnus-deaden-summary)
6911         (gnus-close-group group)
6912         (gnus-summary-clear-local-variables)
6913         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6914           (gnus-summary-clear-local-variables))
6915         (gnus-kill-buffer gnus-summary-buffer))
6916       (unless gnus-single-article-buffer
6917         (setq gnus-article-current nil))
6918       (when gnus-use-trees
6919         (gnus-tree-close group))
6920       (gnus-async-prefetch-remove-group group)
6921       (when (get-buffer gnus-article-buffer)
6922         (bury-buffer gnus-article-buffer))
6923       ;; Return to the group buffer.
6924       (gnus-configure-windows 'group 'force)
6925       ;; Clear the current group name.
6926       (setq gnus-newsgroup-name nil)
6927       (unless (gnus-ephemeral-group-p group)
6928         (gnus-group-update-group group))
6929       (when (equal (gnus-group-group-name) group)
6930         (gnus-group-next-unread-group 1))
6931       (when quit-config
6932         (gnus-handle-ephemeral-exit quit-config)))))
6933
6934 (defun gnus-handle-ephemeral-exit (quit-config)
6935   "Handle movement when leaving an ephemeral group.
6936 The state which existed when entering the ephemeral is reset."
6937   (if (not (buffer-name (car quit-config)))
6938       (gnus-configure-windows 'group 'force)
6939     (set-buffer (car quit-config))
6940     (cond ((eq major-mode 'gnus-summary-mode)
6941            (gnus-set-global-variables))
6942           ((eq major-mode 'gnus-article-mode)
6943            (save-excursion
6944              ;; The `gnus-summary-buffer' variable may point
6945              ;; to the old summary buffer when using a single
6946              ;; article buffer.
6947              (unless (gnus-buffer-live-p gnus-summary-buffer)
6948                (set-buffer gnus-group-buffer))
6949              (set-buffer gnus-summary-buffer)
6950              (gnus-set-global-variables))))
6951     (if (or (eq (cdr quit-config) 'article)
6952             (eq (cdr quit-config) 'pick))
6953         (progn
6954           ;; The current article may be from the ephemeral group
6955           ;; thus it is best that we reload this article
6956           ;;
6957           ;; If we're exiting from a large digest, this can be
6958           ;; extremely slow.  So, it's better not to reload it. -- jh.
6959           ;;(gnus-summary-show-article)
6960           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6961               (gnus-configure-windows 'pick 'force)
6962             (gnus-configure-windows (cdr quit-config) 'force)))
6963       (gnus-configure-windows (cdr quit-config) 'force))
6964     (when (eq major-mode 'gnus-summary-mode)
6965       (gnus-summary-next-subject 1 nil t)
6966       (gnus-summary-recenter)
6967       (gnus-summary-position-point))))
6968
6969 ;;; Dead summaries.
6970
6971 (defvar gnus-dead-summary-mode-map nil)
6972
6973 (unless gnus-dead-summary-mode-map
6974   (setq gnus-dead-summary-mode-map (make-keymap))
6975   (suppress-keymap gnus-dead-summary-mode-map)
6976   (substitute-key-definition
6977    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6978   (dolist (key '("\C-d" "\r" "\177" [delete]))
6979     (define-key gnus-dead-summary-mode-map
6980       key 'gnus-summary-wake-up-the-dead))
6981   (dolist (key '("q" "Q"))
6982     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6983
6984 (defvar gnus-dead-summary-mode nil
6985   "Minor mode for Gnus summary buffers.")
6986
6987 (defun gnus-dead-summary-mode (&optional arg)
6988   "Minor mode for Gnus summary buffers."
6989   (interactive "P")
6990   (when (eq major-mode 'gnus-summary-mode)
6991     (make-local-variable 'gnus-dead-summary-mode)
6992     (setq gnus-dead-summary-mode
6993           (if (null arg) (not gnus-dead-summary-mode)
6994             (> (prefix-numeric-value arg) 0)))
6995     (when gnus-dead-summary-mode
6996       (add-minor-mode
6997        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6998
6999 (defun gnus-deaden-summary ()
7000   "Make the current summary buffer into a dead summary buffer."
7001   ;; Kill any previous dead summary buffer.
7002   (when (and gnus-dead-summary
7003              (buffer-name gnus-dead-summary))
7004     (with-current-buffer gnus-dead-summary
7005       (when gnus-dead-summary-mode
7006         (kill-buffer (current-buffer)))))
7007   ;; Make this the current dead summary.
7008   (setq gnus-dead-summary (current-buffer))
7009   (gnus-dead-summary-mode 1)
7010   (let ((name (buffer-name)))
7011     (when (string-match "Summary" name)
7012       (rename-buffer
7013        (concat (substring name 0 (match-beginning 0)) "Dead "
7014                (substring name (match-beginning 0)))
7015        t)
7016       (bury-buffer))))
7017
7018 (defun gnus-kill-or-deaden-summary (buffer)
7019   "Kill or deaden the summary BUFFER."
7020   (save-excursion
7021     (when (and (buffer-name buffer)
7022                (not gnus-single-article-buffer))
7023       (with-current-buffer buffer
7024         (gnus-kill-buffer gnus-article-buffer)
7025         (gnus-kill-buffer gnus-original-article-buffer)))
7026     (cond
7027      ;; Kill the buffer.
7028      (gnus-kill-summary-on-exit
7029       (when (and gnus-use-trees
7030                  (gnus-buffer-exists-p buffer))
7031         (save-excursion
7032           (set-buffer buffer)
7033           (gnus-tree-close gnus-newsgroup-name)))
7034       (gnus-kill-buffer buffer))
7035      ;; Deaden the buffer.
7036      ((gnus-buffer-exists-p buffer)
7037       (save-excursion
7038         (set-buffer buffer)
7039         (gnus-deaden-summary))))))
7040
7041 (defun gnus-summary-wake-up-the-dead (&rest args)
7042   "Wake up the dead summary buffer."
7043   (interactive)
7044   (gnus-dead-summary-mode -1)
7045   (let ((name (buffer-name)))
7046     (when (string-match "Dead " name)
7047       (rename-buffer
7048        (concat (substring name 0 (match-beginning 0))
7049                (substring name (match-end 0)))
7050        t)))
7051   (gnus-message 3 "This dead summary is now alive again"))
7052
7053 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7054 (defun gnus-summary-fetch-faq (&optional faq-dir)
7055   "Fetch the FAQ for the current group.
7056 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7057 in."
7058   (interactive
7059    (list
7060     (when current-prefix-arg
7061       (completing-read
7062        "FAQ dir: " (and (listp gnus-group-faq-directory)
7063                         (mapcar 'list
7064                                 gnus-group-faq-directory))))))
7065   (let (gnus-faq-buffer)
7066     (when (setq gnus-faq-buffer
7067                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7068       (gnus-configure-windows 'summary-faq))))
7069
7070 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7071 (defun gnus-summary-describe-group (&optional force)
7072   "Describe the current newsgroup."
7073   (interactive "P")
7074   (gnus-group-describe-group force gnus-newsgroup-name))
7075
7076 (defun gnus-summary-describe-briefly ()
7077   "Describe summary mode commands briefly."
7078   (interactive)
7079   (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")))
7080
7081 ;; Walking around group mode buffer from summary mode.
7082
7083 (defun gnus-summary-next-group (&optional no-article target-group backward)
7084   "Exit current newsgroup and then select next unread newsgroup.
7085 If prefix argument NO-ARTICLE is non-nil, no article is selected
7086 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7087 previous group instead."
7088   (interactive "P")
7089   ;; Stop pre-fetching.
7090   (gnus-async-halt-prefetch)
7091   (let ((current-group gnus-newsgroup-name)
7092         (current-buffer (current-buffer))
7093         entered)
7094     ;; First we semi-exit this group to update Xrefs and all variables.
7095     ;; We can't do a real exit, because the window conf must remain
7096     ;; the same in case the user is prompted for info, and we don't
7097     ;; want the window conf to change before that...
7098     (gnus-summary-exit t)
7099     (while (not entered)
7100       ;; Then we find what group we are supposed to enter.
7101       (set-buffer gnus-group-buffer)
7102       (gnus-group-jump-to-group current-group)
7103       (setq target-group
7104             (or target-group
7105                 (if (eq gnus-keep-same-level 'best)
7106                     (gnus-summary-best-group gnus-newsgroup-name)
7107                   (gnus-summary-search-group backward gnus-keep-same-level))))
7108       (if (not target-group)
7109           ;; There are no further groups, so we return to the group
7110           ;; buffer.
7111           (progn
7112             (gnus-message 5 "Returning to the group buffer")
7113             (setq entered t)
7114             (when (gnus-buffer-live-p current-buffer)
7115               (set-buffer current-buffer)
7116               (gnus-summary-exit))
7117             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7118         ;; We try to enter the target group.
7119         (gnus-group-jump-to-group target-group)
7120         (let ((unreads (gnus-group-group-unread)))
7121           (if (and (or (eq t unreads)
7122                        (and unreads (not (zerop unreads))))
7123                    (gnus-summary-read-group
7124                     target-group nil no-article
7125                     (and (buffer-name current-buffer) current-buffer)
7126                     nil backward))
7127               (setq entered t)
7128             (setq current-group target-group
7129                   target-group nil)))))))
7130
7131 (defun gnus-summary-prev-group (&optional no-article)
7132   "Exit current newsgroup and then select previous unread newsgroup.
7133 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7134   (interactive "P")
7135   (gnus-summary-next-group no-article nil t))
7136
7137 ;; Walking around summary lines.
7138
7139 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7140   "Go to the first subject satisfying any non-nil constraint.
7141 If UNREAD is non-nil, the article should be unread.
7142 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7143 If UNSEEN is non-nil, the article should be unseen.
7144 Returns the article selected or nil if there are no matching articles."
7145   (interactive "P")
7146   (cond
7147    ;; Empty summary.
7148    ((null gnus-newsgroup-data)
7149     (gnus-message 3 "No articles in the group")
7150     nil)
7151    ;; Pick the first article.
7152    ((not (or unread undownloaded unseen))
7153     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7154     (gnus-data-number (car gnus-newsgroup-data)))
7155    ;; Find the first unread article.
7156    (t
7157     (let ((data gnus-newsgroup-data))
7158       (while (and data
7159                   (let ((num (gnus-data-number (car data))))
7160                     (or (memq num gnus-newsgroup-unfetched)
7161                         (not (or (and unread
7162                                       (memq num gnus-newsgroup-unreads))
7163                                  (and undownloaded
7164                                       (memq num gnus-newsgroup-undownloaded))
7165                                  (and unseen
7166                                       (memq num gnus-newsgroup-unseen)))))))
7167         (setq data (cdr data)))
7168       (prog1
7169           (if data
7170               (progn
7171                 (goto-char (gnus-data-pos (car data)))
7172                 (gnus-data-number (car data)))
7173             (gnus-message 3 "No more%s articles"
7174                           (let* ((r (when unread " unread"))
7175                                  (d (when undownloaded " undownloaded"))
7176                                  (s (when unseen " unseen"))
7177                                  (l (delq nil (list r d s))))
7178                             (cond ((= 3 (length l))
7179                                    (concat r "," d ", or" s))
7180                                   ((= 2 (length l))
7181                                    (concat (car l) ", or" (cadr l)))
7182                                   ((= 1 (length l))
7183                                    (car l))
7184                                   (t
7185                                    ""))))
7186             nil
7187             )
7188         (gnus-summary-position-point))))))
7189
7190 (defun gnus-summary-next-subject (n &optional unread dont-display)
7191   "Go to next N'th summary line.
7192 If N is negative, go to the previous N'th subject line.
7193 If UNREAD is non-nil, only unread articles are selected.
7194 The difference between N and the actual number of steps taken is
7195 returned."
7196   (interactive "p")
7197   (let ((backward (< n 0))
7198         (n (abs n)))
7199     (while (and (> n 0)
7200                 (if backward
7201                     (gnus-summary-find-prev unread)
7202                   (gnus-summary-find-next unread)))
7203       (unless (zerop (setq n (1- n)))
7204         (gnus-summary-show-thread)))
7205     (when (/= 0 n)
7206       (gnus-message 7 "No more%s articles"
7207                     (if unread " unread" "")))
7208     (unless dont-display
7209       (gnus-summary-recenter)
7210       (gnus-summary-position-point))
7211     n))
7212
7213 (defun gnus-summary-next-unread-subject (n)
7214   "Go to next N'th unread summary line."
7215   (interactive "p")
7216   (gnus-summary-next-subject n t))
7217
7218 (defun gnus-summary-prev-subject (n &optional unread)
7219   "Go to previous N'th summary line.
7220 If optional argument UNREAD is non-nil, only unread article is selected."
7221   (interactive "p")
7222   (gnus-summary-next-subject (- n) unread))
7223
7224 (defun gnus-summary-prev-unread-subject (n)
7225   "Go to previous N'th unread summary line."
7226   (interactive "p")
7227   (gnus-summary-next-subject (- n) t))
7228
7229 (defun gnus-summary-goto-subjects (articles)
7230   "Insert the subject header for ARTICLES in the current buffer."
7231   (save-excursion
7232     (dolist (article articles)
7233       (gnus-summary-goto-subject article t)))
7234   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7235   (gnus-summary-position-point))
7236
7237 (defun gnus-summary-goto-subject (article &optional force silent)
7238   "Go the subject line of ARTICLE.
7239 If FORCE, also allow jumping to articles not currently shown."
7240   (interactive "nArticle number: ")
7241   (unless (numberp article)
7242     (error "Article %s is not a number" article))
7243   (let ((b (point))
7244         (data (gnus-data-find article)))
7245     ;; We read in the article if we have to.
7246     (and (not data)
7247          force
7248          (gnus-summary-insert-subject
7249           article
7250           (if (or (numberp force) (vectorp force)) force)
7251           t)
7252          (setq data (gnus-data-find article)))
7253     (goto-char b)
7254     (if (not data)
7255         (progn
7256           (unless silent
7257             (gnus-message 3 "Can't find article %d" article))
7258           nil)
7259       (let ((pt (gnus-data-pos data)))
7260         (goto-char pt)
7261         (gnus-summary-set-article-display-arrow pt))
7262       (gnus-summary-position-point)
7263       article)))
7264
7265 ;; Walking around summary lines with displaying articles.
7266
7267 (defun gnus-summary-expand-window (&optional arg)
7268   "Make the summary buffer take up the entire Emacs frame.
7269 Given a prefix, will force an `article' buffer configuration."
7270   (interactive "P")
7271   (if arg
7272       (gnus-configure-windows 'article 'force)
7273     (gnus-configure-windows 'summary 'force)))
7274
7275 (defun gnus-summary-display-article (article &optional all-header)
7276   "Display ARTICLE in article buffer."
7277   (when (gnus-buffer-live-p gnus-article-buffer)
7278     (with-current-buffer gnus-article-buffer
7279       (mm-enable-multibyte)))
7280   (gnus-set-global-variables)
7281   (when (gnus-buffer-live-p gnus-article-buffer)
7282     (with-current-buffer gnus-article-buffer
7283       (setq gnus-article-charset gnus-newsgroup-charset)
7284       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7285       (mm-enable-multibyte)))
7286   (if (null article)
7287       nil
7288     (prog1
7289         (if gnus-summary-display-article-function
7290             (funcall gnus-summary-display-article-function article all-header)
7291           (gnus-article-prepare article all-header))
7292       (gnus-run-hooks 'gnus-select-article-hook)
7293       (when (and gnus-current-article
7294                  (not (zerop gnus-current-article)))
7295         (gnus-summary-goto-subject gnus-current-article))
7296       (gnus-summary-recenter)
7297       (when (and gnus-use-trees gnus-show-threads)
7298         (gnus-possibly-generate-tree article)
7299         (gnus-highlight-selected-tree article))
7300       ;; Successfully display article.
7301       (gnus-article-set-window-start
7302        (cdr (assq article gnus-newsgroup-bookmarks))))))
7303
7304 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7305   "Select the current article.
7306 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7307 non-nil, the article will be re-fetched even if it already present in
7308 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7309 be displayed."
7310   ;; Make sure we are in the summary buffer to work around bbdb bug.
7311   (unless (eq major-mode 'gnus-summary-mode)
7312     (set-buffer gnus-summary-buffer))
7313   (let ((article (or article (gnus-summary-article-number)))
7314         (all-headers (not (not all-headers))) ;Must be t or nil.
7315         gnus-summary-display-article-function)
7316     (and (not pseudo)
7317          (gnus-summary-article-pseudo-p article)
7318          (error "This is a pseudo-article"))
7319     (save-excursion
7320       (set-buffer gnus-summary-buffer)
7321       (if (or (and gnus-single-article-buffer
7322                    (or (null gnus-current-article)
7323                        (null gnus-article-current)
7324                        (null (get-buffer gnus-article-buffer))
7325                        (not (eq article (cdr gnus-article-current)))
7326                        (not (equal (car gnus-article-current)
7327                                    gnus-newsgroup-name))))
7328               (and (not gnus-single-article-buffer)
7329                    (or (null gnus-current-article)
7330                        (not (eq gnus-current-article article))))
7331               force)
7332           ;; The requested article is different from the current article.
7333           (progn
7334             (gnus-summary-display-article article all-headers)
7335             (when (gnus-buffer-live-p gnus-article-buffer)
7336               (with-current-buffer gnus-article-buffer
7337                 (if (not gnus-article-decoded-p) ;; a local variable
7338                     (mm-disable-multibyte))))
7339             (gnus-article-set-window-start
7340              (cdr (assq article gnus-newsgroup-bookmarks)))
7341             article)
7342         'old))))
7343
7344 (defun gnus-summary-force-verify-and-decrypt ()
7345   "Display buttons for signed/encrypted parts and verify/decrypt them."
7346   (interactive)
7347   (let ((mm-verify-option 'known)
7348         (mm-decrypt-option 'known)
7349         (gnus-article-emulate-mime t)
7350         (gnus-buttonized-mime-types (append (list "multipart/signed"
7351                                                   "multipart/encrypted")
7352                                             gnus-buttonized-mime-types)))
7353     (gnus-summary-select-article nil 'force)))
7354
7355 (defun gnus-summary-set-current-mark (&optional current-mark)
7356   "Obsolete function."
7357   nil)
7358
7359 (defun gnus-summary-next-article (&optional unread subject backward push)
7360   "Select the next article.
7361 If UNREAD, only unread articles are selected.
7362 If SUBJECT, only articles with SUBJECT are selected.
7363 If BACKWARD, the previous article is selected instead of the next."
7364   (interactive "P")
7365   (cond
7366    ;; Is there such an article?
7367    ((and (gnus-summary-search-forward unread subject backward)
7368          (or (gnus-summary-display-article (gnus-summary-article-number))
7369              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7370     (gnus-summary-position-point))
7371    ;; If not, we try the first unread, if that is wanted.
7372    ((and subject
7373          gnus-auto-select-same
7374          (gnus-summary-first-unread-article))
7375     (gnus-summary-position-point)
7376     (gnus-message 6 "Wrapped"))
7377    ;; Try to get next/previous article not displayed in this group.
7378    ((and gnus-auto-extend-newsgroup
7379          (not unread) (not subject))
7380     (gnus-summary-goto-article
7381      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7382      nil (count-lines (point-min) (point))))
7383    ;; Go to next/previous group.
7384    (t
7385     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7386       (gnus-summary-jump-to-group gnus-newsgroup-name))
7387     (let ((cmd last-command-char)
7388           (point
7389            (with-current-buffer gnus-group-buffer
7390              (point)))
7391           (group
7392            (if (eq gnus-keep-same-level 'best)
7393                (gnus-summary-best-group gnus-newsgroup-name)
7394              (gnus-summary-search-group backward gnus-keep-same-level))))
7395       ;; For some reason, the group window gets selected.  We change
7396       ;; it back.
7397       (select-window (get-buffer-window (current-buffer)))
7398       ;; Select next unread newsgroup automagically.
7399       (cond
7400        ((or (not gnus-auto-select-next)
7401             (not cmd))
7402         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7403        ((or (eq gnus-auto-select-next 'quietly)
7404             (and (eq gnus-auto-select-next 'slightly-quietly)
7405                  push)
7406             (and (eq gnus-auto-select-next 'almost-quietly)
7407                  (gnus-summary-last-article-p)))
7408         ;; Select quietly.
7409         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7410             (gnus-summary-exit)
7411           (gnus-message 7 "No more%s articles (%s)..."
7412                         (if unread " unread" "")
7413                         (if group (concat "selecting " group)
7414                           "exiting"))
7415           (gnus-summary-next-group nil group backward)))
7416        (t
7417         (when (gnus-key-press-event-p last-input-event)
7418           (gnus-summary-walk-group-buffer
7419            gnus-newsgroup-name cmd unread backward point))))))))
7420
7421 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7422   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7423                       (?\C-p (gnus-group-prev-unread-group 1))))
7424         (cursor-in-echo-area t)
7425         keve key group ended prompt)
7426     (save-excursion
7427       (set-buffer gnus-group-buffer)
7428       (goto-char start)
7429       (setq group
7430             (if (eq gnus-keep-same-level 'best)
7431                 (gnus-summary-best-group gnus-newsgroup-name)
7432               (gnus-summary-search-group backward gnus-keep-same-level))))
7433     (while (not ended)
7434       (setq prompt
7435             (format
7436              "No more%s articles%s " (if unread " unread" "")
7437              (if (and group
7438                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7439                  (format " (Type %s for %s [%s])"
7440                          (single-key-description cmd)
7441                          (gnus-group-decoded-name group)
7442                          (gnus-group-unread group))
7443                (format " (Type %s to exit %s)"
7444                        (single-key-description cmd)
7445                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7446       ;; Confirm auto selection.
7447       (setq key (car (setq keve (gnus-read-event-char prompt)))
7448             ended t)
7449       (cond
7450        ((assq key keystrokes)
7451         (let ((obuf (current-buffer)))
7452           (switch-to-buffer gnus-group-buffer)
7453           (when group
7454             (gnus-group-jump-to-group group))
7455           (eval (cadr (assq key keystrokes)))
7456           (setq group (gnus-group-group-name))
7457           (switch-to-buffer obuf))
7458         (setq ended nil))
7459        ((equal key cmd)
7460         (if (or (not group)
7461                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7462             (gnus-summary-exit)
7463           (gnus-summary-next-group nil group backward)))
7464        (t
7465         (push (cdr keve) unread-command-events))))))
7466
7467 (defun gnus-summary-next-unread-article ()
7468   "Select unread article after current one."
7469   (interactive)
7470   (gnus-summary-next-article
7471    (or (not (eq gnus-summary-goto-unread 'never))
7472        (gnus-summary-last-article-p (gnus-summary-article-number)))
7473    (and gnus-auto-select-same
7474         (gnus-summary-article-subject))))
7475
7476 (defun gnus-summary-prev-article (&optional unread subject)
7477   "Select the article after the current one.
7478 If UNREAD is non-nil, only unread articles are selected."
7479   (interactive "P")
7480   (gnus-summary-next-article unread subject t))
7481
7482 (defun gnus-summary-prev-unread-article ()
7483   "Select unread article before current one."
7484   (interactive)
7485   (gnus-summary-prev-article
7486    (or (not (eq gnus-summary-goto-unread 'never))
7487        (gnus-summary-first-article-p (gnus-summary-article-number)))
7488    (and gnus-auto-select-same
7489         (gnus-summary-article-subject))))
7490
7491 (defun gnus-summary-next-page (&optional lines circular stop)
7492   "Show next page of the selected article.
7493 If at the end of the current article, select the next article.
7494 LINES says how many lines should be scrolled up.
7495
7496 If CIRCULAR is non-nil, go to the start of the article instead of
7497 selecting the next article when reaching the end of the current
7498 article.
7499
7500 If STOP is non-nil, just stop when reaching the end of the message.
7501
7502 Also see the variable `gnus-article-skip-boring'."
7503   (interactive "P")
7504   (setq gnus-summary-buffer (current-buffer))
7505   (gnus-set-global-variables)
7506   (let ((article (gnus-summary-article-number))
7507         (article-window (get-buffer-window gnus-article-buffer t))
7508         endp)
7509     ;; If the buffer is empty, we have no article.
7510     (unless article
7511       (error "No article to select"))
7512     (gnus-configure-windows 'article)
7513     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7514         (if (and (eq gnus-summary-goto-unread 'never)
7515                  (not (gnus-summary-last-article-p article)))
7516             (gnus-summary-next-article)
7517           (gnus-summary-next-unread-article))
7518       (if (or (null gnus-current-article)
7519               (null gnus-article-current)
7520               (/= article (cdr gnus-article-current))
7521               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7522           ;; Selected subject is different from current article's.
7523           (gnus-summary-display-article article)
7524         (when article-window
7525           (gnus-eval-in-buffer-window gnus-article-buffer
7526             (setq endp (or (gnus-article-next-page lines)
7527                            (gnus-article-only-boring-p))))
7528           (when endp
7529             (cond (stop
7530                    (gnus-message 3 "End of message"))
7531                   (circular
7532                    (gnus-summary-beginning-of-article))
7533                   (lines
7534                    (gnus-message 3 "End of message"))
7535                   ((null lines)
7536                    (if (and (eq gnus-summary-goto-unread 'never)
7537                             (not (gnus-summary-last-article-p article)))
7538                        (gnus-summary-next-article)
7539                      (gnus-summary-next-unread-article))))))))
7540     (gnus-summary-recenter)
7541     (gnus-summary-position-point)))
7542
7543 (defun gnus-summary-prev-page (&optional lines move)
7544   "Show previous page of selected article.
7545 Argument LINES specifies lines to be scrolled down.
7546 If MOVE, move to the previous unread article if point is at
7547 the beginning of the buffer."
7548   (interactive "P")
7549   (let ((article (gnus-summary-article-number))
7550         (article-window (get-buffer-window gnus-article-buffer t))
7551         endp)
7552     (gnus-configure-windows 'article)
7553     (if (or (null gnus-current-article)
7554             (null gnus-article-current)
7555             (/= article (cdr gnus-article-current))
7556             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7557         ;; Selected subject is different from current article's.
7558         (gnus-summary-display-article article)
7559       (gnus-summary-recenter)
7560       (when article-window
7561         (gnus-eval-in-buffer-window gnus-article-buffer
7562           (setq endp (gnus-article-prev-page lines)))
7563         (when (and move endp)
7564           (cond (lines
7565                  (gnus-message 3 "Beginning of message"))
7566                 ((null lines)
7567                  (if (and (eq gnus-summary-goto-unread 'never)
7568                           (not (gnus-summary-first-article-p article)))
7569                      (gnus-summary-prev-article)
7570                    (gnus-summary-prev-unread-article))))))))
7571   (gnus-summary-position-point))
7572
7573 (defun gnus-summary-prev-page-or-article (&optional lines)
7574   "Show previous page of selected article.
7575 Argument LINES specifies lines to be scrolled down.
7576 If at the beginning of the article, go to the next article."
7577   (interactive "P")
7578   (gnus-summary-prev-page lines t))
7579
7580 (defun gnus-summary-scroll-up (lines)
7581   "Scroll up (or down) one line current article.
7582 Argument LINES specifies lines to be scrolled up (or down if negative)."
7583   (interactive "p")
7584   (gnus-configure-windows 'article)
7585   (gnus-summary-show-thread)
7586   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7587     (gnus-eval-in-buffer-window gnus-article-buffer
7588       (cond ((> lines 0)
7589              (when (gnus-article-next-page lines)
7590                (gnus-message 3 "End of message")))
7591             ((< lines 0)
7592              (gnus-article-prev-page (- lines))))))
7593   (gnus-summary-recenter)
7594   (gnus-summary-position-point))
7595
7596 (defun gnus-summary-scroll-down (lines)
7597   "Scroll down (or up) one line current article.
7598 Argument LINES specifies lines to be scrolled down (or up if negative)."
7599   (interactive "p")
7600   (gnus-summary-scroll-up (- lines)))
7601
7602 (defun gnus-summary-next-same-subject ()
7603   "Select next article which has the same subject as current one."
7604   (interactive)
7605   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7606
7607 (defun gnus-summary-prev-same-subject ()
7608   "Select previous article which has the same subject as current one."
7609   (interactive)
7610   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7611
7612 (defun gnus-summary-next-unread-same-subject ()
7613   "Select next unread article which has the same subject as current one."
7614   (interactive)
7615   (gnus-summary-next-article t (gnus-summary-article-subject)))
7616
7617 (defun gnus-summary-prev-unread-same-subject ()
7618   "Select previous unread article which has the same subject as current one."
7619   (interactive)
7620   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7621
7622 (defun gnus-summary-first-unread-article ()
7623   "Select the first unread article.
7624 Return nil if there are no unread articles."
7625   (interactive)
7626   (prog1
7627       (when (gnus-summary-first-subject t)
7628         (gnus-summary-show-thread)
7629         (gnus-summary-first-subject t)
7630         (gnus-summary-display-article (gnus-summary-article-number)))
7631     (gnus-summary-position-point)))
7632
7633 (defun gnus-summary-first-unread-subject ()
7634   "Place the point on the subject line of the first unread article.
7635 Return nil if there are no unread articles."
7636   (interactive)
7637   (prog1
7638       (when (gnus-summary-first-subject t)
7639         (gnus-summary-show-thread)
7640         (gnus-summary-first-subject t))
7641     (gnus-summary-position-point)))
7642
7643 (defun gnus-summary-first-unseen-subject ()
7644   "Place the point on the subject line of the first unseen article.
7645 Return nil if there are no unseen articles."
7646   (interactive)
7647   (prog1
7648       (when (gnus-summary-first-subject nil nil t)
7649         (gnus-summary-show-thread)
7650         (gnus-summary-first-subject nil nil t))
7651     (gnus-summary-position-point)))
7652
7653 (defun gnus-summary-first-unseen-or-unread-subject ()
7654   "Place the point on the subject line of the first unseen article or,
7655 if all article have been seen, on the subject line of the first unread
7656 article."
7657   (interactive)
7658   (prog1
7659       (unless (when (gnus-summary-first-subject nil nil t)
7660                 (gnus-summary-show-thread)
7661                 (gnus-summary-first-subject nil nil t))
7662         (when (gnus-summary-first-subject t)
7663           (gnus-summary-show-thread)
7664           (gnus-summary-first-subject t)))
7665     (gnus-summary-position-point)))
7666
7667 (defun gnus-summary-first-article ()
7668   "Select the first article.
7669 Return nil if there are no articles."
7670   (interactive)
7671   (prog1
7672       (when (gnus-summary-first-subject)
7673         (gnus-summary-show-thread)
7674         (gnus-summary-first-subject)
7675         (gnus-summary-display-article (gnus-summary-article-number)))
7676     (gnus-summary-position-point)))
7677
7678 (defun gnus-summary-best-unread-article (&optional arg)
7679   "Select the unread article with the highest score.
7680 If given a prefix argument, select the next unread article that has a
7681 score higher than the default score."
7682   (interactive "P")
7683   (let ((article (if arg
7684                      (gnus-summary-better-unread-subject)
7685                    (gnus-summary-best-unread-subject))))
7686     (if article
7687         (gnus-summary-goto-article article)
7688       (error "No unread articles"))))
7689
7690 (defun gnus-summary-best-unread-subject ()
7691   "Select the unread subject with the highest score."
7692   (interactive)
7693   (let ((best -1000000)
7694         (data gnus-newsgroup-data)
7695         article score)
7696     (while data
7697       (and (gnus-data-unread-p (car data))
7698            (> (setq score
7699                     (gnus-summary-article-score (gnus-data-number (car data))))
7700               best)
7701            (setq best score
7702                  article (gnus-data-number (car data))))
7703       (setq data (cdr data)))
7704     (when article
7705       (gnus-summary-goto-subject article))
7706     (gnus-summary-position-point)
7707     article))
7708
7709 (defun gnus-summary-better-unread-subject ()
7710   "Select the first unread subject that has a score over the default score."
7711   (interactive)
7712   (let ((data gnus-newsgroup-data)
7713         article score)
7714     (while (and (setq article (gnus-data-number (car data)))
7715                 (or (gnus-data-read-p (car data))
7716                     (not (> (gnus-summary-article-score article)
7717                             gnus-summary-default-score))))
7718       (setq data (cdr data)))
7719     (when article
7720       (gnus-summary-goto-subject article))
7721     (gnus-summary-position-point)
7722     article))
7723
7724 (defun gnus-summary-last-subject ()
7725   "Go to the last displayed subject line in the group."
7726   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7727     (when article
7728       (gnus-summary-goto-subject article))))
7729
7730 (defun gnus-summary-goto-article (article &optional all-headers force)
7731   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7732 If ALL-HEADERS is non-nil, no header lines are hidden.
7733 If FORCE, go to the article even if it isn't displayed.  If FORCE
7734 is a number, it is the line the article is to be displayed on."
7735   (interactive
7736    (list
7737     (completing-read
7738      "Article number or Message-ID: "
7739      (mapcar (lambda (number) (list (int-to-string number)))
7740              gnus-newsgroup-limit))
7741     current-prefix-arg
7742     t))
7743   (prog1
7744       (if (and (stringp article)
7745                (string-match "@\\|%40" article))
7746           (gnus-summary-refer-article article)
7747         (when (stringp article)
7748           (setq article (string-to-number article)))
7749         (if (gnus-summary-goto-subject article force)
7750             (gnus-summary-display-article article all-headers)
7751           (gnus-message 4 "Couldn't go to article %s" article) nil))
7752     (gnus-summary-position-point)))
7753
7754 (defun gnus-summary-goto-last-article ()
7755   "Go to the previously read article."
7756   (interactive)
7757   (prog1
7758       (when gnus-last-article
7759         (gnus-summary-goto-article gnus-last-article nil t))
7760     (gnus-summary-position-point)))
7761
7762 (defun gnus-summary-pop-article (number)
7763   "Pop one article off the history and go to the previous.
7764 NUMBER articles will be popped off."
7765   (interactive "p")
7766   (let (to)
7767     (setq gnus-newsgroup-history
7768           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7769     (if to
7770         (gnus-summary-goto-article (car to) nil t)
7771       (error "Article history empty")))
7772   (gnus-summary-position-point))
7773
7774 ;; Summary commands and functions for limiting the summary buffer.
7775
7776 (defun gnus-summary-limit-to-articles (n)
7777   "Limit the summary buffer to the next N articles.
7778 If not given a prefix, use the process marked articles instead."
7779   (interactive "P")
7780   (prog1
7781       (let ((articles (gnus-summary-work-articles n)))
7782         (setq gnus-newsgroup-processable nil)
7783         (gnus-summary-limit articles))
7784     (gnus-summary-position-point)))
7785
7786 (defun gnus-summary-pop-limit (&optional total)
7787   "Restore the previous limit.
7788 If given a prefix, remove all limits."
7789   (interactive "P")
7790   (when total
7791     (setq gnus-newsgroup-limits
7792           (list (mapcar (lambda (h) (mail-header-number h))
7793                         gnus-newsgroup-headers))))
7794   (unless gnus-newsgroup-limits
7795     (error "No limit to pop"))
7796   (prog1
7797       (gnus-summary-limit nil 'pop)
7798     (gnus-summary-position-point)))
7799
7800 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7801   "Limit the summary buffer to articles that have subjects that match a regexp.
7802 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7803   (interactive
7804    (list (read-string (if current-prefix-arg
7805                           "Exclude subject (regexp): "
7806                         "Limit to subject (regexp): "))
7807          nil current-prefix-arg))
7808   (unless header
7809     (setq header "subject"))
7810   (when (not (equal "" subject))
7811     (prog1
7812         (let ((articles (gnus-summary-find-matching
7813                          (or header "subject") subject 'all nil nil
7814                          not-matching)))
7815           (unless articles
7816             (error "Found no matches for \"%s\"" subject))
7817           (gnus-summary-limit articles))
7818       (gnus-summary-position-point))))
7819
7820 (defun gnus-summary-limit-to-author (from &optional not-matching)
7821   "Limit the summary buffer to articles that have authors that match a regexp.
7822 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7823   (interactive
7824    (list (read-string (if current-prefix-arg
7825                           "Exclude author (regexp): "
7826                         "Limit to author (regexp): "))
7827          current-prefix-arg))
7828   (gnus-summary-limit-to-subject from "from" not-matching))
7829
7830 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7831   "Limit the summary buffer to articles with the given RECIPIENT.
7832
7833 If NOT-MATCHING, exclude RECIPIENT.
7834
7835 To and Cc headers are checked.  You need to include them in
7836 `nnmail-extra-headers'."
7837   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7838   (interactive
7839    (list (read-string (format "%s recipient (regexp): "
7840                               (if current-prefix-arg "Exclude" "Limit to")))
7841          current-prefix-arg))
7842   (when (not (equal "" recipient))
7843     (prog1 (let* ((to
7844                    (if (memq 'To nnmail-extra-headers)
7845                        (gnus-summary-find-matching
7846                         (cons 'extra 'To) recipient 'all nil nil
7847                         not-matching)
7848                      (gnus-message
7849                       1 "`To' isn't present in `nnmail-extra-headers'")
7850                      (sit-for 1)
7851                      nil))
7852                   (cc
7853                    (if (memq 'Cc nnmail-extra-headers)
7854                        (gnus-summary-find-matching
7855                         (cons 'extra 'Cc) recipient 'all nil nil
7856                         not-matching)
7857                      (gnus-message
7858                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7859                      (sit-for 1)
7860                      nil))
7861                   (articles
7862                    (if not-matching
7863                        ;; We need the numbers that are in both lists:
7864                        (mapcar (lambda (a)
7865                                  (and (memq a to) a))
7866                                cc)
7867                      (nconc to cc))))
7868              (unless articles
7869                (error "Found no matches for \"%s\"" recipient))
7870              (gnus-summary-limit articles))
7871       (gnus-summary-position-point))))
7872
7873 (defun gnus-summary-limit-to-age (age &optional younger-p)
7874   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7875 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7876 articles that are younger than AGE days."
7877   (interactive
7878    (let ((younger current-prefix-arg)
7879          (days-got nil)
7880          days)
7881      (while (not days-got)
7882        (setq days (if younger
7883                       (read-string "Limit to articles younger than (in days, older when negative): ")
7884                     (read-string
7885                      "Limit to articles older than (in days, younger when negative): ")))
7886        (when (> (length days) 0)
7887          (setq days (read days)))
7888        (if (numberp days)
7889            (progn
7890              (setq days-got t)
7891              (when (< days 0)
7892                (setq younger (not younger))
7893                (setq days (* days -1))))
7894          (message "Please enter a number.")
7895          (sleep-for 1)))
7896      (list days younger)))
7897   (prog1
7898       (let ((data gnus-newsgroup-data)
7899             (cutoff (days-to-time age))
7900             articles d date is-younger)
7901         (while (setq d (pop data))
7902           (when (and (vectorp (gnus-data-header d))
7903                      (setq date (mail-header-date (gnus-data-header d))))
7904             (setq is-younger (time-less-p
7905                               (time-since (condition-case ()
7906                                               (date-to-time date)
7907                                             (error '(0 0))))
7908                               cutoff))
7909             (when (if younger-p
7910                       is-younger
7911                     (not is-younger))
7912               (push (gnus-data-number d) articles))))
7913         (gnus-summary-limit (nreverse articles)))
7914     (gnus-summary-position-point)))
7915
7916 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7917   "Limit the summary buffer to articles that match an 'extra' header."
7918   (interactive
7919    (let ((header
7920           (intern
7921            (gnus-completing-read-with-default
7922             (symbol-name (car gnus-extra-headers))
7923             (if current-prefix-arg
7924                 "Exclude extra header"
7925               "Limit extra header")
7926             (mapcar (lambda (x)
7927                       (cons (symbol-name x) x))
7928                     gnus-extra-headers)
7929             nil
7930             t))))
7931      (list header
7932            (read-string (format "%s header %s (regexp): "
7933                                 (if current-prefix-arg "Exclude" "Limit to")
7934                                 header))
7935            current-prefix-arg)))
7936   (when (not (equal "" regexp))
7937     (prog1
7938         (let ((articles (gnus-summary-find-matching
7939                          (cons 'extra header) regexp 'all nil nil
7940                          not-matching)))
7941           (unless articles
7942             (error "Found no matches for \"%s\"" regexp))
7943           (gnus-summary-limit articles))
7944       (gnus-summary-position-point))))
7945
7946 (defun gnus-summary-limit-to-display-predicate ()
7947   "Limit the summary buffer to the predicated in the `display' group parameter."
7948   (interactive)
7949   (unless gnus-newsgroup-display
7950     (error "There is no `display' group parameter"))
7951   (let (articles)
7952     (dolist (number gnus-newsgroup-articles)
7953       (when (funcall gnus-newsgroup-display)
7954         (push number articles)))
7955     (gnus-summary-limit articles))
7956   (gnus-summary-position-point))
7957
7958 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7959 (make-obsolete
7960  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7961
7962 (defun gnus-summary-limit-to-unread (&optional all)
7963   "Limit the summary buffer to articles that are not marked as read.
7964 If ALL is non-nil, limit strictly to unread articles."
7965   (interactive "P")
7966   (if all
7967       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7968     (gnus-summary-limit-to-marks
7969      ;; Concat all the marks that say that an article is read and have
7970      ;; those removed.
7971      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7972            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7973            gnus-low-score-mark gnus-expirable-mark
7974            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7975            gnus-duplicate-mark gnus-souped-mark)
7976      'reverse)))
7977
7978 (defun gnus-summary-limit-to-replied (&optional unreplied)
7979   "Limit the summary buffer to replied articles.
7980 If UNREPLIED (the prefix), limit to unreplied articles."
7981   (interactive "P")
7982   (if unreplied
7983       (gnus-summary-limit
7984        (gnus-set-difference gnus-newsgroup-articles
7985         gnus-newsgroup-replied))
7986     (gnus-summary-limit gnus-newsgroup-replied))
7987   (gnus-summary-position-point))
7988
7989 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7990 (make-obsolete 'gnus-summary-delete-marked-with
7991                'gnus-summary-limit-exclude-marks)
7992
7993 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7994   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7995 If REVERSE, limit the summary buffer to articles that are marked
7996 with MARKS.  MARKS can either be a string of marks or a list of marks.
7997 Returns how many articles were removed."
7998   (interactive "sMarks: ")
7999   (gnus-summary-limit-to-marks marks t))
8000
8001 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8002   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8003 If REVERSE (the prefix), limit the summary buffer to articles that are
8004 not marked with MARKS.  MARKS can either be a string of marks or a
8005 list of marks.
8006 Returns how many articles were removed."
8007   (interactive "sMarks: \nP")
8008   (prog1
8009       (let ((data gnus-newsgroup-data)
8010             (marks (if (listp marks) marks
8011                      (append marks nil))) ; Transform to list.
8012             articles)
8013         (while data
8014           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8015                   (memq (gnus-data-mark (car data)) marks))
8016             (push (gnus-data-number (car data)) articles))
8017           (setq data (cdr data)))
8018         (gnus-summary-limit articles))
8019     (gnus-summary-position-point)))
8020
8021 (defun gnus-summary-limit-to-score (score)
8022   "Limit to articles with score at or above SCORE."
8023   (interactive "NLimit to articles with score of at least: ")
8024   (let ((data gnus-newsgroup-data)
8025         articles)
8026     (while data
8027       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8028                 score)
8029         (push (gnus-data-number (car data)) articles))
8030       (setq data (cdr data)))
8031     (prog1
8032         (gnus-summary-limit articles)
8033       (gnus-summary-position-point))))
8034
8035 (defun gnus-summary-limit-to-unseen ()
8036   "Limit to unseen articles."
8037   (interactive)
8038   (prog1
8039       (gnus-summary-limit gnus-newsgroup-unseen)
8040     (gnus-summary-position-point)))
8041
8042 (defun gnus-summary-limit-include-thread (id)
8043   "Display all the hidden articles that is in the thread with ID in it.
8044 When called interactively, ID is the Message-ID of the current
8045 article."
8046   (interactive (list (mail-header-id (gnus-summary-article-header))))
8047   (let ((articles (gnus-articles-in-thread
8048                    (gnus-id-to-thread (gnus-root-id id)))))
8049     (prog1
8050         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8051       (gnus-summary-limit-include-matching-articles
8052        "subject"
8053        (regexp-quote (gnus-simplify-subject-re
8054                       (mail-header-subject (gnus-id-to-header id)))))
8055       (gnus-summary-position-point))))
8056
8057 (defun gnus-summary-limit-include-matching-articles (header regexp)
8058   "Display all the hidden articles that have HEADERs that match REGEXP."
8059   (interactive (list (read-string "Match on header: ")
8060                      (read-string "Regexp: ")))
8061   (let ((articles (gnus-find-matching-articles header regexp)))
8062     (prog1
8063         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8064       (gnus-summary-position-point))))
8065
8066 (defun gnus-summary-insert-dormant-articles ()
8067   "Insert all the dormant articles for this group into the current buffer."
8068   (interactive)
8069   (let ((gnus-verbose (max 6 gnus-verbose)))
8070     (if (not gnus-newsgroup-dormant)
8071         (gnus-message 3 "No cached articles for this group")
8072       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8073
8074 (defun gnus-summary-limit-include-dormant ()
8075   "Display all the hidden articles that are marked as dormant.
8076 Note that this command only works on a subset of the articles currently
8077 fetched for this group."
8078   (interactive)
8079   (unless gnus-newsgroup-dormant
8080     (error "There are no dormant articles in this group"))
8081   (prog1
8082       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8083     (gnus-summary-position-point)))
8084
8085 (defun gnus-summary-limit-exclude-dormant ()
8086   "Hide all dormant articles."
8087   (interactive)
8088   (prog1
8089       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8090     (gnus-summary-position-point)))
8091
8092 (defun gnus-summary-limit-exclude-childless-dormant ()
8093   "Hide all dormant articles that have no children."
8094   (interactive)
8095   (let ((data (gnus-data-list t))
8096         articles d children)
8097     ;; Find all articles that are either not dormant or have
8098     ;; children.
8099     (while (setq d (pop data))
8100       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8101                 (and (setq children
8102                            (gnus-article-children (gnus-data-number d)))
8103                      (let (found)
8104                        (while children
8105                          (when (memq (car children) articles)
8106                            (setq children nil
8107                                  found t))
8108                          (pop children))
8109                        found)))
8110         (push (gnus-data-number d) articles)))
8111     ;; Do the limiting.
8112     (prog1
8113         (gnus-summary-limit articles)
8114       (gnus-summary-position-point))))
8115
8116 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8117   "Mark all unread excluded articles as read.
8118 If ALL, mark even excluded ticked and dormants as read."
8119   (interactive "P")
8120   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8121   (let ((articles (gnus-sorted-ndifference
8122                    (sort
8123                     (mapcar (lambda (h) (mail-header-number h))
8124                             gnus-newsgroup-headers)
8125                     '<)
8126                    gnus-newsgroup-limit))
8127         article)
8128     (setq gnus-newsgroup-unreads
8129           (gnus-sorted-intersection gnus-newsgroup-unreads
8130                                     gnus-newsgroup-limit))
8131     (if all
8132         (setq gnus-newsgroup-dormant nil
8133               gnus-newsgroup-marked nil
8134               gnus-newsgroup-reads
8135               (nconc
8136                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8137                gnus-newsgroup-reads))
8138       (while (setq article (pop articles))
8139         (unless (or (memq article gnus-newsgroup-dormant)
8140                     (memq article gnus-newsgroup-marked))
8141           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8142
8143 (defun gnus-summary-limit (articles &optional pop)
8144   (if pop
8145       ;; We pop the previous limit off the stack and use that.
8146       (setq articles (car gnus-newsgroup-limits)
8147             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8148     ;; We use the new limit, so we push the old limit on the stack.
8149     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8150   ;; Set the limit.
8151   (setq gnus-newsgroup-limit articles)
8152   (let ((total (length gnus-newsgroup-data))
8153         (data (gnus-data-find-list (gnus-summary-article-number)))
8154         (gnus-summary-mark-below nil)   ; Inhibit this.
8155         found)
8156     ;; This will do all the work of generating the new summary buffer
8157     ;; according to the new limit.
8158     (gnus-summary-prepare)
8159     ;; Hide any threads, possibly.
8160     (gnus-summary-maybe-hide-threads)
8161     ;; Try to return to the article you were at, or one in the
8162     ;; neighborhood.
8163     (when data
8164       ;; We try to find some article after the current one.
8165       (while data
8166         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8167           (setq data nil
8168                 found t))
8169         (setq data (cdr data))))
8170     (unless found
8171       ;; If there is no data, that means that we were after the last
8172       ;; article.  The same goes when we can't find any articles
8173       ;; after the current one.
8174       (goto-char (point-max))
8175       (gnus-summary-find-prev))
8176     (gnus-set-mode-line 'summary)
8177     ;; We return how many articles were removed from the summary
8178     ;; buffer as a result of the new limit.
8179     (- total (length gnus-newsgroup-data))))
8180
8181 (defsubst gnus-invisible-cut-children (threads)
8182   (let ((num 0))
8183     (while threads
8184       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8185         (incf num))
8186       (pop threads))
8187     (< num 2)))
8188
8189 (defsubst gnus-cut-thread (thread)
8190   "Go forwards in the thread until we find an article that we want to display."
8191   (when (or (eq gnus-fetch-old-headers 'some)
8192             (eq gnus-fetch-old-headers 'invisible)
8193             (numberp gnus-fetch-old-headers)
8194             (eq gnus-build-sparse-threads 'some)
8195             (eq gnus-build-sparse-threads 'more))
8196     ;; Deal with old-fetched headers and sparse threads.
8197     (while (and
8198             thread
8199             (or
8200              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8201              (gnus-summary-article-ancient-p
8202               (mail-header-number (car thread))))
8203             (if (or (<= (length (cdr thread)) 1)
8204                     (eq gnus-fetch-old-headers 'invisible))
8205                 (setq gnus-newsgroup-limit
8206                       (delq (mail-header-number (car thread))
8207                             gnus-newsgroup-limit)
8208                       thread (cadr thread))
8209               (when (gnus-invisible-cut-children (cdr thread))
8210                 (let ((th (cdr thread)))
8211                   (while th
8212                     (if (memq (mail-header-number (caar th))
8213                               gnus-newsgroup-limit)
8214                         (setq thread (car th)
8215                               th nil)
8216                       (setq th (cdr th))))))))))
8217   thread)
8218
8219 (defun gnus-cut-threads (threads)
8220   "Cut off all uninteresting articles from the beginning of THREADS."
8221   (when (or (eq gnus-fetch-old-headers 'some)
8222             (eq gnus-fetch-old-headers 'invisible)
8223             (numberp gnus-fetch-old-headers)
8224             (eq gnus-build-sparse-threads 'some)
8225             (eq gnus-build-sparse-threads 'more))
8226     (let ((th threads))
8227       (while th
8228         (setcar th (gnus-cut-thread (car th)))
8229         (setq th (cdr th)))))
8230   ;; Remove nixed out threads.
8231   (delq nil threads))
8232
8233 (defun gnus-summary-initial-limit (&optional show-if-empty)
8234   "Figure out what the initial limit is supposed to be on group entry.
8235 This entails weeding out unwanted dormants, low-scored articles,
8236 fetch-old-headers verbiage, and so on."
8237   ;; Most groups have nothing to remove.
8238   (if (or gnus-inhibit-limiting
8239           (and (null gnus-newsgroup-dormant)
8240                (eq gnus-newsgroup-display 'gnus-not-ignore)
8241                (not (eq gnus-fetch-old-headers 'some))
8242                (not (numberp gnus-fetch-old-headers))
8243                (not (eq gnus-fetch-old-headers 'invisible))
8244                (null gnus-summary-expunge-below)
8245                (not (eq gnus-build-sparse-threads 'some))
8246                (not (eq gnus-build-sparse-threads 'more))
8247                (null gnus-thread-expunge-below)
8248                (not gnus-use-nocem)))
8249       ()                                ; Do nothing.
8250     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8251     (setq gnus-newsgroup-limit nil)
8252     (mapatoms
8253      (lambda (node)
8254        (unless (car (symbol-value node))
8255          ;; These threads have no parents -- they are roots.
8256          (let ((nodes (cdr (symbol-value node)))
8257                thread)
8258            (while nodes
8259              (if (and gnus-thread-expunge-below
8260                       (< (gnus-thread-total-score (car nodes))
8261                          gnus-thread-expunge-below))
8262                  (gnus-expunge-thread (pop nodes))
8263                (setq thread (pop nodes))
8264                (gnus-summary-limit-children thread))))))
8265      gnus-newsgroup-dependencies)
8266     ;; If this limitation resulted in an empty group, we might
8267     ;; pop the previous limit and use it instead.
8268     (when (and (not gnus-newsgroup-limit)
8269                show-if-empty)
8270       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8271     gnus-newsgroup-limit))
8272
8273 (defun gnus-summary-limit-children (thread)
8274   "Return 1 if this subthread is visible and 0 if it is not."
8275   ;; First we get the number of visible children to this thread.  This
8276   ;; is done by recursing down the thread using this function, so this
8277   ;; will really go down to a leaf article first, before slowly
8278   ;; working its way up towards the root.
8279   (when thread
8280     (let* ((max-lisp-eval-depth 5000)
8281            (children
8282            (if (cdr thread)
8283                (apply '+ (mapcar 'gnus-summary-limit-children
8284                                  (cdr thread)))
8285              0))
8286           (number (mail-header-number (car thread)))
8287           score)
8288       (if (and
8289            (not (memq number gnus-newsgroup-marked))
8290            (or
8291             ;; If this article is dormant and has absolutely no visible
8292             ;; children, then this article isn't visible.
8293             (and (memq number gnus-newsgroup-dormant)
8294                  (zerop children))
8295             ;; If this is "fetch-old-headered" and there is no
8296             ;; visible children, then we don't want this article.
8297             (and (or (eq gnus-fetch-old-headers 'some)
8298                      (numberp gnus-fetch-old-headers))
8299                  (gnus-summary-article-ancient-p number)
8300                  (zerop children))
8301             ;; If this is "fetch-old-headered" and `invisible', then
8302             ;; we don't want this article.
8303             (and (eq gnus-fetch-old-headers 'invisible)
8304                  (gnus-summary-article-ancient-p number))
8305             ;; If this is a sparsely inserted article with no children,
8306             ;; we don't want it.
8307             (and (eq gnus-build-sparse-threads 'some)
8308                  (gnus-summary-article-sparse-p number)
8309                  (zerop children))
8310             ;; If we use expunging, and this article is really
8311             ;; low-scored, then we don't want this article.
8312             (when (and gnus-summary-expunge-below
8313                        (< (setq score
8314                                 (or (cdr (assq number gnus-newsgroup-scored))
8315                                     gnus-summary-default-score))
8316                           gnus-summary-expunge-below))
8317               ;; We increase the expunge-tally here, but that has
8318               ;; nothing to do with the limits, really.
8319               (incf gnus-newsgroup-expunged-tally)
8320               ;; We also mark as read here, if that's wanted.
8321               (when (and gnus-summary-mark-below
8322                          (< score gnus-summary-mark-below))
8323                 (setq gnus-newsgroup-unreads
8324                       (delq number gnus-newsgroup-unreads))
8325                 (if gnus-newsgroup-auto-expire
8326                     (push number gnus-newsgroup-expirable)
8327                   (push (cons number gnus-low-score-mark)
8328                         gnus-newsgroup-reads)))
8329               t)
8330             ;; Do the `display' group parameter.
8331             (and gnus-newsgroup-display
8332                  (not (funcall gnus-newsgroup-display)))
8333             ;; Check NoCeM things.
8334             (when (and gnus-use-nocem
8335                        (gnus-nocem-unwanted-article-p
8336                         (mail-header-id (car thread))))
8337               (setq gnus-newsgroup-unreads
8338                     (delq number gnus-newsgroup-unreads))
8339               t)))
8340           ;; Nope, invisible article.
8341           0
8342         ;; Ok, this article is to be visible, so we add it to the limit
8343         ;; and return 1.
8344         (push number gnus-newsgroup-limit)
8345         1))))
8346
8347 (defun gnus-expunge-thread (thread)
8348   "Mark all articles in THREAD as read."
8349   (let* ((number (mail-header-number (car thread))))
8350     (incf gnus-newsgroup-expunged-tally)
8351     ;; We also mark as read here, if that's wanted.
8352     (setq gnus-newsgroup-unreads
8353           (delq number gnus-newsgroup-unreads))
8354     (if gnus-newsgroup-auto-expire
8355         (push number gnus-newsgroup-expirable)
8356       (push (cons number gnus-low-score-mark)
8357             gnus-newsgroup-reads)))
8358   ;; Go recursively through all subthreads.
8359   (mapcar 'gnus-expunge-thread (cdr thread)))
8360
8361 ;; Summary article oriented commands
8362
8363 (defun gnus-summary-refer-parent-article (n)
8364   "Refer parent article N times.
8365 If N is negative, go to ancestor -N instead.
8366 The difference between N and the number of articles fetched is returned."
8367   (interactive "p")
8368   (let ((skip 1)
8369         error header ref)
8370     (when (not (natnump n))
8371       (setq skip (abs n)
8372             n 1))
8373     (while (and (> n 0)
8374                 (not error))
8375       (setq header (gnus-summary-article-header))
8376       (if (and (eq (mail-header-number header)
8377                    (cdr gnus-article-current))
8378                (equal gnus-newsgroup-name
8379                       (car gnus-article-current)))
8380           ;; If we try to find the parent of the currently
8381           ;; displayed article, then we take a look at the actual
8382           ;; References header, since this is slightly more
8383           ;; reliable than the References field we got from the
8384           ;; server.
8385           (save-excursion
8386             (set-buffer gnus-original-article-buffer)
8387             (nnheader-narrow-to-headers)
8388             (unless (setq ref (message-fetch-field "references"))
8389               (when (setq ref (message-fetch-field "in-reply-to"))
8390                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8391             (widen))
8392         (setq ref
8393               ;; It's not the current article, so we take a bet on
8394               ;; the value we got from the server.
8395               (mail-header-references header)))
8396       (if (and ref
8397                (not (equal ref "")))
8398           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8399             (gnus-message 1 "Couldn't find parent"))
8400         (gnus-message 1 "No references in article %d"
8401                       (gnus-summary-article-number))
8402         (setq error t))
8403       (decf n))
8404     (gnus-summary-position-point)
8405     n))
8406
8407 (defun gnus-summary-refer-references ()
8408   "Fetch all articles mentioned in the References header.
8409 Return the number of articles fetched."
8410   (interactive)
8411   (let ((ref (mail-header-references (gnus-summary-article-header)))
8412         (current (gnus-summary-article-number))
8413         (n 0))
8414     (if (or (not ref)
8415             (equal ref ""))
8416         (error "No References in the current article")
8417       ;; For each Message-ID in the References header...
8418       (while (string-match "<[^>]*>" ref)
8419         (incf n)
8420         ;; ... fetch that article.
8421         (gnus-summary-refer-article
8422          (prog1 (match-string 0 ref)
8423            (setq ref (substring ref (match-end 0))))))
8424       (gnus-summary-goto-subject current)
8425       (gnus-summary-position-point)
8426       n)))
8427
8428 (defun gnus-summary-refer-thread (&optional limit)
8429   "Fetch all articles in the current thread.
8430 If LIMIT (the numerical prefix), fetch that many old headers instead
8431 of what's specified by the `gnus-refer-thread-limit' variable."
8432   (interactive "P")
8433   (let ((id (mail-header-id (gnus-summary-article-header)))
8434         (limit (if limit (prefix-numeric-value limit)
8435                  gnus-refer-thread-limit)))
8436     (unless (eq gnus-fetch-old-headers 'invisible)
8437       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8438       ;; Retrieve the headers and read them in.
8439       (if (eq (if (numberp limit)
8440                   (gnus-retrieve-headers
8441                    (list (min
8442                           (+ (mail-header-number
8443                               (gnus-summary-article-header))
8444                              limit)
8445                           gnus-newsgroup-end))
8446                    gnus-newsgroup-name (* limit 2))
8447                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8448                 ;; headers.
8449                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8450                                        gnus-newsgroup-name limit))
8451               'nov)
8452           (gnus-build-all-threads)
8453         (error "Can't fetch thread from back ends that don't support NOV"))
8454       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8455     (gnus-summary-limit-include-thread id)))
8456
8457 (defun gnus-summary-refer-article (message-id)
8458   "Fetch an article specified by MESSAGE-ID."
8459   (interactive "sMessage-ID: ")
8460   (when (and (stringp message-id)
8461              (not (zerop (length message-id))))
8462     (setq message-id (gnus-replace-in-string message-id " " ""))
8463     ;; Construct the correct Message-ID if necessary.
8464     ;; Suggested by tale@pawl.rpi.edu.
8465     (unless (string-match "^<" message-id)
8466       (setq message-id (concat "<" message-id)))
8467     (unless (string-match ">$" message-id)
8468       (setq message-id (concat message-id ">")))
8469     ;; People often post MIDs from URLs, so unhex it:
8470     (unless (string-match "@" message-id)
8471       (setq message-id (gnus-url-unhex-string message-id)))
8472     (let* ((header (gnus-id-to-header message-id))
8473            (sparse (and header
8474                         (gnus-summary-article-sparse-p
8475                          (mail-header-number header))
8476                         (memq (mail-header-number header)
8477                               gnus-newsgroup-limit)))
8478            number)
8479       (cond
8480        ;; If the article is present in the buffer we just go to it.
8481        ((and header
8482              (or (not (gnus-summary-article-sparse-p
8483                        (mail-header-number header)))
8484                  sparse))
8485         (prog1
8486             (gnus-summary-goto-article
8487              (mail-header-number header) nil t)
8488           (when sparse
8489             (gnus-summary-update-article (mail-header-number header)))))
8490        (t
8491         ;; We fetch the article.
8492         (catch 'found
8493           (dolist (gnus-override-method (gnus-refer-article-methods))
8494             (when (and (gnus-check-server gnus-override-method)
8495                        ;; Fetch the header,
8496                        (setq number (gnus-summary-insert-subject message-id)))
8497               ;; and display the article.
8498               (gnus-summary-select-article nil nil nil number)
8499               (throw 'found t)))
8500           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8501
8502 (defun gnus-refer-article-methods ()
8503   "Return a list of referable methods."
8504   (cond
8505    ;; No method, so we default to current and native.
8506    ((null gnus-refer-article-method)
8507     (list gnus-current-select-method gnus-select-method))
8508    ;; Current.
8509    ((eq 'current gnus-refer-article-method)
8510     (list gnus-current-select-method))
8511    ;; List of select methods.
8512    ((not (and (symbolp (car gnus-refer-article-method))
8513               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8514     (let (out)
8515       (dolist (method gnus-refer-article-method)
8516         (push (if (eq 'current method)
8517                   gnus-current-select-method
8518                 method)
8519               out))
8520       (nreverse out)))
8521    ;; One single select method.
8522    (t
8523     (list gnus-refer-article-method))))
8524
8525 (defun gnus-summary-edit-parameters ()
8526   "Edit the group parameters of the current group."
8527   (interactive)
8528   (gnus-group-edit-group gnus-newsgroup-name 'params))
8529
8530 (defun gnus-summary-customize-parameters ()
8531   "Customize the group parameters of the current group."
8532   (interactive)
8533   (gnus-group-customize gnus-newsgroup-name))
8534
8535 (defun gnus-summary-enter-digest-group (&optional force)
8536   "Enter an nndoc group based on the current article.
8537 If FORCE, force a digest interpretation.  If not, try
8538 to guess what the document format is."
8539   (interactive "P")
8540   (let ((conf gnus-current-window-configuration))
8541     (save-window-excursion
8542       (save-excursion
8543         (let (gnus-article-prepare-hook
8544               gnus-display-mime-function
8545               gnus-break-pages)
8546           (gnus-summary-select-article))))
8547     (setq gnus-current-window-configuration conf)
8548     (let* ((name (format "%s-%d"
8549                          (gnus-group-prefixed-name
8550                           gnus-newsgroup-name (list 'nndoc ""))
8551                          (with-current-buffer gnus-summary-buffer
8552                            gnus-current-article)))
8553            (ogroup gnus-newsgroup-name)
8554            (params (append (gnus-info-params (gnus-get-info ogroup))
8555                            (list (cons 'to-group ogroup))
8556                            (list (cons 'parent-group ogroup))
8557                            (list (cons 'save-article-group ogroup))))
8558            (case-fold-search t)
8559            (buf (current-buffer))
8560            dig to-address)
8561       (save-excursion
8562         (set-buffer gnus-original-article-buffer)
8563         ;; Have the digest group inherit the main mail address of
8564         ;; the parent article.
8565         (when (setq to-address (or (gnus-fetch-field "reply-to")
8566                                    (gnus-fetch-field "from")))
8567           (setq params (append
8568                         (list (cons 'to-address
8569                                     (funcall gnus-decode-encoded-word-function
8570                                              to-address))))))
8571         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8572         (insert-buffer-substring gnus-original-article-buffer)
8573         ;; Remove lines that may lead nndoc to misinterpret the
8574         ;; document type.
8575         (narrow-to-region
8576          (goto-char (point-min))
8577          (or (search-forward "\n\n" nil t) (point)))
8578         (goto-char (point-min))
8579         (delete-matching-lines "^Path:\\|^From ")
8580         (widen))
8581       (unwind-protect
8582           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8583                     (gnus-newsgroup-ephemeral-ignored-charsets
8584                      gnus-newsgroup-ignored-charsets))
8585                 (gnus-group-read-ephemeral-group
8586                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8587                               (nndoc-article-type
8588                                ,(if force 'mbox 'guess)))
8589                  t nil nil nil
8590                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8591                                                         "ADAPT")))))
8592               ;; Make all postings to this group go to the parent group.
8593               (nconc (gnus-info-params (gnus-get-info name))
8594                      params)
8595             ;; Couldn't select this doc group.
8596             (switch-to-buffer buf)
8597             (gnus-set-global-variables)
8598             (gnus-configure-windows 'summary)
8599             (gnus-message 3 "Article couldn't be entered?"))
8600         (kill-buffer dig)))))
8601
8602 (defun gnus-summary-read-document (n)
8603   "Open a new group based on the current article(s).
8604 This will allow you to read digests and other similar
8605 documents as newsgroups.
8606 Obeys the standard process/prefix convention."
8607   (interactive "P")
8608   (let* ((ogroup gnus-newsgroup-name)
8609          (params (append (gnus-info-params (gnus-get-info ogroup))
8610                          (list (cons 'to-group ogroup))))
8611          group egroup groups vgroup)
8612     (dolist (article (gnus-summary-work-articles n))
8613       (setq group (format "%s-%d" gnus-newsgroup-name article))
8614       (gnus-summary-remove-process-mark article)
8615       (when (gnus-summary-display-article article)
8616         (save-excursion
8617           (with-temp-buffer
8618             (insert-buffer-substring gnus-original-article-buffer)
8619             ;; Remove some headers that may lead nndoc to make
8620             ;; the wrong guess.
8621             (message-narrow-to-head)
8622             (goto-char (point-min))
8623             (delete-matching-lines "^Path:\\|^From ")
8624             (widen)
8625             (if (setq egroup
8626                       (gnus-group-read-ephemeral-group
8627                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8628                                      (nndoc-article-type guess))
8629                        t nil t))
8630                 (progn
8631             ;; Make all postings to this group go to the parent group.
8632                   (nconc (gnus-info-params (gnus-get-info egroup))
8633                          params)
8634                   (push egroup groups))
8635               ;; Couldn't select this doc group.
8636               (gnus-error 3 "Article couldn't be entered"))))))
8637     ;; Now we have selected all the documents.
8638     (cond
8639      ((not groups)
8640       (error "None of the articles could be interpreted as documents"))
8641      ((gnus-group-read-ephemeral-group
8642        (setq vgroup (format
8643                      "nnvirtual:%s-%s" gnus-newsgroup-name
8644                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8645        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8646        t
8647        (cons (current-buffer) 'summary)))
8648      (t
8649       (error "Couldn't select virtual nndoc group")))))
8650
8651 (defun gnus-summary-isearch-article (&optional regexp-p)
8652   "Do incremental search forward on the current article.
8653 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8654   (interactive "P")
8655   (gnus-summary-select-article)
8656   (gnus-configure-windows 'article)
8657   (gnus-eval-in-buffer-window gnus-article-buffer
8658     (save-restriction
8659       (widen)
8660       (isearch-forward regexp-p))))
8661
8662 (defun gnus-summary-search-article-forward (regexp &optional backward)
8663   "Search for an article containing REGEXP forward.
8664 If BACKWARD, search backward instead."
8665   (interactive
8666    (list (read-string
8667           (format "Search article %s (regexp%s): "
8668                   (if current-prefix-arg "backward" "forward")
8669                   (if gnus-last-search-regexp
8670                       (concat ", default " gnus-last-search-regexp)
8671                     "")))
8672          current-prefix-arg))
8673   (if (string-equal regexp "")
8674       (setq regexp (or gnus-last-search-regexp ""))
8675     (setq gnus-last-search-regexp regexp)
8676     (setq gnus-article-before-search gnus-current-article))
8677   ;; Intentionally set gnus-last-article.
8678   (setq gnus-last-article gnus-article-before-search)
8679   (let ((gnus-last-article gnus-last-article))
8680     (if (gnus-summary-search-article regexp backward)
8681         (gnus-summary-show-thread)
8682       (signal 'search-failed (list regexp)))))
8683
8684 (defun gnus-summary-search-article-backward (regexp)
8685   "Search for an article containing REGEXP backward."
8686   (interactive
8687    (list (read-string
8688           (format "Search article backward (regexp%s): "
8689                   (if gnus-last-search-regexp
8690                       (concat ", default " gnus-last-search-regexp)
8691                     "")))))
8692   (gnus-summary-search-article-forward regexp 'backward))
8693
8694 (defun gnus-summary-search-article (regexp &optional backward)
8695   "Search for an article containing REGEXP.
8696 Optional argument BACKWARD means do search for backward.
8697 `gnus-select-article-hook' is not called during the search."
8698   ;; We have to require this here to make sure that the following
8699   ;; dynamic binding isn't shadowed by autoloading.
8700   (require 'gnus-async)
8701   (require 'gnus-art)
8702   (let ((gnus-select-article-hook nil)  ;Disable hook.
8703         (gnus-article-prepare-hook nil)
8704         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8705         (gnus-use-article-prefetch nil)
8706         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8707         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8708         (gnus-visual nil)
8709         (gnus-keep-backlog nil)
8710         (gnus-break-pages nil)
8711         (gnus-summary-display-arrow nil)
8712         (gnus-updated-mode-lines nil)
8713         (gnus-auto-center-summary nil)
8714         (sum (current-buffer))
8715         (gnus-display-mime-function nil)
8716         (found nil)
8717         point)
8718     (gnus-save-hidden-threads
8719       (gnus-summary-select-article)
8720       (set-buffer gnus-article-buffer)
8721       (goto-char (window-point (get-buffer-window (current-buffer))))
8722       (when backward
8723         (forward-line -1))
8724       (while (not found)
8725         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8726         (if (if backward
8727                 (re-search-backward regexp nil t)
8728               (re-search-forward regexp nil t))
8729             ;; We found the regexp.
8730             (progn
8731               (setq found 'found)
8732               (beginning-of-line)
8733               (set-window-start
8734                (get-buffer-window (current-buffer))
8735                (point))
8736               (forward-line 1)
8737               (set-window-point
8738                (get-buffer-window (current-buffer))
8739                (point))
8740               (set-buffer sum)
8741               (setq point (point)))
8742           ;; We didn't find it, so we go to the next article.
8743           (set-buffer sum)
8744           (setq found 'not)
8745           (while (eq found 'not)
8746             (if (not (if backward (gnus-summary-find-prev)
8747                        (gnus-summary-find-next)))
8748                 ;; No more articles.
8749                 (setq found t)
8750               ;; Select the next article and adjust point.
8751               (unless (gnus-summary-article-sparse-p
8752                        (gnus-summary-article-number))
8753                 (setq found nil)
8754                 (gnus-summary-select-article)
8755                 (set-buffer gnus-article-buffer)
8756                 (widen)
8757                 (goto-char (if backward (point-max) (point-min))))))))
8758       (gnus-message 7 ""))
8759     ;; Return whether we found the regexp.
8760     (when (eq found 'found)
8761       (goto-char point)
8762       (gnus-summary-show-thread)
8763       (gnus-summary-goto-subject gnus-current-article)
8764       (gnus-summary-position-point)
8765       t)))
8766
8767 (defun gnus-find-matching-articles (header regexp)
8768   "Return a list of all articles that match REGEXP on HEADER.
8769 This search includes all articles in the current group that Gnus has
8770 fetched headers for, whether they are displayed or not."
8771   (let ((articles nil)
8772         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8773         (case-fold-search t))
8774     (dolist (header gnus-newsgroup-headers)
8775       (when (string-match regexp (funcall func header))
8776         (push (mail-header-number header) articles)))
8777     (nreverse articles)))
8778
8779 (defun gnus-summary-find-matching (header regexp &optional backward unread
8780                                           not-case-fold not-matching)
8781   "Return a list of all articles that match REGEXP on HEADER.
8782 The search stars on the current article and goes forwards unless
8783 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8784 If UNREAD is non-nil, only unread articles will
8785 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8786 in the comparisons. If NOT-MATCHING, return a list of all articles that
8787 not match REGEXP on HEADER."
8788   (let ((case-fold-search (not not-case-fold))
8789         articles d func)
8790     (if (consp header)
8791         (if (eq (car header) 'extra)
8792             (setq func
8793                   `(lambda (h)
8794                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8795                          "")))
8796           (error "%s is an invalid header" header))
8797       (unless (fboundp (intern (concat "mail-header-" header)))
8798         (error "%s is not a valid header" header))
8799       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8800     (dolist (d (if (eq backward 'all)
8801                    gnus-newsgroup-data
8802                  (gnus-data-find-list
8803                   (gnus-summary-article-number)
8804                   (gnus-data-list backward))))
8805       (when (and (or (not unread)       ; We want all articles...
8806                      (gnus-data-unread-p d)) ; Or just unreads.
8807                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8808                  (if not-matching
8809                      (not (string-match
8810                            regexp
8811                            (funcall func (gnus-data-header d))))
8812                    (string-match regexp
8813                                  (funcall func (gnus-data-header d)))))
8814         (push (gnus-data-number d) articles))) ; Success!
8815     (nreverse articles)))
8816
8817 (defun gnus-summary-execute-command (header regexp command &optional backward)
8818   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8819 If HEADER is an empty string (or nil), the match is done on the entire
8820 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8821   (interactive
8822    (list (let ((completion-ignore-case t))
8823            (completing-read
8824             "Header name: "
8825             (mapcar (lambda (header) (list (format "%s" header)))
8826                     (append
8827                      '("Number" "Subject" "From" "Lines" "Date"
8828                        "Message-ID" "Xref" "References" "Body")
8829                      gnus-extra-headers))
8830             nil 'require-match))
8831          (read-string "Regexp: ")
8832          (read-key-sequence "Command: ")
8833          current-prefix-arg))
8834   (when (equal header "Body")
8835     (setq header ""))
8836   ;; Hidden thread subtrees must be searched as well.
8837   (gnus-summary-show-all-threads)
8838   ;; We don't want to change current point nor window configuration.
8839   (save-excursion
8840     (save-window-excursion
8841       (let (gnus-visual
8842             gnus-treat-strip-trailing-blank-lines
8843             gnus-treat-strip-leading-blank-lines
8844             gnus-treat-strip-multiple-blank-lines
8845             gnus-treat-hide-boring-headers
8846             gnus-treat-fold-newsgroups
8847             gnus-article-prepare-hook)
8848         (gnus-message 6 "Executing %s..." (key-description command))
8849         ;; We'd like to execute COMMAND interactively so as to give arguments.
8850         (gnus-execute header regexp
8851                       `(call-interactively ',(key-binding command))
8852                       backward)
8853         (gnus-message 6 "Executing %s...done" (key-description command))))))
8854
8855 (defun gnus-summary-beginning-of-article ()
8856   "Scroll the article back to the beginning."
8857   (interactive)
8858   (gnus-summary-select-article)
8859   (gnus-configure-windows 'article)
8860   (gnus-eval-in-buffer-window gnus-article-buffer
8861     (widen)
8862     (goto-char (point-min))
8863     (when gnus-break-pages
8864       (gnus-narrow-to-page))))
8865
8866 (defun gnus-summary-end-of-article ()
8867   "Scroll to the end of the article."
8868   (interactive)
8869   (gnus-summary-select-article)
8870   (gnus-configure-windows 'article)
8871   (gnus-eval-in-buffer-window gnus-article-buffer
8872     (widen)
8873     (goto-char (point-max))
8874     (recenter -3)
8875     (when gnus-break-pages
8876       (when (re-search-backward page-delimiter nil t)
8877         (narrow-to-region (match-end 0) (point-max)))
8878       (gnus-narrow-to-page))))
8879
8880 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8881   "Truncate to LEN and quote all \"(\"'s in STRING."
8882   (gnus-replace-in-string (if (and len (> (length string) len))
8883                               (substring string 0 len)
8884                             string)
8885                           "[()]" "\\\\\\&"))
8886
8887 (defun gnus-summary-print-article (&optional filename n)
8888   "Generate and print a PostScript image of the process-marked (mail) articles.
8889
8890 If used interactively, print the current article if none are
8891 process-marked.  With prefix arg, prompt the user for the name of the
8892 file to save in.
8893
8894 When used from Lisp, accept two optional args FILENAME and N.  N means
8895 to print the next N articles.  If N is negative, print the N previous
8896 articles.  If N is nil and articles have been marked with the process
8897 mark, print these instead.
8898
8899 If the optional first argument FILENAME is nil, send the image to the
8900 printer.  If FILENAME is a string, save the PostScript image in a file with
8901 that name.  If FILENAME is a number, prompt the user for the name of the file
8902 to save in."
8903   (interactive (list (ps-print-preprint current-prefix-arg)))
8904   (dolist (article (gnus-summary-work-articles n))
8905     (gnus-summary-select-article nil nil 'pseudo article)
8906     (gnus-eval-in-buffer-window gnus-article-buffer
8907       (gnus-print-buffer))
8908     (gnus-summary-remove-process-mark article))
8909   (ps-despool filename))
8910
8911 (defun gnus-print-buffer ()
8912   (let ((buffer (generate-new-buffer " *print*")))
8913     (unwind-protect
8914         (progn
8915           (copy-to-buffer buffer (point-min) (point-max))
8916           (set-buffer buffer)
8917           (gnus-remove-text-with-property 'gnus-decoration)
8918           (when (gnus-visual-p 'article-highlight 'highlight)
8919             ;; Copy-to-buffer doesn't copy overlay.  So redo
8920             ;; highlight.
8921             (let ((gnus-article-buffer buffer))
8922               (gnus-article-highlight-citation t)
8923               (gnus-article-highlight-signature)
8924               (gnus-article-emphasize)
8925               (gnus-article-delete-invisible-text)))
8926           (let ((ps-left-header
8927                  (list
8928                   (concat "("
8929                           (gnus-summary-print-truncate-and-quote
8930                            (mail-header-subject gnus-current-headers)
8931                            66) ")")
8932                   (concat "("
8933                           (gnus-summary-print-truncate-and-quote
8934                            (mail-header-from gnus-current-headers)
8935                            45) ")")))
8936                 (ps-right-header
8937                  (list
8938                   "/pagenumberstring load"
8939                   (concat "("
8940                           (mail-header-date gnus-current-headers) ")"))))
8941             (gnus-run-hooks 'gnus-ps-print-hook)
8942             (save-excursion
8943               (if window-system
8944                   (ps-spool-buffer-with-faces)
8945                 (ps-spool-buffer)))))
8946       (kill-buffer buffer))))
8947
8948 (defun gnus-summary-show-article (&optional arg)
8949   "Force redisplaying of the current article.
8950 If ARG (the prefix) is a number, show the article with the charset
8951 defined in `gnus-summary-show-article-charset-alist', or the charset
8952 input.
8953 If ARG (the prefix) is non-nil and not a number, show the raw article
8954 without any article massaging functions being run.  Normally, the key
8955 strokes are `C-u g'."
8956   (interactive "P")
8957   (cond
8958    ((numberp arg)
8959     (gnus-summary-show-article t)
8960     (let ((gnus-newsgroup-charset
8961            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8962                (mm-read-coding-system
8963                 "View as charset: " ;; actually it is coding system.
8964                 (with-current-buffer gnus-article-buffer
8965                   (mm-detect-coding-region (point) (point-max))))))
8966           (gnus-newsgroup-ignored-charsets 'gnus-all))
8967       (gnus-summary-select-article nil 'force)
8968       (let ((deps gnus-newsgroup-dependencies)
8969             head header lines)
8970         (save-excursion
8971           (set-buffer gnus-original-article-buffer)
8972           (save-restriction
8973             (message-narrow-to-head)
8974             (setq head (buffer-string))
8975             (goto-char (point-min))
8976             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8977               (goto-char (point-max))
8978               (widen)
8979               (setq lines (1- (count-lines (point) (point-max))))))
8980           (with-temp-buffer
8981             (insert (format "211 %d Article retrieved.\n"
8982                             (cdr gnus-article-current)))
8983             (insert head)
8984             (if lines (insert (format "Lines: %d\n" lines)))
8985             (insert ".\n")
8986             (let ((nntp-server-buffer (current-buffer)))
8987               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8988         (gnus-data-set-header
8989          (gnus-data-find (cdr gnus-article-current))
8990          header)
8991         (gnus-summary-update-article-line
8992          (cdr gnus-article-current) header)
8993         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8994           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8995    ((not arg)
8996     ;; Select the article the normal way.
8997     (gnus-summary-select-article nil 'force))
8998    (t
8999     ;; We have to require this here to make sure that the following
9000     ;; dynamic binding isn't shadowed by autoloading.
9001     (require 'gnus-async)
9002     (require 'gnus-art)
9003     ;; Bind the article treatment functions to nil.
9004     (let ((gnus-have-all-headers t)
9005           gnus-article-prepare-hook
9006           gnus-article-decode-hook
9007           gnus-display-mime-function
9008           gnus-break-pages)
9009       ;; Destroy any MIME parts.
9010       (when (gnus-buffer-live-p gnus-article-buffer)
9011         (save-excursion
9012           (set-buffer gnus-article-buffer)
9013           (mm-destroy-parts gnus-article-mime-handles)
9014           ;; Set it to nil for safety reason.
9015           (setq gnus-article-mime-handle-alist nil)
9016           (setq gnus-article-mime-handles nil)))
9017       (gnus-summary-select-article nil 'force))))
9018   (gnus-summary-goto-subject gnus-current-article)
9019   (gnus-summary-position-point))
9020
9021 (defun gnus-summary-show-raw-article ()
9022   "Show the raw article without any article massaging functions being run."
9023   (interactive)
9024   (gnus-summary-show-article t))
9025
9026 (defun gnus-summary-verbose-headers (&optional arg)
9027   "Toggle permanent full header display.
9028 If ARG is a positive number, turn header display on.
9029 If ARG is a negative number, turn header display off."
9030   (interactive "P")
9031   (setq gnus-show-all-headers
9032         (cond ((or (not (numberp arg))
9033                    (zerop arg))
9034                (not gnus-show-all-headers))
9035               ((natnump arg)
9036                t)))
9037   (gnus-summary-show-article))
9038
9039 (defun gnus-summary-toggle-header (&optional arg)
9040   "Show the headers if they are hidden, or hide them if they are shown.
9041 If ARG is a positive number, show the entire header.
9042 If ARG is a negative number, hide the unwanted header lines."
9043   (interactive "P")
9044   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9045                      (get-buffer-window gnus-article-buffer t))))
9046     (with-current-buffer gnus-article-buffer
9047       (widen)
9048       (article-narrow-to-head)
9049       (let* ((buffer-read-only nil)
9050              (inhibit-point-motion-hooks t)
9051              (hidden (if (numberp arg)
9052                          (>= arg 0)
9053                        (or (not (looking-at "[^ \t\n]+:"))
9054                            (gnus-article-hidden-text-p 'headers))))
9055              s e)
9056         (delete-region (point-min) (point-max))
9057         (with-current-buffer gnus-original-article-buffer
9058           (goto-char (setq s (point-min)))
9059           (setq e (if (search-forward "\n\n" nil t)
9060                       (1- (point))
9061                     (point-max))))
9062         (insert-buffer-substring gnus-original-article-buffer s e)
9063         (run-hooks 'gnus-article-decode-hook)
9064         (if hidden
9065             (let ((gnus-treat-hide-headers nil)
9066                   (gnus-treat-hide-boring-headers nil))
9067               (gnus-delete-wash-type 'headers)
9068               (gnus-treat-article 'head))
9069           (gnus-treat-article 'head))
9070         (widen)
9071         (if window
9072             (set-window-start window (goto-char (point-min))))
9073         (if gnus-break-pages
9074             (gnus-narrow-to-page)
9075           (when (gnus-visual-p 'page-marker)
9076             (let ((buffer-read-only nil))
9077               (gnus-remove-text-with-property 'gnus-prev)
9078               (gnus-remove-text-with-property 'gnus-next))))
9079         (gnus-set-mode-line 'article)))))
9080
9081 (defun gnus-summary-show-all-headers ()
9082   "Make all header lines visible."
9083   (interactive)
9084   (gnus-summary-toggle-header 1))
9085
9086 (defun gnus-summary-caesar-message (&optional arg)
9087   "Caesar rotate the current article by 13.
9088 The numerical prefix specifies how many places to rotate each letter
9089 forward."
9090   (interactive "P")
9091   (gnus-summary-select-article)
9092   (let ((mail-header-separator ""))
9093     (gnus-eval-in-buffer-window gnus-article-buffer
9094       (save-restriction
9095         (widen)
9096         (let ((start (window-start))
9097               buffer-read-only)
9098           (message-caesar-buffer-body arg)
9099           (set-window-start (get-buffer-window (current-buffer)) start)))))
9100   ;; Create buttons and stuff...
9101   (gnus-treat-article nil))
9102
9103 (defun gnus-summary-idna-message (&optional arg)
9104   "Decode IDNA encoded domain names in the current articles.
9105 IDNA encoded domain names looks like `xn--bar'.  If a string
9106 remain unencoded after running this function, it is likely an
9107 invalid IDNA string (`xn--bar' is invalid).
9108
9109 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9110 installed for this command to work."
9111   (interactive "P")
9112   (if (not (and (condition-case nil (require 'idna)
9113                   (file-error))
9114                 (mm-coding-system-p 'utf-8)
9115                 (executable-find (symbol-value 'idna-program))))
9116       (gnus-message
9117        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9118     (gnus-summary-select-article)
9119     (let ((mail-header-separator ""))
9120       (gnus-eval-in-buffer-window gnus-article-buffer
9121         (save-restriction
9122           (widen)
9123           (let ((start (window-start))
9124                 buffer-read-only)
9125             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9126               (replace-match (idna-to-unicode (match-string 1))))
9127             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9128
9129 (autoload 'unmorse-region "morse"
9130   "Convert morse coded text in region to ordinary ASCII text."
9131   t)
9132
9133 (defun gnus-summary-morse-message (&optional arg)
9134   "Morse decode the current article."
9135   (interactive "P")
9136   (gnus-summary-select-article)
9137   (let ((mail-header-separator ""))
9138     (gnus-eval-in-buffer-window gnus-article-buffer
9139       (save-excursion
9140         (save-restriction
9141           (widen)
9142           (let ((pos (window-start))
9143                 buffer-read-only)
9144             (goto-char (point-min))
9145             (when (message-goto-body)
9146               (gnus-narrow-to-body))
9147             (goto-char (point-min))
9148             (while (search-forward "·" (point-max) t)
9149               (replace-match "."))
9150             (unmorse-region (point-min) (point-max))
9151             (widen)
9152             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9153
9154 (defun gnus-summary-stop-page-breaking ()
9155   "Stop page breaking in the current article."
9156   (interactive)
9157   (gnus-summary-select-article)
9158   (gnus-eval-in-buffer-window gnus-article-buffer
9159     (widen)
9160     (when (gnus-visual-p 'page-marker)
9161       (let ((buffer-read-only nil))
9162         (gnus-remove-text-with-property 'gnus-prev)
9163         (gnus-remove-text-with-property 'gnus-next))
9164       (setq gnus-page-broken nil))))
9165
9166 (defun gnus-summary-move-article (&optional n to-newsgroup
9167                                             select-method action)
9168   "Move the current article to a different newsgroup.
9169 If N is a positive number, move the N next articles.
9170 If N is a negative number, move the N previous articles.
9171 If N is nil and any articles have been marked with the process mark,
9172 move those articles instead.
9173 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9174 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9175 re-spool using this method.
9176
9177 When called interactively with TO-NEWSGROUP being nil, the value of
9178 the variable `gnus-move-split-methods' is used for finding a default
9179 for the target newsgroup.
9180
9181 For this function to work, both the current newsgroup and the
9182 newsgroup that you want to move to have to support the `request-move'
9183 and `request-accept' functions.
9184
9185 ACTION can be either `move' (the default), `crosspost' or `copy'."
9186   (interactive "P")
9187   (unless action
9188     (setq action 'move))
9189   ;; Check whether the source group supports the required functions.
9190   (cond ((and (eq action 'move)
9191               (not (gnus-check-backend-function
9192                     'request-move-article gnus-newsgroup-name)))
9193          (error "The current group does not support article moving"))
9194         ((and (eq action 'crosspost)
9195               (not (gnus-check-backend-function
9196                     'request-replace-article gnus-newsgroup-name)))
9197          (error "The current group does not support article editing")))
9198   (let ((articles (gnus-summary-work-articles n))
9199         (prefix (if (gnus-check-backend-function
9200                      'request-move-article gnus-newsgroup-name)
9201                     (funcall gnus-move-group-prefix-function
9202                              gnus-newsgroup-name)
9203                   ""))
9204         (names '((move "Move" "Moving")
9205                  (copy "Copy" "Copying")
9206                  (crosspost "Crosspost" "Crossposting")))
9207         (copy-buf (save-excursion
9208                     (nnheader-set-temp-buffer " *copy article*")))
9209         art-group to-method new-xref article to-groups articles-to-update-marks)
9210     (unless (assq action names)
9211       (error "Unknown action %s" action))
9212     ;; Read the newsgroup name.
9213     (when (and (not to-newsgroup)
9214                (not select-method))
9215       (if (and gnus-move-split-methods
9216                (not
9217                 (and (memq gnus-current-article articles)
9218                      (gnus-buffer-live-p gnus-original-article-buffer))))
9219           ;; When `gnus-move-split-methods' is non-nil, we have to
9220           ;; select an article to give `gnus-read-move-group-name' an
9221           ;; opportunity to suggest an appropriate default.  However,
9222           ;; we needn't render or mark the article.
9223           (let ((gnus-display-mime-function nil)
9224                 (gnus-article-prepare-hook nil)
9225                 (gnus-mark-article-hook nil))
9226             (gnus-summary-select-article nil nil nil (car articles))))
9227       (setq to-newsgroup
9228             (gnus-read-move-group-name
9229              (cadr (assq action names))
9230              (symbol-value (intern (format "gnus-current-%s-group" action)))
9231              articles prefix))
9232       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9233     (setq to-method (or select-method
9234                         (gnus-server-to-method
9235                          (gnus-group-method to-newsgroup))))
9236     ;; Check the method we are to move this article to...
9237     (unless (gnus-check-backend-function
9238              'request-accept-article (car to-method))
9239       (error "%s does not support article copying" (car to-method)))
9240     (unless (gnus-check-server to-method)
9241       (error "Can't open server %s" (car to-method)))
9242     (gnus-message 6 "%s to %s: %s..."
9243                   (caddr (assq action names))
9244                   (or (car select-method) to-newsgroup) articles)
9245     (while articles
9246       (setq article (pop articles))
9247       (setq
9248        art-group
9249        (cond
9250         ;; Move the article.
9251         ((eq action 'move)
9252          ;; Remove this article from future suppression.
9253          (gnus-dup-unsuppress-article article)
9254          (let* ((from-method (gnus-find-method-for-group
9255                               gnus-newsgroup-name))
9256                 (to-method (gnus-find-method-for-group
9257                             to-newsgroup))
9258                 (move-is-internal (gnus-method-equal from-method to-method)))
9259          (gnus-request-move-article
9260           article                       ; Article to move
9261           gnus-newsgroup-name           ; From newsgroup
9262           (nth 1 (gnus-find-method-for-group
9263                   gnus-newsgroup-name)) ; Server
9264           (list 'gnus-request-accept-article
9265                 to-newsgroup (list 'quote select-method)
9266                 (not articles) t)       ; Accept form
9267           (not articles)                ; Only save nov last time
9268           move-is-internal)))           ; is this move internal?
9269         ;; Copy the article.
9270         ((eq action 'copy)
9271          (save-excursion
9272            (set-buffer copy-buf)
9273            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9274              (save-restriction
9275                (nnheader-narrow-to-headers)
9276                (dolist (hdr gnus-copy-article-ignored-headers)
9277                  (message-remove-header hdr t)))
9278              (gnus-request-accept-article
9279               to-newsgroup select-method (not articles) t))))
9280         ;; Crosspost the article.
9281         ((eq action 'crosspost)
9282          (let ((xref (message-tokenize-header
9283                       (mail-header-xref (gnus-summary-article-header article))
9284                       " ")))
9285            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9286                                   ":" (number-to-string article)))
9287            (unless xref
9288              (setq xref (list (system-name))))
9289            (setq new-xref
9290                  (concat
9291                   (mapconcat 'identity
9292                              (delete "Xref:" (delete new-xref xref))
9293                              " ")
9294                   " " new-xref))
9295            (save-excursion
9296              (set-buffer copy-buf)
9297              ;; First put the article in the destination group.
9298              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9299              (when (consp (setq art-group
9300                                 (gnus-request-accept-article
9301                                  to-newsgroup select-method (not articles))))
9302                (setq new-xref (concat new-xref " " (car art-group)
9303                                       ":"
9304                                       (number-to-string (cdr art-group))))
9305                ;; Now we have the new Xrefs header, so we insert
9306                ;; it and replace the new article.
9307                (nnheader-replace-header "Xref" new-xref)
9308                (gnus-request-replace-article
9309                 (cdr art-group) to-newsgroup (current-buffer))
9310                art-group))))))
9311       (cond
9312        ((not art-group)
9313         (gnus-message 1 "Couldn't %s article %s: %s"
9314                       (cadr (assq action names)) article
9315                       (nnheader-get-report (car to-method))))
9316        ((eq art-group 'junk)
9317         (when (eq action 'move)
9318           (gnus-summary-mark-article article gnus-canceled-mark)
9319           (gnus-message 4 "Deleted article %s" article)
9320           ;; run the delete hook
9321           (run-hook-with-args 'gnus-summary-article-delete-hook
9322                               action
9323                               (gnus-data-header
9324                                (assoc article (gnus-data-list nil)))
9325                               gnus-newsgroup-name nil
9326                               select-method)))
9327        (t
9328         (let* ((pto-group (gnus-group-prefixed-name
9329                            (car art-group) to-method))
9330                (info (gnus-get-info pto-group))
9331                (to-group (gnus-info-group info))
9332                to-marks)
9333           ;; Update the group that has been moved to.
9334           (when (and info
9335                      (memq action '(move copy)))
9336             (unless (member to-group to-groups)
9337               (push to-group to-groups))
9338
9339             (unless (memq article gnus-newsgroup-unreads)
9340               (push 'read to-marks)
9341               (gnus-info-set-read
9342                info (gnus-add-to-range (gnus-info-read info)
9343                                        (list (cdr art-group)))))
9344
9345             ;; See whether the article is to be put in the cache.
9346             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9347                              gnus-article-mark-lists
9348                            (delete '(expirable . expire)
9349                                    (copy-sequence gnus-article-mark-lists))))
9350                   (to-article (cdr art-group)))
9351
9352               ;; Enter the article into the cache in the new group,
9353               ;; if that is required.
9354               (when gnus-use-cache
9355                 (gnus-cache-possibly-enter-article
9356                  to-group to-article
9357                  (memq article gnus-newsgroup-marked)
9358                  (memq article gnus-newsgroup-dormant)
9359                  (memq article gnus-newsgroup-unreads)))
9360
9361               (when gnus-preserve-marks
9362                 ;; Copy any marks over to the new group.
9363                 (when (and (equal to-group gnus-newsgroup-name)
9364                            (not (memq article gnus-newsgroup-unreads)))
9365                   ;; Mark this article as read in this group.
9366                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9367                   (setcdr (gnus-active to-group) to-article)
9368                   (setcdr gnus-newsgroup-active to-article))
9369
9370                 (while marks
9371                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9372                     (when (memq article (symbol-value
9373                                          (intern (format "gnus-newsgroup-%s"
9374                                                          (caar marks)))))
9375                       (push (cdar marks) to-marks)
9376                       ;; If the other group is the same as this group,
9377                       ;; then we have to add the mark to the list.
9378                       (when (equal to-group gnus-newsgroup-name)
9379                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9380                              (cons to-article
9381                                    (symbol-value
9382                                     (intern (format "gnus-newsgroup-%s"
9383                                                     (caar marks)))))))
9384                       ;; Copy the marks to other group.
9385                       (gnus-add-marked-articles
9386                        to-group (cdar marks) (list to-article) info)))
9387                   (setq marks (cdr marks)))
9388
9389                 (gnus-request-set-mark
9390                  to-group (list (list (list to-article) 'add to-marks))))
9391
9392               (gnus-dribble-enter
9393                (concat "(gnus-group-set-info '"
9394                        (gnus-prin1-to-string (gnus-get-info to-group))
9395                        ")"))))
9396
9397           ;; Update the Xref header in this article to point to
9398           ;; the new crossposted article we have just created.
9399           (when (eq action 'crosspost)
9400             (save-excursion
9401               (set-buffer copy-buf)
9402               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9403               (nnheader-replace-header "Xref" new-xref)
9404               (gnus-request-replace-article
9405                article gnus-newsgroup-name (current-buffer))))
9406
9407           ;; run the move/copy/crosspost/respool hook
9408           (run-hook-with-args 'gnus-summary-article-move-hook
9409                               action
9410                               (gnus-data-header
9411                                (assoc article (gnus-data-list nil)))
9412                               gnus-newsgroup-name
9413                               to-newsgroup
9414                               select-method))
9415
9416         ;;;!!!Why is this necessary?
9417         (set-buffer gnus-summary-buffer)
9418         
9419         (gnus-summary-goto-subject article)
9420         (when (eq action 'move)
9421           (gnus-summary-mark-article article gnus-canceled-mark))))
9422       (push article articles-to-update-marks))
9423
9424     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9425     ;; Re-activate all groups that have been moved to.
9426     (save-excursion
9427       (set-buffer gnus-group-buffer)
9428       (let ((gnus-group-marked to-groups))
9429         (gnus-group-get-new-news-this-group nil t)))
9430     
9431     (gnus-kill-buffer copy-buf)
9432     (gnus-summary-position-point)
9433     (gnus-set-mode-line 'summary)))
9434
9435 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9436   "Copy the current article to some other group.
9437 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9438 When called interactively, if TO-NEWSGROUP is nil, use the value of
9439 the variable `gnus-move-split-methods' for finding a default target
9440 newsgroup.
9441 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9442 re-spool using this method."
9443   (interactive "P")
9444   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9445
9446 (defun gnus-summary-crosspost-article (&optional n)
9447   "Crosspost the current article to some other group."
9448   (interactive "P")
9449   (gnus-summary-move-article n nil nil 'crosspost))
9450
9451 (defcustom gnus-summary-respool-default-method nil
9452   "Default method type for respooling an article.
9453 If nil, use to the current newsgroup method."
9454   :type 'symbol
9455   :group 'gnus-summary-mail)
9456
9457 (defcustom gnus-summary-display-while-building nil
9458   "If non-nil, show and update the summary buffer as it's being built.
9459 If the value is t, update the buffer after every line is inserted.  If
9460 the value is an integer (N), update the display every N lines."
9461   :version "22.1"
9462   :group 'gnus-thread
9463   :type '(choice (const :tag "off" nil)
9464                  number
9465                  (const :tag "frequently" t)))
9466
9467 (defun gnus-summary-respool-article (&optional n method)
9468   "Respool the current article.
9469 The article will be squeezed through the mail spooling process again,
9470 which means that it will be put in some mail newsgroup or other
9471 depending on `nnmail-split-methods'.
9472 If N is a positive number, respool the N next articles.
9473 If N is a negative number, respool the N previous articles.
9474 If N is nil and any articles have been marked with the process mark,
9475 respool those articles instead.
9476
9477 Respooling can be done both from mail groups and \"real\" newsgroups.
9478 In the former case, the articles in question will be moved from the
9479 current group into whatever groups they are destined to.  In the
9480 latter case, they will be copied into the relevant groups."
9481   (interactive
9482    (list current-prefix-arg
9483          (let* ((methods (gnus-methods-using 'respool))
9484                 (methname
9485                  (symbol-name (or gnus-summary-respool-default-method
9486                                   (car (gnus-find-method-for-group
9487                                         gnus-newsgroup-name)))))
9488                 (method
9489                  (gnus-completing-read-with-default
9490                   methname "Backend to use when respooling"
9491                   methods nil t nil 'gnus-mail-method-history))
9492                 ms)
9493            (cond
9494             ((zerop (length (setq ms (gnus-servers-using-backend
9495                                       (intern method)))))
9496              (list (intern method) ""))
9497             ((= 1 (length ms))
9498              (car ms))
9499             (t
9500              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9501                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9502                            ms-alist))))))))
9503   (unless method
9504     (error "No method given for respooling"))
9505   (if (assoc (symbol-name
9506               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9507              (gnus-methods-using 'respool))
9508       (gnus-summary-move-article n nil method)
9509     (gnus-summary-copy-article n nil method)))
9510
9511 (defun gnus-summary-import-article (file &optional edit)
9512   "Import an arbitrary file into a mail newsgroup."
9513   (interactive "fImport file: \nP")
9514   (let ((group gnus-newsgroup-name)
9515         (now (current-time))
9516         atts lines group-art)
9517     (unless (gnus-check-backend-function 'request-accept-article group)
9518       (error "%s does not support article importing" group))
9519     (or (file-readable-p file)
9520         (not (file-regular-p file))
9521         (error "Can't read %s" file))
9522     (save-excursion
9523       (set-buffer (gnus-get-buffer-create " *import file*"))
9524       (erase-buffer)
9525       (nnheader-insert-file-contents file)
9526       (goto-char (point-min))
9527       (if (nnheader-article-p)
9528           (save-restriction
9529             (goto-char (point-min))
9530             (search-forward "\n\n" nil t)
9531             (narrow-to-region (point-min) (1- (point)))
9532             (goto-char (point-min))
9533             (unless (re-search-forward "^date:" nil t)
9534               (goto-char (point-max))
9535               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9536        ;; This doesn't look like an article, so we fudge some headers.
9537         (setq atts (file-attributes file)
9538               lines (count-lines (point-min) (point-max)))
9539         (insert "From: " (read-string "From: ") "\n"
9540                 "Subject: " (read-string "Subject: ") "\n"
9541                 "Date: " (message-make-date (nth 5 atts)) "\n"
9542                 "Message-ID: " (message-make-message-id) "\n"
9543                 "Lines: " (int-to-string lines) "\n"
9544                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9545       (setq group-art (gnus-request-accept-article group nil t))
9546       (kill-buffer (current-buffer)))
9547     (setq gnus-newsgroup-active (gnus-activate-group group))
9548     (forward-line 1)
9549     (gnus-summary-goto-article (cdr group-art) nil t)
9550     (when edit
9551       (gnus-summary-edit-article))))
9552
9553 (defun gnus-summary-create-article ()
9554   "Create an article in a mail newsgroup."
9555   (interactive)
9556   (let ((group gnus-newsgroup-name)
9557         (now (current-time))
9558         group-art)
9559     (unless (gnus-check-backend-function 'request-accept-article group)
9560       (error "%s does not support article importing" group))
9561     (save-excursion
9562       (set-buffer (gnus-get-buffer-create " *import file*"))
9563       (erase-buffer)
9564       (goto-char (point-min))
9565       ;; This doesn't look like an article, so we fudge some headers.
9566       (insert "From: " (read-string "From: ") "\n"
9567               "Subject: " (read-string "Subject: ") "\n"
9568               "Date: " (message-make-date now) "\n"
9569               "Message-ID: " (message-make-message-id) "\n")
9570       (setq group-art (gnus-request-accept-article group nil t))
9571       (kill-buffer (current-buffer)))
9572     (setq gnus-newsgroup-active (gnus-activate-group group))
9573     (forward-line 1)
9574     (gnus-summary-goto-article (cdr group-art) nil t)
9575     (gnus-summary-edit-article)))
9576
9577 (defun gnus-summary-article-posted-p ()
9578   "Say whether the current (mail) article is available from news as well.
9579 This will be the case if the article has both been mailed and posted."
9580   (interactive)
9581   (let ((id (mail-header-references (gnus-summary-article-header)))
9582         (gnus-override-method (car (gnus-refer-article-methods))))
9583     (if (gnus-request-head id "")
9584         (gnus-message 2 "The current message was found on %s"
9585                       gnus-override-method)
9586       (gnus-message 2 "The current message couldn't be found on %s"
9587                     gnus-override-method)
9588       nil)))
9589
9590 (defun gnus-summary-expire-articles (&optional now)
9591   "Expire all articles that are marked as expirable in the current group."
9592   (interactive)
9593   (when (and (not gnus-group-is-exiting-without-update-p)
9594              (gnus-check-backend-function
9595               'request-expire-articles gnus-newsgroup-name))
9596     ;; This backend supports expiry.
9597     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9598            (expirable (if total
9599                           (progn
9600                             ;; We need to update the info for
9601                             ;; this group for `gnus-list-of-read-articles'
9602                             ;; to give us the right answer.
9603                             (gnus-run-hooks 'gnus-exit-group-hook)
9604                             (gnus-summary-update-info)
9605                             (gnus-list-of-read-articles gnus-newsgroup-name))
9606                         (setq gnus-newsgroup-expirable
9607                               (sort gnus-newsgroup-expirable '<))))
9608            (expiry-wait (if now 'immediate
9609                           (gnus-group-find-parameter
9610                            gnus-newsgroup-name 'expiry-wait)))
9611            (nnmail-expiry-target
9612             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9613                 nnmail-expiry-target))
9614            es)
9615       (when expirable
9616         ;; There are expirable articles in this group, so we run them
9617         ;; through the expiry process.
9618         (gnus-message 6 "Expiring articles...")
9619         (unless (gnus-check-group gnus-newsgroup-name)
9620           (error "Can't open server for %s" gnus-newsgroup-name))
9621         ;; The list of articles that weren't expired is returned.
9622         (save-excursion
9623           (if expiry-wait
9624               (let ((nnmail-expiry-wait-function nil)
9625                     (nnmail-expiry-wait expiry-wait))
9626                 (setq es (gnus-request-expire-articles
9627                           expirable gnus-newsgroup-name)))
9628             (setq es (gnus-request-expire-articles
9629                       expirable gnus-newsgroup-name)))
9630           (unless total
9631             (setq gnus-newsgroup-expirable es))
9632           ;; We go through the old list of expirable, and mark all
9633           ;; really expired articles as nonexistent.
9634           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9635             (let ((gnus-use-cache nil))
9636               (dolist (article expirable)
9637                 (when (and (not (memq article es))
9638                            (gnus-data-find article))
9639                   (gnus-summary-mark-article article gnus-canceled-mark)
9640                   (run-hook-with-args 'gnus-summary-article-expire-hook
9641                                       'delete
9642                                       (gnus-data-header
9643                                        (assoc article (gnus-data-list nil)))
9644                                       gnus-newsgroup-name
9645                                       nil
9646                                       nil))))))
9647         (gnus-message 6 "Expiring articles...done")))))
9648
9649 (defun gnus-summary-expire-articles-now ()
9650   "Expunge all expirable articles in the current group.
9651 This means that *all* articles that are marked as expirable will be
9652 deleted forever, right now."
9653   (interactive)
9654   (or gnus-expert-user
9655       (gnus-yes-or-no-p
9656        "Are you really, really, really sure you want to delete all these messages? ")
9657       (error "Phew!"))
9658   (gnus-summary-expire-articles t))
9659
9660 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9661 (defun gnus-summary-delete-article (&optional n)
9662   "Delete the N next (mail) articles.
9663 This command actually deletes articles.  This is not a marking
9664 command.  The article will disappear forever from your life, never to
9665 return.
9666
9667 If N is negative, delete backwards.
9668 If N is nil and articles have been marked with the process mark,
9669 delete these instead.
9670
9671 If `gnus-novice-user' is non-nil you will be asked for
9672 confirmation before the articles are deleted."
9673   (interactive "P")
9674   (unless (gnus-check-backend-function 'request-expire-articles
9675                                        gnus-newsgroup-name)
9676     (error "The current newsgroup does not support article deletion"))
9677   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9678     (error "Couldn't open server"))
9679   ;; Compute the list of articles to delete.
9680   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9681         (nnmail-expiry-target 'delete)
9682         not-deleted)
9683     (if (and gnus-novice-user
9684              (not (gnus-yes-or-no-p
9685                    (format "Do you really want to delete %s forever? "
9686                            (if (> (length articles) 1)
9687                                (format "these %s articles" (length articles))
9688                              "this article")))))
9689         ()
9690       ;; Delete the articles.
9691       (setq not-deleted (gnus-request-expire-articles
9692                          articles gnus-newsgroup-name 'force))
9693       (while articles
9694         (gnus-summary-remove-process-mark (car articles))
9695         ;; The backend might not have been able to delete the article
9696         ;; after all.
9697         (unless (memq (car articles) not-deleted)
9698           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9699         (let* ((article (car articles))
9700                (ghead  (gnus-data-header
9701                                     (assoc article (gnus-data-list nil)))))
9702           (run-hook-with-args 'gnus-summary-article-delete-hook
9703                               'delete ghead gnus-newsgroup-name nil
9704                               nil))
9705         (setq articles (cdr articles)))
9706       (when not-deleted
9707         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9708     (gnus-summary-position-point)
9709     (gnus-set-mode-line 'summary)
9710     not-deleted))
9711
9712 (defun gnus-summary-edit-article (&optional arg)
9713   "Edit the current article.
9714 This will have permanent effect only in mail groups.
9715 If ARG is nil, edit the decoded articles.
9716 If ARG is 1, edit the raw articles.
9717 If ARG is 2, edit the raw articles even in read-only groups.
9718 If ARG is 3, edit the articles with the current handles.
9719 Otherwise, allow editing of articles even in read-only
9720 groups."
9721   (interactive "P")
9722   (let (force raw current-handles)
9723     (cond
9724      ((null arg))
9725      ((eq arg 1)
9726       (setq raw t))
9727      ((eq arg 2)
9728       (setq raw t
9729             force t))
9730      ((eq arg 3)
9731       (setq current-handles
9732             (and (gnus-buffer-live-p gnus-article-buffer)
9733                  (with-current-buffer gnus-article-buffer
9734                    (prog1
9735                        gnus-article-mime-handles
9736                      (setq gnus-article-mime-handles nil))))))
9737      (t
9738       (setq force t)))
9739     (when (and raw (not force)
9740                (member gnus-newsgroup-name '("nndraft:delayed"
9741                                              "nndraft:drafts"
9742                                              "nndraft:queue")))
9743       (error "Can't edit the raw article in group %s"
9744              gnus-newsgroup-name))
9745     (save-excursion
9746       (set-buffer gnus-summary-buffer)
9747       (let ((mail-parse-charset gnus-newsgroup-charset)
9748             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9749         (gnus-set-global-variables)
9750         (when (and (not force)
9751                    (gnus-group-read-only-p))
9752           (error "The current newsgroup does not support article editing"))
9753         (gnus-summary-show-article t)
9754         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9755           (with-current-buffer gnus-article-buffer
9756             (mm-enable-multibyte)))
9757         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9758             (setq raw t))
9759         (gnus-article-edit-article
9760          (if raw 'ignore
9761            `(lambda ()
9762               (let ((mbl mml-buffer-list))
9763                 (setq mml-buffer-list nil)
9764                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9765                   (mime-to-mml ,'current-handles))
9766                 (let ((mbl1 mml-buffer-list))
9767                   (setq mml-buffer-list mbl)
9768                   (set (make-local-variable 'mml-buffer-list) mbl1))
9769                 (gnus-make-local-hook 'kill-buffer-hook)
9770                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9771          `(lambda (no-highlight)
9772             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9773                   (message-options message-options)
9774                   (message-options-set-recipient)
9775                   (mail-parse-ignored-charsets
9776                    ',gnus-newsgroup-ignored-charsets))
9777               ,(if (not raw) '(progn
9778                                 (mml-to-mime)
9779                                 (mml-destroy-buffers)
9780                                 (remove-hook 'kill-buffer-hook
9781                                              'mml-destroy-buffers t)
9782                                 (kill-local-variable 'mml-buffer-list)))
9783               (gnus-summary-edit-article-done
9784                ,(or (mail-header-references gnus-current-headers) "")
9785                ,(gnus-group-read-only-p)
9786                ,gnus-summary-buffer no-highlight))))))))
9787
9788 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9789
9790 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9791                                                  no-highlight)
9792   "Make edits to the current article permanent."
9793   (interactive)
9794   (save-excursion
9795    ;; The buffer restriction contains the entire article if it exists.
9796     (when (article-goto-body)
9797       (let ((lines (count-lines (point) (point-max)))
9798             (length (- (point-max) (point)))
9799             (case-fold-search t)
9800             (body (copy-marker (point))))
9801         (goto-char (point-min))
9802         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9803           (delete-region (match-beginning 1) (match-end 1))
9804           (insert (number-to-string length)))
9805         (goto-char (point-min))
9806         (when (re-search-forward
9807                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9808           (delete-region (match-beginning 1) (match-end 1))
9809           (insert (number-to-string length)))
9810         (goto-char (point-min))
9811         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9812           (delete-region (match-beginning 1) (match-end 1))
9813           (insert (number-to-string lines))))))
9814   ;; Replace the article.
9815   (let ((buf (current-buffer)))
9816     (with-temp-buffer
9817       (insert-buffer-substring buf)
9818
9819       (if (and (not read-only)
9820                (not (gnus-request-replace-article
9821                      (cdr gnus-article-current) (car gnus-article-current)
9822                      (current-buffer) t)))
9823           (error "Couldn't replace article")
9824         ;; Update the summary buffer.
9825         (if (and references
9826                  (equal (message-tokenize-header references " ")
9827                         (message-tokenize-header
9828                          (or (message-fetch-field "references") "") " ")))
9829             ;; We only have to update this line.
9830             (save-excursion
9831               (save-restriction
9832                 (message-narrow-to-head)
9833                 (let ((head (buffer-substring-no-properties
9834                              (point-min) (point-max)))
9835                       header)
9836                   (with-temp-buffer
9837                     (insert (format "211 %d Article retrieved.\n"
9838                                     (cdr gnus-article-current)))
9839                     (insert head)
9840                     (insert ".\n")
9841                     (let ((nntp-server-buffer (current-buffer)))
9842                       (setq header (car (gnus-get-newsgroup-headers
9843                                          nil t))))
9844                     (save-excursion
9845                       (set-buffer gnus-summary-buffer)
9846                       (gnus-data-set-header
9847                        (gnus-data-find (cdr gnus-article-current))
9848                        header)
9849                       (gnus-summary-update-article-line
9850                        (cdr gnus-article-current) header)
9851                       (if (gnus-summary-goto-subject
9852                            (cdr gnus-article-current) nil t)
9853                           (gnus-summary-update-secondary-mark
9854                            (cdr gnus-article-current))))))))
9855           ;; Update threads.
9856           (set-buffer (or buffer gnus-summary-buffer))
9857           (gnus-summary-update-article (cdr gnus-article-current))
9858           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9859               (gnus-summary-update-secondary-mark
9860                (cdr gnus-article-current))))
9861         ;; Prettify the article buffer again.
9862         (unless no-highlight
9863           (save-excursion
9864             (set-buffer gnus-article-buffer)
9865             ;;;!!! Fix this -- article should be rehighlighted.
9866             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9867             (set-buffer gnus-original-article-buffer)
9868             (gnus-request-article
9869              (cdr gnus-article-current)
9870              (car gnus-article-current) (current-buffer))))
9871         ;; Prettify the summary buffer line.
9872         (when (gnus-visual-p 'summary-highlight 'highlight)
9873           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9874
9875 (defun gnus-summary-edit-wash (key)
9876   "Perform editing command KEY in the article buffer."
9877   (interactive
9878    (list
9879     (progn
9880       (message "%s" (concat (this-command-keys) "- "))
9881       (read-char))))
9882   (message "")
9883   (gnus-summary-edit-article)
9884   (execute-kbd-macro (concat (this-command-keys) key))
9885   (gnus-article-edit-done))
9886
9887 ;;; Respooling
9888
9889 (defun gnus-summary-respool-query (&optional silent trace)
9890   "Query where the respool algorithm would put this article."
9891   (interactive)
9892   (let (gnus-mark-article-hook)
9893     (gnus-summary-select-article)
9894     (save-excursion
9895       (set-buffer gnus-original-article-buffer)
9896       (let ((groups (nnmail-article-group 'identity trace)))
9897         (unless silent
9898           (if groups
9899               (message "This message would go to %s"
9900                        (mapconcat 'car groups ", "))
9901             (message "This message would go to no groups"))
9902           groups)))))
9903
9904 (defun gnus-summary-respool-trace ()
9905   "Trace where the respool algorithm would put this article.
9906 Display a buffer showing all fancy splitting patterns which matched."
9907   (interactive)
9908   (gnus-summary-respool-query nil t))
9909
9910 ;; Summary marking commands.
9911
9912 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9913   "Mark articles which has the same subject as read, and then select the next.
9914 If UNMARK is positive, remove any kind of mark.
9915 If UNMARK is negative, tick articles."
9916   (interactive "P")
9917   (when unmark
9918     (setq unmark (prefix-numeric-value unmark)))
9919   (let ((count
9920          (gnus-summary-mark-same-subject
9921           (gnus-summary-article-subject) unmark)))
9922     ;; Select next unread article.  If auto-select-same mode, should
9923     ;; select the first unread article.
9924     (gnus-summary-next-article t (and gnus-auto-select-same
9925                                       (gnus-summary-article-subject)))
9926     (gnus-message 7 "%d article%s marked as %s"
9927                   count (if (= count 1) " is" "s are")
9928                   (if unmark "unread" "read"))))
9929
9930 (defun gnus-summary-kill-same-subject (&optional unmark)
9931   "Mark articles which has the same subject as read.
9932 If UNMARK is positive, remove any kind of mark.
9933 If UNMARK is negative, tick articles."
9934   (interactive "P")
9935   (when unmark
9936     (setq unmark (prefix-numeric-value unmark)))
9937   (let ((count
9938          (gnus-summary-mark-same-subject
9939           (gnus-summary-article-subject) unmark)))
9940     ;; If marked as read, go to next unread subject.
9941     (when (null unmark)
9942       ;; Go to next unread subject.
9943       (gnus-summary-next-subject 1 t))
9944     (gnus-message 7 "%d articles are marked as %s"
9945                   count (if unmark "unread" "read"))))
9946
9947 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9948   "Mark articles with same SUBJECT as read, and return marked number.
9949 If optional argument UNMARK is positive, remove any kinds of marks.
9950 If optional argument UNMARK is negative, mark articles as unread instead."
9951   (let ((count 1))
9952     (save-excursion
9953       (cond
9954        ((null unmark)                   ; Mark as read.
9955         (while (and
9956                 (progn
9957                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9958                   (gnus-summary-show-thread) t)
9959                 (gnus-summary-find-subject subject))
9960           (setq count (1+ count))))
9961        ((> unmark 0)                    ; Tick.
9962         (while (and
9963                 (progn
9964                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9965                   (gnus-summary-show-thread) t)
9966                 (gnus-summary-find-subject subject))
9967           (setq count (1+ count))))
9968        (t                               ; Mark as unread.
9969         (while (and
9970                 (progn
9971                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9972                   (gnus-summary-show-thread) t)
9973                 (gnus-summary-find-subject subject))
9974           (setq count (1+ count)))))
9975       (gnus-set-mode-line 'summary)
9976       ;; Return the number of marked articles.
9977       count)))
9978
9979 (defun gnus-summary-mark-as-processable (n &optional unmark)
9980   "Set the process mark on the next N articles.
9981 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9982 the process mark instead.  The difference between N and the actual
9983 number of articles marked is returned."
9984   (interactive "P")
9985   (if (and (null n) (gnus-region-active-p))
9986       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9987     (setq n (prefix-numeric-value n))
9988     (let ((backward (< n 0))
9989           (n (abs n)))
9990       (while (and
9991               (> n 0)
9992               (if unmark
9993                   (gnus-summary-remove-process-mark
9994                    (gnus-summary-article-number))
9995                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9996               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9997         (setq n (1- n)))
9998       (when (/= 0 n)
9999         (gnus-message 7 "No more articles"))
10000       (gnus-summary-recenter)
10001       (gnus-summary-position-point)
10002       n)))
10003
10004 (defun gnus-summary-unmark-as-processable (n)
10005   "Remove the process mark from the next N articles.
10006 If N is negative, unmark backward instead.  The difference between N and
10007 the actual number of articles unmarked is returned."
10008   (interactive "P")
10009   (gnus-summary-mark-as-processable n t))
10010
10011 (defun gnus-summary-unmark-all-processable ()
10012   "Remove the process mark from all articles."
10013   (interactive)
10014   (save-excursion
10015     (while gnus-newsgroup-processable
10016       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10017   (gnus-summary-position-point))
10018
10019 (defun gnus-summary-add-mark (article type)
10020   "Mark ARTICLE with a mark of TYPE."
10021   (let ((vtype (car (assq type gnus-article-mark-lists)))
10022         var)
10023     (if (not vtype)
10024         (error "No such mark type: %s" type)
10025       (setq var (intern (format "gnus-newsgroup-%s" type)))
10026       (set var (cons article (symbol-value var)))
10027       (if (memq type '(processable cached replied forwarded recent saved))
10028           (gnus-summary-update-secondary-mark article)
10029         ;;; !!! This is bogus.  We should find out what primary
10030         ;;; !!! mark we want to set.
10031         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10032
10033 (defun gnus-summary-mark-as-expirable (n)
10034   "Mark N articles forward as expirable.
10035 If N is negative, mark backward instead.  The difference between N and
10036 the actual number of articles marked is returned."
10037   (interactive "p")
10038   (gnus-summary-mark-forward n gnus-expirable-mark))
10039
10040 (defun gnus-summary-mark-as-spam (n)
10041   "Mark N articles forward as spam.
10042 If N is negative, mark backward instead.  The difference between N and
10043 the actual number of articles marked is returned."
10044   (interactive "p")
10045   (gnus-summary-mark-forward n gnus-spam-mark))
10046
10047 (defun gnus-summary-mark-article-as-replied (article)
10048   "Mark ARTICLE as replied to and update the summary line.
10049 ARTICLE can also be a list of articles."
10050   (interactive (list (gnus-summary-article-number)))
10051   (let ((articles (if (listp article) article (list article))))
10052     (dolist (article articles)
10053       (unless (numberp article)
10054         (error "%s is not a number" article))
10055       (push article gnus-newsgroup-replied)
10056       (let ((buffer-read-only nil))
10057         (when (gnus-summary-goto-subject article nil t)
10058           (gnus-summary-update-secondary-mark article))))))
10059
10060 (defun gnus-summary-mark-article-as-forwarded (article)
10061   "Mark ARTICLE as forwarded and update the summary line.
10062 ARTICLE can also be a list of articles."
10063   (let ((articles (if (listp article) article (list article))))
10064     (dolist (article articles)
10065       (push article gnus-newsgroup-forwarded)
10066       (let ((buffer-read-only nil))
10067         (when (gnus-summary-goto-subject article nil t)
10068           (gnus-summary-update-secondary-mark article))))))
10069
10070 (defun gnus-summary-set-bookmark (article)
10071   "Set a bookmark in current article."
10072   (interactive (list (gnus-summary-article-number)))
10073   (when (or (not (get-buffer gnus-article-buffer))
10074             (not gnus-current-article)
10075             (not gnus-article-current)
10076             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10077     (error "No current article selected"))
10078   ;; Remove old bookmark, if one exists.
10079   (gnus-pull article gnus-newsgroup-bookmarks)
10080   ;; Set the new bookmark, which is on the form
10081   ;; (article-number . line-number-in-body).
10082   (push
10083    (cons article
10084          (with-current-buffer gnus-article-buffer
10085            (count-lines
10086             (min (point)
10087                  (save-excursion
10088                    (article-goto-body)
10089                    (point)))
10090             (point))))
10091    gnus-newsgroup-bookmarks)
10092   (gnus-message 6 "A bookmark has been added to the current article."))
10093
10094 (defun gnus-summary-remove-bookmark (article)
10095   "Remove the bookmark from the current article."
10096   (interactive (list (gnus-summary-article-number)))
10097   ;; Remove old bookmark, if one exists.
10098   (if (not (assq article gnus-newsgroup-bookmarks))
10099       (gnus-message 6 "No bookmark in current article.")
10100     (gnus-pull article gnus-newsgroup-bookmarks)
10101     (gnus-message 6 "Removed bookmark.")))
10102
10103 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10104 (defun gnus-summary-mark-as-dormant (n)
10105   "Mark N articles forward as dormant.
10106 If N is negative, mark backward instead.  The difference between N and
10107 the actual number of articles marked is returned."
10108   (interactive "p")
10109   (gnus-summary-mark-forward n gnus-dormant-mark))
10110
10111 (defun gnus-summary-set-process-mark (article)
10112   "Set the process mark on ARTICLE and update the summary line."
10113   (setq gnus-newsgroup-processable
10114         (cons article
10115               (delq article gnus-newsgroup-processable)))
10116   (when (gnus-summary-goto-subject article)
10117     (gnus-summary-show-thread)
10118     (gnus-summary-goto-subject article)
10119     (gnus-summary-update-secondary-mark article)))
10120
10121 (defun gnus-summary-remove-process-mark (&rest articles)
10122   "Remove the process mark from ARTICLES and update the summary line."
10123   (dolist (article articles)
10124     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10125     (when (gnus-summary-goto-subject article)
10126       (gnus-summary-show-thread)
10127       (gnus-summary-goto-subject article)
10128       (gnus-summary-update-secondary-mark article)))
10129   t)
10130
10131 (defun gnus-summary-set-saved-mark (article)
10132   "Set the process mark on ARTICLE and update the summary line."
10133   (push article gnus-newsgroup-saved)
10134   (when (gnus-summary-goto-subject article)
10135     (gnus-summary-update-secondary-mark article)))
10136
10137 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10138   "Mark N articles as read forwards.
10139 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10140 The difference between N and the actual number of articles marked is
10141 returned.
10142 If NO-EXPIRE, auto-expiry will be inhibited."
10143   (interactive "p")
10144   (gnus-summary-show-thread)
10145   (let ((backward (< n 0))
10146         (gnus-summary-goto-unread
10147          (and gnus-summary-goto-unread
10148               (not (eq gnus-summary-goto-unread 'never))
10149               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10150                                     gnus-ticked-mark gnus-dormant-mark)))))
10151         (n (abs n))
10152         (mark (or mark gnus-del-mark)))
10153     (while (and (> n 0)
10154                 (gnus-summary-mark-article nil mark no-expire)
10155                 (zerop (gnus-summary-next-subject
10156                         (if backward -1 1)
10157                         (and gnus-summary-goto-unread
10158                              (not (eq gnus-summary-goto-unread 'never)))
10159                         t)))
10160       (setq n (1- n)))
10161     (when (/= 0 n)
10162       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10163     (gnus-summary-recenter)
10164     (gnus-summary-position-point)
10165     (gnus-set-mode-line 'summary)
10166     n))
10167
10168 (defun gnus-summary-mark-article-as-read (mark)
10169   "Mark the current article quickly as read with MARK."
10170   (let ((article (gnus-summary-article-number)))
10171     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10172     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10173     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10174     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10175     (push (cons article mark) gnus-newsgroup-reads)
10176     ;; Possibly remove from cache, if that is used.
10177     (when gnus-use-cache
10178       (gnus-cache-enter-remove-article article))
10179     ;; Allow the backend to change the mark.
10180     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10181     ;; Check for auto-expiry.
10182     (when (and gnus-newsgroup-auto-expire
10183                (memq mark gnus-auto-expirable-marks))
10184       (setq mark gnus-expirable-mark)
10185       ;; Let the backend know about the mark change.
10186       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10187       (push article gnus-newsgroup-expirable))
10188     ;; Set the mark in the buffer.
10189     (gnus-summary-update-mark mark 'unread)
10190     t))
10191
10192 (defun gnus-summary-mark-article-as-unread (mark)
10193   "Mark the current article quickly as unread with MARK."
10194   (let* ((article (gnus-summary-article-number))
10195          (old-mark (gnus-summary-article-mark article)))
10196     ;; Allow the backend to change the mark.
10197     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10198     (if (eq mark old-mark)
10199         t
10200       (if (<= article 0)
10201           (progn
10202             (gnus-error 1 "Can't mark negative article numbers")
10203             nil)
10204         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10205         (setq gnus-newsgroup-spam-marked
10206               (delq article gnus-newsgroup-spam-marked))
10207         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10208         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10209         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10210         (cond ((= mark gnus-ticked-mark)
10211                (setq gnus-newsgroup-marked
10212                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10213                                               article)))
10214               ((= mark gnus-spam-mark)
10215                (setq gnus-newsgroup-spam-marked
10216                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10217                                               article)))
10218               ((= mark gnus-dormant-mark)
10219                (setq gnus-newsgroup-dormant
10220                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10221                                               article)))
10222               (t
10223                (setq gnus-newsgroup-unreads
10224                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10225                                               article))))
10226         (gnus-pull article gnus-newsgroup-reads)
10227
10228         ;; See whether the article is to be put in the cache.
10229         (and gnus-use-cache
10230              (vectorp (gnus-summary-article-header article))
10231              (save-excursion
10232                (gnus-cache-possibly-enter-article
10233                 gnus-newsgroup-name article
10234                 (= mark gnus-ticked-mark)
10235                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10236
10237         ;; Fix the mark.
10238         (gnus-summary-update-mark mark 'unread)
10239         t))))
10240
10241 (defun gnus-summary-mark-article (&optional article mark no-expire)
10242   "Mark ARTICLE with MARK.  MARK can be any character.
10243 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10244 `??' (dormant) and `?E' (expirable).
10245 If MARK is nil, then the default character `?r' is used.
10246 If ARTICLE is nil, then the article on the current line will be
10247 marked.
10248 If NO-EXPIRE, auto-expiry will be inhibited."
10249   ;; The mark might be a string.
10250   (when (stringp mark)
10251     (setq mark (aref mark 0)))
10252   ;; If no mark is given, then we check auto-expiring.
10253   (when (null mark)
10254     (setq mark gnus-del-mark))
10255   (when (and (not no-expire)
10256              gnus-newsgroup-auto-expire
10257              (memq mark gnus-auto-expirable-marks))
10258     (setq mark gnus-expirable-mark))
10259   (let ((article (or article (gnus-summary-article-number)))
10260         (old-mark (gnus-summary-article-mark article)))
10261     ;; Allow the backend to change the mark.
10262     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10263     (if (eq mark old-mark)
10264         t
10265       (unless article
10266         (error "No article on current line"))
10267       (if (not (if (or (= mark gnus-unread-mark)
10268                        (= mark gnus-ticked-mark)
10269                        (= mark gnus-spam-mark)
10270                        (= mark gnus-dormant-mark))
10271                    (gnus-mark-article-as-unread article mark)
10272                  (gnus-mark-article-as-read article mark)))
10273           t
10274         ;; See whether the article is to be put in the cache.
10275         (and gnus-use-cache
10276              (not (= mark gnus-canceled-mark))
10277              (vectorp (gnus-summary-article-header article))
10278              (save-excursion
10279                (gnus-cache-possibly-enter-article
10280                 gnus-newsgroup-name article
10281                 (= mark gnus-ticked-mark)
10282                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10283
10284         (when (gnus-summary-goto-subject article nil t)
10285           (let ((buffer-read-only nil))
10286             (gnus-summary-show-thread)
10287             ;; Fix the mark.
10288             (gnus-summary-update-mark mark 'unread)
10289             t))))))
10290
10291 (defun gnus-summary-update-secondary-mark (article)
10292   "Update the secondary (read, process, cache) mark."
10293   (gnus-summary-update-mark
10294    (cond ((memq article gnus-newsgroup-processable)
10295           gnus-process-mark)
10296          ((memq article gnus-newsgroup-cached)
10297           gnus-cached-mark)
10298          ((memq article gnus-newsgroup-replied)
10299           gnus-replied-mark)
10300          ((memq article gnus-newsgroup-forwarded)
10301           gnus-forwarded-mark)
10302          ((memq article gnus-newsgroup-saved)
10303           gnus-saved-mark)
10304          ((memq article gnus-newsgroup-recent)
10305           gnus-recent-mark)
10306          ((memq article gnus-newsgroup-unseen)
10307           gnus-unseen-mark)
10308          (t gnus-no-mark))
10309    'replied)
10310   (when (gnus-visual-p 'summary-highlight 'highlight)
10311     (gnus-run-hooks 'gnus-summary-update-hook))
10312   t)
10313
10314 (defun gnus-summary-update-download-mark (article)
10315   "Update the download mark."
10316   (gnus-summary-update-mark
10317    (cond ((memq article gnus-newsgroup-undownloaded)
10318           gnus-undownloaded-mark)
10319          (gnus-newsgroup-agentized
10320           gnus-downloaded-mark)
10321          (t
10322           gnus-no-mark))
10323    'download)
10324   (gnus-summary-update-line t)
10325   t)
10326
10327 (defun gnus-summary-update-mark (mark type)
10328   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10329         (buffer-read-only nil))
10330     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10331     (when forward
10332       (when (looking-at "\r")
10333         (incf forward))
10334       (when (<= (+ forward (point)) (point-max))
10335         ;; Go to the right position on the line.
10336         (goto-char (+ forward (point)))
10337         ;; Replace the old mark with the new mark.
10338         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10339         ;; Optionally update the marks by some user rule.
10340         (when (eq type 'unread)
10341           (gnus-data-set-mark
10342            (gnus-data-find (gnus-summary-article-number)) mark)
10343           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10344
10345 (defun gnus-mark-article-as-read (article &optional mark)
10346   "Enter ARTICLE in the pertinent lists and remove it from others."
10347   ;; Make the article expirable.
10348   (let ((mark (or mark gnus-del-mark)))
10349     (setq gnus-newsgroup-expirable
10350           (if (= mark gnus-expirable-mark)
10351               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10352             (delq article gnus-newsgroup-expirable)))
10353     ;; Remove from unread and marked lists.
10354     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10355     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10356     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10357     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10358     (push (cons article mark) gnus-newsgroup-reads)
10359     ;; Possibly remove from cache, if that is used.
10360     (when gnus-use-cache
10361       (gnus-cache-enter-remove-article article))
10362     t))
10363
10364 (defun gnus-mark-article-as-unread (article &optional mark)
10365   "Enter ARTICLE in the pertinent lists and remove it from others."
10366   (let ((mark (or mark gnus-ticked-mark)))
10367     (if (<= article 0)
10368         (progn
10369           (gnus-error 1 "Can't mark negative article numbers")
10370           nil)
10371       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10372             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10373             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10374             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10375             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10376
10377       ;; Unsuppress duplicates?
10378       (when gnus-suppress-duplicates
10379         (gnus-dup-unsuppress-article article))
10380
10381       (cond ((= mark gnus-ticked-mark)
10382              (setq gnus-newsgroup-marked
10383                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10384             ((= mark gnus-spam-mark)
10385              (setq gnus-newsgroup-spam-marked
10386                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10387                                             article)))
10388             ((= mark gnus-dormant-mark)
10389              (setq gnus-newsgroup-dormant
10390                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10391             (t
10392              (setq gnus-newsgroup-unreads
10393                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10394       (gnus-pull article gnus-newsgroup-reads)
10395       t)))
10396
10397 (defalias 'gnus-summary-mark-as-unread-forward
10398   'gnus-summary-tick-article-forward)
10399 (make-obsolete 'gnus-summary-mark-as-unread-forward
10400                'gnus-summary-tick-article-forward)
10401 (defun gnus-summary-tick-article-forward (n)
10402   "Tick N articles forwards.
10403 If N is negative, tick backwards instead.
10404 The difference between N and the number of articles ticked is returned."
10405   (interactive "p")
10406   (gnus-summary-mark-forward n gnus-ticked-mark))
10407
10408 (defalias 'gnus-summary-mark-as-unread-backward
10409   'gnus-summary-tick-article-backward)
10410 (make-obsolete 'gnus-summary-mark-as-unread-backward
10411                'gnus-summary-tick-article-backward)
10412 (defun gnus-summary-tick-article-backward (n)
10413   "Tick N articles backwards.
10414 The difference between N and the number of articles ticked is returned."
10415   (interactive "p")
10416   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10417
10418 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10419 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10420 (defun gnus-summary-tick-article (&optional article clear-mark)
10421   "Mark current article as unread.
10422 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10423 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10424   (interactive)
10425   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10426                                        gnus-ticked-mark)))
10427
10428 (defun gnus-summary-mark-as-read-forward (n)
10429   "Mark N articles as read forwards.
10430 If N is negative, mark backwards instead.
10431 The difference between N and the actual number of articles marked is
10432 returned."
10433   (interactive "p")
10434   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10435
10436 (defun gnus-summary-mark-as-read-backward (n)
10437   "Mark the N articles as read backwards.
10438 The difference between N and the actual number of articles marked is
10439 returned."
10440   (interactive "p")
10441   (gnus-summary-mark-forward
10442    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10443
10444 (defun gnus-summary-mark-as-read (&optional article mark)
10445   "Mark current article as read.
10446 ARTICLE specifies the article to be marked as read.
10447 MARK specifies a string to be inserted at the beginning of the line."
10448   (gnus-summary-mark-article article mark))
10449
10450 (defun gnus-summary-clear-mark-forward (n)
10451   "Clear marks from N articles forward.
10452 If N is negative, clear backward instead.
10453 The difference between N and the number of marks cleared is returned."
10454   (interactive "p")
10455   (gnus-summary-mark-forward n gnus-unread-mark))
10456
10457 (defun gnus-summary-clear-mark-backward (n)
10458   "Clear marks from N articles backward.
10459 The difference between N and the number of marks cleared is returned."
10460   (interactive "p")
10461   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10462
10463 (defun gnus-summary-mark-unread-as-read ()
10464   "Intended to be used by `gnus-summary-mark-article-hook'."
10465   (when (memq gnus-current-article gnus-newsgroup-unreads)
10466     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10467
10468 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10469   "Intended to be used by `gnus-summary-mark-article-hook'."
10470   (let ((mark (gnus-summary-article-mark)))
10471     (when (or (gnus-unread-mark-p mark)
10472               (gnus-read-mark-p mark))
10473       (gnus-summary-mark-article gnus-current-article
10474                                  (or new-mark gnus-read-mark)))))
10475
10476 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10477   "Intended to be used by `gnus-summary-mark-article-hook'."
10478   (let ((mark (gnus-summary-article-mark)))
10479     (when (or (gnus-unread-mark-p mark)
10480               (gnus-read-mark-p mark))
10481       (gnus-summary-mark-article (gnus-summary-article-number)
10482                                  (or new-mark gnus-read-mark)))))
10483
10484 (defun gnus-summary-mark-unread-as-ticked ()
10485   "Intended to be used by `gnus-summary-mark-article-hook'."
10486   (when (memq gnus-current-article gnus-newsgroup-unreads)
10487     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10488
10489 (defun gnus-summary-mark-region-as-read (point mark all)
10490   "Mark all unread articles between point and mark as read.
10491 If given a prefix, mark all articles between point and mark as read,
10492 even ticked and dormant ones."
10493   (interactive "r\nP")
10494   (save-excursion
10495     (let (article)
10496       (goto-char point)
10497       (beginning-of-line)
10498       (while (and
10499               (< (point) mark)
10500               (progn
10501                 (when (or all
10502                           (memq (setq article (gnus-summary-article-number))
10503                                 gnus-newsgroup-unreads))
10504                   (gnus-summary-mark-article article gnus-del-mark))
10505                 t)
10506               (gnus-summary-find-next))))))
10507
10508 (defun gnus-summary-mark-below (score mark)
10509   "Mark articles with score less than SCORE with MARK."
10510   (interactive "P\ncMark: ")
10511   (setq score (if score
10512                   (prefix-numeric-value score)
10513                 (or gnus-summary-default-score 0)))
10514   (save-excursion
10515     (set-buffer gnus-summary-buffer)
10516     (goto-char (point-min))
10517     (while
10518         (progn
10519           (and (< (gnus-summary-article-score) score)
10520                (gnus-summary-mark-article nil mark))
10521           (gnus-summary-find-next)))))
10522
10523 (defun gnus-summary-kill-below (&optional score)
10524   "Mark articles with score below SCORE as read."
10525   (interactive "P")
10526   (gnus-summary-mark-below score gnus-killed-mark))
10527
10528 (defun gnus-summary-clear-above (&optional score)
10529   "Clear all marks from articles with score above SCORE."
10530   (interactive "P")
10531   (gnus-summary-mark-above score gnus-unread-mark))
10532
10533 (defun gnus-summary-tick-above (&optional score)
10534   "Tick all articles with score above SCORE."
10535   (interactive "P")
10536   (gnus-summary-mark-above score gnus-ticked-mark))
10537
10538 (defun gnus-summary-mark-above (score mark)
10539   "Mark articles with score over SCORE with MARK."
10540   (interactive "P\ncMark: ")
10541   (setq score (if score
10542                   (prefix-numeric-value score)
10543                 (or gnus-summary-default-score 0)))
10544   (save-excursion
10545     (set-buffer gnus-summary-buffer)
10546     (goto-char (point-min))
10547     (while (and (progn
10548                   (when (> (gnus-summary-article-score) score)
10549                     (gnus-summary-mark-article nil mark))
10550                   t)
10551                 (gnus-summary-find-next)))))
10552
10553 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10554 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10555 (defun gnus-summary-limit-include-expunged (&optional no-error)
10556   "Display all the hidden articles that were expunged for low scores."
10557   (interactive)
10558   (let ((buffer-read-only nil))
10559     (let ((scored gnus-newsgroup-scored)
10560           headers h)
10561       (while scored
10562         (unless (gnus-summary-article-header (caar scored))
10563           (and (setq h (gnus-number-to-header (caar scored)))
10564                (< (cdar scored) gnus-summary-expunge-below)
10565                (push h headers)))
10566         (setq scored (cdr scored)))
10567       (if (not headers)
10568           (when (not no-error)
10569             (error "No expunged articles hidden"))
10570         (goto-char (point-min))
10571         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10572         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10573         (mapcar (lambda (x) (push (mail-header-number x)
10574                                   gnus-newsgroup-limit))
10575                 headers)
10576         (gnus-summary-prepare-unthreaded (nreverse headers))
10577         (goto-char (point-min))
10578         (gnus-summary-position-point)
10579         t))))
10580
10581 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10582   "Mark all unread articles in this newsgroup as read.
10583 If prefix argument ALL is non-nil, ticked and dormant articles will
10584 also be marked as read.
10585 If QUIETLY is non-nil, no questions will be asked.
10586
10587 If TO-HERE is non-nil, it should be a point in the buffer.  All
10588 articles before (after, if REVERSE is set) this point will be marked
10589 as read.
10590
10591 Note that this function will only catch up the unread article
10592 in the current summary buffer limitation.
10593
10594 The number of articles marked as read is returned."
10595   (interactive "P")
10596   (prog1
10597       (save-excursion
10598         (when (or quietly
10599                   (not gnus-interactive-catchup) ;Without confirmation?
10600                   gnus-expert-user
10601                   (gnus-y-or-n-p
10602                    (if all
10603                        "Mark absolutely all articles as read? "
10604                      "Mark all unread articles as read? ")))
10605           (if (and not-mark
10606                    (not gnus-newsgroup-adaptive)
10607                    (not gnus-newsgroup-auto-expire)
10608                    (not gnus-suppress-duplicates)
10609                    (or (not gnus-use-cache)
10610                        (eq gnus-use-cache 'passive)))
10611               (progn
10612                 (when all
10613                   (setq gnus-newsgroup-marked nil
10614                         gnus-newsgroup-spam-marked nil
10615                         gnus-newsgroup-dormant nil))
10616                 (setq gnus-newsgroup-unreads
10617                       (gnus-sorted-nunion
10618                        (gnus-intersection gnus-newsgroup-unreads
10619                                           gnus-newsgroup-downloadable)
10620                        gnus-newsgroup-unfetched)))
10621             ;; We actually mark all articles as canceled, which we
10622             ;; have to do when using auto-expiry or adaptive scoring.
10623             (gnus-summary-show-all-threads)
10624             (if (and to-here reverse)
10625                 (progn
10626                   (goto-char to-here)
10627                   (gnus-summary-mark-current-read-and-unread-as-read
10628                    gnus-catchup-mark)
10629                   (while (gnus-summary-find-next (not all))
10630                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10631               (when (gnus-summary-first-subject (not all))
10632                 (while (and
10633                         (if to-here (< (point) to-here) t)
10634                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10635                         (gnus-summary-find-next (not all))))))
10636             (gnus-set-mode-line 'summary))
10637           t))
10638     (gnus-summary-position-point)))
10639
10640 (defun gnus-summary-catchup-to-here (&optional all)
10641   "Mark all unticked articles before the current one as read.
10642 If ALL is non-nil, also mark ticked and dormant articles as read."
10643   (interactive "P")
10644   (save-excursion
10645     (gnus-save-hidden-threads
10646       (let ((beg (point)))
10647         ;; We check that there are unread articles.
10648         (when (or all (gnus-summary-find-prev))
10649           (gnus-summary-catchup all t beg)))))
10650   (gnus-summary-position-point))
10651
10652 (defun gnus-summary-catchup-from-here (&optional all)
10653   "Mark all unticked articles after (and including) the current one as read.
10654 If ALL is non-nil, also mark ticked and dormant articles as read."
10655   (interactive "P")
10656   (save-excursion
10657     (gnus-save-hidden-threads
10658       (let ((beg (point)))
10659         ;; We check that there are unread articles.
10660         (when (or all (gnus-summary-find-next))
10661           (gnus-summary-catchup all t beg nil t)))))
10662   (gnus-summary-position-point))
10663
10664 (defun gnus-summary-catchup-all (&optional quietly)
10665   "Mark all articles in this newsgroup as read.
10666 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10667 instead, which marks only unread articles as read."
10668   (interactive "P")
10669   (gnus-summary-catchup t quietly))
10670
10671 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10672   "Mark all unread articles in this group as read, then exit.
10673 If prefix argument ALL is non-nil, all articles are marked as read.
10674 If QUIETLY is non-nil, no questions will be asked."
10675   (interactive "P")
10676   (when (gnus-summary-catchup all quietly nil 'fast)
10677     ;; Select next newsgroup or exit.
10678     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10679              (eq gnus-auto-select-next 'quietly))
10680         (gnus-summary-next-group nil)
10681       (gnus-summary-exit))))
10682
10683 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10684   "Mark all articles in this newsgroup as read, and then exit.
10685 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10686 instead, which marks only unread articles as read."
10687   (interactive "P")
10688   (gnus-summary-catchup-and-exit t quietly))
10689
10690 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10691   "Mark all articles in this group as read and select the next group.
10692 If given a prefix, mark all articles, unread as well as ticked, as
10693 read."
10694   (interactive "P")
10695   (save-excursion
10696     (gnus-summary-catchup all))
10697   (gnus-summary-next-group))
10698
10699 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10700   "Mark all articles in this group as read and select the previous group.
10701 If given a prefix, mark all articles, unread as well as ticked, as
10702 read."
10703   (interactive "P")
10704   (save-excursion
10705     (gnus-summary-catchup all))
10706   (gnus-summary-next-group nil nil t))
10707
10708 ;;;
10709 ;;; with article
10710 ;;;
10711
10712 (defmacro gnus-with-article (article &rest forms)
10713   "Select ARTICLE and perform FORMS in the original article buffer.
10714 Then replace the article with the result."
10715   `(progn
10716      ;; We don't want the article to be marked as read.
10717      (let (gnus-mark-article-hook)
10718        (gnus-summary-select-article t t nil ,article))
10719      (set-buffer gnus-original-article-buffer)
10720      ,@forms
10721      (if (not (gnus-check-backend-function
10722                'request-replace-article (car gnus-article-current)))
10723          (gnus-message 5 "Read-only group; not replacing")
10724        (unless (gnus-request-replace-article
10725                 ,article (car gnus-article-current)
10726                 (current-buffer) t)
10727          (error "Couldn't replace article")))
10728      ;; The cache and backlog have to be flushed somewhat.
10729      (when gnus-keep-backlog
10730        (gnus-backlog-remove-article
10731         (car gnus-article-current) (cdr gnus-article-current)))
10732      (when gnus-use-cache
10733        (gnus-cache-update-article
10734         (car gnus-article-current) (cdr gnus-article-current)))))
10735
10736 (put 'gnus-with-article 'lisp-indent-function 1)
10737 (put 'gnus-with-article 'edebug-form-spec '(form body))
10738
10739 ;; Thread-based commands.
10740
10741 (defun gnus-summary-articles-in-thread (&optional article)
10742   "Return a list of all articles in the current thread.
10743 If ARTICLE is non-nil, return all articles in the thread that starts
10744 with that article."
10745   (let* ((article (or article (gnus-summary-article-number)))
10746          (data (gnus-data-find-list article))
10747          (top-level (gnus-data-level (car data)))
10748          (top-subject
10749           (cond ((null gnus-thread-operation-ignore-subject)
10750                  (gnus-simplify-subject-re
10751                   (mail-header-subject (gnus-data-header (car data)))))
10752                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10753                  (gnus-simplify-subject-fuzzy
10754                   (mail-header-subject (gnus-data-header (car data)))))
10755                 (t nil)))
10756          (end-point (save-excursion
10757                       (if (gnus-summary-go-to-next-thread)
10758                           (point) (point-max))))
10759          articles)
10760     (while (and data
10761                 (< (gnus-data-pos (car data)) end-point))
10762       (when (or (not top-subject)
10763                 (string= top-subject
10764                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10765                              (gnus-simplify-subject-fuzzy
10766                               (mail-header-subject
10767                                (gnus-data-header (car data))))
10768                            (gnus-simplify-subject-re
10769                             (mail-header-subject
10770                              (gnus-data-header (car data)))))))
10771         (push (gnus-data-number (car data)) articles))
10772       (unless (and (setq data (cdr data))
10773                    (> (gnus-data-level (car data)) top-level))
10774         (setq data nil)))
10775     ;; Return the list of articles.
10776     (nreverse articles)))
10777
10778 (defun gnus-summary-rethread-current ()
10779   "Rethread the thread the current article is part of."
10780   (interactive)
10781   (let* ((gnus-show-threads t)
10782          (article (gnus-summary-article-number))
10783          (id (mail-header-id (gnus-summary-article-header)))
10784          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10785     (unless id
10786       (error "No article on the current line"))
10787     (gnus-rebuild-thread id)
10788     (gnus-summary-goto-subject article)))
10789
10790 (defun gnus-summary-reparent-thread ()
10791   "Make the current article child of the marked (or previous) article.
10792
10793 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10794 is non-nil or the Subject: of both articles are the same."
10795   (interactive)
10796   (unless (not (gnus-group-read-only-p))
10797     (error "The current newsgroup does not support article editing"))
10798   (unless (<= (length gnus-newsgroup-processable) 1)
10799     (error "No more than one article may be marked"))
10800   (save-window-excursion
10801     (let ((gnus-article-buffer " *reparent*")
10802           (current-article (gnus-summary-article-number))
10803           ;; First grab the marked article, otherwise one line up.
10804           (parent-article (if (not (null gnus-newsgroup-processable))
10805                               (car gnus-newsgroup-processable)
10806                             (save-excursion
10807                               (if (eq (forward-line -1) 0)
10808                                   (gnus-summary-article-number)
10809                                 (error "Beginning of summary buffer"))))))
10810       (unless (not (eq current-article parent-article))
10811         (error "An article may not be self-referential"))
10812       (let ((message-id (mail-header-id
10813                          (gnus-summary-article-header parent-article))))
10814         (unless (and message-id (not (equal message-id "")))
10815           (error "No message-id in desired parent"))
10816         (gnus-with-article current-article
10817           (save-restriction
10818             (goto-char (point-min))
10819             (message-narrow-to-head)
10820             (if (re-search-forward "^References: " nil t)
10821                 (progn
10822                   (re-search-forward "^[^ \t]" nil t)
10823                   (forward-line -1)
10824                   (end-of-line)
10825                   (insert " " message-id))
10826               (insert "References: " message-id "\n"))))
10827         (set-buffer gnus-summary-buffer)
10828         (gnus-summary-unmark-all-processable)
10829         (gnus-summary-update-article current-article)
10830         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10831             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10832         (gnus-summary-rethread-current)
10833         (gnus-message 3 "Article %d is now the child of article %d"
10834                       current-article parent-article)))))
10835
10836 (defun gnus-summary-toggle-threads (&optional arg)
10837   "Toggle showing conversation threads.
10838 If ARG is positive number, turn showing conversation threads on."
10839   (interactive "P")
10840   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10841     (setq gnus-show-threads
10842           (if (null arg) (not gnus-show-threads)
10843             (> (prefix-numeric-value arg) 0)))
10844     (gnus-summary-prepare)
10845     (gnus-summary-goto-subject current)
10846     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10847     (gnus-summary-position-point)))
10848
10849 (defun gnus-summary-show-all-threads ()
10850   "Show all threads."
10851   (interactive)
10852   (save-excursion
10853     (let ((buffer-read-only nil))
10854       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10855   (gnus-summary-position-point))
10856
10857 (defun gnus-summary-show-thread ()
10858   "Show thread subtrees.
10859 Returns nil if no thread was there to be shown."
10860   (interactive)
10861   (let ((buffer-read-only nil)
10862         (orig (point))
10863         (end (point-at-eol))
10864         ;; Leave point at bol
10865         (beg (progn (beginning-of-line) (point))))
10866     (prog1
10867         ;; Any hidden lines here?
10868         (search-forward "\r" end t)
10869       (subst-char-in-region beg end ?\^M ?\n t)
10870       (goto-char orig)
10871       (gnus-summary-position-point))))
10872
10873 (defun gnus-summary-maybe-hide-threads ()
10874   "If requested, hide the threads that should be hidden."
10875   (when (and gnus-show-threads
10876              gnus-thread-hide-subtree)
10877     (gnus-summary-hide-all-threads
10878      (if (or (consp gnus-thread-hide-subtree)
10879              (functionp gnus-thread-hide-subtree))
10880          (gnus-make-predicate gnus-thread-hide-subtree)
10881        nil))))
10882
10883 ;;; Hiding predicates.
10884
10885 (defun gnus-article-unread-p (header)
10886   (memq (mail-header-number header) gnus-newsgroup-unreads))
10887
10888 (defun gnus-article-unseen-p (header)
10889   (memq (mail-header-number header) gnus-newsgroup-unseen))
10890
10891 (defun gnus-map-articles (predicate articles)
10892   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10893   (apply 'gnus-or (mapcar predicate
10894                           (mapcar 'gnus-summary-article-header articles))))
10895
10896 (defun gnus-summary-hide-all-threads (&optional predicate)
10897   "Hide all thread subtrees.
10898 If PREDICATE is supplied, threads that satisfy this predicate
10899 will not be hidden."
10900   (interactive)
10901   (save-excursion
10902     (goto-char (point-min))
10903     (let ((end nil))
10904       (while (not end)
10905         (when (or (not predicate)
10906                   (gnus-map-articles
10907                    predicate (gnus-summary-article-children)))
10908             (gnus-summary-hide-thread))
10909         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10910   (gnus-summary-position-point))
10911
10912 (defun gnus-summary-hide-thread ()
10913   "Hide thread subtrees.
10914 If PREDICATE is supplied, threads that satisfy this predicate
10915 will not be hidden.
10916 Returns nil if no threads were there to be hidden."
10917   (interactive)
10918   (let ((buffer-read-only nil)
10919         (start (point))
10920         (article (gnus-summary-article-number)))
10921     (goto-char start)
10922     ;; Go forward until either the buffer ends or the subthread
10923     ;; ends.
10924     (when (and (not (eobp))
10925                (or (zerop (gnus-summary-next-thread 1 t))
10926                    (goto-char (point-max))))
10927       (prog1
10928           (if (and (> (point) start)
10929                    (search-backward "\n" start t))
10930               (progn
10931                 (subst-char-in-region start (point) ?\n ?\^M)
10932                 (gnus-summary-goto-subject article))
10933             (goto-char start)
10934             nil)))))
10935
10936 (defun gnus-summary-go-to-next-thread (&optional previous)
10937   "Go to the same level (or less) next thread.
10938 If PREVIOUS is non-nil, go to previous thread instead.
10939 Return the article number moved to, or nil if moving was impossible."
10940   (let ((level (gnus-summary-thread-level))
10941         (way (if previous -1 1))
10942         (beg (point)))
10943     (forward-line way)
10944     (while (and (not (eobp))
10945                 (< level (gnus-summary-thread-level)))
10946       (forward-line way))
10947     (if (eobp)
10948         (progn
10949           (goto-char beg)
10950           nil)
10951       (setq beg (point))
10952       (prog1
10953           (gnus-summary-article-number)
10954         (goto-char beg)))))
10955
10956 (defun gnus-summary-next-thread (n &optional silent)
10957   "Go to the same level next N'th thread.
10958 If N is negative, search backward instead.
10959 Returns the difference between N and the number of skips actually
10960 done.
10961
10962 If SILENT, don't output messages."
10963   (interactive "p")
10964   (let ((backward (< n 0))
10965         (n (abs n)))
10966     (while (and (> n 0)
10967                 (gnus-summary-go-to-next-thread backward))
10968       (decf n))
10969     (unless silent
10970       (gnus-summary-position-point))
10971     (when (and (not silent) (/= 0 n))
10972       (gnus-message 7 "No more threads"))
10973     n))
10974
10975 (defun gnus-summary-prev-thread (n)
10976   "Go to the same level previous N'th thread.
10977 Returns the difference between N and the number of skips actually
10978 done."
10979   (interactive "p")
10980   (gnus-summary-next-thread (- n)))
10981
10982 (defun gnus-summary-go-down-thread ()
10983   "Go down one level in the current thread."
10984   (let ((children (gnus-summary-article-children)))
10985     (when children
10986       (gnus-summary-goto-subject (car children)))))
10987
10988 (defun gnus-summary-go-up-thread ()
10989   "Go up one level in the current thread."
10990   (let ((parent (gnus-summary-article-parent)))
10991     (when parent
10992       (gnus-summary-goto-subject parent))))
10993
10994 (defun gnus-summary-down-thread (n)
10995   "Go down thread N steps.
10996 If N is negative, go up instead.
10997 Returns the difference between N and how many steps down that were
10998 taken."
10999   (interactive "p")
11000   (let ((up (< n 0))
11001         (n (abs n)))
11002     (while (and (> n 0)
11003                 (if up (gnus-summary-go-up-thread)
11004                   (gnus-summary-go-down-thread)))
11005       (setq n (1- n)))
11006     (gnus-summary-position-point)
11007     (when (/= 0 n)
11008       (gnus-message 7 "Can't go further"))
11009     n))
11010
11011 (defun gnus-summary-up-thread (n)
11012   "Go up thread N steps.
11013 If N is negative, go down instead.
11014 Returns the difference between N and how many steps down that were
11015 taken."
11016   (interactive "p")
11017   (gnus-summary-down-thread (- n)))
11018
11019 (defun gnus-summary-top-thread ()
11020   "Go to the top of the thread."
11021   (interactive)
11022   (while (gnus-summary-go-up-thread))
11023   (gnus-summary-article-number))
11024
11025 (defun gnus-summary-kill-thread (&optional unmark)
11026   "Mark articles under current thread as read.
11027 If the prefix argument is positive, remove any kinds of marks.
11028 If the prefix argument is negative, tick articles instead."
11029   (interactive "P")
11030   (when unmark
11031     (setq unmark (prefix-numeric-value unmark)))
11032   (let ((articles (gnus-summary-articles-in-thread)))
11033     (save-excursion
11034       ;; Expand the thread.
11035       (gnus-summary-show-thread)
11036       ;; Mark all the articles.
11037       (while articles
11038         (gnus-summary-goto-subject (car articles))
11039         (cond ((null unmark)
11040                (gnus-summary-mark-article-as-read gnus-killed-mark))
11041               ((> unmark 0)
11042                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11043               (t
11044                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11045         (setq articles (cdr articles))))
11046     ;; Hide killed subtrees.
11047     (and (null unmark)
11048          gnus-thread-hide-killed
11049          (gnus-summary-hide-thread))
11050     ;; If marked as read, go to next unread subject.
11051     (when (null unmark)
11052       ;; Go to next unread subject.
11053       (gnus-summary-next-subject 1 t)))
11054   (gnus-set-mode-line 'summary))
11055
11056 ;; Summary sorting commands
11057
11058 (defun gnus-summary-sort-by-number (&optional reverse)
11059   "Sort the summary buffer by article number.
11060 Argument REVERSE means reverse order."
11061   (interactive "P")
11062   (gnus-summary-sort 'number reverse))
11063
11064 (defun gnus-summary-sort-by-random (&optional reverse)
11065   "Randomize the order in the summary buffer.
11066 Argument REVERSE means to randomize in reverse order."
11067   (interactive "P")
11068   (gnus-summary-sort 'random reverse))
11069
11070 (defun gnus-summary-sort-by-author (&optional reverse)
11071   "Sort the summary buffer by author name alphabetically.
11072 If `case-fold-search' is non-nil, case of letters is ignored.
11073 Argument REVERSE means reverse order."
11074   (interactive "P")
11075   (gnus-summary-sort 'author reverse))
11076
11077 (defun gnus-summary-sort-by-recipient (&optional reverse)
11078   "Sort the summary buffer by recipient name alphabetically.
11079 If `case-fold-search' is non-nil, case of letters is ignored.
11080 Argument REVERSE means reverse order."
11081   (interactive "P")
11082   (gnus-summary-sort 'recipient reverse))
11083
11084 (defun gnus-summary-sort-by-subject (&optional reverse)
11085   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11086 If `case-fold-search' is non-nil, case of letters is ignored.
11087 Argument REVERSE means reverse order."
11088   (interactive "P")
11089   (gnus-summary-sort 'subject reverse))
11090
11091 (defun gnus-summary-sort-by-date (&optional reverse)
11092   "Sort the summary buffer by date.
11093 Argument REVERSE means reverse order."
11094   (interactive "P")
11095   (gnus-summary-sort 'date reverse))
11096
11097 (defun gnus-summary-sort-by-score (&optional reverse)
11098   "Sort the summary buffer by score.
11099 Argument REVERSE means reverse order."
11100   (interactive "P")
11101   (gnus-summary-sort 'score reverse))
11102
11103 (defun gnus-summary-sort-by-lines (&optional reverse)
11104   "Sort the summary buffer by the number of lines.
11105 Argument REVERSE means reverse order."
11106   (interactive "P")
11107   (gnus-summary-sort 'lines reverse))
11108
11109 (defun gnus-summary-sort-by-chars (&optional reverse)
11110   "Sort the summary buffer by article length.
11111 Argument REVERSE means reverse order."
11112   (interactive "P")
11113   (gnus-summary-sort 'chars reverse))
11114
11115 (defun gnus-summary-sort-by-original (&optional reverse)
11116   "Sort the summary buffer using the default sorting method.
11117 Argument REVERSE means reverse order."
11118   (interactive "P")
11119   (let* ((buffer-read-only)
11120          (gnus-summary-prepare-hook nil))
11121     ;; We do the sorting by regenerating the threads.
11122     (gnus-summary-prepare)
11123     ;; Hide subthreads if needed.
11124     (gnus-summary-maybe-hide-threads)))
11125
11126 (defun gnus-summary-sort (predicate reverse)
11127   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11128   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11129          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11130          (gnus-thread-sort-functions
11131           (if (not reverse)
11132               thread
11133             `(lambda (t1 t2)
11134                (,thread t2 t1))))
11135          (gnus-sort-gathered-threads-function
11136           gnus-thread-sort-functions)
11137          (gnus-article-sort-functions
11138           (if (not reverse)
11139               article
11140             `(lambda (t1 t2)
11141                (,article t2 t1))))
11142          (buffer-read-only)
11143          (gnus-summary-prepare-hook nil))
11144     ;; We do the sorting by regenerating the threads.
11145     (gnus-summary-prepare)
11146     ;; Hide subthreads if needed.
11147     (gnus-summary-maybe-hide-threads)))
11148
11149 ;; Summary saving commands.
11150
11151 (defun gnus-summary-save-article (&optional n not-saved)
11152   "Save the current article using the default saver function.
11153 If N is a positive number, save the N next articles.
11154 If N is a negative number, save the N previous articles.
11155 If N is nil and any articles have been marked with the process mark,
11156 save those articles instead.
11157 The variable `gnus-default-article-saver' specifies the saver function."
11158   (interactive "P")
11159   (let* ((articles (gnus-summary-work-articles n))
11160          (save-buffer (save-excursion
11161                         (nnheader-set-temp-buffer " *Gnus Save*")))
11162          (num (length articles))
11163          header file)
11164     (dolist (article articles)
11165       (setq header (gnus-summary-article-header article))
11166       (if (not (vectorp header))
11167           ;; This is a pseudo-article.
11168           (if (assq 'name header)
11169               (gnus-copy-file (cdr (assq 'name header)))
11170             (gnus-message 1 "Article %d is unsaveable" article))
11171         ;; This is a real article.
11172         (save-window-excursion
11173           (let ((gnus-display-mime-function nil)
11174                 (gnus-article-prepare-hook nil))
11175             (gnus-summary-select-article t nil nil article)))
11176         (save-excursion
11177           (set-buffer save-buffer)
11178           (erase-buffer)
11179           (insert-buffer-substring gnus-original-article-buffer))
11180         (setq file (gnus-article-save save-buffer file num))
11181         (gnus-summary-remove-process-mark article)
11182         (unless not-saved
11183           (gnus-summary-set-saved-mark article))))
11184     (gnus-kill-buffer save-buffer)
11185     (gnus-summary-position-point)
11186     (gnus-set-mode-line 'summary)
11187     n))
11188
11189 (defun gnus-summary-pipe-output (&optional arg headers)
11190   "Pipe the current article to a subprocess.
11191 If N is a positive number, pipe the N next articles.
11192 If N is a negative number, pipe the N previous articles.
11193 If N is nil and any articles have been marked with the process mark,
11194 pipe those articles instead.
11195 If HEADERS (the symbolic prefix), include the headers, too."
11196   (interactive (gnus-interactive "P\ny"))
11197   (require 'gnus-art)
11198   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11199         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11200     (gnus-summary-save-article arg t))
11201   (let ((buffer (get-buffer "*Shell Command Output*")))
11202     (when (and buffer
11203                (not (zerop (buffer-size buffer))))
11204       (gnus-configure-windows 'pipe))))
11205
11206 (defun gnus-summary-save-article-mail (&optional arg)
11207   "Append the current article to an mail file.
11208 If N is a positive number, save the N next articles.
11209 If N is a negative number, save the N previous articles.
11210 If N is nil and any articles have been marked with the process mark,
11211 save those articles instead."
11212   (interactive "P")
11213   (require 'gnus-art)
11214   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11215     (gnus-summary-save-article arg)))
11216
11217 (defun gnus-summary-save-article-rmail (&optional arg)
11218   "Append the current article to an rmail file.
11219 If N is a positive number, save the N next articles.
11220 If N is a negative number, save the N previous articles.
11221 If N is nil and any articles have been marked with the process mark,
11222 save those articles instead."
11223   (interactive "P")
11224   (require 'gnus-art)
11225   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11226     (gnus-summary-save-article arg)))
11227
11228 (defun gnus-summary-save-article-file (&optional arg)
11229   "Append the current article to a file.
11230 If N is a positive number, save the N next articles.
11231 If N is a negative number, save the N previous articles.
11232 If N is nil and any articles have been marked with the process mark,
11233 save those articles instead."
11234   (interactive "P")
11235   (require 'gnus-art)
11236   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11237     (gnus-summary-save-article arg)))
11238
11239 (defun gnus-summary-write-article-file (&optional arg)
11240   "Write the current article to a file, deleting the previous file.
11241 If N is a positive number, save the N next articles.
11242 If N is a negative number, save the N previous articles.
11243 If N is nil and any articles have been marked with the process mark,
11244 save those articles instead."
11245   (interactive "P")
11246   (require 'gnus-art)
11247   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11248     (gnus-summary-save-article arg)))
11249
11250 (defun gnus-summary-save-article-body-file (&optional arg)
11251   "Append the current article body to a file.
11252 If N is a positive number, save the N next articles.
11253 If N is a negative number, save the N previous articles.
11254 If N is nil and any articles have been marked with the process mark,
11255 save those articles instead."
11256   (interactive "P")
11257   (require 'gnus-art)
11258   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11259     (gnus-summary-save-article arg)))
11260
11261 (defun gnus-summary-muttprint (&optional arg)
11262   "Print the current article using Muttprint.
11263 If N is a positive number, save the N next articles.
11264 If N is a negative number, save the N previous articles.
11265 If N is nil and any articles have been marked with the process mark,
11266 save those articles instead."
11267   (interactive "P")
11268   (require 'gnus-art)
11269   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11270     (gnus-summary-save-article arg t)))
11271
11272 (defun gnus-summary-pipe-message (program)
11273   "Pipe the current article through PROGRAM."
11274   (interactive "sProgram: ")
11275   (gnus-summary-select-article)
11276   (let ((mail-header-separator ""))
11277     (gnus-eval-in-buffer-window gnus-article-buffer
11278       (save-restriction
11279         (widen)
11280         (let ((start (window-start))
11281               buffer-read-only)
11282           (message-pipe-buffer-body program)
11283           (set-window-start (get-buffer-window (current-buffer)) start))))))
11284
11285 (defun gnus-get-split-value (methods)
11286   "Return a value based on the split METHODS."
11287   (let (split-name method result match)
11288     (when methods
11289       (save-excursion
11290         (set-buffer gnus-original-article-buffer)
11291         (save-restriction
11292           (nnheader-narrow-to-headers)
11293           (while (and methods (not split-name))
11294             (goto-char (point-min))
11295             (setq method (pop methods))
11296             (setq match (car method))
11297             (when (cond
11298                    ((stringp match)
11299                     ;; Regular expression.
11300                     (ignore-errors
11301                       (re-search-forward match nil t)))
11302                    ((functionp match)
11303                     ;; Function.
11304                     (save-restriction
11305                       (widen)
11306                       (setq result (funcall match gnus-newsgroup-name))))
11307                    ((consp match)
11308                     ;; Form.
11309                     (save-restriction
11310                       (widen)
11311                       (setq result (eval match)))))
11312               (setq split-name (cdr method))
11313               (cond ((stringp result)
11314                      (push (expand-file-name
11315                             result gnus-article-save-directory)
11316                            split-name))
11317                     ((consp result)
11318                      (setq split-name (append result split-name)))))))))
11319     (nreverse split-name)))
11320
11321 (defun gnus-valid-move-group-p (group)
11322   (and (boundp group)
11323        (symbol-name group)
11324        (symbol-value group)
11325        (gnus-get-function (gnus-find-method-for-group
11326                            (symbol-name group)) 'request-accept-article t)))
11327
11328 (defun gnus-read-move-group-name (prompt default articles prefix)
11329   "Read a group name."
11330   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11331          (minibuffer-confirm-incomplete nil) ; XEmacs
11332          (prom
11333           (format "%s %s to"
11334                   prompt
11335                   (if (> (length articles) 1)
11336                       (format "these %d articles" (length articles))
11337                     "this article")))
11338          (to-newsgroup
11339           (cond
11340            ((null split-name)
11341             (gnus-completing-read-with-default
11342              default prom
11343              gnus-active-hashtb
11344              'gnus-valid-move-group-p
11345              nil prefix
11346              'gnus-group-history))
11347            ((= 1 (length split-name))
11348             (gnus-completing-read-with-default
11349              (car split-name) prom
11350              gnus-active-hashtb
11351              'gnus-valid-move-group-p
11352              nil nil
11353              'gnus-group-history))
11354            (t
11355             (gnus-completing-read-with-default
11356              nil prom
11357              (mapcar 'list (nreverse split-name))
11358              nil nil nil
11359              'gnus-group-history))))
11360          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11361     (when to-newsgroup
11362       (if (or (string= to-newsgroup "")
11363               (string= to-newsgroup prefix))
11364           (setq to-newsgroup default))
11365       (unless to-newsgroup
11366         (error "No group name entered"))
11367       (or (gnus-active to-newsgroup)
11368           (gnus-activate-group to-newsgroup nil nil to-method)
11369           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11370                                      to-newsgroup))
11371               (or (and (gnus-request-create-group to-newsgroup to-method)
11372                        (gnus-activate-group
11373                         to-newsgroup nil nil to-method)
11374                        (gnus-subscribe-group to-newsgroup))
11375                   (error "Couldn't create group %s" to-newsgroup)))
11376           (error "No such group: %s" to-newsgroup)))
11377     to-newsgroup))
11378
11379 (defun gnus-summary-save-parts (type dir n &optional reverse)
11380   "Save parts matching TYPE to DIR.
11381 If REVERSE, save parts that do not match TYPE."
11382   (interactive
11383    (list (read-string "Save parts of type: "
11384                       (or (car gnus-summary-save-parts-type-history)
11385                           gnus-summary-save-parts-default-mime)
11386                       'gnus-summary-save-parts-type-history)
11387          (setq gnus-summary-save-parts-last-directory
11388                (read-file-name "Save to directory: "
11389                                gnus-summary-save-parts-last-directory
11390                                nil t))
11391          current-prefix-arg))
11392   (gnus-summary-iterate n
11393     (let ((gnus-display-mime-function nil)
11394           (gnus-inhibit-treatment t))
11395       (gnus-summary-select-article))
11396     (save-excursion
11397       (set-buffer gnus-article-buffer)
11398       (let ((handles (or gnus-article-mime-handles
11399                          (mm-dissect-buffer nil gnus-article-loose-mime)
11400                          (and gnus-article-emulate-mime
11401                               (mm-uu-dissect)))))
11402         (when handles
11403           (gnus-summary-save-parts-1 type dir handles reverse)
11404           (unless gnus-article-mime-handles ;; Don't destroy this case.
11405             (mm-destroy-parts handles)))))))
11406
11407 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11408   (if (stringp (car handle))
11409       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11410               (cdr handle))
11411     (when (if reverse
11412               (not (string-match type (mm-handle-media-type handle)))
11413             (string-match type (mm-handle-media-type handle)))
11414       (let ((file (expand-file-name
11415                    (gnus-map-function
11416                     mm-file-name-rewrite-functions
11417                     (file-name-nondirectory
11418                      (or
11419                       (mail-content-type-get
11420                        (mm-handle-disposition handle) 'filename)
11421                       (mail-content-type-get
11422                        (mm-handle-type handle) 'name)
11423                       (concat gnus-newsgroup-name
11424                               "." (number-to-string
11425                                    (cdr gnus-article-current))))))
11426                    dir)))
11427         (unless (file-exists-p file)
11428           (mm-save-part-to-file handle file))))))
11429
11430 ;; Summary extract commands
11431
11432 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11433   (let ((buffer-read-only nil)
11434         (article (gnus-summary-article-number))
11435         after-article b e)
11436     (unless (gnus-summary-goto-subject article)
11437       (error "No such article: %d" article))
11438     (gnus-summary-position-point)
11439     ;; If all commands are to be bunched up on one line, we collect
11440     ;; them here.
11441     (unless gnus-view-pseudos-separately
11442       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11443             files action)
11444         (while ps
11445           (setq action (cdr (assq 'action (car ps))))
11446           (setq files (list (cdr (assq 'name (car ps)))))
11447           (while (and ps (cdr ps)
11448                       (string= (or action "1")
11449                                (or (cdr (assq 'action (cadr ps))) "2")))
11450             (push (cdr (assq 'name (cadr ps))) files)
11451             (setcdr ps (cddr ps)))
11452           (when files
11453             (when (not (string-match "%s" action))
11454               (push " " files))
11455             (push " " files)
11456             (when (assq 'execute (car ps))
11457               (setcdr (assq 'execute (car ps))
11458                       (funcall (if (string-match "%s" action)
11459                                    'format 'concat)
11460                                action
11461                                (mapconcat
11462                                 (lambda (f)
11463                                   (if (equal f " ")
11464                                       f
11465                                     (shell-quote-argument f)))
11466                                 files " ")))))
11467           (setq ps (cdr ps)))))
11468     (if (and gnus-view-pseudos (not not-view))
11469         (while pslist
11470           (when (assq 'execute (car pslist))
11471             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11472                                   (eq gnus-view-pseudos 'not-confirm)))
11473           (setq pslist (cdr pslist)))
11474       (save-excursion
11475         (while pslist
11476           (setq after-article (or (cdr (assq 'article (car pslist)))
11477                                   (gnus-summary-article-number)))
11478           (gnus-summary-goto-subject after-article)
11479           (forward-line 1)
11480           (setq b (point))
11481           (insert "    " (file-name-nondirectory
11482                           (cdr (assq 'name (car pslist))))
11483                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11484           (setq e (point))
11485           (forward-line -1)             ; back to `b'
11486           (gnus-add-text-properties
11487            b (1- e) (list 'gnus-number gnus-reffed-article-number
11488                           gnus-mouse-face-prop gnus-mouse-face))
11489           (gnus-data-enter
11490            after-article gnus-reffed-article-number
11491            gnus-unread-mark b (car pslist) 0 (- e b))
11492           (setq gnus-newsgroup-unreads
11493                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11494                                          gnus-reffed-article-number))
11495           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11496           (setq pslist (cdr pslist)))))))
11497
11498 (defun gnus-pseudos< (p1 p2)
11499   (let ((c1 (cdr (assq 'action p1)))
11500         (c2 (cdr (assq 'action p2))))
11501     (and c1 c2 (string< c1 c2))))
11502
11503 (defun gnus-request-pseudo-article (props)
11504   (cond ((assq 'execute props)
11505          (gnus-execute-command (cdr (assq 'execute props)))))
11506   (let ((gnus-current-article (gnus-summary-article-number)))
11507     (gnus-run-hooks 'gnus-mark-article-hook)))
11508
11509 (defun gnus-execute-command (command &optional automatic)
11510   (save-excursion
11511     (gnus-article-setup-buffer)
11512     (set-buffer gnus-article-buffer)
11513     (setq buffer-read-only nil)
11514     (let ((command (if automatic command
11515                      (read-string "Command: " (cons command 0)))))
11516       (erase-buffer)
11517       (insert "$ " command "\n\n")
11518       (if gnus-view-pseudo-asynchronously
11519           (start-process "gnus-execute" (current-buffer) shell-file-name
11520                          shell-command-switch command)
11521         (call-process shell-file-name nil t nil
11522                       shell-command-switch command)))))
11523
11524 ;; Summary kill commands.
11525
11526 (defun gnus-summary-edit-global-kill (article)
11527   "Edit the \"global\" kill file."
11528   (interactive (list (gnus-summary-article-number)))
11529   (gnus-group-edit-global-kill article))
11530
11531 (defun gnus-summary-edit-local-kill ()
11532   "Edit a local kill file applied to the current newsgroup."
11533   (interactive)
11534   (setq gnus-current-headers (gnus-summary-article-header))
11535   (gnus-group-edit-local-kill
11536    (gnus-summary-article-number) gnus-newsgroup-name))
11537
11538 ;;; Header reading.
11539
11540 (defun gnus-read-header (id &optional header)
11541   "Read the headers of article ID and enter them into the Gnus system."
11542   (let ((group gnus-newsgroup-name)
11543         (gnus-override-method
11544          (or
11545           gnus-override-method
11546           (and (gnus-news-group-p gnus-newsgroup-name)
11547                (car (gnus-refer-article-methods)))))
11548         where)
11549     ;; First we check to see whether the header in question is already
11550     ;; fetched.
11551     (if (stringp id)
11552         ;; This is a Message-ID.
11553         (setq header (or header (gnus-id-to-header id)))
11554       ;; This is an article number.
11555       (setq header (or header (gnus-summary-article-header id))))
11556     (if (and header
11557              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11558         ;; We have found the header.
11559         header
11560       ;; We have to really fetch the header to this article.
11561       (save-excursion
11562         (set-buffer nntp-server-buffer)
11563         (when (setq where (gnus-request-head id group))
11564           (nnheader-fold-continuation-lines)
11565           (goto-char (point-max))
11566           (insert ".\n")
11567           (goto-char (point-min))
11568           (insert "211 ")
11569           (princ (cond
11570                   ((numberp id) id)
11571                   ((cdr where) (cdr where))
11572                   (header (mail-header-number header))
11573                   (t gnus-reffed-article-number))
11574                  (current-buffer))
11575           (insert " Article retrieved.\n"))
11576         (if (or (not where)
11577                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11578             ()                          ; Malformed head.
11579           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11580             (when (and (stringp id)
11581                        (not (string= (gnus-group-real-name group)
11582                                      (car where))))
11583               ;; If we fetched by Message-ID and the article came
11584               ;; from a different group, we fudge some bogus article
11585               ;; numbers for this article.
11586               (mail-header-set-number header gnus-reffed-article-number))
11587             (save-excursion
11588               (set-buffer gnus-summary-buffer)
11589               (decf gnus-reffed-article-number)
11590               (gnus-remove-header (mail-header-number header))
11591               (push header gnus-newsgroup-headers)
11592               (setq gnus-current-headers header)
11593               (push (mail-header-number header) gnus-newsgroup-limit)))
11594           header)))))
11595
11596 (defun gnus-remove-header (number)
11597   "Remove header NUMBER from `gnus-newsgroup-headers'."
11598   (if (and gnus-newsgroup-headers
11599            (= number (mail-header-number (car gnus-newsgroup-headers))))
11600       (pop gnus-newsgroup-headers)
11601     (let ((headers gnus-newsgroup-headers))
11602       (while (and (cdr headers)
11603                   (not (= number (mail-header-number (cadr headers)))))
11604         (pop headers))
11605       (when (cdr headers)
11606         (setcdr headers (cddr headers))))))
11607
11608 ;;;
11609 ;;; summary highlights
11610 ;;;
11611
11612 (defun gnus-highlight-selected-summary ()
11613   "Highlight selected article in summary buffer."
11614   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11615   (when gnus-summary-selected-face
11616     (save-excursion
11617       (let* ((beg (point-at-bol))
11618              (end (point-at-eol))
11619              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11620              (from (if (get-text-property beg gnus-mouse-face-prop)
11621                        beg
11622                      (or (next-single-property-change
11623                           beg gnus-mouse-face-prop nil end)
11624                          beg)))
11625              (to
11626               (if (= from end)
11627                   (- from 2)
11628                 (or (next-single-property-change
11629                      from gnus-mouse-face-prop nil end)
11630                     end))))
11631         ;; If no mouse-face prop on line we will have to = from = end,
11632         ;; so we highlight the entire line instead.
11633         (when (= (+ to 2) from)
11634           (setq from beg)
11635           (setq to end))
11636         (if gnus-newsgroup-selected-overlay
11637             ;; Move old overlay.
11638             (gnus-move-overlay
11639              gnus-newsgroup-selected-overlay from to (current-buffer))
11640           ;; Create new overlay.
11641           (gnus-overlay-put
11642            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11643            'face gnus-summary-selected-face))))))
11644
11645 (defvar gnus-summary-highlight-line-cached nil)
11646 (defvar gnus-summary-highlight-line-trigger nil)
11647
11648 (defun gnus-summary-highlight-line-0 ()
11649   (if (and (eq gnus-summary-highlight-line-trigger
11650                gnus-summary-highlight)
11651            gnus-summary-highlight-line-cached)
11652       gnus-summary-highlight-line-cached
11653     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11654           gnus-summary-highlight-line-cached
11655           (let* ((cond (list 'cond))
11656                  (c cond)
11657                  (list gnus-summary-highlight))
11658             (while list
11659               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11660                               nil))
11661               (setq c (cdr c)
11662                     list (cdr list)))
11663             (gnus-byte-compile (list 'lambda nil cond))))))
11664
11665 (defun gnus-summary-highlight-line ()
11666   "Highlight current line according to `gnus-summary-highlight'."
11667   (let* ((beg (point-at-bol))
11668          (article (or (gnus-summary-article-number) gnus-current-article))
11669          (score (or (cdr (assq article
11670                                gnus-newsgroup-scored))
11671                     gnus-summary-default-score 0))
11672          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11673          (inhibit-read-only t)
11674          (default gnus-summary-default-score)
11675          (default-high gnus-summary-default-high-score)
11676          (default-low gnus-summary-default-low-score)
11677          (uncached (and gnus-summary-use-undownloaded-faces
11678                         (memq article gnus-newsgroup-undownloaded)
11679                         (not (memq article gnus-newsgroup-cached)))))
11680     (let ((face (funcall (gnus-summary-highlight-line-0))))
11681       (unless (eq face (get-text-property beg 'face))
11682         (gnus-put-text-property-excluding-characters-with-faces
11683          beg (point-at-eol) 'face
11684          (setq face (if (boundp face) (symbol-value face) face)))
11685         (when gnus-summary-highlight-line-function
11686           (funcall gnus-summary-highlight-line-function article face))))))
11687
11688 (defun gnus-update-read-articles (group unread &optional compute)
11689   "Update the list of read articles in GROUP.
11690 UNREAD is a sorted list."
11691   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11692         (info (gnus-get-info group))
11693         (prev 1)
11694         read)
11695     (if (or (not info) (not active))
11696         ;; There is no info on this group if it was, in fact,
11697         ;; killed.  Gnus stores no information on killed groups, so
11698         ;; there's nothing to be done.
11699         ;; One could store the information somewhere temporarily,
11700         ;; perhaps...  Hmmm...
11701         ()
11702       ;; Remove any negative articles numbers.
11703       (while (and unread (< (car unread) 0))
11704         (setq unread (cdr unread)))
11705       ;; Remove any expired article numbers
11706       (while (and unread (< (car unread) (car active)))
11707         (setq unread (cdr unread)))
11708       ;; Compute the ranges of read articles by looking at the list of
11709       ;; unread articles.
11710       (while unread
11711         (when (/= (car unread) prev)
11712           (push (if (= prev (1- (car unread))) prev
11713                   (cons prev (1- (car unread))))
11714                 read))
11715         (setq prev (1+ (car unread)))
11716         (setq unread (cdr unread)))
11717       (when (<= prev (cdr active))
11718         (push (cons prev (cdr active)) read))
11719       (setq read (if (> (length read) 1) (nreverse read) read))
11720       (if compute
11721           read
11722         (save-excursion
11723           (let (setmarkundo)
11724             ;; Propagate the read marks to the backend.
11725             (when (gnus-check-backend-function 'request-set-mark group)
11726               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11727                     (add (gnus-remove-from-range read (gnus-info-read info))))
11728                 (when (or add del)
11729                   (unless (gnus-check-group group)
11730                     (error "Can't open server for %s" group))
11731                   (gnus-request-set-mark
11732                    group (delq nil (list (if add (list add 'add '(read)))
11733                                          (if del (list del 'del '(read))))))
11734                   (setq setmarkundo
11735                         `(gnus-request-set-mark
11736                           ,group
11737                           ',(delq nil (list
11738                                        (if del (list del 'add '(read)))
11739                                        (if add (list add 'del '(read))))))))))
11740             (set-buffer gnus-group-buffer)
11741             (gnus-undo-register
11742               `(progn
11743                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11744                  (gnus-info-set-read ',info ',(gnus-info-read info))
11745                  (gnus-get-unread-articles-in-group ',info
11746                                                     (gnus-active ,group))
11747                  (gnus-group-update-group ,group t)
11748                  ,setmarkundo))))
11749         ;; Enter this list into the group info.
11750         (gnus-info-set-read info read)
11751         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11752         (gnus-get-unread-articles-in-group info (gnus-active group))
11753         t))))
11754
11755 (defun gnus-offer-save-summaries ()
11756   "Offer to save all active summary buffers."
11757   (let (buffers)
11758     ;; Go through all buffers and find all summaries.
11759     (dolist (buffer (buffer-list))
11760       (when (and (setq buffer (buffer-name buffer))
11761                  (string-match "Summary" buffer)
11762                  (with-current-buffer buffer
11763                    ;; We check that this is, indeed, a summary buffer.
11764                    (and (eq major-mode 'gnus-summary-mode)
11765                         ;; Also make sure this isn't bogus.
11766                         gnus-newsgroup-prepared
11767                         ;; Also make sure that this isn't a
11768                         ;; dead summary buffer.
11769                         (not gnus-dead-summary-mode))))
11770         (push buffer buffers)))
11771     ;; Go through all these summary buffers and offer to save them.
11772     (when buffers
11773       (save-excursion
11774         (map-y-or-n-p
11775          "Update summary buffer %s? "
11776          (lambda (buf)
11777            (switch-to-buffer buf)
11778            (gnus-summary-exit))
11779          buffers)))))
11780
11781 (defun gnus-summary-setup-default-charset ()
11782   "Setup newsgroup default charset."
11783   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11784       (setq gnus-newsgroup-charset nil)
11785     (let* ((ignored-charsets
11786             (or gnus-newsgroup-ephemeral-ignored-charsets
11787                 (append
11788                  (and gnus-newsgroup-name
11789                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11790                  gnus-newsgroup-ignored-charsets))))
11791       (setq gnus-newsgroup-charset
11792             (or gnus-newsgroup-ephemeral-charset
11793                 (and gnus-newsgroup-name
11794                      (gnus-parameter-charset gnus-newsgroup-name))
11795                 gnus-default-charset))
11796       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11797            ignored-charsets))))
11798
11799 ;;;
11800 ;;; Mime Commands
11801 ;;;
11802
11803 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11804   "Display the current article buffer fully MIME-buttonized.
11805 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11806 treated as multipart/mixed."
11807   (interactive "P")
11808   (require 'gnus-art)
11809   (let ((gnus-unbuttonized-mime-types nil)
11810         (gnus-mime-display-multipart-as-mixed show-all-parts))
11811     (gnus-summary-show-article)))
11812
11813 (defun gnus-summary-repair-multipart (article)
11814   "Add a Content-Type header to a multipart article without one."
11815   (interactive (list (gnus-summary-article-number)))
11816   (gnus-with-article article
11817     (message-narrow-to-head)
11818     (message-remove-header "Mime-Version")
11819     (goto-char (point-max))
11820     (insert "Mime-Version: 1.0\n")
11821     (widen)
11822     (when (search-forward "\n--" nil t)
11823       (let ((separator (buffer-substring (point) (point-at-eol))))
11824         (message-narrow-to-head)
11825         (message-remove-header "Content-Type")
11826         (goto-char (point-max))
11827         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11828                         separator))
11829         (widen))))
11830   (let (gnus-mark-article-hook)
11831     (gnus-summary-select-article t t nil article)))
11832
11833 (defun gnus-summary-toggle-display-buttonized ()
11834   "Toggle the buttonizing of the article buffer."
11835   (interactive)
11836   (require 'gnus-art)
11837   (if (setq gnus-inhibit-mime-unbuttonizing
11838             (not gnus-inhibit-mime-unbuttonizing))
11839       (let ((gnus-unbuttonized-mime-types nil))
11840         (gnus-summary-show-article))
11841     (gnus-summary-show-article)))
11842
11843 ;;;
11844 ;;; Generic summary marking commands
11845 ;;;
11846
11847 (defvar gnus-summary-marking-alist
11848   '((read gnus-del-mark "d")
11849     (unread gnus-unread-mark "u")
11850     (ticked gnus-ticked-mark "!")
11851     (dormant gnus-dormant-mark "?")
11852     (expirable gnus-expirable-mark "e"))
11853   "An alist of names/marks/keystrokes.")
11854
11855 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11856 (defvar gnus-summary-mark-map)
11857
11858 (defun gnus-summary-make-all-marking-commands ()
11859   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11860   (dolist (elem gnus-summary-marking-alist)
11861     (apply 'gnus-summary-make-marking-command elem)))
11862
11863 (defun gnus-summary-make-marking-command (name mark keystroke)
11864   (let ((map (make-sparse-keymap)))
11865     (define-key gnus-summary-generic-mark-map keystroke map)
11866     (dolist (lway `((next "next" next nil "n")
11867                     (next-unread "next unread" next t "N")
11868                     (prev "previous" prev nil "p")
11869                     (prev-unread "previous unread" prev t "P")
11870                     (nomove "" nil nil ,keystroke)))
11871       (let ((func (gnus-summary-make-marking-command-1
11872                    mark (car lway) lway name)))
11873         (setq func (eval func))
11874         (define-key map (nth 4 lway) func)))))
11875
11876 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11877   `(defun ,(intern
11878             (format "gnus-summary-put-mark-as-%s%s"
11879                     name (if (eq way 'nomove)
11880                              ""
11881                            (concat "-" (symbol-name way)))))
11882      (n)
11883      ,(format
11884        "Mark the current article as %s%s.
11885 If N, the prefix, then repeat N times.
11886 If N is negative, move in reverse order.
11887 The difference between N and the actual number of articles marked is
11888 returned."
11889        name (cadr lway))
11890      (interactive "p")
11891      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11892
11893 (defun gnus-summary-generic-mark (n mark move unread)
11894   "Mark N articles with MARK."
11895   (unless (eq major-mode 'gnus-summary-mode)
11896     (error "This command can only be used in the summary buffer"))
11897   (gnus-summary-show-thread)
11898   (let ((nummove
11899          (cond
11900           ((eq move 'next) 1)
11901           ((eq move 'prev) -1)
11902           (t 0))))
11903     (if (zerop nummove)
11904         (setq n 1)
11905       (when (< n 0)
11906         (setq n (abs n)
11907               nummove (* -1 nummove))))
11908     (while (and (> n 0)
11909                 (gnus-summary-mark-article nil mark)
11910                 (zerop (gnus-summary-next-subject nummove unread t)))
11911       (setq n (1- n)))
11912     (when (/= 0 n)
11913       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11914     (gnus-summary-recenter)
11915     (gnus-summary-position-point)
11916     (gnus-set-mode-line 'summary)
11917     n))
11918
11919 (defun gnus-summary-insert-articles (articles)
11920   (when (setq articles
11921               (gnus-sorted-difference articles
11922                                       (mapcar (lambda (h)
11923                                                 (mail-header-number h))
11924                                               gnus-newsgroup-headers)))
11925     (setq gnus-newsgroup-headers
11926           (gnus-merge 'list
11927                       gnus-newsgroup-headers
11928                       (gnus-fetch-headers articles)
11929                       'gnus-article-sort-by-number))
11930     ;; Suppress duplicates?
11931     (when gnus-suppress-duplicates
11932       (gnus-dup-suppress-articles))
11933
11934     ;; We might want to build some more threads first.
11935     (when (and gnus-fetch-old-headers
11936                (eq gnus-headers-retrieved-by 'nov))
11937       (if (eq gnus-fetch-old-headers 'invisible)
11938           (gnus-build-all-threads)
11939         (gnus-build-old-threads)))
11940     ;; Let the Gnus agent mark articles as read.
11941     (when gnus-agent
11942       (gnus-agent-get-undownloaded-list))
11943     ;; Remove list identifiers from subject
11944     (when gnus-list-identifiers
11945       (gnus-summary-remove-list-identifiers))
11946     ;; First and last article in this newsgroup.
11947     (when gnus-newsgroup-headers
11948       (setq gnus-newsgroup-begin
11949             (mail-header-number (car gnus-newsgroup-headers))
11950             gnus-newsgroup-end
11951             (mail-header-number
11952              (gnus-last-element gnus-newsgroup-headers))))
11953     (when gnus-use-scoring
11954       (gnus-possibly-score-headers))))
11955
11956 (defun gnus-summary-insert-old-articles (&optional all)
11957   "Insert all old articles in this group.
11958 If ALL is non-nil, already read articles become readable.
11959 If ALL is a number, fetch this number of articles."
11960   (interactive "P")
11961   (prog1
11962       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11963             older len)
11964         (setq older
11965               ;; Some nntp servers lie about their active range.  When
11966               ;; this happens, the active range can be in the millions.
11967               ;; Use a compressed range to avoid creating a huge list.
11968               (gnus-range-difference (list gnus-newsgroup-active) old))
11969         (setq len (gnus-range-length older))
11970         (cond
11971          ((null older) nil)
11972          ((numberp all)
11973           (if (< all len)
11974               (let ((older-range (nreverse older)))
11975                 (setq older nil)
11976
11977                 (while (> all 0)
11978                   (let* ((r (pop older-range))
11979                          (min (if (numberp r) r (car r)))
11980                          (max (if (numberp r) r (cdr r))))
11981                     (while (and (<= min max)
11982                                 (> all 0))
11983                       (push max older)
11984                       (setq all (1- all)
11985                             max (1- max))))))
11986             (setq older (gnus-uncompress-range older))))
11987          (all
11988           (setq older (gnus-uncompress-range older)))
11989          (t
11990           (when (and (numberp gnus-large-newsgroup)
11991                    (> len gnus-large-newsgroup))
11992               (let* ((cursor-in-echo-area nil)
11993                      (initial (gnus-parameter-large-newsgroup-initial
11994                                gnus-newsgroup-name))
11995                      (input
11996                       (read-string
11997                        (format
11998                         "How many articles from %s (%s %d): "
11999                         (gnus-limit-string
12000                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12001                         (if initial "max" "default")
12002                         len)
12003                        (if initial
12004                            (cons (number-to-string initial)
12005                                  0)))))
12006                 (unless (string-match "^[ \t]*$" input)
12007                   (setq all (string-to-number input))
12008                   (if (< all len)
12009                       (let ((older-range (nreverse older)))
12010                         (setq older nil)
12011
12012                         (while (> all 0)
12013                           (let* ((r (pop older-range))
12014                                  (min (if (numberp r) r (car r)))
12015                                  (max (if (numberp r) r (cdr r))))
12016                             (while (and (<= min max)
12017                                         (> all 0))
12018                               (push max older)
12019                               (setq all (1- all)
12020                                     max (1- max))))))))))
12021           (setq older (gnus-uncompress-range older))))
12022         (if (not older)
12023             (message "No old news.")
12024           (gnus-summary-insert-articles older)
12025           (gnus-summary-limit (gnus-sorted-nunion old older))))
12026     (gnus-summary-position-point)))
12027
12028 (defun gnus-summary-insert-new-articles ()
12029   "Insert all new articles in this group."
12030   (interactive)
12031   (prog1
12032       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12033             (old-active gnus-newsgroup-active)
12034             (nnmail-fetched-sources (list t))
12035             i new)
12036         (setq gnus-newsgroup-active
12037               (gnus-activate-group gnus-newsgroup-name 'scan))
12038         (setq i (cdr gnus-newsgroup-active))
12039         (while (> i (cdr old-active))
12040           (push i new)
12041           (decf i))
12042         (if (not new)
12043             (message "No gnus is bad news")
12044           (gnus-summary-insert-articles new)
12045           (setq gnus-newsgroup-unreads
12046                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12047           (gnus-summary-limit (gnus-sorted-nunion old new))))
12048     (gnus-summary-position-point)))
12049
12050 (gnus-summary-make-all-marking-commands)
12051
12052 (gnus-ems-redefine)
12053
12054 (provide 'gnus-sum)
12055
12056 (run-hooks 'gnus-sum-load-hook)
12057
12058 ;; Local Variables:
12059 ;; coding: iso-8859-1
12060 ;; End:
12061
12062 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12063 ;;; gnus-sum.el ends here