1bb5b2286cf15f766be45c653429c82ff87e9cff
[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 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-map))
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 'mm-decode)
42 (require 'nnoo)
43
44 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
45 (autoload 'gnus-cache-write-active "gnus-cache")
46 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
47 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
48 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
49 (autoload 'mm-uu-dissect "mm-uu")
50 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
51   "Deuglify broken Outlook (Express) articles and redisplay."
52   t)
53 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
54 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
55 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
56
57 (defcustom gnus-kill-summary-on-exit t
58   "*If non-nil, kill the summary buffer when you exit from it.
59 If nil, the summary will become a \"*Dead Summary*\" buffer, and
60 it will be killed sometime later."
61   :group 'gnus-summary-exit
62   :type 'boolean)
63
64 (defcustom gnus-fetch-old-headers nil
65   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
66 If an unread article in the group refers to an older, already read (or
67 just marked as read) article, the old article will not normally be
68 displayed in the Summary buffer.  If this variable is t, Gnus
69 will attempt to grab the headers to the old articles, and thereby
70 build complete threads.  If it has the value `some', only enough
71 headers to connect otherwise loose threads will be displayed.  This
72 variable can also be a number.  In that case, no more than that number
73 of old headers will be fetched.  If it has the value `invisible', all
74 old headers will be fetched, but none will be displayed.
75
76 The server has to support NOV for any of this to work."
77   :group 'gnus-thread
78   :type '(choice (const :tag "off" nil)
79                  (const :tag "on" t)
80                  (const some)
81                  (const invisible)
82                  number
83                  (sexp :menu-tag "other" t)))
84
85 (defcustom gnus-refer-thread-limit 200
86   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
87 If t, fetch all the available old headers."
88   :group 'gnus-thread
89   :type '(choice number
90                  (sexp :menu-tag "other" t)))
91
92 (defcustom gnus-summary-make-false-root 'adopt
93   "*nil means that Gnus won't gather loose threads.
94 If the root of a thread has expired or been read in a previous
95 session, the information necessary to build a complete thread has been
96 lost.  Instead of having many small sub-threads from this original thread
97 scattered all over the summary buffer, Gnus can gather them.
98
99 If non-nil, Gnus will try to gather all loose sub-threads from an
100 original thread into one large thread.
101
102 If this variable is non-nil, it should be one of `none', `adopt',
103 `dummy' or `empty'.
104
105 If this variable is `none', Gnus will not make a false root, but just
106 present the sub-threads after another.
107 If this variable is `dummy', Gnus will create a dummy root that will
108 have all the sub-threads as children.
109 If this variable is `adopt', Gnus will make one of the \"children\"
110 the parent and mark all the step-children as such.
111 If this variable is `empty', the \"children\" are printed with empty
112 subject fields.  (Or rather, they will be printed with a string
113 given by the `gnus-summary-same-subject' variable.)"
114   :group 'gnus-thread
115   :type '(choice (const :tag "off" nil)
116                  (const none)
117                  (const dummy)
118                  (const adopt)
119                  (const empty)))
120
121 (defcustom gnus-summary-make-false-root-always nil
122   "Always make a false dummy root."
123   :version "22.1"
124   :group 'gnus-thread
125   :type 'boolean)
126
127 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
128   "*A regexp to match subjects to be excluded from loose thread gathering.
129 As loose thread gathering is done on subjects only, that means that
130 there can be many false gatherings performed.  By rooting out certain
131 common subjects, gathering might become saner."
132   :group 'gnus-thread
133   :type 'regexp)
134
135 (defcustom gnus-summary-gather-subject-limit nil
136   "*Maximum length of subject comparisons when gathering loose threads.
137 Use nil to compare full subjects.  Setting this variable to a low
138 number will help gather threads that have been corrupted by
139 newsreaders chopping off subject lines, but it might also mean that
140 unrelated articles that have subject that happen to begin with the
141 same few characters will be incorrectly gathered.
142
143 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
144 comparing subjects."
145   :group 'gnus-thread
146   :type '(choice (const :tag "off" nil)
147                  (const fuzzy)
148                  (sexp :menu-tag "on" t)))
149
150 (defcustom gnus-simplify-subject-functions nil
151   "List of functions taking a string argument that simplify subjects.
152 The functions are applied recursively.
153
154 Useful functions to put in this list include:
155 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
156 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
157   :group 'gnus-thread
158   :type '(repeat function))
159
160 (defcustom gnus-simplify-ignored-prefixes nil
161   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
162   :group 'gnus-thread
163   :type '(choice (const :tag "off" nil)
164                  regexp))
165
166 (defcustom gnus-build-sparse-threads nil
167   "*If non-nil, fill in the gaps in threads.
168 If `some', only fill in the gaps that are needed to tie loose threads
169 together.  If `more', fill in all leaf nodes that Gnus can find.  If
170 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
171   :group 'gnus-thread
172   :type '(choice (const :tag "off" nil)
173                  (const some)
174                  (const more)
175                  (sexp :menu-tag "all" t)))
176
177 (defcustom gnus-summary-thread-gathering-function
178   'gnus-gather-threads-by-subject
179   "*Function used for gathering loose threads.
180 There are two pre-defined functions: `gnus-gather-threads-by-subject',
181 which only takes Subjects into consideration; and
182 `gnus-gather-threads-by-references', which compared the References
183 headers of the articles to find matches."
184   :group 'gnus-thread
185   :type '(radio (function-item gnus-gather-threads-by-subject)
186                 (function-item gnus-gather-threads-by-references)
187                 (function :tag "other")))
188
189 (defcustom gnus-summary-same-subject ""
190   "*String indicating that the current article has the same subject as the previous.
191 This variable will only be used if the value of
192 `gnus-summary-make-false-root' is `empty'."
193   :group 'gnus-summary-format
194   :type 'string)
195
196 (defcustom gnus-summary-goto-unread t
197   "*If t, many commands will go to the next unread article.
198 This applies to marking commands as well as other commands that
199 \"naturally\" select the next article, like, for instance, `SPC' at
200 the end of an article.
201
202 If nil, the marking commands do NOT go to the next unread article
203 \(they go to the next article instead).  If `never', commands that
204 usually go to the next unread article, will go to the next article,
205 whether it is read or not."
206   :group 'gnus-summary-marks
207   :link '(custom-manual "(gnus)Setting Marks")
208   :type '(choice (const :tag "off" nil)
209                  (const never)
210                  (sexp :menu-tag "on" t)))
211
212 (defcustom gnus-summary-default-score 0
213   "*Default article score level.
214 All scores generated by the score files will be added to this score.
215 If this variable is nil, scoring will be disabled."
216   :group 'gnus-score-default
217   :type '(choice (const :tag "disable")
218                  integer))
219
220 (defcustom gnus-summary-default-high-score 0
221   "*Default threshold for a high scored article.
222 An article will be highlighted as high scored if its score is greater
223 than this score."
224   :version "22.1"
225   :group 'gnus-score-default
226   :type 'integer)
227
228 (defcustom gnus-summary-default-low-score 0
229   "*Default threshold for a low scored article.
230 An article will be highlighted as low scored if its score is smaller
231 than this score."
232   :version "22.1"
233   :group 'gnus-score-default
234   :type 'integer)
235
236 (defcustom gnus-summary-zcore-fuzz 0
237   "*Fuzziness factor for the zcore in the summary buffer.
238 Articles with scores closer than this to `gnus-summary-default-score'
239 will not be marked."
240   :group 'gnus-summary-format
241   :type 'integer)
242
243 (defcustom gnus-simplify-subject-fuzzy-regexp nil
244   "*Strings to be removed when doing fuzzy matches.
245 This can either be a regular expression or list of regular expressions
246 that will be removed from subject strings if fuzzy subject
247 simplification is selected."
248   :group 'gnus-thread
249   :type '(repeat regexp))
250
251 (defcustom gnus-show-threads t
252   "*If non-nil, display threads in summary mode."
253   :group 'gnus-thread
254   :type 'boolean)
255
256 (defcustom gnus-thread-hide-subtree nil
257   "*If non-nil, hide all threads initially.
258 This can be a predicate specifier which says which threads to hide.
259 If threads are hidden, you have to run the command
260 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
261 to expose hidden threads."
262   :group 'gnus-thread
263   :type '(radio (sexp :format "Non-nil\n"
264                       :match (lambda (widget value)
265                                (not (or (consp value) (functionp value))))
266                       :value t)
267                 (const nil)
268                 (sexp :tag "Predicate specifier")))
269
270 (defcustom gnus-thread-hide-killed t
271   "*If non-nil, hide killed threads automatically."
272   :group 'gnus-thread
273   :type 'boolean)
274
275 (defcustom gnus-thread-ignore-subject t
276   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
277 If nil, articles that have different subjects from their parents will
278 start separate threads."
279   :group 'gnus-thread
280   :type 'boolean)
281
282 (defcustom gnus-thread-operation-ignore-subject t
283   "*If non-nil, subjects will be ignored when doing thread commands.
284 This affects commands like `gnus-summary-kill-thread' and
285 `gnus-summary-lower-thread'.
286
287 If this variable is nil, articles in the same thread with different
288 subjects will not be included in the operation in question.  If this
289 variable is `fuzzy', only articles that have subjects that are fuzzily
290 equal will be included."
291   :group 'gnus-thread
292   :type '(choice (const :tag "off" nil)
293                  (const fuzzy)
294                  (sexp :tag "on" t)))
295
296 (defcustom gnus-thread-indent-level 4
297   "*Number that says how much each sub-thread should be indented."
298   :group 'gnus-thread
299   :type 'integer)
300
301 (defcustom gnus-auto-extend-newsgroup t
302   "*If non-nil, extend newsgroup forward and backward when requested."
303   :group 'gnus-summary-choose
304   :type 'boolean)
305
306 (defcustom gnus-auto-select-first t
307   "*If non-nil, select the article under point.
308 Which article this is is controlled by the `gnus-auto-select-subject'
309 variable.
310
311 If you want to prevent automatic selection of articles in some
312 newsgroups, set the variable to nil in `gnus-select-group-hook'."
313   :group 'gnus-group-select
314   :type '(choice (const :tag "none" nil)
315                  (sexp :menu-tag "first" t)))
316
317 (defcustom gnus-auto-select-subject 'unread
318   "*Says what subject to place under point when entering a group.
319
320 This variable can either be the symbols `first' (place point on the
321 first subject), `unread' (place point on the subject line of the first
322 unread article), `best' (place point on the subject line of the
323 higest-scored article), `unseen' (place point on the subject line of
324 the first unseen article), `unseen-or-unread' (place point on the subject
325 line of the first unseen article or, if all article have been seen, on the
326 subject line of the first unread article), or a function to be called to
327 place point on some subject line."
328   :version "22.1"
329   :group 'gnus-group-select
330   :type '(choice (const best)
331                  (const unread)
332                  (const first)
333                  (const unseen)
334                  (const unseen-or-unread)))
335
336 (defcustom gnus-auto-select-next t
337   "*If non-nil, offer to go to the next group from the end of the previous.
338 If the value is t and the next newsgroup is empty, Gnus will exit
339 summary mode and go back to group mode.  If the value is neither nil
340 nor t, Gnus will select the following unread newsgroup.  In
341 particular, if the value is the symbol `quietly', the next unread
342 newsgroup will be selected without any confirmation, and if it is
343 `almost-quietly', the next group will be selected without any
344 confirmation if you are located on the last article in the group.
345 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
346 will go to the next group without confirmation."
347   :group 'gnus-summary-maneuvering
348   :type '(choice (const :tag "off" nil)
349                  (const quietly)
350                  (const almost-quietly)
351                  (const slightly-quietly)
352                  (sexp :menu-tag "on" t)))
353
354 (defcustom gnus-auto-select-same nil
355   "*If non-nil, select the next article with the same subject.
356 If there are no more articles with the same subject, go to
357 the first unread article."
358   :group 'gnus-summary-maneuvering
359   :type 'boolean)
360
361 (defcustom gnus-auto-goto-ignores 'unfetched
362   "*Says how to handle unfetched articles when maneuvering.
363
364 This variable can either be the symbols nil (maneuver to any
365 article), `undownloaded' (maneuvering while unplugged ignores articles
366 that have not been fetched), `always-undownloaded' (maneuvering always
367 ignores articles that have not been fetched), `unfetched' (maneuvering
368 ignores articles whose headers have not been fetched).
369
370 NOTE: The list of unfetched articles will always be nil when plugged
371 and, when unplugged, a subset of the undownloaded article list."
372   :version "22.1"
373   :group 'gnus-summary-maneuvering
374   :type '(choice (const :tag "None" nil)
375                  (const :tag "Undownloaded when unplugged" undownloaded)
376                  (const :tag "Undownloaded" always-undownloaded)
377                  (const :tag "Unfetched" unfetched)))
378
379 (defcustom gnus-summary-check-current nil
380   "*If non-nil, consider the current article when moving.
381 The \"unread\" movement commands will stay on the same line if the
382 current article is unread."
383   :group 'gnus-summary-maneuvering
384   :type 'boolean)
385
386 (defcustom gnus-auto-center-summary 2
387   "*If non-nil, always center the current summary buffer.
388 In particular, if `vertical' do only vertical recentering.  If non-nil
389 and non-`vertical', do both horizontal and vertical recentering."
390   :group 'gnus-summary-maneuvering
391   :type '(choice (const :tag "none" nil)
392                  (const vertical)
393                  (integer :tag "height")
394                  (sexp :menu-tag "both" t)))
395
396 (defvar gnus-auto-center-group t
397   "*If non-nil, always center the group buffer.")
398
399 (defcustom gnus-show-all-headers nil
400   "*If non-nil, don't hide any headers."
401   :group 'gnus-article-hiding
402   :group 'gnus-article-headers
403   :type 'boolean)
404
405 (defcustom gnus-summary-ignore-duplicates nil
406   "*If non-nil, ignore articles with identical Message-ID headers."
407   :group 'gnus-summary
408   :type 'boolean)
409
410 (defcustom gnus-single-article-buffer t
411   "*If non-nil, display all articles in the same buffer.
412 If nil, each group will get its own article buffer."
413   :group 'gnus-article-various
414   :type 'boolean)
415
416 (defcustom gnus-break-pages t
417   "*If non-nil, do page breaking on articles.
418 The page delimiter is specified by the `gnus-page-delimiter'
419 variable."
420   :group 'gnus-article-various
421   :type 'boolean)
422
423 (defcustom gnus-move-split-methods nil
424   "*Variable used to suggest where articles are to be moved to.
425 It uses the same syntax as the `gnus-split-methods' variable.
426 However, whereas `gnus-split-methods' specifies file names as targets,
427 this variable specifies group names."
428   :group 'gnus-summary-mail
429   :type '(repeat (choice (list :value (fun) function)
430                          (cons :value ("" "") regexp (repeat string))
431                          (sexp :value nil))))
432
433 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
434   "Function used to compute default prefix for article move/copy/etc prompts.
435 The function should take one argument, a group name, and return a
436 string with the suggested prefix."
437   :group 'gnus-summary-mail
438   :type 'function)
439
440 ;; FIXME: Although the custom type is `character' for the following variables,
441 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
442
443 (defcustom gnus-unread-mark ?           ;Whitespace
444   "*Mark used for unread articles."
445   :group 'gnus-summary-marks
446   :type 'character)
447
448 (defcustom gnus-ticked-mark ?!
449   "*Mark used for ticked articles."
450   :group 'gnus-summary-marks
451   :type 'character)
452
453 (defcustom gnus-dormant-mark ??
454   "*Mark used for dormant articles."
455   :group 'gnus-summary-marks
456   :type 'character)
457
458 (defcustom gnus-del-mark ?r
459   "*Mark used for del'd articles."
460   :group 'gnus-summary-marks
461   :type 'character)
462
463 (defcustom gnus-read-mark ?R
464   "*Mark used for read articles."
465   :group 'gnus-summary-marks
466   :type 'character)
467
468 (defcustom gnus-expirable-mark ?E
469   "*Mark used for expirable articles."
470   :group 'gnus-summary-marks
471   :type 'character)
472
473 (defcustom gnus-killed-mark ?K
474   "*Mark used for killed articles."
475   :group 'gnus-summary-marks
476   :type 'character)
477
478 (defcustom gnus-spam-mark ?$
479   "*Mark used for spam articles."
480   :version "22.1"
481   :group 'gnus-summary-marks
482   :type 'character)
483
484 (defcustom gnus-souped-mark ?F
485   "*Mark used for souped articles."
486   :group 'gnus-summary-marks
487   :type 'character)
488
489 (defcustom gnus-kill-file-mark ?X
490   "*Mark used for articles killed by kill files."
491   :group 'gnus-summary-marks
492   :type 'character)
493
494 (defcustom gnus-low-score-mark ?Y
495   "*Mark used for articles with a low score."
496   :group 'gnus-summary-marks
497   :type 'character)
498
499 (defcustom gnus-catchup-mark ?C
500   "*Mark used for articles that are caught up."
501   :group 'gnus-summary-marks
502   :type 'character)
503
504 (defcustom gnus-replied-mark ?A
505   "*Mark used for articles that have been replied to."
506   :group 'gnus-summary-marks
507   :type 'character)
508
509 (defcustom gnus-forwarded-mark ?F
510   "*Mark used for articles that have been forwarded."
511   :version "22.1"
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-recent-mark ?N
516   "*Mark used for articles that are recent."
517   :version "22.1"
518   :group 'gnus-summary-marks
519   :type 'character)
520
521 (defcustom gnus-cached-mark ?*
522   "*Mark used for articles that are in the cache."
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-saved-mark ?S
527   "*Mark used for articles that have been saved."
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-unseen-mark ?.
532   "*Mark used for articles that haven't been seen."
533   :version "22.1"
534   :group 'gnus-summary-marks
535   :type 'character)
536
537 (defcustom gnus-no-mark ?               ;Whitespace
538   "*Mark used for articles that have no other secondary mark."
539   :version "22.1"
540   :group 'gnus-summary-marks
541   :type 'character)
542
543 (defcustom gnus-ancient-mark ?O
544   "*Mark used for ancient articles."
545   :group 'gnus-summary-marks
546   :type 'character)
547
548 (defcustom gnus-sparse-mark ?Q
549   "*Mark used for sparsely reffed articles."
550   :group 'gnus-summary-marks
551   :type 'character)
552
553 (defcustom gnus-canceled-mark ?G
554   "*Mark used for canceled articles."
555   :group 'gnus-summary-marks
556   :type 'character)
557
558 (defcustom gnus-duplicate-mark ?M
559   "*Mark used for duplicate articles."
560   :group 'gnus-summary-marks
561   :type 'character)
562
563 (defcustom gnus-undownloaded-mark ?-
564   "*Mark used for articles that weren't downloaded."
565   :version "22.1"
566   :group 'gnus-summary-marks
567   :type 'character)
568
569 (defcustom gnus-downloaded-mark ?+
570   "*Mark used for articles that were downloaded."
571   :group 'gnus-summary-marks
572   :type 'character)
573
574 (defcustom gnus-downloadable-mark ?%
575   "*Mark used for articles that are to be downloaded."
576   :group 'gnus-summary-marks
577   :type 'character)
578
579 (defcustom gnus-unsendable-mark ?=
580   "*Mark used for articles that won't be sent."
581   :group 'gnus-summary-marks
582   :type 'character)
583
584 (defcustom gnus-score-over-mark ?+
585   "*Score mark used for articles with high scores."
586   :group 'gnus-summary-marks
587   :type 'character)
588
589 (defcustom gnus-score-below-mark ?-
590   "*Score mark used for articles with low scores."
591   :group 'gnus-summary-marks
592   :type 'character)
593
594 (defcustom gnus-empty-thread-mark ?     ;Whitespace
595   "*There is no thread under the article."
596   :group 'gnus-summary-marks
597   :type 'character)
598
599 (defcustom gnus-not-empty-thread-mark ?=
600   "*There is a thread under the article."
601   :group 'gnus-summary-marks
602   :type 'character)
603
604 (defcustom gnus-view-pseudo-asynchronously nil
605   "*If non-nil, Gnus will view pseudo-articles asynchronously."
606   :group 'gnus-extract-view
607   :type 'boolean)
608
609 (defcustom gnus-auto-expirable-marks
610   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
611         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
612         gnus-souped-mark gnus-duplicate-mark)
613   "*The list of marks converted into expiration if a group is auto-expirable."
614   :version "21.1"
615   :group 'gnus-summary
616   :type '(repeat character))
617
618 (defcustom gnus-inhibit-user-auto-expire t
619   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
620   :version "21.1"
621   :group 'gnus-summary
622   :type 'boolean)
623
624 (defcustom gnus-view-pseudos nil
625   "*If `automatic', pseudo-articles will be viewed automatically.
626 If `not-confirm', pseudos will be viewed automatically, and the user
627 will not be asked to confirm the command."
628   :group 'gnus-extract-view
629   :type '(choice (const :tag "off" nil)
630                  (const automatic)
631                  (const not-confirm)))
632
633 (defcustom gnus-view-pseudos-separately t
634   "*If non-nil, one pseudo-article will be created for each file to be viewed.
635 If nil, all files that use the same viewing command will be given as a
636 list of parameters to that command."
637   :group 'gnus-extract-view
638   :type 'boolean)
639
640 (defcustom gnus-insert-pseudo-articles t
641   "*If non-nil, insert pseudo-articles when decoding articles."
642   :group 'gnus-extract-view
643   :type 'boolean)
644
645 (defcustom gnus-summary-dummy-line-format
646   "   %(:                             :%) %S\n"
647   "*The format specification for the dummy roots in the summary buffer.
648 It works along the same lines as a normal formatting string,
649 with some simple extensions.
650
651 %S  The subject
652
653 General format specifiers can also be used.
654 See `(gnus)Formatting Variables'."
655   :link '(custom-manual "(gnus)Formatting Variables")
656   :group 'gnus-threading
657   :type 'string)
658
659 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
660   "*The format specification for the summary mode line.
661 It works along the same lines as a normal formatting string,
662 with some simple extensions:
663
664 %G  Group name
665 %p  Unprefixed group name
666 %A  Current article number
667 %z  Current article score
668 %V  Gnus version
669 %U  Number of unread articles in the group
670 %e  Number of unselected articles in the group
671 %Z  A string with unread/unselected article counts
672 %g  Shortish group name
673 %S  Subject of the current article
674 %u  User-defined spec
675 %s  Current score file name
676 %d  Number of dormant articles
677 %r  Number of articles that have been marked as read in this session
678 %E  Number of articles expunged by the score files"
679   :group 'gnus-summary-format
680   :type 'string)
681
682 (defcustom gnus-list-identifiers nil
683   "Regexp that matches list identifiers to be removed from subject.
684 This can also be a list of regexps."
685   :version "21.1"
686   :group 'gnus-summary-format
687   :group 'gnus-article-hiding
688   :type '(choice (const :tag "none" nil)
689                  (regexp :value ".*")
690                  (repeat :value (".*") regexp)))
691
692 (defcustom gnus-summary-mark-below 0
693   "*Mark all articles with a score below this variable as read.
694 This variable is local to each summary buffer and usually set by the
695 score file."
696   :group 'gnus-score-default
697   :type 'integer)
698
699 (defun gnus-widget-reversible-match (widget value)
700   "Ignoring WIDGET, convert VALUE to internal form.
701 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
702   ;; (debug value)
703   (or (symbolp value)
704       (and (listp value)
705            (eq (length value) 2)
706            (eq (nth 0 value) 'not)
707            (symbolp (nth 1 value)))))
708
709 (defun gnus-widget-reversible-to-internal (widget value)
710   "Ignoring WIDGET, convert VALUE to internal form.
711 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
712 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
713   ;; (debug value)
714   (if (atom value)
715       (list value nil)
716     (list (nth 1 value) t)))
717
718 (defun gnus-widget-reversible-to-external (widget value)
719   "Ignoring WIDGET, convert VALUE to external form.
720 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
721 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
722   ;; (debug value)
723   (if (nth 1 value)
724       (list 'not (nth 0 value))
725     (nth 0 value)))
726
727 (define-widget 'gnus-widget-reversible 'group
728   "A `group' that convert values."
729   :match 'gnus-widget-reversible-match
730   :value-to-internal 'gnus-widget-reversible-to-internal
731   :value-to-external 'gnus-widget-reversible-to-external)
732
733 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
734   "*List of functions used for sorting articles in the summary buffer.
735
736 Each function takes two articles and returns non-nil if the first
737 article should be sorted before the other.  If you use more than one
738 function, the primary sort function should be the last.  You should
739 probably always include `gnus-article-sort-by-number' in the list of
740 sorting functions -- preferably first.  Also note that sorting by date
741 is often much slower than sorting by number, and the sorting order is
742 very similar.  (Sorting by date means sorting by the time the message
743 was sent, sorting by number means sorting by arrival time.)
744
745 Each item can also be a list `(not F)' where F is a function;
746 this reverses the sort order.
747
748 Ready-made functions include `gnus-article-sort-by-number',
749 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
750 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
751 and `gnus-article-sort-by-score'.
752
753 When threading is turned on, the variable `gnus-thread-sort-functions'
754 controls how articles are sorted."
755   :group 'gnus-summary-sort
756   :type '(repeat (gnus-widget-reversible
757                   (choice (function-item gnus-article-sort-by-number)
758                           (function-item gnus-article-sort-by-author)
759                           (function-item gnus-article-sort-by-subject)
760                           (function-item gnus-article-sort-by-date)
761                           (function-item gnus-article-sort-by-score)
762                           (function-item gnus-article-sort-by-random)
763                           (function :tag "other"))
764                   (boolean :tag "Reverse order"))))
765
766
767 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
768   "*List of functions used for sorting threads in the summary buffer.
769 By default, threads are sorted by article number.
770
771 Each function takes two threads and returns non-nil if the first
772 thread should be sorted before the other.  If you use more than one
773 function, the primary sort function should be the last.  You should
774 probably always include `gnus-thread-sort-by-number' in the list of
775 sorting functions -- preferably first.  Also note that sorting by date
776 is often much slower than sorting by number, and the sorting order is
777 very similar.  (Sorting by date means sorting by the time the message
778 was sent, sorting by number means sorting by arrival time.)
779
780 Each list item can also be a list `(not F)' where F is a
781 function; this specifies reversed sort order.
782
783 Ready-made functions include `gnus-thread-sort-by-number',
784 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
785 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
786 `gnus-thread-sort-by-most-recent-number',
787 `gnus-thread-sort-by-most-recent-date',
788 `gnus-thread-sort-by-random', and
789 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
790
791 When threading is turned off, the variable
792 `gnus-article-sort-functions' controls how articles are sorted."
793   :group 'gnus-summary-sort
794   :type '(repeat 
795           (gnus-widget-reversible
796            (choice (function-item gnus-thread-sort-by-number)
797                    (function-item gnus-thread-sort-by-author)
798                    (function-item gnus-thread-sort-by-subject)
799                    (function-item gnus-thread-sort-by-date)
800                    (function-item gnus-thread-sort-by-score)
801                    (function-item gnus-thread-sort-by-most-recent-number)
802                    (function-item gnus-thread-sort-by-most-recent-date)
803                    (function-item gnus-thread-sort-by-random)
804                    (function-item gnus-thread-sort-by-total-score)
805                    (function :tag "other"))
806            (boolean :tag "Reverse order"))))
807
808 (defcustom gnus-thread-score-function '+
809   "*Function used for calculating the total score of a thread.
810
811 The function is called with the scores of the article and each
812 subthread and should then return the score of the thread.
813
814 Some functions you can use are `+', `max', or `min'."
815   :group 'gnus-summary-sort
816   :type 'function)
817
818 (defcustom gnus-summary-expunge-below nil
819   "All articles that have a score less than this variable will be expunged.
820 This variable is local to the summary buffers."
821   :group 'gnus-score-default
822   :type '(choice (const :tag "off" nil)
823                  integer))
824
825 (defcustom gnus-thread-expunge-below nil
826   "All threads that have a total score less than this variable will be expunged.
827 See `gnus-thread-score-function' for en explanation of what a
828 \"thread score\" is.
829
830 This variable is local to the summary buffers."
831   :group 'gnus-threading
832   :group 'gnus-score-default
833   :type '(choice (const :tag "off" nil)
834                  integer))
835
836 (defcustom gnus-summary-mode-hook nil
837   "*A hook for Gnus summary mode.
838 This hook is run before any variables are set in the summary buffer."
839   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
840   :group 'gnus-summary-various
841   :type 'hook)
842
843 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
844 (when (featurep 'xemacs)
845   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
846   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
847   (add-hook 'gnus-summary-mode-hook
848             'gnus-xmas-switch-horizontal-scrollbar-off))
849
850 (defcustom gnus-summary-menu-hook nil
851   "*Hook run after the creation of the summary mode menu."
852   :group 'gnus-summary-visual
853   :type 'hook)
854
855 (defcustom gnus-summary-exit-hook nil
856   "*A hook called on exit from the summary buffer.
857 It will be called with point in the group buffer."
858   :group 'gnus-summary-exit
859   :type 'hook)
860
861 (defcustom gnus-summary-prepare-hook nil
862   "*A hook called after the summary buffer has been generated.
863 If you want to modify the summary buffer, you can use this hook."
864   :group 'gnus-summary-various
865   :type 'hook)
866
867 (defcustom gnus-summary-prepared-hook nil
868   "*A hook called as the last thing after the summary buffer has been generated."
869   :group 'gnus-summary-various
870   :type 'hook)
871
872 (defcustom gnus-summary-generate-hook nil
873   "*A hook run just before generating the summary buffer.
874 This hook is commonly used to customize threading variables and the
875 like."
876   :group 'gnus-summary-various
877   :type 'hook)
878
879 (defcustom gnus-select-group-hook nil
880   "*A hook called when a newsgroup is selected.
881
882 If you'd like to simplify subjects like the
883 `gnus-summary-next-same-subject' command does, you can use the
884 following hook:
885
886  (add-hook gnus-select-group-hook
887            (lambda ()
888              (mapcar (lambda (header)
889                        (mail-header-set-subject
890                         header
891                         (gnus-simplify-subject
892                          (mail-header-subject header) 're-only)))
893                      gnus-newsgroup-headers)))"
894   :group 'gnus-group-select
895   :type 'hook)
896
897 (defcustom gnus-select-article-hook nil
898   "*A hook called when an article is selected."
899   :group 'gnus-summary-choose
900   :options '(gnus-agent-fetch-selected-article)
901   :type 'hook)
902
903 (defcustom gnus-visual-mark-article-hook
904   (list 'gnus-highlight-selected-summary)
905   "*Hook run after selecting an article in the summary buffer.
906 It is meant to be used for highlighting the article in some way.  It
907 is not run if `gnus-visual' is nil."
908   :group 'gnus-summary-visual
909   :type 'hook)
910
911 (defcustom gnus-parse-headers-hook nil
912   "*A hook called before parsing the headers."
913   :group 'gnus-various
914   :type 'hook)
915
916 (defcustom gnus-exit-group-hook nil
917   "*A hook called when exiting summary mode.
918 This hook is not called from the non-updating exit commands like `Q'."
919   :group 'gnus-various
920   :type 'hook)
921
922 (defcustom gnus-summary-update-hook
923   (list 'gnus-summary-highlight-line)
924   "*A hook called when a summary line is changed.
925 The hook will not be called if `gnus-visual' is nil.
926
927 The default function `gnus-summary-highlight-line' will
928 highlight the line according to the `gnus-summary-highlight'
929 variable."
930   :group 'gnus-summary-visual
931   :type 'hook)
932
933 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
934   "*A hook called when an article is selected for the first time.
935 The hook is intended to mark an article as read (or unread)
936 automatically when it is selected."
937   :group 'gnus-summary-choose
938   :type 'hook)
939
940 (defcustom gnus-group-no-more-groups-hook nil
941   "*A hook run when returning to group mode having no more (unread) groups."
942   :group 'gnus-group-select
943   :type 'hook)
944
945 (defcustom gnus-ps-print-hook nil
946   "*A hook run before ps-printing something from Gnus."
947   :group 'gnus-summary
948   :type 'hook)
949
950 (defcustom gnus-summary-article-move-hook nil
951   "*A hook called after an article is moved, copied, respooled, or crossposted."
952   :version "22.1"
953   :group 'gnus-summary
954   :type 'hook)
955
956 (defcustom gnus-summary-article-delete-hook nil
957   "*A hook called after an article is deleted."
958   :version "22.1"
959   :group 'gnus-summary
960   :type 'hook)
961
962 (defcustom gnus-summary-article-expire-hook nil
963   "*A hook called after an article is expired."
964   :version "22.1"
965   :group 'gnus-summary
966   :type 'hook)
967
968 (defcustom gnus-summary-display-arrow
969   (and (fboundp 'display-graphic-p)
970        (display-graphic-p))
971   "*If non-nil, display an arrow highlighting the current article."
972   :version "22.1"
973   :group 'gnus-summary
974   :type 'boolean)
975
976 (defcustom gnus-summary-selected-face 'gnus-summary-selected
977   "Face used for highlighting the current article in the summary buffer."
978   :group 'gnus-summary-visual
979   :type 'face)
980
981 (defvar gnus-tmp-downloaded nil)
982
983 (defcustom gnus-summary-highlight
984   '(((eq mark gnus-canceled-mark)
985      . gnus-summary-cancelled)
986     ((and uncached (> score default-high))
987      . gnus-summary-high-undownloaded)
988     ((and uncached (< score default-low))
989      . gnus-summary-low-undownloaded)
990     (uncached
991      . gnus-summary-normal-undownloaded)
992     ((and (> score default-high)
993           (or (eq mark gnus-dormant-mark)
994               (eq mark gnus-ticked-mark)))
995      . gnus-summary-high-ticked)
996     ((and (< score default-low)
997           (or (eq mark gnus-dormant-mark)
998               (eq mark gnus-ticked-mark)))
999      . gnus-summary-low-ticked)
1000     ((or (eq mark gnus-dormant-mark)
1001          (eq mark gnus-ticked-mark))
1002      . gnus-summary-normal-ticked)
1003     ((and (> score default-high) (eq mark gnus-ancient-mark))
1004      . gnus-summary-high-ancient)
1005     ((and (< score default-low) (eq mark gnus-ancient-mark))
1006      . gnus-summary-low-ancient)
1007     ((eq mark gnus-ancient-mark)
1008      . gnus-summary-normal-ancient)
1009     ((and (> score default-high) (eq mark gnus-unread-mark))
1010      . gnus-summary-high-unread)
1011     ((and (< score default-low) (eq mark gnus-unread-mark))
1012      . gnus-summary-low-unread)
1013     ((eq mark gnus-unread-mark)
1014      . gnus-summary-normal-unread)
1015     ((> score default-high)
1016      . gnus-summary-high-read)
1017     ((< score default-low)
1018      . gnus-summary-low-read)
1019     (t
1020      . gnus-summary-normal-read))
1021   "*Controls the highlighting of summary buffer lines.
1022
1023 A list of (FORM . FACE) pairs.  When deciding how a a particular
1024 summary line should be displayed, each form is evaluated.  The content
1025 of the face field after the first true form is used.  You can change
1026 how those summary lines are displayed, by editing the face field.
1027
1028 You can use the following variables in the FORM field.
1029
1030 score:        The article's score
1031 default:      The default article score.
1032 default-high: The default score for high scored articles.
1033 default-low:  The default score for low scored articles.
1034 below:        The score below which articles are automatically marked as read.
1035 mark:         The article's mark.
1036 uncached:     Non-nil if the article is uncached."
1037   :group 'gnus-summary-visual
1038   :type '(repeat (cons (sexp :tag "Form" nil)
1039                        face)))
1040
1041 (defcustom gnus-alter-header-function nil
1042   "Function called to allow alteration of article header structures.
1043 The function is called with one parameter, the article header vector,
1044 which it may alter in any way."
1045   :type '(choice (const :tag "None" nil)
1046                  function)
1047   :group 'gnus-summary)
1048
1049 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1050   "Variable that says which function should be used to decode a string with encoded words.")
1051
1052 (defcustom gnus-extra-headers '(To Newsgroups)
1053   "*Extra headers to parse."
1054   :version "21.1"
1055   :group 'gnus-summary
1056   :type '(repeat symbol))
1057
1058 (defcustom gnus-ignored-from-addresses
1059   (and user-mail-address (regexp-quote user-mail-address))
1060   "*Regexp of From headers that may be suppressed in favor of To headers."
1061   :version "21.1"
1062   :group 'gnus-summary
1063   :type 'regexp)
1064
1065 (defcustom gnus-summary-to-prefix "-> "
1066   "*String prefixed to the To field in the summary line when
1067 using `gnus-ignored-from-addresses'."
1068   :version "22.1"
1069   :group 'gnus-summary
1070   :type 'string)
1071
1072 (defcustom gnus-summary-newsgroup-prefix "=> "
1073   "*String prefixed to the Newsgroup field in the summary
1074 line when using `gnus-ignored-from-addresses'."
1075   :version "22.1"
1076   :group 'gnus-summary
1077   :type 'string)
1078
1079 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1080   "List of charsets that should be ignored.
1081 When these charsets are used in the \"charset\" parameter, the
1082 default charset will be used instead."
1083   :version "21.1"
1084   :type '(repeat symbol)
1085   :group 'gnus-charset)
1086
1087 (gnus-define-group-parameter
1088  ignored-charsets
1089  :type list
1090  :function-document
1091  "Return the ignored charsets of GROUP."
1092  :variable gnus-group-ignored-charsets-alist
1093  :variable-default
1094  '(("alt\\.chinese\\.text" iso-8859-1))
1095  :variable-document
1096  "Alist of regexps (to match group names) and charsets that should be ignored.
1097 When these charsets are used in the \"charset\" parameter, the
1098 default charset will be used instead."
1099  :variable-group gnus-charset
1100  :variable-type '(repeat (cons (regexp :tag "Group")
1101                                (repeat symbol)))
1102  :parameter-type '(choice :tag "Ignored charsets"
1103                           :value nil
1104                           (repeat (symbol)))
1105  :parameter-document       "\
1106 List of charsets that should be ignored.
1107
1108 When these charsets are used in the \"charset\" parameter, the
1109 default charset will be used instead.")
1110
1111 (defcustom gnus-group-highlight-words-alist nil
1112   "Alist of group regexps and highlight regexps.
1113 This variable uses the same syntax as `gnus-emphasis-alist'."
1114   :version "21.1"
1115   :type '(repeat (cons (regexp :tag "Group")
1116                        (repeat (list (regexp :tag "Highlight regexp")
1117                                      (number :tag "Group for entire word" 0)
1118                                      (number :tag "Group for displayed part" 0)
1119                                      (symbol :tag "Face"
1120                                              gnus-emphasis-highlight-words)))))
1121   :group 'gnus-summary-visual)
1122
1123 (defcustom gnus-summary-show-article-charset-alist
1124   nil
1125   "Alist of number and charset.
1126 The article will be shown with the charset corresponding to the
1127 numbered argument.
1128 For example: ((1 . cn-gb-2312) (2 . big5))."
1129   :version "21.1"
1130   :type '(repeat (cons (number :tag "Argument" 1)
1131                        (symbol :tag "Charset")))
1132   :group 'gnus-charset)
1133
1134 (defcustom gnus-preserve-marks t
1135   "Whether marks are preserved when moving, copying and respooling messages."
1136   :version "21.1"
1137   :type 'boolean
1138   :group 'gnus-summary-marks)
1139
1140 (defcustom gnus-alter-articles-to-read-function nil
1141   "Function to be called to alter the list of articles to be selected."
1142   :type '(choice (const nil) function)
1143   :group 'gnus-summary)
1144
1145 (defcustom gnus-orphan-score nil
1146   "*All orphans get this score added.  Set in the score file."
1147   :group 'gnus-score-default
1148   :type '(choice (const nil)
1149                  integer))
1150
1151 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1152   "*A regexp to match MIME parts when saving multiple parts of a
1153 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1154 This regexp will be used by default when prompting the user for which
1155 type of files to save."
1156   :group 'gnus-summary
1157   :type 'regexp)
1158
1159 (defcustom gnus-read-all-available-headers nil
1160   "Whether Gnus should parse all headers made available to it.
1161 This is mostly relevant for slow back ends where the user may
1162 wish to widen the summary buffer to include all headers
1163 that were fetched.  Say, for nnultimate groups."
1164   :version "22.1"
1165   :group 'gnus-summary
1166   :type '(choice boolean regexp))
1167
1168 (defcustom gnus-summary-muttprint-program "muttprint"
1169   "Command (and optional arguments) used to run Muttprint."
1170   :version "22.1"
1171   :group 'gnus-summary
1172   :type 'string)
1173
1174 (defcustom gnus-article-loose-mime t
1175   "If non-nil, don't require MIME-Version header.
1176 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1177 supply the MIME-Version header or deliberately strip it from the mail.
1178 If non-nil (the default), Gnus will treat some articles as MIME
1179 even if the MIME-Version header is missing."
1180   :version "22.1"
1181   :type 'boolean
1182   :group 'gnus-article-mime)
1183
1184 (defcustom gnus-article-emulate-mime t
1185   "If non-nil, use MIME emulation for uuencode and the like.
1186 This means that Gnus will search message bodies for text that look
1187 like uuencoded bits, yEncoded bits, and so on, and present that using
1188 the normal Gnus MIME machinery."
1189   :version "22.1"
1190   :type 'boolean
1191   :group 'gnus-article-mime)
1192
1193 ;;; Internal variables
1194
1195 (defvar gnus-summary-display-cache nil)
1196 (defvar gnus-article-mime-handles nil)
1197 (defvar gnus-article-decoded-p nil)
1198 (defvar gnus-article-charset nil)
1199 (defvar gnus-article-ignored-charsets nil)
1200 (defvar gnus-scores-exclude-files nil)
1201 (defvar gnus-page-broken nil)
1202
1203 (defvar gnus-original-article nil)
1204 (defvar gnus-article-internal-prepare-hook nil)
1205 (defvar gnus-newsgroup-process-stack nil)
1206
1207 (defvar gnus-thread-indent-array nil)
1208 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1209 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1210   "Function called to sort the articles within a thread after it has been gathered together.")
1211
1212 (defvar gnus-summary-save-parts-type-history nil)
1213 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1214
1215 ;; Avoid highlighting in kill files.
1216 (defvar gnus-summary-inhibit-highlight nil)
1217 (defvar gnus-newsgroup-selected-overlay nil)
1218 (defvar gnus-inhibit-limiting nil)
1219 (defvar gnus-newsgroup-adaptive-score-file nil)
1220 (defvar gnus-current-score-file nil)
1221 (defvar gnus-current-move-group nil)
1222 (defvar gnus-current-copy-group nil)
1223 (defvar gnus-current-crosspost-group nil)
1224 (defvar gnus-newsgroup-display nil)
1225
1226 (defvar gnus-newsgroup-dependencies nil)
1227 (defvar gnus-newsgroup-adaptive nil)
1228 (defvar gnus-summary-display-article-function nil)
1229 (defvar gnus-summary-highlight-line-function nil
1230   "Function called after highlighting a summary line.")
1231
1232 (defvar gnus-summary-line-format-alist
1233   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1234     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1235     (?s gnus-tmp-subject-or-nil ?s)
1236     (?n gnus-tmp-name ?s)
1237     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1238         ?s)
1239     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1240             gnus-tmp-from) ?s)
1241     (?F gnus-tmp-from ?s)
1242     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1243     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1244     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1245     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1246     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1247     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1248     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1249     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1250     (?L gnus-tmp-lines ?s)
1251     (?O gnus-tmp-downloaded ?c)
1252     (?I gnus-tmp-indentation ?s)
1253     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1254     (?R gnus-tmp-replied ?c)
1255     (?\[ gnus-tmp-opening-bracket ?c)
1256     (?\] gnus-tmp-closing-bracket ?c)
1257     (?\> (make-string gnus-tmp-level ? ) ?s)
1258     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1259     (?i gnus-tmp-score ?d)
1260     (?z gnus-tmp-score-char ?c)
1261     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1262     (?U gnus-tmp-unread ?c)
1263     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1264         ?s)
1265     (?t (gnus-summary-number-of-articles-in-thread
1266          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1267         ?d)
1268     (?e (gnus-summary-number-of-articles-in-thread
1269          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1270         ?c)
1271     (?u gnus-tmp-user-defined ?s)
1272     (?P (gnus-pick-line-number) ?d)
1273     (?B gnus-tmp-thread-tree-header-string ?s)
1274     (user-date (gnus-user-date
1275                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1276   "An alist of format specifications that can appear in summary lines.
1277 These are paired with what variables they correspond with, along with
1278 the type of the variable (string, integer, character, etc).")
1279
1280 (defvar gnus-summary-dummy-line-format-alist
1281   `((?S gnus-tmp-subject ?s)
1282     (?N gnus-tmp-number ?d)
1283     (?u gnus-tmp-user-defined ?s)))
1284
1285 (defvar gnus-summary-mode-line-format-alist
1286   `((?G gnus-tmp-group-name ?s)
1287     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1288     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1289     (?A gnus-tmp-article-number ?d)
1290     (?Z gnus-tmp-unread-and-unselected ?s)
1291     (?V gnus-version ?s)
1292     (?U gnus-tmp-unread-and-unticked ?d)
1293     (?S gnus-tmp-subject ?s)
1294     (?e gnus-tmp-unselected ?d)
1295     (?u gnus-tmp-user-defined ?s)
1296     (?d (length gnus-newsgroup-dormant) ?d)
1297     (?t (length gnus-newsgroup-marked) ?d)
1298     (?h (length gnus-newsgroup-spam-marked) ?d)
1299     (?r (length gnus-newsgroup-reads) ?d)
1300     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1301     (?E gnus-newsgroup-expunged-tally ?d)
1302     (?s (gnus-current-score-file-nondirectory) ?s)))
1303
1304 (defvar gnus-last-search-regexp nil
1305   "Default regexp for article search command.")
1306
1307 (defvar gnus-last-shell-command nil
1308   "Default shell command on article.")
1309
1310 (defvar gnus-newsgroup-agentized nil
1311   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1312 (defvar gnus-newsgroup-begin nil)
1313 (defvar gnus-newsgroup-end nil)
1314 (defvar gnus-newsgroup-last-rmail nil)
1315 (defvar gnus-newsgroup-last-mail nil)
1316 (defvar gnus-newsgroup-last-folder nil)
1317 (defvar gnus-newsgroup-last-file nil)
1318 (defvar gnus-newsgroup-auto-expire nil)
1319 (defvar gnus-newsgroup-active nil)
1320
1321 (defvar gnus-newsgroup-data nil)
1322 (defvar gnus-newsgroup-data-reverse nil)
1323 (defvar gnus-newsgroup-limit nil)
1324 (defvar gnus-newsgroup-limits nil)
1325 (defvar gnus-summary-use-undownloaded-faces nil)
1326
1327 (defvar gnus-newsgroup-unreads nil
1328   "Sorted list of unread articles in the current newsgroup.")
1329
1330 (defvar gnus-newsgroup-unselected nil
1331   "Sorted list of unselected unread articles in the current newsgroup.")
1332
1333 (defvar gnus-newsgroup-reads nil
1334   "Alist of read articles and article marks in the current newsgroup.")
1335
1336 (defvar gnus-newsgroup-expunged-tally nil)
1337
1338 (defvar gnus-newsgroup-marked nil
1339   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1340
1341 (defvar gnus-newsgroup-spam-marked nil
1342   "List of ranges of articles that have been marked as spam.")
1343
1344 (defvar gnus-newsgroup-killed nil
1345   "List of ranges of articles that have been through the scoring process.")
1346
1347 (defvar gnus-newsgroup-cached nil
1348   "Sorted list of articles that come from the article cache.")
1349
1350 (defvar gnus-newsgroup-saved nil
1351   "List of articles that have been saved.")
1352
1353 (defvar gnus-newsgroup-kill-headers nil)
1354
1355 (defvar gnus-newsgroup-replied nil
1356   "List of articles that have been replied to in the current newsgroup.")
1357
1358 (defvar gnus-newsgroup-forwarded nil
1359   "List of articles that have been forwarded in the current newsgroup.")
1360
1361 (defvar gnus-newsgroup-recent nil
1362   "List of articles that have are recent in the current newsgroup.")
1363
1364 (defvar gnus-newsgroup-expirable nil
1365   "Sorted list of articles in the current newsgroup that can be expired.")
1366
1367 (defvar gnus-newsgroup-processable nil
1368   "List of articles in the current newsgroup that can be processed.")
1369
1370 (defvar gnus-newsgroup-downloadable nil
1371   "Sorted list of articles in the current newsgroup that can be processed.")
1372
1373 (defvar gnus-newsgroup-unfetched nil
1374   "Sorted list of articles in the current newsgroup whose headers have
1375 not been fetched into the agent.
1376
1377 This list will always be a subset of gnus-newsgroup-undownloaded.")
1378
1379 (defvar gnus-newsgroup-undownloaded nil
1380   "List of articles in the current newsgroup that haven't been downloaded.")
1381
1382 (defvar gnus-newsgroup-unsendable nil
1383   "List of articles in the current newsgroup that won't be sent.")
1384
1385 (defvar gnus-newsgroup-bookmarks nil
1386   "List of articles in the current newsgroup that have bookmarks.")
1387
1388 (defvar gnus-newsgroup-dormant nil
1389   "Sorted list of dormant articles in the current newsgroup.")
1390
1391 (defvar gnus-newsgroup-unseen nil
1392   "List of unseen articles in the current newsgroup.")
1393
1394 (defvar gnus-newsgroup-seen nil
1395   "Range of seen articles in the current newsgroup.")
1396
1397 (defvar gnus-newsgroup-articles nil
1398   "List of articles in the current newsgroup.")
1399
1400 (defvar gnus-newsgroup-scored nil
1401   "List of scored articles in the current newsgroup.")
1402
1403 (defvar gnus-newsgroup-headers nil
1404   "List of article headers in the current newsgroup.")
1405
1406 (defvar gnus-newsgroup-threads nil)
1407
1408 (defvar gnus-newsgroup-prepared nil
1409   "Whether the current group has been prepared properly.")
1410
1411 (defvar gnus-newsgroup-ancient nil
1412   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1413
1414 (defvar gnus-newsgroup-sparse nil)
1415
1416 (defvar gnus-current-article nil)
1417 (defvar gnus-article-current nil)
1418 (defvar gnus-current-headers nil)
1419 (defvar gnus-have-all-headers nil)
1420 (defvar gnus-last-article nil)
1421 (defvar gnus-newsgroup-history nil)
1422 (defvar gnus-newsgroup-charset nil)
1423 (defvar gnus-newsgroup-ephemeral-charset nil)
1424 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1425
1426 (defvar gnus-article-before-search nil)
1427
1428 (defvar gnus-summary-local-variables
1429   '(gnus-newsgroup-name
1430     gnus-newsgroup-begin gnus-newsgroup-end
1431     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1432     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1433     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1434     gnus-newsgroup-unselected gnus-newsgroup-marked
1435     gnus-newsgroup-spam-marked
1436     gnus-newsgroup-reads gnus-newsgroup-saved
1437     gnus-newsgroup-replied gnus-newsgroup-forwarded
1438     gnus-newsgroup-recent
1439     gnus-newsgroup-expirable
1440     gnus-newsgroup-processable gnus-newsgroup-killed
1441     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1442     gnus-newsgroup-unfetched
1443     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1444     gnus-newsgroup-seen gnus-newsgroup-articles
1445     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1446     gnus-newsgroup-headers gnus-newsgroup-threads
1447     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1448     gnus-current-article gnus-current-headers gnus-have-all-headers
1449     gnus-last-article gnus-article-internal-prepare-hook
1450     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1451     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1452     gnus-thread-expunge-below
1453     gnus-score-alist gnus-current-score-file
1454     (gnus-summary-expunge-below . global)
1455     (gnus-summary-mark-below . global)
1456     (gnus-orphan-score . global)
1457     gnus-newsgroup-active gnus-scores-exclude-files
1458     gnus-newsgroup-history gnus-newsgroup-ancient
1459     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1460     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1461     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1462     (gnus-newsgroup-expunged-tally . 0)
1463     gnus-cache-removable-articles gnus-newsgroup-cached
1464     gnus-newsgroup-data gnus-newsgroup-data-reverse
1465     gnus-newsgroup-limit gnus-newsgroup-limits
1466     gnus-newsgroup-charset gnus-newsgroup-display
1467     gnus-summary-use-undownloaded-faces)
1468   "Variables that are buffer-local to the summary buffers.")
1469
1470 (defvar gnus-newsgroup-variables nil
1471   "A list of variables that have separate values in different newsgroups.
1472 A list of newsgroup (summary buffer) local variables, or cons of
1473 variables and their default expressions to be evalled (when the default
1474 values are not nil), that should be made global while the summary buffer
1475 is active.
1476
1477 Note: The default expressions will be evaluated (using function `eval')
1478 before assignment to the local variable rather than just assigned to it.
1479 If the default expression is the symbol `global', that symbol will not
1480 be evaluated but the global value of the local variable will be used
1481 instead.
1482
1483 These variables can be used to set variables in the group parameters
1484 while still allowing them to affect operations done in other buffers.
1485 For example:
1486
1487 \(setq gnus-newsgroup-variables
1488      '(message-use-followup-to
1489        (gnus-visible-headers .
1490          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1491 ")
1492
1493 ;; Byte-compiler warning.
1494 (eval-when-compile
1495   ;; Bind features so that require will believe that gnus-sum has
1496   ;; already been loaded (avoids infinite recursion)
1497   (let ((features (cons 'gnus-sum features)))
1498     ;; Several of the declarations in gnus-sum are needed to load the
1499     ;; following files. Right now, these definitions have been
1500     ;; compiled but not defined (evaluated).  We could either do a
1501     ;; eval-and-compile about all of the declarations or evaluate the
1502     ;; source file.
1503     (if (boundp 'gnus-newsgroup-variables)
1504         nil
1505       (load "gnus-sum.el" t t t))
1506     (require 'gnus)
1507     (require 'gnus-art)))
1508
1509 ;; MIME stuff.
1510
1511 (defvar gnus-decode-encoded-word-methods
1512   '(mail-decode-encoded-word-string)
1513   "List of methods used to decode encoded words.
1514
1515 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1516 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1517 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1518 whose names match REGEXP.
1519
1520 For example:
1521 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1522  mail-decode-encoded-word-string
1523  (\"chinese\" . rfc1843-decode-string))")
1524
1525 (defvar gnus-decode-encoded-word-methods-cache nil)
1526
1527 (defun gnus-multi-decode-encoded-word-string (string)
1528   "Apply the functions from `gnus-encoded-word-methods' that match."
1529   (unless (and gnus-decode-encoded-word-methods-cache
1530                (eq gnus-newsgroup-name
1531                    (car gnus-decode-encoded-word-methods-cache)))
1532     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1533     (mapcar (lambda (x)
1534               (if (symbolp x)
1535                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1536                 (if (and gnus-newsgroup-name
1537                          (string-match (car x) gnus-newsgroup-name))
1538                     (nconc gnus-decode-encoded-word-methods-cache
1539                            (list (cdr x))))))
1540             gnus-decode-encoded-word-methods))
1541   (let ((xlist gnus-decode-encoded-word-methods-cache))
1542     (pop xlist)
1543     (while xlist
1544       (setq string (funcall (pop xlist) string))))
1545   string)
1546
1547 ;; Subject simplification.
1548
1549 (defun gnus-simplify-whitespace (str)
1550   "Remove excessive whitespace from STR."
1551   ;; Multiple spaces.
1552   (while (string-match "[ \t][ \t]+" str)
1553     (setq str (concat (substring str 0 (match-beginning 0))
1554                         " "
1555                         (substring str (match-end 0)))))
1556   ;; Leading spaces.
1557   (when (string-match "^[ \t]+" str)
1558     (setq str (substring str (match-end 0))))
1559   ;; Trailing spaces.
1560   (when (string-match "[ \t]+$" str)
1561     (setq str (substring str 0 (match-beginning 0))))
1562   str)
1563
1564 (defun gnus-simplify-all-whitespace (str)
1565   "Remove all whitespace from STR."
1566   (while (string-match "[ \t\n]+" str)
1567     (setq str (replace-match "" nil nil str)))
1568   str)
1569
1570 (defsubst gnus-simplify-subject-re (subject)
1571   "Remove \"Re:\" from subject lines."
1572   (if (string-match message-subject-re-regexp subject)
1573       (substring subject (match-end 0))
1574     subject))
1575
1576 (defun gnus-simplify-subject (subject &optional re-only)
1577   "Remove `Re:' and words in parentheses.
1578 If RE-ONLY is non-nil, strip leading `Re:'s only."
1579   (let ((case-fold-search t))           ;Ignore case.
1580     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1581     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1582       (setq subject (substring subject (match-end 0))))
1583     ;; Remove uninteresting prefixes.
1584     (when (and (not re-only)
1585                gnus-simplify-ignored-prefixes
1586                (string-match gnus-simplify-ignored-prefixes subject))
1587       (setq subject (substring subject (match-end 0))))
1588     ;; Remove words in parentheses from end.
1589     (unless re-only
1590       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1591         (setq subject (substring subject 0 (match-beginning 0)))))
1592     ;; Return subject string.
1593     subject))
1594
1595 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1596 ;; all whitespace.
1597 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1598   (goto-char (point-min))
1599   (while (re-search-forward regexp nil t)
1600     (replace-match (or newtext ""))))
1601
1602 (defun gnus-simplify-buffer-fuzzy ()
1603   "Simplify string in the buffer fuzzily.
1604 The string in the accessible portion of the current buffer is simplified.
1605 It is assumed to be a single-line subject.
1606 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1607 matter is removed.  Additional things can be deleted by setting
1608 `gnus-simplify-subject-fuzzy-regexp'."
1609   (let ((case-fold-search t)
1610         (modified-tick))
1611     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1612
1613     (while (not (eq modified-tick (buffer-modified-tick)))
1614       (setq modified-tick (buffer-modified-tick))
1615       (cond
1616        ((listp gnus-simplify-subject-fuzzy-regexp)
1617         (mapcar 'gnus-simplify-buffer-fuzzy-step
1618                 gnus-simplify-subject-fuzzy-regexp))
1619        (gnus-simplify-subject-fuzzy-regexp
1620         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1621       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1622       (gnus-simplify-buffer-fuzzy-step
1623        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1624       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1625
1626     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1627     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1628     (gnus-simplify-buffer-fuzzy-step " $")
1629     (gnus-simplify-buffer-fuzzy-step "^ +")))
1630
1631 (defun gnus-simplify-subject-fuzzy (subject)
1632   "Simplify a subject string fuzzily.
1633 See `gnus-simplify-buffer-fuzzy' for details."
1634   (save-excursion
1635     (gnus-set-work-buffer)
1636     (let ((case-fold-search t))
1637       ;; Remove uninteresting prefixes.
1638       (when (and gnus-simplify-ignored-prefixes
1639                  (string-match gnus-simplify-ignored-prefixes subject))
1640         (setq subject (substring subject (match-end 0))))
1641       (insert subject)
1642       (inline (gnus-simplify-buffer-fuzzy))
1643       (buffer-string))))
1644
1645 (defsubst gnus-simplify-subject-fully (subject)
1646   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1647   (cond
1648    (gnus-simplify-subject-functions
1649     (gnus-map-function gnus-simplify-subject-functions subject))
1650    ((null gnus-summary-gather-subject-limit)
1651     (gnus-simplify-subject-re subject))
1652    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1653     (gnus-simplify-subject-fuzzy subject))
1654    ((numberp gnus-summary-gather-subject-limit)
1655     (gnus-limit-string (gnus-simplify-subject-re subject)
1656                        gnus-summary-gather-subject-limit))
1657    (t
1658     subject)))
1659
1660 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1661   "Check whether two subjects are equal.
1662 If optional argument SIMPLE-FIRST is t, first argument is already
1663 simplified."
1664   (cond
1665    ((null simple-first)
1666     (equal (gnus-simplify-subject-fully s1)
1667            (gnus-simplify-subject-fully s2)))
1668    (t
1669     (equal s1
1670            (gnus-simplify-subject-fully s2)))))
1671
1672 (defun gnus-summary-bubble-group ()
1673   "Increase the score of the current group.
1674 This is a handy function to add to `gnus-summary-exit-hook' to
1675 increase the score of each group you read."
1676   (gnus-group-add-score gnus-newsgroup-name))
1677
1678 \f
1679 ;;;
1680 ;;; Gnus summary mode
1681 ;;;
1682
1683 (put 'gnus-summary-mode 'mode-class 'special)
1684
1685 (defvar gnus-article-commands-menu)
1686
1687 ;; Non-orthogonal keys
1688
1689 (gnus-define-keys gnus-summary-mode-map
1690   " " gnus-summary-next-page
1691   "\177" gnus-summary-prev-page
1692   [delete] gnus-summary-prev-page
1693   [backspace] gnus-summary-prev-page
1694   "\r" gnus-summary-scroll-up
1695   "\M-\r" gnus-summary-scroll-down
1696   "n" gnus-summary-next-unread-article
1697   "p" gnus-summary-prev-unread-article
1698   "N" gnus-summary-next-article
1699   "P" gnus-summary-prev-article
1700   "\M-\C-n" gnus-summary-next-same-subject
1701   "\M-\C-p" gnus-summary-prev-same-subject
1702   "\M-n" gnus-summary-next-unread-subject
1703   "\M-p" gnus-summary-prev-unread-subject
1704   "." gnus-summary-first-unread-article
1705   "," gnus-summary-best-unread-article
1706   "\M-s" gnus-summary-search-article-forward
1707   "\M-r" gnus-summary-search-article-backward
1708   "<" gnus-summary-beginning-of-article
1709   ">" gnus-summary-end-of-article
1710   "j" gnus-summary-goto-article
1711   "^" gnus-summary-refer-parent-article
1712   "\M-^" gnus-summary-refer-article
1713   "u" gnus-summary-tick-article-forward
1714   "!" gnus-summary-tick-article-forward
1715   "U" gnus-summary-tick-article-backward
1716   "d" gnus-summary-mark-as-read-forward
1717   "D" gnus-summary-mark-as-read-backward
1718   "E" gnus-summary-mark-as-expirable
1719   "\M-u" gnus-summary-clear-mark-forward
1720   "\M-U" gnus-summary-clear-mark-backward
1721   "k" gnus-summary-kill-same-subject-and-select
1722   "\C-k" gnus-summary-kill-same-subject
1723   "\M-\C-k" gnus-summary-kill-thread
1724   "\M-\C-l" gnus-summary-lower-thread
1725   "e" gnus-summary-edit-article
1726   "#" gnus-summary-mark-as-processable
1727   "\M-#" gnus-summary-unmark-as-processable
1728   "\M-\C-t" gnus-summary-toggle-threads
1729   "\M-\C-s" gnus-summary-show-thread
1730   "\M-\C-h" gnus-summary-hide-thread
1731   "\M-\C-f" gnus-summary-next-thread
1732   "\M-\C-b" gnus-summary-prev-thread
1733   [(meta down)] gnus-summary-next-thread
1734   [(meta up)] gnus-summary-prev-thread
1735   "\M-\C-u" gnus-summary-up-thread
1736   "\M-\C-d" gnus-summary-down-thread
1737   "&" gnus-summary-execute-command
1738   "c" gnus-summary-catchup-and-exit
1739   "\C-w" gnus-summary-mark-region-as-read
1740   "\C-t" gnus-summary-toggle-truncation
1741   "?" gnus-summary-mark-as-dormant
1742   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1743   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1744   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1745   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1746   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1747   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1748   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1749   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1750   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1751   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1752   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1753   "=" gnus-summary-expand-window
1754   "\C-x\C-s" gnus-summary-reselect-current-group
1755   "\M-g" gnus-summary-rescan-group
1756   "w" gnus-summary-stop-page-breaking
1757   "\C-c\C-r" gnus-summary-caesar-message
1758   "f" gnus-summary-followup
1759   "F" gnus-summary-followup-with-original
1760   "C" gnus-summary-cancel-article
1761   "r" gnus-summary-reply
1762   "R" gnus-summary-reply-with-original
1763   "\C-c\C-f" gnus-summary-mail-forward
1764   "o" gnus-summary-save-article
1765   "\C-o" gnus-summary-save-article-mail
1766   "|" gnus-summary-pipe-output
1767   "\M-k" gnus-summary-edit-local-kill
1768   "\M-K" gnus-summary-edit-global-kill
1769   ;; "V" gnus-version
1770   "\C-c\C-d" gnus-summary-describe-group
1771   "q" gnus-summary-exit
1772   "Q" gnus-summary-exit-no-update
1773   "\C-c\C-i" gnus-info-find-node
1774   gnus-mouse-2 gnus-mouse-pick-article
1775   [follow-link] mouse-face
1776   "m" gnus-summary-mail-other-window
1777   "a" gnus-summary-post-news
1778   "i" gnus-summary-news-other-window
1779   "x" gnus-summary-limit-to-unread
1780   "s" gnus-summary-isearch-article
1781   "t" gnus-summary-toggle-header
1782   "g" gnus-summary-show-article
1783   "l" gnus-summary-goto-last-article
1784   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1785   "\C-d" gnus-summary-enter-digest-group
1786   "\M-\C-d" gnus-summary-read-document
1787   "\M-\C-e" gnus-summary-edit-parameters
1788   "\M-\C-a" gnus-summary-customize-parameters
1789   "\C-c\C-b" gnus-bug
1790   "*" gnus-cache-enter-article
1791   "\M-*" gnus-cache-remove-article
1792   "\M-&" gnus-summary-universal-argument
1793   "\C-l" gnus-recenter
1794   "I" gnus-summary-increase-score
1795   "L" gnus-summary-lower-score
1796   "\M-i" gnus-symbolic-argument
1797   "h" gnus-summary-select-article-buffer
1798
1799   "b" gnus-article-view-part
1800   "\M-t" gnus-summary-toggle-display-buttonized
1801
1802   "V" gnus-summary-score-map
1803   "X" gnus-uu-extract-map
1804   "S" gnus-summary-send-map)
1805
1806 ;; Sort of orthogonal keymap
1807 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1808   "t" gnus-summary-tick-article-forward
1809   "!" gnus-summary-tick-article-forward
1810   "d" gnus-summary-mark-as-read-forward
1811   "r" gnus-summary-mark-as-read-forward
1812   "c" gnus-summary-clear-mark-forward
1813   " " gnus-summary-clear-mark-forward
1814   "e" gnus-summary-mark-as-expirable
1815   "x" gnus-summary-mark-as-expirable
1816   "?" gnus-summary-mark-as-dormant
1817   "b" gnus-summary-set-bookmark
1818   "B" gnus-summary-remove-bookmark
1819   "#" gnus-summary-mark-as-processable
1820   "\M-#" gnus-summary-unmark-as-processable
1821   "S" gnus-summary-limit-include-expunged
1822   "C" gnus-summary-catchup
1823   "H" gnus-summary-catchup-to-here
1824   "h" gnus-summary-catchup-from-here
1825   "\C-c" gnus-summary-catchup-all
1826   "k" gnus-summary-kill-same-subject-and-select
1827   "K" gnus-summary-kill-same-subject
1828   "P" gnus-uu-mark-map)
1829
1830 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1831   "c" gnus-summary-clear-above
1832   "u" gnus-summary-tick-above
1833   "m" gnus-summary-mark-above
1834   "k" gnus-summary-kill-below)
1835
1836 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1837   "/" gnus-summary-limit-to-subject
1838   "n" gnus-summary-limit-to-articles
1839   "w" gnus-summary-pop-limit
1840   "s" gnus-summary-limit-to-subject
1841   "a" gnus-summary-limit-to-author
1842   "u" gnus-summary-limit-to-unread
1843   "m" gnus-summary-limit-to-marks
1844   "M" gnus-summary-limit-exclude-marks
1845   "v" gnus-summary-limit-to-score
1846   "*" gnus-summary-limit-include-cached
1847   "D" gnus-summary-limit-include-dormant
1848   "T" gnus-summary-limit-include-thread
1849   "d" gnus-summary-limit-exclude-dormant
1850   "t" gnus-summary-limit-to-age
1851   "." gnus-summary-limit-to-unseen
1852   "x" gnus-summary-limit-to-extra
1853   "p" gnus-summary-limit-to-display-predicate
1854   "E" gnus-summary-limit-include-expunged
1855   "c" gnus-summary-limit-exclude-childless-dormant
1856   "C" gnus-summary-limit-mark-excluded-as-read
1857   "o" gnus-summary-insert-old-articles
1858   "N" gnus-summary-insert-new-articles
1859   "r" gnus-summary-limit-to-replied
1860   "R" gnus-summary-limit-to-recipient)
1861
1862 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1863   "n" gnus-summary-next-unread-article
1864   "p" gnus-summary-prev-unread-article
1865   "N" gnus-summary-next-article
1866   "P" gnus-summary-prev-article
1867   "\C-n" gnus-summary-next-same-subject
1868   "\C-p" gnus-summary-prev-same-subject
1869   "\M-n" gnus-summary-next-unread-subject
1870   "\M-p" gnus-summary-prev-unread-subject
1871   "f" gnus-summary-first-unread-article
1872   "b" gnus-summary-best-unread-article
1873   "j" gnus-summary-goto-article
1874   "g" gnus-summary-goto-subject
1875   "l" gnus-summary-goto-last-article
1876   "o" gnus-summary-pop-article)
1877
1878 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1879   "k" gnus-summary-kill-thread
1880   "l" gnus-summary-lower-thread
1881   "i" gnus-summary-raise-thread
1882   "T" gnus-summary-toggle-threads
1883   "t" gnus-summary-rethread-current
1884   "^" gnus-summary-reparent-thread
1885   "s" gnus-summary-show-thread
1886   "S" gnus-summary-show-all-threads
1887   "h" gnus-summary-hide-thread
1888   "H" gnus-summary-hide-all-threads
1889   "n" gnus-summary-next-thread
1890   "p" gnus-summary-prev-thread
1891   "u" gnus-summary-up-thread
1892   "o" gnus-summary-top-thread
1893   "d" gnus-summary-down-thread
1894   "#" gnus-uu-mark-thread
1895   "\M-#" gnus-uu-unmark-thread)
1896
1897 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1898   "g" gnus-summary-prepare
1899   "c" gnus-summary-insert-cached-articles
1900   "d" gnus-summary-insert-dormant-articles)
1901
1902 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1903   "c" gnus-summary-catchup-and-exit
1904   "C" gnus-summary-catchup-all-and-exit
1905   "E" gnus-summary-exit-no-update
1906   "Q" gnus-summary-exit
1907   "Z" gnus-summary-exit
1908   "n" gnus-summary-catchup-and-goto-next-group
1909   "R" gnus-summary-reselect-current-group
1910   "G" gnus-summary-rescan-group
1911   "N" gnus-summary-next-group
1912   "s" gnus-summary-save-newsrc
1913   "P" gnus-summary-prev-group)
1914
1915 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1916   " " gnus-summary-next-page
1917   "n" gnus-summary-next-page
1918   "\177" gnus-summary-prev-page
1919   [delete] gnus-summary-prev-page
1920   "p" gnus-summary-prev-page
1921   "\r" gnus-summary-scroll-up
1922   "\M-\r" gnus-summary-scroll-down
1923   "<" gnus-summary-beginning-of-article
1924   ">" gnus-summary-end-of-article
1925   "b" gnus-summary-beginning-of-article
1926   "e" gnus-summary-end-of-article
1927   "^" gnus-summary-refer-parent-article
1928   "r" gnus-summary-refer-parent-article
1929   "D" gnus-summary-enter-digest-group
1930   "R" gnus-summary-refer-references
1931   "T" gnus-summary-refer-thread
1932   "g" gnus-summary-show-article
1933   "s" gnus-summary-isearch-article
1934   "P" gnus-summary-print-article
1935   "M" gnus-mailing-list-insinuate
1936   "t" gnus-article-babel)
1937
1938 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1939   "b" gnus-article-add-buttons
1940   "B" gnus-article-add-buttons-to-head
1941   "o" gnus-article-treat-overstrike
1942   "e" gnus-article-emphasize
1943   "w" gnus-article-fill-cited-article
1944   "Q" gnus-article-fill-long-lines
1945   "C" gnus-article-capitalize-sentences
1946   "c" gnus-article-remove-cr
1947   "q" gnus-article-de-quoted-unreadable
1948   "6" gnus-article-de-base64-unreadable
1949   "Z" gnus-article-decode-HZ
1950   "A" gnus-article-treat-ansi-sequences
1951   "h" gnus-article-wash-html
1952   "u" gnus-article-unsplit-urls
1953   "s" gnus-summary-force-verify-and-decrypt
1954   "f" gnus-article-display-x-face
1955   "l" gnus-summary-stop-page-breaking
1956   "r" gnus-summary-caesar-message
1957   "m" gnus-summary-morse-message
1958   "t" gnus-summary-toggle-header
1959   "g" gnus-treat-smiley
1960   "v" gnus-summary-verbose-headers
1961   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1962   "p" gnus-article-verify-x-pgp-sig
1963   "d" gnus-article-treat-dumbquotes
1964   "i" gnus-summary-idna-message)
1965
1966 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1967   ;; mnemonic: deuglif*Y*
1968   "u" gnus-article-outlook-unwrap-lines
1969   "a" gnus-article-outlook-repair-attribution
1970   "c" gnus-article-outlook-rearrange-citation
1971   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1972
1973 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1974   "a" gnus-article-hide
1975   "h" gnus-article-hide-headers
1976   "b" gnus-article-hide-boring-headers
1977   "s" gnus-article-hide-signature
1978   "c" gnus-article-hide-citation
1979   "C" gnus-article-hide-citation-in-followups
1980   "l" gnus-article-hide-list-identifiers
1981   "B" gnus-article-strip-banner
1982   "P" gnus-article-hide-pem
1983   "\C-c" gnus-article-hide-citation-maybe)
1984
1985 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1986   "a" gnus-article-highlight
1987   "h" gnus-article-highlight-headers
1988   "c" gnus-article-highlight-citation
1989   "s" gnus-article-highlight-signature)
1990
1991 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1992   "f" gnus-article-treat-fold-headers
1993   "u" gnus-article-treat-unfold-headers
1994   "n" gnus-article-treat-fold-newsgroups)
1995
1996 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1997   "x" gnus-article-display-x-face
1998   "d" gnus-article-display-face
1999   "s" gnus-treat-smiley
2000   "D" gnus-article-remove-images
2001   "f" gnus-treat-from-picon
2002   "m" gnus-treat-mail-picon
2003   "n" gnus-treat-newsgroups-picon)
2004
2005 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2006   "w" gnus-article-decode-mime-words
2007   "c" gnus-article-decode-charset
2008   "v" gnus-mime-view-all-parts
2009   "b" gnus-article-view-part)
2010
2011 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2012   "z" gnus-article-date-ut
2013   "u" gnus-article-date-ut
2014   "l" gnus-article-date-local
2015   "p" gnus-article-date-english
2016   "e" gnus-article-date-lapsed
2017   "o" gnus-article-date-original
2018   "i" gnus-article-date-iso8601
2019   "s" gnus-article-date-user)
2020
2021 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2022   "t" gnus-article-remove-trailing-blank-lines
2023   "l" gnus-article-strip-leading-blank-lines
2024   "m" gnus-article-strip-multiple-blank-lines
2025   "a" gnus-article-strip-blank-lines
2026   "A" gnus-article-strip-all-blank-lines
2027   "s" gnus-article-strip-leading-space
2028   "e" gnus-article-strip-trailing-space
2029   "w" gnus-article-remove-leading-whitespace)
2030
2031 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2032   "v" gnus-version
2033   "f" gnus-summary-fetch-faq
2034   "d" gnus-summary-describe-group
2035   "h" gnus-summary-describe-briefly
2036   "i" gnus-info-find-node
2037   "c" gnus-group-fetch-charter
2038   "C" gnus-group-fetch-control)
2039
2040 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2041   "e" gnus-summary-expire-articles
2042   "\M-\C-e" gnus-summary-expire-articles-now
2043   "\177" gnus-summary-delete-article
2044   [delete] gnus-summary-delete-article
2045   [backspace] gnus-summary-delete-article
2046   "m" gnus-summary-move-article
2047   "r" gnus-summary-respool-article
2048   "w" gnus-summary-edit-article
2049   "c" gnus-summary-copy-article
2050   "B" gnus-summary-crosspost-article
2051   "q" gnus-summary-respool-query
2052   "t" gnus-summary-respool-trace
2053   "i" gnus-summary-import-article
2054   "I" gnus-summary-create-article
2055   "p" gnus-summary-article-posted-p)
2056
2057 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2058   "o" gnus-summary-save-article
2059   "m" gnus-summary-save-article-mail
2060   "F" gnus-summary-write-article-file
2061   "r" gnus-summary-save-article-rmail
2062   "f" gnus-summary-save-article-file
2063   "b" gnus-summary-save-article-body-file
2064   "h" gnus-summary-save-article-folder
2065   "v" gnus-summary-save-article-vm
2066   "p" gnus-summary-pipe-output
2067   "P" gnus-summary-muttprint
2068   "s" gnus-soup-add-article)
2069
2070 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2071   "b" gnus-summary-display-buttonized
2072   "m" gnus-summary-repair-multipart
2073   "v" gnus-article-view-part
2074   "o" gnus-article-save-part
2075   "O" gnus-article-save-part-and-strip
2076   "d" gnus-article-delete-part
2077   "j" gnus-article-jump-to-part
2078   "c" gnus-article-copy-part
2079   "C" gnus-article-view-part-as-charset
2080   "e" gnus-article-view-part-externally
2081   "E" gnus-article-encrypt-body
2082   "i" gnus-article-inline-part
2083   "|" gnus-article-pipe-part)
2084
2085 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2086   "p" gnus-summary-mark-as-processable
2087   "u" gnus-summary-unmark-as-processable
2088   "U" gnus-summary-unmark-all-processable
2089   "v" gnus-uu-mark-over
2090   "s" gnus-uu-mark-series
2091   "r" gnus-uu-mark-region
2092   "g" gnus-uu-unmark-region
2093   "R" gnus-uu-mark-by-regexp
2094   "G" gnus-uu-unmark-by-regexp
2095   "t" gnus-uu-mark-thread
2096   "T" gnus-uu-unmark-thread
2097   "a" gnus-uu-mark-all
2098   "b" gnus-uu-mark-buffer
2099   "S" gnus-uu-mark-sparse
2100   "k" gnus-summary-kill-process-mark
2101   "y" gnus-summary-yank-process-mark
2102   "w" gnus-summary-save-process-mark
2103   "i" gnus-uu-invert-processable)
2104
2105 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2106   ;;"x" gnus-uu-extract-any
2107   "m" gnus-summary-save-parts
2108   "u" gnus-uu-decode-uu
2109   "U" gnus-uu-decode-uu-and-save
2110   "s" gnus-uu-decode-unshar
2111   "S" gnus-uu-decode-unshar-and-save
2112   "o" gnus-uu-decode-save
2113   "O" gnus-uu-decode-save
2114   "b" gnus-uu-decode-binhex
2115   "B" gnus-uu-decode-binhex
2116   "p" gnus-uu-decode-postscript
2117   "P" gnus-uu-decode-postscript-and-save)
2118
2119 (gnus-define-keys
2120     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2121   "u" gnus-uu-decode-uu-view
2122   "U" gnus-uu-decode-uu-and-save-view
2123   "s" gnus-uu-decode-unshar-view
2124   "S" gnus-uu-decode-unshar-and-save-view
2125   "o" gnus-uu-decode-save-view
2126   "O" gnus-uu-decode-save-view
2127   "b" gnus-uu-decode-binhex-view
2128   "B" gnus-uu-decode-binhex-view
2129   "p" gnus-uu-decode-postscript-view
2130   "P" gnus-uu-decode-postscript-and-save-view)
2131
2132 (defvar gnus-article-post-menu nil)
2133
2134 (defconst gnus-summary-menu-maxlen 20)
2135
2136 (defun gnus-summary-menu-split (menu)
2137   ;; If we have lots of elements, divide them into groups of 20
2138   ;; and make a pane (or submenu) for each one.
2139   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2140       (let ((menu menu) sublists next
2141             (i 1))
2142         (while menu
2143           ;; Pull off the next gnus-summary-menu-maxlen elements
2144           ;; and make them the next element of sublist.
2145           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2146           (if next
2147               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2148                       nil))
2149           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2150                                              (aref (car (last menu)) 0)) menu)
2151                                sublists))
2152           (setq i (1+ i))
2153           (setq menu next))
2154         (nreverse sublists))
2155     ;; Few elements--put them all in one pane.
2156     menu))
2157
2158 (defun gnus-summary-make-menu-bar ()
2159   (gnus-turn-off-edit-menu 'summary)
2160
2161   (unless (boundp 'gnus-summary-misc-menu)
2162
2163     (easy-menu-define
2164       gnus-summary-kill-menu gnus-summary-mode-map ""
2165       (cons
2166        "Score"
2167        (nconc
2168         (list
2169          ["Customize" gnus-score-customize t])
2170         (gnus-make-score-map 'increase)
2171         (gnus-make-score-map 'lower)
2172         '(("Mark"
2173            ["Kill below" gnus-summary-kill-below t]
2174            ["Mark above" gnus-summary-mark-above t]
2175            ["Tick above" gnus-summary-tick-above t]
2176            ["Clear above" gnus-summary-clear-above t])
2177           ["Current score" gnus-summary-current-score t]
2178           ["Set score" gnus-summary-set-score t]
2179           ["Switch current score file..." gnus-score-change-score-file t]
2180           ["Set mark below..." gnus-score-set-mark-below t]
2181           ["Set expunge below..." gnus-score-set-expunge-below t]
2182           ["Edit current score file" gnus-score-edit-current-scores t]
2183           ["Edit score file" gnus-score-edit-file t]
2184           ["Trace score" gnus-score-find-trace t]
2185           ["Find words" gnus-score-find-favourite-words t]
2186           ["Rescore buffer" gnus-summary-rescore t]
2187           ["Increase score..." gnus-summary-increase-score t]
2188           ["Lower score..." gnus-summary-lower-score t]))))
2189
2190     ;; Define both the Article menu in the summary buffer and the
2191     ;; equivalent Commands menu in the article buffer here for
2192     ;; consistency.
2193     (let ((innards
2194            `(("Hide"
2195               ["All" gnus-article-hide t]
2196               ["Headers" gnus-article-hide-headers t]
2197               ["Signature" gnus-article-hide-signature t]
2198               ["Citation" gnus-article-hide-citation t]
2199               ["List identifiers" gnus-article-hide-list-identifiers t]
2200               ["Banner" gnus-article-strip-banner t]
2201               ["Boring headers" gnus-article-hide-boring-headers t])
2202              ("Highlight"
2203               ["All" gnus-article-highlight t]
2204               ["Headers" gnus-article-highlight-headers t]
2205               ["Signature" gnus-article-highlight-signature t]
2206               ["Citation" gnus-article-highlight-citation t])
2207              ("MIME"
2208               ["Words" gnus-article-decode-mime-words t]
2209               ["Charset" gnus-article-decode-charset t]
2210               ["QP" gnus-article-de-quoted-unreadable t]
2211               ["Base64" gnus-article-de-base64-unreadable t]
2212               ["View MIME buttons" gnus-summary-display-buttonized t]
2213               ["View all" gnus-mime-view-all-parts t]
2214               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2215               ["Encrypt body" gnus-article-encrypt-body
2216                :active (not (gnus-group-read-only-p))
2217                ,@(if (featurep 'xemacs) nil
2218                    '(:help "Encrypt the message body on disk"))]
2219               ["Extract all parts..." gnus-summary-save-parts t]
2220               ("Multipart"
2221                ["Repair multipart" gnus-summary-repair-multipart t]
2222                ["Pipe part..." gnus-article-pipe-part t]
2223                ["Inline part" gnus-article-inline-part 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                ["View part externally" gnus-article-view-part-externally t]
2229                ["View part with charset..." gnus-article-view-part-as-charset t]
2230                ["Copy part" gnus-article-copy-part t]
2231                ["Save part..." gnus-article-save-part t]
2232                ["View part" gnus-article-view-part t]))
2233              ("Date"
2234               ["Local" gnus-article-date-local t]
2235               ["ISO8601" gnus-article-date-iso8601 t]
2236               ["UT" gnus-article-date-ut t]
2237               ["Original" gnus-article-date-original t]
2238               ["Lapsed" gnus-article-date-lapsed t]
2239               ["User-defined" gnus-article-date-user t])
2240              ("Display"
2241               ["Remove images" gnus-article-remove-images t]
2242               ["Toggle smiley" gnus-treat-smiley t]
2243               ["Show X-Face" gnus-article-display-x-face t]
2244               ["Show picons in From" gnus-treat-from-picon t]
2245               ["Show picons in mail headers" gnus-treat-mail-picon t]
2246               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2247               ("View as different encoding"
2248                ,@(gnus-summary-menu-split
2249                   (mapcar
2250                    (lambda (cs)
2251                      ;; Since easymenu under Emacs doesn't allow
2252                      ;; lambda forms for menu commands, we should
2253                      ;; provide intern'ed function symbols.
2254                      (let ((command (intern (format "\
2255 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2256                        (fset command
2257                              `(lambda ()
2258                                 (interactive)
2259                                 (let ((gnus-summary-show-article-charset-alist
2260                                        '((1 . ,cs))))
2261                                   (gnus-summary-show-article 1))))
2262                        `[,(symbol-name cs) ,command t]))
2263                    (sort (if (fboundp 'coding-system-list)
2264                              (coding-system-list)
2265                            (mapcar 'car mm-mime-mule-charset-alist))
2266                          'string<)))))
2267              ("Washing"
2268               ("Remove Blanks"
2269                ["Leading" gnus-article-strip-leading-blank-lines t]
2270                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2271                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2272                ["All of the above" gnus-article-strip-blank-lines t]
2273                ["All" gnus-article-strip-all-blank-lines t]
2274                ["Leading space" gnus-article-strip-leading-space t]
2275                ["Trailing space" gnus-article-strip-trailing-space t]
2276                ["Leading space in headers"
2277                 gnus-article-remove-leading-whitespace t])
2278               ["Overstrike" gnus-article-treat-overstrike t]
2279               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2280               ["Emphasis" gnus-article-emphasize t]
2281               ["Word wrap" gnus-article-fill-cited-article t]
2282               ["Fill long lines" gnus-article-fill-long-lines t]
2283               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2284               ["Remove CR" gnus-article-remove-cr t]
2285               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2286               ["Base64" gnus-article-de-base64-unreadable t]
2287               ["Rot 13" gnus-summary-caesar-message
2288                ,@(if (featurep 'xemacs) '(t)
2289                    '(:help "\"Caesar rotate\" article by 13"))]
2290               ["De-IDNA" gnus-summary-idna-message t]
2291               ["Morse decode" gnus-summary-morse-message t]
2292               ["Unix pipe..." gnus-summary-pipe-message t]
2293               ["Add buttons" gnus-article-add-buttons t]
2294               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2295               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2296               ["Verbose header" gnus-summary-verbose-headers t]
2297               ["Toggle header" gnus-summary-toggle-header t]
2298               ["Unfold headers" gnus-article-treat-unfold-headers t]
2299               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2300               ["Html" gnus-article-wash-html t]
2301               ["Unsplit URLs" gnus-article-unsplit-urls t]
2302               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2303               ["Decode HZ" gnus-article-decode-HZ t]
2304               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2305               ("(Outlook) Deuglify"
2306                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2307                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2308                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2309                ["Full (Outlook) deuglify"
2310                 gnus-article-outlook-deuglify-article t])
2311               )
2312              ("Output"
2313               ["Save in default format..." gnus-summary-save-article
2314                ,@(if (featurep 'xemacs) '(t)
2315                    '(:help "Save article using default method"))]
2316               ["Save in file..." gnus-summary-save-article-file
2317                ,@(if (featurep 'xemacs) '(t)
2318                    '(:help "Save article in file"))]
2319               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2320               ["Save in MH folder..." gnus-summary-save-article-folder t]
2321               ["Save in VM folder..." gnus-summary-save-article-vm t]
2322               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2323               ["Save body in file..." gnus-summary-save-article-body-file t]
2324               ["Pipe through a filter..." gnus-summary-pipe-output t]
2325               ["Add to SOUP packet" gnus-soup-add-article t]
2326               ["Print with Muttprint..." gnus-summary-muttprint t]
2327               ["Print" gnus-summary-print-article
2328                ,@(if (featurep 'xemacs) '(t)
2329                    '(:help "Generate and print a PostScript image"))])
2330              ("Copy, move,... (Backend)"
2331               ,@(if (featurep 'xemacs) nil
2332                   '(:help "Copying, moving, expiring articles..."))
2333               ["Respool article..." gnus-summary-respool-article t]
2334               ["Move article..." gnus-summary-move-article
2335                (gnus-check-backend-function
2336                 'request-move-article gnus-newsgroup-name)]
2337               ["Copy article..." gnus-summary-copy-article t]
2338               ["Crosspost article..." gnus-summary-crosspost-article
2339                (gnus-check-backend-function
2340                 'request-replace-article gnus-newsgroup-name)]
2341               ["Import file..." gnus-summary-import-article
2342                (gnus-check-backend-function
2343                 'request-accept-article gnus-newsgroup-name)]
2344               ["Create article..." gnus-summary-create-article
2345                (gnus-check-backend-function
2346                 'request-accept-article gnus-newsgroup-name)]
2347               ["Check if posted" gnus-summary-article-posted-p t]
2348               ["Edit article" gnus-summary-edit-article
2349                (not (gnus-group-read-only-p))]
2350               ["Delete article" gnus-summary-delete-article
2351                (gnus-check-backend-function
2352                 'request-expire-articles gnus-newsgroup-name)]
2353               ["Query respool" gnus-summary-respool-query t]
2354               ["Trace respool" gnus-summary-respool-trace t]
2355               ["Delete expirable articles" gnus-summary-expire-articles-now
2356                (gnus-check-backend-function
2357                 'request-expire-articles gnus-newsgroup-name)])
2358              ("Extract"
2359               ["Uudecode" gnus-uu-decode-uu
2360                ,@(if (featurep 'xemacs) '(t)
2361                    '(:help "Decode uuencoded article(s)"))]
2362               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2363               ["Unshar" gnus-uu-decode-unshar t]
2364               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2365               ["Save" gnus-uu-decode-save t]
2366               ["Binhex" gnus-uu-decode-binhex t]
2367               ["Postscript" gnus-uu-decode-postscript t]
2368               ["All MIME parts" gnus-summary-save-parts t])
2369              ("Cache"
2370               ["Enter article" gnus-cache-enter-article t]
2371               ["Remove article" gnus-cache-remove-article t])
2372              ["Translate" gnus-article-babel t]
2373              ["Select article buffer" gnus-summary-select-article-buffer t]
2374              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2375              ["Isearch article..." gnus-summary-isearch-article t]
2376              ["Beginning of the article" gnus-summary-beginning-of-article t]
2377              ["End of the article" gnus-summary-end-of-article t]
2378              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2379              ["Fetch referenced articles" gnus-summary-refer-references t]
2380              ["Fetch current thread" gnus-summary-refer-thread t]
2381              ["Fetch article with id..." gnus-summary-refer-article t]
2382              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2383              ["Redisplay" gnus-summary-show-article t]
2384              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2385       (easy-menu-define
2386         gnus-summary-article-menu gnus-summary-mode-map ""
2387         (cons "Article" innards))
2388
2389       (if (not (keymapp gnus-summary-article-menu))
2390           (easy-menu-define
2391             gnus-article-commands-menu gnus-article-mode-map ""
2392             (cons "Commands" innards))
2393         ;; in Emacs, don't share menu.
2394         (setq gnus-article-commands-menu
2395               (copy-keymap gnus-summary-article-menu))
2396         (define-key gnus-article-mode-map [menu-bar commands]
2397           (cons "Commands" gnus-article-commands-menu))))
2398
2399     (easy-menu-define
2400       gnus-summary-thread-menu gnus-summary-mode-map ""
2401       '("Threads"
2402         ["Find all messages in thread" gnus-summary-refer-thread t]
2403         ["Toggle threading" gnus-summary-toggle-threads t]
2404         ["Hide threads" gnus-summary-hide-all-threads t]
2405         ["Show threads" gnus-summary-show-all-threads t]
2406         ["Hide thread" gnus-summary-hide-thread t]
2407         ["Show thread" gnus-summary-show-thread t]
2408         ["Go to next thread" gnus-summary-next-thread t]
2409         ["Go to previous thread" gnus-summary-prev-thread t]
2410         ["Go down thread" gnus-summary-down-thread t]
2411         ["Go up thread" gnus-summary-up-thread t]
2412         ["Top of thread" gnus-summary-top-thread t]
2413         ["Mark thread as read" gnus-summary-kill-thread t]
2414         ["Lower thread score" gnus-summary-lower-thread t]
2415         ["Raise thread score" gnus-summary-raise-thread t]
2416         ["Rethread current" gnus-summary-rethread-current t]))
2417
2418     (easy-menu-define
2419       gnus-summary-post-menu gnus-summary-mode-map ""
2420       `("Post"
2421         ["Send a message (mail or news)" gnus-summary-post-news
2422          ,@(if (featurep 'xemacs) '(t)
2423              '(:help "Compose a new message (mail or news)"))]
2424         ["Followup" gnus-summary-followup
2425          ,@(if (featurep 'xemacs) '(t)
2426              '(:help "Post followup to this article"))]
2427         ["Followup and yank" gnus-summary-followup-with-original
2428          ,@(if (featurep 'xemacs) '(t)
2429              '(:help "Post followup to this article, quoting its contents"))]
2430         ["Supersede article" gnus-summary-supersede-article t]
2431         ["Cancel article" gnus-summary-cancel-article
2432          ,@(if (featurep 'xemacs) '(t)
2433              '(:help "Cancel an article you posted"))]
2434         ["Reply" gnus-summary-reply t]
2435         ["Reply and yank" gnus-summary-reply-with-original t]
2436         ["Wide reply" gnus-summary-wide-reply t]
2437         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2438          ,@(if (featurep 'xemacs) '(t)
2439              '(:help "Mail a reply, quoting this article"))]
2440         ["Very wide reply" gnus-summary-very-wide-reply t]
2441         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2442          ,@(if (featurep 'xemacs) '(t)
2443              '(:help "Mail a very wide reply, quoting this article"))]
2444         ["Mail forward" gnus-summary-mail-forward t]
2445         ["Post forward" gnus-summary-post-forward t]
2446         ["Digest and mail" gnus-uu-digest-mail-forward t]
2447         ["Digest and post" gnus-uu-digest-post-forward t]
2448         ["Resend message" gnus-summary-resend-message t]
2449         ["Resend message edit" gnus-summary-resend-message-edit t]
2450         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2451         ["Send a mail" gnus-summary-mail-other-window t]
2452         ["Create a local message" gnus-summary-news-other-window t]
2453         ["Uuencode and post" gnus-uu-post-news
2454          ,@(if (featurep 'xemacs) '(t)
2455              '(:help "Post a uuencoded article"))]
2456         ["Followup via news" gnus-summary-followup-to-mail t]
2457         ["Followup via news and yank"
2458          gnus-summary-followup-to-mail-with-original t]
2459         ;;("Draft"
2460         ;;["Send" gnus-summary-send-draft t]
2461         ;;["Send bounced" gnus-resend-bounced-mail t])
2462         ))
2463
2464     (cond
2465      ((not (keymapp gnus-summary-post-menu))
2466       (setq gnus-article-post-menu gnus-summary-post-menu))
2467      ((not gnus-article-post-menu)
2468       ;; Don't share post menu.
2469       (setq gnus-article-post-menu
2470             (copy-keymap gnus-summary-post-menu))))
2471     (define-key gnus-article-mode-map [menu-bar post]
2472       (cons "Post" gnus-article-post-menu))
2473
2474     (easy-menu-define
2475       gnus-summary-misc-menu gnus-summary-mode-map ""
2476       `("Gnus"
2477         ("Mark Read"
2478          ["Mark as read" gnus-summary-mark-as-read-forward t]
2479          ["Mark same subject and select"
2480           gnus-summary-kill-same-subject-and-select t]
2481          ["Mark same subject" gnus-summary-kill-same-subject t]
2482          ["Catchup" gnus-summary-catchup
2483           ,@(if (featurep 'xemacs) '(t)
2484               '(:help "Mark unread articles in this group as read"))]
2485          ["Catchup all" gnus-summary-catchup-all t]
2486          ["Catchup to here" gnus-summary-catchup-to-here t]
2487          ["Catchup from here" gnus-summary-catchup-from-here t]
2488          ["Catchup region" gnus-summary-mark-region-as-read
2489           (gnus-mark-active-p)]
2490          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2491         ("Mark Various"
2492          ["Tick" gnus-summary-tick-article-forward t]
2493          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2494          ["Remove marks" gnus-summary-clear-mark-forward t]
2495          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2496          ["Set bookmark" gnus-summary-set-bookmark t]
2497          ["Remove bookmark" gnus-summary-remove-bookmark t])
2498         ("Limit to"
2499          ["Marks..." gnus-summary-limit-to-marks t]
2500          ["Subject..." gnus-summary-limit-to-subject t]
2501          ["Author..." gnus-summary-limit-to-author t]
2502          ["Recipient..." gnus-summary-limit-to-recipient t]
2503          ["Age..." gnus-summary-limit-to-age t]
2504          ["Extra..." gnus-summary-limit-to-extra t]
2505          ["Score..." gnus-summary-limit-to-score t]
2506          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2507          ["Unread" gnus-summary-limit-to-unread t]
2508          ["Unseen" gnus-summary-limit-to-unseen t]
2509          ["Replied" gnus-summary-limit-to-replied t]
2510          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2511          ["Next articles" gnus-summary-limit-to-articles t]
2512          ["Pop limit" gnus-summary-pop-limit t]
2513          ["Show dormant" gnus-summary-limit-include-dormant t]
2514          ["Hide childless dormant"
2515           gnus-summary-limit-exclude-childless-dormant t]
2516          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2517          ["Hide marked" gnus-summary-limit-exclude-marks t]
2518          ["Show expunged" gnus-summary-limit-include-expunged t])
2519         ("Process Mark"
2520          ["Set mark" gnus-summary-mark-as-processable t]
2521          ["Remove mark" gnus-summary-unmark-as-processable t]
2522          ["Remove all marks" gnus-summary-unmark-all-processable t]
2523          ["Invert marks" gnus-uu-invert-processable t]
2524          ["Mark above" gnus-uu-mark-over t]
2525          ["Mark series" gnus-uu-mark-series t]
2526          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2527          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2528          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2529          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2530          ["Mark all" gnus-uu-mark-all t]
2531          ["Mark buffer" gnus-uu-mark-buffer t]
2532          ["Mark sparse" gnus-uu-mark-sparse t]
2533          ["Mark thread" gnus-uu-mark-thread t]
2534          ["Unmark thread" gnus-uu-unmark-thread t]
2535          ("Process Mark Sets"
2536           ["Kill" gnus-summary-kill-process-mark t]
2537           ["Yank" gnus-summary-yank-process-mark
2538            gnus-newsgroup-process-stack]
2539           ["Save" gnus-summary-save-process-mark t]
2540           ["Run command on marked..." gnus-summary-universal-argument t]))
2541         ("Scroll article"
2542          ["Page forward" gnus-summary-next-page
2543           ,@(if (featurep 'xemacs) '(t)
2544               '(:help "Show next page of article"))]
2545          ["Page backward" gnus-summary-prev-page
2546           ,@(if (featurep 'xemacs) '(t)
2547               '(:help "Show previous page of article"))]
2548          ["Line forward" gnus-summary-scroll-up t])
2549         ("Move"
2550          ["Next unread article" gnus-summary-next-unread-article t]
2551          ["Previous unread article" gnus-summary-prev-unread-article t]
2552          ["Next article" gnus-summary-next-article t]
2553          ["Previous article" gnus-summary-prev-article t]
2554          ["Next unread subject" gnus-summary-next-unread-subject t]
2555          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2556          ["Next article same subject" gnus-summary-next-same-subject t]
2557          ["Previous article same subject" gnus-summary-prev-same-subject t]
2558          ["First unread article" gnus-summary-first-unread-article t]
2559          ["Best unread article" gnus-summary-best-unread-article t]
2560          ["Go to subject number..." gnus-summary-goto-subject t]
2561          ["Go to article number..." gnus-summary-goto-article t]
2562          ["Go to the last article" gnus-summary-goto-last-article t]
2563          ["Pop article off history" gnus-summary-pop-article t])
2564         ("Sort"
2565          ["Sort by number" gnus-summary-sort-by-number t]
2566          ["Sort by author" gnus-summary-sort-by-author t]
2567          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2568          ["Sort by subject" gnus-summary-sort-by-subject t]
2569          ["Sort by date" gnus-summary-sort-by-date t]
2570          ["Sort by score" gnus-summary-sort-by-score t]
2571          ["Sort by lines" gnus-summary-sort-by-lines t]
2572          ["Sort by characters" gnus-summary-sort-by-chars t]
2573          ["Randomize" gnus-summary-sort-by-random t]
2574          ["Original sort" gnus-summary-sort-by-original t])
2575         ("Help"
2576          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2577          ["Describe group" gnus-summary-describe-group t]
2578          ["Fetch charter" gnus-group-fetch-charter
2579           ,@(if (featurep 'xemacs) nil
2580               '(:help "Display the charter of the current group"))]
2581          ["Fetch control message" gnus-group-fetch-control
2582           ,@(if (featurep 'xemacs) nil
2583               '(:help "Display the archived control message for the current group"))]
2584          ["Read manual" gnus-info-find-node t])
2585         ("Modes"
2586          ["Pick and read" gnus-pick-mode t]
2587          ["Binary" gnus-binary-mode t])
2588         ("Regeneration"
2589          ["Regenerate" gnus-summary-prepare t]
2590          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2591          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2592          ["Toggle threading" gnus-summary-toggle-threads t])
2593         ["See old articles" gnus-summary-insert-old-articles t]
2594         ["See new articles" gnus-summary-insert-new-articles t]
2595         ["Filter articles..." gnus-summary-execute-command t]
2596         ["Run command on articles..." gnus-summary-universal-argument t]
2597         ["Search articles forward..." gnus-summary-search-article-forward t]
2598         ["Search articles backward..." gnus-summary-search-article-backward t]
2599         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2600         ["Expand window" gnus-summary-expand-window t]
2601         ["Expire expirable articles" gnus-summary-expire-articles
2602          (gnus-check-backend-function
2603           'request-expire-articles gnus-newsgroup-name)]
2604         ["Edit local kill file" gnus-summary-edit-local-kill t]
2605         ["Edit main kill file" gnus-summary-edit-global-kill t]
2606         ["Edit group parameters" gnus-summary-edit-parameters t]
2607         ["Customize group parameters" gnus-summary-customize-parameters t]
2608         ["Send a bug report" gnus-bug t]
2609         ("Exit"
2610          ["Catchup and exit" gnus-summary-catchup-and-exit
2611           ,@(if (featurep 'xemacs) '(t)
2612               '(:help "Mark unread articles in this group as read, then exit"))]
2613          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2614          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2615          ["Exit group" gnus-summary-exit
2616           ,@(if (featurep 'xemacs) '(t)
2617               '(:help "Exit current group, return to group selection mode"))]
2618          ["Exit group without updating" gnus-summary-exit-no-update t]
2619          ["Exit and goto next group" gnus-summary-next-group t]
2620          ["Exit and goto prev group" gnus-summary-prev-group t]
2621          ["Reselect group" gnus-summary-reselect-current-group t]
2622          ["Rescan group" gnus-summary-rescan-group t]
2623          ["Update dribble" gnus-summary-save-newsrc t])))
2624
2625     (gnus-run-hooks 'gnus-summary-menu-hook)))
2626
2627 (defvar gnus-summary-tool-bar-map nil)
2628
2629 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2630 (defun gnus-summary-make-tool-bar ()
2631   (if (and (fboundp 'tool-bar-add-item-from-menu)
2632            (default-value 'tool-bar-mode)
2633            (not gnus-summary-tool-bar-map))
2634       (setq gnus-summary-tool-bar-map
2635             (let ((tool-bar-map (make-sparse-keymap))
2636                   (load-path (mm-image-load-path)))
2637               (tool-bar-add-item-from-menu
2638                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2639               (tool-bar-add-item-from-menu
2640                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2641               (tool-bar-add-item-from-menu
2642                'gnus-summary-post-news "post" gnus-summary-mode-map)
2643               (tool-bar-add-item-from-menu
2644                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2645               (tool-bar-add-item-from-menu
2646                'gnus-summary-followup "followup" gnus-summary-mode-map)
2647               (tool-bar-add-item-from-menu
2648                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2649               (tool-bar-add-item-from-menu
2650                'gnus-summary-reply "reply" gnus-summary-mode-map)
2651               (tool-bar-add-item-from-menu
2652                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2653               (tool-bar-add-item-from-menu
2654                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2655               (tool-bar-add-item-from-menu
2656                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2657               (tool-bar-add-item-from-menu
2658                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2659               (tool-bar-add-item-from-menu
2660                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2661               (tool-bar-add-item-from-menu
2662                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2663               (tool-bar-add-item-from-menu
2664                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2665               (tool-bar-add-item-from-menu
2666                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2667               (tool-bar-add-item-from-menu
2668                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2669               tool-bar-map)))
2670   (if gnus-summary-tool-bar-map
2671       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2672
2673 (defun gnus-score-set-default (var value)
2674   "A version of set that updates the GNU Emacs menu-bar."
2675   (set var value)
2676   ;; It is the message that forces the active status to be updated.
2677   (message ""))
2678
2679 (defun gnus-make-score-map (type)
2680   "Make a summary score map of type TYPE."
2681   (if t
2682       nil
2683     (let ((headers '(("author" "from" string)
2684                      ("subject" "subject" string)
2685                      ("article body" "body" string)
2686                      ("article head" "head" string)
2687                      ("xref" "xref" string)
2688                      ("extra header" "extra" string)
2689                      ("lines" "lines" number)
2690                      ("followups to author" "followup" string)))
2691           (types '((number ("less than" <)
2692                            ("greater than" >)
2693                            ("equal" =))
2694                    (string ("substring" s)
2695                            ("exact string" e)
2696                            ("fuzzy string" f)
2697                            ("regexp" r))))
2698           (perms '(("temporary" (current-time-string))
2699                    ("permanent" nil)
2700                    ("immediate" now)))
2701           header)
2702       (list
2703        (apply
2704         'nconc
2705         (list
2706          (if (eq type 'lower)
2707              "Lower score"
2708            "Increase score"))
2709         (let (outh)
2710           (while headers
2711             (setq header (car headers))
2712             (setq outh
2713                   (cons
2714                    (apply
2715                     'nconc
2716                     (list (car header))
2717                     (let ((ts (cdr (assoc (nth 2 header) types)))
2718                           outt)
2719                       (while ts
2720                         (setq outt
2721                               (cons
2722                                (apply
2723                                 'nconc
2724                                 (list (caar ts))
2725                                 (let ((ps perms)
2726                                       outp)
2727                                   (while ps
2728                                     (setq outp
2729                                           (cons
2730                                            (vector
2731                                             (caar ps)
2732                                             (list
2733                                              'gnus-summary-score-entry
2734                                              (nth 1 header)
2735                                              (if (or (string= (nth 1 header)
2736                                                               "head")
2737                                                      (string= (nth 1 header)
2738                                                               "body"))
2739                                                  ""
2740                                                (list 'gnus-summary-header
2741                                                      (nth 1 header)))
2742                                              (list 'quote (nth 1 (car ts)))
2743                                              (list 'gnus-score-delta-default
2744                                                    nil)
2745                                              (nth 1 (car ps))
2746                                              t)
2747                                             t)
2748                                            outp))
2749                                     (setq ps (cdr ps)))
2750                                   (list (nreverse outp))))
2751                                outt))
2752                         (setq ts (cdr ts)))
2753                       (list (nreverse outt))))
2754                    outh))
2755             (setq headers (cdr headers)))
2756           (list (nreverse outh))))))))
2757
2758 \f
2759
2760 (defun gnus-summary-mode (&optional group)
2761   "Major mode for reading articles.
2762
2763 All normal editing commands are switched off.
2764 \\<gnus-summary-mode-map>
2765 Each line in this buffer represents one article.  To read an
2766 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2767 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2768 respectively.
2769
2770 You can also post articles and send mail from this buffer.  To
2771 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2772 of an article, type `\\[gnus-summary-reply]'.
2773
2774 There are approx. one gazillion commands you can execute in this
2775 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2776
2777 The following commands are available:
2778
2779 \\{gnus-summary-mode-map}"
2780   (interactive)
2781   (kill-all-local-variables)
2782   (when (gnus-visual-p 'summary-menu 'menu)
2783     (gnus-summary-make-menu-bar)
2784     (gnus-summary-make-tool-bar))
2785   (gnus-summary-make-local-variables)
2786   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2787     (gnus-summary-make-local-variables))
2788   (gnus-make-thread-indent-array)
2789   (gnus-simplify-mode-line)
2790   (setq major-mode 'gnus-summary-mode)
2791   (setq mode-name "Summary")
2792   (make-local-variable 'minor-mode-alist)
2793   (use-local-map gnus-summary-mode-map)
2794   (buffer-disable-undo)
2795   (setq buffer-read-only t              ;Disable modification
2796         show-trailing-whitespace nil)
2797   (setq truncate-lines t)
2798   (setq selective-display t)
2799   (setq selective-display-ellipses t)   ;Display `...'
2800   (gnus-summary-set-display-table)
2801   (gnus-set-default-directory)
2802   (setq gnus-newsgroup-name group)
2803   (make-local-variable 'gnus-summary-line-format)
2804   (make-local-variable 'gnus-summary-line-format-spec)
2805   (make-local-variable 'gnus-summary-dummy-line-format)
2806   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2807   (make-local-variable 'gnus-summary-mark-positions)
2808   (gnus-make-local-hook 'pre-command-hook)
2809   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2810   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2811   (turn-on-gnus-mailing-list-mode)
2812   (mm-enable-multibyte)
2813   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2814   (gnus-update-summary-mark-positions))
2815
2816 (defun gnus-summary-make-local-variables ()
2817   "Make all the local summary buffer variables."
2818   (let (global)
2819     (dolist (local gnus-summary-local-variables)
2820       (if (consp local)
2821           (progn
2822             (if (eq (cdr local) 'global)
2823                 ;; Copy the global value of the variable.
2824                 (setq global (symbol-value (car local)))
2825               ;; Use the value from the list.
2826               (setq global (eval (cdr local))))
2827             (set (make-local-variable (car local)) global))
2828         ;; Simple nil-valued local variable.
2829         (set (make-local-variable local) nil)))))
2830
2831 (defun gnus-summary-clear-local-variables ()
2832   (let ((locals gnus-summary-local-variables))
2833     (while locals
2834       (if (consp (car locals))
2835           (and (symbolp (caar locals))
2836                (set (caar locals) nil))
2837         (and (symbolp (car locals))
2838              (set (car locals) nil)))
2839       (setq locals (cdr locals)))))
2840
2841 ;; Summary data functions.
2842
2843 (defmacro gnus-data-number (data)
2844   `(car ,data))
2845
2846 (defmacro gnus-data-set-number (data number)
2847   `(setcar ,data ,number))
2848
2849 (defmacro gnus-data-mark (data)
2850   `(nth 1 ,data))
2851
2852 (defmacro gnus-data-set-mark (data mark)
2853   `(setcar (nthcdr 1 ,data) ,mark))
2854
2855 (defmacro gnus-data-pos (data)
2856   `(nth 2 ,data))
2857
2858 (defmacro gnus-data-set-pos (data pos)
2859   `(setcar (nthcdr 2 ,data) ,pos))
2860
2861 (defmacro gnus-data-header (data)
2862   `(nth 3 ,data))
2863
2864 (defmacro gnus-data-set-header (data header)
2865   `(setf (nth 3 ,data) ,header))
2866
2867 (defmacro gnus-data-level (data)
2868   `(nth 4 ,data))
2869
2870 (defmacro gnus-data-unread-p (data)
2871   `(= (nth 1 ,data) gnus-unread-mark))
2872
2873 (defmacro gnus-data-read-p (data)
2874   `(/= (nth 1 ,data) gnus-unread-mark))
2875
2876 (defmacro gnus-data-pseudo-p (data)
2877   `(consp (nth 3 ,data)))
2878
2879 (defmacro gnus-data-find (number)
2880   `(assq ,number gnus-newsgroup-data))
2881
2882 (defmacro gnus-data-find-list (number &optional data)
2883   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2884      (memq (assq ,number bdata)
2885            bdata)))
2886
2887 (defmacro gnus-data-make (number mark pos header level)
2888   `(list ,number ,mark ,pos ,header ,level))
2889
2890 (defun gnus-data-enter (after-article number mark pos header level offset)
2891   (let ((data (gnus-data-find-list after-article)))
2892     (unless data
2893       (error "No such article: %d" after-article))
2894     (setcdr data (cons (gnus-data-make number mark pos header level)
2895                        (cdr data)))
2896     (setq gnus-newsgroup-data-reverse nil)
2897     (gnus-data-update-list (cddr data) offset)))
2898
2899 (defun gnus-data-enter-list (after-article list &optional offset)
2900   (when list
2901     (let ((data (and after-article (gnus-data-find-list after-article)))
2902           (ilist list))
2903       (if (not (or data
2904                    after-article))
2905           (let ((odata gnus-newsgroup-data))
2906             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2907             (when offset
2908               (gnus-data-update-list odata offset)))
2909         ;; Find the last element in the list to be spliced into the main
2910         ;; list.
2911         (setq list (last list))
2912         (if (not data)
2913             (progn
2914               (setcdr list gnus-newsgroup-data)
2915               (setq gnus-newsgroup-data ilist)
2916               (when offset
2917                 (gnus-data-update-list (cdr list) offset)))
2918           (setcdr list (cdr data))
2919           (setcdr data ilist)
2920           (when offset
2921             (gnus-data-update-list (cdr list) offset))))
2922       (setq gnus-newsgroup-data-reverse nil))))
2923
2924 (defun gnus-data-remove (article &optional offset)
2925   (let ((data gnus-newsgroup-data))
2926     (if (= (gnus-data-number (car data)) article)
2927         (progn
2928           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2929                 gnus-newsgroup-data-reverse nil)
2930           (when offset
2931             (gnus-data-update-list gnus-newsgroup-data offset)))
2932       (while (cdr data)
2933         (when (= (gnus-data-number (cadr data)) article)
2934           (setcdr data (cddr data))
2935           (when offset
2936             (gnus-data-update-list (cdr data) offset))
2937           (setq data nil
2938                 gnus-newsgroup-data-reverse nil))
2939         (setq data (cdr data))))))
2940
2941 (defmacro gnus-data-list (backward)
2942   `(if ,backward
2943        (or gnus-newsgroup-data-reverse
2944            (setq gnus-newsgroup-data-reverse
2945                  (reverse gnus-newsgroup-data)))
2946      gnus-newsgroup-data))
2947
2948 (defun gnus-data-update-list (data offset)
2949   "Add OFFSET to the POS of all data entries in DATA."
2950   (setq gnus-newsgroup-data-reverse nil)
2951   (while data
2952     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2953     (setq data (cdr data))))
2954
2955 (defun gnus-summary-article-pseudo-p (article)
2956   "Say whether this article is a pseudo article or not."
2957   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2958
2959 (defmacro gnus-summary-article-sparse-p (article)
2960   "Say whether this article is a sparse article or not."
2961   `(memq ,article gnus-newsgroup-sparse))
2962
2963 (defmacro gnus-summary-article-ancient-p (article)
2964   "Say whether this article is a sparse article or not."
2965   `(memq ,article gnus-newsgroup-ancient))
2966
2967 (defun gnus-article-parent-p (number)
2968   "Say whether this article is a parent or not."
2969   (let ((data (gnus-data-find-list number)))
2970     (and (cdr data)              ; There has to be an article after...
2971          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2972             (gnus-data-level (nth 1 data))))))
2973
2974 (defun gnus-article-children (number)
2975   "Return a list of all children to NUMBER."
2976   (let* ((data (gnus-data-find-list number))
2977          (level (gnus-data-level (car data)))
2978          children)
2979     (setq data (cdr data))
2980     (while (and data
2981                 (= (gnus-data-level (car data)) (1+ level)))
2982       (push (gnus-data-number (car data)) children)
2983       (setq data (cdr data)))
2984     children))
2985
2986 (defmacro gnus-summary-skip-intangible ()
2987   "If the current article is intangible, then jump to a different article."
2988   '(let ((to (get-text-property (point) 'gnus-intangible)))
2989      (and to (gnus-summary-goto-subject to))))
2990
2991 (defmacro gnus-summary-article-intangible-p ()
2992   "Say whether this article is intangible or not."
2993   '(get-text-property (point) 'gnus-intangible))
2994
2995 (defun gnus-article-read-p (article)
2996   "Say whether ARTICLE is read or not."
2997   (not (or (memq article gnus-newsgroup-marked)
2998            (memq article gnus-newsgroup-spam-marked)
2999            (memq article gnus-newsgroup-unreads)
3000            (memq article gnus-newsgroup-unselected)
3001            (memq article gnus-newsgroup-dormant))))
3002
3003 ;; Some summary mode macros.
3004
3005 (defmacro gnus-summary-article-number ()
3006   "The article number of the article on the current line.
3007 If there isn't an article number here, then we return the current
3008 article number."
3009   '(progn
3010      (gnus-summary-skip-intangible)
3011      (or (get-text-property (point) 'gnus-number)
3012          (gnus-summary-last-subject))))
3013
3014 (defmacro gnus-summary-article-header (&optional number)
3015   "Return the header of article NUMBER."
3016   `(gnus-data-header (gnus-data-find
3017                       ,(or number '(gnus-summary-article-number)))))
3018
3019 (defmacro gnus-summary-thread-level (&optional number)
3020   "Return the level of thread that starts with article NUMBER."
3021   `(if (and (eq gnus-summary-make-false-root 'dummy)
3022             (get-text-property (point) 'gnus-intangible))
3023        0
3024      (gnus-data-level (gnus-data-find
3025                        ,(or number '(gnus-summary-article-number))))))
3026
3027 (defmacro gnus-summary-article-mark (&optional number)
3028   "Return the mark of article NUMBER."
3029   `(gnus-data-mark (gnus-data-find
3030                     ,(or number '(gnus-summary-article-number)))))
3031
3032 (defmacro gnus-summary-article-pos (&optional number)
3033   "Return the position of the line of article NUMBER."
3034   `(gnus-data-pos (gnus-data-find
3035                    ,(or number '(gnus-summary-article-number)))))
3036
3037 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3038 (defmacro gnus-summary-article-subject (&optional number)
3039   "Return current subject string or nil if nothing."
3040   `(let ((headers
3041           ,(if number
3042                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3043              '(gnus-data-header (assq (gnus-summary-article-number)
3044                                       gnus-newsgroup-data)))))
3045      (and headers
3046           (vectorp headers)
3047           (mail-header-subject headers))))
3048
3049 (defmacro gnus-summary-article-score (&optional number)
3050   "Return current article score."
3051   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3052                   gnus-newsgroup-scored))
3053        gnus-summary-default-score 0))
3054
3055 (defun gnus-summary-article-children (&optional number)
3056   "Return a list of article numbers that are children of article NUMBER."
3057   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3058          (level (gnus-data-level (car data)))
3059          l children)
3060     (while (and (setq data (cdr data))
3061                 (> (setq l (gnus-data-level (car data))) level))
3062       (and (= (1+ level) l)
3063            (push (gnus-data-number (car data))
3064                  children)))
3065     (nreverse children)))
3066
3067 (defun gnus-summary-article-parent (&optional number)
3068   "Return the article number of the parent of article NUMBER."
3069   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3070                                     (gnus-data-list t)))
3071          (level (gnus-data-level (car data))))
3072     (if (zerop level)
3073         ()                              ; This is a root.
3074       ;; We search until we find an article with a level less than
3075       ;; this one.  That function has to be the parent.
3076       (while (and (setq data (cdr data))
3077                   (not (< (gnus-data-level (car data)) level))))
3078       (and data (gnus-data-number (car data))))))
3079
3080 (defun gnus-unread-mark-p (mark)
3081   "Say whether MARK is the unread mark."
3082   (= mark gnus-unread-mark))
3083
3084 (defun gnus-read-mark-p (mark)
3085   "Say whether MARK is one of the marks that mark as read.
3086 This is all marks except unread, ticked, dormant, and expirable."
3087   (not (or (= mark gnus-unread-mark)
3088            (= mark gnus-ticked-mark)
3089            (= mark gnus-spam-mark)
3090            (= mark gnus-dormant-mark)
3091            (= mark gnus-expirable-mark))))
3092
3093 (defmacro gnus-article-mark (number)
3094   "Return the MARK of article NUMBER.
3095 This macro should only be used when computing the mark the \"first\"
3096 time; i.e., when generating the summary lines.  After that,
3097 `gnus-summary-article-mark' should be used to examine the
3098 marks of articles."
3099   `(cond
3100     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3101     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3102     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3103     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3104     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3105     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3106     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3107     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3108            gnus-ancient-mark))))
3109
3110 ;; Saving hidden threads.
3111
3112 (defmacro gnus-save-hidden-threads (&rest forms)
3113   "Save hidden threads, eval FORMS, and restore the hidden threads."
3114   (let ((config (make-symbol "config")))
3115     `(let ((,config (gnus-hidden-threads-configuration)))
3116        (unwind-protect
3117            (save-excursion
3118              ,@forms)
3119          (gnus-restore-hidden-threads-configuration ,config)))))
3120 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3121 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3122
3123 (defun gnus-data-compute-positions ()
3124   "Compute the positions of all articles."
3125   (setq gnus-newsgroup-data-reverse nil)
3126   (let ((data gnus-newsgroup-data))
3127     (save-excursion
3128       (gnus-save-hidden-threads
3129         (gnus-summary-show-all-threads)
3130         (goto-char (point-min))
3131         (while data
3132           (while (get-text-property (point) 'gnus-intangible)
3133             (forward-line 1))
3134           (gnus-data-set-pos (car data) (+ (point) 3))
3135           (setq data (cdr data))
3136           (forward-line 1))))))
3137
3138 (defun gnus-hidden-threads-configuration ()
3139   "Return the current hidden threads configuration."
3140   (save-excursion
3141     (let (config)
3142       (goto-char (point-min))
3143       (while (search-forward "\r" nil t)
3144         (push (1- (point)) config))
3145       config)))
3146
3147 (defun gnus-restore-hidden-threads-configuration (config)
3148   "Restore hidden threads configuration from CONFIG."
3149   (save-excursion
3150     (let (point buffer-read-only)
3151       (while (setq point (pop config))
3152         (when (and (< point (point-max))
3153                    (goto-char point)
3154                    (eq (char-after) ?\n))
3155           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3156
3157 ;; Various summary mode internalish functions.
3158
3159 (defun gnus-mouse-pick-article (e)
3160   (interactive "e")
3161   (mouse-set-point e)
3162   (gnus-summary-next-page nil t))
3163
3164 (defun gnus-summary-set-display-table ()
3165   "Change the display table.
3166 Odd characters have a tendency to mess
3167 up nicely formatted displays - we make all possible glyphs
3168 display only a single character."
3169
3170   ;; We start from the standard display table, if any.
3171   (let ((table (or (copy-sequence standard-display-table)
3172                    (make-display-table)))
3173         (i 32))
3174     ;; Nix out all the control chars...
3175     (while (>= (setq i (1- i)) 0)
3176       (aset table i [??]))
3177    ;; ... but not newline and cr, of course.  (cr is necessary for the
3178     ;; selective display).
3179     (aset table ?\n nil)
3180     (aset table ?\r nil)
3181     ;; We keep TAB as well.
3182     (aset table ?\t nil)
3183     ;; We nix out any glyphs over 126 that are not set already.
3184     (let ((i 256))
3185       (while (>= (setq i (1- i)) 127)
3186         ;; Only modify if the entry is nil.
3187         (unless (aref table i)
3188           (aset table i [??]))))
3189     (setq buffer-display-table table)))
3190
3191 (defun gnus-summary-set-article-display-arrow (pos)
3192   "Update the overlay arrow to point to line at position POS."
3193   (when (and gnus-summary-display-arrow
3194              (boundp 'overlay-arrow-position)
3195              (boundp 'overlay-arrow-string))
3196     (save-excursion
3197       (goto-char pos)
3198       (beginning-of-line)
3199       (unless overlay-arrow-position
3200         (setq overlay-arrow-position (make-marker)))
3201       (setq overlay-arrow-string "=>"
3202             overlay-arrow-position (set-marker overlay-arrow-position
3203                                                (point)
3204                                                (current-buffer))))))
3205
3206 (defun gnus-summary-setup-buffer (group)
3207   "Initialize summary buffer."
3208   (let ((buffer (gnus-summary-buffer-name group))
3209         (dead-name (concat "*Dead Summary "
3210                            (gnus-group-decoded-name group) "*")))
3211     ;; If a dead summary buffer exists, we kill it.
3212     (when (gnus-buffer-live-p dead-name)
3213       (gnus-kill-buffer dead-name))
3214     (if (get-buffer buffer)
3215         (progn
3216           (set-buffer buffer)
3217           (setq gnus-summary-buffer (current-buffer))
3218           (not gnus-newsgroup-prepared))
3219       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3220       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3221       (gnus-summary-mode group)
3222       (when gnus-carpal
3223         (gnus-carpal-setup-buffer 'summary))
3224       (unless gnus-single-article-buffer
3225         (make-local-variable 'gnus-article-buffer)
3226         (make-local-variable 'gnus-article-current)
3227         (make-local-variable 'gnus-original-article-buffer))
3228       (setq gnus-newsgroup-name group)
3229       ;; Set any local variables in the group parameters.
3230       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3231       t)))
3232
3233 (defun gnus-set-global-variables ()
3234   "Set the global equivalents of the buffer-local variables.
3235 They are set to the latest values they had.  These reflect the summary
3236 buffer that was in action when the last article was fetched."
3237   (when (eq major-mode 'gnus-summary-mode)
3238     (setq gnus-summary-buffer (current-buffer))
3239     (let ((name gnus-newsgroup-name)
3240           (marked gnus-newsgroup-marked)
3241           (spam gnus-newsgroup-spam-marked)
3242           (unread gnus-newsgroup-unreads)
3243           (headers gnus-current-headers)
3244           (data gnus-newsgroup-data)
3245           (summary gnus-summary-buffer)
3246           (article-buffer gnus-article-buffer)
3247           (original gnus-original-article-buffer)
3248           (gac gnus-article-current)
3249           (reffed gnus-reffed-article-number)
3250           (score-file gnus-current-score-file)
3251           (default-charset gnus-newsgroup-charset)
3252           vlist)
3253       (let ((locals gnus-newsgroup-variables))
3254         (while locals
3255           (if (consp (car locals))
3256               (push (eval (caar locals)) vlist)
3257             (push (eval (car locals)) vlist))
3258           (setq locals (cdr locals)))
3259         (setq vlist (nreverse vlist)))
3260       (with-current-buffer gnus-group-buffer
3261         (setq gnus-newsgroup-name name
3262               gnus-newsgroup-marked marked
3263               gnus-newsgroup-spam-marked spam
3264               gnus-newsgroup-unreads unread
3265               gnus-current-headers headers
3266               gnus-newsgroup-data data
3267               gnus-article-current gac
3268               gnus-summary-buffer summary
3269               gnus-article-buffer article-buffer
3270               gnus-original-article-buffer original
3271               gnus-reffed-article-number reffed
3272               gnus-current-score-file score-file
3273               gnus-newsgroup-charset default-charset)
3274         (let ((locals gnus-newsgroup-variables))
3275           (while locals
3276             (if (consp (car locals))
3277                 (set (caar locals) (pop vlist))
3278               (set (car locals) (pop vlist)))
3279             (setq locals (cdr locals))))
3280         ;; The article buffer also has local variables.
3281         (when (gnus-buffer-live-p gnus-article-buffer)
3282           (set-buffer gnus-article-buffer)
3283           (setq gnus-summary-buffer summary))))))
3284
3285 (defun gnus-summary-article-unread-p (article)
3286   "Say whether ARTICLE is unread or not."
3287   (memq article gnus-newsgroup-unreads))
3288
3289 (defun gnus-summary-first-article-p (&optional article)
3290   "Return whether ARTICLE is the first article in the buffer."
3291   (if (not (setq article (or article (gnus-summary-article-number))))
3292       nil
3293     (eq article (caar gnus-newsgroup-data))))
3294
3295 (defun gnus-summary-last-article-p (&optional article)
3296   "Return whether ARTICLE is the last article in the buffer."
3297   (if (not (setq article (or article (gnus-summary-article-number))))
3298       ;; All non-existent numbers are the last article.  :-)
3299       t
3300     (not (cdr (gnus-data-find-list article)))))
3301
3302 (defun gnus-make-thread-indent-array ()
3303   (let ((n 200))
3304     (unless (and gnus-thread-indent-array
3305                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3306       (setq gnus-thread-indent-array (make-vector 201 "")
3307             gnus-thread-indent-array-level gnus-thread-indent-level)
3308       (while (>= n 0)
3309         (aset gnus-thread-indent-array n
3310               (make-string (* n gnus-thread-indent-level) ? ))
3311         (setq n (1- n))))))
3312
3313 (defun gnus-update-summary-mark-positions ()
3314   "Compute where the summary marks are to go."
3315   (save-excursion
3316     (when (gnus-buffer-exists-p gnus-summary-buffer)
3317       (set-buffer gnus-summary-buffer))
3318     (let ((spec gnus-summary-line-format-spec)
3319           pos)
3320       (save-excursion
3321         (gnus-set-work-buffer)
3322         (let ((gnus-tmp-unread ?Z)
3323               (gnus-replied-mark ?Z)
3324               (gnus-score-below-mark ?Z)
3325               (gnus-score-over-mark ?Z)
3326               (gnus-undownloaded-mark ?Z)
3327               (gnus-summary-line-format-spec spec)
3328               (gnus-newsgroup-downloadable '(0))
3329               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3330               case-fold-search ignores)
3331           ;; Here, all marks are bound to Z.
3332           (gnus-summary-insert-line header
3333                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3334           (goto-char (point-min))
3335           ;; Memorize the positions of the same characters as dummy marks.
3336           (while (re-search-forward "[A-D]" nil t)
3337             (push (point) ignores))
3338           (erase-buffer)
3339           ;; We use A-D as dummy marks in order to know column positions
3340           ;; where marks should be inserted.
3341           (setq gnus-tmp-unread ?A
3342                 gnus-replied-mark ?B
3343                 gnus-score-below-mark ?C
3344                 gnus-score-over-mark ?C
3345                 gnus-undownloaded-mark ?D)
3346           (gnus-summary-insert-line header
3347                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3348           ;; Ignore characters which aren't dummy marks.
3349           (dolist (p ignores)
3350             (delete-region (goto-char (1- p)) p)
3351             (insert ?Z))
3352           (goto-char (point-min))
3353           (setq pos (list (cons 'unread
3354                                 (and (search-forward "A" nil t)
3355                                      (- (point) (point-min) 1)))))
3356           (goto-char (point-min))
3357           (push (cons 'replied (and (search-forward "B" nil t)
3358                                     (- (point) (point-min) 1)))
3359                 pos)
3360           (goto-char (point-min))
3361           (push (cons 'score (and (search-forward "C" nil t)
3362                                   (- (point) (point-min) 1)))
3363                 pos)
3364           (goto-char (point-min))
3365           (push (cons 'download (and (search-forward "D" nil t)
3366                                      (- (point) (point-min) 1)))
3367                 pos)))
3368       (setq gnus-summary-mark-positions pos))))
3369
3370 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3371   "Insert a dummy root in the summary buffer."
3372   (beginning-of-line)
3373   (gnus-add-text-properties
3374    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3375    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3376
3377 (defun gnus-summary-extract-address-component (from)
3378   (or (car (funcall gnus-extract-address-components from))
3379       from))
3380
3381 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3382   (let ((mail-parse-charset gnus-newsgroup-charset)
3383         ; Is it really necessary to do this next part for each summary line?
3384         ; Luckily, doesn't seem to slow things down much.
3385         (mail-parse-ignored-charsets
3386          (with-current-buffer gnus-summary-buffer
3387            gnus-newsgroup-ignored-charsets)))
3388     (or
3389      (and gnus-ignored-from-addresses
3390           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3391           (let ((extra-headers (mail-header-extra header))
3392                 to
3393                 newsgroups)
3394             (cond
3395              ((setq to (cdr (assq 'To extra-headers)))
3396               (concat gnus-summary-to-prefix
3397                       (inline
3398                         (gnus-summary-extract-address-component
3399                          (funcall gnus-decode-encoded-word-function to)))))
3400              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3401               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3402      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3403
3404 (defun gnus-summary-insert-line (gnus-tmp-header
3405                                  gnus-tmp-level gnus-tmp-current
3406                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3407                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3408                                  &optional gnus-tmp-dummy gnus-tmp-score
3409                                  gnus-tmp-process)
3410   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3411          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3412          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3413          (gnus-tmp-score-char
3414           (if (or (null gnus-summary-default-score)
3415                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3416                       gnus-summary-zcore-fuzz))
3417               ?                         ;Whitespace
3418             (if (< gnus-tmp-score gnus-summary-default-score)
3419                 gnus-score-below-mark gnus-score-over-mark)))
3420          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3421          (gnus-tmp-replied
3422           (cond (gnus-tmp-process gnus-process-mark)
3423                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3424                  gnus-cached-mark)
3425                 (gnus-tmp-replied gnus-replied-mark)
3426                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3427                  gnus-forwarded-mark)
3428                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3429                  gnus-saved-mark)
3430                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3431                  gnus-recent-mark)
3432                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3433                  gnus-unseen-mark)
3434                 (t gnus-no-mark)))
3435          (gnus-tmp-downloaded
3436           (cond (undownloaded
3437                  gnus-undownloaded-mark)
3438                 (gnus-newsgroup-agentized
3439                  gnus-downloaded-mark)
3440                 (t
3441                  gnus-no-mark)))
3442          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3443          (gnus-tmp-name
3444           (cond
3445            ((string-match "<[^>]+> *$" gnus-tmp-from)
3446             (let ((beg (match-beginning 0)))
3447               (or (and (string-match "^\".+\"" gnus-tmp-from)
3448                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3449                   (substring gnus-tmp-from 0 beg))))
3450            ((string-match "(.+)" gnus-tmp-from)
3451             (substring gnus-tmp-from
3452                        (1+ (match-beginning 0)) (1- (match-end 0))))
3453            (t gnus-tmp-from)))
3454          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3455          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3456          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3457          (buffer-read-only nil))
3458     (when (string= gnus-tmp-name "")
3459       (setq gnus-tmp-name gnus-tmp-from))
3460     (unless (numberp gnus-tmp-lines)
3461       (setq gnus-tmp-lines -1))
3462     (if (= gnus-tmp-lines -1)
3463         (setq gnus-tmp-lines "?")
3464       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3465       (gnus-put-text-property
3466      (point)
3467      (progn (eval gnus-summary-line-format-spec) (point))
3468        'gnus-number gnus-tmp-number)
3469     (when (gnus-visual-p 'summary-highlight 'highlight)
3470       (forward-line -1)
3471       (gnus-run-hooks 'gnus-summary-update-hook)
3472       (forward-line 1))))
3473
3474 (defun gnus-summary-update-line (&optional dont-update)
3475   "Update summary line after change."
3476   (when (and gnus-summary-default-score
3477              (not gnus-summary-inhibit-highlight))
3478     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3479            (article (gnus-summary-article-number))
3480            (score (gnus-summary-article-score article)))
3481       (unless dont-update
3482         (if (and gnus-summary-mark-below
3483                  (< (gnus-summary-article-score)
3484                     gnus-summary-mark-below))
3485             ;; This article has a low score, so we mark it as read.
3486             (when (memq article gnus-newsgroup-unreads)
3487               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3488           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3489             ;; This article was previously marked as read on account
3490             ;; of a low score, but now it has risen, so we mark it as
3491             ;; unread.
3492             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3493         (gnus-summary-update-mark
3494          (if (or (null gnus-summary-default-score)
3495                  (<= (abs (- score gnus-summary-default-score))
3496                      gnus-summary-zcore-fuzz))
3497              ?                          ;Whitespace
3498            (if (< score gnus-summary-default-score)
3499                gnus-score-below-mark gnus-score-over-mark))
3500          'score))
3501       ;; Do visual highlighting.
3502       (when (gnus-visual-p 'summary-highlight 'highlight)
3503         (gnus-run-hooks 'gnus-summary-update-hook)))))
3504
3505 (defvar gnus-tmp-new-adopts nil)
3506
3507 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3508   "Return the number of articles in THREAD.
3509 This may be 0 in some cases -- if none of the articles in
3510 the thread are to be displayed."
3511   (let* ((number
3512          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3513           (cond
3514            ((not (listp thread))
3515             1)
3516            ((and (consp thread) (cdr thread))
3517             (apply
3518              '+ 1 (mapcar
3519                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3520            ((null thread)
3521             1)
3522            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3523             1)
3524            (t 0))))
3525     (when (and level (zerop level) gnus-tmp-new-adopts)
3526       (incf number
3527             (apply '+ (mapcar
3528                        'gnus-summary-number-of-articles-in-thread
3529                        gnus-tmp-new-adopts))))
3530     (if char
3531         (if (> number 1) gnus-not-empty-thread-mark
3532           gnus-empty-thread-mark)
3533       number)))
3534
3535 (defsubst gnus-summary-line-message-size (head)
3536   "Return pretty-printed version of message size.
3537 This function is intended to be used in
3538 `gnus-summary-line-format-alist'."
3539   (let ((c (or (mail-header-chars head) -1)))
3540     (cond ((< c 0) "n/a")               ; chars not available
3541           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3542           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3543           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3544           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3545
3546
3547 (defun gnus-summary-set-local-parameters (group)
3548   "Go through the local params of GROUP and set all variable specs in that list."
3549   (let ((vars '(quit-config)))          ; Ignore quit-config.
3550     (dolist (elem (gnus-group-find-parameter group))
3551       (and (consp elem)                 ; Has to be a cons.
3552            (consp (cdr elem))           ; The cdr has to be a list.
3553            (symbolp (car elem))         ; Has to be a symbol in there.
3554            (not (memq (car elem) vars))
3555            (ignore-errors               ; So we set it.
3556              (push (car elem) vars)
3557              (make-local-variable (car elem))
3558              (set (car elem) (eval (nth 1 elem))))))))
3559
3560 (defun gnus-summary-read-group (group &optional show-all no-article
3561                                       kill-buffer no-display backward
3562                                       select-articles)
3563   "Start reading news in newsgroup GROUP.
3564 If SHOW-ALL is non-nil, already read articles are also listed.
3565 If NO-ARTICLE is non-nil, no article is selected initially.
3566 If NO-DISPLAY, don't generate a summary buffer."
3567   (let (result)
3568     (while (and group
3569                 (null (setq result
3570                             (let ((gnus-auto-select-next nil))
3571                               (or (gnus-summary-read-group-1
3572                                    group show-all no-article
3573                                    kill-buffer no-display
3574                                    select-articles)
3575                                   (setq show-all nil
3576                                         select-articles nil)))))
3577                 (eq gnus-auto-select-next 'quietly))
3578       (set-buffer gnus-group-buffer)
3579       ;; The entry function called above goes to the next
3580       ;; group automatically, so we go two groups back
3581       ;; if we are searching for the previous group.
3582       (when backward
3583         (gnus-group-prev-unread-group 2))
3584       (if (not (equal group (gnus-group-group-name)))
3585           (setq group (gnus-group-group-name))
3586         (setq group nil)))
3587     result))
3588
3589 (defun gnus-summary-read-group-1 (group show-all no-article
3590                                         kill-buffer no-display
3591                                         &optional select-articles)
3592   ;; Killed foreign groups can't be entered.
3593   ;;  (when (and (not (gnus-group-native-p group))
3594   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3595   ;;    (error "Dead non-native groups can't be entered"))
3596   (gnus-message 5 "Retrieving newsgroup: %s..."
3597                 (gnus-group-decoded-name group))
3598   (let* ((new-group (gnus-summary-setup-buffer group))
3599          (quit-config (gnus-group-quit-config group))
3600          (did-select (and new-group (gnus-select-newsgroup
3601                                      group show-all select-articles))))
3602     (cond
3603      ;; This summary buffer exists already, so we just select it.
3604      ((not new-group)
3605       (gnus-set-global-variables)
3606       (when kill-buffer
3607         (gnus-kill-or-deaden-summary kill-buffer))
3608       (gnus-configure-windows 'summary 'force)
3609       (gnus-set-mode-line 'summary)
3610       (gnus-summary-position-point)
3611       (message "")
3612       t)
3613      ;; We couldn't select this group.
3614      ((null did-select)
3615       (when (and (eq major-mode 'gnus-summary-mode)
3616                  (not (equal (current-buffer) kill-buffer)))
3617         (kill-buffer (current-buffer))
3618         (if (not quit-config)
3619             (progn
3620               ;; Update the info -- marks might need to be removed,
3621               ;; for instance.
3622               (gnus-summary-update-info)
3623               (set-buffer gnus-group-buffer)
3624               (gnus-group-jump-to-group group)
3625               (gnus-group-next-unread-group 1))
3626           (gnus-handle-ephemeral-exit quit-config)))
3627       (let ((grpinfo (gnus-get-info group)))
3628         (if (null (gnus-info-read grpinfo))
3629             (gnus-message 3 "Group %s contains no messages"
3630                           (gnus-group-decoded-name group))
3631           (gnus-message 3 "Can't select group")))
3632       nil)
3633      ;; The user did a `C-g' while prompting for number of articles,
3634      ;; so we exit this group.
3635      ((eq did-select 'quit)
3636       (and (eq major-mode 'gnus-summary-mode)
3637            (not (equal (current-buffer) kill-buffer))
3638            (kill-buffer (current-buffer)))
3639       (when kill-buffer
3640         (gnus-kill-or-deaden-summary kill-buffer))
3641       (if (not quit-config)
3642           (progn
3643             (set-buffer gnus-group-buffer)
3644             (gnus-group-jump-to-group group)
3645             (gnus-group-next-unread-group 1)
3646             (gnus-configure-windows 'group 'force))
3647         (gnus-handle-ephemeral-exit quit-config))
3648       ;; Finally signal the quit.
3649       (signal 'quit nil))
3650      ;; The group was successfully selected.
3651      (t
3652       (gnus-set-global-variables)
3653       ;; Save the active value in effect when the group was entered.
3654       (setq gnus-newsgroup-active
3655             (gnus-copy-sequence
3656              (gnus-active gnus-newsgroup-name)))
3657       ;; You can change the summary buffer in some way with this hook.
3658       (gnus-run-hooks 'gnus-select-group-hook)
3659       (when (memq 'summary (gnus-update-format-specifications
3660                             nil 'summary 'summary-mode 'summary-dummy))
3661         ;; The format specification for the summary line was updated,
3662         ;; so we need to update the mark positions as well.
3663         (gnus-update-summary-mark-positions))
3664       ;; Do score processing.
3665       (when gnus-use-scoring
3666         (gnus-possibly-score-headers))
3667       ;; Check whether to fill in the gaps in the threads.
3668       (when gnus-build-sparse-threads
3669         (gnus-build-sparse-threads))
3670       ;; Find the initial limit.
3671       (if show-all
3672           (let ((gnus-newsgroup-dormant nil))
3673             (gnus-summary-initial-limit show-all))
3674         (gnus-summary-initial-limit show-all))
3675       ;; Generate the summary buffer.
3676       (unless no-display
3677         (gnus-summary-prepare))
3678       (when gnus-use-trees
3679         (gnus-tree-open group)
3680         (setq gnus-summary-highlight-line-function
3681               'gnus-tree-highlight-article))
3682       ;; If the summary buffer is empty, but there are some low-scored
3683       ;; articles or some excluded dormants, we include these in the
3684       ;; buffer.
3685       (when (and (zerop (buffer-size))
3686                  (not no-display))
3687         (cond (gnus-newsgroup-dormant
3688                (gnus-summary-limit-include-dormant))
3689               ((and gnus-newsgroup-scored show-all)
3690                (gnus-summary-limit-include-expunged t))))
3691       ;; Function `gnus-apply-kill-file' must be called in this hook.
3692       (gnus-run-hooks 'gnus-apply-kill-hook)
3693       (if (and (zerop (buffer-size))
3694                (not no-display))
3695           (progn
3696             ;; This newsgroup is empty.
3697             (gnus-summary-catchup-and-exit nil t)
3698             (gnus-message 6 "No unread news")
3699             (when kill-buffer
3700               (gnus-kill-or-deaden-summary kill-buffer))
3701             ;; Return nil from this function.
3702             nil)
3703         ;; Hide conversation thread subtrees.  We cannot do this in
3704         ;; gnus-summary-prepare-hook since kill processing may not
3705         ;; work with hidden articles.
3706         (gnus-summary-maybe-hide-threads)
3707         (when kill-buffer
3708           (gnus-kill-or-deaden-summary kill-buffer))
3709         (gnus-summary-auto-select-subject)
3710         ;; Show first unread article if requested.
3711         (if (and (not no-article)
3712                  (not no-display)
3713                  gnus-newsgroup-unreads
3714                  gnus-auto-select-first)
3715             (progn
3716               (gnus-configure-windows 'summary)
3717               (let ((art (gnus-summary-article-number)))
3718                 (unless (and (not gnus-plugged)
3719                              (or (memq art gnus-newsgroup-undownloaded)
3720                                  (memq art gnus-newsgroup-downloadable)))
3721                   (gnus-summary-goto-article art))))
3722           ;; Don't select any articles.
3723           (gnus-summary-position-point)
3724           (gnus-configure-windows 'summary 'force)
3725           (gnus-set-mode-line 'summary))
3726         (when (and gnus-auto-center-group
3727                    (get-buffer-window gnus-group-buffer t))
3728           ;; Gotta use windows, because recenter does weird stuff if
3729           ;; the current buffer ain't the displayed window.
3730           (let ((owin (selected-window)))
3731             (select-window (get-buffer-window gnus-group-buffer t))
3732             (when (gnus-group-goto-group group)
3733               (recenter))
3734             (select-window owin)))
3735         ;; Mark this buffer as "prepared".
3736         (setq gnus-newsgroup-prepared t)
3737         (gnus-run-hooks 'gnus-summary-prepared-hook)
3738         (unless (gnus-ephemeral-group-p group)
3739           (gnus-group-update-group group))
3740         t)))))
3741
3742 (defun gnus-summary-auto-select-subject ()
3743   "Select the subject line on initial group entry."
3744   (goto-char (point-min))
3745   (cond
3746    ((eq gnus-auto-select-subject 'best)
3747     (gnus-summary-best-unread-subject))
3748    ((eq gnus-auto-select-subject 'unread)
3749     (gnus-summary-first-unread-subject))
3750    ((eq gnus-auto-select-subject 'unseen)
3751     (gnus-summary-first-unseen-subject))
3752    ((eq gnus-auto-select-subject 'unseen-or-unread)
3753     (gnus-summary-first-unseen-or-unread-subject))
3754    ((eq gnus-auto-select-subject 'first)
3755     ;; Do nothing.
3756     )
3757    ((functionp gnus-auto-select-subject)
3758     (funcall gnus-auto-select-subject))))
3759
3760 (defun gnus-summary-prepare ()
3761   "Generate the summary buffer."
3762   (interactive)
3763   (let ((buffer-read-only nil))
3764     (erase-buffer)
3765     (setq gnus-newsgroup-data nil
3766           gnus-newsgroup-data-reverse nil)
3767     (gnus-run-hooks 'gnus-summary-generate-hook)
3768     ;; Generate the buffer, either with threads or without.
3769     (when gnus-newsgroup-headers
3770       (gnus-summary-prepare-threads
3771        (if gnus-show-threads
3772            (gnus-sort-gathered-threads
3773             (funcall gnus-summary-thread-gathering-function
3774                      (gnus-sort-threads
3775                       (gnus-cut-threads (gnus-make-threads)))))
3776          ;; Unthreaded display.
3777          (gnus-sort-articles gnus-newsgroup-headers))))
3778     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3779     ;; Call hooks for modifying summary buffer.
3780     (goto-char (point-min))
3781     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3782
3783 (defsubst gnus-general-simplify-subject (subject)
3784   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3785   (setq subject
3786         (cond
3787          ;; Truncate the subject.
3788          (gnus-simplify-subject-functions
3789           (gnus-map-function gnus-simplify-subject-functions subject))
3790          ((numberp gnus-summary-gather-subject-limit)
3791           (setq subject (gnus-simplify-subject-re subject))
3792           (if (> (length subject) gnus-summary-gather-subject-limit)
3793               (substring subject 0 gnus-summary-gather-subject-limit)
3794             subject))
3795          ;; Fuzzily simplify it.
3796          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3797           (gnus-simplify-subject-fuzzy subject))
3798          ;; Just remove the leading "Re:".
3799          (t
3800           (gnus-simplify-subject-re subject))))
3801
3802   (if (and gnus-summary-gather-exclude-subject
3803            (string-match gnus-summary-gather-exclude-subject subject))
3804       nil                         ; This article shouldn't be gathered
3805     subject))
3806
3807 (defun gnus-summary-simplify-subject-query ()
3808   "Query where the respool algorithm would put this article."
3809   (interactive)
3810   (gnus-summary-select-article)
3811   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3812
3813 (defun gnus-gather-threads-by-subject (threads)
3814   "Gather threads by looking at Subject headers."
3815   (if (not gnus-summary-make-false-root)
3816       threads
3817     (let ((hashtb (gnus-make-hashtable 1024))
3818           (prev threads)
3819           (result threads)
3820           subject hthread whole-subject)
3821       (while threads
3822         (setq subject (gnus-general-simplify-subject
3823                        (setq whole-subject (mail-header-subject
3824                                             (caar threads)))))
3825         (when subject
3826           (if (setq hthread (gnus-gethash subject hashtb))
3827               (progn
3828                 ;; We enter a dummy root into the thread, if we
3829                 ;; haven't done that already.
3830                 (unless (stringp (caar hthread))
3831                   (setcar hthread (list whole-subject (car hthread))))
3832                 ;; We add this new gathered thread to this gathered
3833                 ;; thread.
3834                 (setcdr (car hthread)
3835                         (nconc (cdar hthread) (list (car threads))))
3836                 ;; Remove it from the list of threads.
3837                 (setcdr prev (cdr threads))
3838                 (setq threads prev))
3839             ;; Enter this thread into the hash table.
3840             (gnus-sethash subject
3841                           (if gnus-summary-make-false-root-always
3842                               (progn
3843                                 ;; If you want a dummy root above all
3844                                 ;; threads...
3845                                 (setcar threads (list whole-subject
3846                                                       (car threads)))
3847                                 threads)
3848                             threads)
3849                           hashtb)))
3850         (setq prev threads)
3851         (setq threads (cdr threads)))
3852       result)))
3853
3854 (defun gnus-gather-threads-by-references (threads)
3855   "Gather threads by looking at References headers."
3856   (let ((idhashtb (gnus-make-hashtable 1024))
3857         (thhashtb (gnus-make-hashtable 1024))
3858         (prev threads)
3859         (result threads)
3860         ids references id gthread gid entered ref)
3861     (while threads
3862       (when (setq references (mail-header-references (caar threads)))
3863         (setq id (mail-header-id (caar threads))
3864               ids (inline (gnus-split-references references))
3865               entered nil)
3866         (while (setq ref (pop ids))
3867           (setq ids (delete ref ids))
3868           (if (not (setq gid (gnus-gethash ref idhashtb)))
3869               (progn
3870                 (gnus-sethash ref id idhashtb)
3871                 (gnus-sethash id threads thhashtb))
3872             (setq gthread (gnus-gethash gid thhashtb))
3873             (unless entered
3874               ;; We enter a dummy root into the thread, if we
3875               ;; haven't done that already.
3876               (unless (stringp (caar gthread))
3877                 (setcar gthread (list (mail-header-subject (caar gthread))
3878                                       (car gthread))))
3879               ;; We add this new gathered thread to this gathered
3880               ;; thread.
3881               (setcdr (car gthread)
3882                       (nconc (cdar gthread) (list (car threads)))))
3883             ;; Add it into the thread hash table.
3884             (gnus-sethash id gthread thhashtb)
3885             (setq entered t)
3886             ;; Remove it from the list of threads.
3887             (setcdr prev (cdr threads))
3888             (setq threads prev))))
3889       (setq prev threads)
3890       (setq threads (cdr threads)))
3891     result))
3892
3893 (defun gnus-sort-gathered-threads (threads)
3894   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3895   (let ((result threads))
3896     (while threads
3897       (when (stringp (caar threads))
3898         (setcdr (car threads)
3899                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3900       (setq threads (cdr threads)))
3901     result))
3902
3903 (defun gnus-thread-loop-p (root thread)
3904   "Say whether ROOT is in THREAD."
3905   (let ((stack (list thread))
3906         (infloop 0)
3907         th)
3908     (while (setq thread (pop stack))
3909       (setq th (cdr thread))
3910       (while (and th
3911                   (not (eq (caar th) root)))
3912         (pop th))
3913       (if th
3914           ;; We have found a loop.
3915           (let (ref-dep)
3916             (setcdr thread (delq (car th) (cdr thread)))
3917             (if (boundp (setq ref-dep (intern "none"
3918                                               gnus-newsgroup-dependencies)))
3919                 (setcdr (symbol-value ref-dep)
3920                         (nconc (cdr (symbol-value ref-dep))
3921                                (list (car th))))
3922               (set ref-dep (list nil (car th))))
3923             (setq infloop 1
3924                   stack nil))
3925         ;; Push all the subthreads onto the stack.
3926         (push (cdr thread) stack)))
3927     infloop))
3928
3929 (defun gnus-make-threads ()
3930   "Go through the dependency hashtb and find the roots.  Return all threads."
3931   (let (threads)
3932     (while (catch 'infloop
3933              (mapatoms
3934               (lambda (refs)
3935                 ;; Deal with self-referencing References loops.
3936                 (when (and (car (symbol-value refs))
3937                            (not (zerop
3938                                  (apply
3939                                   '+
3940                                   (mapcar
3941                                    (lambda (thread)
3942                                      (gnus-thread-loop-p
3943                                       (car (symbol-value refs)) thread))
3944                                    (cdr (symbol-value refs)))))))
3945                   (setq threads nil)
3946                   (throw 'infloop t))
3947                 (unless (car (symbol-value refs))
3948                   ;; These threads do not refer back to any other
3949                   ;; articles, so they're roots.
3950                   (setq threads (append (cdr (symbol-value refs)) threads))))
3951               gnus-newsgroup-dependencies)))
3952     threads))
3953
3954 ;; Build the thread tree.
3955 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3956   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3957
3958 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3959 if it was already present.
3960
3961 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3962 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3963 Message-IDs will be renamed to a unique Message-ID before being
3964 entered.
3965
3966 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3967   (let* ((id (mail-header-id header))
3968          (id-dep (and id (intern id dependencies)))
3969          parent-id ref ref-dep ref-header replaced)
3970     ;; Enter this `header' in the `dependencies' table.
3971     (cond
3972      ((not id-dep)
3973       (setq header nil))
3974      ;; The first two cases do the normal part: enter a new `header'
3975      ;; in the `dependencies' table.
3976      ((not (boundp id-dep))
3977       (set id-dep (list header)))
3978      ((null (car (symbol-value id-dep)))
3979       (setcar (symbol-value id-dep) header))
3980
3981      ;; From here the `header' was already present in the
3982      ;; `dependencies' table.
3983      (force-new
3984       ;; Overrides an existing entry;
3985       ;; just set the header part of the entry.
3986       (setcar (symbol-value id-dep) header)
3987       (setq replaced t))
3988
3989      ;; Renames the existing `header' to a unique Message-ID.
3990      ((not gnus-summary-ignore-duplicates)
3991       ;; An article with this Message-ID has already been seen.
3992       ;; We rename the Message-ID.
3993       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3994            (list header))
3995       (mail-header-set-id header id))
3996
3997      ;; The last case ignores an existing entry, except it adds any
3998      ;; additional Xrefs (in case the two articles came from different
3999      ;; servers.
4000      ;; Also sets `header' to `nil' meaning that the `dependencies'
4001      ;; table was *not* modified.
4002      (t
4003       (mail-header-set-xref
4004        (car (symbol-value id-dep))
4005        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4006                    "")
4007                (or (mail-header-xref header) "")))
4008       (setq header nil)))
4009
4010     (when (and header (not replaced))
4011       ;; First check that we are not creating a References loop.
4012       (setq parent-id (gnus-parent-id (mail-header-references header)))
4013       (setq ref parent-id)
4014       (while (and ref
4015                   (setq ref-dep (intern-soft ref dependencies))
4016                   (boundp ref-dep)
4017                   (setq ref-header (car (symbol-value ref-dep))))
4018         (if (string= id ref)
4019             ;; Yuk!  This is a reference loop.  Make the article be a
4020             ;; root article.
4021             (progn
4022               (mail-header-set-references (car (symbol-value id-dep)) "none")
4023               (setq ref nil)
4024               (setq parent-id nil))
4025           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4026       (setq ref-dep (intern (or parent-id "none") dependencies))
4027       (if (boundp ref-dep)
4028           (setcdr (symbol-value ref-dep)
4029                   (nconc (cdr (symbol-value ref-dep))
4030                          (list (symbol-value id-dep))))
4031         (set ref-dep (list nil (symbol-value id-dep)))))
4032     header))
4033
4034 (defun gnus-extract-message-id-from-in-reply-to (string)
4035   (if (string-match "<[^>]+>" string)
4036       (substring string (match-beginning 0) (match-end 0))
4037     nil))
4038
4039 (defun gnus-build-sparse-threads ()
4040   (let ((headers gnus-newsgroup-headers)
4041         (mail-parse-charset gnus-newsgroup-charset)
4042         (gnus-summary-ignore-duplicates t)
4043         header references generation relations
4044         subject child end new-child date)
4045     ;; First we create an alist of generations/relations, where
4046     ;; generations is how much we trust the relation, and the relation
4047     ;; is parent/child.
4048     (gnus-message 7 "Making sparse threads...")
4049     (save-excursion
4050       (nnheader-set-temp-buffer " *gnus sparse threads*")
4051       (while (setq header (pop headers))
4052         (when (and (setq references (mail-header-references header))
4053                    (not (string= references "")))
4054           (insert references)
4055           (setq child (mail-header-id header)
4056                 subject (mail-header-subject header)
4057                 date (mail-header-date header)
4058                 generation 0)
4059           (while (search-backward ">" nil t)
4060             (setq end (1+ (point)))
4061             (when (search-backward "<" nil t)
4062               (setq new-child (buffer-substring (point) end))
4063               (push (list (incf generation)
4064                           child (setq child new-child)
4065                           subject date)
4066                     relations)))
4067           (when child
4068             (push (list (1+ generation) child nil subject) relations))
4069           (erase-buffer)))
4070       (kill-buffer (current-buffer)))
4071     ;; Sort over trustworthiness.
4072     (mapcar
4073      (lambda (relation)
4074        (when (gnus-dependencies-add-header
4075               (make-full-mail-header
4076                gnus-reffed-article-number
4077                (nth 3 relation) "" (or (nth 4 relation) "")
4078                (nth 1 relation)
4079                (or (nth 2 relation) "") 0 0 "")
4080               gnus-newsgroup-dependencies nil)
4081          (push gnus-reffed-article-number gnus-newsgroup-limit)
4082          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4083          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4084                gnus-newsgroup-reads)
4085          (decf gnus-reffed-article-number)))
4086      (sort relations 'car-less-than-car))
4087     (gnus-message 7 "Making sparse threads...done")))
4088
4089 (defun gnus-build-old-threads ()
4090   ;; Look at all the articles that refer back to old articles, and
4091   ;; fetch the headers for the articles that aren't there.  This will
4092   ;; build complete threads - if the roots haven't been expired by the
4093   ;; server, that is.
4094   (let ((mail-parse-charset gnus-newsgroup-charset)
4095         id heads)
4096     (mapatoms
4097      (lambda (refs)
4098        (when (not (car (symbol-value refs)))
4099          (setq heads (cdr (symbol-value refs)))
4100          (while heads
4101            (if (memq (mail-header-number (caar heads))
4102                      gnus-newsgroup-dormant)
4103                (setq heads (cdr heads))
4104              (setq id (symbol-name refs))
4105              (while (and (setq id (gnus-build-get-header id))
4106                          (not (car (gnus-id-to-thread id)))))
4107              (setq heads nil)))))
4108      gnus-newsgroup-dependencies)))
4109
4110 (defsubst gnus-remove-odd-characters (string)
4111   "Translate STRING into something that doesn't contain weird characters."
4112   (mm-subst-char-in-string
4113    ?\r ?\-
4114    (mm-subst-char-in-string ?\n ?\- string t) t))
4115
4116 ;; This function has to be called with point after the article number
4117 ;; on the beginning of the line.
4118 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4119   (let ((eol (point-at-eol))
4120         (buffer (current-buffer))
4121         header references in-reply-to)
4122
4123     ;; overview: [num subject from date id refs chars lines misc]
4124     (unwind-protect
4125         (let (x)
4126           (narrow-to-region (point) eol)
4127           (unless (eobp)
4128             (forward-char))
4129
4130           (setq header
4131                 (make-full-mail-header
4132                  number                 ; number
4133                  (condition-case ()     ; subject
4134                      (gnus-remove-odd-characters
4135                       (funcall gnus-decode-encoded-word-function
4136                                (setq x (nnheader-nov-field))))
4137                    (error x))
4138                  (condition-case ()     ; from
4139                      (gnus-remove-odd-characters
4140                       (funcall gnus-decode-encoded-word-function
4141                                (setq x (nnheader-nov-field))))
4142                    (error x))
4143                  (nnheader-nov-field)   ; date
4144                  (nnheader-nov-read-message-id number)  ; id
4145                  (setq references (nnheader-nov-field)) ; refs
4146                  (nnheader-nov-read-integer) ; chars
4147                  (nnheader-nov-read-integer) ; lines
4148                  (unless (eobp)
4149                    (if (looking-at "Xref: ")
4150                        (goto-char (match-end 0)))
4151                    (nnheader-nov-field)) ; Xref
4152                  (nnheader-nov-parse-extra)))) ; extra
4153
4154       (widen))
4155
4156     (when (and (string= references "")
4157                (setq in-reply-to (mail-header-extra header))
4158                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4159       (mail-header-set-references
4160        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4161
4162     (when gnus-alter-header-function
4163       (funcall gnus-alter-header-function header))
4164     (gnus-dependencies-add-header header dependencies force-new)))
4165
4166 (defun gnus-build-get-header (id)
4167   "Look through the buffer of NOV lines and find the header to ID.
4168 Enter this line into the dependencies hash table, and return
4169 the id of the parent article (if any)."
4170   (let ((deps gnus-newsgroup-dependencies)
4171         found header)
4172     (prog1
4173         (save-excursion
4174           (set-buffer nntp-server-buffer)
4175           (let ((case-fold-search nil))
4176             (goto-char (point-min))
4177             (while (and (not found)
4178                         (search-forward id nil t))
4179               (beginning-of-line)
4180               (setq found (looking-at
4181                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4182                                    (regexp-quote id))))
4183               (or found (beginning-of-line 2)))
4184             (when found
4185               (beginning-of-line)
4186               (and
4187                (setq header (gnus-nov-parse-line
4188                              (read (current-buffer)) deps))
4189                (gnus-parent-id (mail-header-references header))))))
4190       (when header
4191         (let ((number (mail-header-number header)))
4192           (push number gnus-newsgroup-limit)
4193           (push header gnus-newsgroup-headers)
4194           (if (memq number gnus-newsgroup-unselected)
4195               (progn
4196                 (setq gnus-newsgroup-unreads
4197                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4198                                                number))
4199                 (setq gnus-newsgroup-unselected
4200                       (delq number gnus-newsgroup-unselected)))
4201             (push number gnus-newsgroup-ancient)))))))
4202
4203 (defun gnus-build-all-threads ()
4204   "Read all the headers."
4205   (let ((gnus-summary-ignore-duplicates t)
4206         (mail-parse-charset gnus-newsgroup-charset)
4207         (dependencies gnus-newsgroup-dependencies)
4208         header article)
4209     (save-excursion
4210       (set-buffer nntp-server-buffer)
4211       (let ((case-fold-search nil))
4212         (goto-char (point-min))
4213         (while (not (eobp))
4214           (ignore-errors
4215             (setq article (read (current-buffer))
4216                   header (gnus-nov-parse-line article dependencies)))
4217           (when header
4218             (with-current-buffer gnus-summary-buffer
4219               (push header gnus-newsgroup-headers)
4220               (if (memq (setq article (mail-header-number header))
4221                         gnus-newsgroup-unselected)
4222                   (progn
4223                     (setq gnus-newsgroup-unreads
4224                           (gnus-add-to-sorted-list
4225                            gnus-newsgroup-unreads article))
4226                     (setq gnus-newsgroup-unselected
4227                           (delq article gnus-newsgroup-unselected)))
4228                 (push article gnus-newsgroup-ancient)))
4229             (forward-line 1)))))))
4230
4231 (defun gnus-summary-update-article-line (article header)
4232   "Update the line for ARTICLE using HEADER."
4233   (let* ((id (mail-header-id header))
4234          (thread (gnus-id-to-thread id)))
4235     (unless thread
4236       (error "Article in no thread"))
4237     ;; Update the thread.
4238     (setcar thread header)
4239     (gnus-summary-goto-subject article)
4240     (let* ((datal (gnus-data-find-list article))
4241            (data (car datal))
4242            (buffer-read-only nil)
4243            (level (gnus-summary-thread-level)))
4244       (gnus-delete-line)
4245       (let ((inserted (- (point)
4246                          (progn
4247                            (gnus-summary-insert-line
4248                             header level nil
4249                             (memq article gnus-newsgroup-undownloaded)
4250                             (gnus-article-mark article)
4251                             (memq article gnus-newsgroup-replied)
4252                             (memq article gnus-newsgroup-expirable)
4253                             ;; Only insert the Subject string when it's different
4254                             ;; from the previous Subject string.
4255                             (if (and
4256                                  gnus-show-threads
4257                                  (gnus-subject-equal
4258                                   (condition-case ()
4259                                       (mail-header-subject
4260                                        (gnus-data-header
4261                                         (cadr
4262                                          (gnus-data-find-list
4263                                           article
4264                                           (gnus-data-list t)))))
4265                                     ;; Error on the side of excessive subjects.
4266                                     (error ""))
4267                                   (mail-header-subject header)))
4268                                 ""
4269                               (mail-header-subject header))
4270                             nil (cdr (assq article gnus-newsgroup-scored))
4271                             (memq article gnus-newsgroup-processable))
4272                            (point)))))
4273         (when (cdr datal)
4274           (gnus-data-update-list
4275            (cdr datal)
4276            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4277
4278 (defun gnus-summary-update-article (article &optional iheader)
4279   "Update ARTICLE in the summary buffer."
4280   (set-buffer gnus-summary-buffer)
4281   (let* ((header (gnus-summary-article-header article))
4282          (id (mail-header-id header))
4283          (data (gnus-data-find article))
4284          (thread (gnus-id-to-thread id))
4285          (references (mail-header-references header))
4286          (parent
4287           (gnus-id-to-thread
4288            (or (gnus-parent-id
4289                 (when (and references
4290                            (not (equal "" references)))
4291                   references))
4292                "none")))
4293          (buffer-read-only nil)
4294          (old (car thread)))
4295     (when thread
4296       (unless iheader
4297         (setcar thread nil)
4298         (when parent
4299           (delq thread parent)))
4300       (if (gnus-summary-insert-subject id header)
4301           ;; Set the (possibly) new article number in the data structure.
4302           (gnus-data-set-number data (gnus-id-to-article id))
4303         (setcar thread old)
4304         nil))))
4305
4306 (defun gnus-rebuild-thread (id &optional line)
4307   "Rebuild the thread containing ID.
4308 If LINE, insert the rebuilt thread starting on line LINE."
4309   (let ((buffer-read-only nil)
4310         old-pos current thread data)
4311     (if (not gnus-show-threads)
4312         (setq thread (list (car (gnus-id-to-thread id))))
4313       ;; Get the thread this article is part of.
4314       (setq thread (gnus-remove-thread id)))
4315     (setq old-pos (point-at-bol))
4316     (setq current (save-excursion
4317                     (and (re-search-backward "[\r\n]" nil t)
4318                          (gnus-summary-article-number))))
4319     ;; If this is a gathered thread, we have to go some re-gathering.
4320     (when (stringp (car thread))
4321       (let ((subject (car thread))
4322             roots thr)
4323         (setq thread (cdr thread))
4324         (while thread
4325           (unless (memq (setq thr (gnus-id-to-thread
4326                                    (gnus-root-id
4327                                     (mail-header-id (caar thread)))))
4328                         roots)
4329             (push thr roots))
4330           (setq thread (cdr thread)))
4331         ;; We now have all (unique) roots.
4332         (if (= (length roots) 1)
4333             ;; All the loose roots are now one solid root.
4334             (setq thread (car roots))
4335           (setq thread (cons subject (gnus-sort-threads roots))))))
4336     (let (threads)
4337       ;; We then insert this thread into the summary buffer.
4338       (when line
4339         (goto-char (point-min))
4340         (forward-line (1- line)))
4341       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4342         (if gnus-show-threads
4343             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4344           (gnus-summary-prepare-unthreaded thread))
4345         (setq data (nreverse gnus-newsgroup-data))
4346         (setq threads gnus-newsgroup-threads))
4347       ;; We splice the new data into the data structure.
4348       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4349       ;;!!! then we want to insert at the beginning of the buffer.
4350       ;;!!! That happens to be true with Gnus now, but that may
4351       ;;!!! change in the future.  Perhaps.
4352       (gnus-data-enter-list
4353        (if line nil current) data (- (point) old-pos))
4354       (setq gnus-newsgroup-threads
4355             (nconc threads gnus-newsgroup-threads))
4356       (gnus-data-compute-positions))))
4357
4358 (defun gnus-number-to-header (number)
4359   "Return the header for article NUMBER."
4360   (let ((headers gnus-newsgroup-headers))
4361     (while (and headers
4362                 (not (= number (mail-header-number (car headers)))))
4363       (pop headers))
4364     (when headers
4365       (car headers))))
4366
4367 (defun gnus-parent-headers (in-headers &optional generation)
4368   "Return the headers of the GENERATIONeth parent of HEADERS."
4369   (unless generation
4370     (setq generation 1))
4371   (let ((parent t)
4372         (headers in-headers)
4373         references)
4374     (while (and parent
4375                 (not (zerop generation))
4376                 (setq references (mail-header-references headers)))
4377       (setq headers (if (and references
4378                              (setq parent (gnus-parent-id references)))
4379                         (car (gnus-id-to-thread parent))
4380                       nil))
4381       (decf generation))
4382     (and (not (eq headers in-headers))
4383          headers)))
4384
4385 (defun gnus-id-to-thread (id)
4386   "Return the (sub-)thread where ID appears."
4387   (gnus-gethash id gnus-newsgroup-dependencies))
4388
4389 (defun gnus-id-to-article (id)
4390   "Return the article number of ID."
4391   (let ((thread (gnus-id-to-thread id)))
4392     (when (and thread
4393                (car thread))
4394       (mail-header-number (car thread)))))
4395
4396 (defun gnus-id-to-header (id)
4397   "Return the article headers of ID."
4398   (car (gnus-id-to-thread id)))
4399
4400 (defun gnus-article-displayed-root-p (article)
4401   "Say whether ARTICLE is a root(ish) article."
4402   (let ((level (gnus-summary-thread-level article))
4403         (refs (mail-header-references  (gnus-summary-article-header article)))
4404         particle)
4405     (cond
4406      ((null level) nil)
4407      ((zerop level) t)
4408      ((null refs) t)
4409      ((null (gnus-parent-id refs)) t)
4410      ((and (= 1 level)
4411            (null (setq particle (gnus-id-to-article
4412                                  (gnus-parent-id refs))))
4413            (null (gnus-summary-thread-level particle)))))))
4414
4415 (defun gnus-root-id (id)
4416   "Return the id of the root of the thread where ID appears."
4417   (let (last-id prev)
4418     (while (and id (setq prev (car (gnus-id-to-thread id))))
4419       (setq last-id id
4420             id (gnus-parent-id (mail-header-references prev))))
4421     last-id))
4422
4423 (defun gnus-articles-in-thread (thread)
4424   "Return the list of articles in THREAD."
4425   (cons (mail-header-number (car thread))
4426         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4427
4428 (defun gnus-remove-thread (id &optional dont-remove)
4429   "Remove the thread that has ID in it."
4430   (let (headers thread last-id)
4431     ;; First go up in this thread until we find the root.
4432     (setq last-id (gnus-root-id id)
4433           headers (message-flatten-list (gnus-id-to-thread last-id)))
4434     ;; We have now found the real root of this thread.  It might have
4435     ;; been gathered into some loose thread, so we have to search
4436     ;; through the threads to find the thread we wanted.
4437     (let ((threads gnus-newsgroup-threads)
4438           sub)
4439       (while threads
4440         (setq sub (car threads))
4441         (if (stringp (car sub))
4442             ;; This is a gathered thread, so we look at the roots
4443             ;; below it to find whether this article is in this
4444             ;; gathered root.
4445             (progn
4446               (setq sub (cdr sub))
4447               (while sub
4448                 (when (member (caar sub) headers)
4449                   (setq thread (car threads)
4450                         threads nil
4451                         sub nil))
4452                 (setq sub (cdr sub))))
4453           ;; It's an ordinary thread, so we check it.
4454           (when (eq (car sub) (car headers))
4455             (setq thread sub
4456                   threads nil)))
4457         (setq threads (cdr threads)))
4458       ;; If this article is in no thread, then it's a root.
4459       (if thread
4460           (unless dont-remove
4461             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4462         (setq thread (gnus-id-to-thread last-id)))
4463       (when thread
4464         (prog1
4465             thread                      ; We return this thread.
4466           (unless dont-remove
4467             (if (stringp (car thread))
4468                 (progn
4469                   ;; If we use dummy roots, then we have to remove the
4470                   ;; dummy root as well.
4471                   (when (eq gnus-summary-make-false-root 'dummy)
4472                     ;; We go to the dummy root by going to
4473                     ;; the first sub-"thread", and then one line up.
4474                     (gnus-summary-goto-article
4475                      (mail-header-number (caadr thread)))
4476                     (forward-line -1)
4477                     (gnus-delete-line)
4478                     (gnus-data-compute-positions))
4479                   (setq thread (cdr thread))
4480                   (while thread
4481                     (gnus-remove-thread-1 (car thread))
4482                     (setq thread (cdr thread))))
4483               (gnus-remove-thread-1 thread))))))))
4484
4485 (defun gnus-remove-thread-1 (thread)
4486   "Remove the thread THREAD recursively."
4487   (let ((number (mail-header-number (pop thread)))
4488         d)
4489     (setq thread (reverse thread))
4490     (while thread
4491       (gnus-remove-thread-1 (pop thread)))
4492     (when (setq d (gnus-data-find number))
4493       (goto-char (gnus-data-pos d))
4494       (gnus-summary-show-thread)
4495       (gnus-data-remove
4496        number
4497        (- (point-at-bol)
4498           (prog1
4499               (1+ (point-at-eol))
4500             (gnus-delete-line)))))))
4501
4502 (defun gnus-sort-threads-1 (threads func)
4503   (sort (mapcar (lambda (thread)
4504                   (cons (car thread)
4505                         (and (cdr thread)
4506                              (gnus-sort-threads-1 (cdr thread) func))))
4507                 threads) func))
4508
4509 (defun gnus-sort-threads (threads)
4510   "Sort THREADS."
4511   (if (not gnus-thread-sort-functions)
4512       threads
4513     (gnus-message 8 "Sorting threads...")
4514     (let ((max-lisp-eval-depth 5000))
4515       (prog1 (gnus-sort-threads-1
4516          threads
4517          (gnus-make-sort-function gnus-thread-sort-functions))
4518         (gnus-message 8 "Sorting threads...done")))))
4519
4520 (defun gnus-sort-articles (articles)
4521   "Sort ARTICLES."
4522   (when gnus-article-sort-functions
4523     (gnus-message 7 "Sorting articles...")
4524     (prog1
4525         (setq gnus-newsgroup-headers
4526               (sort articles (gnus-make-sort-function
4527                               gnus-article-sort-functions)))
4528       (gnus-message 7 "Sorting articles...done"))))
4529
4530 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4531 (defmacro gnus-thread-header (thread)
4532   "Return header of first article in THREAD.
4533 Note that THREAD must never, ever be anything else than a variable -
4534 using some other form will lead to serious barfage."
4535   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4536   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4537   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4538         (vector thread) 2))
4539
4540 (defsubst gnus-article-sort-by-number (h1 h2)
4541   "Sort articles by article number."
4542   (< (mail-header-number h1)
4543      (mail-header-number h2)))
4544
4545 (defun gnus-thread-sort-by-number (h1 h2)
4546   "Sort threads by root article number."
4547   (gnus-article-sort-by-number
4548    (gnus-thread-header h1) (gnus-thread-header h2)))
4549
4550 (defsubst gnus-article-sort-by-random (h1 h2)
4551   "Sort articles by article number."
4552   (zerop (random 2)))
4553
4554 (defun gnus-thread-sort-by-random (h1 h2)
4555   "Sort threads by root article number."
4556   (gnus-article-sort-by-random
4557    (gnus-thread-header h1) (gnus-thread-header h2)))
4558
4559 (defsubst gnus-article-sort-by-lines (h1 h2)
4560   "Sort articles by article Lines header."
4561   (< (mail-header-lines h1)
4562      (mail-header-lines h2)))
4563
4564 (defun gnus-thread-sort-by-lines (h1 h2)
4565   "Sort threads by root article Lines header."
4566   (gnus-article-sort-by-lines
4567    (gnus-thread-header h1) (gnus-thread-header h2)))
4568
4569 (defsubst gnus-article-sort-by-chars (h1 h2)
4570   "Sort articles by octet length."
4571   (< (mail-header-chars h1)
4572      (mail-header-chars h2)))
4573
4574 (defun gnus-thread-sort-by-chars (h1 h2)
4575   "Sort threads by root article octet length."
4576   (gnus-article-sort-by-chars
4577    (gnus-thread-header h1) (gnus-thread-header h2)))
4578
4579 (defsubst gnus-article-sort-by-author (h1 h2)
4580   "Sort articles by root author."
4581   (string-lessp
4582    (let ((extract (funcall
4583                    gnus-extract-address-components
4584                    (mail-header-from h1))))
4585      (or (car extract) (cadr extract) ""))
4586    (let ((extract (funcall
4587                    gnus-extract-address-components
4588                    (mail-header-from h2))))
4589      (or (car extract) (cadr extract) ""))))
4590
4591 (defun gnus-thread-sort-by-author (h1 h2)
4592   "Sort threads by root author."
4593   (gnus-article-sort-by-author
4594    (gnus-thread-header h1)  (gnus-thread-header h2)))
4595
4596 (defsubst gnus-article-sort-by-recipient (h1 h2)
4597   "Sort articles by recipient."
4598   (string-lessp
4599    (let ((extract (funcall
4600                    gnus-extract-address-components
4601                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4602      (or (car extract) (cadr extract)))
4603    (let ((extract (funcall
4604                    gnus-extract-address-components
4605                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4606      (or (car extract) (cadr extract)))))
4607
4608 (defsubst gnus-article-sort-by-subject (h1 h2)
4609   "Sort articles by root subject."
4610   (string-lessp
4611    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4612    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4613
4614 (defun gnus-thread-sort-by-subject (h1 h2)
4615   "Sort threads by root subject."
4616   (gnus-article-sort-by-subject
4617    (gnus-thread-header h1) (gnus-thread-header h2)))
4618
4619 (defsubst gnus-article-sort-by-date (h1 h2)
4620   "Sort articles by root article date."
4621   (time-less-p
4622    (gnus-date-get-time (mail-header-date h1))
4623    (gnus-date-get-time (mail-header-date h2))))
4624
4625 (defun gnus-thread-sort-by-date (h1 h2)
4626   "Sort threads by root article date."
4627   (gnus-article-sort-by-date
4628    (gnus-thread-header h1) (gnus-thread-header h2)))
4629
4630 (defsubst gnus-article-sort-by-score (h1 h2)
4631   "Sort articles by root article score.
4632 Unscored articles will be counted as having a score of zero."
4633   (> (or (cdr (assq (mail-header-number h1)
4634                     gnus-newsgroup-scored))
4635          gnus-summary-default-score 0)
4636      (or (cdr (assq (mail-header-number h2)
4637                     gnus-newsgroup-scored))
4638          gnus-summary-default-score 0)))
4639
4640 (defun gnus-thread-sort-by-score (h1 h2)
4641   "Sort threads by root article score."
4642   (gnus-article-sort-by-score
4643    (gnus-thread-header h1) (gnus-thread-header h2)))
4644
4645 (defun gnus-thread-sort-by-total-score (h1 h2)
4646   "Sort threads by the sum of all scores in the thread.
4647 Unscored articles will be counted as having a score of zero."
4648   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4649
4650 (defun gnus-thread-total-score (thread)
4651   ;; This function find the total score of THREAD.
4652   (cond
4653    ((null thread)
4654     0)
4655    ((consp thread)
4656     (if (stringp (car thread))
4657         (apply gnus-thread-score-function 0
4658                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4659       (gnus-thread-total-score-1 thread)))
4660    (t
4661     (gnus-thread-total-score-1 (list thread)))))
4662
4663 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4664   "Sort threads such that the thread with the most recently arrived article comes first."
4665   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4666
4667 (defun gnus-thread-highest-number (thread)
4668   "Return the highest article number in THREAD."
4669   (apply 'max (mapcar (lambda (header)
4670                         (mail-header-number header))
4671                       (message-flatten-list thread))))
4672
4673 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4674   "Sort threads such that the thread with the most recently dated article comes first."
4675   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4676
4677 (defun gnus-thread-latest-date (thread)
4678   "Return the highest article date in THREAD."
4679   (let ((previous-time 0))
4680     (apply 'max
4681            (mapcar
4682             (lambda (header)
4683               (setq previous-time
4684                     (condition-case ()
4685                         (time-to-seconds (mail-header-parse-date
4686                                           (mail-header-date header)))
4687                       (error previous-time))))
4688             (sort
4689              (message-flatten-list thread)
4690              (lambda (h1 h2)
4691                (< (mail-header-number h1)
4692                   (mail-header-number h2))))))))
4693
4694 (defun gnus-thread-total-score-1 (root)
4695   ;; This function find the total score of the thread below ROOT.
4696   (setq root (car root))
4697   (apply gnus-thread-score-function
4698          (or (append
4699               (mapcar 'gnus-thread-total-score
4700                       (cdr (gnus-id-to-thread (mail-header-id root))))
4701               (when (> (mail-header-number root) 0)
4702                 (list (or (cdr (assq (mail-header-number root)
4703                                      gnus-newsgroup-scored))
4704                           gnus-summary-default-score 0))))
4705              (list gnus-summary-default-score)
4706              '(0))))
4707
4708 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4709 (defvar gnus-tmp-prev-subject nil)
4710 (defvar gnus-tmp-false-parent nil)
4711 (defvar gnus-tmp-root-expunged nil)
4712 (defvar gnus-tmp-dummy-line nil)
4713
4714 (eval-when-compile (defvar gnus-tmp-header))
4715 (defun gnus-extra-header (type &optional header)
4716   "Return the extra header of TYPE."
4717   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4718       ""))
4719
4720 (defvar gnus-tmp-thread-tree-header-string "")
4721
4722 (defcustom gnus-sum-thread-tree-root "> "
4723   "With %B spec, used for the root of a thread.
4724 If nil, use subject instead."
4725   :version "22.1"
4726   :type '(radio (const :format "%v  " nil) string)
4727   :group 'gnus-thread)
4728 (defcustom gnus-sum-thread-tree-false-root "> "
4729   "With %B spec, used for a false root of a thread.
4730 If nil, use subject instead."
4731   :version "22.1"
4732   :type '(radio (const :format "%v  " nil) string)
4733   :group 'gnus-thread)
4734 (defcustom gnus-sum-thread-tree-single-indent ""
4735   "With %B spec, used for a thread with just one message.
4736 If nil, use subject instead."
4737   :version "22.1"
4738   :type '(radio (const :format "%v  " nil) string)
4739   :group 'gnus-thread)
4740 (defcustom gnus-sum-thread-tree-vertical "| "
4741   "With %B spec, used for drawing a vertical line."
4742   :version "22.1"
4743   :type 'string
4744   :group 'gnus-thread)
4745 (defcustom gnus-sum-thread-tree-indent "  "
4746   "With %B spec, used for indenting."
4747   :version "22.1"
4748   :type 'string
4749   :group 'gnus-thread)
4750 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4751   "With %B spec, used for a leaf with brothers."
4752   :version "22.1"
4753   :type 'string
4754   :group 'gnus-thread)
4755 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4756   "With %B spec, used for a leaf without brothers."
4757   :version "22.1"
4758   :type 'string
4759   :group 'gnus-thread)
4760
4761 (defun gnus-summary-prepare-threads (threads)
4762   "Prepare summary buffer from THREADS and indentation LEVEL.
4763 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4764 or a straight list of headers."
4765   (gnus-message 7 "Generating summary...")
4766
4767   (setq gnus-newsgroup-threads threads)
4768   (beginning-of-line)
4769
4770   (let ((gnus-tmp-level 0)
4771         (default-score (or gnus-summary-default-score 0))
4772         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4773         (building-line-count gnus-summary-display-while-building)
4774         (building-count (integerp gnus-summary-display-while-building))
4775         thread number subject stack state gnus-tmp-gathered beg-match
4776         new-roots gnus-tmp-new-adopts thread-end simp-subject
4777         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4778         gnus-tmp-replied gnus-tmp-subject-or-nil
4779         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4780         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4781         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4782         tree-stack)
4783
4784     (setq gnus-tmp-prev-subject nil
4785           gnus-tmp-thread-tree-header-string "")
4786
4787     (if (vectorp (car threads))
4788         ;; If this is a straight (sic) list of headers, then a
4789         ;; threaded summary display isn't required, so we just create
4790         ;; an unthreaded one.
4791         (gnus-summary-prepare-unthreaded threads)
4792
4793       ;; Do the threaded display.
4794
4795       (if gnus-summary-display-while-building
4796           (switch-to-buffer (buffer-name)))
4797       (while (or threads stack gnus-tmp-new-adopts new-roots)
4798
4799         (if (and (= gnus-tmp-level 0)
4800                  (or (not stack)
4801                      (= (caar stack) 0))
4802                  (not gnus-tmp-false-parent)
4803                  (or gnus-tmp-new-adopts new-roots))
4804             (if gnus-tmp-new-adopts
4805                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4806                       thread (list (car gnus-tmp-new-adopts))
4807                       gnus-tmp-header (caar thread)
4808                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4809               (when new-roots
4810                 (setq thread (list (car new-roots))
4811                       gnus-tmp-header (caar thread)
4812                       new-roots (cdr new-roots))))
4813
4814           (if threads
4815               ;; If there are some threads, we do them before the
4816               ;; threads on the stack.
4817               (setq thread threads
4818                     gnus-tmp-header (caar thread))
4819             ;; There were no current threads, so we pop something off
4820             ;; the stack.
4821             (setq state (car stack)
4822                   gnus-tmp-level (car state)
4823                   tree-stack (cadr state)
4824                   thread (caddr state)
4825                   stack (cdr stack)
4826                   gnus-tmp-header (caar thread))))
4827
4828         (setq gnus-tmp-false-parent nil)
4829         (setq gnus-tmp-root-expunged nil)
4830         (setq thread-end nil)
4831
4832         (if (stringp gnus-tmp-header)
4833             ;; The header is a dummy root.
4834             (cond
4835              ((eq gnus-summary-make-false-root 'adopt)
4836               ;; We let the first article adopt the rest.
4837               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4838                                                (cddar thread)))
4839               (setq gnus-tmp-gathered
4840                     (nconc (mapcar
4841                             (lambda (h) (mail-header-number (car h)))
4842                             (cddar thread))
4843                            gnus-tmp-gathered))
4844               (setq thread (cons (list (caar thread)
4845                                        (cadar thread))
4846                                  (cdr thread)))
4847               (setq gnus-tmp-level -1
4848                     gnus-tmp-false-parent t))
4849              ((eq gnus-summary-make-false-root 'empty)
4850               ;; We print adopted articles with empty subject fields.
4851               (setq gnus-tmp-gathered
4852                     (nconc (mapcar
4853                             (lambda (h) (mail-header-number (car h)))
4854                             (cddar thread))
4855                            gnus-tmp-gathered))
4856               (setq gnus-tmp-level -1))
4857              ((eq gnus-summary-make-false-root 'dummy)
4858               ;; We remember that we probably want to output a dummy
4859               ;; root.
4860               (setq gnus-tmp-dummy-line gnus-tmp-header)
4861               (setq gnus-tmp-prev-subject gnus-tmp-header))
4862              (t
4863               ;; We do not make a root for the gathered
4864               ;; sub-threads at all.
4865               (setq gnus-tmp-level -1)))
4866
4867           (setq number (mail-header-number gnus-tmp-header)
4868                 subject (mail-header-subject gnus-tmp-header)
4869                 simp-subject (gnus-simplify-subject-fully subject))
4870
4871           (cond
4872            ;; If the thread has changed subject, we might want to make
4873            ;; this subthread into a root.
4874            ((and (null gnus-thread-ignore-subject)
4875                  (not (zerop gnus-tmp-level))
4876                  gnus-tmp-prev-subject
4877                  (not (string= gnus-tmp-prev-subject simp-subject)))
4878             (setq new-roots (nconc new-roots (list (car thread)))
4879                   thread-end t
4880                   gnus-tmp-header nil))
4881            ;; If the article lies outside the current limit,
4882            ;; then we do not display it.
4883            ((not (memq number gnus-newsgroup-limit))
4884             (setq gnus-tmp-gathered
4885                   (nconc (mapcar
4886                           (lambda (h) (mail-header-number (car h)))
4887                           (cdar thread))
4888                          gnus-tmp-gathered))
4889             (setq gnus-tmp-new-adopts (if (cdar thread)
4890                                           (append gnus-tmp-new-adopts
4891                                                   (cdar thread))
4892                                         gnus-tmp-new-adopts)
4893                   thread-end t
4894                   gnus-tmp-header nil)
4895             (when (zerop gnus-tmp-level)
4896               (setq gnus-tmp-root-expunged t)))
4897            ;; Perhaps this article is to be marked as read?
4898            ((and gnus-summary-mark-below
4899                  (< (or (cdr (assq number gnus-newsgroup-scored))
4900                         default-score)
4901                     gnus-summary-mark-below)
4902                  ;; Don't touch sparse articles.
4903                  (not (gnus-summary-article-sparse-p number))
4904                  (not (gnus-summary-article-ancient-p number)))
4905             (setq gnus-newsgroup-unreads
4906                   (delq number gnus-newsgroup-unreads))
4907             (if gnus-newsgroup-auto-expire
4908                 (setq gnus-newsgroup-expirable
4909                       (gnus-add-to-sorted-list
4910                        gnus-newsgroup-expirable number))
4911               (push (cons number gnus-low-score-mark)
4912                     gnus-newsgroup-reads))))
4913
4914           (when gnus-tmp-header
4915             ;; We may have an old dummy line to output before this
4916             ;; article.
4917             (when (and gnus-tmp-dummy-line
4918                        (gnus-subject-equal
4919                         gnus-tmp-dummy-line
4920                         (mail-header-subject gnus-tmp-header)))
4921               (gnus-summary-insert-dummy-line
4922                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4923               (setq gnus-tmp-dummy-line nil))
4924
4925             ;; Compute the mark.
4926             (setq gnus-tmp-unread (gnus-article-mark number))
4927
4928             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4929                                   gnus-tmp-header gnus-tmp-level)
4930                   gnus-newsgroup-data)
4931
4932             ;; Actually insert the line.
4933             (setq
4934              gnus-tmp-subject-or-nil
4935              (cond
4936               ((and gnus-thread-ignore-subject
4937                     gnus-tmp-prev-subject
4938                     (not (string= gnus-tmp-prev-subject simp-subject)))
4939                subject)
4940               ((zerop gnus-tmp-level)
4941                (if (and (eq gnus-summary-make-false-root 'empty)
4942                         (memq number gnus-tmp-gathered)
4943                         gnus-tmp-prev-subject
4944                         (string= gnus-tmp-prev-subject simp-subject))
4945                    gnus-summary-same-subject
4946                  subject))
4947               (t gnus-summary-same-subject)))
4948             (if (and (eq gnus-summary-make-false-root 'adopt)
4949                      (= gnus-tmp-level 1)
4950                      (memq number gnus-tmp-gathered))
4951                 (setq gnus-tmp-opening-bracket ?\<
4952                       gnus-tmp-closing-bracket ?\>)
4953               (setq gnus-tmp-opening-bracket ?\[
4954                     gnus-tmp-closing-bracket ?\]))
4955             (setq
4956              gnus-tmp-indentation
4957              (aref gnus-thread-indent-array gnus-tmp-level)
4958              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4959              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4960                                 gnus-summary-default-score 0)
4961              gnus-tmp-score-char
4962              (if (or (null gnus-summary-default-score)
4963                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4964                          gnus-summary-zcore-fuzz))
4965                  ?                      ;Whitespace
4966                (if (< gnus-tmp-score gnus-summary-default-score)
4967                    gnus-score-below-mark gnus-score-over-mark))
4968              gnus-tmp-replied
4969              (cond ((memq number gnus-newsgroup-processable)
4970                     gnus-process-mark)
4971                    ((memq number gnus-newsgroup-cached)
4972                     gnus-cached-mark)
4973                    ((memq number gnus-newsgroup-replied)
4974                     gnus-replied-mark)
4975                    ((memq number gnus-newsgroup-forwarded)
4976                     gnus-forwarded-mark)
4977                    ((memq number gnus-newsgroup-saved)
4978                     gnus-saved-mark)
4979                    ((memq number gnus-newsgroup-recent)
4980                     gnus-recent-mark)
4981                    ((memq number gnus-newsgroup-unseen)
4982                     gnus-unseen-mark)
4983                    (t gnus-no-mark))
4984              gnus-tmp-downloaded
4985              (cond ((memq number gnus-newsgroup-undownloaded)
4986                     gnus-undownloaded-mark)
4987                    (gnus-newsgroup-agentized
4988                     gnus-downloaded-mark)
4989                    (t
4990                     gnus-no-mark))
4991              gnus-tmp-from (mail-header-from gnus-tmp-header)
4992              gnus-tmp-name
4993              (cond
4994               ((string-match "<[^>]+> *$" gnus-tmp-from)
4995                (setq beg-match (match-beginning 0))
4996                (or (and (string-match "^\".+\"" gnus-tmp-from)
4997                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4998                    (substring gnus-tmp-from 0 beg-match)))
4999               ((string-match "(.+)" gnus-tmp-from)
5000                (substring gnus-tmp-from
5001                           (1+ (match-beginning 0)) (1- (match-end 0))))
5002               (t gnus-tmp-from))
5003
5004              ;; Do the %B string
5005              gnus-tmp-thread-tree-header-string
5006              (cond
5007               ((not gnus-show-threads) "")
5008               ((zerop gnus-tmp-level)
5009                (cond ((cdar thread)
5010                       (or gnus-sum-thread-tree-root subject))
5011                      (gnus-tmp-new-adopts
5012                       (or gnus-sum-thread-tree-false-root subject))
5013                      (t
5014                       (or gnus-sum-thread-tree-single-indent subject))))
5015               (t
5016                (concat (apply 'concat
5017                               (mapcar (lambda (item)
5018                                         (if (= item 1)
5019                                             gnus-sum-thread-tree-vertical
5020                                           gnus-sum-thread-tree-indent))
5021                                       (cdr (reverse tree-stack))))
5022                        (if (nth 1 thread)
5023                            gnus-sum-thread-tree-leaf-with-other
5024                          gnus-sum-thread-tree-single-leaf)))))
5025             (when (string= gnus-tmp-name "")
5026               (setq gnus-tmp-name gnus-tmp-from))
5027             (unless (numberp gnus-tmp-lines)
5028               (setq gnus-tmp-lines -1))
5029             (if (= gnus-tmp-lines -1)
5030                 (setq gnus-tmp-lines "?")
5031               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5032               (gnus-put-text-property
5033              (point)
5034              (progn (eval gnus-summary-line-format-spec) (point))
5035                'gnus-number number)
5036             (when gnus-visual-p
5037               (forward-line -1)
5038               (gnus-run-hooks 'gnus-summary-update-hook)
5039               (forward-line 1))
5040
5041             (setq gnus-tmp-prev-subject simp-subject)))
5042
5043         (when (nth 1 thread)
5044           (push (list (max 0 gnus-tmp-level)
5045                       (copy-sequence tree-stack)
5046                       (nthcdr 1 thread))
5047                 stack))
5048         (push (if (nth 1 thread) 1 0) tree-stack)
5049         (incf gnus-tmp-level)
5050         (setq threads (if thread-end nil (cdar thread)))
5051         (if gnus-summary-display-while-building
5052             (if building-count
5053                 (progn
5054                   ;; use a set frequency
5055                   (setq building-line-count (1- building-line-count))
5056                   (when (= building-line-count 0)
5057                     (sit-for 0)
5058                     (setq building-line-count
5059                           gnus-summary-display-while-building)))
5060               ;; always
5061               (sit-for 0)))
5062         (unless threads
5063           (setq gnus-tmp-level 0)))))
5064   (gnus-message 7 "Generating summary...done"))
5065
5066 (defun gnus-summary-prepare-unthreaded (headers)
5067   "Generate an unthreaded summary buffer based on HEADERS."
5068   (let (header number mark)
5069
5070     (beginning-of-line)
5071
5072     (while headers
5073       ;; We may have to root out some bad articles...
5074       (when (memq (setq number (mail-header-number
5075                                 (setq header (pop headers))))
5076                   gnus-newsgroup-limit)
5077         ;; Mark article as read when it has a low score.
5078         (when (and gnus-summary-mark-below
5079                    (< (or (cdr (assq number gnus-newsgroup-scored))
5080                           gnus-summary-default-score 0)
5081                       gnus-summary-mark-below)
5082                    (not (gnus-summary-article-ancient-p number)))
5083           (setq gnus-newsgroup-unreads
5084                 (delq number gnus-newsgroup-unreads))
5085           (if gnus-newsgroup-auto-expire
5086               (push number gnus-newsgroup-expirable)
5087             (push (cons number gnus-low-score-mark)
5088                   gnus-newsgroup-reads)))
5089
5090         (setq mark (gnus-article-mark number))
5091         (push (gnus-data-make number mark (1+ (point)) header 0)
5092               gnus-newsgroup-data)
5093         (gnus-summary-insert-line
5094          header 0 number
5095          (memq number gnus-newsgroup-undownloaded)
5096          mark (memq number gnus-newsgroup-replied)
5097          (memq number gnus-newsgroup-expirable)
5098          (mail-header-subject header) nil
5099          (cdr (assq number gnus-newsgroup-scored))
5100          (memq number gnus-newsgroup-processable))))))
5101
5102 (defun gnus-summary-remove-list-identifiers ()
5103   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5104   (let ((regexp (if (consp gnus-list-identifiers)
5105                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5106                   gnus-list-identifiers))
5107         changed subject)
5108     (when regexp
5109       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5110       (dolist (header gnus-newsgroup-headers)
5111         (setq subject (mail-header-subject header)
5112               changed nil)
5113         (while (string-match regexp subject)
5114           (setq subject
5115                 (concat (substring subject 0 (match-beginning 1))
5116                         (substring subject (match-end 0)))
5117                 changed t))
5118         (when changed
5119           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5120             (setq subject
5121                   (concat (substring subject 0 (match-beginning 1))
5122                           (substring subject (match-end 1)))))
5123           (mail-header-set-subject header subject))))))
5124
5125 (defun gnus-fetch-headers (articles)
5126   "Fetch headers of ARTICLES."
5127   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5128     (gnus-message 5 "Fetching headers for %s..." name)
5129     (prog1
5130         (if (eq 'nov
5131                 (setq gnus-headers-retrieved-by
5132                       (gnus-retrieve-headers
5133                        articles gnus-newsgroup-name
5134                        ;; We might want to fetch old headers, but
5135                        ;; not if there is only 1 article.
5136                        (and (or (and
5137                                  (not (eq gnus-fetch-old-headers 'some))
5138                                  (not (numberp gnus-fetch-old-headers)))
5139                                 (> (length articles) 1))
5140                             gnus-fetch-old-headers))))
5141             (gnus-get-newsgroup-headers-xover
5142              articles nil nil gnus-newsgroup-name t)
5143           (gnus-get-newsgroup-headers))
5144       (gnus-message 5 "Fetching headers for %s...done" name))))
5145
5146 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5147   "Select newsgroup GROUP.
5148 If READ-ALL is non-nil, all articles in the group are selected.
5149 If SELECT-ARTICLES, only select those articles from GROUP."
5150   (let* ((entry (gnus-group-entry group))
5151          ;;!!! Dirty hack; should be removed.
5152          (gnus-summary-ignore-duplicates
5153           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5154               t
5155             gnus-summary-ignore-duplicates))
5156          (info (nth 2 entry))
5157          articles fetched-articles cached)
5158
5159     (unless (gnus-check-server
5160              (set (make-local-variable 'gnus-current-select-method)
5161                   (gnus-find-method-for-group group)))
5162       (error "Couldn't open server"))
5163
5164     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5165         (gnus-activate-group group)     ; Or we can activate it...
5166         (progn                          ; Or we bug out.
5167           (when (equal major-mode 'gnus-summary-mode)
5168             (gnus-kill-buffer (current-buffer)))
5169           (error "Couldn't activate group %s: %s"
5170                  group (gnus-status-message group))))
5171
5172     (unless (gnus-request-group group t)
5173       (when (equal major-mode 'gnus-summary-mode)
5174         (gnus-kill-buffer (current-buffer)))
5175       (error "Couldn't request group %s: %s"
5176              group (gnus-status-message group)))
5177
5178     (when gnus-agent
5179       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5180
5181       (setq gnus-summary-use-undownloaded-faces
5182             (gnus-agent-find-parameter
5183              group
5184              'agent-enable-undownloaded-faces)))
5185
5186     (setq gnus-newsgroup-name group
5187           gnus-newsgroup-unselected nil
5188           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5189
5190     (let ((display (gnus-group-find-parameter group 'display)))
5191       (setq gnus-newsgroup-display
5192             (cond
5193              ((not (zerop (or (car-safe read-all) 0)))
5194               ;; The user entered the group with C-u SPC/RET, let's show
5195               ;; all articles.
5196               'gnus-not-ignore)
5197              ((eq display 'all)
5198               'gnus-not-ignore)
5199              ((arrayp display)
5200               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5201              ((numberp display)
5202               ;; The following is probably the "correct" solution, but
5203               ;; it makes Gnus fetch all headers and then limit the
5204               ;; articles (which is slow), so instead we hack the
5205               ;; select-articles parameter instead. -- Simon Josefsson
5206               ;; <jas@kth.se>
5207               ;;
5208               ;; (gnus-byte-compile
5209               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5210               ;;                         display)))))
5211               (setq select-articles
5212                     (gnus-uncompress-range
5213                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5214                              (if (> tmp 0)
5215                                  tmp
5216                                1))
5217                            (cdr (gnus-active group)))))
5218               nil)
5219              (t
5220               nil))))
5221
5222     (gnus-summary-setup-default-charset)
5223
5224     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5225     (when (gnus-virtual-group-p group)
5226       (setq cached gnus-newsgroup-cached))
5227
5228     (setq gnus-newsgroup-unreads
5229           (gnus-sorted-ndifference
5230            (gnus-sorted-ndifference gnus-newsgroup-unreads
5231                                     gnus-newsgroup-marked)
5232            gnus-newsgroup-dormant))
5233
5234     (setq gnus-newsgroup-processable nil)
5235
5236     (gnus-update-read-articles group gnus-newsgroup-unreads)
5237
5238     ;; Adjust and set lists of article marks.
5239     (when info
5240       (gnus-adjust-marked-articles info))
5241     (if (setq articles select-articles)
5242         (setq gnus-newsgroup-unselected
5243               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5244       (setq articles (gnus-articles-to-read group read-all)))
5245
5246     (cond
5247      ((null articles)
5248       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5249       'quit)
5250      ((eq articles 0) nil)
5251      (t
5252       ;; Init the dependencies hash table.
5253       (setq gnus-newsgroup-dependencies
5254             (gnus-make-hashtable (length articles)))
5255       (gnus-set-global-variables)
5256       ;; Retrieve the headers and read them in.
5257
5258       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5259
5260       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5261       (when cached
5262         (setq gnus-newsgroup-cached cached))
5263
5264       ;; Suppress duplicates?
5265       (when gnus-suppress-duplicates
5266         (gnus-dup-suppress-articles))
5267
5268       ;; Set the initial limit.
5269       (setq gnus-newsgroup-limit (copy-sequence articles))
5270       ;; Remove canceled articles from the list of unread articles.
5271       (setq fetched-articles
5272             (mapcar (lambda (headers) (mail-header-number headers))
5273                     gnus-newsgroup-headers))
5274       (setq gnus-newsgroup-articles fetched-articles)
5275       (setq gnus-newsgroup-unreads
5276             (gnus-sorted-nintersection
5277              gnus-newsgroup-unreads fetched-articles))
5278       (gnus-compute-unseen-list)
5279
5280       ;; Removed marked articles that do not exist.
5281       (gnus-update-missing-marks
5282        (gnus-sorted-difference articles fetched-articles))
5283       ;; We might want to build some more threads first.
5284       (when (and gnus-fetch-old-headers
5285                  (eq gnus-headers-retrieved-by 'nov))
5286         (if (eq gnus-fetch-old-headers 'invisible)
5287             (gnus-build-all-threads)
5288           (gnus-build-old-threads)))
5289       ;; Let the Gnus agent mark articles as read.
5290       (when gnus-agent
5291         (gnus-agent-get-undownloaded-list))
5292       ;; Remove list identifiers from subject
5293       (when gnus-list-identifiers
5294         (gnus-summary-remove-list-identifiers))
5295       ;; Check whether auto-expire is to be done in this group.
5296       (setq gnus-newsgroup-auto-expire
5297             (gnus-group-auto-expirable-p group))
5298       ;; Set up the article buffer now, if necessary.
5299       (unless gnus-single-article-buffer
5300         (gnus-article-setup-buffer))
5301       ;; First and last article in this newsgroup.
5302       (when gnus-newsgroup-headers
5303         (setq gnus-newsgroup-begin
5304               (mail-header-number (car gnus-newsgroup-headers))
5305               gnus-newsgroup-end
5306               (mail-header-number
5307                (gnus-last-element gnus-newsgroup-headers))))
5308       ;; GROUP is successfully selected.
5309       (or gnus-newsgroup-headers t)))))
5310
5311 (defun gnus-compute-unseen-list ()
5312   ;; The `seen' marks are treated specially.
5313   (if (not gnus-newsgroup-seen)
5314       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5315     (setq gnus-newsgroup-unseen
5316           (gnus-inverse-list-range-intersection
5317            gnus-newsgroup-articles gnus-newsgroup-seen))))
5318
5319 (defun gnus-summary-display-make-predicate (display)
5320   (require 'gnus-agent)
5321   (when (= (length display) 1)
5322     (setq display (car display)))
5323   (unless gnus-summary-display-cache
5324     (dolist (elem (append '((unread . unread)
5325                             (read . read)
5326                             (unseen . unseen))
5327                           gnus-article-mark-lists))
5328       (push (cons (cdr elem)
5329                   (gnus-byte-compile
5330                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5331             gnus-summary-display-cache)))
5332   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5333         (gnus-category-predicate-cache gnus-summary-display-cache))
5334     (gnus-get-predicate display)))
5335
5336 ;; Uses the dynamically bound `number' variable.
5337 (eval-when-compile
5338   (defvar number))
5339 (defun gnus-article-marked-p (type &optional article)
5340   (let ((article (or article number)))
5341     (cond
5342      ((eq type 'tick)
5343       (memq article gnus-newsgroup-marked))
5344      ((eq type 'spam)
5345       (memq article gnus-newsgroup-spam-marked))
5346      ((eq type 'unsend)
5347       (memq article gnus-newsgroup-unsendable))
5348      ((eq type 'undownload)
5349       (memq article gnus-newsgroup-undownloaded))
5350      ((eq type 'download)
5351       (memq article gnus-newsgroup-downloadable))
5352      ((eq type 'unread)
5353       (memq article gnus-newsgroup-unreads))
5354      ((eq type 'read)
5355       (memq article gnus-newsgroup-reads))
5356      ((eq type 'dormant)
5357       (memq article gnus-newsgroup-dormant) )
5358      ((eq type 'expire)
5359       (memq article gnus-newsgroup-expirable))
5360      ((eq type 'reply)
5361       (memq article gnus-newsgroup-replied))
5362      ((eq type 'killed)
5363       (memq article gnus-newsgroup-killed))
5364      ((eq type 'bookmark)
5365       (assq article gnus-newsgroup-bookmarks))
5366      ((eq type 'score)
5367       (assq article gnus-newsgroup-scored))
5368      ((eq type 'save)
5369       (memq article gnus-newsgroup-saved))
5370      ((eq type 'cache)
5371       (memq article gnus-newsgroup-cached))
5372      ((eq type 'forward)
5373       (memq article gnus-newsgroup-forwarded))
5374      ((eq type 'seen)
5375       (not (memq article gnus-newsgroup-unseen)))
5376      ((eq type 'recent)
5377       (memq article gnus-newsgroup-recent))
5378      (t t))))
5379
5380 (defun gnus-articles-to-read (group &optional read-all)
5381   "Find out what articles the user wants to read."
5382   (let* ((articles
5383           ;; Select all articles if `read-all' is non-nil, or if there
5384           ;; are no unread articles.
5385           (if (or read-all
5386                   (and (zerop (length gnus-newsgroup-marked))
5387                        (zerop (length gnus-newsgroup-unreads)))
5388                   ;; Fetch all if the predicate is non-nil.
5389                   gnus-newsgroup-display)
5390               ;; We want to select the headers for all the articles in
5391               ;; the group, so we select either all the active
5392               ;; articles in the group, or (if that's nil), the
5393               ;; articles in the cache.
5394               (or
5395                (gnus-uncompress-range (gnus-active group))
5396                (gnus-cache-articles-in-group group))
5397             ;; Select only the "normal" subset of articles.
5398             (gnus-sorted-nunion
5399              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5400              gnus-newsgroup-unreads)))
5401          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5402          (scored (length scored-list))
5403          (number (length articles))
5404          (marked (+ (length gnus-newsgroup-marked)
5405                     (length gnus-newsgroup-dormant)))
5406          (select
5407           (cond
5408            ((numberp read-all)
5409             read-all)
5410            ((numberp gnus-newsgroup-display)
5411             gnus-newsgroup-display)
5412            (t
5413             (condition-case ()
5414                 (cond
5415                  ((and (or (<= scored marked) (= scored number))
5416                        (numberp gnus-large-newsgroup)
5417                        (> number gnus-large-newsgroup))
5418                   (let* ((cursor-in-echo-area nil)
5419                          (initial (gnus-parameter-large-newsgroup-initial
5420                                    gnus-newsgroup-name))
5421                          (input
5422                           (read-string
5423                            (format
5424                             "How many articles from %s (%s %d): "
5425                             (gnus-limit-string
5426                              (gnus-group-decoded-name gnus-newsgroup-name)
5427                              35)
5428                             (if initial "max" "default")
5429                             number)
5430                            (if initial
5431                                (cons (number-to-string initial)
5432                                      0)))))
5433                     (if (string-match "^[ \t]*$" input) number input)))
5434                  ((and (> scored marked) (< scored number)
5435                        (> (- scored number) 20))
5436                   (let ((input
5437                          (read-string
5438                           (format "%s %s (%d scored, %d total): "
5439                                   "How many articles from"
5440                                   (gnus-group-decoded-name group)
5441                                   scored number))))
5442                     (if (string-match "^[ \t]*$" input)
5443                         number input)))
5444                  (t number))
5445               (quit
5446                (message "Quit getting the articles to read")
5447                nil))))))
5448     (setq select (if (stringp select) (string-to-number select) select))
5449     (if (or (null select) (zerop select))
5450         select
5451       (if (and (not (zerop scored)) (<= (abs select) scored))
5452           (progn
5453             (setq articles (sort scored-list '<))
5454             (setq number (length articles)))
5455         (setq articles (copy-sequence articles)))
5456
5457       (when (< (abs select) number)
5458         (if (< select 0)
5459             ;; Select the N oldest articles.
5460             (setcdr (nthcdr (1- (abs select)) articles) nil)
5461           ;; Select the N most recent articles.
5462           (setq articles (nthcdr (- number select) articles))))
5463       (setq gnus-newsgroup-unselected
5464             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5465       (when gnus-alter-articles-to-read-function
5466         (setq articles
5467               (sort
5468                (funcall gnus-alter-articles-to-read-function
5469                         gnus-newsgroup-name articles)
5470                '<)))
5471       articles)))
5472
5473 (defun gnus-killed-articles (killed articles)
5474   (let (out)
5475     (while articles
5476       (when (inline (gnus-member-of-range (car articles) killed))
5477         (push (car articles) out))
5478       (setq articles (cdr articles)))
5479     out))
5480
5481 (defun gnus-uncompress-marks (marks)
5482   "Uncompress the mark ranges in MARKS."
5483   (let ((uncompressed '(score bookmark))
5484         out)
5485     (while marks
5486       (if (memq (caar marks) uncompressed)
5487           (push (car marks) out)
5488         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5489       (setq marks (cdr marks)))
5490     out))
5491
5492 (defun gnus-article-mark-to-type (mark)
5493   "Return the type of MARK."
5494   (or (cadr (assq mark gnus-article-special-mark-lists))
5495       'list))
5496
5497 (defun gnus-article-unpropagatable-p (mark)
5498   "Return whether MARK should be propagated to back end."
5499   (memq mark gnus-article-unpropagated-mark-lists))
5500
5501 (defun gnus-adjust-marked-articles (info)
5502   "Set all article lists and remove all marks that are no longer valid."
5503   (let* ((marked-lists (gnus-info-marks info))
5504          (active (gnus-active (gnus-info-group info)))
5505          (min (car active))
5506          (max (cdr active))
5507          (types gnus-article-mark-lists)
5508          marks var articles article mark mark-type
5509          bgn end)
5510
5511     (dolist (marks marked-lists)
5512       (setq mark (car marks)
5513             mark-type (gnus-article-mark-to-type mark)
5514             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5515
5516       ;; We set the variable according to the type of the marks list,
5517       ;; and then adjust the marks to a subset of the active articles.
5518       (cond
5519        ;; Adjust "simple" lists - compressed yet unsorted
5520        ((eq mark-type 'list)
5521         ;; Simultaneously uncompress and clip to active range
5522         ;; See gnus-uncompress-range for a description of possible marks
5523         (let (l lh)
5524           (if (not (cadr marks))
5525               (set var nil)
5526             (setq articles (if (numberp (cddr marks))
5527                                (list (cdr marks))
5528                              (cdr marks))
5529                   lh (cons nil nil)
5530                   l lh)
5531
5532             (while (setq article (pop articles))
5533               (cond ((consp article)
5534                      (setq bgn (max (car article) min)
5535                            end (min (cdr article) max))
5536                      (while (<= bgn end)
5537                        (setq l (setcdr l (cons bgn nil))
5538                              bgn (1+ bgn))))
5539                     ((and (<= min article)
5540                           (>= max article))
5541                      (setq l (setcdr l (cons article nil))))))
5542             (set var (cdr lh)))))
5543        ;; Adjust assocs.
5544        ((eq mark-type 'tuple)
5545         (set var (setq articles (cdr marks)))
5546         (when (not (listp (cdr (symbol-value var))))
5547           (set var (list (symbol-value var))))
5548         (when (not (listp (cdr articles)))
5549           (setq articles (list articles)))
5550         (while articles
5551           (when (or (not (consp (setq article (pop articles))))
5552                     (< (car article) min)
5553                     (> (car article) max))
5554             (set var (delq article (symbol-value var))))))
5555        ;; Adjust ranges (sloppily).
5556        ((eq mark-type 'range)
5557         (cond
5558          ((eq mark 'seen)
5559           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5560           ;; It should be (seen (NUM1 . NUM2)).
5561           (when (numberp (cddr marks))
5562             (setcdr marks (list (cdr marks))))
5563           (setq articles (cdr marks))
5564           (while (and articles
5565                       (or (and (consp (car articles))
5566                                (> min (cdar articles)))
5567                           (and (numberp (car articles))
5568                                (> min (car articles)))))
5569             (pop articles))
5570           (set var articles))))))))
5571
5572 (defun gnus-update-missing-marks (missing)
5573   "Go through the list of MISSING articles and remove them from the mark lists."
5574   (when missing
5575     (let (var m)
5576       ;; Go through all types.
5577       (dolist (elem gnus-article-mark-lists)
5578         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5579           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5580           (when (symbol-value var)
5581             ;; This list has articles.  So we delete all missing
5582             ;; articles from it.
5583             (setq m missing)
5584             (while m
5585               (set var (delq (pop m) (symbol-value var))))))))))
5586
5587 (defun gnus-update-marks ()
5588   "Enter the various lists of marked articles into the newsgroup info list."
5589   (let ((types gnus-article-mark-lists)
5590         (info (gnus-get-info gnus-newsgroup-name))
5591         type list newmarked symbol delta-marks)
5592     (when info
5593       ;; Add all marks lists to the list of marks lists.
5594       (while (setq type (pop types))
5595         (setq list (symbol-value
5596                     (setq symbol
5597                           (intern (format "gnus-newsgroup-%s" (car type))))))
5598
5599         (when list
5600           ;; Get rid of the entries of the articles that have the
5601           ;; default score.
5602           (when (and (eq (cdr type) 'score)
5603                      gnus-save-score
5604                      list)
5605             (let* ((arts list)
5606                    (prev (cons nil list))
5607                    (all prev))
5608               (while arts
5609                 (if (or (not (consp (car arts)))
5610                         (= (cdar arts) gnus-summary-default-score))
5611                     (setcdr prev (cdr arts))
5612                   (setq prev arts))
5613                 (setq arts (cdr arts)))
5614               (setq list (cdr all)))))
5615
5616         (when (eq (cdr type) 'seen)
5617           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5618
5619         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5620           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5621
5622         (when (and (gnus-check-backend-function
5623                     'request-set-mark gnus-newsgroup-name)
5624                    (not (gnus-article-unpropagatable-p (cdr type))))
5625           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5626                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5627                  (add (gnus-remove-from-range
5628                        (gnus-copy-sequence list) old)))
5629             (when add
5630               (push (list add 'add (list (cdr type))) delta-marks))
5631             (when del
5632               (push (list del 'del (list (cdr type))) delta-marks))))
5633
5634         (when list
5635           (push (cons (cdr type) list) newmarked)))
5636
5637       (when delta-marks
5638         (unless (gnus-check-group gnus-newsgroup-name)
5639           (error "Can't open server for %s" gnus-newsgroup-name))
5640         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5641
5642       ;; Enter these new marks into the info of the group.
5643       (if (nthcdr 3 info)
5644           (setcar (nthcdr 3 info) newmarked)
5645         ;; Add the marks lists to the end of the info.
5646         (when newmarked
5647           (setcdr (nthcdr 2 info) (list newmarked))))
5648
5649       ;; Cut off the end of the info if there's nothing else there.
5650       (let ((i 5))
5651         (while (and (> i 2)
5652                     (not (nth i info)))
5653           (when (nthcdr (decf i) info)
5654             (setcdr (nthcdr i info) nil)))))))
5655
5656 (defun gnus-set-mode-line (where)
5657   "Set the mode line of the article or summary buffers.
5658 If WHERE is `summary', the summary mode line format will be used."
5659   ;; Is this mode line one we keep updated?
5660   (when (and (memq where gnus-updated-mode-lines)
5661              (symbol-value
5662               (intern (format "gnus-%s-mode-line-format-spec" where))))
5663     (let (mode-string)
5664       (save-excursion
5665         ;; We evaluate this in the summary buffer since these
5666         ;; variables are buffer-local to that buffer.
5667         (set-buffer gnus-summary-buffer)
5668        ;; We bind all these variables that are used in the `eval' form
5669         ;; below.
5670         (let* ((mformat (symbol-value
5671                          (intern
5672                           (format "gnus-%s-mode-line-format-spec" where))))
5673                (gnus-tmp-group-name (gnus-group-decoded-name
5674                                      gnus-newsgroup-name))
5675                (gnus-tmp-article-number (or gnus-current-article 0))
5676                (gnus-tmp-unread gnus-newsgroup-unreads)
5677                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5678                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5679                (gnus-tmp-unread-and-unselected
5680                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5681                             (zerop gnus-tmp-unselected))
5682                        "")
5683                       ((zerop gnus-tmp-unselected)
5684                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5685                       (t (format "{%d(+%d) more}"
5686                                  gnus-tmp-unread-and-unticked
5687                                  gnus-tmp-unselected))))
5688                (gnus-tmp-subject
5689                 (if (and gnus-current-headers
5690                          (vectorp gnus-current-headers))
5691                     (gnus-mode-string-quote
5692                      (mail-header-subject gnus-current-headers))
5693                   ""))
5694                bufname-length max-len
5695                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5696           (setq mode-string (eval mformat))
5697           (setq bufname-length (if (string-match "%b" mode-string)
5698                                    (- (length
5699                                        (buffer-name
5700                                         (if (eq where 'summary)
5701                                             nil
5702                                           (get-buffer gnus-article-buffer))))
5703                                       2)
5704                                  0))
5705           (setq max-len (max 4 (if gnus-mode-non-string-length
5706                                    (- (window-width)
5707                                       gnus-mode-non-string-length
5708                                       bufname-length)
5709                                  (length mode-string))))
5710           ;; We might have to chop a bit of the string off...
5711           (when (> (length mode-string) max-len)
5712             (setq mode-string
5713                   (concat (truncate-string-to-width mode-string (- max-len 3))
5714                           "...")))
5715           ;; Pad the mode string a bit.
5716           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5717       ;; Update the mode line.
5718       (setq mode-line-buffer-identification
5719             (gnus-mode-line-buffer-identification (list mode-string)))
5720       (set-buffer-modified-p t))))
5721
5722 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5723   "Go through the HEADERS list and add all Xrefs to a hash table.
5724 The resulting hash table is returned, or nil if no Xrefs were found."
5725   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5726          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5727          (xref-hashtb (gnus-make-hashtable))
5728          start group entry number xrefs header)
5729     (while headers
5730       (setq header (pop headers))
5731       (when (and (setq xrefs (mail-header-xref header))
5732                  (not (memq (setq number (mail-header-number header))
5733                             unreads)))
5734         (setq start 0)
5735         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5736           (setq start (match-end 0))
5737           (setq group (if prefix
5738                           (concat prefix (substring xrefs (match-beginning 1)
5739                                                     (match-end 1)))
5740                         (substring xrefs (match-beginning 1) (match-end 1))))
5741           (setq number
5742                 (string-to-number (substring xrefs (match-beginning 2)
5743                                           (match-end 2))))
5744           (if (setq entry (gnus-gethash group xref-hashtb))
5745               (setcdr entry (cons number (cdr entry)))
5746             (gnus-sethash group (cons number nil) xref-hashtb)))))
5747     (and start xref-hashtb)))
5748
5749 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5750   "Look through all the headers and mark the Xrefs as read."
5751   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5752         name info xref-hashtb idlist method nth4)
5753     (save-excursion
5754       (set-buffer gnus-group-buffer)
5755       (when (setq xref-hashtb
5756                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5757         (mapatoms
5758          (lambda (group)
5759            (unless (string= from-newsgroup (setq name (symbol-name group)))
5760              (setq idlist (symbol-value group))
5761              ;; Dead groups are not updated.
5762              (and (prog1
5763                       (setq info (gnus-get-info name))
5764                     (when (stringp (setq nth4 (gnus-info-method info)))
5765                       (setq nth4 (gnus-server-to-method nth4))))
5766                   ;; Only do the xrefs if the group has the same
5767                   ;; select method as the group we have just read.
5768                   (or (gnus-methods-equal-p
5769                        nth4 (gnus-find-method-for-group from-newsgroup))
5770                       virtual
5771                       (equal nth4 (setq method (gnus-find-method-for-group
5772                                                 from-newsgroup)))
5773                       (and (equal (car nth4) (car method))
5774                            (equal (nth 1 nth4) (nth 1 method))))
5775                   gnus-use-cross-reference
5776                   (or (not (eq gnus-use-cross-reference t))
5777                       virtual
5778                       ;; Only do cross-references on subscribed
5779                       ;; groups, if that is what is wanted.
5780                       (<= (gnus-info-level info) gnus-level-subscribed))
5781                   (gnus-group-make-articles-read name idlist))))
5782          xref-hashtb)))))
5783
5784 (defun gnus-compute-read-articles (group articles)
5785   (let* ((entry (gnus-group-entry group))
5786          (info (nth 2 entry))
5787          (active (gnus-active group))
5788          ninfo)
5789     (when entry
5790       ;; First peel off all invalid article numbers.
5791       (when active
5792         (let ((ids articles)
5793               id first)
5794           (while (setq id (pop ids))
5795             (when (and first (> id (cdr active)))
5796               ;; We'll end up in this situation in one particular
5797               ;; obscure situation.  If you re-scan a group and get
5798               ;; a new article that is cross-posted to a different
5799               ;; group that has not been re-scanned, you might get
5800               ;; crossposted article that has a higher number than
5801               ;; Gnus believes possible.  So we re-activate this
5802               ;; group as well.  This might mean doing the
5803               ;; crossposting thingy will *increase* the number
5804               ;; of articles in some groups.  Tsk, tsk.
5805               (setq active (or (gnus-activate-group group) active)))
5806             (when (or (> id (cdr active))
5807                       (< id (car active)))
5808               (setq articles (delq id articles))))))
5809       ;; If the read list is nil, we init it.
5810       (if (and active
5811                (null (gnus-info-read info))
5812                (> (car active) 1))
5813           (setq ninfo (cons 1 (1- (car active))))
5814         (setq ninfo (gnus-info-read info)))
5815       ;; Then we add the read articles to the range.
5816       (gnus-add-to-range
5817        ninfo (setq articles (sort articles '<))))))
5818
5819 (defun gnus-group-make-articles-read (group articles)
5820   "Update the info of GROUP to say that ARTICLES are read."
5821   (let* ((num 0)
5822          (entry (gnus-group-entry group))
5823          (info (nth 2 entry))
5824          (active (gnus-active group))
5825          range)
5826     (when entry
5827       (setq range (gnus-compute-read-articles group articles))
5828       (with-current-buffer gnus-group-buffer
5829         (gnus-undo-register
5830           `(progn
5831              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5832              (gnus-info-set-read ',info ',(gnus-info-read info))
5833              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5834              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5835              (gnus-group-update-group ,group t))))
5836       ;; Add the read articles to the range.
5837       (gnus-info-set-read info range)
5838       (gnus-request-set-mark group (list (list range 'add '(read))))
5839       ;; Then we have to re-compute how many unread
5840       ;; articles there are in this group.
5841       (when active
5842         (cond
5843          ((not range)
5844           (setq num (- (1+ (cdr active)) (car active))))
5845          ((not (listp (cdr range)))
5846           (setq num (- (cdr active) (- (1+ (cdr range))
5847                                        (car range)))))
5848          (t
5849           (while range
5850             (if (numberp (car range))
5851                 (setq num (1+ num))
5852               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5853             (setq range (cdr range)))
5854           (setq num (- (cdr active) num))))
5855         ;; Update the number of unread articles.
5856         (setcar entry num)
5857         ;; Update the group buffer.
5858         (unless (gnus-ephemeral-group-p group)
5859           (gnus-group-update-group group t))))))
5860
5861 (defvar gnus-newsgroup-none-id 0)
5862
5863 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5864   (let ((cur nntp-server-buffer)
5865         (dependencies
5866          (or dependencies
5867              (with-current-buffer gnus-summary-buffer
5868                gnus-newsgroup-dependencies)))
5869         headers id end ref number
5870         (mail-parse-charset gnus-newsgroup-charset)
5871         (mail-parse-ignored-charsets
5872          (save-excursion (condition-case nil
5873                              (set-buffer gnus-summary-buffer)
5874                            (error))
5875                          gnus-newsgroup-ignored-charsets)))
5876     (save-excursion
5877       (set-buffer nntp-server-buffer)
5878       ;; Translate all TAB characters into SPACE characters.
5879       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5880       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5881       (ietf-drums-unfold-fws)
5882       (gnus-run-hooks 'gnus-parse-headers-hook)
5883       (let ((case-fold-search t)
5884             in-reply-to header p lines chars)
5885         (goto-char (point-min))
5886         ;; Search to the beginning of the next header.  Error messages
5887         ;; do not begin with 2 or 3.
5888         (while (re-search-forward "^[23][0-9]+ " nil t)
5889           (setq id nil
5890                 ref nil)
5891           ;; This implementation of this function, with nine
5892           ;; search-forwards instead of the one re-search-forward and
5893           ;; a case (which basically was the old function) is actually
5894           ;; about twice as fast, even though it looks messier.  You
5895           ;; can't have everything, I guess.  Speed and elegance
5896           ;; doesn't always go hand in hand.
5897           (setq
5898            header
5899            (vector
5900             ;; Number.
5901             (prog1
5902                 (setq number (read cur))
5903               (end-of-line)
5904               (setq p (point))
5905               (narrow-to-region (point)
5906                                 (or (and (search-forward "\n.\n" nil t)
5907                                          (- (point) 2))
5908                                     (point))))
5909             ;; Subject.
5910             (progn
5911               (goto-char p)
5912               (if (search-forward "\nsubject:" nil t)
5913                   (funcall gnus-decode-encoded-word-function
5914                            (nnheader-header-value))
5915                 "(none)"))
5916             ;; From.
5917             (progn
5918               (goto-char p)
5919               (if (search-forward "\nfrom:" nil t)
5920                   (funcall gnus-decode-encoded-word-function
5921                            (nnheader-header-value))
5922                 "(nobody)"))
5923             ;; Date.
5924             (progn
5925               (goto-char p)
5926               (if (search-forward "\ndate:" nil t)
5927                   (nnheader-header-value) ""))
5928             ;; Message-ID.
5929             (progn
5930               (goto-char p)
5931               (setq id (if (re-search-forward
5932                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5933                            ;; We do it this way to make sure the Message-ID
5934                            ;; is (somewhat) syntactically valid.
5935                            (buffer-substring (match-beginning 1)
5936                                              (match-end 1))
5937                          ;; If there was no message-id, we just fake one
5938                          ;; to make subsequent routines simpler.
5939                          (nnheader-generate-fake-message-id number))))
5940             ;; References.
5941             (progn
5942               (goto-char p)
5943               (if (search-forward "\nreferences:" nil t)
5944                   (progn
5945                     (setq end (point))
5946                     (prog1
5947                         (nnheader-header-value)
5948                       (setq ref
5949                             (buffer-substring
5950                              (progn
5951                                (end-of-line)
5952                                (search-backward ">" end t)
5953                                (1+ (point)))
5954                              (progn
5955                                (search-backward "<" end t)
5956                                (point))))))
5957                 ;; Get the references from the in-reply-to header if there
5958                 ;; were no references and the in-reply-to header looks
5959                 ;; promising.
5960                 (if (and (search-forward "\nin-reply-to:" nil t)
5961                          (setq in-reply-to (nnheader-header-value))
5962                          (string-match "<[^>]+>" in-reply-to))
5963                     (let (ref2)
5964                       (setq ref (substring in-reply-to (match-beginning 0)
5965                                            (match-end 0)))
5966                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5967                         (setq ref2 (substring in-reply-to (match-beginning 0)
5968                                               (match-end 0)))
5969                         (when (> (length ref2) (length ref))
5970                           (setq ref ref2)))
5971                       ref)
5972                   (setq ref nil))))
5973             ;; Chars.
5974             (progn
5975               (goto-char p)
5976               (if (search-forward "\nchars: " nil t)
5977                   (if (numberp (setq chars (ignore-errors (read cur))))
5978                       chars -1)
5979                 -1))
5980             ;; Lines.
5981             (progn
5982               (goto-char p)
5983               (if (search-forward "\nlines: " nil t)
5984                   (if (numberp (setq lines (ignore-errors (read cur))))
5985                       lines -1)
5986                 -1))
5987             ;; Xref.
5988             (progn
5989               (goto-char p)
5990               (and (search-forward "\nxref:" nil t)
5991                    (nnheader-header-value)))
5992             ;; Extra.
5993             (when gnus-extra-headers
5994               (let ((extra gnus-extra-headers)
5995                     out)
5996                 (while extra
5997                   (goto-char p)
5998                   (when (search-forward
5999                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6000                     (push (cons (car extra) (nnheader-header-value))
6001                           out))
6002                   (pop extra))
6003                 out))))
6004           (when (equal id ref)
6005             (setq ref nil))
6006
6007           (when gnus-alter-header-function
6008             (funcall gnus-alter-header-function header)
6009             (setq id (mail-header-id header)
6010                   ref (gnus-parent-id (mail-header-references header))))
6011
6012           (when (setq header
6013                       (gnus-dependencies-add-header
6014                        header dependencies force-new))
6015             (push header headers))
6016           (goto-char (point-max))
6017           (widen))
6018         (nreverse headers)))))
6019
6020 ;; Goes through the xover lines and returns a list of vectors
6021 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6022                                                   force-new dependencies
6023                                                   group also-fetch-heads)
6024   "Parse the news overview data in the server buffer.
6025 Return a list of headers that match SEQUENCE (see
6026 `nntp-retrieve-headers')."
6027   ;; Get the Xref when the users reads the articles since most/some
6028   ;; NNTP servers do not include Xrefs when using XOVER.
6029   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6030   (let ((mail-parse-charset gnus-newsgroup-charset)
6031         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6032         (cur nntp-server-buffer)
6033         (dependencies (or dependencies gnus-newsgroup-dependencies))
6034         (allp (cond
6035                ((eq gnus-read-all-available-headers t)
6036                 t)
6037                ((stringp gnus-read-all-available-headers)
6038                 (string-match gnus-read-all-available-headers group))
6039                (t
6040                 nil)))
6041         number headers header)
6042     (save-excursion
6043       (set-buffer nntp-server-buffer)
6044       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6045       ;; Allow the user to mangle the headers before parsing them.
6046       (gnus-run-hooks 'gnus-parse-headers-hook)
6047       (goto-char (point-min))
6048       (gnus-parse-without-error
6049         (while (and (or sequence allp)
6050                     (not (eobp)))
6051           (setq number (read cur))
6052           (when (not allp)
6053             (while (and sequence
6054                         (< (car sequence) number))
6055               (setq sequence (cdr sequence))))
6056           (when (and (or allp
6057                          (and sequence
6058                               (eq number (car sequence))))
6059                      (progn
6060                        (setq sequence (cdr sequence))
6061                        (setq header (inline
6062                                       (gnus-nov-parse-line
6063                                        number dependencies force-new)))))
6064             (push header headers))
6065           (forward-line 1)))
6066       ;; A common bug in inn is that if you have posted an article and
6067       ;; then retrieves the active file, it will answer correctly --
6068       ;; the new article is included.  However, a NOV entry for the
6069       ;; article may not have been generated yet, so this may fail.
6070       ;; We work around this problem by retrieving the last few
6071       ;; headers using HEAD.
6072       (if (or (not also-fetch-heads)
6073               (not sequence))
6074           ;; We (probably) got all the headers.
6075           (nreverse headers)
6076         (let ((gnus-nov-is-evil t))
6077           (nconc
6078            (nreverse headers)
6079            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6080              (gnus-get-newsgroup-headers))))))))
6081
6082 (defun gnus-article-get-xrefs ()
6083   "Fill in the Xref value in `gnus-current-headers', if necessary.
6084 This is meant to be called in `gnus-article-internal-prepare-hook'."
6085   (let ((headers (with-current-buffer gnus-summary-buffer
6086                    gnus-current-headers)))
6087     (or (not gnus-use-cross-reference)
6088         (not headers)
6089         (and (mail-header-xref headers)
6090              (not (string= (mail-header-xref headers) "")))
6091         (let ((case-fold-search t)
6092               xref)
6093           (save-restriction
6094             (nnheader-narrow-to-headers)
6095             (goto-char (point-min))
6096             (when (or (and (not (eobp))
6097                            (eq (downcase (char-after)) ?x)
6098                            (looking-at "Xref:"))
6099                       (search-forward "\nXref:" nil t))
6100               (goto-char (1+ (match-end 0)))
6101               (setq xref (buffer-substring (point) (point-at-eol)))
6102               (mail-header-set-xref headers xref)))))))
6103
6104 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6105   "Find article ID and insert the summary line for that article.
6106 OLD-HEADER can either be a header or a line number to insert
6107 the subject line on."
6108   (let* ((line (and (numberp old-header) old-header))
6109          (old-header (and (vectorp old-header) old-header))
6110          (header (cond ((and old-header use-old-header)
6111                         old-header)
6112                        ((and (numberp id)
6113                              (gnus-number-to-header id))
6114                         (gnus-number-to-header id))
6115                        (t
6116                         (gnus-read-header id))))
6117          (number (and (numberp id) id))
6118          d)
6119     (when header
6120       ;; Rebuild the thread that this article is part of and go to the
6121       ;; article we have fetched.
6122       (when (and (not gnus-show-threads)
6123                  old-header)
6124         (when (and number
6125                    (setq d (gnus-data-find (mail-header-number old-header))))
6126           (goto-char (gnus-data-pos d))
6127           (gnus-data-remove
6128            number
6129            (- (point-at-bol)
6130               (prog1
6131                   (1+ (point-at-eol))
6132                 (gnus-delete-line))))))
6133       ;; Remove list identifiers from subject.
6134       (when gnus-list-identifiers
6135         (let ((gnus-newsgroup-headers (list header)))
6136           (gnus-summary-remove-list-identifiers)))
6137       (when old-header
6138         (mail-header-set-number header (mail-header-number old-header)))
6139       (setq gnus-newsgroup-sparse
6140             (delq (setq number (mail-header-number header))
6141                   gnus-newsgroup-sparse))
6142       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6143       (push number gnus-newsgroup-limit)
6144       (gnus-rebuild-thread (mail-header-id header) line)
6145       (gnus-summary-goto-subject number nil t))
6146     (when (and (numberp number)
6147                (> number 0))
6148       ;; We have to update the boundaries even if we can't fetch the
6149       ;; article if ID is a number -- so that the next `P' or `N'
6150       ;; command will fetch the previous (or next) article even
6151       ;; if the one we tried to fetch this time has been canceled.
6152       (when (> number gnus-newsgroup-end)
6153         (setq gnus-newsgroup-end number))
6154       (when (< number gnus-newsgroup-begin)
6155         (setq gnus-newsgroup-begin number))
6156       (setq gnus-newsgroup-unselected
6157             (delq number gnus-newsgroup-unselected)))
6158     ;; Report back a success?
6159     (and header (mail-header-number header))))
6160
6161 ;;; Process/prefix in the summary buffer
6162
6163 (defun gnus-summary-work-articles (n)
6164   "Return a list of articles to be worked upon.
6165 The prefix argument, the list of process marked articles, and the
6166 current article will be taken into consideration."
6167   (save-excursion
6168     (set-buffer gnus-summary-buffer)
6169     (cond
6170      (n
6171       ;; A numerical prefix has been given.
6172       (setq n (prefix-numeric-value n))
6173       (let ((backward (< n 0))
6174             (n (abs (prefix-numeric-value n)))
6175             articles article)
6176         (save-excursion
6177           (while
6178               (and (> n 0)
6179                    (push (setq article (gnus-summary-article-number))
6180                          articles)
6181                    (if backward
6182                        (gnus-summary-find-prev nil article)
6183                      (gnus-summary-find-next nil article)))
6184             (decf n)))
6185         (nreverse articles)))
6186      ((and (gnus-region-active-p) (mark))
6187       (message "region active")
6188       ;; Work on the region between point and mark.
6189       (let ((max (max (point) (mark)))
6190             articles article)
6191         (save-excursion
6192           (goto-char (min (min (point) (mark))))
6193           (while
6194               (and
6195                (push (setq article (gnus-summary-article-number)) articles)
6196                (gnus-summary-find-next nil article)
6197                (< (point) max)))
6198           (nreverse articles))))
6199      (gnus-newsgroup-processable
6200       ;; There are process-marked articles present.
6201       ;; Save current state.
6202       (gnus-summary-save-process-mark)
6203       ;; Return the list.
6204       (reverse gnus-newsgroup-processable))
6205      (t
6206       ;; Just return the current article.
6207       (list (gnus-summary-article-number))))))
6208
6209 (defmacro gnus-summary-iterate (arg &rest forms)
6210   "Iterate over the process/prefixed articles and do FORMS.
6211 ARG is the interactive prefix given to the command.  FORMS will be
6212 executed with point over the summary line of the articles."
6213   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6214     `(let ((,articles (gnus-summary-work-articles ,arg)))
6215        (while ,articles
6216          (gnus-summary-goto-subject (car ,articles))
6217          ,@forms
6218          (pop ,articles)))))
6219
6220 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6221 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6222
6223 (defun gnus-summary-save-process-mark ()
6224   "Push the current set of process marked articles on the stack."
6225   (interactive)
6226   (push (copy-sequence gnus-newsgroup-processable)
6227         gnus-newsgroup-process-stack))
6228
6229 (defun gnus-summary-kill-process-mark ()
6230   "Push the current set of process marked articles on the stack and unmark."
6231   (interactive)
6232   (gnus-summary-save-process-mark)
6233   (gnus-summary-unmark-all-processable))
6234
6235 (defun gnus-summary-yank-process-mark ()
6236   "Pop the last process mark state off the stack and restore it."
6237   (interactive)
6238   (unless gnus-newsgroup-process-stack
6239     (error "Empty mark stack"))
6240   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6241
6242 (defun gnus-summary-process-mark-set (set)
6243   "Make SET into the current process marked articles."
6244   (gnus-summary-unmark-all-processable)
6245   (mapc 'gnus-summary-set-process-mark set))
6246
6247 ;;; Searching and stuff
6248
6249 (defun gnus-summary-search-group (&optional backward use-level)
6250   "Search for next unread newsgroup.
6251 If optional argument BACKWARD is non-nil, search backward instead."
6252   (save-excursion
6253     (set-buffer gnus-group-buffer)
6254     (when (gnus-group-search-forward
6255            backward nil (if use-level (gnus-group-group-level) nil))
6256       (gnus-group-group-name))))
6257
6258 (defun gnus-summary-best-group (&optional exclude-group)
6259   "Find the name of the best unread group.
6260 If EXCLUDE-GROUP, do not go to this group."
6261   (with-current-buffer gnus-group-buffer
6262     (save-excursion
6263       (gnus-group-best-unread-group exclude-group))))
6264
6265 (defun gnus-summary-find-next (&optional unread article backward)
6266   (if backward
6267       (gnus-summary-find-prev unread article)
6268     (let* ((dummy (gnus-summary-article-intangible-p))
6269            (article (or article (gnus-summary-article-number)))
6270            (data (gnus-data-find-list article))
6271            result)
6272       (when (and (not dummy)
6273                  (or (not gnus-summary-check-current)
6274                      (not unread)
6275                      (not (gnus-data-unread-p (car data)))))
6276         (setq data (cdr data)))
6277       (when (setq result
6278                   (if unread
6279                       (progn
6280                         (while data
6281                           (unless (memq (gnus-data-number (car data))
6282                                         (cond
6283                                          ((eq gnus-auto-goto-ignores
6284                                               'always-undownloaded)
6285                                           gnus-newsgroup-undownloaded)
6286                                          (gnus-plugged
6287                                           nil)
6288                                          ((eq gnus-auto-goto-ignores
6289                                               'unfetched)
6290                                           gnus-newsgroup-unfetched)
6291                                          ((eq gnus-auto-goto-ignores
6292                                               'undownloaded)
6293                                           gnus-newsgroup-undownloaded)))
6294                             (when (gnus-data-unread-p (car data))
6295                               (setq result (car data)
6296                                     data nil)))
6297                           (setq data (cdr data)))
6298                         result)
6299                     (car data)))
6300         (goto-char (gnus-data-pos result))
6301         (gnus-data-number result)))))
6302
6303 (defun gnus-summary-find-prev (&optional unread article)
6304   (let* ((eobp (eobp))
6305          (article (or article (gnus-summary-article-number)))
6306          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6307          result)
6308     (when (and (not eobp)
6309                (or (not gnus-summary-check-current)
6310                    (not unread)
6311                    (not (gnus-data-unread-p (car data)))))
6312       (setq data (cdr data)))
6313     (when (setq result
6314                 (if unread
6315                     (progn
6316                       (while data
6317                         (unless (memq (gnus-data-number (car data))
6318                                       (cond
6319                                        ((eq gnus-auto-goto-ignores
6320                                             'always-undownloaded)
6321                                         gnus-newsgroup-undownloaded)
6322                                        (gnus-plugged
6323                                         nil)
6324                                        ((eq gnus-auto-goto-ignores
6325                                             'unfetched)
6326                                         gnus-newsgroup-unfetched)
6327                                        ((eq gnus-auto-goto-ignores
6328                                             'undownloaded)
6329                                         gnus-newsgroup-undownloaded)))
6330                           (when (gnus-data-unread-p (car data))
6331                             (setq result (car data)
6332                                   data nil)))
6333                         (setq data (cdr data)))
6334                       result)
6335                   (car data)))
6336       (goto-char (gnus-data-pos result))
6337       (gnus-data-number result))))
6338
6339 (defun gnus-summary-find-subject (subject &optional unread backward article)
6340   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6341          (article (or article (gnus-summary-article-number)))
6342          (articles (gnus-data-list backward))
6343          (arts (gnus-data-find-list article articles))
6344          result)
6345     (when (or (not gnus-summary-check-current)
6346               (not unread)
6347               (not (gnus-data-unread-p (car arts))))
6348       (setq arts (cdr arts)))
6349     (while arts
6350       (and (or (not unread)
6351                (gnus-data-unread-p (car arts)))
6352            (vectorp (gnus-data-header (car arts)))
6353            (gnus-subject-equal
6354             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6355            (setq result (car arts)
6356                  arts nil))
6357       (setq arts (cdr arts)))
6358     (and result
6359          (goto-char (gnus-data-pos result))
6360          (gnus-data-number result))))
6361
6362 (defun gnus-summary-search-forward (&optional unread subject backward)
6363   "Search forward for an article.
6364 If UNREAD, look for unread articles.  If SUBJECT, look for
6365 articles with that subject.  If BACKWARD, search backward instead."
6366   (cond (subject (gnus-summary-find-subject subject unread backward))
6367         (backward (gnus-summary-find-prev unread))
6368         (t (gnus-summary-find-next unread))))
6369
6370 (defun gnus-recenter (&optional n)
6371   "Center point in window and redisplay frame.
6372 Also do horizontal recentering."
6373   (interactive "P")
6374   (when (and gnus-auto-center-summary
6375              (not (eq gnus-auto-center-summary 'vertical)))
6376     (gnus-horizontal-recenter))
6377   (recenter n))
6378
6379 (defun gnus-summary-recenter ()
6380   "Center point in the summary window.
6381 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6382 displayed, no centering will be performed."
6383   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6384   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6385   (interactive)
6386   ;; The user has to want it.
6387   (when gnus-auto-center-summary
6388     (let* ((top (cond ((< (window-height) 4) 0)
6389                       ((< (window-height) 7) 1)
6390                       (t (if (numberp gnus-auto-center-summary)
6391                              gnus-auto-center-summary
6392                            (/ (1- (window-height)) 2)))))
6393            (height (1- (window-height)))
6394            (bottom (save-excursion (goto-char (point-max))
6395                                    (forward-line (- height))
6396                                    (point)))
6397            (window (get-buffer-window (current-buffer))))
6398       (when (get-buffer-window gnus-article-buffer)
6399         ;; Only do recentering when the article buffer is displayed,
6400         ;; Set the window start to either `bottom', which is the biggest
6401         ;; possible valid number, or the second line from the top,
6402         ;; whichever is the least.
6403         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6404           (if (> bottom top-pos)
6405               ;; Keep the second line from the top visible
6406               (set-window-start window top-pos t)
6407             ;; Try to keep the bottom line visible; if it's partially
6408             ;; obscured, either scroll one more line to make it fully
6409             ;; visible, or revert to using TOP-POS.
6410             (save-excursion
6411               (goto-char (point-max))
6412               (forward-line -1)
6413               (let ((last-line-start (point)))
6414                 (goto-char bottom)
6415                 (set-window-start window (point) t)
6416                 (when (not (pos-visible-in-window-p last-line-start window))
6417                   (forward-line 1)
6418                   (set-window-start window (min (point) top-pos) t)))))))
6419       ;; Do horizontal recentering while we're at it.
6420       (when (and (get-buffer-window (current-buffer) t)
6421                  (not (eq gnus-auto-center-summary 'vertical)))
6422         (let ((selected (selected-window)))
6423           (select-window (get-buffer-window (current-buffer) t))
6424           (gnus-summary-position-point)
6425           (gnus-horizontal-recenter)
6426           (select-window selected))))))
6427
6428 (defun gnus-summary-jump-to-group (newsgroup)
6429   "Move point to NEWSGROUP in group mode buffer."
6430   ;; Keep update point of group mode buffer if visible.
6431   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6432       (save-window-excursion
6433         ;; Take care of tree window mode.
6434         (when (get-buffer-window gnus-group-buffer)
6435           (pop-to-buffer gnus-group-buffer))
6436         (gnus-group-jump-to-group newsgroup))
6437     (save-excursion
6438       ;; Take care of tree window mode.
6439       (if (get-buffer-window gnus-group-buffer)
6440           (pop-to-buffer gnus-group-buffer)
6441         (set-buffer gnus-group-buffer))
6442       (gnus-group-jump-to-group newsgroup))))
6443
6444 ;; This function returns a list of article numbers based on the
6445 ;; difference between the ranges of read articles in this group and
6446 ;; the range of active articles.
6447 (defun gnus-list-of-unread-articles (group)
6448   (let* ((read (gnus-info-read (gnus-get-info group)))
6449          (active (or (gnus-active group) (gnus-activate-group group)))
6450          (last (or (cdr active)
6451                    (error "Group %s couldn't be activated " group)))
6452          first nlast unread)
6453     ;; If none are read, then all are unread.
6454     (if (not read)
6455         (setq first (car active))
6456       ;; If the range of read articles is a single range, then the
6457       ;; first unread article is the article after the last read
6458       ;; article.  Sounds logical, doesn't it?
6459       (if (and (not (listp (cdr read)))
6460                (or (< (car read) (car active))
6461                    (progn (setq read (list read))
6462                           nil)))
6463           (setq first (max (car active) (1+ (cdr read))))
6464         ;; `read' is a list of ranges.
6465         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6466                                   (caar read)))
6467                   1)
6468           (setq first (car active)))
6469         (while read
6470           (when first
6471             (while (< first nlast)
6472               (setq unread (cons first unread)
6473                     first (1+ first))))
6474           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6475           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6476           (setq read (cdr read)))))
6477     ;; And add the last unread articles.
6478     (while (<= first last)
6479       (setq unread (cons first unread)
6480             first (1+ first)))
6481     ;; Return the list of unread articles.
6482     (delq 0 (nreverse unread))))
6483
6484 (defun gnus-list-of-read-articles (group)
6485   "Return a list of unread, unticked and non-dormant articles."
6486   (let* ((info (gnus-get-info group))
6487          (marked (gnus-info-marks info))
6488          (active (gnus-active group)))
6489     (and info active
6490          (gnus-list-range-difference
6491           (gnus-list-range-difference
6492            (gnus-sorted-complement
6493             (gnus-uncompress-range active)
6494             (gnus-list-of-unread-articles group))
6495            (cdr (assq 'dormant marked)))
6496           (cdr (assq 'tick marked))))))
6497
6498 ;; This function returns a sequence of article numbers based on the
6499 ;; difference between the ranges of read articles in this group and
6500 ;; the range of active articles.
6501 (defun gnus-sequence-of-unread-articles (group)
6502   (let* ((read (gnus-info-read (gnus-get-info group)))
6503          (active (or (gnus-active group) (gnus-activate-group group)))
6504          (last (cdr active))
6505          first nlast unread)
6506     ;; If none are read, then all are unread.
6507     (if (not read)
6508         (setq first (car active))
6509       ;; If the range of read articles is a single range, then the
6510       ;; first unread article is the article after the last read
6511       ;; article.  Sounds logical, doesn't it?
6512       (if (and (not (listp (cdr read)))
6513                (or (< (car read) (car active))
6514                    (progn (setq read (list read))
6515                           nil)))
6516           (setq first (max (car active) (1+ (cdr read))))
6517         ;; `read' is a list of ranges.
6518         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6519                                   (caar read)))
6520                   1)
6521           (setq first (car active)))
6522         (while read
6523           (when first
6524             (push (cons first nlast) unread))
6525           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6526           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6527           (setq read (cdr read)))))
6528     ;; And add the last unread articles.
6529     (cond ((< first last)
6530            (push (cons first last) unread))
6531           ((= first last)
6532            (push first unread)))
6533     ;; Return the sequence of unread articles.
6534     (delq 0 (nreverse unread))))
6535
6536 ;; Various summary commands
6537
6538 (defun gnus-summary-select-article-buffer ()
6539   "Reconfigure windows to show article buffer."
6540   (interactive)
6541   (if (not (gnus-buffer-live-p gnus-article-buffer))
6542       (error "There is no article buffer for this summary buffer")
6543     (gnus-configure-windows 'article)
6544     (select-window (get-buffer-window gnus-article-buffer))))
6545
6546 (defun gnus-summary-universal-argument (arg)
6547   "Perform any operation on all articles that are process/prefixed."
6548   (interactive "P")
6549   (let ((articles (gnus-summary-work-articles arg))
6550         func article)
6551     (if (eq
6552          (setq
6553           func
6554           (key-binding
6555            (read-key-sequence
6556             (substitute-command-keys
6557              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6558          'undefined)
6559         (gnus-error 1 "Undefined key")
6560       (save-excursion
6561         (while articles
6562           (gnus-summary-goto-subject (setq article (pop articles)))
6563           (let (gnus-newsgroup-processable)
6564             (command-execute func))
6565           (gnus-summary-remove-process-mark article)))))
6566   (gnus-summary-position-point))
6567
6568 (defun gnus-summary-toggle-truncation (&optional arg)
6569   "Toggle truncation of summary lines.
6570 With ARG, turn line truncation on if ARG is positive."
6571   (interactive "P")
6572   (setq truncate-lines
6573         (if (null arg) (not truncate-lines)
6574           (> (prefix-numeric-value arg) 0)))
6575   (redraw-display))
6576
6577 (defun gnus-summary-find-for-reselect ()
6578   "Return the number of an article to stay on across a reselect.
6579 The current article is considered, then following articles, then previous
6580 articles.  An article is sought which is not cancelled and isn't a temporary
6581 insertion from another group.  If there's no such then return a dummy 0."
6582   (let (found)
6583     (dolist (rev '(nil t))
6584       (unless found      ; don't demand the reverse list if we don't need it
6585         (let ((data (gnus-data-find-list
6586                      (gnus-summary-article-number) (gnus-data-list rev))))
6587           (while (and data (not found))
6588             (if (and (< 0 (gnus-data-number (car data)))
6589                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6590                 (setq found (gnus-data-number (car data))))
6591             (setq data (cdr data))))))
6592     (or found 0)))
6593
6594 (defun gnus-summary-reselect-current-group (&optional all rescan)
6595   "Exit and then reselect the current newsgroup.
6596 The prefix argument ALL means to select all articles."
6597   (interactive "P")
6598   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6599     (error "Ephemeral groups can't be reselected"))
6600   (let ((current-subject (gnus-summary-find-for-reselect))
6601         (group gnus-newsgroup-name))
6602     (setq gnus-newsgroup-begin nil)
6603     (gnus-summary-exit nil 'leave-hidden)
6604     ;; We have to adjust the point of group mode buffer because
6605     ;; point was moved to the next unread newsgroup by exiting.
6606     (gnus-summary-jump-to-group group)
6607     (when rescan
6608       (save-excursion
6609         (gnus-group-get-new-news-this-group 1)))
6610     (gnus-group-read-group all t)
6611     (gnus-summary-goto-subject current-subject nil t)))
6612
6613 (defun gnus-summary-rescan-group (&optional all)
6614   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6615   (interactive "P")
6616   (gnus-summary-reselect-current-group all t))
6617
6618 (defun gnus-summary-update-info (&optional non-destructive)
6619   (save-excursion
6620     (let ((group gnus-newsgroup-name))
6621       (when group
6622         (when gnus-newsgroup-kill-headers
6623           (setq gnus-newsgroup-killed
6624                 (gnus-compress-sequence
6625                  (gnus-sorted-union
6626                   (gnus-list-range-intersection
6627                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6628                   gnus-newsgroup-unreads)
6629                  t)))
6630         (unless (listp (cdr gnus-newsgroup-killed))
6631           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6632         (let ((headers gnus-newsgroup-headers))
6633           ;; Set the new ranges of read articles.
6634           (with-current-buffer gnus-group-buffer
6635             (gnus-undo-force-boundary))
6636           (gnus-update-read-articles
6637            group (gnus-sorted-union
6638                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6639           ;; Set the current article marks.
6640           (let ((gnus-newsgroup-scored
6641                  (if (and (not gnus-save-score)
6642                           (not non-destructive))
6643                      nil
6644                    gnus-newsgroup-scored)))
6645             (save-excursion
6646               (gnus-update-marks)))
6647           ;; Do the cross-ref thing.
6648           (when gnus-use-cross-reference
6649             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6650           ;; Do not switch windows but change the buffer to work.
6651           (set-buffer gnus-group-buffer)
6652           (unless (gnus-ephemeral-group-p group)
6653             (gnus-group-update-group group)))))))
6654
6655 (defun gnus-summary-save-newsrc (&optional force)
6656   "Save the current number of read/marked articles in the dribble buffer.
6657 The dribble buffer will then be saved.
6658 If FORCE (the prefix), also save the .newsrc file(s)."
6659   (interactive "P")
6660   (gnus-summary-update-info t)
6661   (if force
6662       (gnus-save-newsrc-file)
6663     (gnus-dribble-save)))
6664
6665 (defun gnus-summary-exit (&optional temporary leave-hidden)
6666   "Exit reading current newsgroup, and then return to group selection mode.
6667 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6668   (interactive)
6669   (gnus-set-global-variables)
6670   (when (gnus-buffer-live-p gnus-article-buffer)
6671     (save-excursion
6672       (set-buffer gnus-article-buffer)
6673       (mm-destroy-parts gnus-article-mime-handles)
6674       ;; Set it to nil for safety reason.
6675       (setq gnus-article-mime-handle-alist nil)
6676       (setq gnus-article-mime-handles nil)))
6677   (gnus-kill-save-kill-buffer)
6678   (gnus-async-halt-prefetch)
6679   (let* ((group gnus-newsgroup-name)
6680          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6681          (gnus-group-is-exiting-p t)
6682          (mode major-mode)
6683          (group-point nil)
6684          (buf (current-buffer)))
6685     (unless quit-config
6686       ;; Do adaptive scoring, and possibly save score files.
6687       (when gnus-newsgroup-adaptive
6688         (gnus-score-adaptive))
6689       (when gnus-use-scoring
6690         (gnus-score-save)))
6691     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6692     ;; If we have several article buffers, we kill them at exit.
6693     (unless gnus-single-article-buffer
6694       (gnus-kill-buffer gnus-original-article-buffer)
6695       (setq gnus-article-current nil))
6696     (when gnus-use-cache
6697       (gnus-cache-possibly-remove-articles)
6698       (gnus-cache-save-buffers))
6699     (gnus-async-prefetch-remove-group group)
6700     (when gnus-suppress-duplicates
6701       (gnus-dup-enter-articles))
6702     (when gnus-use-trees
6703       (gnus-tree-close group))
6704     (when gnus-use-cache
6705       (gnus-cache-write-active))
6706     ;; Remove entries for this group.
6707     (nnmail-purge-split-history (gnus-group-real-name group))
6708     ;; Make all changes in this group permanent.
6709     (unless quit-config
6710       (gnus-run-hooks 'gnus-exit-group-hook)
6711       (gnus-summary-update-info))
6712     (gnus-close-group group)
6713     ;; Make sure where we were, and go to next newsgroup.
6714     (set-buffer gnus-group-buffer)
6715     (unless quit-config
6716       (gnus-group-jump-to-group group))
6717     (gnus-run-hooks 'gnus-summary-exit-hook)
6718     (unless (or quit-config
6719                 ;; If this group has disappeared from the summary
6720                 ;; buffer, don't skip forwards.
6721                 (not (string= group (gnus-group-group-name))))
6722       (gnus-group-next-unread-group 1))
6723     (setq group-point (point))
6724     (if temporary
6725         nil                             ;Nothing to do.
6726       ;; If we have several article buffers, we kill them at exit.
6727       (unless gnus-single-article-buffer
6728         (gnus-kill-buffer gnus-article-buffer)
6729         (gnus-kill-buffer gnus-original-article-buffer)
6730         (setq gnus-article-current nil))
6731       (set-buffer buf)
6732       (if (not gnus-kill-summary-on-exit)
6733           (progn
6734             (gnus-deaden-summary)
6735             (setq mode nil))
6736         ;; We set all buffer-local variables to nil.  It is unclear why
6737         ;; this is needed, but if we don't, buffer-local variables are
6738         ;; not garbage-collected, it seems.  This would the lead to en
6739         ;; ever-growing Emacs.
6740         (gnus-summary-clear-local-variables)
6741         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6742           (gnus-summary-clear-local-variables))
6743         (when (get-buffer gnus-article-buffer)
6744           (bury-buffer gnus-article-buffer))
6745         ;; Return to group mode buffer.
6746         (when (eq mode 'gnus-summary-mode)
6747           (gnus-kill-buffer buf)))
6748       (setq gnus-current-select-method gnus-select-method)
6749       (set-buffer gnus-group-buffer)
6750       (if quit-config
6751           (gnus-handle-ephemeral-exit quit-config)
6752         (goto-char group-point)
6753         ;; If gnus-group-buffer is already displayed, make sure we also move
6754         ;; the cursor in the window that displays it.
6755         (let ((win (get-buffer-window (current-buffer) 0)))
6756           (if win (set-window-point win (point))))
6757         (unless leave-hidden
6758           (gnus-configure-windows 'group 'force)))
6759       ;; Clear the current group name.
6760       (unless quit-config
6761         (setq gnus-newsgroup-name nil)))))
6762
6763 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6764 (defun gnus-summary-exit-no-update (&optional no-questions)
6765   "Quit reading current newsgroup without updating read article info."
6766   (interactive)
6767   (let* ((group gnus-newsgroup-name)
6768          (gnus-group-is-exiting-p t)
6769          (gnus-group-is-exiting-without-update-p t)
6770          (quit-config (gnus-group-quit-config group)))
6771     (when (or no-questions
6772               gnus-expert-user
6773               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6774       (gnus-async-halt-prefetch)
6775       (run-hooks 'gnus-summary-prepare-exit-hook)
6776       (when (gnus-buffer-live-p gnus-article-buffer)
6777         (save-excursion
6778           (set-buffer gnus-article-buffer)
6779           (mm-destroy-parts gnus-article-mime-handles)
6780           ;; Set it to nil for safety reason.
6781           (setq gnus-article-mime-handle-alist nil)
6782           (setq gnus-article-mime-handles nil)))
6783       ;; If we have several article buffers, we kill them at exit.
6784       (unless gnus-single-article-buffer
6785         (gnus-kill-buffer gnus-article-buffer)
6786         (gnus-kill-buffer gnus-original-article-buffer)
6787         (setq gnus-article-current nil))
6788       (if (not gnus-kill-summary-on-exit)
6789           (gnus-deaden-summary)
6790         (gnus-close-group group)
6791         (gnus-summary-clear-local-variables)
6792         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6793           (gnus-summary-clear-local-variables))
6794         (gnus-kill-buffer gnus-summary-buffer))
6795       (unless gnus-single-article-buffer
6796         (setq gnus-article-current nil))
6797       (when gnus-use-trees
6798         (gnus-tree-close group))
6799       (gnus-async-prefetch-remove-group group)
6800       (when (get-buffer gnus-article-buffer)
6801         (bury-buffer gnus-article-buffer))
6802       ;; Return to the group buffer.
6803       (gnus-configure-windows 'group 'force)
6804       ;; Clear the current group name.
6805       (setq gnus-newsgroup-name nil)
6806       (unless (gnus-ephemeral-group-p group)
6807         (gnus-group-update-group group))
6808       (when (equal (gnus-group-group-name) group)
6809         (gnus-group-next-unread-group 1))
6810       (when quit-config
6811         (gnus-handle-ephemeral-exit quit-config)))))
6812
6813 (defun gnus-handle-ephemeral-exit (quit-config)
6814   "Handle movement when leaving an ephemeral group.
6815 The state which existed when entering the ephemeral is reset."
6816   (if (not (buffer-name (car quit-config)))
6817       (gnus-configure-windows 'group 'force)
6818     (set-buffer (car quit-config))
6819     (cond ((eq major-mode 'gnus-summary-mode)
6820            (gnus-set-global-variables))
6821           ((eq major-mode 'gnus-article-mode)
6822            (save-excursion
6823              ;; The `gnus-summary-buffer' variable may point
6824              ;; to the old summary buffer when using a single
6825              ;; article buffer.
6826              (unless (gnus-buffer-live-p gnus-summary-buffer)
6827                (set-buffer gnus-group-buffer))
6828              (set-buffer gnus-summary-buffer)
6829              (gnus-set-global-variables))))
6830     (if (or (eq (cdr quit-config) 'article)
6831             (eq (cdr quit-config) 'pick))
6832         (progn
6833           ;; The current article may be from the ephemeral group
6834           ;; thus it is best that we reload this article
6835           ;;
6836           ;; If we're exiting from a large digest, this can be
6837           ;; extremely slow.  So, it's better not to reload it. -- jh.
6838           ;;(gnus-summary-show-article)
6839           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6840               (gnus-configure-windows 'pick 'force)
6841             (gnus-configure-windows (cdr quit-config) 'force)))
6842       (gnus-configure-windows (cdr quit-config) 'force))
6843     (when (eq major-mode 'gnus-summary-mode)
6844       (gnus-summary-next-subject 1 nil t)
6845       (gnus-summary-recenter)
6846       (gnus-summary-position-point))))
6847
6848 ;;; Dead summaries.
6849
6850 (defvar gnus-dead-summary-mode-map nil)
6851
6852 (unless gnus-dead-summary-mode-map
6853   (setq gnus-dead-summary-mode-map (make-keymap))
6854   (suppress-keymap gnus-dead-summary-mode-map)
6855   (substitute-key-definition
6856    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6857   (dolist (key '("\C-d" "\r" "\177" [delete]))
6858     (define-key gnus-dead-summary-mode-map
6859       key 'gnus-summary-wake-up-the-dead))
6860   (dolist (key '("q" "Q"))
6861     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6862
6863 (defvar gnus-dead-summary-mode nil
6864   "Minor mode for Gnus summary buffers.")
6865
6866 (defun gnus-dead-summary-mode (&optional arg)
6867   "Minor mode for Gnus summary buffers."
6868   (interactive "P")
6869   (when (eq major-mode 'gnus-summary-mode)
6870     (make-local-variable 'gnus-dead-summary-mode)
6871     (setq gnus-dead-summary-mode
6872           (if (null arg) (not gnus-dead-summary-mode)
6873             (> (prefix-numeric-value arg) 0)))
6874     (when gnus-dead-summary-mode
6875       (add-minor-mode
6876        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6877
6878 (defun gnus-deaden-summary ()
6879   "Make the current summary buffer into a dead summary buffer."
6880   ;; Kill any previous dead summary buffer.
6881   (when (and gnus-dead-summary
6882              (buffer-name gnus-dead-summary))
6883     (with-current-buffer gnus-dead-summary
6884       (when gnus-dead-summary-mode
6885         (kill-buffer (current-buffer)))))
6886   ;; Make this the current dead summary.
6887   (setq gnus-dead-summary (current-buffer))
6888   (gnus-dead-summary-mode 1)
6889   (let ((name (buffer-name)))
6890     (when (string-match "Summary" name)
6891       (rename-buffer
6892        (concat (substring name 0 (match-beginning 0)) "Dead "
6893                (substring name (match-beginning 0)))
6894        t)
6895       (bury-buffer))))
6896
6897 (defun gnus-kill-or-deaden-summary (buffer)
6898   "Kill or deaden the summary BUFFER."
6899   (save-excursion
6900     (when (and (buffer-name buffer)
6901                (not gnus-single-article-buffer))
6902       (with-current-buffer buffer
6903         (gnus-kill-buffer gnus-article-buffer)
6904         (gnus-kill-buffer gnus-original-article-buffer)))
6905     (cond
6906      ;; Kill the buffer.
6907      (gnus-kill-summary-on-exit
6908       (when (and gnus-use-trees
6909                  (gnus-buffer-exists-p buffer))
6910         (save-excursion
6911           (set-buffer buffer)
6912           (gnus-tree-close gnus-newsgroup-name)))
6913       (gnus-kill-buffer buffer))
6914      ;; Deaden the buffer.
6915      ((gnus-buffer-exists-p buffer)
6916       (save-excursion
6917         (set-buffer buffer)
6918         (gnus-deaden-summary))))))
6919
6920 (defun gnus-summary-wake-up-the-dead (&rest args)
6921   "Wake up the dead summary buffer."
6922   (interactive)
6923   (gnus-dead-summary-mode -1)
6924   (let ((name (buffer-name)))
6925     (when (string-match "Dead " name)
6926       (rename-buffer
6927        (concat (substring name 0 (match-beginning 0))
6928                (substring name (match-end 0)))
6929        t)))
6930   (gnus-message 3 "This dead summary is now alive again"))
6931
6932 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6933 (defun gnus-summary-fetch-faq (&optional faq-dir)
6934   "Fetch the FAQ for the current group.
6935 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6936 in."
6937   (interactive
6938    (list
6939     (when current-prefix-arg
6940       (completing-read
6941        "FAQ dir: " (and (listp gnus-group-faq-directory)
6942                         (mapcar 'list
6943                                 gnus-group-faq-directory))))))
6944   (let (gnus-faq-buffer)
6945     (when (setq gnus-faq-buffer
6946                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6947       (gnus-configure-windows 'summary-faq))))
6948
6949 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6950 (defun gnus-summary-describe-group (&optional force)
6951   "Describe the current newsgroup."
6952   (interactive "P")
6953   (gnus-group-describe-group force gnus-newsgroup-name))
6954
6955 (defun gnus-summary-describe-briefly ()
6956   "Describe summary mode commands briefly."
6957   (interactive)
6958   (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")))
6959
6960 ;; Walking around group mode buffer from summary mode.
6961
6962 (defun gnus-summary-next-group (&optional no-article target-group backward)
6963   "Exit current newsgroup and then select next unread newsgroup.
6964 If prefix argument NO-ARTICLE is non-nil, no article is selected
6965 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6966 previous group instead."
6967   (interactive "P")
6968   ;; Stop pre-fetching.
6969   (gnus-async-halt-prefetch)
6970   (let ((current-group gnus-newsgroup-name)
6971         (current-buffer (current-buffer))
6972         entered)
6973     ;; First we semi-exit this group to update Xrefs and all variables.
6974     ;; We can't do a real exit, because the window conf must remain
6975     ;; the same in case the user is prompted for info, and we don't
6976     ;; want the window conf to change before that...
6977     (gnus-summary-exit t)
6978     (while (not entered)
6979       ;; Then we find what group we are supposed to enter.
6980       (set-buffer gnus-group-buffer)
6981       (gnus-group-jump-to-group current-group)
6982       (setq target-group
6983             (or target-group
6984                 (if (eq gnus-keep-same-level 'best)
6985                     (gnus-summary-best-group gnus-newsgroup-name)
6986                   (gnus-summary-search-group backward gnus-keep-same-level))))
6987       (if (not target-group)
6988           ;; There are no further groups, so we return to the group
6989           ;; buffer.
6990           (progn
6991             (gnus-message 5 "Returning to the group buffer")
6992             (setq entered t)
6993             (when (gnus-buffer-live-p current-buffer)
6994               (set-buffer current-buffer)
6995               (gnus-summary-exit))
6996             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6997         ;; We try to enter the target group.
6998         (gnus-group-jump-to-group target-group)
6999         (let ((unreads (gnus-group-group-unread)))
7000           (if (and (or (eq t unreads)
7001                        (and unreads (not (zerop unreads))))
7002                    (gnus-summary-read-group
7003                     target-group nil no-article
7004                     (and (buffer-name current-buffer) current-buffer)
7005                     nil backward))
7006               (setq entered t)
7007             (setq current-group target-group
7008                   target-group nil)))))))
7009
7010 (defun gnus-summary-prev-group (&optional no-article)
7011   "Exit current newsgroup and then select previous unread newsgroup.
7012 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7013   (interactive "P")
7014   (gnus-summary-next-group no-article nil t))
7015
7016 ;; Walking around summary lines.
7017
7018 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7019   "Go to the first subject satisfying any non-nil constraint.
7020 If UNREAD is non-nil, the article should be unread.
7021 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7022 If UNSEEN is non-nil, the article should be unseen.
7023 Returns the article selected or nil if there are no matching articles."
7024   (interactive "P")
7025   (cond
7026    ;; Empty summary.
7027    ((null gnus-newsgroup-data)
7028     (gnus-message 3 "No articles in the group")
7029     nil)
7030    ;; Pick the first article.
7031    ((not (or unread undownloaded unseen))
7032     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7033     (gnus-data-number (car gnus-newsgroup-data)))
7034    ;; Find the first unread article.
7035    (t
7036     (let ((data gnus-newsgroup-data))
7037       (while (and data
7038                   (let ((num (gnus-data-number (car data))))
7039                     (or (memq num gnus-newsgroup-unfetched)
7040                         (not (or (and unread
7041                                       (memq num gnus-newsgroup-unreads))
7042                                  (and undownloaded
7043                                       (memq num gnus-newsgroup-undownloaded))
7044                                  (and unseen
7045                                       (memq num gnus-newsgroup-unseen)))))))
7046         (setq data (cdr data)))
7047       (prog1
7048           (if data
7049               (progn
7050                 (goto-char (gnus-data-pos (car data)))
7051                 (gnus-data-number (car data)))
7052             (gnus-message 3 "No more%s articles"
7053                           (let* ((r (when unread " unread"))
7054                                  (d (when undownloaded " undownloaded"))
7055                                  (s (when unseen " unseen"))
7056                                  (l (delq nil (list r d s))))
7057                             (cond ((= 3 (length l))
7058                                    (concat r "," d ", or" s))
7059                                   ((= 2 (length l))
7060                                    (concat (car l) ", or" (cadr l)))
7061                                   ((= 1 (length l))
7062                                    (car l))
7063                                   (t
7064                                    ""))))
7065             nil
7066             )
7067         (gnus-summary-position-point))))))
7068
7069 (defun gnus-summary-next-subject (n &optional unread dont-display)
7070   "Go to next N'th summary line.
7071 If N is negative, go to the previous N'th subject line.
7072 If UNREAD is non-nil, only unread articles are selected.
7073 The difference between N and the actual number of steps taken is
7074 returned."
7075   (interactive "p")
7076   (let ((backward (< n 0))
7077         (n (abs n)))
7078     (while (and (> n 0)
7079                 (if backward
7080                     (gnus-summary-find-prev unread)
7081                   (gnus-summary-find-next unread)))
7082       (unless (zerop (setq n (1- n)))
7083         (gnus-summary-show-thread)))
7084     (when (/= 0 n)
7085       (gnus-message 7 "No more%s articles"
7086                     (if unread " unread" "")))
7087     (unless dont-display
7088       (gnus-summary-recenter)
7089       (gnus-summary-position-point))
7090     n))
7091
7092 (defun gnus-summary-next-unread-subject (n)
7093   "Go to next N'th unread summary line."
7094   (interactive "p")
7095   (gnus-summary-next-subject n t))
7096
7097 (defun gnus-summary-prev-subject (n &optional unread)
7098   "Go to previous N'th summary line.
7099 If optional argument UNREAD is non-nil, only unread article is selected."
7100   (interactive "p")
7101   (gnus-summary-next-subject (- n) unread))
7102
7103 (defun gnus-summary-prev-unread-subject (n)
7104   "Go to previous N'th unread summary line."
7105   (interactive "p")
7106   (gnus-summary-next-subject (- n) t))
7107
7108 (defun gnus-summary-goto-subjects (articles)
7109   "Insert the subject header for ARTICLES in the current buffer."
7110   (save-excursion
7111     (dolist (article articles)
7112       (gnus-summary-goto-subject article t)))
7113   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7114   (gnus-summary-position-point))
7115
7116 (defun gnus-summary-goto-subject (article &optional force silent)
7117   "Go the subject line of ARTICLE.
7118 If FORCE, also allow jumping to articles not currently shown."
7119   (interactive "nArticle number: ")
7120   (unless (numberp article)
7121     (error "Article %s is not a number" article))
7122   (let ((b (point))
7123         (data (gnus-data-find article)))
7124     ;; We read in the article if we have to.
7125     (and (not data)
7126          force
7127          (gnus-summary-insert-subject
7128           article
7129           (if (or (numberp force) (vectorp force)) force)
7130           t)
7131          (setq data (gnus-data-find article)))
7132     (goto-char b)
7133     (if (not data)
7134         (progn
7135           (unless silent
7136             (gnus-message 3 "Can't find article %d" article))
7137           nil)
7138       (let ((pt (gnus-data-pos data)))
7139         (goto-char pt)
7140         (gnus-summary-set-article-display-arrow pt))
7141       (gnus-summary-position-point)
7142       article)))
7143
7144 ;; Walking around summary lines with displaying articles.
7145
7146 (defun gnus-summary-expand-window (&optional arg)
7147   "Make the summary buffer take up the entire Emacs frame.
7148 Given a prefix, will force an `article' buffer configuration."
7149   (interactive "P")
7150   (if arg
7151       (gnus-configure-windows 'article 'force)
7152     (gnus-configure-windows 'summary 'force)))
7153
7154 (defun gnus-summary-display-article (article &optional all-header)
7155   "Display ARTICLE in article buffer."
7156   (when (gnus-buffer-live-p gnus-article-buffer)
7157     (with-current-buffer gnus-article-buffer
7158       (mm-enable-multibyte)))
7159   (gnus-set-global-variables)
7160   (when (gnus-buffer-live-p gnus-article-buffer)
7161     (with-current-buffer gnus-article-buffer
7162       (setq gnus-article-charset gnus-newsgroup-charset)
7163       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7164       (mm-enable-multibyte)))
7165   (if (null article)
7166       nil
7167     (prog1
7168         (if gnus-summary-display-article-function
7169             (funcall gnus-summary-display-article-function article all-header)
7170           (gnus-article-prepare article all-header))
7171       (gnus-run-hooks 'gnus-select-article-hook)
7172       (when (and gnus-current-article
7173                  (not (zerop gnus-current-article)))
7174         (gnus-summary-goto-subject gnus-current-article))
7175       (gnus-summary-recenter)
7176       (when (and gnus-use-trees gnus-show-threads)
7177         (gnus-possibly-generate-tree article)
7178         (gnus-highlight-selected-tree article))
7179       ;; Successfully display article.
7180       (gnus-article-set-window-start
7181        (cdr (assq article gnus-newsgroup-bookmarks))))))
7182
7183 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7184   "Select the current article.
7185 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7186 non-nil, the article will be re-fetched even if it already present in
7187 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7188 be displayed."
7189   ;; Make sure we are in the summary buffer to work around bbdb bug.
7190   (unless (eq major-mode 'gnus-summary-mode)
7191     (set-buffer gnus-summary-buffer))
7192   (let ((article (or article (gnus-summary-article-number)))
7193         (all-headers (not (not all-headers))) ;Must be t or nil.
7194         gnus-summary-display-article-function)
7195     (and (not pseudo)
7196          (gnus-summary-article-pseudo-p article)
7197          (error "This is a pseudo-article"))
7198     (save-excursion
7199       (set-buffer gnus-summary-buffer)
7200       (if (or (and gnus-single-article-buffer
7201                    (or (null gnus-current-article)
7202                        (null gnus-article-current)
7203                        (null (get-buffer gnus-article-buffer))
7204                        (not (eq article (cdr gnus-article-current)))
7205                        (not (equal (car gnus-article-current)
7206                                    gnus-newsgroup-name))))
7207               (and (not gnus-single-article-buffer)
7208                    (or (null gnus-current-article)
7209                        (not (eq gnus-current-article article))))
7210               force)
7211           ;; The requested article is different from the current article.
7212           (progn
7213             (gnus-summary-display-article article all-headers)
7214             (when (gnus-buffer-live-p gnus-article-buffer)
7215               (with-current-buffer gnus-article-buffer
7216                 (if (not gnus-article-decoded-p) ;; a local variable
7217                     (mm-disable-multibyte))))
7218             (gnus-article-set-window-start
7219              (cdr (assq article gnus-newsgroup-bookmarks)))
7220             article)
7221         'old))))
7222
7223 (defun gnus-summary-force-verify-and-decrypt ()
7224   "Display buttons for signed/encrypted parts and verify/decrypt them."
7225   (interactive)
7226   (let ((mm-verify-option 'known)
7227         (mm-decrypt-option 'known)
7228         (gnus-article-emulate-mime t)
7229         (gnus-buttonized-mime-types (append (list "multipart/signed"
7230                                                   "multipart/encrypted")
7231                                             gnus-buttonized-mime-types)))
7232     (gnus-summary-select-article nil 'force)))
7233
7234 (defun gnus-summary-set-current-mark (&optional current-mark)
7235   "Obsolete function."
7236   nil)
7237
7238 (defun gnus-summary-next-article (&optional unread subject backward push)
7239   "Select the next article.
7240 If UNREAD, only unread articles are selected.
7241 If SUBJECT, only articles with SUBJECT are selected.
7242 If BACKWARD, the previous article is selected instead of the next."
7243   (interactive "P")
7244   (cond
7245    ;; Is there such an article?
7246    ((and (gnus-summary-search-forward unread subject backward)
7247          (or (gnus-summary-display-article (gnus-summary-article-number))
7248              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7249     (gnus-summary-position-point))
7250    ;; If not, we try the first unread, if that is wanted.
7251    ((and subject
7252          gnus-auto-select-same
7253          (gnus-summary-first-unread-article))
7254     (gnus-summary-position-point)
7255     (gnus-message 6 "Wrapped"))
7256    ;; Try to get next/previous article not displayed in this group.
7257    ((and gnus-auto-extend-newsgroup
7258          (not unread) (not subject))
7259     (gnus-summary-goto-article
7260      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7261      nil (count-lines (point-min) (point))))
7262    ;; Go to next/previous group.
7263    (t
7264     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7265       (gnus-summary-jump-to-group gnus-newsgroup-name))
7266     (let ((cmd last-command-char)
7267           (point
7268            (with-current-buffer gnus-group-buffer
7269              (point)))
7270           (group
7271            (if (eq gnus-keep-same-level 'best)
7272                (gnus-summary-best-group gnus-newsgroup-name)
7273              (gnus-summary-search-group backward gnus-keep-same-level))))
7274       ;; For some reason, the group window gets selected.  We change
7275       ;; it back.
7276       (select-window (get-buffer-window (current-buffer)))
7277       ;; Select next unread newsgroup automagically.
7278       (cond
7279        ((or (not gnus-auto-select-next)
7280             (not cmd))
7281         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7282        ((or (eq gnus-auto-select-next 'quietly)
7283             (and (eq gnus-auto-select-next 'slightly-quietly)
7284                  push)
7285             (and (eq gnus-auto-select-next 'almost-quietly)
7286                  (gnus-summary-last-article-p)))
7287         ;; Select quietly.
7288         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7289             (gnus-summary-exit)
7290           (gnus-message 7 "No more%s articles (%s)..."
7291                         (if unread " unread" "")
7292                         (if group (concat "selecting " group)
7293                           "exiting"))
7294           (gnus-summary-next-group nil group backward)))
7295        (t
7296         (when (gnus-key-press-event-p last-input-event)
7297           (gnus-summary-walk-group-buffer
7298            gnus-newsgroup-name cmd unread backward point))))))))
7299
7300 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7301   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7302                       (?\C-p (gnus-group-prev-unread-group 1))))
7303         (cursor-in-echo-area t)
7304         keve key group ended prompt)
7305     (save-excursion
7306       (set-buffer gnus-group-buffer)
7307       (goto-char start)
7308       (setq group
7309             (if (eq gnus-keep-same-level 'best)
7310                 (gnus-summary-best-group gnus-newsgroup-name)
7311               (gnus-summary-search-group backward gnus-keep-same-level))))
7312     (while (not ended)
7313       (setq prompt
7314             (format
7315              "No more%s articles%s " (if unread " unread" "")
7316              (if (and group
7317                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7318                  (format " (Type %s for %s [%s])"
7319                          (single-key-description cmd)
7320                          (gnus-group-decoded-name group)
7321                          (gnus-group-unread group))
7322                (format " (Type %s to exit %s)"
7323                        (single-key-description cmd)
7324                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7325       ;; Confirm auto selection.
7326       (setq key (car (setq keve (gnus-read-event-char prompt)))
7327             ended t)
7328       (cond
7329        ((assq key keystrokes)
7330         (let ((obuf (current-buffer)))
7331           (switch-to-buffer gnus-group-buffer)
7332           (when group
7333             (gnus-group-jump-to-group group))
7334           (eval (cadr (assq key keystrokes)))
7335           (setq group (gnus-group-group-name))
7336           (switch-to-buffer obuf))
7337         (setq ended nil))
7338        ((equal key cmd)
7339         (if (or (not group)
7340                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7341             (gnus-summary-exit)
7342           (gnus-summary-next-group nil group backward)))
7343        (t
7344         (push (cdr keve) unread-command-events))))))
7345
7346 (defun gnus-summary-next-unread-article ()
7347   "Select unread article after current one."
7348   (interactive)
7349   (gnus-summary-next-article
7350    (or (not (eq gnus-summary-goto-unread 'never))
7351        (gnus-summary-last-article-p (gnus-summary-article-number)))
7352    (and gnus-auto-select-same
7353         (gnus-summary-article-subject))))
7354
7355 (defun gnus-summary-prev-article (&optional unread subject)
7356   "Select the article after the current one.
7357 If UNREAD is non-nil, only unread articles are selected."
7358   (interactive "P")
7359   (gnus-summary-next-article unread subject t))
7360
7361 (defun gnus-summary-prev-unread-article ()
7362   "Select unread article before current one."
7363   (interactive)
7364   (gnus-summary-prev-article
7365    (or (not (eq gnus-summary-goto-unread 'never))
7366        (gnus-summary-first-article-p (gnus-summary-article-number)))
7367    (and gnus-auto-select-same
7368         (gnus-summary-article-subject))))
7369
7370 (defun gnus-summary-next-page (&optional lines circular stop)
7371   "Show next page of the selected article.
7372 If at the end of the current article, select the next article.
7373 LINES says how many lines should be scrolled up.
7374
7375 If CIRCULAR is non-nil, go to the start of the article instead of
7376 selecting the next article when reaching the end of the current
7377 article.
7378
7379 If STOP is non-nil, just stop when reaching the end of the message.
7380
7381 Also see the variable `gnus-article-skip-boring'."
7382   (interactive "P")
7383   (setq gnus-summary-buffer (current-buffer))
7384   (gnus-set-global-variables)
7385   (let ((article (gnus-summary-article-number))
7386         (article-window (get-buffer-window gnus-article-buffer t))
7387         endp)
7388     ;; If the buffer is empty, we have no article.
7389     (unless article
7390       (error "No article to select"))
7391     (gnus-configure-windows 'article)
7392     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7393         (if (and (eq gnus-summary-goto-unread 'never)
7394                  (not (gnus-summary-last-article-p article)))
7395             (gnus-summary-next-article)
7396           (gnus-summary-next-unread-article))
7397       (if (or (null gnus-current-article)
7398               (null gnus-article-current)
7399               (/= article (cdr gnus-article-current))
7400               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7401           ;; Selected subject is different from current article's.
7402           (gnus-summary-display-article article)
7403         (when article-window
7404           (gnus-eval-in-buffer-window gnus-article-buffer
7405             (setq endp (or (gnus-article-next-page lines)
7406                            (gnus-article-only-boring-p))))
7407           (when endp
7408             (cond (stop
7409                    (gnus-message 3 "End of message"))
7410                   (circular
7411                    (gnus-summary-beginning-of-article))
7412                   (lines
7413                    (gnus-message 3 "End of message"))
7414                   ((null lines)
7415                    (if (and (eq gnus-summary-goto-unread 'never)
7416                             (not (gnus-summary-last-article-p article)))
7417                        (gnus-summary-next-article)
7418                      (gnus-summary-next-unread-article))))))))
7419     (gnus-summary-recenter)
7420     (gnus-summary-position-point)))
7421
7422 (defun gnus-summary-prev-page (&optional lines move)
7423   "Show previous page of selected article.
7424 Argument LINES specifies lines to be scrolled down.
7425 If MOVE, move to the previous unread article if point is at
7426 the beginning of the buffer."
7427   (interactive "P")
7428   (let ((article (gnus-summary-article-number))
7429         (article-window (get-buffer-window gnus-article-buffer t))
7430         endp)
7431     (gnus-configure-windows 'article)
7432     (if (or (null gnus-current-article)
7433             (null gnus-article-current)
7434             (/= article (cdr gnus-article-current))
7435             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7436         ;; Selected subject is different from current article's.
7437         (gnus-summary-display-article article)
7438       (gnus-summary-recenter)
7439       (when article-window
7440         (gnus-eval-in-buffer-window gnus-article-buffer
7441           (setq endp (gnus-article-prev-page lines)))
7442         (when (and move endp)
7443           (cond (lines
7444                  (gnus-message 3 "Beginning of message"))
7445                 ((null lines)
7446                  (if (and (eq gnus-summary-goto-unread 'never)
7447                           (not (gnus-summary-first-article-p article)))
7448                      (gnus-summary-prev-article)
7449                    (gnus-summary-prev-unread-article))))))))
7450   (gnus-summary-position-point))
7451
7452 (defun gnus-summary-prev-page-or-article (&optional lines)
7453   "Show previous page of selected article.
7454 Argument LINES specifies lines to be scrolled down.
7455 If at the beginning of the article, go to the next article."
7456   (interactive "P")
7457   (gnus-summary-prev-page lines t))
7458
7459 (defun gnus-summary-scroll-up (lines)
7460   "Scroll up (or down) one line current article.
7461 Argument LINES specifies lines to be scrolled up (or down if negative)."
7462   (interactive "p")
7463   (gnus-configure-windows 'article)
7464   (gnus-summary-show-thread)
7465   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7466     (gnus-eval-in-buffer-window gnus-article-buffer
7467       (cond ((> lines 0)
7468              (when (gnus-article-next-page lines)
7469                (gnus-message 3 "End of message")))
7470             ((< lines 0)
7471              (gnus-article-prev-page (- lines))))))
7472   (gnus-summary-recenter)
7473   (gnus-summary-position-point))
7474
7475 (defun gnus-summary-scroll-down (lines)
7476   "Scroll down (or up) one line current article.
7477 Argument LINES specifies lines to be scrolled down (or up if negative)."
7478   (interactive "p")
7479   (gnus-summary-scroll-up (- lines)))
7480
7481 (defun gnus-summary-next-same-subject ()
7482   "Select next article which has the same subject as current one."
7483   (interactive)
7484   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7485
7486 (defun gnus-summary-prev-same-subject ()
7487   "Select previous article which has the same subject as current one."
7488   (interactive)
7489   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7490
7491 (defun gnus-summary-next-unread-same-subject ()
7492   "Select next unread article which has the same subject as current one."
7493   (interactive)
7494   (gnus-summary-next-article t (gnus-summary-article-subject)))
7495
7496 (defun gnus-summary-prev-unread-same-subject ()
7497   "Select previous unread article which has the same subject as current one."
7498   (interactive)
7499   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7500
7501 (defun gnus-summary-first-unread-article ()
7502   "Select the first unread article.
7503 Return nil if there are no unread articles."
7504   (interactive)
7505   (prog1
7506       (when (gnus-summary-first-subject t)
7507         (gnus-summary-show-thread)
7508         (gnus-summary-first-subject t)
7509         (gnus-summary-display-article (gnus-summary-article-number)))
7510     (gnus-summary-position-point)))
7511
7512 (defun gnus-summary-first-unread-subject ()
7513   "Place the point on the subject line of the first unread article.
7514 Return nil if there are no unread articles."
7515   (interactive)
7516   (prog1
7517       (when (gnus-summary-first-subject t)
7518         (gnus-summary-show-thread)
7519         (gnus-summary-first-subject t))
7520     (gnus-summary-position-point)))
7521
7522 (defun gnus-summary-first-unseen-subject ()
7523   "Place the point on the subject line of the first unseen article.
7524 Return nil if there are no unseen articles."
7525   (interactive)
7526   (prog1
7527       (when (gnus-summary-first-subject nil nil t)
7528         (gnus-summary-show-thread)
7529         (gnus-summary-first-subject nil nil t))
7530     (gnus-summary-position-point)))
7531
7532 (defun gnus-summary-first-unseen-or-unread-subject ()
7533   "Place the point on the subject line of the first unseen article or,
7534 if all article have been seen, on the subject line of the first unread
7535 article."
7536   (interactive)
7537   (prog1
7538       (unless (when (gnus-summary-first-subject nil nil t)
7539                 (gnus-summary-show-thread)
7540                 (gnus-summary-first-subject nil nil t))
7541         (when (gnus-summary-first-subject t)
7542           (gnus-summary-show-thread)
7543           (gnus-summary-first-subject t)))
7544     (gnus-summary-position-point)))
7545
7546 (defun gnus-summary-first-article ()
7547   "Select the first article.
7548 Return nil if there are no articles."
7549   (interactive)
7550   (prog1
7551       (when (gnus-summary-first-subject)
7552         (gnus-summary-show-thread)
7553         (gnus-summary-first-subject)
7554         (gnus-summary-display-article (gnus-summary-article-number)))
7555     (gnus-summary-position-point)))
7556
7557 (defun gnus-summary-best-unread-article (&optional arg)
7558   "Select the unread article with the highest score.
7559 If given a prefix argument, select the next unread article that has a
7560 score higher than the default score."
7561   (interactive "P")
7562   (let ((article (if arg
7563                      (gnus-summary-better-unread-subject)
7564                    (gnus-summary-best-unread-subject))))
7565     (if article
7566         (gnus-summary-goto-article article)
7567       (error "No unread articles"))))
7568
7569 (defun gnus-summary-best-unread-subject ()
7570   "Select the unread subject with the highest score."
7571   (interactive)
7572   (let ((best -1000000)
7573         (data gnus-newsgroup-data)
7574         article score)
7575     (while data
7576       (and (gnus-data-unread-p (car data))
7577            (> (setq score
7578                     (gnus-summary-article-score (gnus-data-number (car data))))
7579               best)
7580            (setq best score
7581                  article (gnus-data-number (car data))))
7582       (setq data (cdr data)))
7583     (when article
7584       (gnus-summary-goto-subject article))
7585     (gnus-summary-position-point)
7586     article))
7587
7588 (defun gnus-summary-better-unread-subject ()
7589   "Select the first unread subject that has a score over the default score."
7590   (interactive)
7591   (let ((data gnus-newsgroup-data)
7592         article score)
7593     (while (and (setq article (gnus-data-number (car data)))
7594                 (or (gnus-data-read-p (car data))
7595                     (not (> (gnus-summary-article-score article)
7596                             gnus-summary-default-score))))
7597       (setq data (cdr data)))
7598     (when article
7599       (gnus-summary-goto-subject article))
7600     (gnus-summary-position-point)
7601     article))
7602
7603 (defun gnus-summary-last-subject ()
7604   "Go to the last displayed subject line in the group."
7605   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7606     (when article
7607       (gnus-summary-goto-subject article))))
7608
7609 (defun gnus-summary-goto-article (article &optional all-headers force)
7610   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7611 If ALL-HEADERS is non-nil, no header lines are hidden.
7612 If FORCE, go to the article even if it isn't displayed.  If FORCE
7613 is a number, it is the line the article is to be displayed on."
7614   (interactive
7615    (list
7616     (completing-read
7617      "Article number or Message-ID: "
7618      (mapcar (lambda (number) (list (int-to-string number)))
7619              gnus-newsgroup-limit))
7620     current-prefix-arg
7621     t))
7622   (prog1
7623       (if (and (stringp article)
7624                (string-match "@\\|%40" article))
7625           (gnus-summary-refer-article article)
7626         (when (stringp article)
7627           (setq article (string-to-number article)))
7628         (if (gnus-summary-goto-subject article force)
7629             (gnus-summary-display-article article all-headers)
7630           (gnus-message 4 "Couldn't go to article %s" article) nil))
7631     (gnus-summary-position-point)))
7632
7633 (defun gnus-summary-goto-last-article ()
7634   "Go to the previously read article."
7635   (interactive)
7636   (prog1
7637       (when gnus-last-article
7638         (gnus-summary-goto-article gnus-last-article nil t))
7639     (gnus-summary-position-point)))
7640
7641 (defun gnus-summary-pop-article (number)
7642   "Pop one article off the history and go to the previous.
7643 NUMBER articles will be popped off."
7644   (interactive "p")
7645   (let (to)
7646     (setq gnus-newsgroup-history
7647           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7648     (if to
7649         (gnus-summary-goto-article (car to) nil t)
7650       (error "Article history empty")))
7651   (gnus-summary-position-point))
7652
7653 ;; Summary commands and functions for limiting the summary buffer.
7654
7655 (defun gnus-summary-limit-to-articles (n)
7656   "Limit the summary buffer to the next N articles.
7657 If not given a prefix, use the process marked articles instead."
7658   (interactive "P")
7659   (prog1
7660       (let ((articles (gnus-summary-work-articles n)))
7661         (setq gnus-newsgroup-processable nil)
7662         (gnus-summary-limit articles))
7663     (gnus-summary-position-point)))
7664
7665 (defun gnus-summary-pop-limit (&optional total)
7666   "Restore the previous limit.
7667 If given a prefix, remove all limits."
7668   (interactive "P")
7669   (when total
7670     (setq gnus-newsgroup-limits
7671           (list (mapcar (lambda (h) (mail-header-number h))
7672                         gnus-newsgroup-headers))))
7673   (unless gnus-newsgroup-limits
7674     (error "No limit to pop"))
7675   (prog1
7676       (gnus-summary-limit nil 'pop)
7677     (gnus-summary-position-point)))
7678
7679 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7680   "Limit the summary buffer to articles that have subjects that match a regexp.
7681 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7682   (interactive
7683    (list (read-string (if current-prefix-arg
7684                           "Exclude subject (regexp): "
7685                         "Limit to subject (regexp): "))
7686          nil current-prefix-arg))
7687   (unless header
7688     (setq header "subject"))
7689   (when (not (equal "" subject))
7690     (prog1
7691         (let ((articles (gnus-summary-find-matching
7692                          (or header "subject") subject 'all nil nil
7693                          not-matching)))
7694           (unless articles
7695             (error "Found no matches for \"%s\"" subject))
7696           (gnus-summary-limit articles))
7697       (gnus-summary-position-point))))
7698
7699 (defun gnus-summary-limit-to-author (from &optional not-matching)
7700   "Limit the summary buffer to articles that have authors that match a regexp.
7701 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7702   (interactive
7703    (list (read-string (if current-prefix-arg
7704                           "Exclude author (regexp): "
7705                         "Limit to author (regexp): "))
7706          current-prefix-arg))
7707   (gnus-summary-limit-to-subject from "from" not-matching))
7708
7709 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7710   "Limit the summary buffer to articles with the given RECIPIENT.
7711
7712 If NOT-MATCHING, exclude RECIPIENT.
7713
7714 To and Cc headers are checked.  You need to include them in
7715 `nnmail-extra-headers'."
7716   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7717   (interactive
7718    (list (read-string (format "%s recipient (regexp): "
7719                               (if current-prefix-arg "Exclude" "Limit to")))
7720          current-prefix-arg))
7721   (when (not (equal "" recipient))
7722     (prog1 (let* ((to
7723                    (if (memq 'To nnmail-extra-headers)
7724                        (gnus-summary-find-matching
7725                         (cons 'extra 'To) recipient 'all nil nil
7726                         not-matching)
7727                      (gnus-message
7728                       1 "`To' isn't present in `nnmail-extra-headers'")
7729                      (sit-for 1)
7730                      nil))
7731                   (cc
7732                    (if (memq 'Cc nnmail-extra-headers)
7733                        (gnus-summary-find-matching
7734                         (cons 'extra 'Cc) recipient 'all nil nil
7735                         not-matching)
7736                      (gnus-message
7737                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7738                      (sit-for 1)
7739                      nil))
7740                   (articles
7741                    (if not-matching
7742                        ;; We need the numbers that are in both lists:
7743                        (mapcar (lambda (a)
7744                                  (and (memq a to) a))
7745                                cc)
7746                      (nconc to cc))))
7747              (unless articles
7748                (error "Found no matches for \"%s\"" recipient))
7749              (gnus-summary-limit articles))
7750       (gnus-summary-position-point))))
7751
7752 (defun gnus-summary-limit-to-age (age &optional younger-p)
7753   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7754 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7755 articles that are younger than AGE days."
7756   (interactive
7757    (let ((younger current-prefix-arg)
7758          (days-got nil)
7759          days)
7760      (while (not days-got)
7761        (setq days (if younger
7762                       (read-string "Limit to articles younger than (in days, older when negative): ")
7763                     (read-string
7764                      "Limit to articles older than (in days, younger when negative): ")))
7765        (when (> (length days) 0)
7766          (setq days (read days)))
7767        (if (numberp days)
7768            (progn
7769              (setq days-got t)
7770              (when (< days 0)
7771                (setq younger (not younger))
7772                (setq days (* days -1))))
7773          (message "Please enter a number.")
7774          (sleep-for 1)))
7775      (list days younger)))
7776   (prog1
7777       (let ((data gnus-newsgroup-data)
7778             (cutoff (days-to-time age))
7779             articles d date is-younger)
7780         (while (setq d (pop data))
7781           (when (and (vectorp (gnus-data-header d))
7782                      (setq date (mail-header-date (gnus-data-header d))))
7783             (setq is-younger (time-less-p
7784                               (time-since (condition-case ()
7785                                               (date-to-time date)
7786                                             (error '(0 0))))
7787                               cutoff))
7788             (when (if younger-p
7789                       is-younger
7790                     (not is-younger))
7791               (push (gnus-data-number d) articles))))
7792         (gnus-summary-limit (nreverse articles)))
7793     (gnus-summary-position-point)))
7794
7795 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7796   "Limit the summary buffer to articles that match an 'extra' header."
7797   (interactive
7798    (let ((header
7799           (intern
7800            (gnus-completing-read-with-default
7801             (symbol-name (car gnus-extra-headers))
7802             (if current-prefix-arg
7803                 "Exclude extra header:"
7804               "Limit extra header:")
7805             (mapcar (lambda (x)
7806                       (cons (symbol-name x) x))
7807                     gnus-extra-headers)
7808             nil
7809             t))))
7810      (list header
7811            (read-string (format "%s header %s (regexp): "
7812                                 (if current-prefix-arg "Exclude" "Limit to")
7813                                 header))
7814            current-prefix-arg)))
7815   (when (not (equal "" regexp))
7816     (prog1
7817         (let ((articles (gnus-summary-find-matching
7818                          (cons 'extra header) regexp 'all nil nil
7819                          not-matching)))
7820           (unless articles
7821             (error "Found no matches for \"%s\"" regexp))
7822           (gnus-summary-limit articles))
7823       (gnus-summary-position-point))))
7824
7825 (defun gnus-summary-limit-to-display-predicate ()
7826   "Limit the summary buffer to the predicated in the `display' group parameter."
7827   (interactive)
7828   (unless gnus-newsgroup-display
7829     (error "There is no `display' group parameter"))
7830   (let (articles)
7831     (dolist (number gnus-newsgroup-articles)
7832       (when (funcall gnus-newsgroup-display)
7833         (push number articles)))
7834     (gnus-summary-limit articles))
7835   (gnus-summary-position-point))
7836
7837 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7838 (make-obsolete
7839  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7840
7841 (defun gnus-summary-limit-to-unread (&optional all)
7842   "Limit the summary buffer to articles that are not marked as read.
7843 If ALL is non-nil, limit strictly to unread articles."
7844   (interactive "P")
7845   (if all
7846       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7847     (gnus-summary-limit-to-marks
7848      ;; Concat all the marks that say that an article is read and have
7849      ;; those removed.
7850      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7851            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7852            gnus-low-score-mark gnus-expirable-mark
7853            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7854            gnus-duplicate-mark gnus-souped-mark)
7855      'reverse)))
7856
7857 (defun gnus-summary-limit-to-replied (&optional unreplied)
7858   "Limit the summary buffer to replied articles.
7859 If UNREPLIED (the prefix), limit to unreplied articles."
7860   (interactive "P")
7861   (if unreplied
7862       (gnus-summary-limit
7863        (gnus-set-difference gnus-newsgroup-articles
7864         gnus-newsgroup-replied))
7865     (gnus-summary-limit gnus-newsgroup-replied))
7866   (gnus-summary-position-point))
7867
7868 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7869 (make-obsolete 'gnus-summary-delete-marked-with
7870                'gnus-summary-limit-exclude-marks)
7871
7872 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7873   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7874 If REVERSE, limit the summary buffer to articles that are marked
7875 with MARKS.  MARKS can either be a string of marks or a list of marks.
7876 Returns how many articles were removed."
7877   (interactive "sMarks: ")
7878   (gnus-summary-limit-to-marks marks t))
7879
7880 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7881   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7882 If REVERSE (the prefix), limit the summary buffer to articles that are
7883 not marked with MARKS.  MARKS can either be a string of marks or a
7884 list of marks.
7885 Returns how many articles were removed."
7886   (interactive "sMarks: \nP")
7887   (prog1
7888       (let ((data gnus-newsgroup-data)
7889             (marks (if (listp marks) marks
7890                      (append marks nil))) ; Transform to list.
7891             articles)
7892         (while data
7893           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7894                   (memq (gnus-data-mark (car data)) marks))
7895             (push (gnus-data-number (car data)) articles))
7896           (setq data (cdr data)))
7897         (gnus-summary-limit articles))
7898     (gnus-summary-position-point)))
7899
7900 (defun gnus-summary-limit-to-score (score)
7901   "Limit to articles with score at or above SCORE."
7902   (interactive "NLimit to articles with score of at least: ")
7903   (let ((data gnus-newsgroup-data)
7904         articles)
7905     (while data
7906       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7907                 score)
7908         (push (gnus-data-number (car data)) articles))
7909       (setq data (cdr data)))
7910     (prog1
7911         (gnus-summary-limit articles)
7912       (gnus-summary-position-point))))
7913
7914 (defun gnus-summary-limit-to-unseen ()
7915   "Limit to unseen articles."
7916   (interactive)
7917   (prog1
7918       (gnus-summary-limit gnus-newsgroup-unseen)
7919     (gnus-summary-position-point)))
7920
7921 (defun gnus-summary-limit-include-thread (id)
7922   "Display all the hidden articles that is in the thread with ID in it.
7923 When called interactively, ID is the Message-ID of the current
7924 article."
7925   (interactive (list (mail-header-id (gnus-summary-article-header))))
7926   (let ((articles (gnus-articles-in-thread
7927                    (gnus-id-to-thread (gnus-root-id id)))))
7928     (prog1
7929         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7930       (gnus-summary-limit-include-matching-articles
7931        "subject"
7932        (regexp-quote (gnus-simplify-subject-re
7933                       (mail-header-subject (gnus-id-to-header id)))))
7934       (gnus-summary-position-point))))
7935
7936 (defun gnus-summary-limit-include-matching-articles (header regexp)
7937   "Display all the hidden articles that have HEADERs that match REGEXP."
7938   (interactive (list (read-string "Match on header: ")
7939                      (read-string "Regexp: ")))
7940   (let ((articles (gnus-find-matching-articles header regexp)))
7941     (prog1
7942         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7943       (gnus-summary-position-point))))
7944
7945 (defun gnus-summary-insert-dormant-articles ()
7946   "Insert all the dormant articles for this group into the current buffer."
7947   (interactive)
7948   (let ((gnus-verbose (max 6 gnus-verbose)))
7949     (if (not gnus-newsgroup-dormant)
7950         (gnus-message 3 "No cached articles for this group")
7951       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7952
7953 (defun gnus-summary-limit-include-dormant ()
7954   "Display all the hidden articles that are marked as dormant.
7955 Note that this command only works on a subset of the articles currently
7956 fetched for this group."
7957   (interactive)
7958   (unless gnus-newsgroup-dormant
7959     (error "There are no dormant articles in this group"))
7960   (prog1
7961       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7962     (gnus-summary-position-point)))
7963
7964 (defun gnus-summary-limit-exclude-dormant ()
7965   "Hide all dormant articles."
7966   (interactive)
7967   (prog1
7968       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7969     (gnus-summary-position-point)))
7970
7971 (defun gnus-summary-limit-exclude-childless-dormant ()
7972   "Hide all dormant articles that have no children."
7973   (interactive)
7974   (let ((data (gnus-data-list t))
7975         articles d children)
7976     ;; Find all articles that are either not dormant or have
7977     ;; children.
7978     (while (setq d (pop data))
7979       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7980                 (and (setq children
7981                            (gnus-article-children (gnus-data-number d)))
7982                      (let (found)
7983                        (while children
7984                          (when (memq (car children) articles)
7985                            (setq children nil
7986                                  found t))
7987                          (pop children))
7988                        found)))
7989         (push (gnus-data-number d) articles)))
7990     ;; Do the limiting.
7991     (prog1
7992         (gnus-summary-limit articles)
7993       (gnus-summary-position-point))))
7994
7995 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7996   "Mark all unread excluded articles as read.
7997 If ALL, mark even excluded ticked and dormants as read."
7998   (interactive "P")
7999   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8000   (let ((articles (gnus-sorted-ndifference
8001                    (sort
8002                     (mapcar (lambda (h) (mail-header-number h))
8003                             gnus-newsgroup-headers)
8004                     '<)
8005                    gnus-newsgroup-limit))
8006         article)
8007     (setq gnus-newsgroup-unreads
8008           (gnus-sorted-intersection gnus-newsgroup-unreads
8009                                     gnus-newsgroup-limit))
8010     (if all
8011         (setq gnus-newsgroup-dormant nil
8012               gnus-newsgroup-marked nil
8013               gnus-newsgroup-reads
8014               (nconc
8015                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8016                gnus-newsgroup-reads))
8017       (while (setq article (pop articles))
8018         (unless (or (memq article gnus-newsgroup-dormant)
8019                     (memq article gnus-newsgroup-marked))
8020           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8021
8022 (defun gnus-summary-limit (articles &optional pop)
8023   (if pop
8024       ;; We pop the previous limit off the stack and use that.
8025       (setq articles (car gnus-newsgroup-limits)
8026             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8027     ;; We use the new limit, so we push the old limit on the stack.
8028     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8029   ;; Set the limit.
8030   (setq gnus-newsgroup-limit articles)
8031   (let ((total (length gnus-newsgroup-data))
8032         (data (gnus-data-find-list (gnus-summary-article-number)))
8033         (gnus-summary-mark-below nil)   ; Inhibit this.
8034         found)
8035     ;; This will do all the work of generating the new summary buffer
8036     ;; according to the new limit.
8037     (gnus-summary-prepare)
8038     ;; Hide any threads, possibly.
8039     (gnus-summary-maybe-hide-threads)
8040     ;; Try to return to the article you were at, or one in the
8041     ;; neighborhood.
8042     (when data
8043       ;; We try to find some article after the current one.
8044       (while data
8045         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8046           (setq data nil
8047                 found t))
8048         (setq data (cdr data))))
8049     (unless found
8050       ;; If there is no data, that means that we were after the last
8051       ;; article.  The same goes when we can't find any articles
8052       ;; after the current one.
8053       (goto-char (point-max))
8054       (gnus-summary-find-prev))
8055     (gnus-set-mode-line 'summary)
8056     ;; We return how many articles were removed from the summary
8057     ;; buffer as a result of the new limit.
8058     (- total (length gnus-newsgroup-data))))
8059
8060 (defsubst gnus-invisible-cut-children (threads)
8061   (let ((num 0))
8062     (while threads
8063       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8064         (incf num))
8065       (pop threads))
8066     (< num 2)))
8067
8068 (defsubst gnus-cut-thread (thread)
8069   "Go forwards in the thread until we find an article that we want to display."
8070   (when (or (eq gnus-fetch-old-headers 'some)
8071             (eq gnus-fetch-old-headers 'invisible)
8072             (numberp gnus-fetch-old-headers)
8073             (eq gnus-build-sparse-threads 'some)
8074             (eq gnus-build-sparse-threads 'more))
8075     ;; Deal with old-fetched headers and sparse threads.
8076     (while (and
8077             thread
8078             (or
8079              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8080              (gnus-summary-article-ancient-p
8081               (mail-header-number (car thread))))
8082             (if (or (<= (length (cdr thread)) 1)
8083                     (eq gnus-fetch-old-headers 'invisible))
8084                 (setq gnus-newsgroup-limit
8085                       (delq (mail-header-number (car thread))
8086                             gnus-newsgroup-limit)
8087                       thread (cadr thread))
8088               (when (gnus-invisible-cut-children (cdr thread))
8089                 (let ((th (cdr thread)))
8090                   (while th
8091                     (if (memq (mail-header-number (caar th))
8092                               gnus-newsgroup-limit)
8093                         (setq thread (car th)
8094                               th nil)
8095                       (setq th (cdr th))))))))))
8096   thread)
8097
8098 (defun gnus-cut-threads (threads)
8099   "Cut off all uninteresting articles from the beginning of THREADS."
8100   (when (or (eq gnus-fetch-old-headers 'some)
8101             (eq gnus-fetch-old-headers 'invisible)
8102             (numberp gnus-fetch-old-headers)
8103             (eq gnus-build-sparse-threads 'some)
8104             (eq gnus-build-sparse-threads 'more))
8105     (let ((th threads))
8106       (while th
8107         (setcar th (gnus-cut-thread (car th)))
8108         (setq th (cdr th)))))
8109   ;; Remove nixed out threads.
8110   (delq nil threads))
8111
8112 (defun gnus-summary-initial-limit (&optional show-if-empty)
8113   "Figure out what the initial limit is supposed to be on group entry.
8114 This entails weeding out unwanted dormants, low-scored articles,
8115 fetch-old-headers verbiage, and so on."
8116   ;; Most groups have nothing to remove.
8117   (if (or gnus-inhibit-limiting
8118           (and (null gnus-newsgroup-dormant)
8119                (eq gnus-newsgroup-display 'gnus-not-ignore)
8120                (not (eq gnus-fetch-old-headers 'some))
8121                (not (numberp gnus-fetch-old-headers))
8122                (not (eq gnus-fetch-old-headers 'invisible))
8123                (null gnus-summary-expunge-below)
8124                (not (eq gnus-build-sparse-threads 'some))
8125                (not (eq gnus-build-sparse-threads 'more))
8126                (null gnus-thread-expunge-below)
8127                (not gnus-use-nocem)))
8128       ()                                ; Do nothing.
8129     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8130     (setq gnus-newsgroup-limit nil)
8131     (mapatoms
8132      (lambda (node)
8133        (unless (car (symbol-value node))
8134          ;; These threads have no parents -- they are roots.
8135          (let ((nodes (cdr (symbol-value node)))
8136                thread)
8137            (while nodes
8138              (if (and gnus-thread-expunge-below
8139                       (< (gnus-thread-total-score (car nodes))
8140                          gnus-thread-expunge-below))
8141                  (gnus-expunge-thread (pop nodes))
8142                (setq thread (pop nodes))
8143                (gnus-summary-limit-children thread))))))
8144      gnus-newsgroup-dependencies)
8145     ;; If this limitation resulted in an empty group, we might
8146     ;; pop the previous limit and use it instead.
8147     (when (and (not gnus-newsgroup-limit)
8148                show-if-empty)
8149       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8150     gnus-newsgroup-limit))
8151
8152 (defun gnus-summary-limit-children (thread)
8153   "Return 1 if this subthread is visible and 0 if it is not."
8154   ;; First we get the number of visible children to this thread.  This
8155   ;; is done by recursing down the thread using this function, so this
8156   ;; will really go down to a leaf article first, before slowly
8157   ;; working its way up towards the root.
8158   (when thread
8159     (let* ((max-lisp-eval-depth 5000)
8160            (children
8161            (if (cdr thread)
8162                (apply '+ (mapcar 'gnus-summary-limit-children
8163                                  (cdr thread)))
8164              0))
8165           (number (mail-header-number (car thread)))
8166           score)
8167       (if (and
8168            (not (memq number gnus-newsgroup-marked))
8169            (or
8170             ;; If this article is dormant and has absolutely no visible
8171             ;; children, then this article isn't visible.
8172             (and (memq number gnus-newsgroup-dormant)
8173                  (zerop children))
8174             ;; If this is "fetch-old-headered" and there is no
8175             ;; visible children, then we don't want this article.
8176             (and (or (eq gnus-fetch-old-headers 'some)
8177                      (numberp gnus-fetch-old-headers))
8178                  (gnus-summary-article-ancient-p number)
8179                  (zerop children))
8180             ;; If this is "fetch-old-headered" and `invisible', then
8181             ;; we don't want this article.
8182             (and (eq gnus-fetch-old-headers 'invisible)
8183                  (gnus-summary-article-ancient-p number))
8184             ;; If this is a sparsely inserted article with no children,
8185             ;; we don't want it.
8186             (and (eq gnus-build-sparse-threads 'some)
8187                  (gnus-summary-article-sparse-p number)
8188                  (zerop children))
8189             ;; If we use expunging, and this article is really
8190             ;; low-scored, then we don't want this article.
8191             (when (and gnus-summary-expunge-below
8192                        (< (setq score
8193                                 (or (cdr (assq number gnus-newsgroup-scored))
8194                                     gnus-summary-default-score))
8195                           gnus-summary-expunge-below))
8196               ;; We increase the expunge-tally here, but that has
8197               ;; nothing to do with the limits, really.
8198               (incf gnus-newsgroup-expunged-tally)
8199               ;; We also mark as read here, if that's wanted.
8200               (when (and gnus-summary-mark-below
8201                          (< score gnus-summary-mark-below))
8202                 (setq gnus-newsgroup-unreads
8203                       (delq number gnus-newsgroup-unreads))
8204                 (if gnus-newsgroup-auto-expire
8205                     (push number gnus-newsgroup-expirable)
8206                   (push (cons number gnus-low-score-mark)
8207                         gnus-newsgroup-reads)))
8208               t)
8209             ;; Do the `display' group parameter.
8210             (and gnus-newsgroup-display
8211                  (not (funcall gnus-newsgroup-display)))
8212             ;; Check NoCeM things.
8213             (when (and gnus-use-nocem
8214                        (gnus-nocem-unwanted-article-p
8215                         (mail-header-id (car thread))))
8216               (setq gnus-newsgroup-unreads
8217                     (delq number gnus-newsgroup-unreads))
8218               t)))
8219           ;; Nope, invisible article.
8220           0
8221         ;; Ok, this article is to be visible, so we add it to the limit
8222         ;; and return 1.
8223         (push number gnus-newsgroup-limit)
8224         1))))
8225
8226 (defun gnus-expunge-thread (thread)
8227   "Mark all articles in THREAD as read."
8228   (let* ((number (mail-header-number (car thread))))
8229     (incf gnus-newsgroup-expunged-tally)
8230     ;; We also mark as read here, if that's wanted.
8231     (setq gnus-newsgroup-unreads
8232           (delq number gnus-newsgroup-unreads))
8233     (if gnus-newsgroup-auto-expire
8234         (push number gnus-newsgroup-expirable)
8235       (push (cons number gnus-low-score-mark)
8236             gnus-newsgroup-reads)))
8237   ;; Go recursively through all subthreads.
8238   (mapcar 'gnus-expunge-thread (cdr thread)))
8239
8240 ;; Summary article oriented commands
8241
8242 (defun gnus-summary-refer-parent-article (n)
8243   "Refer parent article N times.
8244 If N is negative, go to ancestor -N instead.
8245 The difference between N and the number of articles fetched is returned."
8246   (interactive "p")
8247   (let ((skip 1)
8248         error header ref)
8249     (when (not (natnump n))
8250       (setq skip (abs n)
8251             n 1))
8252     (while (and (> n 0)
8253                 (not error))
8254       (setq header (gnus-summary-article-header))
8255       (if (and (eq (mail-header-number header)
8256                    (cdr gnus-article-current))
8257                (equal gnus-newsgroup-name
8258                       (car gnus-article-current)))
8259           ;; If we try to find the parent of the currently
8260           ;; displayed article, then we take a look at the actual
8261           ;; References header, since this is slightly more
8262           ;; reliable than the References field we got from the
8263           ;; server.
8264           (save-excursion
8265             (set-buffer gnus-original-article-buffer)
8266             (nnheader-narrow-to-headers)
8267             (unless (setq ref (message-fetch-field "references"))
8268               (when (setq ref (message-fetch-field "in-reply-to"))
8269                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8270             (widen))
8271         (setq ref
8272               ;; It's not the current article, so we take a bet on
8273               ;; the value we got from the server.
8274               (mail-header-references header)))
8275       (if (and ref
8276                (not (equal ref "")))
8277           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8278             (gnus-message 1 "Couldn't find parent"))
8279         (gnus-message 1 "No references in article %d"
8280                       (gnus-summary-article-number))
8281         (setq error t))
8282       (decf n))
8283     (gnus-summary-position-point)
8284     n))
8285
8286 (defun gnus-summary-refer-references ()
8287   "Fetch all articles mentioned in the References header.
8288 Return the number of articles fetched."
8289   (interactive)
8290   (let ((ref (mail-header-references (gnus-summary-article-header)))
8291         (current (gnus-summary-article-number))
8292         (n 0))
8293     (if (or (not ref)
8294             (equal ref ""))
8295         (error "No References in the current article")
8296       ;; For each Message-ID in the References header...
8297       (while (string-match "<[^>]*>" ref)
8298         (incf n)
8299         ;; ... fetch that article.
8300         (gnus-summary-refer-article
8301          (prog1 (match-string 0 ref)
8302            (setq ref (substring ref (match-end 0))))))
8303       (gnus-summary-goto-subject current)
8304       (gnus-summary-position-point)
8305       n)))
8306
8307 (defun gnus-summary-refer-thread (&optional limit)
8308   "Fetch all articles in the current thread.
8309 If LIMIT (the numerical prefix), fetch that many old headers instead
8310 of what's specified by the `gnus-refer-thread-limit' variable."
8311   (interactive "P")
8312   (let ((id (mail-header-id (gnus-summary-article-header)))
8313         (limit (if limit (prefix-numeric-value limit)
8314                  gnus-refer-thread-limit)))
8315     (unless (eq gnus-fetch-old-headers 'invisible)
8316       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8317       ;; Retrieve the headers and read them in.
8318       (if (eq (if (numberp limit)
8319                   (gnus-retrieve-headers
8320                    (list (min
8321                           (+ (mail-header-number
8322                               (gnus-summary-article-header))
8323                              limit)
8324                           gnus-newsgroup-end))
8325                    gnus-newsgroup-name (* limit 2))
8326                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8327                 ;; headers.
8328                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8329                                        gnus-newsgroup-name limit))
8330               'nov)
8331           (gnus-build-all-threads)
8332         (error "Can't fetch thread from back ends that don't support NOV"))
8333       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8334     (gnus-summary-limit-include-thread id)))
8335
8336 (defun gnus-summary-refer-article (message-id)
8337   "Fetch an article specified by MESSAGE-ID."
8338   (interactive "sMessage-ID: ")
8339   (when (and (stringp message-id)
8340              (not (zerop (length message-id))))
8341     (setq message-id (gnus-replace-in-string message-id " " ""))
8342     ;; Construct the correct Message-ID if necessary.
8343     ;; Suggested by tale@pawl.rpi.edu.
8344     (unless (string-match "^<" message-id)
8345       (setq message-id (concat "<" message-id)))
8346     (unless (string-match ">$" message-id)
8347       (setq message-id (concat message-id ">")))
8348     ;; People often post MIDs from URLs, so unhex it:
8349     (unless (string-match "@" message-id)
8350       (setq message-id (gnus-url-unhex-string message-id)))
8351     (let* ((header (gnus-id-to-header message-id))
8352            (sparse (and header
8353                         (gnus-summary-article-sparse-p
8354                          (mail-header-number header))
8355                         (memq (mail-header-number header)
8356                               gnus-newsgroup-limit)))
8357            number)
8358       (cond
8359        ;; If the article is present in the buffer we just go to it.
8360        ((and header
8361              (or (not (gnus-summary-article-sparse-p
8362                        (mail-header-number header)))
8363                  sparse))
8364         (prog1
8365             (gnus-summary-goto-article
8366              (mail-header-number header) nil t)
8367           (when sparse
8368             (gnus-summary-update-article (mail-header-number header)))))
8369        (t
8370         ;; We fetch the article.
8371         (catch 'found
8372           (dolist (gnus-override-method (gnus-refer-article-methods))
8373             (when (and (gnus-check-server gnus-override-method)
8374                        ;; Fetch the header,
8375                        (setq number (gnus-summary-insert-subject message-id)))
8376               ;; and display the article.
8377               (gnus-summary-select-article nil nil nil number)
8378               (throw 'found t)))
8379           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8380
8381 (defun gnus-refer-article-methods ()
8382   "Return a list of referable methods."
8383   (cond
8384    ;; No method, so we default to current and native.
8385    ((null gnus-refer-article-method)
8386     (list gnus-current-select-method gnus-select-method))
8387    ;; Current.
8388    ((eq 'current gnus-refer-article-method)
8389     (list gnus-current-select-method))
8390    ;; List of select methods.
8391    ((not (and (symbolp (car gnus-refer-article-method))
8392               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8393     (let (out)
8394       (dolist (method gnus-refer-article-method)
8395         (push (if (eq 'current method)
8396                   gnus-current-select-method
8397                 method)
8398               out))
8399       (nreverse out)))
8400    ;; One single select method.
8401    (t
8402     (list gnus-refer-article-method))))
8403
8404 (defun gnus-summary-edit-parameters ()
8405   "Edit the group parameters of the current group."
8406   (interactive)
8407   (gnus-group-edit-group gnus-newsgroup-name 'params))
8408
8409 (defun gnus-summary-customize-parameters ()
8410   "Customize the group parameters of the current group."
8411   (interactive)
8412   (gnus-group-customize gnus-newsgroup-name))
8413
8414 (defun gnus-summary-enter-digest-group (&optional force)
8415   "Enter an nndoc group based on the current article.
8416 If FORCE, force a digest interpretation.  If not, try
8417 to guess what the document format is."
8418   (interactive "P")
8419   (let ((conf gnus-current-window-configuration))
8420     (save-window-excursion
8421       (save-excursion
8422         (let (gnus-article-prepare-hook
8423               gnus-display-mime-function
8424               gnus-break-pages)
8425           (gnus-summary-select-article))))
8426     (setq gnus-current-window-configuration conf)
8427     (let* ((name (format "%s-%d"
8428                          (gnus-group-prefixed-name
8429                           gnus-newsgroup-name (list 'nndoc ""))
8430                          (with-current-buffer gnus-summary-buffer
8431                            gnus-current-article)))
8432            (ogroup gnus-newsgroup-name)
8433            (params (append (gnus-info-params (gnus-get-info ogroup))
8434                            (list (cons 'to-group ogroup))
8435                            (list (cons 'parent-group ogroup))
8436                            (list (cons 'save-article-group ogroup))))
8437            (case-fold-search t)
8438            (buf (current-buffer))
8439            dig to-address)
8440       (save-excursion
8441         (set-buffer gnus-original-article-buffer)
8442         ;; Have the digest group inherit the main mail address of
8443         ;; the parent article.
8444         (when (setq to-address (or (gnus-fetch-field "reply-to")
8445                                    (gnus-fetch-field "from")))
8446           (setq params (append
8447                         (list (cons 'to-address
8448                                     (funcall gnus-decode-encoded-word-function
8449                                              to-address))))))
8450         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8451         (insert-buffer-substring gnus-original-article-buffer)
8452         ;; Remove lines that may lead nndoc to misinterpret the
8453         ;; document type.
8454         (narrow-to-region
8455          (goto-char (point-min))
8456          (or (search-forward "\n\n" nil t) (point)))
8457         (goto-char (point-min))
8458         (delete-matching-lines "^Path:\\|^From ")
8459         (widen))
8460       (unwind-protect
8461           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8462                     (gnus-newsgroup-ephemeral-ignored-charsets
8463                      gnus-newsgroup-ignored-charsets))
8464                 (gnus-group-read-ephemeral-group
8465                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8466                               (nndoc-article-type
8467                                ,(if force 'mbox 'guess)))
8468                  t nil nil nil
8469                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8470                                                         "ADAPT")))))
8471               ;; Make all postings to this group go to the parent group.
8472               (nconc (gnus-info-params (gnus-get-info name))
8473                      params)
8474             ;; Couldn't select this doc group.
8475             (switch-to-buffer buf)
8476             (gnus-set-global-variables)
8477             (gnus-configure-windows 'summary)
8478             (gnus-message 3 "Article couldn't be entered?"))
8479         (kill-buffer dig)))))
8480
8481 (defun gnus-summary-read-document (n)
8482   "Open a new group based on the current article(s).
8483 This will allow you to read digests and other similar
8484 documents as newsgroups.
8485 Obeys the standard process/prefix convention."
8486   (interactive "P")
8487   (let* ((ogroup gnus-newsgroup-name)
8488          (params (append (gnus-info-params (gnus-get-info ogroup))
8489                          (list (cons 'to-group ogroup))))
8490          group egroup groups vgroup)
8491     (dolist (article (gnus-summary-work-articles n))
8492       (setq group (format "%s-%d" gnus-newsgroup-name article))
8493       (gnus-summary-remove-process-mark article)
8494       (when (gnus-summary-display-article article)
8495         (save-excursion
8496           (with-temp-buffer
8497             (insert-buffer-substring gnus-original-article-buffer)
8498             ;; Remove some headers that may lead nndoc to make
8499             ;; the wrong guess.
8500             (message-narrow-to-head)
8501             (goto-char (point-min))
8502             (delete-matching-lines "^Path:\\|^From ")
8503             (widen)
8504             (if (setq egroup
8505                       (gnus-group-read-ephemeral-group
8506                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8507                                      (nndoc-article-type guess))
8508                        t nil t))
8509                 (progn
8510             ;; Make all postings to this group go to the parent group.
8511                   (nconc (gnus-info-params (gnus-get-info egroup))
8512                          params)
8513                   (push egroup groups))
8514               ;; Couldn't select this doc group.
8515               (gnus-error 3 "Article couldn't be entered"))))))
8516     ;; Now we have selected all the documents.
8517     (cond
8518      ((not groups)
8519       (error "None of the articles could be interpreted as documents"))
8520      ((gnus-group-read-ephemeral-group
8521        (setq vgroup (format
8522                      "nnvirtual:%s-%s" gnus-newsgroup-name
8523                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8524        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8525        t
8526        (cons (current-buffer) 'summary)))
8527      (t
8528       (error "Couldn't select virtual nndoc group")))))
8529
8530 (defun gnus-summary-isearch-article (&optional regexp-p)
8531   "Do incremental search forward on the current article.
8532 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8533   (interactive "P")
8534   (gnus-summary-select-article)
8535   (gnus-configure-windows 'article)
8536   (gnus-eval-in-buffer-window gnus-article-buffer
8537     (save-restriction
8538       (widen)
8539       (isearch-forward regexp-p))))
8540
8541 (defun gnus-summary-search-article-forward (regexp &optional backward)
8542   "Search for an article containing REGEXP forward.
8543 If BACKWARD, search backward instead."
8544   (interactive
8545    (list (read-string
8546           (format "Search article %s (regexp%s): "
8547                   (if current-prefix-arg "backward" "forward")
8548                   (if gnus-last-search-regexp
8549                       (concat ", default " gnus-last-search-regexp)
8550                     "")))
8551          current-prefix-arg))
8552   (if (string-equal regexp "")
8553       (setq regexp (or gnus-last-search-regexp ""))
8554     (setq gnus-last-search-regexp regexp)
8555     (setq gnus-article-before-search gnus-current-article))
8556   ;; Intentionally set gnus-last-article.
8557   (setq gnus-last-article gnus-article-before-search)
8558   (let ((gnus-last-article gnus-last-article))
8559     (if (gnus-summary-search-article regexp backward)
8560         (gnus-summary-show-thread)
8561       (signal 'search-failed (list regexp)))))
8562
8563 (defun gnus-summary-search-article-backward (regexp)
8564   "Search for an article containing REGEXP backward."
8565   (interactive
8566    (list (read-string
8567           (format "Search article backward (regexp%s): "
8568                   (if gnus-last-search-regexp
8569                       (concat ", default " gnus-last-search-regexp)
8570                     "")))))
8571   (gnus-summary-search-article-forward regexp 'backward))
8572
8573 (defun gnus-summary-search-article (regexp &optional backward)
8574   "Search for an article containing REGEXP.
8575 Optional argument BACKWARD means do search for backward.
8576 `gnus-select-article-hook' is not called during the search."
8577   ;; We have to require this here to make sure that the following
8578   ;; dynamic binding isn't shadowed by autoloading.
8579   (require 'gnus-async)
8580   (require 'gnus-art)
8581   (let ((gnus-select-article-hook nil)  ;Disable hook.
8582         (gnus-article-prepare-hook nil)
8583         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8584         (gnus-use-article-prefetch nil)
8585         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8586         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8587         (gnus-visual nil)
8588         (gnus-keep-backlog nil)
8589         (gnus-break-pages nil)
8590         (gnus-summary-display-arrow nil)
8591         (gnus-updated-mode-lines nil)
8592         (gnus-auto-center-summary nil)
8593         (sum (current-buffer))
8594         (gnus-display-mime-function nil)
8595         (found nil)
8596         point)
8597     (gnus-save-hidden-threads
8598       (gnus-summary-select-article)
8599       (set-buffer gnus-article-buffer)
8600       (goto-char (window-point (get-buffer-window (current-buffer))))
8601       (when backward
8602         (forward-line -1))
8603       (while (not found)
8604         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8605         (if (if backward
8606                 (re-search-backward regexp nil t)
8607               (re-search-forward regexp nil t))
8608             ;; We found the regexp.
8609             (progn
8610               (setq found 'found)
8611               (beginning-of-line)
8612               (set-window-start
8613                (get-buffer-window (current-buffer))
8614                (point))
8615               (forward-line 1)
8616               (set-window-point
8617                (get-buffer-window (current-buffer))
8618                (point))
8619               (set-buffer sum)
8620               (setq point (point)))
8621           ;; We didn't find it, so we go to the next article.
8622           (set-buffer sum)
8623           (setq found 'not)
8624           (while (eq found 'not)
8625             (if (not (if backward (gnus-summary-find-prev)
8626                        (gnus-summary-find-next)))
8627                 ;; No more articles.
8628                 (setq found t)
8629               ;; Select the next article and adjust point.
8630               (unless (gnus-summary-article-sparse-p
8631                        (gnus-summary-article-number))
8632                 (setq found nil)
8633                 (gnus-summary-select-article)
8634                 (set-buffer gnus-article-buffer)
8635                 (widen)
8636                 (goto-char (if backward (point-max) (point-min))))))))
8637       (gnus-message 7 ""))
8638     ;; Return whether we found the regexp.
8639     (when (eq found 'found)
8640       (goto-char point)
8641       (gnus-summary-show-thread)
8642       (gnus-summary-goto-subject gnus-current-article)
8643       (gnus-summary-position-point)
8644       t)))
8645
8646 (defun gnus-find-matching-articles (header regexp)
8647   "Return a list of all articles that match REGEXP on HEADER.
8648 This search includes all articles in the current group that Gnus has
8649 fetched headers for, whether they are displayed or not."
8650   (let ((articles nil)
8651         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8652         (case-fold-search t))
8653     (dolist (header gnus-newsgroup-headers)
8654       (when (string-match regexp (funcall func header))
8655         (push (mail-header-number header) articles)))
8656     (nreverse articles)))
8657
8658 (defun gnus-summary-find-matching (header regexp &optional backward unread
8659                                           not-case-fold not-matching)
8660   "Return a list of all articles that match REGEXP on HEADER.
8661 The search stars on the current article and goes forwards unless
8662 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8663 If UNREAD is non-nil, only unread articles will
8664 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8665 in the comparisons. If NOT-MATCHING, return a list of all articles that
8666 not match REGEXP on HEADER."
8667   (let ((case-fold-search (not not-case-fold))
8668         articles d func)
8669     (if (consp header)
8670         (if (eq (car header) 'extra)
8671             (setq func
8672                   `(lambda (h)
8673                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8674                          "")))
8675           (error "%s is an invalid header" header))
8676       (unless (fboundp (intern (concat "mail-header-" header)))
8677         (error "%s is not a valid header" header))
8678       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8679     (dolist (d (if (eq backward 'all)
8680                    gnus-newsgroup-data
8681                  (gnus-data-find-list
8682                   (gnus-summary-article-number)
8683                   (gnus-data-list backward))))
8684       (when (and (or (not unread)       ; We want all articles...
8685                      (gnus-data-unread-p d)) ; Or just unreads.
8686                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8687                  (if not-matching
8688                      (not (string-match
8689                            regexp
8690                            (funcall func (gnus-data-header d))))
8691                    (string-match regexp
8692                                  (funcall func (gnus-data-header d)))))
8693         (push (gnus-data-number d) articles))) ; Success!
8694     (nreverse articles)))
8695
8696 (defun gnus-summary-execute-command (header regexp command &optional backward)
8697   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8698 If HEADER is an empty string (or nil), the match is done on the entire
8699 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8700   (interactive
8701    (list (let ((completion-ignore-case t))
8702            (completing-read
8703             "Header name: "
8704             (mapcar (lambda (header) (list (format "%s" header)))
8705                     (append
8706                      '("Number" "Subject" "From" "Lines" "Date"
8707                        "Message-ID" "Xref" "References" "Body")
8708                      gnus-extra-headers))
8709             nil 'require-match))
8710          (read-string "Regexp: ")
8711          (read-key-sequence "Command: ")
8712          current-prefix-arg))
8713   (when (equal header "Body")
8714     (setq header ""))
8715   ;; Hidden thread subtrees must be searched as well.
8716   (gnus-summary-show-all-threads)
8717   ;; We don't want to change current point nor window configuration.
8718   (save-excursion
8719     (save-window-excursion
8720       (let (gnus-visual
8721             gnus-treat-strip-trailing-blank-lines
8722             gnus-treat-strip-leading-blank-lines
8723             gnus-treat-strip-multiple-blank-lines
8724             gnus-treat-hide-boring-headers
8725             gnus-treat-fold-newsgroups
8726             gnus-article-prepare-hook)
8727         (gnus-message 6 "Executing %s..." (key-description command))
8728         ;; We'd like to execute COMMAND interactively so as to give arguments.
8729         (gnus-execute header regexp
8730                       `(call-interactively ',(key-binding command))
8731                       backward)
8732         (gnus-message 6 "Executing %s...done" (key-description command))))))
8733
8734 (defun gnus-summary-beginning-of-article ()
8735   "Scroll the article back to the beginning."
8736   (interactive)
8737   (gnus-summary-select-article)
8738   (gnus-configure-windows 'article)
8739   (gnus-eval-in-buffer-window gnus-article-buffer
8740     (widen)
8741     (goto-char (point-min))
8742     (when gnus-break-pages
8743       (gnus-narrow-to-page))))
8744
8745 (defun gnus-summary-end-of-article ()
8746   "Scroll to the end of the article."
8747   (interactive)
8748   (gnus-summary-select-article)
8749   (gnus-configure-windows 'article)
8750   (gnus-eval-in-buffer-window gnus-article-buffer
8751     (widen)
8752     (goto-char (point-max))
8753     (recenter -3)
8754     (when gnus-break-pages
8755       (when (re-search-backward page-delimiter nil t)
8756         (narrow-to-region (match-end 0) (point-max)))
8757       (gnus-narrow-to-page))))
8758
8759 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8760   "Truncate to LEN and quote all \"(\"'s in STRING."
8761   (gnus-replace-in-string (if (and len (> (length string) len))
8762                               (substring string 0 len)
8763                             string)
8764                           "[()]" "\\\\\\&"))
8765
8766 (defun gnus-summary-print-article (&optional filename n)
8767   "Generate and print a PostScript image of the process-marked (mail) articles.
8768
8769 If used interactively, print the current article if none are
8770 process-marked.  With prefix arg, prompt the user for the name of the
8771 file to save in.
8772
8773 When used from Lisp, accept two optional args FILENAME and N.  N means
8774 to print the next N articles.  If N is negative, print the N previous
8775 articles.  If N is nil and articles have been marked with the process
8776 mark, print these instead.
8777
8778 If the optional first argument FILENAME is nil, send the image to the
8779 printer.  If FILENAME is a string, save the PostScript image in a file with
8780 that name.  If FILENAME is a number, prompt the user for the name of the file
8781 to save in."
8782   (interactive (list (ps-print-preprint current-prefix-arg)))
8783   (dolist (article (gnus-summary-work-articles n))
8784     (gnus-summary-select-article nil nil 'pseudo article)
8785     (gnus-eval-in-buffer-window gnus-article-buffer
8786       (gnus-print-buffer))
8787     (gnus-summary-remove-process-mark article))
8788   (ps-despool filename))
8789
8790 (defun gnus-print-buffer ()
8791   (let ((buffer (generate-new-buffer " *print*")))
8792     (unwind-protect
8793         (progn
8794           (copy-to-buffer buffer (point-min) (point-max))
8795           (set-buffer buffer)
8796           (gnus-remove-text-with-property 'gnus-decoration)
8797           (when (gnus-visual-p 'article-highlight 'highlight)
8798             ;; Copy-to-buffer doesn't copy overlay.  So redo
8799             ;; highlight.
8800             (let ((gnus-article-buffer buffer))
8801               (gnus-article-highlight-citation t)
8802               (gnus-article-highlight-signature)
8803               (gnus-article-emphasize)
8804               (gnus-article-delete-invisible-text)))
8805           (let ((ps-left-header
8806                  (list
8807                   (concat "("
8808                           (gnus-summary-print-truncate-and-quote
8809                            (mail-header-subject gnus-current-headers)
8810                            66) ")")
8811                   (concat "("
8812                           (gnus-summary-print-truncate-and-quote
8813                            (mail-header-from gnus-current-headers)
8814                            45) ")")))
8815                 (ps-right-header
8816                  (list
8817                   "/pagenumberstring load"
8818                   (concat "("
8819                           (mail-header-date gnus-current-headers) ")"))))
8820             (gnus-run-hooks 'gnus-ps-print-hook)
8821             (save-excursion
8822               (if window-system
8823                   (ps-spool-buffer-with-faces)
8824                 (ps-spool-buffer)))))
8825       (kill-buffer buffer))))
8826
8827 (defun gnus-summary-show-article (&optional arg)
8828   "Force redisplaying of the current article.
8829 If ARG (the prefix) is a number, show the article with the charset
8830 defined in `gnus-summary-show-article-charset-alist', or the charset
8831 input.
8832 If ARG (the prefix) is non-nil and not a number, show the raw article
8833 without any article massaging functions being run.  Normally, the key
8834 strokes are `C-u g'."
8835   (interactive "P")
8836   (cond
8837    ((numberp arg)
8838     (gnus-summary-show-article t)
8839     (let ((gnus-newsgroup-charset
8840            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8841                (mm-read-coding-system
8842                 "View as charset: " ;; actually it is coding system.
8843                 (with-current-buffer gnus-article-buffer
8844                   (mm-detect-coding-region (point) (point-max))))))
8845           (gnus-newsgroup-ignored-charsets 'gnus-all))
8846       (gnus-summary-select-article nil 'force)
8847       (let ((deps gnus-newsgroup-dependencies)
8848             head header lines)
8849         (save-excursion
8850           (set-buffer gnus-original-article-buffer)
8851           (save-restriction
8852             (message-narrow-to-head)
8853             (setq head (buffer-string))
8854             (goto-char (point-min))
8855             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8856               (goto-char (point-max))
8857               (widen)
8858               (setq lines (1- (count-lines (point) (point-max))))))
8859           (with-temp-buffer
8860             (insert (format "211 %d Article retrieved.\n"
8861                             (cdr gnus-article-current)))
8862             (insert head)
8863             (if lines (insert (format "Lines: %d\n" lines)))
8864             (insert ".\n")
8865             (let ((nntp-server-buffer (current-buffer)))
8866               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8867         (gnus-data-set-header
8868          (gnus-data-find (cdr gnus-article-current))
8869          header)
8870         (gnus-summary-update-article-line
8871          (cdr gnus-article-current) header)
8872         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8873           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8874    ((not arg)
8875     ;; Select the article the normal way.
8876     (gnus-summary-select-article nil 'force))
8877    (t
8878     ;; We have to require this here to make sure that the following
8879     ;; dynamic binding isn't shadowed by autoloading.
8880     (require 'gnus-async)
8881     (require 'gnus-art)
8882     ;; Bind the article treatment functions to nil.
8883     (let ((gnus-have-all-headers t)
8884           gnus-article-prepare-hook
8885           gnus-article-decode-hook
8886           gnus-display-mime-function
8887           gnus-break-pages)
8888       ;; Destroy any MIME parts.
8889       (when (gnus-buffer-live-p gnus-article-buffer)
8890         (save-excursion
8891           (set-buffer gnus-article-buffer)
8892           (mm-destroy-parts gnus-article-mime-handles)
8893           ;; Set it to nil for safety reason.
8894           (setq gnus-article-mime-handle-alist nil)
8895           (setq gnus-article-mime-handles nil)))
8896       (gnus-summary-select-article nil 'force))))
8897   (gnus-summary-goto-subject gnus-current-article)
8898   (gnus-summary-position-point))
8899
8900 (defun gnus-summary-show-raw-article ()
8901   "Show the raw article without any article massaging functions being run."
8902   (interactive)
8903   (gnus-summary-show-article t))
8904
8905 (defun gnus-summary-verbose-headers (&optional arg)
8906   "Toggle permanent full header display.
8907 If ARG is a positive number, turn header display on.
8908 If ARG is a negative number, turn header display off."
8909   (interactive "P")
8910   (setq gnus-show-all-headers
8911         (cond ((or (not (numberp arg))
8912                    (zerop arg))
8913                (not gnus-show-all-headers))
8914               ((natnump arg)
8915                t)))
8916   (gnus-summary-show-article))
8917
8918 (defun gnus-summary-toggle-header (&optional arg)
8919   "Show the headers if they are hidden, or hide them if they are shown.
8920 If ARG is a positive number, show the entire header.
8921 If ARG is a negative number, hide the unwanted header lines."
8922   (interactive "P")
8923   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8924                      (get-buffer-window gnus-article-buffer t))))
8925     (with-current-buffer gnus-article-buffer
8926       (widen)
8927       (article-narrow-to-head)
8928       (let* ((buffer-read-only nil)
8929              (inhibit-point-motion-hooks t)
8930              (hidden (if (numberp arg)
8931                          (>= arg 0)
8932                        (or (not (looking-at "[^ \t\n]+:"))
8933                            (gnus-article-hidden-text-p 'headers))))
8934              s e)
8935         (delete-region (point-min) (point-max))
8936         (with-current-buffer gnus-original-article-buffer
8937           (goto-char (setq s (point-min)))
8938           (setq e (if (search-forward "\n\n" nil t)
8939                       (1- (point))
8940                     (point-max))))
8941         (insert-buffer-substring gnus-original-article-buffer s e)
8942         (run-hooks 'gnus-article-decode-hook)
8943         (if hidden
8944             (let ((gnus-treat-hide-headers nil)
8945                   (gnus-treat-hide-boring-headers nil))
8946               (gnus-delete-wash-type 'headers)
8947               (gnus-treat-article 'head))
8948           (gnus-treat-article 'head))
8949         (widen)
8950         (if window
8951             (set-window-start window (goto-char (point-min))))
8952         (if gnus-break-pages
8953             (gnus-narrow-to-page)
8954           (when (gnus-visual-p 'page-marker)
8955             (let ((buffer-read-only nil))
8956               (gnus-remove-text-with-property 'gnus-prev)
8957               (gnus-remove-text-with-property 'gnus-next))))
8958         (gnus-set-mode-line 'article)))))
8959
8960 (defun gnus-summary-show-all-headers ()
8961   "Make all header lines visible."
8962   (interactive)
8963   (gnus-summary-toggle-header 1))
8964
8965 (defun gnus-summary-caesar-message (&optional arg)
8966   "Caesar rotate the current article by 13.
8967 The numerical prefix specifies how many places to rotate each letter
8968 forward."
8969   (interactive "P")
8970   (gnus-summary-select-article)
8971   (let ((mail-header-separator ""))
8972     (gnus-eval-in-buffer-window gnus-article-buffer
8973       (save-restriction
8974         (widen)
8975         (let ((start (window-start))
8976               buffer-read-only)
8977           (message-caesar-buffer-body arg)
8978           (set-window-start (get-buffer-window (current-buffer)) start)))))
8979   ;; Create buttons and stuff...
8980   (gnus-treat-article nil))
8981
8982 (defun gnus-summary-idna-message (&optional arg)
8983   "Decode IDNA encoded domain names in the current articles.
8984 IDNA encoded domain names looks like `xn--bar'.  If a string
8985 remain unencoded after running this function, it is likely an
8986 invalid IDNA string (`xn--bar' is invalid).
8987
8988 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
8989 installed for this command to work."
8990   (interactive "P")
8991   (if (not (and (condition-case nil (require 'idna)
8992                   (file-error))
8993                 (mm-coding-system-p 'utf-8)
8994                 (executable-find (symbol-value 'idna-program))))
8995       (gnus-message
8996        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
8997     (gnus-summary-select-article)
8998     (let ((mail-header-separator ""))
8999       (gnus-eval-in-buffer-window gnus-article-buffer
9000         (save-restriction
9001           (widen)
9002           (let ((start (window-start))
9003                 buffer-read-only)
9004             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9005               (replace-match (idna-to-unicode (match-string 1))))
9006             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9007
9008 (autoload 'unmorse-region "morse"
9009   "Convert morse coded text in region to ordinary ASCII text."
9010   t)
9011
9012 (defun gnus-summary-morse-message (&optional arg)
9013   "Morse decode the current article."
9014   (interactive "P")
9015   (gnus-summary-select-article)
9016   (let ((mail-header-separator ""))
9017     (gnus-eval-in-buffer-window gnus-article-buffer
9018       (save-excursion
9019         (save-restriction
9020           (widen)
9021           (let ((pos (window-start))
9022                 buffer-read-only)
9023             (goto-char (point-min))
9024             (when (message-goto-body)
9025               (gnus-narrow-to-body))
9026             (goto-char (point-min))
9027             (while (search-forward "·" (point-max) t)
9028               (replace-match "."))
9029             (unmorse-region (point-min) (point-max))
9030             (widen)
9031             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9032
9033 (defun gnus-summary-stop-page-breaking ()
9034   "Stop page breaking in the current article."
9035   (interactive)
9036   (gnus-summary-select-article)
9037   (gnus-eval-in-buffer-window gnus-article-buffer
9038     (widen)
9039     (when (gnus-visual-p 'page-marker)
9040       (let ((buffer-read-only nil))
9041         (gnus-remove-text-with-property 'gnus-prev)
9042         (gnus-remove-text-with-property 'gnus-next))
9043       (setq gnus-page-broken nil))))
9044
9045 (defun gnus-summary-move-article (&optional n to-newsgroup
9046                                             select-method action)
9047   "Move the current article to a different newsgroup.
9048 If N is a positive number, move the N next articles.
9049 If N is a negative number, move the N previous articles.
9050 If N is nil and any articles have been marked with the process mark,
9051 move those articles instead.
9052 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9053 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9054 re-spool using this method.
9055
9056 When called interactively with TO-NEWSGROUP being nil, the value of
9057 the variable `gnus-move-split-methods' is used for finding a default
9058 for the target newsgroup.
9059
9060 For this function to work, both the current newsgroup and the
9061 newsgroup that you want to move to have to support the `request-move'
9062 and `request-accept' functions.
9063
9064 ACTION can be either `move' (the default), `crosspost' or `copy'."
9065   (interactive "P")
9066   (unless action
9067     (setq action 'move))
9068   ;; Check whether the source group supports the required functions.
9069   (cond ((and (eq action 'move)
9070               (not (gnus-check-backend-function
9071                     'request-move-article gnus-newsgroup-name)))
9072          (error "The current group does not support article moving"))
9073         ((and (eq action 'crosspost)
9074               (not (gnus-check-backend-function
9075                     'request-replace-article gnus-newsgroup-name)))
9076          (error "The current group does not support article editing")))
9077   (let ((articles (gnus-summary-work-articles n))
9078         (prefix (if (gnus-check-backend-function
9079                      'request-move-article gnus-newsgroup-name)
9080                     (funcall gnus-move-group-prefix-function
9081                              gnus-newsgroup-name)
9082                   ""))
9083         (names '((move "Move" "Moving")
9084                  (copy "Copy" "Copying")
9085                  (crosspost "Crosspost" "Crossposting")))
9086         (copy-buf (save-excursion
9087                     (nnheader-set-temp-buffer " *copy article*")))
9088         art-group to-method new-xref article to-groups articles-to-update-marks)
9089     (unless (assq action names)
9090       (error "Unknown action %s" action))
9091     ;; Read the newsgroup name.
9092     (when (and (not to-newsgroup)
9093                (not select-method))
9094       (if (and gnus-move-split-methods
9095                (not
9096                 (and (memq gnus-current-article articles)
9097                      (gnus-buffer-live-p gnus-original-article-buffer))))
9098           ;; When `gnus-move-split-methods' is non-nil, we have to
9099           ;; select an article to give `gnus-read-move-group-name' an
9100           ;; opportunity to suggest an appropriate default.  However,
9101           ;; we needn't render or mark the article.
9102           (let ((gnus-display-mime-function nil)
9103                 (gnus-article-prepare-hook nil)
9104                 (gnus-mark-article-hook nil))
9105             (gnus-summary-select-article nil nil nil (car articles))))
9106       (setq to-newsgroup
9107             (gnus-read-move-group-name
9108              (cadr (assq action names))
9109              (symbol-value (intern (format "gnus-current-%s-group" action)))
9110              articles prefix))
9111       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9112     (setq to-method (or select-method
9113                         (gnus-server-to-method
9114                          (gnus-group-method to-newsgroup))))
9115     ;; Check the method we are to move this article to...
9116     (unless (gnus-check-backend-function
9117              'request-accept-article (car to-method))
9118       (error "%s does not support article copying" (car to-method)))
9119     (unless (gnus-check-server to-method)
9120       (error "Can't open server %s" (car to-method)))
9121     (gnus-message 6 "%s to %s: %s..."
9122                   (caddr (assq action names))
9123                   (or (car select-method) to-newsgroup) articles)
9124     (while articles
9125       (setq article (pop articles))
9126       (setq
9127        art-group
9128        (cond
9129         ;; Move the article.
9130         ((eq action 'move)
9131          ;; Remove this article from future suppression.
9132          (gnus-dup-unsuppress-article article)
9133          (let* ((from-method (gnus-find-method-for-group
9134                               gnus-newsgroup-name))
9135                 (to-method (gnus-find-method-for-group
9136                             to-newsgroup))
9137                 (move-is-internal (gnus-method-equal from-method to-method)))
9138          (gnus-request-move-article
9139           article                       ; Article to move
9140           gnus-newsgroup-name           ; From newsgroup
9141           (nth 1 (gnus-find-method-for-group
9142                   gnus-newsgroup-name)) ; Server
9143           (list 'gnus-request-accept-article
9144                 to-newsgroup (list 'quote select-method)
9145                 (not articles) t)       ; Accept form
9146           (not articles)                ; Only save nov last time
9147           move-is-internal)))           ; is this move internal?
9148         ;; Copy the article.
9149         ((eq action 'copy)
9150          (save-excursion
9151            (set-buffer copy-buf)
9152            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9153              (save-restriction
9154                (nnheader-narrow-to-headers)
9155                (dolist (hdr gnus-copy-article-ignored-headers)
9156                  (message-remove-header hdr t)))
9157              (gnus-request-accept-article
9158               to-newsgroup select-method (not articles) t))))
9159         ;; Crosspost the article.
9160         ((eq action 'crosspost)
9161          (let ((xref (message-tokenize-header
9162                       (mail-header-xref (gnus-summary-article-header article))
9163                       " ")))
9164            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9165                                   ":" (number-to-string article)))
9166            (unless xref
9167              (setq xref (list (system-name))))
9168            (setq new-xref
9169                  (concat
9170                   (mapconcat 'identity
9171                              (delete "Xref:" (delete new-xref xref))
9172                              " ")
9173                   " " new-xref))
9174            (save-excursion
9175              (set-buffer copy-buf)
9176              ;; First put the article in the destination group.
9177              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9178              (when (consp (setq art-group
9179                                 (gnus-request-accept-article
9180                                  to-newsgroup select-method (not articles))))
9181                (setq new-xref (concat new-xref " " (car art-group)
9182                                       ":"
9183                                       (number-to-string (cdr art-group))))
9184                ;; Now we have the new Xrefs header, so we insert
9185                ;; it and replace the new article.
9186                (nnheader-replace-header "Xref" new-xref)
9187                (gnus-request-replace-article
9188                 (cdr art-group) to-newsgroup (current-buffer))
9189                art-group))))))
9190       (cond
9191        ((not art-group)
9192         (gnus-message 1 "Couldn't %s article %s: %s"
9193                       (cadr (assq action names)) article
9194                       (nnheader-get-report (car to-method))))
9195        ((eq art-group 'junk)
9196         (when (eq action 'move)
9197           (gnus-summary-mark-article article gnus-canceled-mark)
9198           (gnus-message 4 "Deleted article %s" article)
9199           ;; run the delete hook
9200           (run-hook-with-args 'gnus-summary-article-delete-hook
9201                               action
9202                               (gnus-data-header
9203                                (assoc article (gnus-data-list nil)))
9204                               gnus-newsgroup-name nil
9205                               select-method)))
9206        (t
9207         (let* ((pto-group (gnus-group-prefixed-name
9208                            (car art-group) to-method))
9209                (info (gnus-get-info pto-group))
9210                (to-group (gnus-info-group info))
9211                to-marks)
9212           ;; Update the group that has been moved to.
9213           (when (and info
9214                      (memq action '(move copy)))
9215             (unless (member to-group to-groups)
9216               (push to-group to-groups))
9217
9218             (unless (memq article gnus-newsgroup-unreads)
9219               (push 'read to-marks)
9220               (gnus-info-set-read
9221                info (gnus-add-to-range (gnus-info-read info)
9222                                        (list (cdr art-group)))))
9223
9224             ;; See whether the article is to be put in the cache.
9225             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9226                              gnus-article-mark-lists
9227                            (delete '(expirable . expire)
9228                                    (copy-sequence gnus-article-mark-lists))))
9229                   (to-article (cdr art-group)))
9230
9231               ;; Enter the article into the cache in the new group,
9232               ;; if that is required.
9233               (when gnus-use-cache
9234                 (gnus-cache-possibly-enter-article
9235                  to-group to-article
9236                  (memq article gnus-newsgroup-marked)
9237                  (memq article gnus-newsgroup-dormant)
9238                  (memq article gnus-newsgroup-unreads)))
9239
9240               (when gnus-preserve-marks
9241                 ;; Copy any marks over to the new group.
9242                 (when (and (equal to-group gnus-newsgroup-name)
9243                            (not (memq article gnus-newsgroup-unreads)))
9244                   ;; Mark this article as read in this group.
9245                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9246                   (setcdr (gnus-active to-group) to-article)
9247                   (setcdr gnus-newsgroup-active to-article))
9248
9249                 (while marks
9250                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9251                     (when (memq article (symbol-value
9252                                          (intern (format "gnus-newsgroup-%s"
9253                                                          (caar marks)))))
9254                       (push (cdar marks) to-marks)
9255                       ;; If the other group is the same as this group,
9256                       ;; then we have to add the mark to the list.
9257                       (when (equal to-group gnus-newsgroup-name)
9258                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9259                              (cons to-article
9260                                    (symbol-value
9261                                     (intern (format "gnus-newsgroup-%s"
9262                                                     (caar marks)))))))
9263                       ;; Copy the marks to other group.
9264                       (gnus-add-marked-articles
9265                        to-group (cdar marks) (list to-article) info)))
9266                   (setq marks (cdr marks)))
9267
9268                 (gnus-request-set-mark
9269                  to-group (list (list (list to-article) 'add to-marks))))
9270
9271               (gnus-dribble-enter
9272                (concat "(gnus-group-set-info '"
9273                        (gnus-prin1-to-string (gnus-get-info to-group))
9274                        ")"))))
9275
9276           ;; Update the Xref header in this article to point to
9277           ;; the new crossposted article we have just created.
9278           (when (eq action 'crosspost)
9279             (save-excursion
9280               (set-buffer copy-buf)
9281               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9282               (nnheader-replace-header "Xref" new-xref)
9283               (gnus-request-replace-article
9284                article gnus-newsgroup-name (current-buffer))))
9285
9286           ;; run the move/copy/crosspost/respool hook
9287           (run-hook-with-args 'gnus-summary-article-move-hook
9288                               action
9289                               (gnus-data-header
9290                                (assoc article (gnus-data-list nil)))
9291                               gnus-newsgroup-name
9292                               to-newsgroup
9293                               select-method))
9294
9295         ;;;!!!Why is this necessary?
9296         (set-buffer gnus-summary-buffer)
9297         
9298         (gnus-summary-goto-subject article)
9299         (when (eq action 'move)
9300           (gnus-summary-mark-article article gnus-canceled-mark))))
9301       (push article articles-to-update-marks))
9302
9303     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9304     ;; Re-activate all groups that have been moved to.
9305     (save-excursion
9306       (set-buffer gnus-group-buffer)
9307       (let ((gnus-group-marked to-groups))
9308         (gnus-group-get-new-news-this-group nil t)))
9309     
9310     (gnus-kill-buffer copy-buf)
9311     (gnus-summary-position-point)
9312     (gnus-set-mode-line 'summary)))
9313
9314 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9315   "Copy the current article to some other group.
9316 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9317 When called interactively, if TO-NEWSGROUP is nil, use the value of
9318 the variable `gnus-move-split-methods' for finding a default target
9319 newsgroup.
9320 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9321 re-spool using this method."
9322   (interactive "P")
9323   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9324
9325 (defun gnus-summary-crosspost-article (&optional n)
9326   "Crosspost the current article to some other group."
9327   (interactive "P")
9328   (gnus-summary-move-article n nil nil 'crosspost))
9329
9330 (defcustom gnus-summary-respool-default-method nil
9331   "Default method type for respooling an article.
9332 If nil, use to the current newsgroup method."
9333   :type 'symbol
9334   :group 'gnus-summary-mail)
9335
9336 (defcustom gnus-summary-display-while-building nil
9337   "If non-nil, show and update the summary buffer as it's being built.
9338 If the value is t, update the buffer after every line is inserted.  If
9339 the value is an integer (N), update the display every N lines."
9340   :version "22.1"
9341   :group 'gnus-thread
9342   :type '(choice (const :tag "off" nil)
9343                  number
9344                  (const :tag "frequently" t)))
9345
9346 (defun gnus-summary-respool-article (&optional n method)
9347   "Respool the current article.
9348 The article will be squeezed through the mail spooling process again,
9349 which means that it will be put in some mail newsgroup or other
9350 depending on `nnmail-split-methods'.
9351 If N is a positive number, respool the N next articles.
9352 If N is a negative number, respool the N previous articles.
9353 If N is nil and any articles have been marked with the process mark,
9354 respool those articles instead.
9355
9356 Respooling can be done both from mail groups and \"real\" newsgroups.
9357 In the former case, the articles in question will be moved from the
9358 current group into whatever groups they are destined to.  In the
9359 latter case, they will be copied into the relevant groups."
9360   (interactive
9361    (list current-prefix-arg
9362          (let* ((methods (gnus-methods-using 'respool))
9363                 (methname
9364                  (symbol-name (or gnus-summary-respool-default-method
9365                                   (car (gnus-find-method-for-group
9366                                         gnus-newsgroup-name)))))
9367                 (method
9368                  (gnus-completing-read-with-default
9369                   methname "What backend do you want to use when respooling?"
9370                   methods nil t nil 'gnus-mail-method-history))
9371                 ms)
9372            (cond
9373             ((zerop (length (setq ms (gnus-servers-using-backend
9374                                       (intern method)))))
9375              (list (intern method) ""))
9376             ((= 1 (length ms))
9377              (car ms))
9378             (t
9379              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9380                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9381                            ms-alist))))))))
9382   (unless method
9383     (error "No method given for respooling"))
9384   (if (assoc (symbol-name
9385               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9386              (gnus-methods-using 'respool))
9387       (gnus-summary-move-article n nil method)
9388     (gnus-summary-copy-article n nil method)))
9389
9390 (defun gnus-summary-import-article (file &optional edit)
9391   "Import an arbitrary file into a mail newsgroup."
9392   (interactive "fImport file: \nP")
9393   (let ((group gnus-newsgroup-name)
9394         (now (current-time))
9395         atts lines group-art)
9396     (unless (gnus-check-backend-function 'request-accept-article group)
9397       (error "%s does not support article importing" group))
9398     (or (file-readable-p file)
9399         (not (file-regular-p file))
9400         (error "Can't read %s" file))
9401     (save-excursion
9402       (set-buffer (gnus-get-buffer-create " *import file*"))
9403       (erase-buffer)
9404       (nnheader-insert-file-contents file)
9405       (goto-char (point-min))
9406       (if (nnheader-article-p)
9407           (save-restriction
9408             (goto-char (point-min))
9409             (search-forward "\n\n" nil t)
9410             (narrow-to-region (point-min) (1- (point)))
9411             (goto-char (point-min))
9412             (unless (re-search-forward "^date:" nil t)
9413               (goto-char (point-max))
9414               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9415        ;; This doesn't look like an article, so we fudge some headers.
9416         (setq atts (file-attributes file)
9417               lines (count-lines (point-min) (point-max)))
9418         (insert "From: " (read-string "From: ") "\n"
9419                 "Subject: " (read-string "Subject: ") "\n"
9420                 "Date: " (message-make-date (nth 5 atts)) "\n"
9421                 "Message-ID: " (message-make-message-id) "\n"
9422                 "Lines: " (int-to-string lines) "\n"
9423                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9424       (setq group-art (gnus-request-accept-article group nil t))
9425       (kill-buffer (current-buffer)))
9426     (setq gnus-newsgroup-active (gnus-activate-group group))
9427     (forward-line 1)
9428     (gnus-summary-goto-article (cdr group-art) nil t)
9429     (when edit
9430       (gnus-summary-edit-article))))
9431
9432 (defun gnus-summary-create-article ()
9433   "Create an article in a mail newsgroup."
9434   (interactive)
9435   (let ((group gnus-newsgroup-name)
9436         (now (current-time))
9437         group-art)
9438     (unless (gnus-check-backend-function 'request-accept-article group)
9439       (error "%s does not support article importing" group))
9440     (save-excursion
9441       (set-buffer (gnus-get-buffer-create " *import file*"))
9442       (erase-buffer)
9443       (goto-char (point-min))
9444       ;; This doesn't look like an article, so we fudge some headers.
9445       (insert "From: " (read-string "From: ") "\n"
9446               "Subject: " (read-string "Subject: ") "\n"
9447               "Date: " (message-make-date now) "\n"
9448               "Message-ID: " (message-make-message-id) "\n")
9449       (setq group-art (gnus-request-accept-article group nil t))
9450       (kill-buffer (current-buffer)))
9451     (setq gnus-newsgroup-active (gnus-activate-group group))
9452     (forward-line 1)
9453     (gnus-summary-goto-article (cdr group-art) nil t)
9454     (gnus-summary-edit-article)))
9455
9456 (defun gnus-summary-article-posted-p ()
9457   "Say whether the current (mail) article is available from news as well.
9458 This will be the case if the article has both been mailed and posted."
9459   (interactive)
9460   (let ((id (mail-header-references (gnus-summary-article-header)))
9461         (gnus-override-method (car (gnus-refer-article-methods))))
9462     (if (gnus-request-head id "")
9463         (gnus-message 2 "The current message was found on %s"
9464                       gnus-override-method)
9465       (gnus-message 2 "The current message couldn't be found on %s"
9466                     gnus-override-method)
9467       nil)))
9468
9469 (defun gnus-summary-expire-articles (&optional now)
9470   "Expire all articles that are marked as expirable in the current group."
9471   (interactive)
9472   (when (and (not gnus-group-is-exiting-without-update-p)
9473              (gnus-check-backend-function
9474               'request-expire-articles gnus-newsgroup-name))
9475     ;; This backend supports expiry.
9476     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9477            (expirable (if total
9478                           (progn
9479                             ;; We need to update the info for
9480                             ;; this group for `gnus-list-of-read-articles'
9481                             ;; to give us the right answer.
9482                             (gnus-run-hooks 'gnus-exit-group-hook)
9483                             (gnus-summary-update-info)
9484                             (gnus-list-of-read-articles gnus-newsgroup-name))
9485                         (setq gnus-newsgroup-expirable
9486                               (sort gnus-newsgroup-expirable '<))))
9487            (expiry-wait (if now 'immediate
9488                           (gnus-group-find-parameter
9489                            gnus-newsgroup-name 'expiry-wait)))
9490            (nnmail-expiry-target
9491             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9492                 nnmail-expiry-target))
9493            es)
9494       (when expirable
9495         ;; There are expirable articles in this group, so we run them
9496         ;; through the expiry process.
9497         (gnus-message 6 "Expiring articles...")
9498         (unless (gnus-check-group gnus-newsgroup-name)
9499           (error "Can't open server for %s" gnus-newsgroup-name))
9500         ;; The list of articles that weren't expired is returned.
9501         (save-excursion
9502           (if expiry-wait
9503               (let ((nnmail-expiry-wait-function nil)
9504                     (nnmail-expiry-wait expiry-wait))
9505                 (setq es (gnus-request-expire-articles
9506                           expirable gnus-newsgroup-name)))
9507             (setq es (gnus-request-expire-articles
9508                       expirable gnus-newsgroup-name)))
9509           (unless total
9510             (setq gnus-newsgroup-expirable es))
9511           ;; We go through the old list of expirable, and mark all
9512           ;; really expired articles as nonexistent.
9513           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9514             (let ((gnus-use-cache nil))
9515               (dolist (article expirable)
9516                 (when (and (not (memq article es))
9517                            (gnus-data-find article))
9518                   (gnus-summary-mark-article article gnus-canceled-mark)
9519                   (run-hook-with-args 'gnus-summary-article-expire-hook
9520                                       'delete
9521                                       (gnus-data-header
9522                                        (assoc article (gnus-data-list nil)))
9523                                       gnus-newsgroup-name
9524                                       nil
9525                                       nil))))))
9526         (gnus-message 6 "Expiring articles...done")))))
9527
9528 (defun gnus-summary-expire-articles-now ()
9529   "Expunge all expirable articles in the current group.
9530 This means that *all* articles that are marked as expirable will be
9531 deleted forever, right now."
9532   (interactive)
9533   (or gnus-expert-user
9534       (gnus-yes-or-no-p
9535        "Are you really, really, really sure you want to delete all these messages? ")
9536       (error "Phew!"))
9537   (gnus-summary-expire-articles t))
9538
9539 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9540 (defun gnus-summary-delete-article (&optional n)
9541   "Delete the N next (mail) articles.
9542 This command actually deletes articles.  This is not a marking
9543 command.  The article will disappear forever from your life, never to
9544 return.
9545
9546 If N is negative, delete backwards.
9547 If N is nil and articles have been marked with the process mark,
9548 delete these instead.
9549
9550 If `gnus-novice-user' is non-nil you will be asked for
9551 confirmation before the articles are deleted."
9552   (interactive "P")
9553   (unless (gnus-check-backend-function 'request-expire-articles
9554                                        gnus-newsgroup-name)
9555     (error "The current newsgroup does not support article deletion"))
9556   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9557     (error "Couldn't open server"))
9558   ;; Compute the list of articles to delete.
9559   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9560         (nnmail-expiry-target 'delete)
9561         not-deleted)
9562     (if (and gnus-novice-user
9563              (not (gnus-yes-or-no-p
9564                    (format "Do you really want to delete %s forever? "
9565                            (if (> (length articles) 1)
9566                                (format "these %s articles" (length articles))
9567                              "this article")))))
9568         ()
9569       ;; Delete the articles.
9570       (setq not-deleted (gnus-request-expire-articles
9571                          articles gnus-newsgroup-name 'force))
9572       (while articles
9573         (gnus-summary-remove-process-mark (car articles))
9574         ;; The backend might not have been able to delete the article
9575         ;; after all.
9576         (unless (memq (car articles) not-deleted)
9577           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9578         (let* ((article (car articles))
9579                (ghead  (gnus-data-header
9580                                     (assoc article (gnus-data-list nil)))))
9581           (run-hook-with-args 'gnus-summary-article-delete-hook
9582                               'delete ghead gnus-newsgroup-name nil
9583                               nil))
9584         (setq articles (cdr articles)))
9585       (when not-deleted
9586         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9587     (gnus-summary-position-point)
9588     (gnus-set-mode-line 'summary)
9589     not-deleted))
9590
9591 (defun gnus-summary-edit-article (&optional arg)
9592   "Edit the current article.
9593 This will have permanent effect only in mail groups.
9594 If ARG is nil, edit the decoded articles.
9595 If ARG is 1, edit the raw articles.
9596 If ARG is 2, edit the raw articles even in read-only groups.
9597 If ARG is 3, edit the articles with the current handles.
9598 Otherwise, allow editing of articles even in read-only
9599 groups."
9600   (interactive "P")
9601   (let (force raw current-handles)
9602     (cond
9603      ((null arg))
9604      ((eq arg 1)
9605       (setq raw t))
9606      ((eq arg 2)
9607       (setq raw t
9608             force t))
9609      ((eq arg 3)
9610       (setq current-handles
9611             (and (gnus-buffer-live-p gnus-article-buffer)
9612                  (with-current-buffer gnus-article-buffer
9613                    (prog1
9614                        gnus-article-mime-handles
9615                      (setq gnus-article-mime-handles nil))))))
9616      (t
9617       (setq force t)))
9618     (when (and raw (not force)
9619                (member gnus-newsgroup-name '("nndraft:delayed"
9620                                              "nndraft:drafts"
9621                                              "nndraft:queue")))
9622       (error "Can't edit the raw article in group %s"
9623              gnus-newsgroup-name))
9624     (save-excursion
9625       (set-buffer gnus-summary-buffer)
9626       (let ((mail-parse-charset gnus-newsgroup-charset)
9627             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9628         (gnus-set-global-variables)
9629         (when (and (not force)
9630                    (gnus-group-read-only-p))
9631           (error "The current newsgroup does not support article editing"))
9632         (gnus-summary-show-article t)
9633         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9634           (with-current-buffer gnus-article-buffer
9635             (mm-enable-multibyte)))
9636         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9637             (setq raw t))
9638         (gnus-article-edit-article
9639          (if raw 'ignore
9640            `(lambda ()
9641               (let ((mbl mml-buffer-list))
9642                 (setq mml-buffer-list nil)
9643                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9644                   (mime-to-mml ,'current-handles))
9645                 (let ((mbl1 mml-buffer-list))
9646                   (setq mml-buffer-list mbl)
9647                   (set (make-local-variable 'mml-buffer-list) mbl1))
9648                 (gnus-make-local-hook 'kill-buffer-hook)
9649                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9650          `(lambda (no-highlight)
9651             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9652                   (message-options message-options)
9653                   (message-options-set-recipient)
9654                   (mail-parse-ignored-charsets
9655                    ',gnus-newsgroup-ignored-charsets))
9656               ,(if (not raw) '(progn
9657                                 (mml-to-mime)
9658                                 (mml-destroy-buffers)
9659                                 (remove-hook 'kill-buffer-hook
9660                                              'mml-destroy-buffers t)
9661                                 (kill-local-variable 'mml-buffer-list)))
9662               (gnus-summary-edit-article-done
9663                ,(or (mail-header-references gnus-current-headers) "")
9664                ,(gnus-group-read-only-p)
9665                ,gnus-summary-buffer no-highlight))))))))
9666
9667 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9668
9669 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9670                                                  no-highlight)
9671   "Make edits to the current article permanent."
9672   (interactive)
9673   (save-excursion
9674    ;; The buffer restriction contains the entire article if it exists.
9675     (when (article-goto-body)
9676       (let ((lines (count-lines (point) (point-max)))
9677             (length (- (point-max) (point)))
9678             (case-fold-search t)
9679             (body (copy-marker (point))))
9680         (goto-char (point-min))
9681         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9682           (delete-region (match-beginning 1) (match-end 1))
9683           (insert (number-to-string length)))
9684         (goto-char (point-min))
9685         (when (re-search-forward
9686                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9687           (delete-region (match-beginning 1) (match-end 1))
9688           (insert (number-to-string length)))
9689         (goto-char (point-min))
9690         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9691           (delete-region (match-beginning 1) (match-end 1))
9692           (insert (number-to-string lines))))))
9693   ;; Replace the article.
9694   (let ((buf (current-buffer)))
9695     (with-temp-buffer
9696       (insert-buffer-substring buf)
9697
9698       (if (and (not read-only)
9699                (not (gnus-request-replace-article
9700                      (cdr gnus-article-current) (car gnus-article-current)
9701                      (current-buffer) t)))
9702           (error "Couldn't replace article")
9703         ;; Update the summary buffer.
9704         (if (and references
9705                  (equal (message-tokenize-header references " ")
9706                         (message-tokenize-header
9707                          (or (message-fetch-field "references") "") " ")))
9708             ;; We only have to update this line.
9709             (save-excursion
9710               (save-restriction
9711                 (message-narrow-to-head)
9712                 (let ((head (buffer-string))
9713                       header)
9714                   (with-temp-buffer
9715                     (insert (format "211 %d Article retrieved.\n"
9716                                     (cdr gnus-article-current)))
9717                     (insert head)
9718                     (insert ".\n")
9719                     (let ((nntp-server-buffer (current-buffer)))
9720                       (setq header (car (gnus-get-newsgroup-headers
9721                                          nil t))))
9722                     (save-excursion
9723                       (set-buffer gnus-summary-buffer)
9724                       (gnus-data-set-header
9725                        (gnus-data-find (cdr gnus-article-current))
9726                        header)
9727                       (gnus-summary-update-article-line
9728                        (cdr gnus-article-current) header)
9729                       (if (gnus-summary-goto-subject
9730                            (cdr gnus-article-current) nil t)
9731                           (gnus-summary-update-secondary-mark
9732                            (cdr gnus-article-current))))))))
9733           ;; Update threads.
9734           (set-buffer (or buffer gnus-summary-buffer))
9735           (gnus-summary-update-article (cdr gnus-article-current))
9736           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9737               (gnus-summary-update-secondary-mark
9738                (cdr gnus-article-current))))
9739         ;; Prettify the article buffer again.
9740         (unless no-highlight
9741           (save-excursion
9742             (set-buffer gnus-article-buffer)
9743             ;;;!!! Fix this -- article should be rehighlighted.
9744             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9745             (set-buffer gnus-original-article-buffer)
9746             (gnus-request-article
9747              (cdr gnus-article-current)
9748              (car gnus-article-current) (current-buffer))))
9749         ;; Prettify the summary buffer line.
9750         (when (gnus-visual-p 'summary-highlight 'highlight)
9751           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9752
9753 (defun gnus-summary-edit-wash (key)
9754   "Perform editing command KEY in the article buffer."
9755   (interactive
9756    (list
9757     (progn
9758       (message "%s" (concat (this-command-keys) "- "))
9759       (read-char))))
9760   (message "")
9761   (gnus-summary-edit-article)
9762   (execute-kbd-macro (concat (this-command-keys) key))
9763   (gnus-article-edit-done))
9764
9765 ;;; Respooling
9766
9767 (defun gnus-summary-respool-query (&optional silent trace)
9768   "Query where the respool algorithm would put this article."
9769   (interactive)
9770   (let (gnus-mark-article-hook)
9771     (gnus-summary-select-article)
9772     (save-excursion
9773       (set-buffer gnus-original-article-buffer)
9774       (let ((groups (nnmail-article-group 'identity trace)))
9775         (unless silent
9776           (if groups
9777               (message "This message would go to %s"
9778                        (mapconcat 'car groups ", "))
9779             (message "This message would go to no groups"))
9780           groups)))))
9781
9782 (defun gnus-summary-respool-trace ()
9783   "Trace where the respool algorithm would put this article.
9784 Display a buffer showing all fancy splitting patterns which matched."
9785   (interactive)
9786   (gnus-summary-respool-query nil t))
9787
9788 ;; Summary marking commands.
9789
9790 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9791   "Mark articles which has the same subject as read, and then select the next.
9792 If UNMARK is positive, remove any kind of mark.
9793 If UNMARK is negative, tick articles."
9794   (interactive "P")
9795   (when unmark
9796     (setq unmark (prefix-numeric-value unmark)))
9797   (let ((count
9798          (gnus-summary-mark-same-subject
9799           (gnus-summary-article-subject) unmark)))
9800     ;; Select next unread article.  If auto-select-same mode, should
9801     ;; select the first unread article.
9802     (gnus-summary-next-article t (and gnus-auto-select-same
9803                                       (gnus-summary-article-subject)))
9804     (gnus-message 7 "%d article%s marked as %s"
9805                   count (if (= count 1) " is" "s are")
9806                   (if unmark "unread" "read"))))
9807
9808 (defun gnus-summary-kill-same-subject (&optional unmark)
9809   "Mark articles which has the same subject as read.
9810 If UNMARK is positive, remove any kind of mark.
9811 If UNMARK is negative, tick articles."
9812   (interactive "P")
9813   (when unmark
9814     (setq unmark (prefix-numeric-value unmark)))
9815   (let ((count
9816          (gnus-summary-mark-same-subject
9817           (gnus-summary-article-subject) unmark)))
9818     ;; If marked as read, go to next unread subject.
9819     (when (null unmark)
9820       ;; Go to next unread subject.
9821       (gnus-summary-next-subject 1 t))
9822     (gnus-message 7 "%d articles are marked as %s"
9823                   count (if unmark "unread" "read"))))
9824
9825 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9826   "Mark articles with same SUBJECT as read, and return marked number.
9827 If optional argument UNMARK is positive, remove any kinds of marks.
9828 If optional argument UNMARK is negative, mark articles as unread instead."
9829   (let ((count 1))
9830     (save-excursion
9831       (cond
9832        ((null unmark)                   ; Mark as read.
9833         (while (and
9834                 (progn
9835                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9836                   (gnus-summary-show-thread) t)
9837                 (gnus-summary-find-subject subject))
9838           (setq count (1+ count))))
9839        ((> unmark 0)                    ; Tick.
9840         (while (and
9841                 (progn
9842                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9843                   (gnus-summary-show-thread) t)
9844                 (gnus-summary-find-subject subject))
9845           (setq count (1+ count))))
9846        (t                               ; Mark as unread.
9847         (while (and
9848                 (progn
9849                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9850                   (gnus-summary-show-thread) t)
9851                 (gnus-summary-find-subject subject))
9852           (setq count (1+ count)))))
9853       (gnus-set-mode-line 'summary)
9854       ;; Return the number of marked articles.
9855       count)))
9856
9857 (defun gnus-summary-mark-as-processable (n &optional unmark)
9858   "Set the process mark on the next N articles.
9859 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9860 the process mark instead.  The difference between N and the actual
9861 number of articles marked is returned."
9862   (interactive "P")
9863   (if (and (null n) (gnus-region-active-p))
9864       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9865     (setq n (prefix-numeric-value n))
9866     (let ((backward (< n 0))
9867           (n (abs n)))
9868       (while (and
9869               (> n 0)
9870               (if unmark
9871                   (gnus-summary-remove-process-mark
9872                    (gnus-summary-article-number))
9873                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9874               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9875         (setq n (1- n)))
9876       (when (/= 0 n)
9877         (gnus-message 7 "No more articles"))
9878       (gnus-summary-recenter)
9879       (gnus-summary-position-point)
9880       n)))
9881
9882 (defun gnus-summary-unmark-as-processable (n)
9883   "Remove the process mark from the next N articles.
9884 If N is negative, unmark backward instead.  The difference between N and
9885 the actual number of articles unmarked is returned."
9886   (interactive "P")
9887   (gnus-summary-mark-as-processable n t))
9888
9889 (defun gnus-summary-unmark-all-processable ()
9890   "Remove the process mark from all articles."
9891   (interactive)
9892   (save-excursion
9893     (while gnus-newsgroup-processable
9894       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9895   (gnus-summary-position-point))
9896
9897 (defun gnus-summary-add-mark (article type)
9898   "Mark ARTICLE with a mark of TYPE."
9899   (let ((vtype (car (assq type gnus-article-mark-lists)))
9900         var)
9901     (if (not vtype)
9902         (error "No such mark type: %s" type)
9903       (setq var (intern (format "gnus-newsgroup-%s" type)))
9904       (set var (cons article (symbol-value var)))
9905       (if (memq type '(processable cached replied forwarded recent saved))
9906           (gnus-summary-update-secondary-mark article)
9907         ;;; !!! This is bogus.  We should find out what primary
9908         ;;; !!! mark we want to set.
9909         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9910
9911 (defun gnus-summary-mark-as-expirable (n)
9912   "Mark N articles forward as expirable.
9913 If N is negative, mark backward instead.  The difference between N and
9914 the actual number of articles marked is returned."
9915   (interactive "p")
9916   (gnus-summary-mark-forward n gnus-expirable-mark))
9917
9918 (defun gnus-summary-mark-as-spam (n)
9919   "Mark N articles forward as spam.
9920 If N is negative, mark backward instead.  The difference between N and
9921 the actual number of articles marked is returned."
9922   (interactive "p")
9923   (gnus-summary-mark-forward n gnus-spam-mark))
9924
9925 (defun gnus-summary-mark-article-as-replied (article)
9926   "Mark ARTICLE as replied to and update the summary line.
9927 ARTICLE can also be a list of articles."
9928   (interactive (list (gnus-summary-article-number)))
9929   (let ((articles (if (listp article) article (list article))))
9930     (dolist (article articles)
9931       (unless (numberp article)
9932         (error "%s is not a number" article))
9933       (push article gnus-newsgroup-replied)
9934       (let ((buffer-read-only nil))
9935         (when (gnus-summary-goto-subject article nil t)
9936           (gnus-summary-update-secondary-mark article))))))
9937
9938 (defun gnus-summary-mark-article-as-forwarded (article)
9939   "Mark ARTICLE as forwarded and update the summary line.
9940 ARTICLE can also be a list of articles."
9941   (let ((articles (if (listp article) article (list article))))
9942     (dolist (article articles)
9943       (push article gnus-newsgroup-forwarded)
9944       (let ((buffer-read-only nil))
9945         (when (gnus-summary-goto-subject article nil t)
9946           (gnus-summary-update-secondary-mark article))))))
9947
9948 (defun gnus-summary-set-bookmark (article)
9949   "Set a bookmark in current article."
9950   (interactive (list (gnus-summary-article-number)))
9951   (when (or (not (get-buffer gnus-article-buffer))
9952             (not gnus-current-article)
9953             (not gnus-article-current)
9954             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9955     (error "No current article selected"))
9956   ;; Remove old bookmark, if one exists.
9957   (gnus-pull article gnus-newsgroup-bookmarks)
9958   ;; Set the new bookmark, which is on the form
9959   ;; (article-number . line-number-in-body).
9960   (push
9961    (cons article
9962          (with-current-buffer gnus-article-buffer
9963            (count-lines
9964             (min (point)
9965                  (save-excursion
9966                    (article-goto-body)
9967                    (point)))
9968             (point))))
9969    gnus-newsgroup-bookmarks)
9970   (gnus-message 6 "A bookmark has been added to the current article."))
9971
9972 (defun gnus-summary-remove-bookmark (article)
9973   "Remove the bookmark from the current article."
9974   (interactive (list (gnus-summary-article-number)))
9975   ;; Remove old bookmark, if one exists.
9976   (if (not (assq article gnus-newsgroup-bookmarks))
9977       (gnus-message 6 "No bookmark in current article.")
9978     (gnus-pull article gnus-newsgroup-bookmarks)
9979     (gnus-message 6 "Removed bookmark.")))
9980
9981 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9982 (defun gnus-summary-mark-as-dormant (n)
9983   "Mark N articles forward as dormant.
9984 If N is negative, mark backward instead.  The difference between N and
9985 the actual number of articles marked is returned."
9986   (interactive "p")
9987   (gnus-summary-mark-forward n gnus-dormant-mark))
9988
9989 (defun gnus-summary-set-process-mark (article)
9990   "Set the process mark on ARTICLE and update the summary line."
9991   (setq gnus-newsgroup-processable
9992         (cons article
9993               (delq article gnus-newsgroup-processable)))
9994   (when (gnus-summary-goto-subject article)
9995     (gnus-summary-show-thread)
9996     (gnus-summary-goto-subject article)
9997     (gnus-summary-update-secondary-mark article)))
9998
9999 (defun gnus-summary-remove-process-mark (&rest articles)
10000   "Remove the process mark from ARTICLES and update the summary line."
10001   (dolist (article articles)
10002     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10003     (when (gnus-summary-goto-subject article)
10004       (gnus-summary-show-thread)
10005       (gnus-summary-goto-subject article)
10006       (gnus-summary-update-secondary-mark article))))
10007
10008 (defun gnus-summary-set-saved-mark (article)
10009   "Set the process mark on ARTICLE and update the summary line."
10010   (push article gnus-newsgroup-saved)
10011   (when (gnus-summary-goto-subject article)
10012     (gnus-summary-update-secondary-mark article)))
10013
10014 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10015   "Mark N articles as read forwards.
10016 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10017 The difference between N and the actual number of articles marked is
10018 returned.
10019 If NO-EXPIRE, auto-expiry will be inhibited."
10020   (interactive "p")
10021   (gnus-summary-show-thread)
10022   (let ((backward (< n 0))
10023         (gnus-summary-goto-unread
10024          (and gnus-summary-goto-unread
10025               (not (eq gnus-summary-goto-unread 'never))
10026               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10027                                     gnus-ticked-mark gnus-dormant-mark)))))
10028         (n (abs n))
10029         (mark (or mark gnus-del-mark)))
10030     (while (and (> n 0)
10031                 (gnus-summary-mark-article nil mark no-expire)
10032                 (zerop (gnus-summary-next-subject
10033                         (if backward -1 1)
10034                         (and gnus-summary-goto-unread
10035                              (not (eq gnus-summary-goto-unread 'never)))
10036                         t)))
10037       (setq n (1- n)))
10038     (when (/= 0 n)
10039       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10040     (gnus-summary-recenter)
10041     (gnus-summary-position-point)
10042     (gnus-set-mode-line 'summary)
10043     n))
10044
10045 (defun gnus-summary-mark-article-as-read (mark)
10046   "Mark the current article quickly as read with MARK."
10047   (let ((article (gnus-summary-article-number)))
10048     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10049     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10050     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10051     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10052     (push (cons article mark) gnus-newsgroup-reads)
10053     ;; Possibly remove from cache, if that is used.
10054     (when gnus-use-cache
10055       (gnus-cache-enter-remove-article article))
10056     ;; Allow the backend to change the mark.
10057     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10058     ;; Check for auto-expiry.
10059     (when (and gnus-newsgroup-auto-expire
10060                (memq mark gnus-auto-expirable-marks))
10061       (setq mark gnus-expirable-mark)
10062       ;; Let the backend know about the mark change.
10063       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10064       (push article gnus-newsgroup-expirable))
10065     ;; Set the mark in the buffer.
10066     (gnus-summary-update-mark mark 'unread)
10067     t))
10068
10069 (defun gnus-summary-mark-article-as-unread (mark)
10070   "Mark the current article quickly as unread with MARK."
10071   (let* ((article (gnus-summary-article-number))
10072          (old-mark (gnus-summary-article-mark article)))
10073     ;; Allow the backend to change the mark.
10074     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10075     (if (eq mark old-mark)
10076         t
10077       (if (<= article 0)
10078           (progn
10079             (gnus-error 1 "Can't mark negative article numbers")
10080             nil)
10081         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10082         (setq gnus-newsgroup-spam-marked
10083               (delq article gnus-newsgroup-spam-marked))
10084         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10085         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10086         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10087         (cond ((= mark gnus-ticked-mark)
10088                (setq gnus-newsgroup-marked
10089                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10090                                               article)))
10091               ((= mark gnus-spam-mark)
10092                (setq gnus-newsgroup-spam-marked
10093                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10094                                               article)))
10095               ((= mark gnus-dormant-mark)
10096                (setq gnus-newsgroup-dormant
10097                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10098                                               article)))
10099               (t
10100                (setq gnus-newsgroup-unreads
10101                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10102                                               article))))
10103         (gnus-pull article gnus-newsgroup-reads)
10104
10105         ;; See whether the article is to be put in the cache.
10106         (and gnus-use-cache
10107              (vectorp (gnus-summary-article-header article))
10108              (save-excursion
10109                (gnus-cache-possibly-enter-article
10110                 gnus-newsgroup-name article
10111                 (= mark gnus-ticked-mark)
10112                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10113
10114         ;; Fix the mark.
10115         (gnus-summary-update-mark mark 'unread)
10116         t))))
10117
10118 (defun gnus-summary-mark-article (&optional article mark no-expire)
10119   "Mark ARTICLE with MARK.  MARK can be any character.
10120 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10121 `??' (dormant) and `?E' (expirable).
10122 If MARK is nil, then the default character `?r' is used.
10123 If ARTICLE is nil, then the article on the current line will be
10124 marked.
10125 If NO-EXPIRE, auto-expiry will be inhibited."
10126   ;; The mark might be a string.
10127   (when (stringp mark)
10128     (setq mark (aref mark 0)))
10129   ;; If no mark is given, then we check auto-expiring.
10130   (when (null mark)
10131     (setq mark gnus-del-mark))
10132   (when (and (not no-expire)
10133              gnus-newsgroup-auto-expire
10134              (memq mark gnus-auto-expirable-marks))
10135     (setq mark gnus-expirable-mark))
10136   (let ((article (or article (gnus-summary-article-number)))
10137         (old-mark (gnus-summary-article-mark article)))
10138     ;; Allow the backend to change the mark.
10139     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10140     (if (eq mark old-mark)
10141         t
10142       (unless article
10143         (error "No article on current line"))
10144       (if (not (if (or (= mark gnus-unread-mark)
10145                        (= mark gnus-ticked-mark)
10146                        (= mark gnus-spam-mark)
10147                        (= mark gnus-dormant-mark))
10148                    (gnus-mark-article-as-unread article mark)
10149                  (gnus-mark-article-as-read article mark)))
10150           t
10151         ;; See whether the article is to be put in the cache.
10152         (and gnus-use-cache
10153              (not (= mark gnus-canceled-mark))
10154              (vectorp (gnus-summary-article-header article))
10155              (save-excursion
10156                (gnus-cache-possibly-enter-article
10157                 gnus-newsgroup-name article
10158                 (= mark gnus-ticked-mark)
10159                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10160
10161         (when (gnus-summary-goto-subject article nil t)
10162           (let ((buffer-read-only nil))
10163             (gnus-summary-show-thread)
10164             ;; Fix the mark.
10165             (gnus-summary-update-mark mark 'unread)
10166             t))))))
10167
10168 (defun gnus-summary-update-secondary-mark (article)
10169   "Update the secondary (read, process, cache) mark."
10170   (gnus-summary-update-mark
10171    (cond ((memq article gnus-newsgroup-processable)
10172           gnus-process-mark)
10173          ((memq article gnus-newsgroup-cached)
10174           gnus-cached-mark)
10175          ((memq article gnus-newsgroup-replied)
10176           gnus-replied-mark)
10177          ((memq article gnus-newsgroup-forwarded)
10178           gnus-forwarded-mark)
10179          ((memq article gnus-newsgroup-saved)
10180           gnus-saved-mark)
10181          ((memq article gnus-newsgroup-recent)
10182           gnus-recent-mark)
10183          ((memq article gnus-newsgroup-unseen)
10184           gnus-unseen-mark)
10185          (t gnus-no-mark))
10186    'replied)
10187   (when (gnus-visual-p 'summary-highlight 'highlight)
10188     (gnus-run-hooks 'gnus-summary-update-hook))
10189   t)
10190
10191 (defun gnus-summary-update-download-mark (article)
10192   "Update the download mark."
10193   (gnus-summary-update-mark
10194    (cond ((memq article gnus-newsgroup-undownloaded)
10195           gnus-undownloaded-mark)
10196          (gnus-newsgroup-agentized
10197           gnus-downloaded-mark)
10198          (t
10199           gnus-no-mark))
10200    'download)
10201   (gnus-summary-update-line t)
10202   t)
10203
10204 (defun gnus-summary-update-mark (mark type)
10205   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10206         (buffer-read-only nil))
10207     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10208     (when forward
10209       (when (looking-at "\r")
10210         (incf forward))
10211       (when (<= (+ forward (point)) (point-max))
10212         ;; Go to the right position on the line.
10213         (goto-char (+ forward (point)))
10214         ;; Replace the old mark with the new mark.
10215         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10216         ;; Optionally update the marks by some user rule.
10217         (when (eq type 'unread)
10218           (gnus-data-set-mark
10219            (gnus-data-find (gnus-summary-article-number)) mark)
10220           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10221
10222 (defun gnus-mark-article-as-read (article &optional mark)
10223   "Enter ARTICLE in the pertinent lists and remove it from others."
10224   ;; Make the article expirable.
10225   (let ((mark (or mark gnus-del-mark)))
10226     (setq gnus-newsgroup-expirable
10227           (if (= mark gnus-expirable-mark)
10228               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10229             (delq article gnus-newsgroup-expirable)))
10230     ;; Remove from unread and marked lists.
10231     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10232     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10233     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10234     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10235     (push (cons article mark) gnus-newsgroup-reads)
10236     ;; Possibly remove from cache, if that is used.
10237     (when gnus-use-cache
10238       (gnus-cache-enter-remove-article article))
10239     t))
10240
10241 (defun gnus-mark-article-as-unread (article &optional mark)
10242   "Enter ARTICLE in the pertinent lists and remove it from others."
10243   (let ((mark (or mark gnus-ticked-mark)))
10244     (if (<= article 0)
10245         (progn
10246           (gnus-error 1 "Can't mark negative article numbers")
10247           nil)
10248       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10249             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10250             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10251             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10252             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10253
10254       ;; Unsuppress duplicates?
10255       (when gnus-suppress-duplicates
10256         (gnus-dup-unsuppress-article article))
10257
10258       (cond ((= mark gnus-ticked-mark)
10259              (setq gnus-newsgroup-marked
10260                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10261             ((= mark gnus-spam-mark)
10262              (setq gnus-newsgroup-spam-marked
10263                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10264                                             article)))
10265             ((= mark gnus-dormant-mark)
10266              (setq gnus-newsgroup-dormant
10267                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10268             (t
10269              (setq gnus-newsgroup-unreads
10270                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10271       (gnus-pull article gnus-newsgroup-reads)
10272       t)))
10273
10274 (defalias 'gnus-summary-mark-as-unread-forward
10275   'gnus-summary-tick-article-forward)
10276 (make-obsolete 'gnus-summary-mark-as-unread-forward
10277                'gnus-summary-tick-article-forward)
10278 (defun gnus-summary-tick-article-forward (n)
10279   "Tick N articles forwards.
10280 If N is negative, tick backwards instead.
10281 The difference between N and the number of articles ticked is returned."
10282   (interactive "p")
10283   (gnus-summary-mark-forward n gnus-ticked-mark))
10284
10285 (defalias 'gnus-summary-mark-as-unread-backward
10286   'gnus-summary-tick-article-backward)
10287 (make-obsolete 'gnus-summary-mark-as-unread-backward
10288                'gnus-summary-tick-article-backward)
10289 (defun gnus-summary-tick-article-backward (n)
10290   "Tick N articles backwards.
10291 The difference between N and the number of articles ticked is returned."
10292   (interactive "p")
10293   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10294
10295 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10296 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10297 (defun gnus-summary-tick-article (&optional article clear-mark)
10298   "Mark current article as unread.
10299 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10300 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10301   (interactive)
10302   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10303                                        gnus-ticked-mark)))
10304
10305 (defun gnus-summary-mark-as-read-forward (n)
10306   "Mark N articles as read forwards.
10307 If N is negative, mark backwards instead.
10308 The difference between N and the actual number of articles marked is
10309 returned."
10310   (interactive "p")
10311   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10312
10313 (defun gnus-summary-mark-as-read-backward (n)
10314   "Mark the N articles as read backwards.
10315 The difference between N and the actual number of articles marked is
10316 returned."
10317   (interactive "p")
10318   (gnus-summary-mark-forward
10319    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10320
10321 (defun gnus-summary-mark-as-read (&optional article mark)
10322   "Mark current article as read.
10323 ARTICLE specifies the article to be marked as read.
10324 MARK specifies a string to be inserted at the beginning of the line."
10325   (gnus-summary-mark-article article mark))
10326
10327 (defun gnus-summary-clear-mark-forward (n)
10328   "Clear marks from N articles forward.
10329 If N is negative, clear backward instead.
10330 The difference between N and the number of marks cleared is returned."
10331   (interactive "p")
10332   (gnus-summary-mark-forward n gnus-unread-mark))
10333
10334 (defun gnus-summary-clear-mark-backward (n)
10335   "Clear marks from N articles backward.
10336 The difference between N and the number of marks cleared is returned."
10337   (interactive "p")
10338   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10339
10340 (defun gnus-summary-mark-unread-as-read ()
10341   "Intended to be used by `gnus-summary-mark-article-hook'."
10342   (when (memq gnus-current-article gnus-newsgroup-unreads)
10343     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10344
10345 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10346   "Intended to be used by `gnus-summary-mark-article-hook'."
10347   (let ((mark (gnus-summary-article-mark)))
10348     (when (or (gnus-unread-mark-p mark)
10349               (gnus-read-mark-p mark))
10350       (gnus-summary-mark-article gnus-current-article
10351                                  (or new-mark gnus-read-mark)))))
10352
10353 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10354   "Intended to be used by `gnus-summary-mark-article-hook'."
10355   (let ((mark (gnus-summary-article-mark)))
10356     (when (or (gnus-unread-mark-p mark)
10357               (gnus-read-mark-p mark))
10358       (gnus-summary-mark-article (gnus-summary-article-number)
10359                                  (or new-mark gnus-read-mark)))))
10360
10361 (defun gnus-summary-mark-unread-as-ticked ()
10362   "Intended to be used by `gnus-summary-mark-article-hook'."
10363   (when (memq gnus-current-article gnus-newsgroup-unreads)
10364     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10365
10366 (defun gnus-summary-mark-region-as-read (point mark all)
10367   "Mark all unread articles between point and mark as read.
10368 If given a prefix, mark all articles between point and mark as read,
10369 even ticked and dormant ones."
10370   (interactive "r\nP")
10371   (save-excursion
10372     (let (article)
10373       (goto-char point)
10374       (beginning-of-line)
10375       (while (and
10376               (< (point) mark)
10377               (progn
10378                 (when (or all
10379                           (memq (setq article (gnus-summary-article-number))
10380                                 gnus-newsgroup-unreads))
10381                   (gnus-summary-mark-article article gnus-del-mark))
10382                 t)
10383               (gnus-summary-find-next))))))
10384
10385 (defun gnus-summary-mark-below (score mark)
10386   "Mark articles with score less than SCORE with MARK."
10387   (interactive "P\ncMark: ")
10388   (setq score (if score
10389                   (prefix-numeric-value score)
10390                 (or gnus-summary-default-score 0)))
10391   (save-excursion
10392     (set-buffer gnus-summary-buffer)
10393     (goto-char (point-min))
10394     (while
10395         (progn
10396           (and (< (gnus-summary-article-score) score)
10397                (gnus-summary-mark-article nil mark))
10398           (gnus-summary-find-next)))))
10399
10400 (defun gnus-summary-kill-below (&optional score)
10401   "Mark articles with score below SCORE as read."
10402   (interactive "P")
10403   (gnus-summary-mark-below score gnus-killed-mark))
10404
10405 (defun gnus-summary-clear-above (&optional score)
10406   "Clear all marks from articles with score above SCORE."
10407   (interactive "P")
10408   (gnus-summary-mark-above score gnus-unread-mark))
10409
10410 (defun gnus-summary-tick-above (&optional score)
10411   "Tick all articles with score above SCORE."
10412   (interactive "P")
10413   (gnus-summary-mark-above score gnus-ticked-mark))
10414
10415 (defun gnus-summary-mark-above (score mark)
10416   "Mark articles with score over SCORE with MARK."
10417   (interactive "P\ncMark: ")
10418   (setq score (if score
10419                   (prefix-numeric-value score)
10420                 (or gnus-summary-default-score 0)))
10421   (save-excursion
10422     (set-buffer gnus-summary-buffer)
10423     (goto-char (point-min))
10424     (while (and (progn
10425                   (when (> (gnus-summary-article-score) score)
10426                     (gnus-summary-mark-article nil mark))
10427                   t)
10428                 (gnus-summary-find-next)))))
10429
10430 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10431 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10432 (defun gnus-summary-limit-include-expunged (&optional no-error)
10433   "Display all the hidden articles that were expunged for low scores."
10434   (interactive)
10435   (let ((buffer-read-only nil))
10436     (let ((scored gnus-newsgroup-scored)
10437           headers h)
10438       (while scored
10439         (unless (gnus-summary-article-header (caar scored))
10440           (and (setq h (gnus-number-to-header (caar scored)))
10441                (< (cdar scored) gnus-summary-expunge-below)
10442                (push h headers)))
10443         (setq scored (cdr scored)))
10444       (if (not headers)
10445           (when (not no-error)
10446             (error "No expunged articles hidden"))
10447         (goto-char (point-min))
10448         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10449         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10450         (mapcar (lambda (x) (push (mail-header-number x)
10451                                   gnus-newsgroup-limit))
10452                 headers)
10453         (gnus-summary-prepare-unthreaded (nreverse headers))
10454         (goto-char (point-min))
10455         (gnus-summary-position-point)
10456         t))))
10457
10458 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10459   "Mark all unread articles in this newsgroup as read.
10460 If prefix argument ALL is non-nil, ticked and dormant articles will
10461 also be marked as read.
10462 If QUIETLY is non-nil, no questions will be asked.
10463
10464 If TO-HERE is non-nil, it should be a point in the buffer.  All
10465 articles before (after, if REVERSE is set) this point will be marked
10466 as read.
10467
10468 Note that this function will only catch up the unread article
10469 in the current summary buffer limitation.
10470
10471 The number of articles marked as read is returned."
10472   (interactive "P")
10473   (prog1
10474       (save-excursion
10475         (when (or quietly
10476                   (not gnus-interactive-catchup) ;Without confirmation?
10477                   gnus-expert-user
10478                   (gnus-y-or-n-p
10479                    (if all
10480                        "Mark absolutely all articles as read? "
10481                      "Mark all unread articles as read? ")))
10482           (if (and not-mark
10483                    (not gnus-newsgroup-adaptive)
10484                    (not gnus-newsgroup-auto-expire)
10485                    (not gnus-suppress-duplicates)
10486                    (or (not gnus-use-cache)
10487                        (eq gnus-use-cache 'passive)))
10488               (progn
10489                 (when all
10490                   (setq gnus-newsgroup-marked nil
10491                         gnus-newsgroup-spam-marked nil
10492                         gnus-newsgroup-dormant nil))
10493                 (setq gnus-newsgroup-unreads
10494                       (gnus-sorted-nunion
10495                        (gnus-intersection gnus-newsgroup-unreads
10496                                           gnus-newsgroup-downloadable)
10497                        gnus-newsgroup-unfetched)))
10498             ;; We actually mark all articles as canceled, which we
10499             ;; have to do when using auto-expiry or adaptive scoring.
10500             (gnus-summary-show-all-threads)
10501             (if (and to-here reverse)
10502                 (progn
10503                   (goto-char to-here)
10504                   (gnus-summary-mark-current-read-and-unread-as-read
10505                    gnus-catchup-mark)
10506                   (while (gnus-summary-find-next (not all))
10507                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10508               (when (gnus-summary-first-subject (not all))
10509                 (while (and
10510                         (if to-here (< (point) to-here) t)
10511                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10512                         (gnus-summary-find-next (not all))))))
10513             (gnus-set-mode-line 'summary))
10514           t))
10515     (gnus-summary-position-point)))
10516
10517 (defun gnus-summary-catchup-to-here (&optional all)
10518   "Mark all unticked articles before the current one as read.
10519 If ALL is non-nil, also mark ticked and dormant articles as read."
10520   (interactive "P")
10521   (save-excursion
10522     (gnus-save-hidden-threads
10523       (let ((beg (point)))
10524         ;; We check that there are unread articles.
10525         (when (or all (gnus-summary-find-prev))
10526           (gnus-summary-catchup all t beg)))))
10527   (gnus-summary-position-point))
10528
10529 (defun gnus-summary-catchup-from-here (&optional all)
10530   "Mark all unticked articles after (and including) the current one as read.
10531 If ALL is non-nil, also mark ticked and dormant articles as read."
10532   (interactive "P")
10533   (save-excursion
10534     (gnus-save-hidden-threads
10535       (let ((beg (point)))
10536         ;; We check that there are unread articles.
10537         (when (or all (gnus-summary-find-next))
10538           (gnus-summary-catchup all t beg nil t)))))
10539   (gnus-summary-position-point))
10540
10541 (defun gnus-summary-catchup-all (&optional quietly)
10542   "Mark all articles in this newsgroup as read.
10543 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10544 instead, which marks only unread articles as read."
10545   (interactive "P")
10546   (gnus-summary-catchup t quietly))
10547
10548 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10549   "Mark all unread articles in this group as read, then exit.
10550 If prefix argument ALL is non-nil, all articles are marked as read.
10551 If QUIETLY is non-nil, no questions will be asked."
10552   (interactive "P")
10553   (when (gnus-summary-catchup all quietly nil 'fast)
10554     ;; Select next newsgroup or exit.
10555     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10556              (eq gnus-auto-select-next 'quietly))
10557         (gnus-summary-next-group nil)
10558       (gnus-summary-exit))))
10559
10560 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10561   "Mark all articles in this newsgroup as read, and then exit.
10562 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10563 instead, which marks only unread articles as read."
10564   (interactive "P")
10565   (gnus-summary-catchup-and-exit t quietly))
10566
10567 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10568   "Mark all articles in this group as read and select the next group.
10569 If given a prefix, mark all articles, unread as well as ticked, as
10570 read."
10571   (interactive "P")
10572   (save-excursion
10573     (gnus-summary-catchup all))
10574   (gnus-summary-next-group))
10575
10576 ;;;
10577 ;;; with article
10578 ;;;
10579
10580 (defmacro gnus-with-article (article &rest forms)
10581   "Select ARTICLE and perform FORMS in the original article buffer.
10582 Then replace the article with the result."
10583   `(progn
10584      ;; We don't want the article to be marked as read.
10585      (let (gnus-mark-article-hook)
10586        (gnus-summary-select-article t t nil ,article))
10587      (set-buffer gnus-original-article-buffer)
10588      ,@forms
10589      (if (not (gnus-check-backend-function
10590                'request-replace-article (car gnus-article-current)))
10591          (gnus-message 5 "Read-only group; not replacing")
10592        (unless (gnus-request-replace-article
10593                 ,article (car gnus-article-current)
10594                 (current-buffer) t)
10595          (error "Couldn't replace article")))
10596      ;; The cache and backlog have to be flushed somewhat.
10597      (when gnus-keep-backlog
10598        (gnus-backlog-remove-article
10599         (car gnus-article-current) (cdr gnus-article-current)))
10600      (when gnus-use-cache
10601        (gnus-cache-update-article
10602         (car gnus-article-current) (cdr gnus-article-current)))))
10603
10604 (put 'gnus-with-article 'lisp-indent-function 1)
10605 (put 'gnus-with-article 'edebug-form-spec '(form body))
10606
10607 ;; Thread-based commands.
10608
10609 (defun gnus-summary-articles-in-thread (&optional article)
10610   "Return a list of all articles in the current thread.
10611 If ARTICLE is non-nil, return all articles in the thread that starts
10612 with that article."
10613   (let* ((article (or article (gnus-summary-article-number)))
10614          (data (gnus-data-find-list article))
10615          (top-level (gnus-data-level (car data)))
10616          (top-subject
10617           (cond ((null gnus-thread-operation-ignore-subject)
10618                  (gnus-simplify-subject-re
10619                   (mail-header-subject (gnus-data-header (car data)))))
10620                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10621                  (gnus-simplify-subject-fuzzy
10622                   (mail-header-subject (gnus-data-header (car data)))))
10623                 (t nil)))
10624          (end-point (save-excursion
10625                       (if (gnus-summary-go-to-next-thread)
10626                           (point) (point-max))))
10627          articles)
10628     (while (and data
10629                 (< (gnus-data-pos (car data)) end-point))
10630       (when (or (not top-subject)
10631                 (string= top-subject
10632                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10633                              (gnus-simplify-subject-fuzzy
10634                               (mail-header-subject
10635                                (gnus-data-header (car data))))
10636                            (gnus-simplify-subject-re
10637                             (mail-header-subject
10638                              (gnus-data-header (car data)))))))
10639         (push (gnus-data-number (car data)) articles))
10640       (unless (and (setq data (cdr data))
10641                    (> (gnus-data-level (car data)) top-level))
10642         (setq data nil)))
10643     ;; Return the list of articles.
10644     (nreverse articles)))
10645
10646 (defun gnus-summary-rethread-current ()
10647   "Rethread the thread the current article is part of."
10648   (interactive)
10649   (let* ((gnus-show-threads t)
10650          (article (gnus-summary-article-number))
10651          (id (mail-header-id (gnus-summary-article-header)))
10652          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10653     (unless id
10654       (error "No article on the current line"))
10655     (gnus-rebuild-thread id)
10656     (gnus-summary-goto-subject article)))
10657
10658 (defun gnus-summary-reparent-thread ()
10659   "Make the current article child of the marked (or previous) article.
10660
10661 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10662 is non-nil or the Subject: of both articles are the same."
10663   (interactive)
10664   (unless (not (gnus-group-read-only-p))
10665     (error "The current newsgroup does not support article editing"))
10666   (unless (<= (length gnus-newsgroup-processable) 1)
10667     (error "No more than one article may be marked"))
10668   (save-window-excursion
10669     (let ((gnus-article-buffer " *reparent*")
10670           (current-article (gnus-summary-article-number))
10671           ;; First grab the marked article, otherwise one line up.
10672           (parent-article (if (not (null gnus-newsgroup-processable))
10673                               (car gnus-newsgroup-processable)
10674                             (save-excursion
10675                               (if (eq (forward-line -1) 0)
10676                                   (gnus-summary-article-number)
10677                                 (error "Beginning of summary buffer"))))))
10678       (unless (not (eq current-article parent-article))
10679         (error "An article may not be self-referential"))
10680       (let ((message-id (mail-header-id
10681                          (gnus-summary-article-header parent-article))))
10682         (unless (and message-id (not (equal message-id "")))
10683           (error "No message-id in desired parent"))
10684         (gnus-with-article current-article
10685           (save-restriction
10686             (goto-char (point-min))
10687             (message-narrow-to-head)
10688             (if (re-search-forward "^References: " nil t)
10689                 (progn
10690                   (re-search-forward "^[^ \t]" nil t)
10691                   (forward-line -1)
10692                   (end-of-line)
10693                   (insert " " message-id))
10694               (insert "References: " message-id "\n"))))
10695         (set-buffer gnus-summary-buffer)
10696         (gnus-summary-unmark-all-processable)
10697         (gnus-summary-update-article current-article)
10698         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10699             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10700         (gnus-summary-rethread-current)
10701         (gnus-message 3 "Article %d is now the child of article %d"
10702                       current-article parent-article)))))
10703
10704 (defun gnus-summary-toggle-threads (&optional arg)
10705   "Toggle showing conversation threads.
10706 If ARG is positive number, turn showing conversation threads on."
10707   (interactive "P")
10708   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10709     (setq gnus-show-threads
10710           (if (null arg) (not gnus-show-threads)
10711             (> (prefix-numeric-value arg) 0)))
10712     (gnus-summary-prepare)
10713     (gnus-summary-goto-subject current)
10714     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10715     (gnus-summary-position-point)))
10716
10717 (defun gnus-summary-show-all-threads ()
10718   "Show all threads."
10719   (interactive)
10720   (save-excursion
10721     (let ((buffer-read-only nil))
10722       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10723   (gnus-summary-position-point))
10724
10725 (defun gnus-summary-show-thread ()
10726   "Show thread subtrees.
10727 Returns nil if no thread was there to be shown."
10728   (interactive)
10729   (let ((buffer-read-only nil)
10730         (orig (point))
10731         (end (point-at-eol))
10732         ;; Leave point at bol
10733         (beg (progn (beginning-of-line) (point))))
10734     (prog1
10735         ;; Any hidden lines here?
10736         (search-forward "\r" end t)
10737       (subst-char-in-region beg end ?\^M ?\n t)
10738       (goto-char orig)
10739       (gnus-summary-position-point))))
10740
10741 (defun gnus-summary-maybe-hide-threads ()
10742   "If requested, hide the threads that should be hidden."
10743   (when (and gnus-show-threads
10744              gnus-thread-hide-subtree)
10745     (gnus-summary-hide-all-threads
10746      (if (or (consp gnus-thread-hide-subtree)
10747              (functionp gnus-thread-hide-subtree))
10748          (gnus-make-predicate gnus-thread-hide-subtree)
10749        nil))))
10750
10751 ;;; Hiding predicates.
10752
10753 (defun gnus-article-unread-p (header)
10754   (memq (mail-header-number header) gnus-newsgroup-unreads))
10755
10756 (defun gnus-article-unseen-p (header)
10757   (memq (mail-header-number header) gnus-newsgroup-unseen))
10758
10759 (defun gnus-map-articles (predicate articles)
10760   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10761   (apply 'gnus-or (mapcar predicate
10762                           (mapcar 'gnus-summary-article-header articles))))
10763
10764 (defun gnus-summary-hide-all-threads (&optional predicate)
10765   "Hide all thread subtrees.
10766 If PREDICATE is supplied, threads that satisfy this predicate
10767 will not be hidden."
10768   (interactive)
10769   (save-excursion
10770     (goto-char (point-min))
10771     (let ((end nil))
10772       (while (not end)
10773         (when (or (not predicate)
10774                   (gnus-map-articles
10775                    predicate (gnus-summary-article-children)))
10776             (gnus-summary-hide-thread))
10777         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10778   (gnus-summary-position-point))
10779
10780 (defun gnus-summary-hide-thread ()
10781   "Hide thread subtrees.
10782 If PREDICATE is supplied, threads that satisfy this predicate
10783 will not be hidden.
10784 Returns nil if no threads were there to be hidden."
10785   (interactive)
10786   (let ((buffer-read-only nil)
10787         (start (point))
10788         (article (gnus-summary-article-number)))
10789     (goto-char start)
10790     ;; Go forward until either the buffer ends or the subthread
10791     ;; ends.
10792     (when (and (not (eobp))
10793                (or (zerop (gnus-summary-next-thread 1 t))
10794                    (goto-char (point-max))))
10795       (prog1
10796           (if (and (> (point) start)
10797                    (search-backward "\n" start t))
10798               (progn
10799                 (subst-char-in-region start (point) ?\n ?\^M)
10800                 (gnus-summary-goto-subject article))
10801             (goto-char start)
10802             nil)))))
10803
10804 (defun gnus-summary-go-to-next-thread (&optional previous)
10805   "Go to the same level (or less) next thread.
10806 If PREVIOUS is non-nil, go to previous thread instead.
10807 Return the article number moved to, or nil if moving was impossible."
10808   (let ((level (gnus-summary-thread-level))
10809         (way (if previous -1 1))
10810         (beg (point)))
10811     (forward-line way)
10812     (while (and (not (eobp))
10813                 (< level (gnus-summary-thread-level)))
10814       (forward-line way))
10815     (if (eobp)
10816         (progn
10817           (goto-char beg)
10818           nil)
10819       (setq beg (point))
10820       (prog1
10821           (gnus-summary-article-number)
10822         (goto-char beg)))))
10823
10824 (defun gnus-summary-next-thread (n &optional silent)
10825   "Go to the same level next N'th thread.
10826 If N is negative, search backward instead.
10827 Returns the difference between N and the number of skips actually
10828 done.
10829
10830 If SILENT, don't output messages."
10831   (interactive "p")
10832   (let ((backward (< n 0))
10833         (n (abs n)))
10834     (while (and (> n 0)
10835                 (gnus-summary-go-to-next-thread backward))
10836       (decf n))
10837     (unless silent
10838       (gnus-summary-position-point))
10839     (when (and (not silent) (/= 0 n))
10840       (gnus-message 7 "No more threads"))
10841     n))
10842
10843 (defun gnus-summary-prev-thread (n)
10844   "Go to the same level previous N'th thread.
10845 Returns the difference between N and the number of skips actually
10846 done."
10847   (interactive "p")
10848   (gnus-summary-next-thread (- n)))
10849
10850 (defun gnus-summary-go-down-thread ()
10851   "Go down one level in the current thread."
10852   (let ((children (gnus-summary-article-children)))
10853     (when children
10854       (gnus-summary-goto-subject (car children)))))
10855
10856 (defun gnus-summary-go-up-thread ()
10857   "Go up one level in the current thread."
10858   (let ((parent (gnus-summary-article-parent)))
10859     (when parent
10860       (gnus-summary-goto-subject parent))))
10861
10862 (defun gnus-summary-down-thread (n)
10863   "Go down thread N steps.
10864 If N is negative, go up instead.
10865 Returns the difference between N and how many steps down that were
10866 taken."
10867   (interactive "p")
10868   (let ((up (< n 0))
10869         (n (abs n)))
10870     (while (and (> n 0)
10871                 (if up (gnus-summary-go-up-thread)
10872                   (gnus-summary-go-down-thread)))
10873       (setq n (1- n)))
10874     (gnus-summary-position-point)
10875     (when (/= 0 n)
10876       (gnus-message 7 "Can't go further"))
10877     n))
10878
10879 (defun gnus-summary-up-thread (n)
10880   "Go up thread N steps.
10881 If N is negative, go down instead.
10882 Returns the difference between N and how many steps down that were
10883 taken."
10884   (interactive "p")
10885   (gnus-summary-down-thread (- n)))
10886
10887 (defun gnus-summary-top-thread ()
10888   "Go to the top of the thread."
10889   (interactive)
10890   (while (gnus-summary-go-up-thread))
10891   (gnus-summary-article-number))
10892
10893 (defun gnus-summary-kill-thread (&optional unmark)
10894   "Mark articles under current thread as read.
10895 If the prefix argument is positive, remove any kinds of marks.
10896 If the prefix argument is negative, tick articles instead."
10897   (interactive "P")
10898   (when unmark
10899     (setq unmark (prefix-numeric-value unmark)))
10900   (let ((articles (gnus-summary-articles-in-thread)))
10901     (save-excursion
10902       ;; Expand the thread.
10903       (gnus-summary-show-thread)
10904       ;; Mark all the articles.
10905       (while articles
10906         (gnus-summary-goto-subject (car articles))
10907         (cond ((null unmark)
10908                (gnus-summary-mark-article-as-read gnus-killed-mark))
10909               ((> unmark 0)
10910                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10911               (t
10912                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10913         (setq articles (cdr articles))))
10914     ;; Hide killed subtrees.
10915     (and (null unmark)
10916          gnus-thread-hide-killed
10917          (gnus-summary-hide-thread))
10918     ;; If marked as read, go to next unread subject.
10919     (when (null unmark)
10920       ;; Go to next unread subject.
10921       (gnus-summary-next-subject 1 t)))
10922   (gnus-set-mode-line 'summary))
10923
10924 ;; Summary sorting commands
10925
10926 (defun gnus-summary-sort-by-number (&optional reverse)
10927   "Sort the summary buffer by article number.
10928 Argument REVERSE means reverse order."
10929   (interactive "P")
10930   (gnus-summary-sort 'number reverse))
10931
10932 (defun gnus-summary-sort-by-random (&optional reverse)
10933   "Randomize the order in the summary buffer.
10934 Argument REVERSE means to randomize in reverse order."
10935   (interactive "P")
10936   (gnus-summary-sort 'random reverse))
10937
10938 (defun gnus-summary-sort-by-author (&optional reverse)
10939   "Sort the summary buffer by author name alphabetically.
10940 If `case-fold-search' is non-nil, case of letters is ignored.
10941 Argument REVERSE means reverse order."
10942   (interactive "P")
10943   (gnus-summary-sort 'author reverse))
10944
10945 (defun gnus-summary-sort-by-recipient (&optional reverse)
10946   "Sort the summary buffer by recipient name alphabetically.
10947 If `case-fold-search' is non-nil, case of letters is ignored.
10948 Argument REVERSE means reverse order."
10949   (interactive "P")
10950   (gnus-summary-sort 'recipient reverse))
10951
10952 (defun gnus-summary-sort-by-subject (&optional reverse)
10953   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10954 If `case-fold-search' is non-nil, case of letters is ignored.
10955 Argument REVERSE means reverse order."
10956   (interactive "P")
10957   (gnus-summary-sort 'subject reverse))
10958
10959 (defun gnus-summary-sort-by-date (&optional reverse)
10960   "Sort the summary buffer by date.
10961 Argument REVERSE means reverse order."
10962   (interactive "P")
10963   (gnus-summary-sort 'date reverse))
10964
10965 (defun gnus-summary-sort-by-score (&optional reverse)
10966   "Sort the summary buffer by score.
10967 Argument REVERSE means reverse order."
10968   (interactive "P")
10969   (gnus-summary-sort 'score reverse))
10970
10971 (defun gnus-summary-sort-by-lines (&optional reverse)
10972   "Sort the summary buffer by the number of lines.
10973 Argument REVERSE means reverse order."
10974   (interactive "P")
10975   (gnus-summary-sort 'lines reverse))
10976
10977 (defun gnus-summary-sort-by-chars (&optional reverse)
10978   "Sort the summary buffer by article length.
10979 Argument REVERSE means reverse order."
10980   (interactive "P")
10981   (gnus-summary-sort 'chars reverse))
10982
10983 (defun gnus-summary-sort-by-original (&optional reverse)
10984   "Sort the summary buffer using the default sorting method.
10985 Argument REVERSE means reverse order."
10986   (interactive "P")
10987   (let* ((buffer-read-only)
10988          (gnus-summary-prepare-hook nil))
10989     ;; We do the sorting by regenerating the threads.
10990     (gnus-summary-prepare)
10991     ;; Hide subthreads if needed.
10992     (gnus-summary-maybe-hide-threads)))
10993
10994 (defun gnus-summary-sort (predicate reverse)
10995   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10996   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10997          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10998          (gnus-thread-sort-functions
10999           (if (not reverse)
11000               thread
11001             `(lambda (t1 t2)
11002                (,thread t2 t1))))
11003          (gnus-sort-gathered-threads-function
11004           gnus-thread-sort-functions)
11005          (gnus-article-sort-functions
11006           (if (not reverse)
11007               article
11008             `(lambda (t1 t2)
11009                (,article t2 t1))))
11010          (buffer-read-only)
11011          (gnus-summary-prepare-hook nil))
11012     ;; We do the sorting by regenerating the threads.
11013     (gnus-summary-prepare)
11014     ;; Hide subthreads if needed.
11015     (gnus-summary-maybe-hide-threads)))
11016
11017 ;; Summary saving commands.
11018
11019 (defun gnus-summary-save-article (&optional n not-saved)
11020   "Save the current article using the default saver function.
11021 If N is a positive number, save the N next articles.
11022 If N is a negative number, save the N previous articles.
11023 If N is nil and any articles have been marked with the process mark,
11024 save those articles instead.
11025 The variable `gnus-default-article-saver' specifies the saver function."
11026   (interactive "P")
11027   (let* ((articles (gnus-summary-work-articles n))
11028          (save-buffer (save-excursion
11029                         (nnheader-set-temp-buffer " *Gnus Save*")))
11030          (num (length articles))
11031          header file)
11032     (dolist (article articles)
11033       (setq header (gnus-summary-article-header article))
11034       (if (not (vectorp header))
11035           ;; This is a pseudo-article.
11036           (if (assq 'name header)
11037               (gnus-copy-file (cdr (assq 'name header)))
11038             (gnus-message 1 "Article %d is unsaveable" article))
11039         ;; This is a real article.
11040         (save-window-excursion
11041           (let ((gnus-display-mime-function nil)
11042                 (gnus-article-prepare-hook nil))
11043             (gnus-summary-select-article t nil nil article)))
11044         (save-excursion
11045           (set-buffer save-buffer)
11046           (erase-buffer)
11047           (insert-buffer-substring gnus-original-article-buffer))
11048         (setq file (gnus-article-save save-buffer file num))
11049         (gnus-summary-remove-process-mark article)
11050         (unless not-saved
11051           (gnus-summary-set-saved-mark article))))
11052     (gnus-kill-buffer save-buffer)
11053     (gnus-summary-position-point)
11054     (gnus-set-mode-line 'summary)
11055     n))
11056
11057 (defun gnus-summary-pipe-output (&optional arg headers)
11058   "Pipe the current article to a subprocess.
11059 If N is a positive number, pipe the N next articles.
11060 If N is a negative number, pipe the N previous articles.
11061 If N is nil and any articles have been marked with the process mark,
11062 pipe those articles instead.
11063 If HEADERS (the symbolic prefix), include the headers, too."
11064   (interactive (gnus-interactive "P\ny"))
11065   (require 'gnus-art)
11066   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11067         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11068     (gnus-summary-save-article arg t))
11069   (let ((buffer (get-buffer "*Shell Command Output*")))
11070     (when (and buffer
11071                (not (zerop (buffer-size buffer))))
11072       (gnus-configure-windows 'pipe))))
11073
11074 (defun gnus-summary-save-article-mail (&optional arg)
11075   "Append the current article to an mail file.
11076 If N is a positive number, save the N next articles.
11077 If N is a negative number, save the N previous articles.
11078 If N is nil and any articles have been marked with the process mark,
11079 save those articles instead."
11080   (interactive "P")
11081   (require 'gnus-art)
11082   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11083     (gnus-summary-save-article arg)))
11084
11085 (defun gnus-summary-save-article-rmail (&optional arg)
11086   "Append the current article to an rmail file.
11087 If N is a positive number, save the N next articles.
11088 If N is a negative number, save the N previous articles.
11089 If N is nil and any articles have been marked with the process mark,
11090 save those articles instead."
11091   (interactive "P")
11092   (require 'gnus-art)
11093   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11094     (gnus-summary-save-article arg)))
11095
11096 (defun gnus-summary-save-article-file (&optional arg)
11097   "Append the current article to a file.
11098 If N is a positive number, save the N next articles.
11099 If N is a negative number, save the N previous articles.
11100 If N is nil and any articles have been marked with the process mark,
11101 save those articles instead."
11102   (interactive "P")
11103   (require 'gnus-art)
11104   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11105     (gnus-summary-save-article arg)))
11106
11107 (defun gnus-summary-write-article-file (&optional arg)
11108   "Write the current article to a file, deleting the previous file.
11109 If N is a positive number, save the N next articles.
11110 If N is a negative number, save the N previous articles.
11111 If N is nil and any articles have been marked with the process mark,
11112 save those articles instead."
11113   (interactive "P")
11114   (require 'gnus-art)
11115   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11116     (gnus-summary-save-article arg)))
11117
11118 (defun gnus-summary-save-article-body-file (&optional arg)
11119   "Append the current article body to a file.
11120 If N is a positive number, save the N next articles.
11121 If N is a negative number, save the N previous articles.
11122 If N is nil and any articles have been marked with the process mark,
11123 save those articles instead."
11124   (interactive "P")
11125   (require 'gnus-art)
11126   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11127     (gnus-summary-save-article arg)))
11128
11129 (defun gnus-summary-muttprint (&optional arg)
11130   "Print the current article using Muttprint.
11131 If N is a positive number, save the N next articles.
11132 If N is a negative number, save the N previous articles.
11133 If N is nil and any articles have been marked with the process mark,
11134 save those articles instead."
11135   (interactive "P")
11136   (require 'gnus-art)
11137   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11138     (gnus-summary-save-article arg t)))
11139
11140 (defun gnus-summary-pipe-message (program)
11141   "Pipe the current article through PROGRAM."
11142   (interactive "sProgram: ")
11143   (gnus-summary-select-article)
11144   (let ((mail-header-separator ""))
11145     (gnus-eval-in-buffer-window gnus-article-buffer
11146       (save-restriction
11147         (widen)
11148         (let ((start (window-start))
11149               buffer-read-only)
11150           (message-pipe-buffer-body program)
11151           (set-window-start (get-buffer-window (current-buffer)) start))))))
11152
11153 (defun gnus-get-split-value (methods)
11154   "Return a value based on the split METHODS."
11155   (let (split-name method result match)
11156     (when methods
11157       (save-excursion
11158         (set-buffer gnus-original-article-buffer)
11159         (save-restriction
11160           (nnheader-narrow-to-headers)
11161           (while (and methods (not split-name))
11162             (goto-char (point-min))
11163             (setq method (pop methods))
11164             (setq match (car method))
11165             (when (cond
11166                    ((stringp match)
11167                     ;; Regular expression.
11168                     (ignore-errors
11169                       (re-search-forward match nil t)))
11170                    ((functionp match)
11171                     ;; Function.
11172                     (save-restriction
11173                       (widen)
11174                       (setq result (funcall match gnus-newsgroup-name))))
11175                    ((consp match)
11176                     ;; Form.
11177                     (save-restriction
11178                       (widen)
11179                       (setq result (eval match)))))
11180               (setq split-name (cdr method))
11181               (cond ((stringp result)
11182                      (push (expand-file-name
11183                             result gnus-article-save-directory)
11184                            split-name))
11185                     ((consp result)
11186                      (setq split-name (append result split-name)))))))))
11187     (nreverse split-name)))
11188
11189 (defun gnus-valid-move-group-p (group)
11190   (and (boundp group)
11191        (symbol-name group)
11192        (symbol-value group)
11193        (gnus-get-function (gnus-find-method-for-group
11194                            (symbol-name group)) 'request-accept-article t)))
11195
11196 (defun gnus-read-move-group-name (prompt default articles prefix)
11197   "Read a group name."
11198   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11199          (minibuffer-confirm-incomplete nil) ; XEmacs
11200          (prom
11201           (format "%s %s to:"
11202                   prompt
11203                   (if (> (length articles) 1)
11204                       (format "these %d articles" (length articles))
11205                     "this article")))
11206          (to-newsgroup
11207           (cond
11208            ((null split-name)
11209             (gnus-completing-read-with-default
11210              default prom
11211              gnus-active-hashtb
11212              'gnus-valid-move-group-p
11213              nil prefix
11214              'gnus-group-history))
11215            ((= 1 (length split-name))
11216             (gnus-completing-read-with-default
11217              (car split-name) prom
11218              gnus-active-hashtb
11219              'gnus-valid-move-group-p
11220              nil nil
11221              'gnus-group-history))
11222            (t
11223             (gnus-completing-read-with-default
11224              nil prom
11225              (mapcar 'list (nreverse split-name))
11226              nil nil nil
11227              'gnus-group-history))))
11228          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11229     (when to-newsgroup
11230       (if (or (string= to-newsgroup "")
11231               (string= to-newsgroup prefix))
11232           (setq to-newsgroup default))
11233       (unless to-newsgroup
11234         (error "No group name entered"))
11235       (or (gnus-active to-newsgroup)
11236           (gnus-activate-group to-newsgroup nil nil to-method)
11237           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11238                                      to-newsgroup))
11239               (or (and (gnus-request-create-group to-newsgroup to-method)
11240                        (gnus-activate-group
11241                         to-newsgroup nil nil to-method)
11242                        (gnus-subscribe-group to-newsgroup))
11243                   (error "Couldn't create group %s" to-newsgroup)))
11244           (error "No such group: %s" to-newsgroup)))
11245     to-newsgroup))
11246
11247 (defun gnus-summary-save-parts (type dir n &optional reverse)
11248   "Save parts matching TYPE to DIR.
11249 If REVERSE, save parts that do not match TYPE."
11250   (interactive
11251    (list (read-string "Save parts of type: "
11252                       (or (car gnus-summary-save-parts-type-history)
11253                           gnus-summary-save-parts-default-mime)
11254                       'gnus-summary-save-parts-type-history)
11255          (setq gnus-summary-save-parts-last-directory
11256                (read-file-name "Save to directory: "
11257                                gnus-summary-save-parts-last-directory
11258                                nil t))
11259          current-prefix-arg))
11260   (gnus-summary-iterate n
11261     (let ((gnus-display-mime-function nil)
11262           (gnus-inhibit-treatment t))
11263       (gnus-summary-select-article))
11264     (save-excursion
11265       (set-buffer gnus-article-buffer)
11266       (let ((handles (or gnus-article-mime-handles
11267                          (mm-dissect-buffer nil gnus-article-loose-mime)
11268                          (and gnus-article-emulate-mime
11269                               (mm-uu-dissect)))))
11270         (when handles
11271           (gnus-summary-save-parts-1 type dir handles reverse)
11272           (unless gnus-article-mime-handles ;; Don't destroy this case.
11273             (mm-destroy-parts handles)))))))
11274
11275 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11276   (if (stringp (car handle))
11277       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11278               (cdr handle))
11279     (when (if reverse
11280               (not (string-match type (mm-handle-media-type handle)))
11281             (string-match type (mm-handle-media-type handle)))
11282       (let ((file (expand-file-name
11283                    (gnus-map-function
11284                     mm-file-name-rewrite-functions
11285                     (file-name-nondirectory
11286                      (or
11287                       (mail-content-type-get
11288                        (mm-handle-disposition handle) 'filename)
11289                       (mail-content-type-get
11290                        (mm-handle-type handle) 'name)
11291                       (concat gnus-newsgroup-name
11292                               "." (number-to-string
11293                                    (cdr gnus-article-current))))))
11294                    dir)))
11295         (unless (file-exists-p file)
11296           (mm-save-part-to-file handle file))))))
11297
11298 ;; Summary extract commands
11299
11300 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11301   (let ((buffer-read-only nil)
11302         (article (gnus-summary-article-number))
11303         after-article b e)
11304     (unless (gnus-summary-goto-subject article)
11305       (error "No such article: %d" article))
11306     (gnus-summary-position-point)
11307     ;; If all commands are to be bunched up on one line, we collect
11308     ;; them here.
11309     (unless gnus-view-pseudos-separately
11310       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11311             files action)
11312         (while ps
11313           (setq action (cdr (assq 'action (car ps))))
11314           (setq files (list (cdr (assq 'name (car ps)))))
11315           (while (and ps (cdr ps)
11316                       (string= (or action "1")
11317                                (or (cdr (assq 'action (cadr ps))) "2")))
11318             (push (cdr (assq 'name (cadr ps))) files)
11319             (setcdr ps (cddr ps)))
11320           (when files
11321             (when (not (string-match "%s" action))
11322               (push " " files))
11323             (push " " files)
11324             (when (assq 'execute (car ps))
11325               (setcdr (assq 'execute (car ps))
11326                       (funcall (if (string-match "%s" action)
11327                                    'format 'concat)
11328                                action
11329                                (mapconcat
11330                                 (lambda (f)
11331                                   (if (equal f " ")
11332                                       f
11333                                     (shell-quote-argument f)))
11334                                 files " ")))))
11335           (setq ps (cdr ps)))))
11336     (if (and gnus-view-pseudos (not not-view))
11337         (while pslist
11338           (when (assq 'execute (car pslist))
11339             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11340                                   (eq gnus-view-pseudos 'not-confirm)))
11341           (setq pslist (cdr pslist)))
11342       (save-excursion
11343         (while pslist
11344           (setq after-article (or (cdr (assq 'article (car pslist)))
11345                                   (gnus-summary-article-number)))
11346           (gnus-summary-goto-subject after-article)
11347           (forward-line 1)
11348           (setq b (point))
11349           (insert "    " (file-name-nondirectory
11350                           (cdr (assq 'name (car pslist))))
11351                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11352           (setq e (point))
11353           (forward-line -1)             ; back to `b'
11354           (gnus-add-text-properties
11355            b (1- e) (list 'gnus-number gnus-reffed-article-number
11356                           gnus-mouse-face-prop gnus-mouse-face))
11357           (gnus-data-enter
11358            after-article gnus-reffed-article-number
11359            gnus-unread-mark b (car pslist) 0 (- e b))
11360           (setq gnus-newsgroup-unreads
11361                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11362                                          gnus-reffed-article-number))
11363           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11364           (setq pslist (cdr pslist)))))))
11365
11366 (defun gnus-pseudos< (p1 p2)
11367   (let ((c1 (cdr (assq 'action p1)))
11368         (c2 (cdr (assq 'action p2))))
11369     (and c1 c2 (string< c1 c2))))
11370
11371 (defun gnus-request-pseudo-article (props)
11372   (cond ((assq 'execute props)
11373          (gnus-execute-command (cdr (assq 'execute props)))))
11374   (let ((gnus-current-article (gnus-summary-article-number)))
11375     (gnus-run-hooks 'gnus-mark-article-hook)))
11376
11377 (defun gnus-execute-command (command &optional automatic)
11378   (save-excursion
11379     (gnus-article-setup-buffer)
11380     (set-buffer gnus-article-buffer)
11381     (setq buffer-read-only nil)
11382     (let ((command (if automatic command
11383                      (read-string "Command: " (cons command 0)))))
11384       (erase-buffer)
11385       (insert "$ " command "\n\n")
11386       (if gnus-view-pseudo-asynchronously
11387           (start-process "gnus-execute" (current-buffer) shell-file-name
11388                          shell-command-switch command)
11389         (call-process shell-file-name nil t nil
11390                       shell-command-switch command)))))
11391
11392 ;; Summary kill commands.
11393
11394 (defun gnus-summary-edit-global-kill (article)
11395   "Edit the \"global\" kill file."
11396   (interactive (list (gnus-summary-article-number)))
11397   (gnus-group-edit-global-kill article))
11398
11399 (defun gnus-summary-edit-local-kill ()
11400   "Edit a local kill file applied to the current newsgroup."
11401   (interactive)
11402   (setq gnus-current-headers (gnus-summary-article-header))
11403   (gnus-group-edit-local-kill
11404    (gnus-summary-article-number) gnus-newsgroup-name))
11405
11406 ;;; Header reading.
11407
11408 (defun gnus-read-header (id &optional header)
11409   "Read the headers of article ID and enter them into the Gnus system."
11410   (let ((group gnus-newsgroup-name)
11411         (gnus-override-method
11412          (or
11413           gnus-override-method
11414           (and (gnus-news-group-p gnus-newsgroup-name)
11415                (car (gnus-refer-article-methods)))))
11416         where)
11417     ;; First we check to see whether the header in question is already
11418     ;; fetched.
11419     (if (stringp id)
11420         ;; This is a Message-ID.
11421         (setq header (or header (gnus-id-to-header id)))
11422       ;; This is an article number.
11423       (setq header (or header (gnus-summary-article-header id))))
11424     (if (and header
11425              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11426         ;; We have found the header.
11427         header
11428       ;; We have to really fetch the header to this article.
11429       (save-excursion
11430         (set-buffer nntp-server-buffer)
11431         (when (setq where (gnus-request-head id group))
11432           (nnheader-fold-continuation-lines)
11433           (goto-char (point-max))
11434           (insert ".\n")
11435           (goto-char (point-min))
11436           (insert "211 ")
11437           (princ (cond
11438                   ((numberp id) id)
11439                   ((cdr where) (cdr where))
11440                   (header (mail-header-number header))
11441                   (t gnus-reffed-article-number))
11442                  (current-buffer))
11443           (insert " Article retrieved.\n"))
11444         (if (or (not where)
11445                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11446             ()                          ; Malformed head.
11447           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11448             (when (and (stringp id)
11449                        (not (string= (gnus-group-real-name group)
11450                                      (car where))))
11451               ;; If we fetched by Message-ID and the article came
11452               ;; from a different group, we fudge some bogus article
11453               ;; numbers for this article.
11454               (mail-header-set-number header gnus-reffed-article-number))
11455             (save-excursion
11456               (set-buffer gnus-summary-buffer)
11457               (decf gnus-reffed-article-number)
11458               (gnus-remove-header (mail-header-number header))
11459               (push header gnus-newsgroup-headers)
11460               (setq gnus-current-headers header)
11461               (push (mail-header-number header) gnus-newsgroup-limit)))
11462           header)))))
11463
11464 (defun gnus-remove-header (number)
11465   "Remove header NUMBER from `gnus-newsgroup-headers'."
11466   (if (and gnus-newsgroup-headers
11467            (= number (mail-header-number (car gnus-newsgroup-headers))))
11468       (pop gnus-newsgroup-headers)
11469     (let ((headers gnus-newsgroup-headers))
11470       (while (and (cdr headers)
11471                   (not (= number (mail-header-number (cadr headers)))))
11472         (pop headers))
11473       (when (cdr headers)
11474         (setcdr headers (cddr headers))))))
11475
11476 ;;;
11477 ;;; summary highlights
11478 ;;;
11479
11480 (defun gnus-highlight-selected-summary ()
11481   "Highlight selected article in summary buffer."
11482   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11483   (when gnus-summary-selected-face
11484     (save-excursion
11485       (let* ((beg (point-at-bol))
11486              (end (point-at-eol))
11487              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11488              (from (if (get-text-property beg gnus-mouse-face-prop)
11489                        beg
11490                      (or (next-single-property-change
11491                           beg gnus-mouse-face-prop nil end)
11492                          beg)))
11493              (to
11494               (if (= from end)
11495                   (- from 2)
11496                 (or (next-single-property-change
11497                      from gnus-mouse-face-prop nil end)
11498                     end))))
11499         ;; If no mouse-face prop on line we will have to = from = end,
11500         ;; so we highlight the entire line instead.
11501         (when (= (+ to 2) from)
11502           (setq from beg)
11503           (setq to end))
11504         (if gnus-newsgroup-selected-overlay
11505             ;; Move old overlay.
11506             (gnus-move-overlay
11507              gnus-newsgroup-selected-overlay from to (current-buffer))
11508           ;; Create new overlay.
11509           (gnus-overlay-put
11510            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11511            'face gnus-summary-selected-face))))))
11512
11513 (defvar gnus-summary-highlight-line-cached nil)
11514 (defvar gnus-summary-highlight-line-trigger nil)
11515
11516 (defun gnus-summary-highlight-line-0 ()
11517   (if (and (eq gnus-summary-highlight-line-trigger
11518                gnus-summary-highlight)
11519            gnus-summary-highlight-line-cached)
11520       gnus-summary-highlight-line-cached
11521     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11522           gnus-summary-highlight-line-cached
11523           (let* ((cond (list 'cond))
11524                  (c cond)
11525                  (list gnus-summary-highlight))
11526             (while list
11527               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11528                               nil))
11529               (setq c (cdr c)
11530                     list (cdr list)))
11531             (gnus-byte-compile (list 'lambda nil cond))))))
11532
11533 (defun gnus-summary-highlight-line ()
11534   "Highlight current line according to `gnus-summary-highlight'."
11535   (let* ((beg (point-at-bol))
11536          (article (or (gnus-summary-article-number) gnus-current-article))
11537          (score (or (cdr (assq article
11538                                gnus-newsgroup-scored))
11539                     gnus-summary-default-score 0))
11540          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11541          (inhibit-read-only t)
11542          (default gnus-summary-default-score)
11543          (default-high gnus-summary-default-high-score)
11544          (default-low gnus-summary-default-low-score)
11545          (uncached (and gnus-summary-use-undownloaded-faces
11546                         (memq article gnus-newsgroup-undownloaded)
11547                         (not (memq article gnus-newsgroup-cached)))))
11548     (let ((face (funcall (gnus-summary-highlight-line-0))))
11549       (unless (eq face (get-text-property beg 'face))
11550         (gnus-put-text-property-excluding-characters-with-faces
11551          beg (point-at-eol) 'face
11552          (setq face (if (boundp face) (symbol-value face) face)))
11553         (when gnus-summary-highlight-line-function
11554           (funcall gnus-summary-highlight-line-function article face))))))
11555
11556 (defun gnus-update-read-articles (group unread &optional compute)
11557   "Update the list of read articles in GROUP.
11558 UNREAD is a sorted list."
11559   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11560         (info (gnus-get-info group))
11561         (prev 1)
11562         read)
11563     (if (or (not info) (not active))
11564         ;; There is no info on this group if it was, in fact,
11565         ;; killed.  Gnus stores no information on killed groups, so
11566         ;; there's nothing to be done.
11567         ;; One could store the information somewhere temporarily,
11568         ;; perhaps...  Hmmm...
11569         ()
11570       ;; Remove any negative articles numbers.
11571       (while (and unread (< (car unread) 0))
11572         (setq unread (cdr unread)))
11573       ;; Remove any expired article numbers
11574       (while (and unread (< (car unread) (car active)))
11575         (setq unread (cdr unread)))
11576       ;; Compute the ranges of read articles by looking at the list of
11577       ;; unread articles.
11578       (while unread
11579         (when (/= (car unread) prev)
11580           (push (if (= prev (1- (car unread))) prev
11581                   (cons prev (1- (car unread))))
11582                 read))
11583         (setq prev (1+ (car unread)))
11584         (setq unread (cdr unread)))
11585       (when (<= prev (cdr active))
11586         (push (cons prev (cdr active)) read))
11587       (setq read (if (> (length read) 1) (nreverse read) read))
11588       (if compute
11589           read
11590         (save-excursion
11591           (let (setmarkundo)
11592             ;; Propagate the read marks to the backend.
11593             (when (gnus-check-backend-function 'request-set-mark group)
11594               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11595                     (add (gnus-remove-from-range read (gnus-info-read info))))
11596                 (when (or add del)
11597                   (unless (gnus-check-group group)
11598                     (error "Can't open server for %s" group))
11599                   (gnus-request-set-mark
11600                    group (delq nil (list (if add (list add 'add '(read)))
11601                                          (if del (list del 'del '(read))))))
11602                   (setq setmarkundo
11603                         `(gnus-request-set-mark
11604                           ,group
11605                           ',(delq nil (list
11606                                        (if del (list del 'add '(read)))
11607                                        (if add (list add 'del '(read))))))))))
11608             (set-buffer gnus-group-buffer)
11609             (gnus-undo-register
11610               `(progn
11611                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11612                  (gnus-info-set-read ',info ',(gnus-info-read info))
11613                  (gnus-get-unread-articles-in-group ',info
11614                                                     (gnus-active ,group))
11615                  (gnus-group-update-group ,group t)
11616                  ,setmarkundo))))
11617         ;; Enter this list into the group info.
11618         (gnus-info-set-read info read)
11619         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11620         (gnus-get-unread-articles-in-group info (gnus-active group))
11621         t))))
11622
11623 (defun gnus-offer-save-summaries ()
11624   "Offer to save all active summary buffers."
11625   (let (buffers)
11626     ;; Go through all buffers and find all summaries.
11627     (dolist (buffer (buffer-list))
11628       (when (and (setq buffer (buffer-name buffer))
11629                  (string-match "Summary" buffer)
11630                  (with-current-buffer buffer
11631                    ;; We check that this is, indeed, a summary buffer.
11632                    (and (eq major-mode 'gnus-summary-mode)
11633                         ;; Also make sure this isn't bogus.
11634                         gnus-newsgroup-prepared
11635                         ;; Also make sure that this isn't a
11636                         ;; dead summary buffer.
11637                         (not gnus-dead-summary-mode))))
11638         (push buffer buffers)))
11639     ;; Go through all these summary buffers and offer to save them.
11640     (when buffers
11641       (save-excursion
11642         (map-y-or-n-p
11643          "Update summary buffer %s? "
11644          (lambda (buf)
11645            (switch-to-buffer buf)
11646            (gnus-summary-exit))
11647          buffers)))))
11648
11649 (defun gnus-summary-setup-default-charset ()
11650   "Setup newsgroup default charset."
11651   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11652       (setq gnus-newsgroup-charset nil)
11653     (let* ((ignored-charsets
11654             (or gnus-newsgroup-ephemeral-ignored-charsets
11655                 (append
11656                  (and gnus-newsgroup-name
11657                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11658                  gnus-newsgroup-ignored-charsets))))
11659       (setq gnus-newsgroup-charset
11660             (or gnus-newsgroup-ephemeral-charset
11661                 (and gnus-newsgroup-name
11662                      (gnus-parameter-charset gnus-newsgroup-name))
11663                 gnus-default-charset))
11664       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11665            ignored-charsets))))
11666
11667 ;;;
11668 ;;; Mime Commands
11669 ;;;
11670
11671 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11672   "Display the current article buffer fully MIME-buttonized.
11673 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11674 treated as multipart/mixed."
11675   (interactive "P")
11676   (require 'gnus-art)
11677   (let ((gnus-unbuttonized-mime-types nil)
11678         (gnus-mime-display-multipart-as-mixed show-all-parts))
11679     (gnus-summary-show-article)))
11680
11681 (defun gnus-summary-repair-multipart (article)
11682   "Add a Content-Type header to a multipart article without one."
11683   (interactive (list (gnus-summary-article-number)))
11684   (gnus-with-article article
11685     (message-narrow-to-head)
11686     (message-remove-header "Mime-Version")
11687     (goto-char (point-max))
11688     (insert "Mime-Version: 1.0\n")
11689     (widen)
11690     (when (search-forward "\n--" nil t)
11691       (let ((separator (buffer-substring (point) (point-at-eol))))
11692         (message-narrow-to-head)
11693         (message-remove-header "Content-Type")
11694         (goto-char (point-max))
11695         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11696                         separator))
11697         (widen))))
11698   (let (gnus-mark-article-hook)
11699     (gnus-summary-select-article t t nil article)))
11700
11701 (defun gnus-summary-toggle-display-buttonized ()
11702   "Toggle the buttonizing of the article buffer."
11703   (interactive)
11704   (require 'gnus-art)
11705   (if (setq gnus-inhibit-mime-unbuttonizing
11706             (not gnus-inhibit-mime-unbuttonizing))
11707       (let ((gnus-unbuttonized-mime-types nil))
11708         (gnus-summary-show-article))
11709     (gnus-summary-show-article)))
11710
11711 ;;;
11712 ;;; Generic summary marking commands
11713 ;;;
11714
11715 (defvar gnus-summary-marking-alist
11716   '((read gnus-del-mark "d")
11717     (unread gnus-unread-mark "u")
11718     (ticked gnus-ticked-mark "!")
11719     (dormant gnus-dormant-mark "?")
11720     (expirable gnus-expirable-mark "e"))
11721   "An alist of names/marks/keystrokes.")
11722
11723 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11724 (defvar gnus-summary-mark-map)
11725
11726 (defun gnus-summary-make-all-marking-commands ()
11727   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11728   (dolist (elem gnus-summary-marking-alist)
11729     (apply 'gnus-summary-make-marking-command elem)))
11730
11731 (defun gnus-summary-make-marking-command (name mark keystroke)
11732   (let ((map (make-sparse-keymap)))
11733     (define-key gnus-summary-generic-mark-map keystroke map)
11734     (dolist (lway `((next "next" next nil "n")
11735                     (next-unread "next unread" next t "N")
11736                     (prev "previous" prev nil "p")
11737                     (prev-unread "previous unread" prev t "P")
11738                     (nomove "" nil nil ,keystroke)))
11739       (let ((func (gnus-summary-make-marking-command-1
11740                    mark (car lway) lway name)))
11741         (setq func (eval func))
11742         (define-key map (nth 4 lway) func)))))
11743
11744 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11745   `(defun ,(intern
11746             (format "gnus-summary-put-mark-as-%s%s"
11747                     name (if (eq way 'nomove)
11748                              ""
11749                            (concat "-" (symbol-name way)))))
11750      (n)
11751      ,(format
11752        "Mark the current article as %s%s.
11753 If N, the prefix, then repeat N times.
11754 If N is negative, move in reverse order.
11755 The difference between N and the actual number of articles marked is
11756 returned."
11757        name (cadr lway))
11758      (interactive "p")
11759      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11760
11761 (defun gnus-summary-generic-mark (n mark move unread)
11762   "Mark N articles with MARK."
11763   (unless (eq major-mode 'gnus-summary-mode)
11764     (error "This command can only be used in the summary buffer"))
11765   (gnus-summary-show-thread)
11766   (let ((nummove
11767          (cond
11768           ((eq move 'next) 1)
11769           ((eq move 'prev) -1)
11770           (t 0))))
11771     (if (zerop nummove)
11772         (setq n 1)
11773       (when (< n 0)
11774         (setq n (abs n)
11775               nummove (* -1 nummove))))
11776     (while (and (> n 0)
11777                 (gnus-summary-mark-article nil mark)
11778                 (zerop (gnus-summary-next-subject nummove unread t)))
11779       (setq n (1- n)))
11780     (when (/= 0 n)
11781       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11782     (gnus-summary-recenter)
11783     (gnus-summary-position-point)
11784     (gnus-set-mode-line 'summary)
11785     n))
11786
11787 (defun gnus-summary-insert-articles (articles)
11788   (when (setq articles
11789               (gnus-sorted-difference articles
11790                                       (mapcar (lambda (h)
11791                                                 (mail-header-number h))
11792                                               gnus-newsgroup-headers)))
11793     (setq gnus-newsgroup-headers
11794           (gnus-merge 'list
11795                       gnus-newsgroup-headers
11796                       (gnus-fetch-headers articles)
11797                       'gnus-article-sort-by-number))
11798     ;; Suppress duplicates?
11799     (when gnus-suppress-duplicates
11800       (gnus-dup-suppress-articles))
11801
11802     ;; We might want to build some more threads first.
11803     (when (and gnus-fetch-old-headers
11804                (eq gnus-headers-retrieved-by 'nov))
11805       (if (eq gnus-fetch-old-headers 'invisible)
11806           (gnus-build-all-threads)
11807         (gnus-build-old-threads)))
11808     ;; Let the Gnus agent mark articles as read.
11809     (when gnus-agent
11810       (gnus-agent-get-undownloaded-list))
11811     ;; Remove list identifiers from subject
11812     (when gnus-list-identifiers
11813       (gnus-summary-remove-list-identifiers))
11814     ;; First and last article in this newsgroup.
11815     (when gnus-newsgroup-headers
11816       (setq gnus-newsgroup-begin
11817             (mail-header-number (car gnus-newsgroup-headers))
11818             gnus-newsgroup-end
11819             (mail-header-number
11820              (gnus-last-element gnus-newsgroup-headers))))
11821     (when gnus-use-scoring
11822       (gnus-possibly-score-headers))))
11823
11824 (defun gnus-summary-insert-old-articles (&optional all)
11825   "Insert all old articles in this group.
11826 If ALL is non-nil, already read articles become readable.
11827 If ALL is a number, fetch this number of articles."
11828   (interactive "P")
11829   (prog1
11830       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11831             older len)
11832         (setq older
11833               ;; Some nntp servers lie about their active range.  When
11834               ;; this happens, the active range can be in the millions.
11835               ;; Use a compressed range to avoid creating a huge list.
11836               (gnus-range-difference (list gnus-newsgroup-active) old))
11837         (setq len (gnus-range-length older))
11838         (cond
11839          ((null older) nil)
11840          ((numberp all)
11841           (if (< all len)
11842               (let ((older-range (nreverse older)))
11843                 (setq older nil)
11844
11845                 (while (> all 0)
11846                   (let* ((r (pop older-range))
11847                          (min (if (numberp r) r (car r)))
11848                          (max (if (numberp r) r (cdr r))))
11849                     (while (and (<= min max)
11850                                 (> all 0))
11851                       (push max older)
11852                       (setq all (1- all)
11853                             max (1- max))))))
11854             (setq older (gnus-uncompress-range older))))
11855          (all
11856           (setq older (gnus-uncompress-range older)))
11857          (t
11858           (when (and (numberp gnus-large-newsgroup)
11859                    (> len gnus-large-newsgroup))
11860               (let* ((cursor-in-echo-area nil)
11861                      (initial (gnus-parameter-large-newsgroup-initial
11862                                gnus-newsgroup-name))
11863                      (input
11864                       (read-string
11865                        (format
11866                         "How many articles from %s (%s %d): "
11867                         (gnus-limit-string
11868                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11869                         (if initial "max" "default")
11870                         len)
11871                        (if initial
11872                            (cons (number-to-string initial)
11873                                  0)))))
11874                 (unless (string-match "^[ \t]*$" input)
11875                   (setq all (string-to-number input))
11876                   (if (< all len)
11877                       (let ((older-range (nreverse older)))
11878                         (setq older nil)
11879
11880                         (while (> all 0)
11881                           (let* ((r (pop older-range))
11882                                  (min (if (numberp r) r (car r)))
11883                                  (max (if (numberp r) r (cdr r))))
11884                             (while (and (<= min max)
11885                                         (> all 0))
11886                               (push max older)
11887                               (setq all (1- all)
11888                                     max (1- max))))))))))
11889           (setq older (gnus-uncompress-range older))))
11890         (if (not older)
11891             (message "No old news.")
11892           (gnus-summary-insert-articles older)
11893           (gnus-summary-limit (gnus-sorted-nunion old older))))
11894     (gnus-summary-position-point)))
11895
11896 (defun gnus-summary-insert-new-articles ()
11897   "Insert all new articles in this group."
11898   (interactive)
11899   (prog1
11900       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11901             (old-active gnus-newsgroup-active)
11902             (nnmail-fetched-sources (list t))
11903             i new)
11904         (setq gnus-newsgroup-active
11905               (gnus-activate-group gnus-newsgroup-name 'scan))
11906         (setq i (cdr gnus-newsgroup-active))
11907         (while (> i (cdr old-active))
11908           (push i new)
11909           (decf i))
11910         (if (not new)
11911             (message "No gnus is bad news")
11912           (gnus-summary-insert-articles new)
11913           (setq gnus-newsgroup-unreads
11914                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11915           (gnus-summary-limit (gnus-sorted-nunion old new))))
11916     (gnus-summary-position-point)))
11917
11918 (gnus-summary-make-all-marking-commands)
11919
11920 (gnus-ems-redefine)
11921
11922 (provide 'gnus-sum)
11923
11924 (run-hooks 'gnus-sum-load-hook)
11925
11926 ;; Local Variables:
11927 ;; coding: iso-8859-1
11928 ;; End:
11929
11930 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
11931 ;;; gnus-sum.el ends here