(gnus-summary-from-or-to-or-newsgroups): Don't use
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-mode))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'gmm-utils)
42 (require 'mm-decode)
43 (require 'nnoo)
44
45 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
46 (autoload 'gnus-cache-write-active "gnus-cache")
47 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
48 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
49 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
50 (autoload 'mm-uu-dissect "mm-uu")
51 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
52   "Deuglify broken Outlook (Express) articles and redisplay."
53   t)
54 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
55 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
56 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
57
58 (defcustom gnus-kill-summary-on-exit t
59   "*If non-nil, kill the summary buffer when you exit from it.
60 If nil, the summary will become a \"*Dead Summary*\" buffer, and
61 it will be killed sometime later."
62   :group 'gnus-summary-exit
63   :type 'boolean)
64
65 (defcustom gnus-fetch-old-headers nil
66   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
67 If an unread article in the group refers to an older, already
68 read (or just marked as read) article, the old article will not
69 normally be displayed in the Summary buffer.  If this variable is
70 t, Gnus will attempt to grab the headers to the old articles, and
71 thereby build complete threads.  If it has the value `some', all
72 old headers will be fetched but only enough headers to connect
73 otherwise loose threads will be displayed.  This variable can
74 also be a number.  In that case, no more than that number of old
75 headers will be fetched.  If it has the value `invisible', all
76 old headers will be fetched, but none will be displayed.
77
78 The server has to support NOV for any of this to work.
79
80 This feature can seriously impact performance it ignores all
81 locally cached header entries."
82   :group 'gnus-thread
83   :type '(choice (const :tag "off" nil)
84                  (const :tag "on" t)
85                  (const some)
86                  (const invisible)
87                  number
88                  (sexp :menu-tag "other" t)))
89
90 (defcustom gnus-refer-thread-limit 200
91   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
92 If t, fetch all the available old headers."
93   :group 'gnus-thread
94   :type '(choice number
95                  (sexp :menu-tag "other" t)))
96
97 (defcustom gnus-summary-make-false-root 'adopt
98   "*nil means that Gnus won't gather loose threads.
99 If the root of a thread has expired or been read in a previous
100 session, the information necessary to build a complete thread has been
101 lost.  Instead of having many small sub-threads from this original thread
102 scattered all over the summary buffer, Gnus can gather them.
103
104 If non-nil, Gnus will try to gather all loose sub-threads from an
105 original thread into one large thread.
106
107 If this variable is non-nil, it should be one of `none', `adopt',
108 `dummy' or `empty'.
109
110 If this variable is `none', Gnus will not make a false root, but just
111 present the sub-threads after another.
112 If this variable is `dummy', Gnus will create a dummy root that will
113 have all the sub-threads as children.
114 If this variable is `adopt', Gnus will make one of the \"children\"
115 the parent and mark all the step-children as such.
116 If this variable is `empty', the \"children\" are printed with empty
117 subject fields.  (Or rather, they will be printed with a string
118 given by the `gnus-summary-same-subject' variable.)"
119   :group 'gnus-thread
120   :type '(choice (const :tag "off" nil)
121                  (const none)
122                  (const dummy)
123                  (const adopt)
124                  (const empty)))
125
126 (defcustom gnus-summary-make-false-root-always nil
127   "Always make a false dummy root."
128   :version "22.1"
129   :group 'gnus-thread
130   :type 'boolean)
131
132 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
133   "*A regexp to match subjects to be excluded from loose thread gathering.
134 As loose thread gathering is done on subjects only, that means that
135 there can be many false gatherings performed.  By rooting out certain
136 common subjects, gathering might become saner."
137   :group 'gnus-thread
138   :type 'regexp)
139
140 (defcustom gnus-summary-gather-subject-limit nil
141   "*Maximum length of subject comparisons when gathering loose threads.
142 Use nil to compare full subjects.  Setting this variable to a low
143 number will help gather threads that have been corrupted by
144 newsreaders chopping off subject lines, but it might also mean that
145 unrelated articles that have subject that happen to begin with the
146 same few characters will be incorrectly gathered.
147
148 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
149 comparing subjects."
150   :group 'gnus-thread
151   :type '(choice (const :tag "off" nil)
152                  (const fuzzy)
153                  (sexp :menu-tag "on" t)))
154
155 (defcustom gnus-simplify-subject-functions nil
156   "List of functions taking a string argument that simplify subjects.
157 The functions are applied recursively.
158
159 Useful functions to put in this list include:
160 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
161 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
162   :group 'gnus-thread
163   :type '(repeat function))
164
165 (defcustom gnus-simplify-ignored-prefixes nil
166   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  regexp))
170
171 (defcustom gnus-build-sparse-threads nil
172   "*If non-nil, fill in the gaps in threads.
173 If `some', only fill in the gaps that are needed to tie loose threads
174 together.  If `more', fill in all leaf nodes that Gnus can find.  If
175 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
176   :group 'gnus-thread
177   :type '(choice (const :tag "off" nil)
178                  (const some)
179                  (const more)
180                  (sexp :menu-tag "all" t)))
181
182 (defcustom gnus-summary-thread-gathering-function
183   'gnus-gather-threads-by-subject
184   "*Function used for gathering loose threads.
185 There are two pre-defined functions: `gnus-gather-threads-by-subject',
186 which only takes Subjects into consideration; and
187 `gnus-gather-threads-by-references', which compared the References
188 headers of the articles to find matches."
189   :group 'gnus-thread
190   :type '(radio (function-item gnus-gather-threads-by-subject)
191                 (function-item gnus-gather-threads-by-references)
192                 (function :tag "other")))
193
194 (defcustom gnus-summary-same-subject ""
195   "*String indicating that the current article has the same subject as the previous.
196 This variable will only be used if the value of
197 `gnus-summary-make-false-root' is `empty'."
198   :group 'gnus-summary-format
199   :type 'string)
200
201 (defcustom gnus-summary-goto-unread t
202   "*If t, many commands will go to the next unread article.
203 This applies to marking commands as well as other commands that
204 \"naturally\" select the next article, like, for instance, `SPC' at
205 the end of an article.
206
207 If nil, the marking commands do NOT go to the next unread article
208 \(they go to the next article instead).  If `never', commands that
209 usually go to the next unread article, will go to the next article,
210 whether it is read or not."
211   :group 'gnus-summary-marks
212   :link '(custom-manual "(gnus)Setting Marks")
213   :type '(choice (const :tag "off" nil)
214                  (const never)
215                  (sexp :menu-tag "on" t)))
216
217 (defcustom gnus-summary-default-score 0
218   "*Default article score level.
219 All scores generated by the score files will be added to this score.
220 If this variable is nil, scoring will be disabled."
221   :group 'gnus-score-default
222   :type '(choice (const :tag "disable")
223                  integer))
224
225 (defcustom gnus-summary-default-high-score 0
226   "*Default threshold for a high scored article.
227 An article will be highlighted as high scored if its score is greater
228 than this score."
229   :version "22.1"
230   :group 'gnus-score-default
231   :type 'integer)
232
233 (defcustom gnus-summary-default-low-score 0
234   "*Default threshold for a low scored article.
235 An article will be highlighted as low scored if its score is smaller
236 than this score."
237   :version "22.1"
238   :group 'gnus-score-default
239   :type 'integer)
240
241 (defcustom gnus-summary-zcore-fuzz 0
242   "*Fuzziness factor for the zcore in the summary buffer.
243 Articles with scores closer than this to `gnus-summary-default-score'
244 will not be marked."
245   :group 'gnus-summary-format
246   :type 'integer)
247
248 (defcustom gnus-simplify-subject-fuzzy-regexp nil
249   "*Strings to be removed when doing fuzzy matches.
250 This can either be a regular expression or list of regular expressions
251 that will be removed from subject strings if fuzzy subject
252 simplification is selected."
253   :group 'gnus-thread
254   :type '(repeat regexp))
255
256 (defcustom gnus-show-threads t
257   "*If non-nil, display threads in summary mode."
258   :group 'gnus-thread
259   :type 'boolean)
260
261 (defcustom gnus-thread-hide-subtree nil
262   "*If non-nil, hide all threads initially.
263 This can be a predicate specifier which says which threads to hide.
264 If threads are hidden, you have to run the command
265 `gnus-summary-show-thread' by hand or select an article."
266   :group 'gnus-thread
267   :type '(radio (sexp :format "Non-nil\n"
268                       :match (lambda (widget value)
269                                (not (or (consp value) (functionp value))))
270                       :value t)
271                 (const nil)
272                 (sexp :tag "Predicate specifier")))
273
274 (defcustom gnus-thread-hide-killed t
275   "*If non-nil, hide killed threads automatically."
276   :group 'gnus-thread
277   :type 'boolean)
278
279 (defcustom gnus-thread-ignore-subject t
280   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
281 If nil, articles that have different subjects from their parents will
282 start separate threads."
283   :group 'gnus-thread
284   :type 'boolean)
285
286 (defcustom gnus-thread-operation-ignore-subject t
287   "*If non-nil, subjects will be ignored when doing thread commands.
288 This affects commands like `gnus-summary-kill-thread' and
289 `gnus-summary-lower-thread'.
290
291 If this variable is nil, articles in the same thread with different
292 subjects will not be included in the operation in question.  If this
293 variable is `fuzzy', only articles that have subjects that are fuzzily
294 equal will be included."
295   :group 'gnus-thread
296   :type '(choice (const :tag "off" nil)
297                  (const fuzzy)
298                  (sexp :tag "on" t)))
299
300 (defcustom gnus-thread-indent-level 4
301   "*Number that says how much each sub-thread should be indented."
302   :group 'gnus-thread
303   :type 'integer)
304
305 (defcustom gnus-auto-extend-newsgroup t
306   "*If non-nil, extend newsgroup forward and backward when requested."
307   :group 'gnus-summary-choose
308   :type 'boolean)
309
310 (defcustom gnus-auto-select-first t
311   "*If non-nil, select the article under point.
312 Which article this is is controlled by the `gnus-auto-select-subject'
313 variable.
314
315 If you want to prevent automatic selection of articles in some
316 newsgroups, set the variable to nil in `gnus-select-group-hook'."
317   :group 'gnus-group-select
318   :type '(choice (const :tag "none" nil)
319                  (sexp :menu-tag "first" t)))
320
321 (defcustom gnus-auto-select-subject 'unread
322   "*Says what subject to place under point when entering a group.
323
324 This variable can either be the symbols `first' (place point on the
325 first subject), `unread' (place point on the subject line of the first
326 unread article), `best' (place point on the subject line of the
327 higest-scored article), `unseen' (place point on the subject line of
328 the first unseen article), `unseen-or-unread' (place point on the subject
329 line of the first unseen article or, if all article have been seen, on the
330 subject line of the first unread article), or a function to be called to
331 place point on some subject line."
332   :version "22.1"
333   :group 'gnus-group-select
334   :type '(choice (const best)
335                  (const unread)
336                  (const first)
337                  (const unseen)
338                  (const unseen-or-unread)))
339
340 (defcustom gnus-auto-select-next t
341   "*If non-nil, offer to go to the next group from the end of the previous.
342 If the value is t and the next newsgroup is empty, Gnus will exit
343 summary mode and go back to group mode.  If the value is neither nil
344 nor t, Gnus will select the following unread newsgroup.  In
345 particular, if the value is the symbol `quietly', the next unread
346 newsgroup will be selected without any confirmation, and if it is
347 `almost-quietly', the next group will be selected without any
348 confirmation if you are located on the last article in the group.
349 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
350 will go to the next group without confirmation."
351   :group 'gnus-summary-maneuvering
352   :type '(choice (const :tag "off" nil)
353                  (const quietly)
354                  (const almost-quietly)
355                  (const slightly-quietly)
356                  (sexp :menu-tag "on" t)))
357
358 (defcustom gnus-auto-select-same nil
359   "*If non-nil, select the next article with the same subject.
360 If there are no more articles with the same subject, go to
361 the first unread article."
362   :group 'gnus-summary-maneuvering
363   :type 'boolean)
364
365 (defcustom gnus-auto-goto-ignores 'unfetched
366   "*Says how to handle unfetched articles when maneuvering.
367
368 This variable can either be the symbols nil (maneuver to any
369 article), `undownloaded' (maneuvering while unplugged ignores articles
370 that have not been fetched), `always-undownloaded' (maneuvering always
371 ignores articles that have not been fetched), `unfetched' (maneuvering
372 ignores articles whose headers have not been fetched).
373
374 NOTE: The list of unfetched articles will always be nil when plugged
375 and, when unplugged, a subset of the undownloaded article list."
376   :version "22.1"
377   :group 'gnus-summary-maneuvering
378   :type '(choice (const :tag "None" nil)
379                  (const :tag "Undownloaded when unplugged" undownloaded)
380                  (const :tag "Undownloaded" always-undownloaded)
381                  (const :tag "Unfetched" unfetched)))
382
383 (defcustom gnus-summary-check-current nil
384   "*If non-nil, consider the current article when moving.
385 The \"unread\" movement commands will stay on the same line if the
386 current article is unread."
387   :group 'gnus-summary-maneuvering
388   :type 'boolean)
389
390 (defcustom gnus-auto-center-summary 2
391   "*If non-nil, always center the current summary buffer.
392 In particular, if `vertical' do only vertical recentering.  If non-nil
393 and non-`vertical', do both horizontal and vertical recentering."
394   :group 'gnus-summary-maneuvering
395   :type '(choice (const :tag "none" nil)
396                  (const vertical)
397                  (integer :tag "height")
398                  (sexp :menu-tag "both" t)))
399
400 (defvar gnus-auto-center-group t
401   "*If non-nil, always center the group buffer.")
402
403 (defcustom gnus-show-all-headers nil
404   "*If non-nil, don't hide any headers."
405   :group 'gnus-article-hiding
406   :group 'gnus-article-headers
407   :type 'boolean)
408
409 (defcustom gnus-summary-ignore-duplicates nil
410   "*If non-nil, ignore articles with identical Message-ID headers."
411   :group 'gnus-summary
412   :type 'boolean)
413
414 (defcustom gnus-single-article-buffer t
415   "*If non-nil, display all articles in the same buffer.
416 If nil, each group will get its own article buffer."
417   :group 'gnus-article-various
418   :type 'boolean)
419
420 (defcustom gnus-break-pages t
421   "*If non-nil, do page breaking on articles.
422 The page delimiter is specified by the `gnus-page-delimiter'
423 variable."
424   :group 'gnus-article-various
425   :type 'boolean)
426
427 (defcustom gnus-move-split-methods nil
428   "*Variable used to suggest where articles are to be moved to.
429 It uses the same syntax as the `gnus-split-methods' variable.
430 However, whereas `gnus-split-methods' specifies file names as targets,
431 this variable specifies group names."
432   :group 'gnus-summary-mail
433   :type '(repeat (choice (list :value (fun) function)
434                          (cons :value ("" "") regexp (repeat string))
435                          (sexp :value nil))))
436
437 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
438   "Function used to compute default prefix for article move/copy/etc prompts.
439 The function should take one argument, a group name, and return a
440 string with the suggested prefix."
441   :group 'gnus-summary-mail
442   :type 'function)
443
444 ;; FIXME: Although the custom type is `character' for the following variables,
445 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
446
447 (defcustom gnus-unread-mark ?           ;Whitespace
448   "*Mark used for unread articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-ticked-mark ?!
453   "*Mark used for ticked articles."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-dormant-mark ??
458   "*Mark used for dormant articles."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-del-mark ?r
463   "*Mark used for del'd articles."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-read-mark ?R
468   "*Mark used for read articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-expirable-mark ?E
473   "*Mark used for expirable articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-killed-mark ?K
478   "*Mark used for killed articles."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-spam-mark ?$
483   "*Mark used for spam articles."
484   :version "22.1"
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-souped-mark ?F
489   "*Mark used for souped articles."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-kill-file-mark ?X
494   "*Mark used for articles killed by kill files."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-low-score-mark ?Y
499   "*Mark used for articles with a low score."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-catchup-mark ?C
504   "*Mark used for articles that are caught up."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-replied-mark ?A
509   "*Mark used for articles that have been replied to."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-forwarded-mark ?F
514   "*Mark used for articles that have been forwarded."
515   :version "22.1"
516   :group 'gnus-summary-marks
517   :type 'character)
518
519 (defcustom gnus-recent-mark ?N
520   "*Mark used for articles that are recent."
521   :version "22.1"
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-cached-mark ?*
526   "*Mark used for articles that are in the cache."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-saved-mark ?S
531   "*Mark used for articles that have been saved."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-unseen-mark ?.
536   "*Mark used for articles that haven't been seen."
537   :version "22.1"
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-no-mark ?               ;Whitespace
542   "*Mark used for articles that have no other secondary mark."
543   :version "22.1"
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-ancient-mark ?O
548   "*Mark used for ancient articles."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-sparse-mark ?Q
553   "*Mark used for sparsely reffed articles."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-canceled-mark ?G
558   "*Mark used for canceled articles."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-duplicate-mark ?M
563   "*Mark used for duplicate articles."
564   :group 'gnus-summary-marks
565   :type 'character)
566
567 (defcustom gnus-undownloaded-mark ?-
568   "*Mark used for articles that weren't downloaded."
569   :version "22.1"
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-downloaded-mark ?+
574   "*Mark used for articles that were downloaded."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-downloadable-mark ?%
579   "*Mark used for articles that are to be downloaded."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-unsendable-mark ?=
584   "*Mark used for articles that won't be sent."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-score-over-mark ?+
589   "*Score mark used for articles with high scores."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-score-below-mark ?-
594   "*Score mark used for articles with low scores."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-empty-thread-mark ?     ;Whitespace
599   "*There is no thread under the article."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-not-empty-thread-mark ?=
604   "*There is a thread under the article."
605   :group 'gnus-summary-marks
606   :type 'character)
607
608 (defcustom gnus-view-pseudo-asynchronously nil
609   "*If non-nil, Gnus will view pseudo-articles asynchronously."
610   :group 'gnus-extract-view
611   :type 'boolean)
612
613 (defcustom gnus-auto-expirable-marks
614   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
615         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
616         gnus-souped-mark gnus-duplicate-mark)
617   "*The list of marks converted into expiration if a group is auto-expirable."
618   :version "21.1"
619   :group 'gnus-summary
620   :type '(repeat character))
621
622 (defcustom gnus-inhibit-user-auto-expire t
623   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
624   :version "21.1"
625   :group 'gnus-summary
626   :type 'boolean)
627
628 (defcustom gnus-view-pseudos nil
629   "*If `automatic', pseudo-articles will be viewed automatically.
630 If `not-confirm', pseudos will be viewed automatically, and the user
631 will not be asked to confirm the command."
632   :group 'gnus-extract-view
633   :type '(choice (const :tag "off" nil)
634                  (const automatic)
635                  (const not-confirm)))
636
637 (defcustom gnus-view-pseudos-separately t
638   "*If non-nil, one pseudo-article will be created for each file to be viewed.
639 If nil, all files that use the same viewing command will be given as a
640 list of parameters to that command."
641   :group 'gnus-extract-view
642   :type 'boolean)
643
644 (defcustom gnus-insert-pseudo-articles t
645   "*If non-nil, insert pseudo-articles when decoding articles."
646   :group 'gnus-extract-view
647   :type 'boolean)
648
649 (defcustom gnus-summary-dummy-line-format
650   "   %(:                             :%) %S\n"
651   "*The format specification for the dummy roots in the summary buffer.
652 It works along the same lines as a normal formatting string,
653 with some simple extensions.
654
655 %S  The subject
656
657 General format specifiers can also be used.
658 See `(gnus)Formatting Variables'."
659   :link '(custom-manual "(gnus)Formatting Variables")
660   :group 'gnus-threading
661   :type 'string)
662
663 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
664   "*The format specification for the summary mode line.
665 It works along the same lines as a normal formatting string,
666 with some simple extensions:
667
668 %G  Group name
669 %p  Unprefixed group name
670 %A  Current article number
671 %z  Current article score
672 %V  Gnus version
673 %U  Number of unread articles in the group
674 %e  Number of unselected articles in the group
675 %Z  A string with unread/unselected article counts
676 %g  Shortish group name
677 %S  Subject of the current article
678 %u  User-defined spec
679 %s  Current score file name
680 %d  Number of dormant articles
681 %r  Number of articles that have been marked as read in this session
682 %E  Number of articles expunged by the score files"
683   :group 'gnus-summary-format
684   :type 'string)
685
686 (defcustom gnus-list-identifiers nil
687   "Regexp that matches list identifiers to be removed from subject.
688 This can also be a list of regexps."
689   :version "21.1"
690   :group 'gnus-summary-format
691   :group 'gnus-article-hiding
692   :type '(choice (const :tag "none" nil)
693                  (regexp :value ".*")
694                  (repeat :value (".*") regexp)))
695
696 (defcustom gnus-summary-mark-below 0
697   "*Mark all articles with a score below this variable as read.
698 This variable is local to each summary buffer and usually set by the
699 score file."
700   :group 'gnus-score-default
701   :type 'integer)
702
703 (defun gnus-widget-reversible-match (widget value)
704   "Ignoring WIDGET, convert VALUE to internal form.
705 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
706   ;; (debug value)
707   (or (symbolp value)
708       (and (listp value)
709            (eq (length value) 2)
710            (eq (nth 0 value) 'not)
711            (symbolp (nth 1 value)))))
712
713 (defun gnus-widget-reversible-to-internal (widget value)
714   "Ignoring WIDGET, convert VALUE to internal form.
715 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
716 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
717   ;; (debug value)
718   (if (atom value)
719       (list value nil)
720     (list (nth 1 value) t)))
721
722 (defun gnus-widget-reversible-to-external (widget value)
723   "Ignoring WIDGET, convert VALUE to external form.
724 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
725 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
726   ;; (debug value)
727   (if (nth 1 value)
728       (list 'not (nth 0 value))
729     (nth 0 value)))
730
731 (define-widget 'gnus-widget-reversible 'group
732   "A `group' that convert values."
733   :match 'gnus-widget-reversible-match
734   :value-to-internal 'gnus-widget-reversible-to-internal
735   :value-to-external 'gnus-widget-reversible-to-external)
736
737 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
738   "*List of functions used for sorting articles in the summary buffer.
739
740 Each function takes two articles and returns non-nil if the first
741 article should be sorted before the other.  If you use more than one
742 function, the primary sort function should be the last.  You should
743 probably always include `gnus-article-sort-by-number' in the list of
744 sorting functions -- preferably first.  Also note that sorting by date
745 is often much slower than sorting by number, and the sorting order is
746 very similar.  (Sorting by date means sorting by the time the message
747 was sent, sorting by number means sorting by arrival time.)
748
749 Each item can also be a list `(not F)' where F is a function;
750 this reverses the sort order.
751
752 Ready-made functions include `gnus-article-sort-by-number',
753 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
754 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
755 and `gnus-article-sort-by-score'.
756
757 When threading is turned on, the variable `gnus-thread-sort-functions'
758 controls how articles are sorted."
759   :group 'gnus-summary-sort
760   :type '(repeat (gnus-widget-reversible
761                   (choice (function-item gnus-article-sort-by-number)
762                           (function-item gnus-article-sort-by-author)
763                           (function-item gnus-article-sort-by-subject)
764                           (function-item gnus-article-sort-by-date)
765                           (function-item gnus-article-sort-by-score)
766                           (function-item gnus-article-sort-by-random)
767                           (function :tag "other"))
768                   (boolean :tag "Reverse order"))))
769
770
771 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
772   "*List of functions used for sorting threads in the summary buffer.
773 By default, threads are sorted by article number.
774
775 Each function takes two threads and returns non-nil if the first
776 thread should be sorted before the other.  If you use more than one
777 function, the primary sort function should be the last.  You should
778 probably always include `gnus-thread-sort-by-number' in the list of
779 sorting functions -- preferably first.  Also note that sorting by date
780 is often much slower than sorting by number, and the sorting order is
781 very similar.  (Sorting by date means sorting by the time the message
782 was sent, sorting by number means sorting by arrival time.)
783
784 Each list item can also be a list `(not F)' where F is a
785 function; this specifies reversed sort order.
786
787 Ready-made functions include `gnus-thread-sort-by-number',
788 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
789 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
790 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
791 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
792 and `gnus-thread-sort-by-total-score' (see
793 `gnus-thread-score-function').
794
795 When threading is turned off, the variable
796 `gnus-article-sort-functions' controls how articles are sorted."
797   :group 'gnus-summary-sort
798   :type '(repeat
799           (gnus-widget-reversible
800            (choice (function-item gnus-thread-sort-by-number)
801                    (function-item gnus-thread-sort-by-author)
802                    (function-item gnus-thread-sort-by-recipient)
803                    (function-item gnus-thread-sort-by-subject)
804                    (function-item gnus-thread-sort-by-date)
805                    (function-item gnus-thread-sort-by-score)
806                    (function-item gnus-thread-sort-by-most-recent-number)
807                    (function-item gnus-thread-sort-by-most-recent-date)
808                    (function-item gnus-thread-sort-by-random)
809                    (function-item gnus-thread-sort-by-total-score)
810                    (function :tag "other"))
811            (boolean :tag "Reverse order"))))
812
813 (defcustom gnus-thread-score-function '+
814   "*Function used for calculating the total score of a thread.
815
816 The function is called with the scores of the article and each
817 subthread and should then return the score of the thread.
818
819 Some functions you can use are `+', `max', or `min'."
820   :group 'gnus-summary-sort
821   :type 'function)
822
823 (defcustom gnus-summary-expunge-below nil
824   "All articles that have a score less than this variable will be expunged.
825 This variable is local to the summary buffers."
826   :group 'gnus-score-default
827   :type '(choice (const :tag "off" nil)
828                  integer))
829
830 (defcustom gnus-thread-expunge-below nil
831   "All threads that have a total score less than this variable will be expunged.
832 See `gnus-thread-score-function' for en explanation of what a
833 \"thread score\" is.
834
835 This variable is local to the summary buffers."
836   :group 'gnus-threading
837   :group 'gnus-score-default
838   :type '(choice (const :tag "off" nil)
839                  integer))
840
841 (defcustom gnus-summary-mode-hook nil
842   "*A hook for Gnus summary mode.
843 This hook is run before any variables are set in the summary buffer."
844   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
845   :group 'gnus-summary-various
846   :type 'hook)
847
848 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
849 (when (featurep 'xemacs)
850   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
851   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
852   (add-hook 'gnus-summary-mode-hook
853             'gnus-xmas-switch-horizontal-scrollbar-off))
854
855 (defcustom gnus-summary-menu-hook nil
856   "*Hook run after the creation of the summary mode menu."
857   :group 'gnus-summary-visual
858   :type 'hook)
859
860 (defcustom gnus-summary-exit-hook nil
861   "*A hook called on exit from the summary buffer.
862 It will be called with point in the group buffer."
863   :group 'gnus-summary-exit
864   :type 'hook)
865
866 (defcustom gnus-summary-prepare-hook nil
867   "*A hook called after the summary buffer has been generated.
868 If you want to modify the summary buffer, you can use this hook."
869   :group 'gnus-summary-various
870   :type 'hook)
871
872 (defcustom gnus-summary-prepared-hook nil
873   "*A hook called as the last thing after the summary buffer has been generated."
874   :group 'gnus-summary-various
875   :type 'hook)
876
877 (defcustom gnus-summary-generate-hook nil
878   "*A hook run just before generating the summary buffer.
879 This hook is commonly used to customize threading variables and the
880 like."
881   :group 'gnus-summary-various
882   :type 'hook)
883
884 (defcustom gnus-select-group-hook nil
885   "*A hook called when a newsgroup is selected.
886
887 If you'd like to simplify subjects like the
888 `gnus-summary-next-same-subject' command does, you can use the
889 following hook:
890
891  (add-hook gnus-select-group-hook
892            (lambda ()
893              (mapcar (lambda (header)
894                        (mail-header-set-subject
895                         header
896                         (gnus-simplify-subject
897                          (mail-header-subject header) 're-only)))
898                      gnus-newsgroup-headers)))"
899   :group 'gnus-group-select
900   :type 'hook)
901
902 (defcustom gnus-select-article-hook nil
903   "*A hook called when an article is selected."
904   :group 'gnus-summary-choose
905   :options '(gnus-agent-fetch-selected-article)
906   :type 'hook)
907
908 (defcustom gnus-visual-mark-article-hook
909   (list 'gnus-highlight-selected-summary)
910   "*Hook run after selecting an article in the summary buffer.
911 It is meant to be used for highlighting the article in some way.  It
912 is not run if `gnus-visual' is nil."
913   :group 'gnus-summary-visual
914   :type 'hook)
915
916 (defcustom gnus-parse-headers-hook nil
917   "*A hook called before parsing the headers."
918   :group 'gnus-various
919   :type 'hook)
920
921 (defcustom gnus-exit-group-hook nil
922   "*A hook called when exiting summary mode.
923 This hook is not called from the non-updating exit commands like `Q'."
924   :group 'gnus-various
925   :type 'hook)
926
927 (defcustom gnus-summary-update-hook
928   (list 'gnus-summary-highlight-line)
929   "*A hook called when a summary line is changed.
930 The hook will not be called if `gnus-visual' is nil.
931
932 The default function `gnus-summary-highlight-line' will
933 highlight the line according to the `gnus-summary-highlight'
934 variable."
935   :group 'gnus-summary-visual
936   :type 'hook)
937
938 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
939   "*A hook called when an article is selected for the first time.
940 The hook is intended to mark an article as read (or unread)
941 automatically when it is selected."
942   :group 'gnus-summary-choose
943   :type 'hook)
944
945 (defcustom gnus-group-no-more-groups-hook nil
946   "*A hook run when returning to group mode having no more (unread) groups."
947   :group 'gnus-group-select
948   :type 'hook)
949
950 (defcustom gnus-ps-print-hook nil
951   "*A hook run before ps-printing something from Gnus."
952   :group 'gnus-summary
953   :type 'hook)
954
955 (defcustom gnus-summary-article-move-hook nil
956   "*A hook called after an article is moved, copied, respooled, or crossposted."
957   :version "22.1"
958   :group 'gnus-summary
959   :type 'hook)
960
961 (defcustom gnus-summary-article-delete-hook nil
962   "*A hook called after an article is deleted."
963   :version "22.1"
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-article-expire-hook nil
968   "*A hook called after an article is expired."
969   :version "22.1"
970   :group 'gnus-summary
971   :type 'hook)
972
973 (defcustom gnus-summary-display-arrow
974   (and (fboundp 'display-graphic-p)
975        (display-graphic-p))
976   "*If non-nil, display an arrow highlighting the current article."
977   :version "22.1"
978   :group 'gnus-summary
979   :type 'boolean)
980
981 (defcustom gnus-summary-selected-face 'gnus-summary-selected
982   "Face used for highlighting the current article in the summary buffer."
983   :group 'gnus-summary-visual
984   :type 'face)
985
986 (defvar gnus-tmp-downloaded nil)
987
988 (defcustom gnus-summary-highlight
989   '(((eq mark gnus-canceled-mark)
990      . gnus-summary-cancelled)
991     ((and uncached (> score default-high))
992      . gnus-summary-high-undownloaded)
993     ((and uncached (< score default-low))
994      . gnus-summary-low-undownloaded)
995     (uncached
996      . gnus-summary-normal-undownloaded)
997     ((and (> score default-high)
998           (or (eq mark gnus-dormant-mark)
999               (eq mark gnus-ticked-mark)))
1000      . gnus-summary-high-ticked)
1001     ((and (< score default-low)
1002           (or (eq mark gnus-dormant-mark)
1003               (eq mark gnus-ticked-mark)))
1004      . gnus-summary-low-ticked)
1005     ((or (eq mark gnus-dormant-mark)
1006          (eq mark gnus-ticked-mark))
1007      . gnus-summary-normal-ticked)
1008     ((and (> score default-high) (eq mark gnus-ancient-mark))
1009      . gnus-summary-high-ancient)
1010     ((and (< score default-low) (eq mark gnus-ancient-mark))
1011      . gnus-summary-low-ancient)
1012     ((eq mark gnus-ancient-mark)
1013      . gnus-summary-normal-ancient)
1014     ((and (> score default-high) (eq mark gnus-unread-mark))
1015      . gnus-summary-high-unread)
1016     ((and (< score default-low) (eq mark gnus-unread-mark))
1017      . gnus-summary-low-unread)
1018     ((eq mark gnus-unread-mark)
1019      . gnus-summary-normal-unread)
1020     ((> score default-high)
1021      . gnus-summary-high-read)
1022     ((< score default-low)
1023      . gnus-summary-low-read)
1024     (t
1025      . gnus-summary-normal-read))
1026   "*Controls the highlighting of summary buffer lines.
1027
1028 A list of (FORM . FACE) pairs.  When deciding how a a particular
1029 summary line should be displayed, each form is evaluated.  The content
1030 of the face field after the first true form is used.  You can change
1031 how those summary lines are displayed, by editing the face field.
1032
1033 You can use the following variables in the FORM field.
1034
1035 score:        The article's score
1036 default:      The default article score.
1037 default-high: The default score for high scored articles.
1038 default-low:  The default score for low scored articles.
1039 below:        The score below which articles are automatically marked as read.
1040 mark:         The article's mark.
1041 uncached:     Non-nil if the article is uncached."
1042   :group 'gnus-summary-visual
1043   :type '(repeat (cons (sexp :tag "Form" nil)
1044                        face)))
1045
1046 (defcustom gnus-alter-header-function nil
1047   "Function called to allow alteration of article header structures.
1048 The function is called with one parameter, the article header vector,
1049 which it may alter in any way."
1050   :type '(choice (const :tag "None" nil)
1051                  function)
1052   :group 'gnus-summary)
1053
1054 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1055   "Variable that says which function should be used to decode a string with encoded words.")
1056
1057 (defcustom gnus-extra-headers '(To Newsgroups)
1058   "*Extra headers to parse."
1059   :version "21.1"
1060   :group 'gnus-summary
1061   :type '(repeat symbol))
1062
1063 (defcustom gnus-ignored-from-addresses
1064   (and user-mail-address  
1065        (not (string= user-mail-address ""))
1066        (regexp-quote user-mail-address))
1067   "*Regexp of From headers that may be suppressed in favor of To headers."
1068   :version "21.1"
1069   :group 'gnus-summary
1070   :type 'regexp)
1071
1072 (defcustom gnus-summary-to-prefix "-> "
1073   "*String prefixed to the To field in the summary line when
1074 using `gnus-ignored-from-addresses'."
1075   :version "22.1"
1076   :group 'gnus-summary
1077   :type 'string)
1078
1079 (defcustom gnus-summary-newsgroup-prefix "=> "
1080   "*String prefixed to the Newsgroup field in the summary
1081 line when using `gnus-ignored-from-addresses'."
1082   :version "22.1"
1083   :group 'gnus-summary
1084   :type 'string)
1085
1086 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1087   "List of charsets that should be ignored.
1088 When these charsets are used in the \"charset\" parameter, the
1089 default charset will be used instead."
1090   :version "21.1"
1091   :type '(repeat symbol)
1092   :group 'gnus-charset)
1093
1094 (gnus-define-group-parameter
1095  ignored-charsets
1096  :type list
1097  :function-document
1098  "Return the ignored charsets of GROUP."
1099  :variable gnus-group-ignored-charsets-alist
1100  :variable-default
1101  '(("alt\\.chinese\\.text" iso-8859-1))
1102  :variable-document
1103  "Alist of regexps (to match group names) and charsets that should be ignored.
1104 When these charsets are used in the \"charset\" parameter, the
1105 default charset will be used instead."
1106  :variable-group gnus-charset
1107  :variable-type '(repeat (cons (regexp :tag "Group")
1108                                (repeat symbol)))
1109  :parameter-type '(choice :tag "Ignored charsets"
1110                           :value nil
1111                           (repeat (symbol)))
1112  :parameter-document       "\
1113 List of charsets that should be ignored.
1114
1115 When these charsets are used in the \"charset\" parameter, the
1116 default charset will be used instead.")
1117
1118 (defcustom gnus-group-highlight-words-alist nil
1119   "Alist of group regexps and highlight regexps.
1120 This variable uses the same syntax as `gnus-emphasis-alist'."
1121   :version "21.1"
1122   :type '(repeat (cons (regexp :tag "Group")
1123                        (repeat (list (regexp :tag "Highlight regexp")
1124                                      (number :tag "Group for entire word" 0)
1125                                      (number :tag "Group for displayed part" 0)
1126                                      (symbol :tag "Face"
1127                                              gnus-emphasis-highlight-words)))))
1128   :group 'gnus-summary-visual)
1129
1130 (defcustom gnus-summary-show-article-charset-alist
1131   nil
1132   "Alist of number and charset.
1133 The article will be shown with the charset corresponding to the
1134 numbered argument.
1135 For example: ((1 . cn-gb-2312) (2 . big5))."
1136   :version "21.1"
1137   :type '(repeat (cons (number :tag "Argument" 1)
1138                        (symbol :tag "Charset")))
1139   :group 'gnus-charset)
1140
1141 (defcustom gnus-preserve-marks t
1142   "Whether marks are preserved when moving, copying and respooling messages."
1143   :version "21.1"
1144   :type 'boolean
1145   :group 'gnus-summary-marks)
1146
1147 (defcustom gnus-alter-articles-to-read-function nil
1148   "Function to be called to alter the list of articles to be selected."
1149   :type '(choice (const nil) function)
1150   :group 'gnus-summary)
1151
1152 (defcustom gnus-orphan-score nil
1153   "*All orphans get this score added.  Set in the score file."
1154   :group 'gnus-score-default
1155   :type '(choice (const nil)
1156                  integer))
1157
1158 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1159   "*A regexp to match MIME parts when saving multiple parts of a
1160 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1161 This regexp will be used by default when prompting the user for which
1162 type of files to save."
1163   :group 'gnus-summary
1164   :type 'regexp)
1165
1166 (defcustom gnus-read-all-available-headers nil
1167   "Whether Gnus should parse all headers made available to it.
1168 This is mostly relevant for slow back ends where the user may
1169 wish to widen the summary buffer to include all headers
1170 that were fetched.  Say, for nnultimate groups."
1171   :version "22.1"
1172   :group 'gnus-summary
1173   :type '(choice boolean regexp))
1174
1175 (defcustom gnus-summary-muttprint-program "muttprint"
1176   "Command (and optional arguments) used to run Muttprint."
1177   :version "22.1"
1178   :group 'gnus-summary
1179   :type 'string)
1180
1181 (defcustom gnus-article-loose-mime t
1182   "If non-nil, don't require MIME-Version header.
1183 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1184 supply the MIME-Version header or deliberately strip it from the mail.
1185 If non-nil (the default), Gnus will treat some articles as MIME
1186 even if the MIME-Version header is missing."
1187   :version "22.1"
1188   :type 'boolean
1189   :group 'gnus-article-mime)
1190
1191 (defcustom gnus-article-emulate-mime t
1192   "If non-nil, use MIME emulation for uuencode and the like.
1193 This means that Gnus will search message bodies for text that look
1194 like uuencoded bits, yEncoded bits, and so on, and present that using
1195 the normal Gnus MIME machinery."
1196   :version "22.1"
1197   :type 'boolean
1198   :group 'gnus-article-mime)
1199
1200 ;;; Internal variables
1201
1202 (defvar gnus-summary-display-cache nil)
1203 (defvar gnus-article-mime-handles nil)
1204 (defvar gnus-article-decoded-p nil)
1205 (defvar gnus-article-charset nil)
1206 (defvar gnus-article-ignored-charsets nil)
1207 (defvar gnus-scores-exclude-files nil)
1208 (defvar gnus-page-broken nil)
1209
1210 (defvar gnus-original-article nil)
1211 (defvar gnus-article-internal-prepare-hook nil)
1212 (defvar gnus-newsgroup-process-stack nil)
1213
1214 (defvar gnus-thread-indent-array nil)
1215 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1216 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1217   "Function called to sort the articles within a thread after it has been gathered together.")
1218
1219 (defvar gnus-summary-save-parts-type-history nil)
1220 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1221
1222 ;; Avoid highlighting in kill files.
1223 (defvar gnus-summary-inhibit-highlight nil)
1224 (defvar gnus-newsgroup-selected-overlay nil)
1225 (defvar gnus-inhibit-limiting nil)
1226 (defvar gnus-newsgroup-adaptive-score-file nil)
1227 (defvar gnus-current-score-file nil)
1228 (defvar gnus-current-move-group nil)
1229 (defvar gnus-current-copy-group nil)
1230 (defvar gnus-current-crosspost-group nil)
1231 (defvar gnus-newsgroup-display nil)
1232
1233 (defvar gnus-newsgroup-dependencies nil)
1234 (defvar gnus-newsgroup-adaptive nil)
1235 (defvar gnus-summary-display-article-function nil)
1236 (defvar gnus-summary-highlight-line-function nil
1237   "Function called after highlighting a summary line.")
1238
1239 (defvar gnus-summary-line-format-alist
1240   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1241     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1242     (?s gnus-tmp-subject-or-nil ?s)
1243     (?n gnus-tmp-name ?s)
1244     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1245         ?s)
1246     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1247             gnus-tmp-from) ?s)
1248     (?F gnus-tmp-from ?s)
1249     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1250     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1251     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1252     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1253     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1254     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1255     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1256     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1257     (?L gnus-tmp-lines ?s)
1258     (?O gnus-tmp-downloaded ?c)
1259     (?I gnus-tmp-indentation ?s)
1260     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1261     (?R gnus-tmp-replied ?c)
1262     (?\[ gnus-tmp-opening-bracket ?c)
1263     (?\] gnus-tmp-closing-bracket ?c)
1264     (?\> (make-string gnus-tmp-level ? ) ?s)
1265     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1266     (?i gnus-tmp-score ?d)
1267     (?z gnus-tmp-score-char ?c)
1268     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1269     (?U gnus-tmp-unread ?c)
1270     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1271         ?s)
1272     (?t (gnus-summary-number-of-articles-in-thread
1273          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1274         ?d)
1275     (?e (gnus-summary-number-of-articles-in-thread
1276          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1277         ?c)
1278     (?u gnus-tmp-user-defined ?s)
1279     (?P (gnus-pick-line-number) ?d)
1280     (?B gnus-tmp-thread-tree-header-string ?s)
1281     (user-date (gnus-user-date
1282                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1283   "An alist of format specifications that can appear in summary lines.
1284 These are paired with what variables they correspond with, along with
1285 the type of the variable (string, integer, character, etc).")
1286
1287 (defvar gnus-summary-dummy-line-format-alist
1288   `((?S gnus-tmp-subject ?s)
1289     (?N gnus-tmp-number ?d)
1290     (?u gnus-tmp-user-defined ?s)))
1291
1292 (defvar gnus-summary-mode-line-format-alist
1293   `((?G gnus-tmp-group-name ?s)
1294     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1295     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1296     (?A gnus-tmp-article-number ?d)
1297     (?Z gnus-tmp-unread-and-unselected ?s)
1298     (?V gnus-version ?s)
1299     (?U gnus-tmp-unread-and-unticked ?d)
1300     (?S gnus-tmp-subject ?s)
1301     (?e gnus-tmp-unselected ?d)
1302     (?u gnus-tmp-user-defined ?s)
1303     (?d (length gnus-newsgroup-dormant) ?d)
1304     (?t (length gnus-newsgroup-marked) ?d)
1305     (?h (length gnus-newsgroup-spam-marked) ?d)
1306     (?r (length gnus-newsgroup-reads) ?d)
1307     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1308     (?E gnus-newsgroup-expunged-tally ?d)
1309     (?s (gnus-current-score-file-nondirectory) ?s)))
1310
1311 (defvar gnus-last-search-regexp nil
1312   "Default regexp for article search command.")
1313
1314 (defvar gnus-last-shell-command nil
1315   "Default shell command on article.")
1316
1317 (defvar gnus-newsgroup-agentized nil
1318   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1319 (defvar gnus-newsgroup-begin nil)
1320 (defvar gnus-newsgroup-end nil)
1321 (defvar gnus-newsgroup-last-rmail nil)
1322 (defvar gnus-newsgroup-last-mail nil)
1323 (defvar gnus-newsgroup-last-folder nil)
1324 (defvar gnus-newsgroup-last-file nil)
1325 (defvar gnus-newsgroup-auto-expire nil)
1326 (defvar gnus-newsgroup-active nil)
1327
1328 (defvar gnus-newsgroup-data nil)
1329 (defvar gnus-newsgroup-data-reverse nil)
1330 (defvar gnus-newsgroup-limit nil)
1331 (defvar gnus-newsgroup-limits nil)
1332 (defvar gnus-summary-use-undownloaded-faces nil)
1333
1334 (defvar gnus-newsgroup-unreads nil
1335   "Sorted list of unread articles in the current newsgroup.")
1336
1337 (defvar gnus-newsgroup-unselected nil
1338   "Sorted list of unselected unread articles in the current newsgroup.")
1339
1340 (defvar gnus-newsgroup-reads nil
1341   "Alist of read articles and article marks in the current newsgroup.")
1342
1343 (defvar gnus-newsgroup-expunged-tally nil)
1344
1345 (defvar gnus-newsgroup-marked nil
1346   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1347
1348 (defvar gnus-newsgroup-spam-marked nil
1349   "List of ranges of articles that have been marked as spam.")
1350
1351 (defvar gnus-newsgroup-killed nil
1352   "List of ranges of articles that have been through the scoring process.")
1353
1354 (defvar gnus-newsgroup-cached nil
1355   "Sorted list of articles that come from the article cache.")
1356
1357 (defvar gnus-newsgroup-saved nil
1358   "List of articles that have been saved.")
1359
1360 (defvar gnus-newsgroup-kill-headers nil)
1361
1362 (defvar gnus-newsgroup-replied nil
1363   "List of articles that have been replied to in the current newsgroup.")
1364
1365 (defvar gnus-newsgroup-forwarded nil
1366   "List of articles that have been forwarded in the current newsgroup.")
1367
1368 (defvar gnus-newsgroup-recent nil
1369   "List of articles that have are recent in the current newsgroup.")
1370
1371 (defvar gnus-newsgroup-expirable nil
1372   "Sorted list of articles in the current newsgroup that can be expired.")
1373
1374 (defvar gnus-newsgroup-processable nil
1375   "List of articles in the current newsgroup that can be processed.")
1376
1377 (defvar gnus-newsgroup-downloadable nil
1378   "Sorted list of articles in the current newsgroup that can be processed.")
1379
1380 (defvar gnus-newsgroup-unfetched nil
1381   "Sorted list of articles in the current newsgroup whose headers have
1382 not been fetched into the agent.
1383
1384 This list will always be a subset of gnus-newsgroup-undownloaded.")
1385
1386 (defvar gnus-newsgroup-undownloaded nil
1387   "List of articles in the current newsgroup that haven't been downloaded.")
1388
1389 (defvar gnus-newsgroup-unsendable nil
1390   "List of articles in the current newsgroup that won't be sent.")
1391
1392 (defvar gnus-newsgroup-bookmarks nil
1393   "List of articles in the current newsgroup that have bookmarks.")
1394
1395 (defvar gnus-newsgroup-dormant nil
1396   "Sorted list of dormant articles in the current newsgroup.")
1397
1398 (defvar gnus-newsgroup-unseen nil
1399   "List of unseen articles in the current newsgroup.")
1400
1401 (defvar gnus-newsgroup-seen nil
1402   "Range of seen articles in the current newsgroup.")
1403
1404 (defvar gnus-newsgroup-articles nil
1405   "List of articles in the current newsgroup.")
1406
1407 (defvar gnus-newsgroup-scored nil
1408   "List of scored articles in the current newsgroup.")
1409
1410 (defvar gnus-newsgroup-headers nil
1411   "List of article headers in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-threads nil)
1414
1415 (defvar gnus-newsgroup-prepared nil
1416   "Whether the current group has been prepared properly.")
1417
1418 (defvar gnus-newsgroup-ancient nil
1419   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1420
1421 (defvar gnus-newsgroup-sparse nil)
1422
1423 (defvar gnus-current-article nil)
1424 (defvar gnus-article-current nil)
1425 (defvar gnus-current-headers nil)
1426 (defvar gnus-have-all-headers nil)
1427 (defvar gnus-last-article nil)
1428 (defvar gnus-newsgroup-history nil)
1429 (defvar gnus-newsgroup-charset nil)
1430 (defvar gnus-newsgroup-ephemeral-charset nil)
1431 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1432
1433 (defvar gnus-article-before-search nil)
1434
1435 (defvar gnus-summary-local-variables
1436   '(gnus-newsgroup-name
1437     gnus-newsgroup-begin gnus-newsgroup-end
1438     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1439     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1440     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1441     gnus-newsgroup-unselected gnus-newsgroup-marked
1442     gnus-newsgroup-spam-marked
1443     gnus-newsgroup-reads gnus-newsgroup-saved
1444     gnus-newsgroup-replied gnus-newsgroup-forwarded
1445     gnus-newsgroup-recent
1446     gnus-newsgroup-expirable
1447     gnus-newsgroup-processable gnus-newsgroup-killed
1448     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1449     gnus-newsgroup-unfetched
1450     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1451     gnus-newsgroup-seen gnus-newsgroup-articles
1452     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1453     gnus-newsgroup-headers gnus-newsgroup-threads
1454     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1455     gnus-current-article gnus-current-headers gnus-have-all-headers
1456     gnus-last-article gnus-article-internal-prepare-hook
1457     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1458     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1459     gnus-thread-expunge-below
1460     gnus-score-alist gnus-current-score-file
1461     (gnus-summary-expunge-below . global)
1462     (gnus-summary-mark-below . global)
1463     (gnus-orphan-score . global)
1464     gnus-newsgroup-active gnus-scores-exclude-files
1465     gnus-newsgroup-history gnus-newsgroup-ancient
1466     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1467     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1468     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1469     (gnus-newsgroup-expunged-tally . 0)
1470     gnus-cache-removable-articles gnus-newsgroup-cached
1471     gnus-newsgroup-data gnus-newsgroup-data-reverse
1472     gnus-newsgroup-limit gnus-newsgroup-limits
1473     gnus-newsgroup-charset gnus-newsgroup-display
1474     gnus-summary-use-undownloaded-faces)
1475   "Variables that are buffer-local to the summary buffers.")
1476
1477 (defvar gnus-newsgroup-variables nil
1478   "A list of variables that have separate values in different newsgroups.
1479 A list of newsgroup (summary buffer) local variables, or cons of
1480 variables and their default expressions to be evalled (when the default
1481 values are not nil), that should be made global while the summary buffer
1482 is active.
1483
1484 Note: The default expressions will be evaluated (using function `eval')
1485 before assignment to the local variable rather than just assigned to it.
1486 If the default expression is the symbol `global', that symbol will not
1487 be evaluated but the global value of the local variable will be used
1488 instead.
1489
1490 These variables can be used to set variables in the group parameters
1491 while still allowing them to affect operations done in other buffers.
1492 For example:
1493
1494 \(setq gnus-newsgroup-variables
1495      '(message-use-followup-to
1496        (gnus-visible-headers .
1497          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1498 ")
1499
1500 ;; Byte-compiler warning.
1501 (eval-when-compile
1502   ;; Bind features so that require will believe that gnus-sum has
1503   ;; already been loaded (avoids infinite recursion)
1504   (let ((features (cons 'gnus-sum features)))
1505     ;; Several of the declarations in gnus-sum are needed to load the
1506     ;; following files. Right now, these definitions have been
1507     ;; compiled but not defined (evaluated).  We could either do a
1508     ;; eval-and-compile about all of the declarations or evaluate the
1509     ;; source file.
1510     (if (boundp 'gnus-newsgroup-variables)
1511         nil
1512       (load "gnus-sum.el" t t t))
1513     (require 'gnus)
1514     (require 'gnus-art)))
1515
1516 ;; MIME stuff.
1517
1518 (defvar gnus-decode-encoded-word-methods
1519   '(mail-decode-encoded-word-string)
1520   "List of methods used to decode encoded words.
1521
1522 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1523 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1524 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1525 whose names match REGEXP.
1526
1527 For example:
1528 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1529  mail-decode-encoded-word-string
1530  (\"chinese\" . rfc1843-decode-string))")
1531
1532 (defvar gnus-decode-encoded-word-methods-cache nil)
1533
1534 (defun gnus-multi-decode-encoded-word-string (string)
1535   "Apply the functions from `gnus-encoded-word-methods' that match."
1536   (unless (and gnus-decode-encoded-word-methods-cache
1537                (eq gnus-newsgroup-name
1538                    (car gnus-decode-encoded-word-methods-cache)))
1539     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1540     (mapcar (lambda (x)
1541               (if (symbolp x)
1542                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1543                 (if (and gnus-newsgroup-name
1544                          (string-match (car x) gnus-newsgroup-name))
1545                     (nconc gnus-decode-encoded-word-methods-cache
1546                            (list (cdr x))))))
1547             gnus-decode-encoded-word-methods))
1548   (let ((xlist gnus-decode-encoded-word-methods-cache))
1549     (pop xlist)
1550     (while xlist
1551       (setq string (funcall (pop xlist) string))))
1552   string)
1553
1554 ;; Subject simplification.
1555
1556 (defun gnus-simplify-whitespace (str)
1557   "Remove excessive whitespace from STR."
1558   ;; Multiple spaces.
1559   (while (string-match "[ \t][ \t]+" str)
1560     (setq str (concat (substring str 0 (match-beginning 0))
1561                         " "
1562                         (substring str (match-end 0)))))
1563   ;; Leading spaces.
1564   (when (string-match "^[ \t]+" str)
1565     (setq str (substring str (match-end 0))))
1566   ;; Trailing spaces.
1567   (when (string-match "[ \t]+$" str)
1568     (setq str (substring str 0 (match-beginning 0))))
1569   str)
1570
1571 (defun gnus-simplify-all-whitespace (str)
1572   "Remove all whitespace from STR."
1573   (while (string-match "[ \t\n]+" str)
1574     (setq str (replace-match "" nil nil str)))
1575   str)
1576
1577 (defsubst gnus-simplify-subject-re (subject)
1578   "Remove \"Re:\" from subject lines."
1579   (if (string-match message-subject-re-regexp subject)
1580       (substring subject (match-end 0))
1581     subject))
1582
1583 (defun gnus-simplify-subject (subject &optional re-only)
1584   "Remove `Re:' and words in parentheses.
1585 If RE-ONLY is non-nil, strip leading `Re:'s only."
1586   (let ((case-fold-search t))           ;Ignore case.
1587     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1588     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1589       (setq subject (substring subject (match-end 0))))
1590     ;; Remove uninteresting prefixes.
1591     (when (and (not re-only)
1592                gnus-simplify-ignored-prefixes
1593                (string-match gnus-simplify-ignored-prefixes subject))
1594       (setq subject (substring subject (match-end 0))))
1595     ;; Remove words in parentheses from end.
1596     (unless re-only
1597       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1598         (setq subject (substring subject 0 (match-beginning 0)))))
1599     ;; Return subject string.
1600     subject))
1601
1602 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1603 ;; all whitespace.
1604 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1605   (goto-char (point-min))
1606   (while (re-search-forward regexp nil t)
1607     (replace-match (or newtext ""))))
1608
1609 (defun gnus-simplify-buffer-fuzzy ()
1610   "Simplify string in the buffer fuzzily.
1611 The string in the accessible portion of the current buffer is simplified.
1612 It is assumed to be a single-line subject.
1613 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1614 matter is removed.  Additional things can be deleted by setting
1615 `gnus-simplify-subject-fuzzy-regexp'."
1616   (let ((case-fold-search t)
1617         (modified-tick))
1618     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1619
1620     (while (not (eq modified-tick (buffer-modified-tick)))
1621       (setq modified-tick (buffer-modified-tick))
1622       (cond
1623        ((listp gnus-simplify-subject-fuzzy-regexp)
1624         (mapcar 'gnus-simplify-buffer-fuzzy-step
1625                 gnus-simplify-subject-fuzzy-regexp))
1626        (gnus-simplify-subject-fuzzy-regexp
1627         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1628       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1629       (gnus-simplify-buffer-fuzzy-step
1630        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1631       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1632
1633     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1634     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1635     (gnus-simplify-buffer-fuzzy-step " $")
1636     (gnus-simplify-buffer-fuzzy-step "^ +")))
1637
1638 (defun gnus-simplify-subject-fuzzy (subject)
1639   "Simplify a subject string fuzzily.
1640 See `gnus-simplify-buffer-fuzzy' for details."
1641   (save-excursion
1642     (gnus-set-work-buffer)
1643     (let ((case-fold-search t))
1644       ;; Remove uninteresting prefixes.
1645       (when (and gnus-simplify-ignored-prefixes
1646                  (string-match gnus-simplify-ignored-prefixes subject))
1647         (setq subject (substring subject (match-end 0))))
1648       (insert subject)
1649       (inline (gnus-simplify-buffer-fuzzy))
1650       (buffer-string))))
1651
1652 (defsubst gnus-simplify-subject-fully (subject)
1653   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1654   (cond
1655    (gnus-simplify-subject-functions
1656     (gnus-map-function gnus-simplify-subject-functions subject))
1657    ((null gnus-summary-gather-subject-limit)
1658     (gnus-simplify-subject-re subject))
1659    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1660     (gnus-simplify-subject-fuzzy subject))
1661    ((numberp gnus-summary-gather-subject-limit)
1662     (gnus-limit-string (gnus-simplify-subject-re subject)
1663                        gnus-summary-gather-subject-limit))
1664    (t
1665     subject)))
1666
1667 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1668   "Check whether two subjects are equal.
1669 If optional argument SIMPLE-FIRST is t, first argument is already
1670 simplified."
1671   (cond
1672    ((null simple-first)
1673     (equal (gnus-simplify-subject-fully s1)
1674            (gnus-simplify-subject-fully s2)))
1675    (t
1676     (equal s1
1677            (gnus-simplify-subject-fully s2)))))
1678
1679 (defun gnus-summary-bubble-group ()
1680   "Increase the score of the current group.
1681 This is a handy function to add to `gnus-summary-exit-hook' to
1682 increase the score of each group you read."
1683   (gnus-group-add-score gnus-newsgroup-name))
1684
1685 \f
1686 ;;;
1687 ;;; Gnus summary mode
1688 ;;;
1689
1690 (put 'gnus-summary-mode 'mode-class 'special)
1691
1692 (defvar gnus-article-commands-menu)
1693
1694 ;; Non-orthogonal keys
1695
1696 (gnus-define-keys gnus-summary-mode-map
1697   " " gnus-summary-next-page
1698   "\177" gnus-summary-prev-page
1699   [delete] gnus-summary-prev-page
1700   [backspace] gnus-summary-prev-page
1701   "\r" gnus-summary-scroll-up
1702   "\M-\r" gnus-summary-scroll-down
1703   "n" gnus-summary-next-unread-article
1704   "p" gnus-summary-prev-unread-article
1705   "N" gnus-summary-next-article
1706   "P" gnus-summary-prev-article
1707   "\M-\C-n" gnus-summary-next-same-subject
1708   "\M-\C-p" gnus-summary-prev-same-subject
1709   "\M-n" gnus-summary-next-unread-subject
1710   "\M-p" gnus-summary-prev-unread-subject
1711   "." gnus-summary-first-unread-article
1712   "," gnus-summary-best-unread-article
1713   "\M-s" gnus-summary-search-article-forward
1714   "\M-r" gnus-summary-search-article-backward
1715   "<" gnus-summary-beginning-of-article
1716   ">" gnus-summary-end-of-article
1717   "j" gnus-summary-goto-article
1718   "^" gnus-summary-refer-parent-article
1719   "\M-^" gnus-summary-refer-article
1720   "u" gnus-summary-tick-article-forward
1721   "!" gnus-summary-tick-article-forward
1722   "U" gnus-summary-tick-article-backward
1723   "d" gnus-summary-mark-as-read-forward
1724   "D" gnus-summary-mark-as-read-backward
1725   "E" gnus-summary-mark-as-expirable
1726   "\M-u" gnus-summary-clear-mark-forward
1727   "\M-U" gnus-summary-clear-mark-backward
1728   "k" gnus-summary-kill-same-subject-and-select
1729   "\C-k" gnus-summary-kill-same-subject
1730   "\M-\C-k" gnus-summary-kill-thread
1731   "\M-\C-l" gnus-summary-lower-thread
1732   "e" gnus-summary-edit-article
1733   "#" gnus-summary-mark-as-processable
1734   "\M-#" gnus-summary-unmark-as-processable
1735   "\M-\C-t" gnus-summary-toggle-threads
1736   "\M-\C-s" gnus-summary-show-thread
1737   "\M-\C-h" gnus-summary-hide-thread
1738   "\M-\C-f" gnus-summary-next-thread
1739   "\M-\C-b" gnus-summary-prev-thread
1740   [(meta down)] gnus-summary-next-thread
1741   [(meta up)] gnus-summary-prev-thread
1742   "\M-\C-u" gnus-summary-up-thread
1743   "\M-\C-d" gnus-summary-down-thread
1744   "&" gnus-summary-execute-command
1745   "c" gnus-summary-catchup-and-exit
1746   "\C-w" gnus-summary-mark-region-as-read
1747   "\C-t" gnus-summary-toggle-truncation
1748   "?" gnus-summary-mark-as-dormant
1749   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1750   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1751   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1752   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1753   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1754   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1755   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1756   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1757   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1758   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1759   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1760   "=" gnus-summary-expand-window
1761   "\C-x\C-s" gnus-summary-reselect-current-group
1762   "\M-g" gnus-summary-rescan-group
1763   "w" gnus-summary-stop-page-breaking
1764   "\C-c\C-r" gnus-summary-caesar-message
1765   "f" gnus-summary-followup
1766   "F" gnus-summary-followup-with-original
1767   "C" gnus-summary-cancel-article
1768   "r" gnus-summary-reply
1769   "R" gnus-summary-reply-with-original
1770   "\C-c\C-f" gnus-summary-mail-forward
1771   "o" gnus-summary-save-article
1772   "\C-o" gnus-summary-save-article-mail
1773   "|" gnus-summary-pipe-output
1774   "\M-k" gnus-summary-edit-local-kill
1775   "\M-K" gnus-summary-edit-global-kill
1776   ;; "V" gnus-version
1777   "\C-c\C-d" gnus-summary-describe-group
1778   "q" gnus-summary-exit
1779   "Q" gnus-summary-exit-no-update
1780   "\C-c\C-i" gnus-info-find-node
1781   gnus-mouse-2 gnus-mouse-pick-article
1782   [follow-link] mouse-face
1783   "m" gnus-summary-mail-other-window
1784   "a" gnus-summary-post-news
1785   "i" gnus-summary-news-other-window
1786   "x" gnus-summary-limit-to-unread
1787   "s" gnus-summary-isearch-article
1788   "t" gnus-summary-toggle-header
1789   "g" gnus-summary-show-article
1790   "l" gnus-summary-goto-last-article
1791   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1792   "\C-d" gnus-summary-enter-digest-group
1793   "\M-\C-d" gnus-summary-read-document
1794   "\M-\C-e" gnus-summary-edit-parameters
1795   "\M-\C-a" gnus-summary-customize-parameters
1796   "\C-c\C-b" gnus-bug
1797   "*" gnus-cache-enter-article
1798   "\M-*" gnus-cache-remove-article
1799   "\M-&" gnus-summary-universal-argument
1800   "\C-l" gnus-recenter
1801   "I" gnus-summary-increase-score
1802   "L" gnus-summary-lower-score
1803   "\M-i" gnus-symbolic-argument
1804   "h" gnus-summary-select-article-buffer
1805
1806   "b" gnus-article-view-part
1807   "\M-t" gnus-summary-toggle-display-buttonized
1808
1809   "V" gnus-summary-score-map
1810   "X" gnus-uu-extract-map
1811   "S" gnus-summary-send-map)
1812
1813 ;; Sort of orthogonal keymap
1814 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1815   "t" gnus-summary-tick-article-forward
1816   "!" gnus-summary-tick-article-forward
1817   "d" gnus-summary-mark-as-read-forward
1818   "r" gnus-summary-mark-as-read-forward
1819   "c" gnus-summary-clear-mark-forward
1820   " " gnus-summary-clear-mark-forward
1821   "e" gnus-summary-mark-as-expirable
1822   "x" gnus-summary-mark-as-expirable
1823   "?" gnus-summary-mark-as-dormant
1824   "b" gnus-summary-set-bookmark
1825   "B" gnus-summary-remove-bookmark
1826   "#" gnus-summary-mark-as-processable
1827   "\M-#" gnus-summary-unmark-as-processable
1828   "S" gnus-summary-limit-include-expunged
1829   "C" gnus-summary-catchup
1830   "H" gnus-summary-catchup-to-here
1831   "h" gnus-summary-catchup-from-here
1832   "\C-c" gnus-summary-catchup-all
1833   "k" gnus-summary-kill-same-subject-and-select
1834   "K" gnus-summary-kill-same-subject
1835   "P" gnus-uu-mark-map)
1836
1837 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1838   "c" gnus-summary-clear-above
1839   "u" gnus-summary-tick-above
1840   "m" gnus-summary-mark-above
1841   "k" gnus-summary-kill-below)
1842
1843 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1844   "/" gnus-summary-limit-to-subject
1845   "n" gnus-summary-limit-to-articles
1846   "w" gnus-summary-pop-limit
1847   "s" gnus-summary-limit-to-subject
1848   "a" gnus-summary-limit-to-author
1849   "u" gnus-summary-limit-to-unread
1850   "m" gnus-summary-limit-to-marks
1851   "M" gnus-summary-limit-exclude-marks
1852   "v" gnus-summary-limit-to-score
1853   "*" gnus-summary-limit-include-cached
1854   "D" gnus-summary-limit-include-dormant
1855   "T" gnus-summary-limit-include-thread
1856   "d" gnus-summary-limit-exclude-dormant
1857   "t" gnus-summary-limit-to-age
1858   "." gnus-summary-limit-to-unseen
1859   "x" gnus-summary-limit-to-extra
1860   "p" gnus-summary-limit-to-display-predicate
1861   "E" gnus-summary-limit-include-expunged
1862   "c" gnus-summary-limit-exclude-childless-dormant
1863   "C" gnus-summary-limit-mark-excluded-as-read
1864   "o" gnus-summary-insert-old-articles
1865   "N" gnus-summary-insert-new-articles
1866   "r" gnus-summary-limit-to-replied
1867   "R" gnus-summary-limit-to-recipient)
1868
1869 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1870   "n" gnus-summary-next-unread-article
1871   "p" gnus-summary-prev-unread-article
1872   "N" gnus-summary-next-article
1873   "P" gnus-summary-prev-article
1874   "\C-n" gnus-summary-next-same-subject
1875   "\C-p" gnus-summary-prev-same-subject
1876   "\M-n" gnus-summary-next-unread-subject
1877   "\M-p" gnus-summary-prev-unread-subject
1878   "f" gnus-summary-first-unread-article
1879   "b" gnus-summary-best-unread-article
1880   "j" gnus-summary-goto-article
1881   "g" gnus-summary-goto-subject
1882   "l" gnus-summary-goto-last-article
1883   "o" gnus-summary-pop-article)
1884
1885 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1886   "k" gnus-summary-kill-thread
1887   "l" gnus-summary-lower-thread
1888   "i" gnus-summary-raise-thread
1889   "T" gnus-summary-toggle-threads
1890   "t" gnus-summary-rethread-current
1891   "^" gnus-summary-reparent-thread
1892   "s" gnus-summary-show-thread
1893   "S" gnus-summary-show-all-threads
1894   "h" gnus-summary-hide-thread
1895   "H" gnus-summary-hide-all-threads
1896   "n" gnus-summary-next-thread
1897   "p" gnus-summary-prev-thread
1898   "u" gnus-summary-up-thread
1899   "o" gnus-summary-top-thread
1900   "d" gnus-summary-down-thread
1901   "#" gnus-uu-mark-thread
1902   "\M-#" gnus-uu-unmark-thread)
1903
1904 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1905   "g" gnus-summary-prepare
1906   "c" gnus-summary-insert-cached-articles
1907   "d" gnus-summary-insert-dormant-articles)
1908
1909 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1910   "c" gnus-summary-catchup-and-exit
1911   "C" gnus-summary-catchup-all-and-exit
1912   "E" gnus-summary-exit-no-update
1913   "Q" gnus-summary-exit
1914   "Z" gnus-summary-exit
1915   "n" gnus-summary-catchup-and-goto-next-group
1916   "p" gnus-summary-catchup-and-goto-prev-group
1917   "R" gnus-summary-reselect-current-group
1918   "G" gnus-summary-rescan-group
1919   "N" gnus-summary-next-group
1920   "s" gnus-summary-save-newsrc
1921   "P" gnus-summary-prev-group)
1922
1923 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1924   " " gnus-summary-next-page
1925   "n" gnus-summary-next-page
1926   "\177" gnus-summary-prev-page
1927   [delete] gnus-summary-prev-page
1928   "p" gnus-summary-prev-page
1929   "\r" gnus-summary-scroll-up
1930   "\M-\r" gnus-summary-scroll-down
1931   "<" gnus-summary-beginning-of-article
1932   ">" gnus-summary-end-of-article
1933   "b" gnus-summary-beginning-of-article
1934   "e" gnus-summary-end-of-article
1935   "^" gnus-summary-refer-parent-article
1936   "r" gnus-summary-refer-parent-article
1937   "D" gnus-summary-enter-digest-group
1938   "R" gnus-summary-refer-references
1939   "T" gnus-summary-refer-thread
1940   "g" gnus-summary-show-article
1941   "s" gnus-summary-isearch-article
1942   "P" gnus-summary-print-article
1943   "M" gnus-mailing-list-insinuate
1944   "t" gnus-article-babel)
1945
1946 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1947   "b" gnus-article-add-buttons
1948   "B" gnus-article-add-buttons-to-head
1949   "o" gnus-article-treat-overstrike
1950   "e" gnus-article-emphasize
1951   "w" gnus-article-fill-cited-article
1952   "Q" gnus-article-fill-long-lines
1953   "C" gnus-article-capitalize-sentences
1954   "c" gnus-article-remove-cr
1955   "q" gnus-article-de-quoted-unreadable
1956   "6" gnus-article-de-base64-unreadable
1957   "Z" gnus-article-decode-HZ
1958   "A" gnus-article-treat-ansi-sequences
1959   "h" gnus-article-wash-html
1960   "u" gnus-article-unsplit-urls
1961   "s" gnus-summary-force-verify-and-decrypt
1962   "f" gnus-article-display-x-face
1963   "l" gnus-summary-stop-page-breaking
1964   "r" gnus-summary-caesar-message
1965   "m" gnus-summary-morse-message
1966   "t" gnus-summary-toggle-header
1967   "g" gnus-treat-smiley
1968   "v" gnus-summary-verbose-headers
1969   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1970   "p" gnus-article-verify-x-pgp-sig
1971   "d" gnus-article-treat-dumbquotes
1972   "i" gnus-summary-idna-message)
1973
1974 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1975   ;; mnemonic: deuglif*Y*
1976   "u" gnus-article-outlook-unwrap-lines
1977   "a" gnus-article-outlook-repair-attribution
1978   "c" gnus-article-outlook-rearrange-citation
1979   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1980
1981 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1982   "a" gnus-article-hide
1983   "h" gnus-article-hide-headers
1984   "b" gnus-article-hide-boring-headers
1985   "s" gnus-article-hide-signature
1986   "c" gnus-article-hide-citation
1987   "C" gnus-article-hide-citation-in-followups
1988   "l" gnus-article-hide-list-identifiers
1989   "B" gnus-article-strip-banner
1990   "P" gnus-article-hide-pem
1991   "\C-c" gnus-article-hide-citation-maybe)
1992
1993 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1994   "a" gnus-article-highlight
1995   "h" gnus-article-highlight-headers
1996   "c" gnus-article-highlight-citation
1997   "s" gnus-article-highlight-signature)
1998
1999 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2000   "f" gnus-article-treat-fold-headers
2001   "u" gnus-article-treat-unfold-headers
2002   "n" gnus-article-treat-fold-newsgroups)
2003
2004 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2005   "x" gnus-article-display-x-face
2006   "d" gnus-article-display-face
2007   "s" gnus-treat-smiley
2008   "D" gnus-article-remove-images
2009   "f" gnus-treat-from-picon
2010   "m" gnus-treat-mail-picon
2011   "n" gnus-treat-newsgroups-picon)
2012
2013 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2014   "w" gnus-article-decode-mime-words
2015   "c" gnus-article-decode-charset
2016   "v" gnus-mime-view-all-parts
2017   "b" gnus-article-view-part)
2018
2019 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2020   "z" gnus-article-date-ut
2021   "u" gnus-article-date-ut
2022   "l" gnus-article-date-local
2023   "p" gnus-article-date-english
2024   "e" gnus-article-date-lapsed
2025   "o" gnus-article-date-original
2026   "i" gnus-article-date-iso8601
2027   "s" gnus-article-date-user)
2028
2029 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2030   "t" gnus-article-remove-trailing-blank-lines
2031   "l" gnus-article-strip-leading-blank-lines
2032   "m" gnus-article-strip-multiple-blank-lines
2033   "a" gnus-article-strip-blank-lines
2034   "A" gnus-article-strip-all-blank-lines
2035   "s" gnus-article-strip-leading-space
2036   "e" gnus-article-strip-trailing-space
2037   "w" gnus-article-remove-leading-whitespace)
2038
2039 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2040   "v" gnus-version
2041   "f" gnus-summary-fetch-faq
2042   "d" gnus-summary-describe-group
2043   "h" gnus-summary-describe-briefly
2044   "i" gnus-info-find-node
2045   "c" gnus-group-fetch-charter
2046   "C" gnus-group-fetch-control)
2047
2048 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2049   "e" gnus-summary-expire-articles
2050   "\M-\C-e" gnus-summary-expire-articles-now
2051   "\177" gnus-summary-delete-article
2052   [delete] gnus-summary-delete-article
2053   [backspace] gnus-summary-delete-article
2054   "m" gnus-summary-move-article
2055   "r" gnus-summary-respool-article
2056   "w" gnus-summary-edit-article
2057   "c" gnus-summary-copy-article
2058   "B" gnus-summary-crosspost-article
2059   "q" gnus-summary-respool-query
2060   "t" gnus-summary-respool-trace
2061   "i" gnus-summary-import-article
2062   "I" gnus-summary-create-article
2063   "p" gnus-summary-article-posted-p)
2064
2065 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2066   "o" gnus-summary-save-article
2067   "m" gnus-summary-save-article-mail
2068   "F" gnus-summary-write-article-file
2069   "r" gnus-summary-save-article-rmail
2070   "f" gnus-summary-save-article-file
2071   "b" gnus-summary-save-article-body-file
2072   "h" gnus-summary-save-article-folder
2073   "v" gnus-summary-save-article-vm
2074   "p" gnus-summary-pipe-output
2075   "P" gnus-summary-muttprint
2076   "s" gnus-soup-add-article)
2077
2078 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2079   "b" gnus-summary-display-buttonized
2080   "m" gnus-summary-repair-multipart
2081   "v" gnus-article-view-part
2082   "o" gnus-article-save-part
2083   "O" gnus-article-save-part-and-strip
2084   "r" gnus-article-replace-part
2085   "d" gnus-article-delete-part
2086   "j" gnus-article-jump-to-part
2087   "c" gnus-article-copy-part
2088   "C" gnus-article-view-part-as-charset
2089   "e" gnus-article-view-part-externally
2090   "E" gnus-article-encrypt-body
2091   "i" gnus-article-inline-part
2092   "|" gnus-article-pipe-part)
2093
2094 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2095   "p" gnus-summary-mark-as-processable
2096   "u" gnus-summary-unmark-as-processable
2097   "U" gnus-summary-unmark-all-processable
2098   "v" gnus-uu-mark-over
2099   "s" gnus-uu-mark-series
2100   "r" gnus-uu-mark-region
2101   "g" gnus-uu-unmark-region
2102   "R" gnus-uu-mark-by-regexp
2103   "G" gnus-uu-unmark-by-regexp
2104   "t" gnus-uu-mark-thread
2105   "T" gnus-uu-unmark-thread
2106   "a" gnus-uu-mark-all
2107   "b" gnus-uu-mark-buffer
2108   "S" gnus-uu-mark-sparse
2109   "k" gnus-summary-kill-process-mark
2110   "y" gnus-summary-yank-process-mark
2111   "w" gnus-summary-save-process-mark
2112   "i" gnus-uu-invert-processable)
2113
2114 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2115   ;;"x" gnus-uu-extract-any
2116   "m" gnus-summary-save-parts
2117   "u" gnus-uu-decode-uu
2118   "U" gnus-uu-decode-uu-and-save
2119   "s" gnus-uu-decode-unshar
2120   "S" gnus-uu-decode-unshar-and-save
2121   "o" gnus-uu-decode-save
2122   "O" gnus-uu-decode-save
2123   "b" gnus-uu-decode-binhex
2124   "B" gnus-uu-decode-binhex
2125   "p" gnus-uu-decode-postscript
2126   "P" gnus-uu-decode-postscript-and-save)
2127
2128 (gnus-define-keys
2129     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2130   "u" gnus-uu-decode-uu-view
2131   "U" gnus-uu-decode-uu-and-save-view
2132   "s" gnus-uu-decode-unshar-view
2133   "S" gnus-uu-decode-unshar-and-save-view
2134   "o" gnus-uu-decode-save-view
2135   "O" gnus-uu-decode-save-view
2136   "b" gnus-uu-decode-binhex-view
2137   "B" gnus-uu-decode-binhex-view
2138   "p" gnus-uu-decode-postscript-view
2139   "P" gnus-uu-decode-postscript-and-save-view)
2140
2141 (defvar gnus-article-post-menu nil)
2142
2143 (defconst gnus-summary-menu-maxlen 20)
2144
2145 (defun gnus-summary-menu-split (menu)
2146   ;; If we have lots of elements, divide them into groups of 20
2147   ;; and make a pane (or submenu) for each one.
2148   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2149       (let ((menu menu) sublists next
2150             (i 1))
2151         (while menu
2152           ;; Pull off the next gnus-summary-menu-maxlen elements
2153           ;; and make them the next element of sublist.
2154           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2155           (if next
2156               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2157                       nil))
2158           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2159                                              (aref (car (last menu)) 0)) menu)
2160                                sublists))
2161           (setq i (1+ i))
2162           (setq menu next))
2163         (nreverse sublists))
2164     ;; Few elements--put them all in one pane.
2165     menu))
2166
2167 (defun gnus-summary-make-menu-bar ()
2168   (gnus-turn-off-edit-menu 'summary)
2169
2170   (unless (boundp 'gnus-summary-misc-menu)
2171
2172     (easy-menu-define
2173       gnus-summary-kill-menu gnus-summary-mode-map ""
2174       (cons
2175        "Score"
2176        (nconc
2177         (list
2178          ["Customize" gnus-score-customize t])
2179         (gnus-make-score-map 'increase)
2180         (gnus-make-score-map 'lower)
2181         '(("Mark"
2182            ["Kill below" gnus-summary-kill-below t]
2183            ["Mark above" gnus-summary-mark-above t]
2184            ["Tick above" gnus-summary-tick-above t]
2185            ["Clear above" gnus-summary-clear-above t])
2186           ["Current score" gnus-summary-current-score t]
2187           ["Set score" gnus-summary-set-score t]
2188           ["Switch current score file..." gnus-score-change-score-file t]
2189           ["Set mark below..." gnus-score-set-mark-below t]
2190           ["Set expunge below..." gnus-score-set-expunge-below t]
2191           ["Edit current score file" gnus-score-edit-current-scores t]
2192           ["Edit score file" gnus-score-edit-file t]
2193           ["Trace score" gnus-score-find-trace t]
2194           ["Find words" gnus-score-find-favourite-words t]
2195           ["Rescore buffer" gnus-summary-rescore t]
2196           ["Increase score..." gnus-summary-increase-score t]
2197           ["Lower score..." gnus-summary-lower-score t]))))
2198
2199     ;; Define both the Article menu in the summary buffer and the
2200     ;; equivalent Commands menu in the article buffer here for
2201     ;; consistency.
2202     (let ((innards
2203            `(("Hide"
2204               ["All" gnus-article-hide t]
2205               ["Headers" gnus-article-hide-headers t]
2206               ["Signature" gnus-article-hide-signature t]
2207               ["Citation" gnus-article-hide-citation t]
2208               ["List identifiers" gnus-article-hide-list-identifiers t]
2209               ["Banner" gnus-article-strip-banner t]
2210               ["Boring headers" gnus-article-hide-boring-headers t])
2211              ("Highlight"
2212               ["All" gnus-article-highlight t]
2213               ["Headers" gnus-article-highlight-headers t]
2214               ["Signature" gnus-article-highlight-signature t]
2215               ["Citation" gnus-article-highlight-citation t])
2216              ("MIME"
2217               ["Words" gnus-article-decode-mime-words t]
2218               ["Charset" gnus-article-decode-charset t]
2219               ["QP" gnus-article-de-quoted-unreadable t]
2220               ["Base64" gnus-article-de-base64-unreadable t]
2221               ["View MIME buttons" gnus-summary-display-buttonized t]
2222               ["View all" gnus-mime-view-all-parts t]
2223               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2224               ["Encrypt body" gnus-article-encrypt-body
2225                :active (not (gnus-group-read-only-p))
2226                ,@(if (featurep 'xemacs) nil
2227                    '(:help "Encrypt the message body on disk"))]
2228               ["Extract all parts..." gnus-summary-save-parts t]
2229               ("Multipart"
2230                ["Repair multipart" gnus-summary-repair-multipart t]
2231                ["Pipe part..." gnus-article-pipe-part t]
2232                ["Inline part" gnus-article-inline-part t]
2233                ["Encrypt body" gnus-article-encrypt-body
2234                 :active (not (gnus-group-read-only-p))
2235                ,@(if (featurep 'xemacs) nil
2236                    '(:help "Encrypt the message body on disk"))]
2237                ["View part externally" gnus-article-view-part-externally t]
2238                ["View part with charset..." gnus-article-view-part-as-charset t]
2239                ["Copy part" gnus-article-copy-part t]
2240                ["Save part..." gnus-article-save-part t]
2241                ["View part" gnus-article-view-part t]))
2242              ("Date"
2243               ["Local" gnus-article-date-local t]
2244               ["ISO8601" gnus-article-date-iso8601 t]
2245               ["UT" gnus-article-date-ut t]
2246               ["Original" gnus-article-date-original t]
2247               ["Lapsed" gnus-article-date-lapsed t]
2248               ["User-defined" gnus-article-date-user t])
2249              ("Display"
2250               ["Remove images" gnus-article-remove-images t]
2251               ["Toggle smiley" gnus-treat-smiley t]
2252               ["Show X-Face" gnus-article-display-x-face t]
2253               ["Show picons in From" gnus-treat-from-picon t]
2254               ["Show picons in mail headers" gnus-treat-mail-picon t]
2255               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2256               ("View as different encoding"
2257                ,@(gnus-summary-menu-split
2258                   (mapcar
2259                    (lambda (cs)
2260                      ;; Since easymenu under Emacs doesn't allow
2261                      ;; lambda forms for menu commands, we should
2262                      ;; provide intern'ed function symbols.
2263                      (let ((command (intern (format "\
2264 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2265                        (fset command
2266                              `(lambda ()
2267                                 (interactive)
2268                                 (let ((gnus-summary-show-article-charset-alist
2269                                        '((1 . ,cs))))
2270                                   (gnus-summary-show-article 1))))
2271                        `[,(symbol-name cs) ,command t]))
2272                    (sort (if (fboundp 'coding-system-list)
2273                              (coding-system-list)
2274                            (mapcar 'car mm-mime-mule-charset-alist))
2275                          'string<)))))
2276              ("Washing"
2277               ("Remove Blanks"
2278                ["Leading" gnus-article-strip-leading-blank-lines t]
2279                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2280                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2281                ["All of the above" gnus-article-strip-blank-lines t]
2282                ["All" gnus-article-strip-all-blank-lines t]
2283                ["Leading space" gnus-article-strip-leading-space t]
2284                ["Trailing space" gnus-article-strip-trailing-space t]
2285                ["Leading space in headers"
2286                 gnus-article-remove-leading-whitespace t])
2287               ["Overstrike" gnus-article-treat-overstrike t]
2288               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2289               ["Emphasis" gnus-article-emphasize t]
2290               ["Word wrap" gnus-article-fill-cited-article t]
2291               ["Fill long lines" gnus-article-fill-long-lines t]
2292               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2293               ["Remove CR" gnus-article-remove-cr t]
2294               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2295               ["Base64" gnus-article-de-base64-unreadable t]
2296               ["Rot 13" gnus-summary-caesar-message
2297                ,@(if (featurep 'xemacs) '(t)
2298                    '(:help "\"Caesar rotate\" article by 13"))]
2299               ["De-IDNA" gnus-summary-idna-message t]
2300               ["Morse decode" gnus-summary-morse-message t]
2301               ["Unix pipe..." gnus-summary-pipe-message t]
2302               ["Add buttons" gnus-article-add-buttons t]
2303               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2304               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2305               ["Verbose header" gnus-summary-verbose-headers t]
2306               ["Toggle header" gnus-summary-toggle-header t]
2307               ["Unfold headers" gnus-article-treat-unfold-headers t]
2308               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2309               ["Html" gnus-article-wash-html t]
2310               ["Unsplit URLs" gnus-article-unsplit-urls t]
2311               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2312               ["Decode HZ" gnus-article-decode-HZ t]
2313               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2314               ("(Outlook) Deuglify"
2315                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2316                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2317                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2318                ["Full (Outlook) deuglify"
2319                 gnus-article-outlook-deuglify-article t])
2320               )
2321              ("Output"
2322               ["Save in default format..." gnus-summary-save-article
2323                ,@(if (featurep 'xemacs) '(t)
2324                    '(:help "Save article using default method"))]
2325               ["Save in file..." gnus-summary-save-article-file
2326                ,@(if (featurep 'xemacs) '(t)
2327                    '(:help "Save article in file"))]
2328               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2329               ["Save in MH folder..." gnus-summary-save-article-folder t]
2330               ["Save in VM folder..." gnus-summary-save-article-vm t]
2331               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2332               ["Save body in file..." gnus-summary-save-article-body-file t]
2333               ["Pipe through a filter..." gnus-summary-pipe-output t]
2334               ["Add to SOUP packet" gnus-soup-add-article t]
2335               ["Print with Muttprint..." gnus-summary-muttprint t]
2336               ["Print" gnus-summary-print-article
2337                ,@(if (featurep 'xemacs) '(t)
2338                    '(:help "Generate and print a PostScript image"))])
2339              ("Copy, move,... (Backend)"
2340               ,@(if (featurep 'xemacs) nil
2341                   '(:help "Copying, moving, expiring articles..."))
2342               ["Respool article..." gnus-summary-respool-article t]
2343               ["Move article..." gnus-summary-move-article
2344                (gnus-check-backend-function
2345                 'request-move-article gnus-newsgroup-name)]
2346               ["Copy article..." gnus-summary-copy-article t]
2347               ["Crosspost article..." gnus-summary-crosspost-article
2348                (gnus-check-backend-function
2349                 'request-replace-article gnus-newsgroup-name)]
2350               ["Import file..." gnus-summary-import-article
2351                (gnus-check-backend-function
2352                 'request-accept-article gnus-newsgroup-name)]
2353               ["Create article..." gnus-summary-create-article
2354                (gnus-check-backend-function
2355                 'request-accept-article gnus-newsgroup-name)]
2356               ["Check if posted" gnus-summary-article-posted-p t]
2357               ["Edit article" gnus-summary-edit-article
2358                (not (gnus-group-read-only-p))]
2359               ["Delete article" gnus-summary-delete-article
2360                (gnus-check-backend-function
2361                 'request-expire-articles gnus-newsgroup-name)]
2362               ["Query respool" gnus-summary-respool-query t]
2363               ["Trace respool" gnus-summary-respool-trace t]
2364               ["Delete expirable articles" gnus-summary-expire-articles-now
2365                (gnus-check-backend-function
2366                 'request-expire-articles gnus-newsgroup-name)])
2367              ("Extract"
2368               ["Uudecode" gnus-uu-decode-uu
2369                ,@(if (featurep 'xemacs) '(t)
2370                    '(:help "Decode uuencoded article(s)"))]
2371               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2372               ["Unshar" gnus-uu-decode-unshar t]
2373               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2374               ["Save" gnus-uu-decode-save t]
2375               ["Binhex" gnus-uu-decode-binhex t]
2376               ["Postscript" gnus-uu-decode-postscript t]
2377               ["All MIME parts" gnus-summary-save-parts t])
2378              ("Cache"
2379               ["Enter article" gnus-cache-enter-article t]
2380               ["Remove article" gnus-cache-remove-article t])
2381              ["Translate" gnus-article-babel t]
2382              ["Select article buffer" gnus-summary-select-article-buffer t]
2383              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2384              ["Isearch article..." gnus-summary-isearch-article t]
2385              ["Beginning of the article" gnus-summary-beginning-of-article t]
2386              ["End of the article" gnus-summary-end-of-article t]
2387              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2388              ["Fetch referenced articles" gnus-summary-refer-references t]
2389              ["Fetch current thread" gnus-summary-refer-thread t]
2390              ["Fetch article with id..." gnus-summary-refer-article t]
2391              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2392              ["Redisplay" gnus-summary-show-article t]
2393              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2394       (easy-menu-define
2395         gnus-summary-article-menu gnus-summary-mode-map ""
2396         (cons "Article" innards))
2397
2398       (if (not (keymapp gnus-summary-article-menu))
2399           (easy-menu-define
2400             gnus-article-commands-menu gnus-article-mode-map ""
2401             (cons "Commands" innards))
2402         ;; in Emacs, don't share menu.
2403         (setq gnus-article-commands-menu
2404               (copy-keymap gnus-summary-article-menu))
2405         (define-key gnus-article-mode-map [menu-bar commands]
2406           (cons "Commands" gnus-article-commands-menu))))
2407
2408     (easy-menu-define
2409       gnus-summary-thread-menu gnus-summary-mode-map ""
2410       '("Threads"
2411         ["Find all messages in thread" gnus-summary-refer-thread t]
2412         ["Toggle threading" gnus-summary-toggle-threads t]
2413         ["Hide threads" gnus-summary-hide-all-threads t]
2414         ["Show threads" gnus-summary-show-all-threads t]
2415         ["Hide thread" gnus-summary-hide-thread t]
2416         ["Show thread" gnus-summary-show-thread t]
2417         ["Go to next thread" gnus-summary-next-thread t]
2418         ["Go to previous thread" gnus-summary-prev-thread t]
2419         ["Go down thread" gnus-summary-down-thread t]
2420         ["Go up thread" gnus-summary-up-thread t]
2421         ["Top of thread" gnus-summary-top-thread t]
2422         ["Mark thread as read" gnus-summary-kill-thread t]
2423         ["Lower thread score" gnus-summary-lower-thread t]
2424         ["Raise thread score" gnus-summary-raise-thread t]
2425         ["Rethread current" gnus-summary-rethread-current t]))
2426
2427     (easy-menu-define
2428       gnus-summary-post-menu gnus-summary-mode-map ""
2429       `("Post"
2430         ["Send a message (mail or news)" gnus-summary-post-news
2431          ,@(if (featurep 'xemacs) '(t)
2432              '(:help "Compose a new message (mail or news)"))]
2433         ["Followup" gnus-summary-followup
2434          ,@(if (featurep 'xemacs) '(t)
2435              '(:help "Post followup to this article"))]
2436         ["Followup and yank" gnus-summary-followup-with-original
2437          ,@(if (featurep 'xemacs) '(t)
2438              '(:help "Post followup to this article, quoting its contents"))]
2439         ["Supersede article" gnus-summary-supersede-article t]
2440         ["Cancel article" gnus-summary-cancel-article
2441          ,@(if (featurep 'xemacs) '(t)
2442              '(:help "Cancel an article you posted"))]
2443         ["Reply" gnus-summary-reply t]
2444         ["Reply and yank" gnus-summary-reply-with-original t]
2445         ["Wide reply" gnus-summary-wide-reply t]
2446         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2447          ,@(if (featurep 'xemacs) '(t)
2448              '(:help "Mail a reply, quoting this article"))]
2449         ["Very wide reply" gnus-summary-very-wide-reply t]
2450         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2451          ,@(if (featurep 'xemacs) '(t)
2452              '(:help "Mail a very wide reply, quoting this article"))]
2453         ["Mail forward" gnus-summary-mail-forward t]
2454         ["Post forward" gnus-summary-post-forward t]
2455         ["Digest and mail" gnus-uu-digest-mail-forward t]
2456         ["Digest and post" gnus-uu-digest-post-forward t]
2457         ["Resend message" gnus-summary-resend-message t]
2458         ["Resend message edit" gnus-summary-resend-message-edit t]
2459         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2460         ["Send a mail" gnus-summary-mail-other-window t]
2461         ["Create a local message" gnus-summary-news-other-window t]
2462         ["Uuencode and post" gnus-uu-post-news
2463          ,@(if (featurep 'xemacs) '(t)
2464              '(:help "Post a uuencoded article"))]
2465         ["Followup via news" gnus-summary-followup-to-mail t]
2466         ["Followup via news and yank"
2467          gnus-summary-followup-to-mail-with-original t]
2468         ;;("Draft"
2469         ;;["Send" gnus-summary-send-draft t]
2470         ;;["Send bounced" gnus-resend-bounced-mail t])
2471         ))
2472
2473     (cond
2474      ((not (keymapp gnus-summary-post-menu))
2475       (setq gnus-article-post-menu gnus-summary-post-menu))
2476      ((not gnus-article-post-menu)
2477       ;; Don't share post menu.
2478       (setq gnus-article-post-menu
2479             (copy-keymap gnus-summary-post-menu))))
2480     (define-key gnus-article-mode-map [menu-bar post]
2481       (cons "Post" gnus-article-post-menu))
2482
2483     (easy-menu-define
2484       gnus-summary-misc-menu gnus-summary-mode-map ""
2485       `("Gnus"
2486         ("Mark Read"
2487          ["Mark as read" gnus-summary-mark-as-read-forward t]
2488          ["Mark same subject and select"
2489           gnus-summary-kill-same-subject-and-select t]
2490          ["Mark same subject" gnus-summary-kill-same-subject t]
2491          ["Catchup" gnus-summary-catchup
2492           ,@(if (featurep 'xemacs) '(t)
2493               '(:help "Mark unread articles in this group as read"))]
2494          ["Catchup all" gnus-summary-catchup-all t]
2495          ["Catchup to here" gnus-summary-catchup-to-here t]
2496          ["Catchup from here" gnus-summary-catchup-from-here t]
2497          ["Catchup region" gnus-summary-mark-region-as-read
2498           (gnus-mark-active-p)]
2499          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2500         ("Mark Various"
2501          ["Tick" gnus-summary-tick-article-forward t]
2502          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2503          ["Remove marks" gnus-summary-clear-mark-forward t]
2504          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2505          ["Set bookmark" gnus-summary-set-bookmark t]
2506          ["Remove bookmark" gnus-summary-remove-bookmark t])
2507         ("Limit to"
2508          ["Marks..." gnus-summary-limit-to-marks t]
2509          ["Subject..." gnus-summary-limit-to-subject t]
2510          ["Author..." gnus-summary-limit-to-author t]
2511          ["Recipient..." gnus-summary-limit-to-recipient t]
2512          ["Age..." gnus-summary-limit-to-age t]
2513          ["Extra..." gnus-summary-limit-to-extra t]
2514          ["Score..." gnus-summary-limit-to-score t]
2515          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2516          ["Unread" gnus-summary-limit-to-unread t]
2517          ["Unseen" gnus-summary-limit-to-unseen t]
2518          ["Replied" gnus-summary-limit-to-replied t]
2519          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2520          ["Next articles" gnus-summary-limit-to-articles t]
2521          ["Pop limit" gnus-summary-pop-limit t]
2522          ["Show dormant" gnus-summary-limit-include-dormant t]
2523          ["Hide childless dormant"
2524           gnus-summary-limit-exclude-childless-dormant t]
2525          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2526          ["Hide marked" gnus-summary-limit-exclude-marks t]
2527          ["Show expunged" gnus-summary-limit-include-expunged t])
2528         ("Process Mark"
2529          ["Set mark" gnus-summary-mark-as-processable t]
2530          ["Remove mark" gnus-summary-unmark-as-processable t]
2531          ["Remove all marks" gnus-summary-unmark-all-processable t]
2532          ["Invert marks" gnus-uu-invert-processable t]
2533          ["Mark above" gnus-uu-mark-over t]
2534          ["Mark series" gnus-uu-mark-series t]
2535          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2536          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2537          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2538          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2539          ["Mark all" gnus-uu-mark-all t]
2540          ["Mark buffer" gnus-uu-mark-buffer t]
2541          ["Mark sparse" gnus-uu-mark-sparse t]
2542          ["Mark thread" gnus-uu-mark-thread t]
2543          ["Unmark thread" gnus-uu-unmark-thread t]
2544          ("Process Mark Sets"
2545           ["Kill" gnus-summary-kill-process-mark t]
2546           ["Yank" gnus-summary-yank-process-mark
2547            gnus-newsgroup-process-stack]
2548           ["Save" gnus-summary-save-process-mark t]
2549           ["Run command on marked..." gnus-summary-universal-argument t]))
2550         ("Scroll article"
2551          ["Page forward" gnus-summary-next-page
2552           ,@(if (featurep 'xemacs) '(t)
2553               '(:help "Show next page of article"))]
2554          ["Page backward" gnus-summary-prev-page
2555           ,@(if (featurep 'xemacs) '(t)
2556               '(:help "Show previous page of article"))]
2557          ["Line forward" gnus-summary-scroll-up t])
2558         ("Move"
2559          ["Next unread article" gnus-summary-next-unread-article t]
2560          ["Previous unread article" gnus-summary-prev-unread-article t]
2561          ["Next article" gnus-summary-next-article t]
2562          ["Previous article" gnus-summary-prev-article t]
2563          ["Next unread subject" gnus-summary-next-unread-subject t]
2564          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2565          ["Next article same subject" gnus-summary-next-same-subject t]
2566          ["Previous article same subject" gnus-summary-prev-same-subject t]
2567          ["First unread article" gnus-summary-first-unread-article t]
2568          ["Best unread article" gnus-summary-best-unread-article t]
2569          ["Go to subject number..." gnus-summary-goto-subject t]
2570          ["Go to article number..." gnus-summary-goto-article t]
2571          ["Go to the last article" gnus-summary-goto-last-article t]
2572          ["Pop article off history" gnus-summary-pop-article t])
2573         ("Sort"
2574          ["Sort by number" gnus-summary-sort-by-number t]
2575          ["Sort by author" gnus-summary-sort-by-author t]
2576          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2577          ["Sort by subject" gnus-summary-sort-by-subject t]
2578          ["Sort by date" gnus-summary-sort-by-date t]
2579          ["Sort by score" gnus-summary-sort-by-score t]
2580          ["Sort by lines" gnus-summary-sort-by-lines t]
2581          ["Sort by characters" gnus-summary-sort-by-chars t]
2582          ["Randomize" gnus-summary-sort-by-random t]
2583          ["Original sort" gnus-summary-sort-by-original t])
2584         ("Help"
2585          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2586          ["Describe group" gnus-summary-describe-group t]
2587          ["Fetch charter" gnus-group-fetch-charter
2588           ,@(if (featurep 'xemacs) nil
2589               '(:help "Display the charter of the current group"))]
2590          ["Fetch control message" gnus-group-fetch-control
2591           ,@(if (featurep 'xemacs) nil
2592               '(:help "Display the archived control message for the current group"))]
2593          ["Read manual" gnus-info-find-node t])
2594         ("Modes"
2595          ["Pick and read" gnus-pick-mode t]
2596          ["Binary" gnus-binary-mode t])
2597         ("Regeneration"
2598          ["Regenerate" gnus-summary-prepare t]
2599          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2600          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2601          ["Toggle threading" gnus-summary-toggle-threads t])
2602         ["See old articles" gnus-summary-insert-old-articles t]
2603         ["See new articles" gnus-summary-insert-new-articles t]
2604         ["Filter articles..." gnus-summary-execute-command t]
2605         ["Run command on articles..." gnus-summary-universal-argument t]
2606         ["Search articles forward..." gnus-summary-search-article-forward t]
2607         ["Search articles backward..." gnus-summary-search-article-backward t]
2608         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2609         ["Expand window" gnus-summary-expand-window t]
2610         ["Expire expirable articles" gnus-summary-expire-articles
2611          (gnus-check-backend-function
2612           'request-expire-articles gnus-newsgroup-name)]
2613         ["Edit local kill file" gnus-summary-edit-local-kill t]
2614         ["Edit main kill file" gnus-summary-edit-global-kill t]
2615         ["Edit group parameters" gnus-summary-edit-parameters t]
2616         ["Customize group parameters" gnus-summary-customize-parameters t]
2617         ["Send a bug report" gnus-bug t]
2618         ("Exit"
2619          ["Catchup and exit" gnus-summary-catchup-and-exit
2620           ,@(if (featurep 'xemacs) '(t)
2621               '(:help "Mark unread articles in this group as read, then exit"))]
2622          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2623          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2624          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2625          ["Exit group" gnus-summary-exit
2626           ,@(if (featurep 'xemacs) '(t)
2627               '(:help "Exit current group, return to group selection mode"))]
2628          ["Exit group without updating" gnus-summary-exit-no-update t]
2629          ["Exit and goto next group" gnus-summary-next-group t]
2630          ["Exit and goto prev group" gnus-summary-prev-group t]
2631          ["Reselect group" gnus-summary-reselect-current-group t]
2632          ["Rescan group" gnus-summary-rescan-group t]
2633          ["Update dribble" gnus-summary-save-newsrc t])))
2634
2635     (gnus-run-hooks 'gnus-summary-menu-hook)))
2636
2637 (defvar gnus-summary-tool-bar-map nil)
2638
2639 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2640 ;; affect _new_ message buffers.  We might add a function that walks thru all
2641 ;; summary-mode buffers and force the update.
2642 (defun gnus-summary-tool-bar-update (&optional symbol value)
2643   "Update summary mode toolbar.
2644 Setter function for custom variables."
2645   (setq-default gnus-summary-tool-bar-map nil)
2646   (when symbol
2647     ;; When used as ":set" function:
2648     (set-default symbol value))
2649   (when (gnus-buffer-live-p gnus-summary-buffer)
2650     (with-current-buffer gnus-summary-buffer
2651       (gnus-summary-make-tool-bar))))
2652
2653 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2654                                      'gnus-summary-tool-bar-gnome
2655                                    'gnus-summary-tool-bar-retro)
2656   "Specifies the Gnus summary tool bar.
2657
2658 It can be either a list or a symbol refering to a list.  See
2659 `gmm-tool-bar-from-list' for the format of the list.  The
2660 default key map is `gnus-summary-mode-map'.
2661
2662 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2663 `gnus-summary-tool-bar-retro'."
2664   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2665                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2666                  (repeat :tag "User defined list" gmm-tool-bar-item)
2667                  (symbol))
2668   :version "23.0" ;; No Gnus
2669   :initialize 'custom-initialize-default
2670   :set 'gnus-summary-tool-bar-update
2671   :group 'gnus-summary)
2672
2673 (defcustom gnus-summary-tool-bar-gnome
2674   '((gnus-summary-post-news "mail/compose" nil)
2675     (gnus-summary-insert-new-articles "mail/inbox" nil
2676                                       :visible (or (not gnus-agent)
2677                                                    gnus-plugged))
2678     (gnus-summary-reply-with-original "mail/reply")
2679     (gnus-summary-reply "mail/reply" nil :visible nil)
2680     (gnus-summary-followup-with-original "mail/reply-all")
2681     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2682     (gnus-summary-mail-forward "mail/forward")
2683     (gnus-summary-save-article "mail/save")
2684     (gnus-summary-search-article-forward "search" nil :visible nil)
2685     (gnus-summary-print-article "print")
2686     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2687     ;; Some new commands that may need more suitable icons:
2688     (gnus-summary-save-newsrc "save" nil :visible nil)
2689     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2690     (gnus-summary-prev-article "left-arrow")
2691     (gnus-summary-next-article "right-arrow")
2692     (gnus-summary-next-page "next-page")
2693     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2694     ;;
2695     ;; Maybe some sort-by-... could be added:
2696     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2697     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2698     (gnus-summary-mark-as-expirable
2699      "delete" nil
2700      :visible (gnus-check-backend-function 'request-expire-articles
2701                                            gnus-newsgroup-name))
2702     (gnus-summary-mark-as-spam
2703      "mail/spam" t
2704      :visible (and (fboundp 'spam-group-ham-contents-p)
2705                    (spam-group-ham-contents-p gnus-newsgroup-name))
2706      :help "Mark as spam")
2707     (gnus-summary-mark-as-read-forward
2708      "mail/not-spam" nil
2709      :visible (and (fboundp 'spam-group-spam-contents-p)
2710                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2711     ;;
2712     (gnus-summary-exit "exit")
2713     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2714     (gnus-info-find-node "help"))
2715   "List of functions for the summary tool bar (GNOME style).
2716
2717 See `gmm-tool-bar-from-list' for the format of the list."
2718   :type '(repeat gmm-tool-bar-item)
2719   :version "23.0" ;; No Gnus
2720   :initialize 'custom-initialize-default
2721   :set 'gnus-summary-tool-bar-update
2722   :group 'gnus-summary)
2723
2724 (defcustom gnus-summary-tool-bar-retro
2725   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2726     (gnus-summary-next-unread-article "gnus/next-ur")
2727     (gnus-summary-post-news "gnus/post")
2728     (gnus-summary-followup-with-original "gnus/fuwo")
2729     (gnus-summary-followup "gnus/followup")
2730     (gnus-summary-reply-with-original "gnus/reply-wo")
2731     (gnus-summary-reply "gnus/reply")
2732     (gnus-summary-caesar-message "gnus/rot13")
2733     (gnus-uu-decode-uu "gnus/uu-decode")
2734     (gnus-summary-save-article-file "gnus/save-aif")
2735     (gnus-summary-save-article "gnus/save-art")
2736     (gnus-uu-post-news "gnus/uu-post")
2737     (gnus-summary-catchup "gnus/catchup")
2738     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2739     (gnus-summary-exit "gnus/exit-summ")
2740     ;; Some new command that may need more suitable icons:
2741     (gnus-summary-print-article "gnus/print" nil :visible nil)
2742     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2743     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2744     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2745     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2746     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2747     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2748     ;;
2749     (gnus-info-find-node "gnus/help" nil :visible nil))
2750   "List of functions for the summary tool bar (retro look).
2751
2752 See `gmm-tool-bar-from-list' for the format of the list."
2753   :type '(repeat gmm-tool-bar-item)
2754   :version "23.0" ;; No Gnus
2755   :initialize 'custom-initialize-default
2756   :set 'gnus-summary-tool-bar-update
2757   :group 'gnus-summary)
2758
2759 (defcustom gnus-summary-tool-bar-zap-list t
2760   "List of icon items from the global tool bar.
2761 These items are not displayed in the Gnus summary mode tool bar.
2762
2763 See `gmm-tool-bar-from-list' for the format of the list."
2764   :type 'gmm-tool-bar-zap-list
2765   :version "23.0" ;; No Gnus
2766   :initialize 'custom-initialize-default
2767   :set 'gnus-summary-tool-bar-update
2768   :group 'gnus-summary)
2769
2770 (defvar image-load-path)
2771
2772 (defun gnus-summary-make-tool-bar (&optional force)
2773   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2774 When FORCE, rebuild the tool bar."
2775   (when (and (not (featurep 'xemacs))
2776              (boundp 'tool-bar-mode)
2777              tool-bar-mode
2778              (or (not gnus-summary-tool-bar-map) force))
2779     (let* ((load-path
2780             (gmm-image-load-path-for-library "gnus"
2781                                              "mail/save.xpm"
2782                                              nil t))
2783            (image-load-path (cons (car load-path)
2784                                   (when (boundp 'image-load-path)
2785                                     image-load-path)))
2786            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2787                                         gnus-summary-tool-bar-zap-list
2788                                         'gnus-summary-mode-map)))
2789       (when map
2790         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2791         ;; uses it's value.
2792         (setq gnus-summary-tool-bar-map map))))
2793   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2794
2795 (defun gnus-score-set-default (var value)
2796   "A version of set that updates the GNU Emacs menu-bar."
2797   (set var value)
2798   ;; It is the message that forces the active status to be updated.
2799   (message ""))
2800
2801 (defun gnus-make-score-map (type)
2802   "Make a summary score map of type TYPE."
2803   (if t
2804       nil
2805     (let ((headers '(("author" "from" string)
2806                      ("subject" "subject" string)
2807                      ("article body" "body" string)
2808                      ("article head" "head" string)
2809                      ("xref" "xref" string)
2810                      ("extra header" "extra" string)
2811                      ("lines" "lines" number)
2812                      ("followups to author" "followup" string)))
2813           (types '((number ("less than" <)
2814                            ("greater than" >)
2815                            ("equal" =))
2816                    (string ("substring" s)
2817                            ("exact string" e)
2818                            ("fuzzy string" f)
2819                            ("regexp" r))))
2820           (perms '(("temporary" (current-time-string))
2821                    ("permanent" nil)
2822                    ("immediate" now)))
2823           header)
2824       (list
2825        (apply
2826         'nconc
2827         (list
2828          (if (eq type 'lower)
2829              "Lower score"
2830            "Increase score"))
2831         (let (outh)
2832           (while headers
2833             (setq header (car headers))
2834             (setq outh
2835                   (cons
2836                    (apply
2837                     'nconc
2838                     (list (car header))
2839                     (let ((ts (cdr (assoc (nth 2 header) types)))
2840                           outt)
2841                       (while ts
2842                         (setq outt
2843                               (cons
2844                                (apply
2845                                 'nconc
2846                                 (list (caar ts))
2847                                 (let ((ps perms)
2848                                       outp)
2849                                   (while ps
2850                                     (setq outp
2851                                           (cons
2852                                            (vector
2853                                             (caar ps)
2854                                             (list
2855                                              'gnus-summary-score-entry
2856                                              (nth 1 header)
2857                                              (if (or (string= (nth 1 header)
2858                                                               "head")
2859                                                      (string= (nth 1 header)
2860                                                               "body"))
2861                                                  ""
2862                                                (list 'gnus-summary-header
2863                                                      (nth 1 header)))
2864                                              (list 'quote (nth 1 (car ts)))
2865                                              (list 'gnus-score-delta-default
2866                                                    nil)
2867                                              (nth 1 (car ps))
2868                                              t)
2869                                             t)
2870                                            outp))
2871                                     (setq ps (cdr ps)))
2872                                   (list (nreverse outp))))
2873                                outt))
2874                         (setq ts (cdr ts)))
2875                       (list (nreverse outt))))
2876                    outh))
2877             (setq headers (cdr headers)))
2878           (list (nreverse outh))))))))
2879
2880 \f
2881
2882 (defun gnus-summary-mode (&optional group)
2883   "Major mode for reading articles.
2884
2885 All normal editing commands are switched off.
2886 \\<gnus-summary-mode-map>
2887 Each line in this buffer represents one article.  To read an
2888 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2889 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2890 respectively.
2891
2892 You can also post articles and send mail from this buffer.  To
2893 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2894 of an article, type `\\[gnus-summary-reply]'.
2895
2896 There are approx. one gazillion commands you can execute in this
2897 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2898
2899 The following commands are available:
2900
2901 \\{gnus-summary-mode-map}"
2902   (interactive)
2903   (kill-all-local-variables)
2904   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2905     (gnus-summary-make-local-variables))
2906   (gnus-summary-make-local-variables)
2907   (setq gnus-newsgroup-name group)
2908   (when (gnus-visual-p 'summary-menu 'menu)
2909     (gnus-summary-make-menu-bar)
2910     (gnus-summary-make-tool-bar))
2911   (gnus-make-thread-indent-array)
2912   (gnus-simplify-mode-line)
2913   (setq major-mode 'gnus-summary-mode)
2914   (setq mode-name "Summary")
2915   (make-local-variable 'minor-mode-alist)
2916   (use-local-map gnus-summary-mode-map)
2917   (buffer-disable-undo)
2918   (setq buffer-read-only t              ;Disable modification
2919         show-trailing-whitespace nil)
2920   (setq truncate-lines t)
2921   (setq selective-display t)
2922   (setq selective-display-ellipses t)   ;Display `...'
2923   (gnus-summary-set-display-table)
2924   (gnus-set-default-directory)
2925   (make-local-variable 'gnus-summary-line-format)
2926   (make-local-variable 'gnus-summary-line-format-spec)
2927   (make-local-variable 'gnus-summary-dummy-line-format)
2928   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2929   (make-local-variable 'gnus-summary-mark-positions)
2930   (gnus-make-local-hook 'pre-command-hook)
2931   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2932   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2933   (turn-on-gnus-mailing-list-mode)
2934   (mm-enable-multibyte)
2935   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2936   (gnus-update-summary-mark-positions))
2937
2938 (defun gnus-summary-make-local-variables ()
2939   "Make all the local summary buffer variables."
2940   (let (global)
2941     (dolist (local gnus-summary-local-variables)
2942       (if (consp local)
2943           (progn
2944             (if (eq (cdr local) 'global)
2945                 ;; Copy the global value of the variable.
2946                 (setq global (symbol-value (car local)))
2947               ;; Use the value from the list.
2948               (setq global (eval (cdr local))))
2949             (set (make-local-variable (car local)) global))
2950         ;; Simple nil-valued local variable.
2951         (set (make-local-variable local) nil)))))
2952
2953 (defun gnus-summary-clear-local-variables ()
2954   (let ((locals gnus-summary-local-variables))
2955     (while locals
2956       (if (consp (car locals))
2957           (and (symbolp (caar locals))
2958                (set (caar locals) nil))
2959         (and (symbolp (car locals))
2960              (set (car locals) nil)))
2961       (setq locals (cdr locals)))))
2962
2963 ;; Summary data functions.
2964
2965 (defmacro gnus-data-number (data)
2966   `(car ,data))
2967
2968 (defmacro gnus-data-set-number (data number)
2969   `(setcar ,data ,number))
2970
2971 (defmacro gnus-data-mark (data)
2972   `(nth 1 ,data))
2973
2974 (defmacro gnus-data-set-mark (data mark)
2975   `(setcar (nthcdr 1 ,data) ,mark))
2976
2977 (defmacro gnus-data-pos (data)
2978   `(nth 2 ,data))
2979
2980 (defmacro gnus-data-set-pos (data pos)
2981   `(setcar (nthcdr 2 ,data) ,pos))
2982
2983 (defmacro gnus-data-header (data)
2984   `(nth 3 ,data))
2985
2986 (defmacro gnus-data-set-header (data header)
2987   `(setf (nth 3 ,data) ,header))
2988
2989 (defmacro gnus-data-level (data)
2990   `(nth 4 ,data))
2991
2992 (defmacro gnus-data-unread-p (data)
2993   `(= (nth 1 ,data) gnus-unread-mark))
2994
2995 (defmacro gnus-data-read-p (data)
2996   `(/= (nth 1 ,data) gnus-unread-mark))
2997
2998 (defmacro gnus-data-pseudo-p (data)
2999   `(consp (nth 3 ,data)))
3000
3001 (defmacro gnus-data-find (number)
3002   `(assq ,number gnus-newsgroup-data))
3003
3004 (defmacro gnus-data-find-list (number &optional data)
3005   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3006      (memq (assq ,number bdata)
3007            bdata)))
3008
3009 (defmacro gnus-data-make (number mark pos header level)
3010   `(list ,number ,mark ,pos ,header ,level))
3011
3012 (defun gnus-data-enter (after-article number mark pos header level offset)
3013   (let ((data (gnus-data-find-list after-article)))
3014     (unless data
3015       (error "No such article: %d" after-article))
3016     (setcdr data (cons (gnus-data-make number mark pos header level)
3017                        (cdr data)))
3018     (setq gnus-newsgroup-data-reverse nil)
3019     (gnus-data-update-list (cddr data) offset)))
3020
3021 (defun gnus-data-enter-list (after-article list &optional offset)
3022   (when list
3023     (let ((data (and after-article (gnus-data-find-list after-article)))
3024           (ilist list))
3025       (if (not (or data
3026                    after-article))
3027           (let ((odata gnus-newsgroup-data))
3028             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3029             (when offset
3030               (gnus-data-update-list odata offset)))
3031         ;; Find the last element in the list to be spliced into the main
3032         ;; list.
3033         (setq list (last list))
3034         (if (not data)
3035             (progn
3036               (setcdr list gnus-newsgroup-data)
3037               (setq gnus-newsgroup-data ilist)
3038               (when offset
3039                 (gnus-data-update-list (cdr list) offset)))
3040           (setcdr list (cdr data))
3041           (setcdr data ilist)
3042           (when offset
3043             (gnus-data-update-list (cdr list) offset))))
3044       (setq gnus-newsgroup-data-reverse nil))))
3045
3046 (defun gnus-data-remove (article &optional offset)
3047   (let ((data gnus-newsgroup-data))
3048     (if (= (gnus-data-number (car data)) article)
3049         (progn
3050           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3051                 gnus-newsgroup-data-reverse nil)
3052           (when offset
3053             (gnus-data-update-list gnus-newsgroup-data offset)))
3054       (while (cdr data)
3055         (when (= (gnus-data-number (cadr data)) article)
3056           (setcdr data (cddr data))
3057           (when offset
3058             (gnus-data-update-list (cdr data) offset))
3059           (setq data nil
3060                 gnus-newsgroup-data-reverse nil))
3061         (setq data (cdr data))))))
3062
3063 (defmacro gnus-data-list (backward)
3064   `(if ,backward
3065        (or gnus-newsgroup-data-reverse
3066            (setq gnus-newsgroup-data-reverse
3067                  (reverse gnus-newsgroup-data)))
3068      gnus-newsgroup-data))
3069
3070 (defun gnus-data-update-list (data offset)
3071   "Add OFFSET to the POS of all data entries in DATA."
3072   (setq gnus-newsgroup-data-reverse nil)
3073   (while data
3074     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3075     (setq data (cdr data))))
3076
3077 (defun gnus-summary-article-pseudo-p (article)
3078   "Say whether this article is a pseudo article or not."
3079   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3080
3081 (defmacro gnus-summary-article-sparse-p (article)
3082   "Say whether this article is a sparse article or not."
3083   `(memq ,article gnus-newsgroup-sparse))
3084
3085 (defmacro gnus-summary-article-ancient-p (article)
3086   "Say whether this article is a sparse article or not."
3087   `(memq ,article gnus-newsgroup-ancient))
3088
3089 (defun gnus-article-parent-p (number)
3090   "Say whether this article is a parent or not."
3091   (let ((data (gnus-data-find-list number)))
3092     (and (cdr data)              ; There has to be an article after...
3093          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3094             (gnus-data-level (nth 1 data))))))
3095
3096 (defun gnus-article-children (number)
3097   "Return a list of all children to NUMBER."
3098   (let* ((data (gnus-data-find-list number))
3099          (level (gnus-data-level (car data)))
3100          children)
3101     (setq data (cdr data))
3102     (while (and data
3103                 (= (gnus-data-level (car data)) (1+ level)))
3104       (push (gnus-data-number (car data)) children)
3105       (setq data (cdr data)))
3106     children))
3107
3108 (defmacro gnus-summary-skip-intangible ()
3109   "If the current article is intangible, then jump to a different article."
3110   '(let ((to (get-text-property (point) 'gnus-intangible)))
3111      (and to (gnus-summary-goto-subject to))))
3112
3113 (defmacro gnus-summary-article-intangible-p ()
3114   "Say whether this article is intangible or not."
3115   '(get-text-property (point) 'gnus-intangible))
3116
3117 (defun gnus-article-read-p (article)
3118   "Say whether ARTICLE is read or not."
3119   (not (or (memq article gnus-newsgroup-marked)
3120            (memq article gnus-newsgroup-spam-marked)
3121            (memq article gnus-newsgroup-unreads)
3122            (memq article gnus-newsgroup-unselected)
3123            (memq article gnus-newsgroup-dormant))))
3124
3125 ;; Some summary mode macros.
3126
3127 (defmacro gnus-summary-article-number ()
3128   "The article number of the article on the current line.
3129 If there isn't an article number here, then we return the current
3130 article number."
3131   '(progn
3132      (gnus-summary-skip-intangible)
3133      (or (get-text-property (point) 'gnus-number)
3134          (gnus-summary-last-subject))))
3135
3136 (defmacro gnus-summary-article-header (&optional number)
3137   "Return the header of article NUMBER."
3138   `(gnus-data-header (gnus-data-find
3139                       ,(or number '(gnus-summary-article-number)))))
3140
3141 (defmacro gnus-summary-thread-level (&optional number)
3142   "Return the level of thread that starts with article NUMBER."
3143   `(if (and (eq gnus-summary-make-false-root 'dummy)
3144             (get-text-property (point) 'gnus-intangible))
3145        0
3146      (gnus-data-level (gnus-data-find
3147                        ,(or number '(gnus-summary-article-number))))))
3148
3149 (defmacro gnus-summary-article-mark (&optional number)
3150   "Return the mark of article NUMBER."
3151   `(gnus-data-mark (gnus-data-find
3152                     ,(or number '(gnus-summary-article-number)))))
3153
3154 (defmacro gnus-summary-article-pos (&optional number)
3155   "Return the position of the line of article NUMBER."
3156   `(gnus-data-pos (gnus-data-find
3157                    ,(or number '(gnus-summary-article-number)))))
3158
3159 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3160 (defmacro gnus-summary-article-subject (&optional number)
3161   "Return current subject string or nil if nothing."
3162   `(let ((headers
3163           ,(if number
3164                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3165              '(gnus-data-header (assq (gnus-summary-article-number)
3166                                       gnus-newsgroup-data)))))
3167      (and headers
3168           (vectorp headers)
3169           (mail-header-subject headers))))
3170
3171 (defmacro gnus-summary-article-score (&optional number)
3172   "Return current article score."
3173   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3174                   gnus-newsgroup-scored))
3175        gnus-summary-default-score 0))
3176
3177 (defun gnus-summary-article-children (&optional number)
3178   "Return a list of article numbers that are children of article NUMBER."
3179   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3180          (level (gnus-data-level (car data)))
3181          l children)
3182     (while (and (setq data (cdr data))
3183                 (> (setq l (gnus-data-level (car data))) level))
3184       (and (= (1+ level) l)
3185            (push (gnus-data-number (car data))
3186                  children)))
3187     (nreverse children)))
3188
3189 (defun gnus-summary-article-parent (&optional number)
3190   "Return the article number of the parent of article NUMBER."
3191   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3192                                     (gnus-data-list t)))
3193          (level (gnus-data-level (car data))))
3194     (if (zerop level)
3195         ()                              ; This is a root.
3196       ;; We search until we find an article with a level less than
3197       ;; this one.  That function has to be the parent.
3198       (while (and (setq data (cdr data))
3199                   (not (< (gnus-data-level (car data)) level))))
3200       (and data (gnus-data-number (car data))))))
3201
3202 (defun gnus-unread-mark-p (mark)
3203   "Say whether MARK is the unread mark."
3204   (= mark gnus-unread-mark))
3205
3206 (defun gnus-read-mark-p (mark)
3207   "Say whether MARK is one of the marks that mark as read.
3208 This is all marks except unread, ticked, dormant, and expirable."
3209   (not (or (= mark gnus-unread-mark)
3210            (= mark gnus-ticked-mark)
3211            (= mark gnus-spam-mark)
3212            (= mark gnus-dormant-mark)
3213            (= mark gnus-expirable-mark))))
3214
3215 (defmacro gnus-article-mark (number)
3216   "Return the MARK of article NUMBER.
3217 This macro should only be used when computing the mark the \"first\"
3218 time; i.e., when generating the summary lines.  After that,
3219 `gnus-summary-article-mark' should be used to examine the
3220 marks of articles."
3221   `(cond
3222     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3223     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3224     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3225     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3226     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3227     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3228     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3229     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3230            gnus-ancient-mark))))
3231
3232 ;; Saving hidden threads.
3233
3234 (defmacro gnus-save-hidden-threads (&rest forms)
3235   "Save hidden threads, eval FORMS, and restore the hidden threads."
3236   (let ((config (make-symbol "config")))
3237     `(let ((,config (gnus-hidden-threads-configuration)))
3238        (unwind-protect
3239            (save-excursion
3240              ,@forms)
3241          (gnus-restore-hidden-threads-configuration ,config)))))
3242 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3243 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3244
3245 (defun gnus-data-compute-positions ()
3246   "Compute the positions of all articles."
3247   (setq gnus-newsgroup-data-reverse nil)
3248   (let ((data gnus-newsgroup-data))
3249     (save-excursion
3250       (gnus-save-hidden-threads
3251         (gnus-summary-show-all-threads)
3252         (goto-char (point-min))
3253         (while data
3254           (while (get-text-property (point) 'gnus-intangible)
3255             (forward-line 1))
3256           (gnus-data-set-pos (car data) (+ (point) 3))
3257           (setq data (cdr data))
3258           (forward-line 1))))))
3259
3260 (defun gnus-hidden-threads-configuration ()
3261   "Return the current hidden threads configuration."
3262   (save-excursion
3263     (let (config)
3264       (goto-char (point-min))
3265       (while (search-forward "\r" nil t)
3266         (push (1- (point)) config))
3267       config)))
3268
3269 (defun gnus-restore-hidden-threads-configuration (config)
3270   "Restore hidden threads configuration from CONFIG."
3271   (save-excursion
3272     (let (point buffer-read-only)
3273       (while (setq point (pop config))
3274         (when (and (< point (point-max))
3275                    (goto-char point)
3276                    (eq (char-after) ?\n))
3277           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3278
3279 ;; Various summary mode internalish functions.
3280
3281 (defun gnus-mouse-pick-article (e)
3282   (interactive "e")
3283   (mouse-set-point e)
3284   (gnus-summary-next-page nil t))
3285
3286 (defun gnus-summary-set-display-table ()
3287   "Change the display table.
3288 Odd characters have a tendency to mess
3289 up nicely formatted displays - we make all possible glyphs
3290 display only a single character."
3291
3292   ;; We start from the standard display table, if any.
3293   (let ((table (or (copy-sequence standard-display-table)
3294                    (make-display-table)))
3295         (i 32))
3296     ;; Nix out all the control chars...
3297     (while (>= (setq i (1- i)) 0)
3298       (aset table i [??]))
3299    ;; ... but not newline and cr, of course.  (cr is necessary for the
3300     ;; selective display).
3301     (aset table ?\n nil)
3302     (aset table ?\r nil)
3303     ;; We keep TAB as well.
3304     (aset table ?\t nil)
3305     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3306     ;; Emacs 23 (unicode), that are not set already.
3307     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3308                  160
3309                256)))
3310       (while (>= (setq i (1- i)) 127)
3311         ;; Only modify if the entry is nil.
3312         (unless (aref table i)
3313           (aset table i [??]))))
3314     (setq buffer-display-table table)))
3315
3316 (defun gnus-summary-set-article-display-arrow (pos)
3317   "Update the overlay arrow to point to line at position POS."
3318   (when (and gnus-summary-display-arrow
3319              (boundp 'overlay-arrow-position)
3320              (boundp 'overlay-arrow-string))
3321     (save-excursion
3322       (goto-char pos)
3323       (beginning-of-line)
3324       (unless overlay-arrow-position
3325         (setq overlay-arrow-position (make-marker)))
3326       (setq overlay-arrow-string "=>"
3327             overlay-arrow-position (set-marker overlay-arrow-position
3328                                                (point)
3329                                                (current-buffer))))))
3330
3331 (defun gnus-summary-setup-buffer (group)
3332   "Initialize summary buffer."
3333   (let ((buffer (gnus-summary-buffer-name group))
3334         (dead-name (concat "*Dead Summary "
3335                            (gnus-group-decoded-name group) "*")))
3336     ;; If a dead summary buffer exists, we kill it.
3337     (when (gnus-buffer-live-p dead-name)
3338       (gnus-kill-buffer dead-name))
3339     (if (get-buffer buffer)
3340         (progn
3341           (set-buffer buffer)
3342           (setq gnus-summary-buffer (current-buffer))
3343           (not gnus-newsgroup-prepared))
3344       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3345       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3346       (gnus-summary-mode group)
3347       (when gnus-carpal
3348         (gnus-carpal-setup-buffer 'summary))
3349       (unless gnus-single-article-buffer
3350         (make-local-variable 'gnus-article-buffer)
3351         (make-local-variable 'gnus-article-current)
3352         (make-local-variable 'gnus-original-article-buffer))
3353       (setq gnus-newsgroup-name group)
3354       ;; Set any local variables in the group parameters.
3355       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3356       t)))
3357
3358 (defun gnus-set-global-variables ()
3359   "Set the global equivalents of the buffer-local variables.
3360 They are set to the latest values they had.  These reflect the summary
3361 buffer that was in action when the last article was fetched."
3362   (when (eq major-mode 'gnus-summary-mode)
3363     (setq gnus-summary-buffer (current-buffer))
3364     (let ((name gnus-newsgroup-name)
3365           (marked gnus-newsgroup-marked)
3366           (spam gnus-newsgroup-spam-marked)
3367           (unread gnus-newsgroup-unreads)
3368           (headers gnus-current-headers)
3369           (data gnus-newsgroup-data)
3370           (summary gnus-summary-buffer)
3371           (article-buffer gnus-article-buffer)
3372           (original gnus-original-article-buffer)
3373           (gac gnus-article-current)
3374           (reffed gnus-reffed-article-number)
3375           (score-file gnus-current-score-file)
3376           (default-charset gnus-newsgroup-charset)
3377           vlist)
3378       (let ((locals gnus-newsgroup-variables))
3379         (while locals
3380           (if (consp (car locals))
3381               (push (eval (caar locals)) vlist)
3382             (push (eval (car locals)) vlist))
3383           (setq locals (cdr locals)))
3384         (setq vlist (nreverse vlist)))
3385       (with-current-buffer gnus-group-buffer
3386         (setq gnus-newsgroup-name name
3387               gnus-newsgroup-marked marked
3388               gnus-newsgroup-spam-marked spam
3389               gnus-newsgroup-unreads unread
3390               gnus-current-headers headers
3391               gnus-newsgroup-data data
3392               gnus-article-current gac
3393               gnus-summary-buffer summary
3394               gnus-article-buffer article-buffer
3395               gnus-original-article-buffer original
3396               gnus-reffed-article-number reffed
3397               gnus-current-score-file score-file
3398               gnus-newsgroup-charset default-charset)
3399         (let ((locals gnus-newsgroup-variables))
3400           (while locals
3401             (if (consp (car locals))
3402                 (set (caar locals) (pop vlist))
3403               (set (car locals) (pop vlist)))
3404             (setq locals (cdr locals))))
3405         ;; The article buffer also has local variables.
3406         (when (gnus-buffer-live-p gnus-article-buffer)
3407           (set-buffer gnus-article-buffer)
3408           (setq gnus-summary-buffer summary))))))
3409
3410 (defun gnus-summary-article-unread-p (article)
3411   "Say whether ARTICLE is unread or not."
3412   (memq article gnus-newsgroup-unreads))
3413
3414 (defun gnus-summary-first-article-p (&optional article)
3415   "Return whether ARTICLE is the first article in the buffer."
3416   (if (not (setq article (or article (gnus-summary-article-number))))
3417       nil
3418     (eq article (caar gnus-newsgroup-data))))
3419
3420 (defun gnus-summary-last-article-p (&optional article)
3421   "Return whether ARTICLE is the last article in the buffer."
3422   (if (not (setq article (or article (gnus-summary-article-number))))
3423       ;; All non-existent numbers are the last article.  :-)
3424       t
3425     (not (cdr (gnus-data-find-list article)))))
3426
3427 (defun gnus-make-thread-indent-array ()
3428   (let ((n 200))
3429     (unless (and gnus-thread-indent-array
3430                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3431       (setq gnus-thread-indent-array (make-vector 201 "")
3432             gnus-thread-indent-array-level gnus-thread-indent-level)
3433       (while (>= n 0)
3434         (aset gnus-thread-indent-array n
3435               (make-string (* n gnus-thread-indent-level) ? ))
3436         (setq n (1- n))))))
3437
3438 (defun gnus-update-summary-mark-positions ()
3439   "Compute where the summary marks are to go."
3440   (save-excursion
3441     (when (gnus-buffer-exists-p gnus-summary-buffer)
3442       (set-buffer gnus-summary-buffer))
3443     (let ((spec gnus-summary-line-format-spec)
3444           pos)
3445       (save-excursion
3446         (gnus-set-work-buffer)
3447         (let ((gnus-tmp-unread ?Z)
3448               (gnus-replied-mark ?Z)
3449               (gnus-score-below-mark ?Z)
3450               (gnus-score-over-mark ?Z)
3451               (gnus-undownloaded-mark ?Z)
3452               (gnus-summary-line-format-spec spec)
3453               (gnus-newsgroup-downloadable '(0))
3454               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3455               case-fold-search ignores)
3456           ;; Here, all marks are bound to Z.
3457           (gnus-summary-insert-line header
3458                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3459           (goto-char (point-min))
3460           ;; Memorize the positions of the same characters as dummy marks.
3461           (while (re-search-forward "[A-D]" nil t)
3462             (push (point) ignores))
3463           (erase-buffer)
3464           ;; We use A-D as dummy marks in order to know column positions
3465           ;; where marks should be inserted.
3466           (setq gnus-tmp-unread ?A
3467                 gnus-replied-mark ?B
3468                 gnus-score-below-mark ?C
3469                 gnus-score-over-mark ?C
3470                 gnus-undownloaded-mark ?D)
3471           (gnus-summary-insert-line header
3472                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3473           ;; Ignore characters which aren't dummy marks.
3474           (dolist (p ignores)
3475             (delete-region (goto-char (1- p)) p)
3476             (insert ?Z))
3477           (goto-char (point-min))
3478           (setq pos (list (cons 'unread
3479                                 (and (search-forward "A" nil t)
3480                                      (- (point) (point-min) 1)))))
3481           (goto-char (point-min))
3482           (push (cons 'replied (and (search-forward "B" nil t)
3483                                     (- (point) (point-min) 1)))
3484                 pos)
3485           (goto-char (point-min))
3486           (push (cons 'score (and (search-forward "C" nil t)
3487                                   (- (point) (point-min) 1)))
3488                 pos)
3489           (goto-char (point-min))
3490           (push (cons 'download (and (search-forward "D" nil t)
3491                                      (- (point) (point-min) 1)))
3492                 pos)))
3493       (setq gnus-summary-mark-positions pos))))
3494
3495 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3496   "Insert a dummy root in the summary buffer."
3497   (beginning-of-line)
3498   (gnus-add-text-properties
3499    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3500    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3501
3502 (defun gnus-summary-extract-address-component (from)
3503   (or (car (funcall gnus-extract-address-components from))
3504       from))
3505
3506 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3507   (let ((mail-parse-charset gnus-newsgroup-charset)
3508         ; Is it really necessary to do this next part for each summary line?
3509         ; Luckily, doesn't seem to slow things down much.
3510         (mail-parse-ignored-charsets
3511          (with-current-buffer gnus-summary-buffer
3512            gnus-newsgroup-ignored-charsets)))
3513     (or
3514      (and gnus-ignored-from-addresses
3515           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3516           (let ((extra-headers (mail-header-extra header))
3517                 to
3518                 newsgroups)
3519             (cond
3520              ((setq to (cdr (assq 'To extra-headers)))
3521               (concat gnus-summary-to-prefix
3522                       (inline
3523                         (gnus-summary-extract-address-component
3524                          (funcall gnus-decode-encoded-word-function to)))))
3525              ((setq newsgroups
3526                     (or
3527                      (cdr (assq 'Newsgroups extra-headers))
3528                      (and
3529                       (eq (car (gnus-find-method-for-group
3530                                 gnus-newsgroup-name)) 'nntp)
3531                       (gnus-group-real-name gnus-newsgroup-name))))
3532               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3533      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3534
3535 (defun gnus-summary-insert-line (gnus-tmp-header
3536                                  gnus-tmp-level gnus-tmp-current
3537                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3538                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3539                                  &optional gnus-tmp-dummy gnus-tmp-score
3540                                  gnus-tmp-process)
3541   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3542          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3543          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3544          (gnus-tmp-score-char
3545           (if (or (null gnus-summary-default-score)
3546                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3547                       gnus-summary-zcore-fuzz))
3548               ?                         ;Whitespace
3549             (if (< gnus-tmp-score gnus-summary-default-score)
3550                 gnus-score-below-mark gnus-score-over-mark)))
3551          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3552          (gnus-tmp-replied
3553           (cond (gnus-tmp-process gnus-process-mark)
3554                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3555                  gnus-cached-mark)
3556                 (gnus-tmp-replied gnus-replied-mark)
3557                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3558                  gnus-forwarded-mark)
3559                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3560                  gnus-saved-mark)
3561                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3562                  gnus-recent-mark)
3563                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3564                  gnus-unseen-mark)
3565                 (t gnus-no-mark)))
3566          (gnus-tmp-downloaded
3567           (cond (undownloaded
3568                  gnus-undownloaded-mark)
3569                 (gnus-newsgroup-agentized
3570                  gnus-downloaded-mark)
3571                 (t
3572                  gnus-no-mark)))
3573          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3574          (gnus-tmp-name
3575           (cond
3576            ((string-match "<[^>]+> *$" gnus-tmp-from)
3577             (let ((beg (match-beginning 0)))
3578               (or (and (string-match "^\".+\"" gnus-tmp-from)
3579                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3580                   (substring gnus-tmp-from 0 beg))))
3581            ((string-match "(.+)" gnus-tmp-from)
3582             (substring gnus-tmp-from
3583                        (1+ (match-beginning 0)) (1- (match-end 0))))
3584            (t gnus-tmp-from)))
3585          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3586          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3587          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3588          (buffer-read-only nil))
3589     (when (string= gnus-tmp-name "")
3590       (setq gnus-tmp-name gnus-tmp-from))
3591     (unless (numberp gnus-tmp-lines)
3592       (setq gnus-tmp-lines -1))
3593     (if (= gnus-tmp-lines -1)
3594         (setq gnus-tmp-lines "?")
3595       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3596       (gnus-put-text-property
3597      (point)
3598      (progn (eval gnus-summary-line-format-spec) (point))
3599        'gnus-number gnus-tmp-number)
3600     (when (gnus-visual-p 'summary-highlight 'highlight)
3601       (forward-line -1)
3602       (gnus-run-hooks 'gnus-summary-update-hook)
3603       (forward-line 1))))
3604
3605 (defun gnus-summary-update-line (&optional dont-update)
3606   "Update summary line after change."
3607   (when (and gnus-summary-default-score
3608              (not gnus-summary-inhibit-highlight))
3609     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3610            (article (gnus-summary-article-number))
3611            (score (gnus-summary-article-score article)))
3612       (unless dont-update
3613         (if (and gnus-summary-mark-below
3614                  (< (gnus-summary-article-score)
3615                     gnus-summary-mark-below))
3616             ;; This article has a low score, so we mark it as read.
3617             (when (memq article gnus-newsgroup-unreads)
3618               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3619           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3620             ;; This article was previously marked as read on account
3621             ;; of a low score, but now it has risen, so we mark it as
3622             ;; unread.
3623             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3624         (gnus-summary-update-mark
3625          (if (or (null gnus-summary-default-score)
3626                  (<= (abs (- score gnus-summary-default-score))
3627                      gnus-summary-zcore-fuzz))
3628              ?                          ;Whitespace
3629            (if (< score gnus-summary-default-score)
3630                gnus-score-below-mark gnus-score-over-mark))
3631          'score))
3632       ;; Do visual highlighting.
3633       (when (gnus-visual-p 'summary-highlight 'highlight)
3634         (gnus-run-hooks 'gnus-summary-update-hook)))))
3635
3636 (defvar gnus-tmp-new-adopts nil)
3637
3638 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3639   "Return the number of articles in THREAD.
3640 This may be 0 in some cases -- if none of the articles in
3641 the thread are to be displayed."
3642   (let* ((number
3643          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3644           (cond
3645            ((not (listp thread))
3646             1)
3647            ((and (consp thread) (cdr thread))
3648             (apply
3649              '+ 1 (mapcar
3650                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3651            ((null thread)
3652             1)
3653            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3654             1)
3655            (t 0))))
3656     (when (and level (zerop level) gnus-tmp-new-adopts)
3657       (incf number
3658             (apply '+ (mapcar
3659                        'gnus-summary-number-of-articles-in-thread
3660                        gnus-tmp-new-adopts))))
3661     (if char
3662         (if (> number 1) gnus-not-empty-thread-mark
3663           gnus-empty-thread-mark)
3664       number)))
3665
3666 (defsubst gnus-summary-line-message-size (head)
3667   "Return pretty-printed version of message size.
3668 This function is intended to be used in
3669 `gnus-summary-line-format-alist'."
3670   (let ((c (or (mail-header-chars head) -1)))
3671     (cond ((< c 0) "n/a")               ; chars not available
3672           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3673           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3674           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3675           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3676
3677
3678 (defun gnus-summary-set-local-parameters (group)
3679   "Go through the local params of GROUP and set all variable specs in that list."
3680   (let ((vars '(quit-config)))          ; Ignore quit-config.
3681     (dolist (elem (gnus-group-find-parameter group))
3682       (and (consp elem)                 ; Has to be a cons.
3683            (consp (cdr elem))           ; The cdr has to be a list.
3684            (symbolp (car elem))         ; Has to be a symbol in there.
3685            (not (memq (car elem) vars))
3686            (ignore-errors               ; So we set it.
3687              (push (car elem) vars)
3688              (make-local-variable (car elem))
3689              (set (car elem) (eval (nth 1 elem))))))))
3690
3691 (defun gnus-summary-read-group (group &optional show-all no-article
3692                                       kill-buffer no-display backward
3693                                       select-articles)
3694   "Start reading news in newsgroup GROUP.
3695 If SHOW-ALL is non-nil, already read articles are also listed.
3696 If NO-ARTICLE is non-nil, no article is selected initially.
3697 If NO-DISPLAY, don't generate a summary buffer."
3698   (let (result)
3699     (while (and group
3700                 (null (setq result
3701                             (let ((gnus-auto-select-next nil))
3702                               (or (gnus-summary-read-group-1
3703                                    group show-all no-article
3704                                    kill-buffer no-display
3705                                    select-articles)
3706                                   (setq show-all nil
3707                                         select-articles nil)))))
3708                 (eq gnus-auto-select-next 'quietly))
3709       (set-buffer gnus-group-buffer)
3710       ;; The entry function called above goes to the next
3711       ;; group automatically, so we go two groups back
3712       ;; if we are searching for the previous group.
3713       (when backward
3714         (gnus-group-prev-unread-group 2))
3715       (if (not (equal group (gnus-group-group-name)))
3716           (setq group (gnus-group-group-name))
3717         (setq group nil)))
3718     result))
3719
3720 (defun gnus-summary-read-group-1 (group show-all no-article
3721                                         kill-buffer no-display
3722                                         &optional select-articles)
3723   ;; Killed foreign groups can't be entered.
3724   ;;  (when (and (not (gnus-group-native-p group))
3725   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3726   ;;    (error "Dead non-native groups can't be entered"))
3727   (gnus-message 5 "Retrieving newsgroup: %s..."
3728                 (gnus-group-decoded-name group))
3729   (let* ((new-group (gnus-summary-setup-buffer group))
3730          (quit-config (gnus-group-quit-config group))
3731          (did-select (and new-group (gnus-select-newsgroup
3732                                      group show-all select-articles))))
3733     (cond
3734      ;; This summary buffer exists already, so we just select it.
3735      ((not new-group)
3736       (gnus-set-global-variables)
3737       (when kill-buffer
3738         (gnus-kill-or-deaden-summary kill-buffer))
3739       (gnus-configure-windows 'summary 'force)
3740       (gnus-set-mode-line 'summary)
3741       (gnus-summary-position-point)
3742       (message "")
3743       t)
3744      ;; We couldn't select this group.
3745      ((null did-select)
3746       (when (and (eq major-mode 'gnus-summary-mode)
3747                  (not (equal (current-buffer) kill-buffer)))
3748         (kill-buffer (current-buffer))
3749         (if (not quit-config)
3750             (progn
3751               ;; Update the info -- marks might need to be removed,
3752               ;; for instance.
3753               (gnus-summary-update-info)
3754               (set-buffer gnus-group-buffer)
3755               (gnus-group-jump-to-group group)
3756               (gnus-group-next-unread-group 1))
3757           (gnus-handle-ephemeral-exit quit-config)))
3758       (let ((grpinfo (gnus-get-info group)))
3759         (if (null (gnus-info-read grpinfo))
3760             (gnus-message 3 "Group %s contains no messages"
3761                           (gnus-group-decoded-name group))
3762           (gnus-message 3 "Can't select group")))
3763       nil)
3764      ;; The user did a `C-g' while prompting for number of articles,
3765      ;; so we exit this group.
3766      ((eq did-select 'quit)
3767       (and (eq major-mode 'gnus-summary-mode)
3768            (not (equal (current-buffer) kill-buffer))
3769            (kill-buffer (current-buffer)))
3770       (when kill-buffer
3771         (gnus-kill-or-deaden-summary kill-buffer))
3772       (if (not quit-config)
3773           (progn
3774             (set-buffer gnus-group-buffer)
3775             (gnus-group-jump-to-group group)
3776             (gnus-group-next-unread-group 1)
3777             (gnus-configure-windows 'group 'force))
3778         (gnus-handle-ephemeral-exit quit-config))
3779       ;; Finally signal the quit.
3780       (signal 'quit nil))
3781      ;; The group was successfully selected.
3782      (t
3783       (gnus-set-global-variables)
3784       ;; Save the active value in effect when the group was entered.
3785       (setq gnus-newsgroup-active
3786             (gnus-copy-sequence
3787              (gnus-active gnus-newsgroup-name)))
3788       ;; You can change the summary buffer in some way with this hook.
3789       (gnus-run-hooks 'gnus-select-group-hook)
3790       (when (memq 'summary (gnus-update-format-specifications
3791                             nil 'summary 'summary-mode 'summary-dummy))
3792         ;; The format specification for the summary line was updated,
3793         ;; so we need to update the mark positions as well.
3794         (gnus-update-summary-mark-positions))
3795       ;; Do score processing.
3796       (when gnus-use-scoring
3797         (gnus-possibly-score-headers))
3798       ;; Check whether to fill in the gaps in the threads.
3799       (when gnus-build-sparse-threads
3800         (gnus-build-sparse-threads))
3801       ;; Find the initial limit.
3802       (if show-all
3803           (let ((gnus-newsgroup-dormant nil))
3804             (gnus-summary-initial-limit show-all))
3805         (gnus-summary-initial-limit show-all))
3806       ;; Generate the summary buffer.
3807       (unless no-display
3808         (gnus-summary-prepare))
3809       (when gnus-use-trees
3810         (gnus-tree-open group)
3811         (setq gnus-summary-highlight-line-function
3812               'gnus-tree-highlight-article))
3813       ;; If the summary buffer is empty, but there are some low-scored
3814       ;; articles or some excluded dormants, we include these in the
3815       ;; buffer.
3816       (when (and (zerop (buffer-size))
3817                  (not no-display))
3818         (cond (gnus-newsgroup-dormant
3819                (gnus-summary-limit-include-dormant))
3820               ((and gnus-newsgroup-scored show-all)
3821                (gnus-summary-limit-include-expunged t))))
3822       ;; Function `gnus-apply-kill-file' must be called in this hook.
3823       (gnus-run-hooks 'gnus-apply-kill-hook)
3824       (if (and (zerop (buffer-size))
3825                (not no-display))
3826           (progn
3827             ;; This newsgroup is empty.
3828             (gnus-summary-catchup-and-exit nil t)
3829             (gnus-message 6 "No unread news")
3830             (when kill-buffer
3831               (gnus-kill-or-deaden-summary kill-buffer))
3832             ;; Return nil from this function.
3833             nil)
3834         ;; Hide conversation thread subtrees.  We cannot do this in
3835         ;; gnus-summary-prepare-hook since kill processing may not
3836         ;; work with hidden articles.
3837         (gnus-summary-maybe-hide-threads)
3838         (when kill-buffer
3839           (gnus-kill-or-deaden-summary kill-buffer))
3840         (gnus-summary-auto-select-subject)
3841         ;; Show first unread article if requested.
3842         (if (and (not no-article)
3843                  (not no-display)
3844                  gnus-newsgroup-unreads
3845                  gnus-auto-select-first)
3846             (progn
3847               (gnus-configure-windows 'summary)
3848               (let ((art (gnus-summary-article-number)))
3849                 (unless (and (not gnus-plugged)
3850                              (or (memq art gnus-newsgroup-undownloaded)
3851                                  (memq art gnus-newsgroup-downloadable)))
3852                   (gnus-summary-goto-article art))))
3853           ;; Don't select any articles.
3854           (gnus-summary-position-point)
3855           (gnus-configure-windows 'summary 'force)
3856           (gnus-set-mode-line 'summary))
3857         (when (and gnus-auto-center-group
3858                    (get-buffer-window gnus-group-buffer t))
3859           ;; Gotta use windows, because recenter does weird stuff if
3860           ;; the current buffer ain't the displayed window.
3861           (let ((owin (selected-window)))
3862             (select-window (get-buffer-window gnus-group-buffer t))
3863             (when (gnus-group-goto-group group)
3864               (recenter))
3865             (select-window owin)))
3866         ;; Mark this buffer as "prepared".
3867         (setq gnus-newsgroup-prepared t)
3868         (gnus-run-hooks 'gnus-summary-prepared-hook)
3869         (unless (gnus-ephemeral-group-p group)
3870           (gnus-group-update-group group))
3871         t)))))
3872
3873 (defun gnus-summary-auto-select-subject ()
3874   "Select the subject line on initial group entry."
3875   (goto-char (point-min))
3876   (cond
3877    ((eq gnus-auto-select-subject 'best)
3878     (gnus-summary-best-unread-subject))
3879    ((eq gnus-auto-select-subject 'unread)
3880     (gnus-summary-first-unread-subject))
3881    ((eq gnus-auto-select-subject 'unseen)
3882     (gnus-summary-first-unseen-subject))
3883    ((eq gnus-auto-select-subject 'unseen-or-unread)
3884     (gnus-summary-first-unseen-or-unread-subject))
3885    ((eq gnus-auto-select-subject 'first)
3886     ;; Do nothing.
3887     )
3888    ((functionp gnus-auto-select-subject)
3889     (funcall gnus-auto-select-subject))))
3890
3891 (defun gnus-summary-prepare ()
3892   "Generate the summary buffer."
3893   (interactive)
3894   (let ((buffer-read-only nil))
3895     (erase-buffer)
3896     (setq gnus-newsgroup-data nil
3897           gnus-newsgroup-data-reverse nil)
3898     (gnus-run-hooks 'gnus-summary-generate-hook)
3899     ;; Generate the buffer, either with threads or without.
3900     (when gnus-newsgroup-headers
3901       (gnus-summary-prepare-threads
3902        (if gnus-show-threads
3903            (gnus-sort-gathered-threads
3904             (funcall gnus-summary-thread-gathering-function
3905                      (gnus-sort-threads
3906                       (gnus-cut-threads (gnus-make-threads)))))
3907          ;; Unthreaded display.
3908          (gnus-sort-articles gnus-newsgroup-headers))))
3909     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3910     ;; Call hooks for modifying summary buffer.
3911     (goto-char (point-min))
3912     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3913
3914 (defsubst gnus-general-simplify-subject (subject)
3915   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3916   (setq subject
3917         (cond
3918          ;; Truncate the subject.
3919          (gnus-simplify-subject-functions
3920           (gnus-map-function gnus-simplify-subject-functions subject))
3921          ((numberp gnus-summary-gather-subject-limit)
3922           (setq subject (gnus-simplify-subject-re subject))
3923           (if (> (length subject) gnus-summary-gather-subject-limit)
3924               (substring subject 0 gnus-summary-gather-subject-limit)
3925             subject))
3926          ;; Fuzzily simplify it.
3927          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3928           (gnus-simplify-subject-fuzzy subject))
3929          ;; Just remove the leading "Re:".
3930          (t
3931           (gnus-simplify-subject-re subject))))
3932
3933   (if (and gnus-summary-gather-exclude-subject
3934            (string-match gnus-summary-gather-exclude-subject subject))
3935       nil                         ; This article shouldn't be gathered
3936     subject))
3937
3938 (defun gnus-summary-simplify-subject-query ()
3939   "Query where the respool algorithm would put this article."
3940   (interactive)
3941   (gnus-summary-select-article)
3942   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3943
3944 (defun gnus-gather-threads-by-subject (threads)
3945   "Gather threads by looking at Subject headers."
3946   (if (not gnus-summary-make-false-root)
3947       threads
3948     (let ((hashtb (gnus-make-hashtable 1024))
3949           (prev threads)
3950           (result threads)
3951           subject hthread whole-subject)
3952       (while threads
3953         (setq subject (gnus-general-simplify-subject
3954                        (setq whole-subject (mail-header-subject
3955                                             (caar threads)))))
3956         (when subject
3957           (if (setq hthread (gnus-gethash subject hashtb))
3958               (progn
3959                 ;; We enter a dummy root into the thread, if we
3960                 ;; haven't done that already.
3961                 (unless (stringp (caar hthread))
3962                   (setcar hthread (list whole-subject (car hthread))))
3963                 ;; We add this new gathered thread to this gathered
3964                 ;; thread.
3965                 (setcdr (car hthread)
3966                         (nconc (cdar hthread) (list (car threads))))
3967                 ;; Remove it from the list of threads.
3968                 (setcdr prev (cdr threads))
3969                 (setq threads prev))
3970             ;; Enter this thread into the hash table.
3971             (gnus-sethash subject
3972                           (if gnus-summary-make-false-root-always
3973                               (progn
3974                                 ;; If you want a dummy root above all
3975                                 ;; threads...
3976                                 (setcar threads (list whole-subject
3977                                                       (car threads)))
3978                                 threads)
3979                             threads)
3980                           hashtb)))
3981         (setq prev threads)
3982         (setq threads (cdr threads)))
3983       result)))
3984
3985 (defun gnus-gather-threads-by-references (threads)
3986   "Gather threads by looking at References headers."
3987   (let ((idhashtb (gnus-make-hashtable 1024))
3988         (thhashtb (gnus-make-hashtable 1024))
3989         (prev threads)
3990         (result threads)
3991         ids references id gthread gid entered ref)
3992     (while threads
3993       (when (setq references (mail-header-references (caar threads)))
3994         (setq id (mail-header-id (caar threads))
3995               ids (inline (gnus-split-references references))
3996               entered nil)
3997         (while (setq ref (pop ids))
3998           (setq ids (delete ref ids))
3999           (if (not (setq gid (gnus-gethash ref idhashtb)))
4000               (progn
4001                 (gnus-sethash ref id idhashtb)
4002                 (gnus-sethash id threads thhashtb))
4003             (setq gthread (gnus-gethash gid thhashtb))
4004             (unless entered
4005               ;; We enter a dummy root into the thread, if we
4006               ;; haven't done that already.
4007               (unless (stringp (caar gthread))
4008                 (setcar gthread (list (mail-header-subject (caar gthread))
4009                                       (car gthread))))
4010               ;; We add this new gathered thread to this gathered
4011               ;; thread.
4012               (setcdr (car gthread)
4013                       (nconc (cdar gthread) (list (car threads)))))
4014             ;; Add it into the thread hash table.
4015             (gnus-sethash id gthread thhashtb)
4016             (setq entered t)
4017             ;; Remove it from the list of threads.
4018             (setcdr prev (cdr threads))
4019             (setq threads prev))))
4020       (setq prev threads)
4021       (setq threads (cdr threads)))
4022     result))
4023
4024 (defun gnus-sort-gathered-threads (threads)
4025   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4026   (let ((result threads))
4027     (while threads
4028       (when (stringp (caar threads))
4029         (setcdr (car threads)
4030                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4031       (setq threads (cdr threads)))
4032     result))
4033
4034 (defun gnus-thread-loop-p (root thread)
4035   "Say whether ROOT is in THREAD."
4036   (let ((stack (list thread))
4037         (infloop 0)
4038         th)
4039     (while (setq thread (pop stack))
4040       (setq th (cdr thread))
4041       (while (and th
4042                   (not (eq (caar th) root)))
4043         (pop th))
4044       (if th
4045           ;; We have found a loop.
4046           (let (ref-dep)
4047             (setcdr thread (delq (car th) (cdr thread)))
4048             (if (boundp (setq ref-dep (intern "none"
4049                                               gnus-newsgroup-dependencies)))
4050                 (setcdr (symbol-value ref-dep)
4051                         (nconc (cdr (symbol-value ref-dep))
4052                                (list (car th))))
4053               (set ref-dep (list nil (car th))))
4054             (setq infloop 1
4055                   stack nil))
4056         ;; Push all the subthreads onto the stack.
4057         (push (cdr thread) stack)))
4058     infloop))
4059
4060 (defun gnus-make-threads ()
4061   "Go through the dependency hashtb and find the roots.  Return all threads."
4062   (let (threads)
4063     (while (catch 'infloop
4064              (mapatoms
4065               (lambda (refs)
4066                 ;; Deal with self-referencing References loops.
4067                 (when (and (car (symbol-value refs))
4068                            (not (zerop
4069                                  (apply
4070                                   '+
4071                                   (mapcar
4072                                    (lambda (thread)
4073                                      (gnus-thread-loop-p
4074                                       (car (symbol-value refs)) thread))
4075                                    (cdr (symbol-value refs)))))))
4076                   (setq threads nil)
4077                   (throw 'infloop t))
4078                 (unless (car (symbol-value refs))
4079                   ;; These threads do not refer back to any other
4080                   ;; articles, so they're roots.
4081                   (setq threads (append (cdr (symbol-value refs)) threads))))
4082               gnus-newsgroup-dependencies)))
4083     threads))
4084
4085 ;; Build the thread tree.
4086 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4087   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4088
4089 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4090 if it was already present.
4091
4092 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4093 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4094 Message-IDs will be renamed to a unique Message-ID before being
4095 entered.
4096
4097 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4098   (let* ((id (mail-header-id header))
4099          (id-dep (and id (intern id dependencies)))
4100          parent-id ref ref-dep ref-header replaced)
4101     ;; Enter this `header' in the `dependencies' table.
4102     (cond
4103      ((not id-dep)
4104       (setq header nil))
4105      ;; The first two cases do the normal part: enter a new `header'
4106      ;; in the `dependencies' table.
4107      ((not (boundp id-dep))
4108       (set id-dep (list header)))
4109      ((null (car (symbol-value id-dep)))
4110       (setcar (symbol-value id-dep) header))
4111
4112      ;; From here the `header' was already present in the
4113      ;; `dependencies' table.
4114      (force-new
4115       ;; Overrides an existing entry;
4116       ;; just set the header part of the entry.
4117       (setcar (symbol-value id-dep) header)
4118       (setq replaced t))
4119
4120      ;; Renames the existing `header' to a unique Message-ID.
4121      ((not gnus-summary-ignore-duplicates)
4122       ;; An article with this Message-ID has already been seen.
4123       ;; We rename the Message-ID.
4124       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4125            (list header))
4126       (mail-header-set-id header id))
4127
4128      ;; The last case ignores an existing entry, except it adds any
4129      ;; additional Xrefs (in case the two articles came from different
4130      ;; servers.
4131      ;; Also sets `header' to `nil' meaning that the `dependencies'
4132      ;; table was *not* modified.
4133      (t
4134       (mail-header-set-xref
4135        (car (symbol-value id-dep))
4136        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4137                    "")
4138                (or (mail-header-xref header) "")))
4139       (setq header nil)))
4140
4141     (when (and header (not replaced))
4142       ;; First check that we are not creating a References loop.
4143       (setq parent-id (gnus-parent-id (mail-header-references header)))
4144       (setq ref parent-id)
4145       (while (and ref
4146                   (setq ref-dep (intern-soft ref dependencies))
4147                   (boundp ref-dep)
4148                   (setq ref-header (car (symbol-value ref-dep))))
4149         (if (string= id ref)
4150             ;; Yuk!  This is a reference loop.  Make the article be a
4151             ;; root article.
4152             (progn
4153               (mail-header-set-references (car (symbol-value id-dep)) "none")
4154               (setq ref nil)
4155               (setq parent-id nil))
4156           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4157       (setq ref-dep (intern (or parent-id "none") dependencies))
4158       (if (boundp ref-dep)
4159           (setcdr (symbol-value ref-dep)
4160                   (nconc (cdr (symbol-value ref-dep))
4161                          (list (symbol-value id-dep))))
4162         (set ref-dep (list nil (symbol-value id-dep)))))
4163     header))
4164
4165 (defun gnus-extract-message-id-from-in-reply-to (string)
4166   (if (string-match "<[^>]+>" string)
4167       (substring string (match-beginning 0) (match-end 0))
4168     nil))
4169
4170 (defun gnus-build-sparse-threads ()
4171   (let ((headers gnus-newsgroup-headers)
4172         (mail-parse-charset gnus-newsgroup-charset)
4173         (gnus-summary-ignore-duplicates t)
4174         header references generation relations
4175         subject child end new-child date)
4176     ;; First we create an alist of generations/relations, where
4177     ;; generations is how much we trust the relation, and the relation
4178     ;; is parent/child.
4179     (gnus-message 7 "Making sparse threads...")
4180     (save-excursion
4181       (nnheader-set-temp-buffer " *gnus sparse threads*")
4182       (while (setq header (pop headers))
4183         (when (and (setq references (mail-header-references header))
4184                    (not (string= references "")))
4185           (insert references)
4186           (setq child (mail-header-id header)
4187                 subject (mail-header-subject header)
4188                 date (mail-header-date header)
4189                 generation 0)
4190           (while (search-backward ">" nil t)
4191             (setq end (1+ (point)))
4192             (when (search-backward "<" nil t)
4193               (setq new-child (buffer-substring (point) end))
4194               (push (list (incf generation)
4195                           child (setq child new-child)
4196                           subject date)
4197                     relations)))
4198           (when child
4199             (push (list (1+ generation) child nil subject) relations))
4200           (erase-buffer)))
4201       (kill-buffer (current-buffer)))
4202     ;; Sort over trustworthiness.
4203     (mapcar
4204      (lambda (relation)
4205        (when (gnus-dependencies-add-header
4206               (make-full-mail-header
4207                gnus-reffed-article-number
4208                (nth 3 relation) "" (or (nth 4 relation) "")
4209                (nth 1 relation)
4210                (or (nth 2 relation) "") 0 0 "")
4211               gnus-newsgroup-dependencies nil)
4212          (push gnus-reffed-article-number gnus-newsgroup-limit)
4213          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4214          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4215                gnus-newsgroup-reads)
4216          (decf gnus-reffed-article-number)))
4217      (sort relations 'car-less-than-car))
4218     (gnus-message 7 "Making sparse threads...done")))
4219
4220 (defun gnus-build-old-threads ()
4221   ;; Look at all the articles that refer back to old articles, and
4222   ;; fetch the headers for the articles that aren't there.  This will
4223   ;; build complete threads - if the roots haven't been expired by the
4224   ;; server, that is.
4225   (let ((mail-parse-charset gnus-newsgroup-charset)
4226         id heads)
4227     (mapatoms
4228      (lambda (refs)
4229        (when (not (car (symbol-value refs)))
4230          (setq heads (cdr (symbol-value refs)))
4231          (while heads
4232            (if (memq (mail-header-number (caar heads))
4233                      gnus-newsgroup-dormant)
4234                (setq heads (cdr heads))
4235              (setq id (symbol-name refs))
4236              (while (and (setq id (gnus-build-get-header id))
4237                          (not (car (gnus-id-to-thread id)))))
4238              (setq heads nil)))))
4239      gnus-newsgroup-dependencies)))
4240
4241 (defsubst gnus-remove-odd-characters (string)
4242   "Translate STRING into something that doesn't contain weird characters."
4243   (mm-subst-char-in-string
4244    ?\r ?\-
4245    (mm-subst-char-in-string ?\n ?\- string t) t))
4246
4247 ;; This function has to be called with point after the article number
4248 ;; on the beginning of the line.
4249 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4250   (let ((eol (point-at-eol))
4251         (buffer (current-buffer))
4252         header references in-reply-to)
4253
4254     ;; overview: [num subject from date id refs chars lines misc]
4255     (unwind-protect
4256         (let (x)
4257           (narrow-to-region (point) eol)
4258           (unless (eobp)
4259             (forward-char))
4260
4261           (setq header
4262                 (make-full-mail-header
4263                  number                 ; number
4264                  (condition-case ()     ; subject
4265                      (gnus-remove-odd-characters
4266                       (funcall gnus-decode-encoded-word-function
4267                                (setq x (nnheader-nov-field))))
4268                    (error x))
4269                  (condition-case ()     ; from
4270                      (gnus-remove-odd-characters
4271                       (funcall gnus-decode-encoded-word-function
4272                                (setq x (nnheader-nov-field))))
4273                    (error x))
4274                  (nnheader-nov-field)   ; date
4275                  (nnheader-nov-read-message-id number)  ; id
4276                  (setq references (nnheader-nov-field)) ; refs
4277                  (nnheader-nov-read-integer) ; chars
4278                  (nnheader-nov-read-integer) ; lines
4279                  (unless (eobp)
4280                    (if (looking-at "Xref: ")
4281                        (goto-char (match-end 0)))
4282                    (nnheader-nov-field)) ; Xref
4283                  (nnheader-nov-parse-extra)))) ; extra
4284
4285       (widen))
4286
4287     (when (and (string= references "")
4288                (setq in-reply-to (mail-header-extra header))
4289                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4290       (mail-header-set-references
4291        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4292
4293     (when gnus-alter-header-function
4294       (funcall gnus-alter-header-function header))
4295     (gnus-dependencies-add-header header dependencies force-new)))
4296
4297 (defun gnus-build-get-header (id)
4298   "Look through the buffer of NOV lines and find the header to ID.
4299 Enter this line into the dependencies hash table, and return
4300 the id of the parent article (if any)."
4301   (let ((deps gnus-newsgroup-dependencies)
4302         found header)
4303     (prog1
4304         (save-excursion
4305           (set-buffer nntp-server-buffer)
4306           (let ((case-fold-search nil))
4307             (goto-char (point-min))
4308             (while (and (not found)
4309                         (search-forward id nil t))
4310               (beginning-of-line)
4311               (setq found (looking-at
4312                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4313                                    (regexp-quote id))))
4314               (or found (beginning-of-line 2)))
4315             (when found
4316               (beginning-of-line)
4317               (and
4318                (setq header (gnus-nov-parse-line
4319                              (read (current-buffer)) deps))
4320                (gnus-parent-id (mail-header-references header))))))
4321       (when header
4322         (let ((number (mail-header-number header)))
4323           (push number gnus-newsgroup-limit)
4324           (push header gnus-newsgroup-headers)
4325           (if (memq number gnus-newsgroup-unselected)
4326               (progn
4327                 (setq gnus-newsgroup-unreads
4328                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4329                                                number))
4330                 (setq gnus-newsgroup-unselected
4331                       (delq number gnus-newsgroup-unselected)))
4332             (push number gnus-newsgroup-ancient)))))))
4333
4334 (defun gnus-build-all-threads ()
4335   "Read all the headers."
4336   (let ((gnus-summary-ignore-duplicates t)
4337         (mail-parse-charset gnus-newsgroup-charset)
4338         (dependencies gnus-newsgroup-dependencies)
4339         header article)
4340     (save-excursion
4341       (set-buffer nntp-server-buffer)
4342       (let ((case-fold-search nil))
4343         (goto-char (point-min))
4344         (while (not (eobp))
4345           (ignore-errors
4346             (setq article (read (current-buffer))
4347                   header (gnus-nov-parse-line article dependencies)))
4348           (when header
4349             (with-current-buffer gnus-summary-buffer
4350               (push header gnus-newsgroup-headers)
4351               (if (memq (setq article (mail-header-number header))
4352                         gnus-newsgroup-unselected)
4353                   (progn
4354                     (setq gnus-newsgroup-unreads
4355                           (gnus-add-to-sorted-list
4356                            gnus-newsgroup-unreads article))
4357                     (setq gnus-newsgroup-unselected
4358                           (delq article gnus-newsgroup-unselected)))
4359                 (push article gnus-newsgroup-ancient)))
4360             (forward-line 1)))))))
4361
4362 (defun gnus-summary-update-article-line (article header)
4363   "Update the line for ARTICLE using HEADER."
4364   (let* ((id (mail-header-id header))
4365          (thread (gnus-id-to-thread id)))
4366     (unless thread
4367       (error "Article in no thread"))
4368     ;; Update the thread.
4369     (setcar thread header)
4370     (gnus-summary-goto-subject article)
4371     (let* ((datal (gnus-data-find-list article))
4372            (data (car datal))
4373            (buffer-read-only nil)
4374            (level (gnus-summary-thread-level)))
4375       (gnus-delete-line)
4376       (let ((inserted (- (point)
4377                          (progn
4378                            (gnus-summary-insert-line
4379                             header level nil
4380                             (memq article gnus-newsgroup-undownloaded)
4381                             (gnus-article-mark article)
4382                             (memq article gnus-newsgroup-replied)
4383                             (memq article gnus-newsgroup-expirable)
4384                             ;; Only insert the Subject string when it's different
4385                             ;; from the previous Subject string.
4386                             (if (and
4387                                  gnus-show-threads
4388                                  (gnus-subject-equal
4389                                   (condition-case ()
4390                                       (mail-header-subject
4391                                        (gnus-data-header
4392                                         (cadr
4393                                          (gnus-data-find-list
4394                                           article
4395                                           (gnus-data-list t)))))
4396                                     ;; Error on the side of excessive subjects.
4397                                     (error ""))
4398                                   (mail-header-subject header)))
4399                                 ""
4400                               (mail-header-subject header))
4401                             nil (cdr (assq article gnus-newsgroup-scored))
4402                             (memq article gnus-newsgroup-processable))
4403                            (point)))))
4404         (when (cdr datal)
4405           (gnus-data-update-list
4406            (cdr datal)
4407            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4408
4409 (defun gnus-summary-update-article (article &optional iheader)
4410   "Update ARTICLE in the summary buffer."
4411   (set-buffer gnus-summary-buffer)
4412   (let* ((header (gnus-summary-article-header article))
4413          (id (mail-header-id header))
4414          (data (gnus-data-find article))
4415          (thread (gnus-id-to-thread id))
4416          (references (mail-header-references header))
4417          (parent
4418           (gnus-id-to-thread
4419            (or (gnus-parent-id
4420                 (when (and references
4421                            (not (equal "" references)))
4422                   references))
4423                "none")))
4424          (buffer-read-only nil)
4425          (old (car thread)))
4426     (when thread
4427       (unless iheader
4428         (setcar thread nil)
4429         (when parent
4430           (delq thread parent)))
4431       (if (gnus-summary-insert-subject id header)
4432           ;; Set the (possibly) new article number in the data structure.
4433           (gnus-data-set-number data (gnus-id-to-article id))
4434         (setcar thread old)
4435         nil))))
4436
4437 (defun gnus-rebuild-thread (id &optional line)
4438   "Rebuild the thread containing ID.
4439 If LINE, insert the rebuilt thread starting on line LINE."
4440   (let ((buffer-read-only nil)
4441         old-pos current thread data)
4442     (if (not gnus-show-threads)
4443         (setq thread (list (car (gnus-id-to-thread id))))
4444       ;; Get the thread this article is part of.
4445       (setq thread (gnus-remove-thread id)))
4446     (setq old-pos (point-at-bol))
4447     (setq current (save-excursion
4448                     (and (re-search-backward "[\r\n]" nil t)
4449                          (gnus-summary-article-number))))
4450     ;; If this is a gathered thread, we have to go some re-gathering.
4451     (when (stringp (car thread))
4452       (let ((subject (car thread))
4453             roots thr)
4454         (setq thread (cdr thread))
4455         (while thread
4456           (unless (memq (setq thr (gnus-id-to-thread
4457                                    (gnus-root-id
4458                                     (mail-header-id (caar thread)))))
4459                         roots)
4460             (push thr roots))
4461           (setq thread (cdr thread)))
4462         ;; We now have all (unique) roots.
4463         (if (= (length roots) 1)
4464             ;; All the loose roots are now one solid root.
4465             (setq thread (car roots))
4466           (setq thread (cons subject (gnus-sort-threads roots))))))
4467     (let (threads)
4468       ;; We then insert this thread into the summary buffer.
4469       (when line
4470         (goto-char (point-min))
4471         (forward-line (1- line)))
4472       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4473         (if gnus-show-threads
4474             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4475           (gnus-summary-prepare-unthreaded thread))
4476         (setq data (nreverse gnus-newsgroup-data))
4477         (setq threads gnus-newsgroup-threads))
4478       ;; We splice the new data into the data structure.
4479       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4480       ;;!!! then we want to insert at the beginning of the buffer.
4481       ;;!!! That happens to be true with Gnus now, but that may
4482       ;;!!! change in the future.  Perhaps.
4483       (gnus-data-enter-list
4484        (if line nil current) data (- (point) old-pos))
4485       (setq gnus-newsgroup-threads
4486             (nconc threads gnus-newsgroup-threads))
4487       (gnus-data-compute-positions))))
4488
4489 (defun gnus-number-to-header (number)
4490   "Return the header for article NUMBER."
4491   (let ((headers gnus-newsgroup-headers))
4492     (while (and headers
4493                 (not (= number (mail-header-number (car headers)))))
4494       (pop headers))
4495     (when headers
4496       (car headers))))
4497
4498 (defun gnus-parent-headers (in-headers &optional generation)
4499   "Return the headers of the GENERATIONeth parent of HEADERS."
4500   (unless generation
4501     (setq generation 1))
4502   (let ((parent t)
4503         (headers in-headers)
4504         references)
4505     (while (and parent
4506                 (not (zerop generation))
4507                 (setq references (mail-header-references headers)))
4508       (setq headers (if (and references
4509                              (setq parent (gnus-parent-id references)))
4510                         (car (gnus-id-to-thread parent))
4511                       nil))
4512       (decf generation))
4513     (and (not (eq headers in-headers))
4514          headers)))
4515
4516 (defun gnus-id-to-thread (id)
4517   "Return the (sub-)thread where ID appears."
4518   (gnus-gethash id gnus-newsgroup-dependencies))
4519
4520 (defun gnus-id-to-article (id)
4521   "Return the article number of ID."
4522   (let ((thread (gnus-id-to-thread id)))
4523     (when (and thread
4524                (car thread))
4525       (mail-header-number (car thread)))))
4526
4527 (defun gnus-id-to-header (id)
4528   "Return the article headers of ID."
4529   (car (gnus-id-to-thread id)))
4530
4531 (defun gnus-article-displayed-root-p (article)
4532   "Say whether ARTICLE is a root(ish) article."
4533   (let ((level (gnus-summary-thread-level article))
4534         (refs (mail-header-references  (gnus-summary-article-header article)))
4535         particle)
4536     (cond
4537      ((null level) nil)
4538      ((zerop level) t)
4539      ((null refs) t)
4540      ((null (gnus-parent-id refs)) t)
4541      ((and (= 1 level)
4542            (null (setq particle (gnus-id-to-article
4543                                  (gnus-parent-id refs))))
4544            (null (gnus-summary-thread-level particle)))))))
4545
4546 (defun gnus-root-id (id)
4547   "Return the id of the root of the thread where ID appears."
4548   (let (last-id prev)
4549     (while (and id (setq prev (car (gnus-id-to-thread id))))
4550       (setq last-id id
4551             id (gnus-parent-id (mail-header-references prev))))
4552     last-id))
4553
4554 (defun gnus-articles-in-thread (thread)
4555   "Return the list of articles in THREAD."
4556   (cons (mail-header-number (car thread))
4557         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4558
4559 (defun gnus-remove-thread (id &optional dont-remove)
4560   "Remove the thread that has ID in it."
4561   (let (headers thread last-id)
4562     ;; First go up in this thread until we find the root.
4563     (setq last-id (gnus-root-id id)
4564           headers (message-flatten-list (gnus-id-to-thread last-id)))
4565     ;; We have now found the real root of this thread.  It might have
4566     ;; been gathered into some loose thread, so we have to search
4567     ;; through the threads to find the thread we wanted.
4568     (let ((threads gnus-newsgroup-threads)
4569           sub)
4570       (while threads
4571         (setq sub (car threads))
4572         (if (stringp (car sub))
4573             ;; This is a gathered thread, so we look at the roots
4574             ;; below it to find whether this article is in this
4575             ;; gathered root.
4576             (progn
4577               (setq sub (cdr sub))
4578               (while sub
4579                 (when (member (caar sub) headers)
4580                   (setq thread (car threads)
4581                         threads nil
4582                         sub nil))
4583                 (setq sub (cdr sub))))
4584           ;; It's an ordinary thread, so we check it.
4585           (when (eq (car sub) (car headers))
4586             (setq thread sub
4587                   threads nil)))
4588         (setq threads (cdr threads)))
4589       ;; If this article is in no thread, then it's a root.
4590       (if thread
4591           (unless dont-remove
4592             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4593         (setq thread (gnus-id-to-thread last-id)))
4594       (when thread
4595         (prog1
4596             thread                      ; We return this thread.
4597           (unless dont-remove
4598             (if (stringp (car thread))
4599                 (progn
4600                   ;; If we use dummy roots, then we have to remove the
4601                   ;; dummy root as well.
4602                   (when (eq gnus-summary-make-false-root 'dummy)
4603                     ;; We go to the dummy root by going to
4604                     ;; the first sub-"thread", and then one line up.
4605                     (gnus-summary-goto-article
4606                      (mail-header-number (caadr thread)))
4607                     (forward-line -1)
4608                     (gnus-delete-line)
4609                     (gnus-data-compute-positions))
4610                   (setq thread (cdr thread))
4611                   (while thread
4612                     (gnus-remove-thread-1 (car thread))
4613                     (setq thread (cdr thread))))
4614               (gnus-remove-thread-1 thread))))))))
4615
4616 (defun gnus-remove-thread-1 (thread)
4617   "Remove the thread THREAD recursively."
4618   (let ((number (mail-header-number (pop thread)))
4619         d)
4620     (setq thread (reverse thread))
4621     (while thread
4622       (gnus-remove-thread-1 (pop thread)))
4623     (when (setq d (gnus-data-find number))
4624       (goto-char (gnus-data-pos d))
4625       (gnus-summary-show-thread)
4626       (gnus-data-remove
4627        number
4628        (- (point-at-bol)
4629           (prog1
4630               (1+ (point-at-eol))
4631             (gnus-delete-line)))))))
4632
4633 (defun gnus-sort-threads-1 (threads func)
4634   (sort (mapcar (lambda (thread)
4635                   (cons (car thread)
4636                         (and (cdr thread)
4637                              (gnus-sort-threads-1 (cdr thread) func))))
4638                 threads) func))
4639
4640 (defun gnus-sort-threads (threads)
4641   "Sort THREADS."
4642   (if (not gnus-thread-sort-functions)
4643       threads
4644     (gnus-message 8 "Sorting threads...")
4645     (let ((max-lisp-eval-depth 5000))
4646       (prog1 (gnus-sort-threads-1
4647          threads
4648          (gnus-make-sort-function gnus-thread-sort-functions))
4649         (gnus-message 8 "Sorting threads...done")))))
4650
4651 (defun gnus-sort-articles (articles)
4652   "Sort ARTICLES."
4653   (when gnus-article-sort-functions
4654     (gnus-message 7 "Sorting articles...")
4655     (prog1
4656         (setq gnus-newsgroup-headers
4657               (sort articles (gnus-make-sort-function
4658                               gnus-article-sort-functions)))
4659       (gnus-message 7 "Sorting articles...done"))))
4660
4661 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4662 (defmacro gnus-thread-header (thread)
4663   "Return header of first article in THREAD.
4664 Note that THREAD must never, ever be anything else than a variable -
4665 using some other form will lead to serious barfage."
4666   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4667   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4668   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4669         (vector thread) 2))
4670
4671 (defsubst gnus-article-sort-by-number (h1 h2)
4672   "Sort articles by article number."
4673   (< (mail-header-number h1)
4674      (mail-header-number h2)))
4675
4676 (defun gnus-thread-sort-by-number (h1 h2)
4677   "Sort threads by root article number."
4678   (gnus-article-sort-by-number
4679    (gnus-thread-header h1) (gnus-thread-header h2)))
4680
4681 (defsubst gnus-article-sort-by-random (h1 h2)
4682   "Sort articles by article number."
4683   (zerop (random 2)))
4684
4685 (defun gnus-thread-sort-by-random (h1 h2)
4686   "Sort threads by root article number."
4687   (gnus-article-sort-by-random
4688    (gnus-thread-header h1) (gnus-thread-header h2)))
4689
4690 (defsubst gnus-article-sort-by-lines (h1 h2)
4691   "Sort articles by article Lines header."
4692   (< (mail-header-lines h1)
4693      (mail-header-lines h2)))
4694
4695 (defun gnus-thread-sort-by-lines (h1 h2)
4696   "Sort threads by root article Lines header."
4697   (gnus-article-sort-by-lines
4698    (gnus-thread-header h1) (gnus-thread-header h2)))
4699
4700 (defsubst gnus-article-sort-by-chars (h1 h2)
4701   "Sort articles by octet length."
4702   (< (mail-header-chars h1)
4703      (mail-header-chars h2)))
4704
4705 (defun gnus-thread-sort-by-chars (h1 h2)
4706   "Sort threads by root article octet length."
4707   (gnus-article-sort-by-chars
4708    (gnus-thread-header h1) (gnus-thread-header h2)))
4709
4710 (defsubst gnus-article-sort-by-author (h1 h2)
4711   "Sort articles by root author."
4712   (string-lessp
4713    (let ((extract (funcall
4714                    gnus-extract-address-components
4715                    (mail-header-from h1))))
4716      (or (car extract) (cadr extract) ""))
4717    (let ((extract (funcall
4718                    gnus-extract-address-components
4719                    (mail-header-from h2))))
4720      (or (car extract) (cadr extract) ""))))
4721
4722 (defun gnus-thread-sort-by-author (h1 h2)
4723   "Sort threads by root author."
4724   (gnus-article-sort-by-author
4725    (gnus-thread-header h1)  (gnus-thread-header h2)))
4726
4727 (defsubst gnus-article-sort-by-recipient (h1 h2)
4728   "Sort articles by recipient."
4729   (string-lessp
4730    (let ((extract (funcall
4731                    gnus-extract-address-components
4732                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4733      (or (car extract) (cadr extract)))
4734    (let ((extract (funcall
4735                    gnus-extract-address-components
4736                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4737      (or (car extract) (cadr extract)))))
4738
4739 (defun gnus-thread-sort-by-recipient (h1 h2)
4740   "Sort threads by root recipient."
4741   (gnus-article-sort-by-recipient
4742    (gnus-thread-header h1) (gnus-thread-header h2)))
4743
4744 (defsubst gnus-article-sort-by-subject (h1 h2)
4745   "Sort articles by root subject."
4746   (string-lessp
4747    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4748    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4749
4750 (defun gnus-thread-sort-by-subject (h1 h2)
4751   "Sort threads by root subject."
4752   (gnus-article-sort-by-subject
4753    (gnus-thread-header h1) (gnus-thread-header h2)))
4754
4755 (defsubst gnus-article-sort-by-date (h1 h2)
4756   "Sort articles by root article date."
4757   (time-less-p
4758    (gnus-date-get-time (mail-header-date h1))
4759    (gnus-date-get-time (mail-header-date h2))))
4760
4761 (defun gnus-thread-sort-by-date (h1 h2)
4762   "Sort threads by root article date."
4763   (gnus-article-sort-by-date
4764    (gnus-thread-header h1) (gnus-thread-header h2)))
4765
4766 (defsubst gnus-article-sort-by-score (h1 h2)
4767   "Sort articles by root article score.
4768 Unscored articles will be counted as having a score of zero."
4769   (> (or (cdr (assq (mail-header-number h1)
4770                     gnus-newsgroup-scored))
4771          gnus-summary-default-score 0)
4772      (or (cdr (assq (mail-header-number h2)
4773                     gnus-newsgroup-scored))
4774          gnus-summary-default-score 0)))
4775
4776 (defun gnus-thread-sort-by-score (h1 h2)
4777   "Sort threads by root article score."
4778   (gnus-article-sort-by-score
4779    (gnus-thread-header h1) (gnus-thread-header h2)))
4780
4781 (defun gnus-thread-sort-by-total-score (h1 h2)
4782   "Sort threads by the sum of all scores in the thread.
4783 Unscored articles will be counted as having a score of zero."
4784   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4785
4786 (defun gnus-thread-total-score (thread)
4787   ;; This function find the total score of THREAD.
4788   (cond
4789    ((null thread)
4790     0)
4791    ((consp thread)
4792     (if (stringp (car thread))
4793         (apply gnus-thread-score-function 0
4794                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4795       (gnus-thread-total-score-1 thread)))
4796    (t
4797     (gnus-thread-total-score-1 (list thread)))))
4798
4799 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4800   "Sort threads such that the thread with the most recently arrived article comes first."
4801   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4802
4803 (defun gnus-thread-highest-number (thread)
4804   "Return the highest article number in THREAD."
4805   (apply 'max (mapcar (lambda (header)
4806                         (mail-header-number header))
4807                       (message-flatten-list thread))))
4808
4809 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4810   "Sort threads such that the thread with the most recently dated article comes first."
4811   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4812
4813 (defun gnus-thread-latest-date (thread)
4814   "Return the highest article date in THREAD."
4815   (let ((previous-time 0))
4816     (apply 'max
4817            (mapcar
4818             (lambda (header)
4819               (setq previous-time
4820                     (condition-case ()
4821                         (time-to-seconds (mail-header-parse-date
4822                                           (mail-header-date header)))
4823                       (error previous-time))))
4824             (sort
4825              (message-flatten-list thread)
4826              (lambda (h1 h2)
4827                (< (mail-header-number h1)
4828                   (mail-header-number h2))))))))
4829
4830 (defun gnus-thread-total-score-1 (root)
4831   ;; This function find the total score of the thread below ROOT.
4832   (setq root (car root))
4833   (apply gnus-thread-score-function
4834          (or (append
4835               (mapcar 'gnus-thread-total-score
4836                       (cdr (gnus-id-to-thread (mail-header-id root))))
4837               (when (> (mail-header-number root) 0)
4838                 (list (or (cdr (assq (mail-header-number root)
4839                                      gnus-newsgroup-scored))
4840                           gnus-summary-default-score 0))))
4841              (list gnus-summary-default-score)
4842              '(0))))
4843
4844 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4845 (defvar gnus-tmp-prev-subject nil)
4846 (defvar gnus-tmp-false-parent nil)
4847 (defvar gnus-tmp-root-expunged nil)
4848 (defvar gnus-tmp-dummy-line nil)
4849
4850 (eval-when-compile (defvar gnus-tmp-header))
4851 (defun gnus-extra-header (type &optional header)
4852   "Return the extra header of TYPE."
4853   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4854       ""))
4855
4856 (defvar gnus-tmp-thread-tree-header-string "")
4857
4858 (defcustom gnus-sum-thread-tree-root "> "
4859   "With %B spec, used for the root of a thread.
4860 If nil, use subject instead."
4861   :version "22.1"
4862   :type '(radio (const :format "%v  " nil) string)
4863   :group 'gnus-thread)
4864
4865 (defcustom gnus-sum-thread-tree-false-root "> "
4866   "With %B spec, used for a false root of a thread.
4867 If nil, use subject instead."
4868   :version "22.1"
4869   :type '(radio (const :format "%v  " nil) string)
4870   :group 'gnus-thread)
4871
4872 (defcustom gnus-sum-thread-tree-single-indent ""
4873   "With %B spec, used for a thread with just one message.
4874 If nil, use subject instead."
4875   :version "22.1"
4876   :type '(radio (const :format "%v  " nil) string)
4877   :group 'gnus-thread)
4878
4879 (defcustom gnus-sum-thread-tree-vertical "| "
4880   "With %B spec, used for drawing a vertical line."
4881   :version "22.1"
4882   :type 'string
4883   :group 'gnus-thread)
4884
4885 (defcustom gnus-sum-thread-tree-indent "  "
4886   "With %B spec, used for indenting."
4887   :version "22.1"
4888   :type 'string
4889   :group 'gnus-thread)
4890
4891 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4892   "With %B spec, used for a leaf with brothers."
4893   :version "22.1"
4894   :type 'string
4895   :group 'gnus-thread)
4896
4897 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4898   "With %B spec, used for a leaf without brothers."
4899   :version "22.1"
4900   :type 'string
4901   :group 'gnus-thread)
4902
4903 (defun gnus-summary-prepare-threads (threads)
4904   "Prepare summary buffer from THREADS and indentation LEVEL.
4905 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4906 or a straight list of headers."
4907   (gnus-message 7 "Generating summary...")
4908
4909   (setq gnus-newsgroup-threads threads)
4910   (beginning-of-line)
4911
4912   (let ((gnus-tmp-level 0)
4913         (default-score (or gnus-summary-default-score 0))
4914         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4915         (building-line-count gnus-summary-display-while-building)
4916         (building-count (integerp gnus-summary-display-while-building))
4917         thread number subject stack state gnus-tmp-gathered beg-match
4918         new-roots gnus-tmp-new-adopts thread-end simp-subject
4919         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4920         gnus-tmp-replied gnus-tmp-subject-or-nil
4921         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4922         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4923         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4924         tree-stack)
4925
4926     (setq gnus-tmp-prev-subject nil
4927           gnus-tmp-thread-tree-header-string "")
4928
4929     (if (vectorp (car threads))
4930         ;; If this is a straight (sic) list of headers, then a
4931         ;; threaded summary display isn't required, so we just create
4932         ;; an unthreaded one.
4933         (gnus-summary-prepare-unthreaded threads)
4934
4935       ;; Do the threaded display.
4936
4937       (if gnus-summary-display-while-building
4938           (switch-to-buffer (buffer-name)))
4939       (while (or threads stack gnus-tmp-new-adopts new-roots)
4940
4941         (if (and (= gnus-tmp-level 0)
4942                  (or (not stack)
4943                      (= (caar stack) 0))
4944                  (not gnus-tmp-false-parent)
4945                  (or gnus-tmp-new-adopts new-roots))
4946             (if gnus-tmp-new-adopts
4947                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4948                       thread (list (car gnus-tmp-new-adopts))
4949                       gnus-tmp-header (caar thread)
4950                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4951               (when new-roots
4952                 (setq thread (list (car new-roots))
4953                       gnus-tmp-header (caar thread)
4954                       new-roots (cdr new-roots))))
4955
4956           (if threads
4957               ;; If there are some threads, we do them before the
4958               ;; threads on the stack.
4959               (setq thread threads
4960                     gnus-tmp-header (caar thread))
4961             ;; There were no current threads, so we pop something off
4962             ;; the stack.
4963             (setq state (car stack)
4964                   gnus-tmp-level (car state)
4965                   tree-stack (cadr state)
4966                   thread (caddr state)
4967                   stack (cdr stack)
4968                   gnus-tmp-header (caar thread))))
4969
4970         (setq gnus-tmp-false-parent nil)
4971         (setq gnus-tmp-root-expunged nil)
4972         (setq thread-end nil)
4973
4974         (if (stringp gnus-tmp-header)
4975             ;; The header is a dummy root.
4976             (cond
4977              ((eq gnus-summary-make-false-root 'adopt)
4978               ;; We let the first article adopt the rest.
4979               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4980                                                (cddar thread)))
4981               (setq gnus-tmp-gathered
4982                     (nconc (mapcar
4983                             (lambda (h) (mail-header-number (car h)))
4984                             (cddar thread))
4985                            gnus-tmp-gathered))
4986               (setq thread (cons (list (caar thread)
4987                                        (cadar thread))
4988                                  (cdr thread)))
4989               (setq gnus-tmp-level -1
4990                     gnus-tmp-false-parent t))
4991              ((eq gnus-summary-make-false-root 'empty)
4992               ;; We print adopted articles with empty subject fields.
4993               (setq gnus-tmp-gathered
4994                     (nconc (mapcar
4995                             (lambda (h) (mail-header-number (car h)))
4996                             (cddar thread))
4997                            gnus-tmp-gathered))
4998               (setq gnus-tmp-level -1))
4999              ((eq gnus-summary-make-false-root 'dummy)
5000               ;; We remember that we probably want to output a dummy
5001               ;; root.
5002               (setq gnus-tmp-dummy-line gnus-tmp-header)
5003               (setq gnus-tmp-prev-subject gnus-tmp-header))
5004              (t
5005               ;; We do not make a root for the gathered
5006               ;; sub-threads at all.
5007               (setq gnus-tmp-level -1)))
5008
5009           (setq number (mail-header-number gnus-tmp-header)
5010                 subject (mail-header-subject gnus-tmp-header)
5011                 simp-subject (gnus-simplify-subject-fully subject))
5012
5013           (cond
5014            ;; If the thread has changed subject, we might want to make
5015            ;; this subthread into a root.
5016            ((and (null gnus-thread-ignore-subject)
5017                  (not (zerop gnus-tmp-level))
5018                  gnus-tmp-prev-subject
5019                  (not (string= gnus-tmp-prev-subject simp-subject)))
5020             (setq new-roots (nconc new-roots (list (car thread)))
5021                   thread-end t
5022                   gnus-tmp-header nil))
5023            ;; If the article lies outside the current limit,
5024            ;; then we do not display it.
5025            ((not (memq number gnus-newsgroup-limit))
5026             (setq gnus-tmp-gathered
5027                   (nconc (mapcar
5028                           (lambda (h) (mail-header-number (car h)))
5029                           (cdar thread))
5030                          gnus-tmp-gathered))
5031             (setq gnus-tmp-new-adopts (if (cdar thread)
5032                                           (append gnus-tmp-new-adopts
5033                                                   (cdar thread))
5034                                         gnus-tmp-new-adopts)
5035                   thread-end t
5036                   gnus-tmp-header nil)
5037             (when (zerop gnus-tmp-level)
5038               (setq gnus-tmp-root-expunged t)))
5039            ;; Perhaps this article is to be marked as read?
5040            ((and gnus-summary-mark-below
5041                  (< (or (cdr (assq number gnus-newsgroup-scored))
5042                         default-score)
5043                     gnus-summary-mark-below)
5044                  ;; Don't touch sparse articles.
5045                  (not (gnus-summary-article-sparse-p number))
5046                  (not (gnus-summary-article-ancient-p number)))
5047             (setq gnus-newsgroup-unreads
5048                   (delq number gnus-newsgroup-unreads))
5049             (if gnus-newsgroup-auto-expire
5050                 (setq gnus-newsgroup-expirable
5051                       (gnus-add-to-sorted-list
5052                        gnus-newsgroup-expirable number))
5053               (push (cons number gnus-low-score-mark)
5054                     gnus-newsgroup-reads))))
5055
5056           (when gnus-tmp-header
5057             ;; We may have an old dummy line to output before this
5058             ;; article.
5059             (when (and gnus-tmp-dummy-line
5060                        (gnus-subject-equal
5061                         gnus-tmp-dummy-line
5062                         (mail-header-subject gnus-tmp-header)))
5063               (gnus-summary-insert-dummy-line
5064                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5065               (setq gnus-tmp-dummy-line nil))
5066
5067             ;; Compute the mark.
5068             (setq gnus-tmp-unread (gnus-article-mark number))
5069
5070             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5071                                   gnus-tmp-header gnus-tmp-level)
5072                   gnus-newsgroup-data)
5073
5074             ;; Actually insert the line.
5075             (setq
5076              gnus-tmp-subject-or-nil
5077              (cond
5078               ((and gnus-thread-ignore-subject
5079                     gnus-tmp-prev-subject
5080                     (not (string= gnus-tmp-prev-subject simp-subject)))
5081                subject)
5082               ((zerop gnus-tmp-level)
5083                (if (and (eq gnus-summary-make-false-root 'empty)
5084                         (memq number gnus-tmp-gathered)
5085                         gnus-tmp-prev-subject
5086                         (string= gnus-tmp-prev-subject simp-subject))
5087                    gnus-summary-same-subject
5088                  subject))
5089               (t gnus-summary-same-subject)))
5090             (if (and (eq gnus-summary-make-false-root 'adopt)
5091                      (= gnus-tmp-level 1)
5092                      (memq number gnus-tmp-gathered))
5093                 (setq gnus-tmp-opening-bracket ?\<
5094                       gnus-tmp-closing-bracket ?\>)
5095               (setq gnus-tmp-opening-bracket ?\[
5096                     gnus-tmp-closing-bracket ?\]))
5097             (setq
5098              gnus-tmp-indentation
5099              (aref gnus-thread-indent-array gnus-tmp-level)
5100              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5101              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5102                                 gnus-summary-default-score 0)
5103              gnus-tmp-score-char
5104              (if (or (null gnus-summary-default-score)
5105                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5106                          gnus-summary-zcore-fuzz))
5107                  ?                      ;Whitespace
5108                (if (< gnus-tmp-score gnus-summary-default-score)
5109                    gnus-score-below-mark gnus-score-over-mark))
5110              gnus-tmp-replied
5111              (cond ((memq number gnus-newsgroup-processable)
5112                     gnus-process-mark)
5113                    ((memq number gnus-newsgroup-cached)
5114                     gnus-cached-mark)
5115                    ((memq number gnus-newsgroup-replied)
5116                     gnus-replied-mark)
5117                    ((memq number gnus-newsgroup-forwarded)
5118                     gnus-forwarded-mark)
5119                    ((memq number gnus-newsgroup-saved)
5120                     gnus-saved-mark)
5121                    ((memq number gnus-newsgroup-recent)
5122                     gnus-recent-mark)
5123                    ((memq number gnus-newsgroup-unseen)
5124                     gnus-unseen-mark)
5125                    (t gnus-no-mark))
5126              gnus-tmp-downloaded
5127              (cond ((memq number gnus-newsgroup-undownloaded)
5128                     gnus-undownloaded-mark)
5129                    (gnus-newsgroup-agentized
5130                     gnus-downloaded-mark)
5131                    (t
5132                     gnus-no-mark))
5133              gnus-tmp-from (mail-header-from gnus-tmp-header)
5134              gnus-tmp-name
5135              (cond
5136               ((string-match "<[^>]+> *$" gnus-tmp-from)
5137                (setq beg-match (match-beginning 0))
5138                (or (and (string-match "^\".+\"" gnus-tmp-from)
5139                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5140                    (substring gnus-tmp-from 0 beg-match)))
5141               ((string-match "(.+)" gnus-tmp-from)
5142                (substring gnus-tmp-from
5143                           (1+ (match-beginning 0)) (1- (match-end 0))))
5144               (t gnus-tmp-from))
5145
5146              ;; Do the %B string
5147              gnus-tmp-thread-tree-header-string
5148              (cond
5149               ((not gnus-show-threads) "")
5150               ((zerop gnus-tmp-level)
5151                (cond ((cdar thread)
5152                       (or gnus-sum-thread-tree-root subject))
5153                      (gnus-tmp-new-adopts
5154                       (or gnus-sum-thread-tree-false-root subject))
5155                      (t
5156                       (or gnus-sum-thread-tree-single-indent subject))))
5157               (t
5158                (concat (apply 'concat
5159                               (mapcar (lambda (item)
5160                                         (if (= item 1)
5161                                             gnus-sum-thread-tree-vertical
5162                                           gnus-sum-thread-tree-indent))
5163                                       (cdr (reverse tree-stack))))
5164                        (if (nth 1 thread)
5165                            gnus-sum-thread-tree-leaf-with-other
5166                          gnus-sum-thread-tree-single-leaf)))))
5167             (when (string= gnus-tmp-name "")
5168               (setq gnus-tmp-name gnus-tmp-from))
5169             (unless (numberp gnus-tmp-lines)
5170               (setq gnus-tmp-lines -1))
5171             (if (= gnus-tmp-lines -1)
5172                 (setq gnus-tmp-lines "?")
5173               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5174               (gnus-put-text-property
5175              (point)
5176              (progn (eval gnus-summary-line-format-spec) (point))
5177                'gnus-number number)
5178             (when gnus-visual-p
5179               (forward-line -1)
5180               (gnus-run-hooks 'gnus-summary-update-hook)
5181               (forward-line 1))
5182
5183             (setq gnus-tmp-prev-subject simp-subject)))
5184
5185         (when (nth 1 thread)
5186           (push (list (max 0 gnus-tmp-level)
5187                       (copy-sequence tree-stack)
5188                       (nthcdr 1 thread))
5189                 stack))
5190         (push (if (nth 1 thread) 1 0) tree-stack)
5191         (incf gnus-tmp-level)
5192         (setq threads (if thread-end nil (cdar thread)))
5193         (if gnus-summary-display-while-building
5194             (if building-count
5195                 (progn
5196                   ;; use a set frequency
5197                   (setq building-line-count (1- building-line-count))
5198                   (when (= building-line-count 0)
5199                     (sit-for 0)
5200                     (setq building-line-count
5201                           gnus-summary-display-while-building)))
5202               ;; always
5203               (sit-for 0)))
5204         (unless threads
5205           (setq gnus-tmp-level 0)))))
5206   (gnus-message 7 "Generating summary...done"))
5207
5208 (defun gnus-summary-prepare-unthreaded (headers)
5209   "Generate an unthreaded summary buffer based on HEADERS."
5210   (let (header number mark)
5211
5212     (beginning-of-line)
5213
5214     (while headers
5215       ;; We may have to root out some bad articles...
5216       (when (memq (setq number (mail-header-number
5217                                 (setq header (pop headers))))
5218                   gnus-newsgroup-limit)
5219         ;; Mark article as read when it has a low score.
5220         (when (and gnus-summary-mark-below
5221                    (< (or (cdr (assq number gnus-newsgroup-scored))
5222                           gnus-summary-default-score 0)
5223                       gnus-summary-mark-below)
5224                    (not (gnus-summary-article-ancient-p number)))
5225           (setq gnus-newsgroup-unreads
5226                 (delq number gnus-newsgroup-unreads))
5227           (if gnus-newsgroup-auto-expire
5228               (push number gnus-newsgroup-expirable)
5229             (push (cons number gnus-low-score-mark)
5230                   gnus-newsgroup-reads)))
5231
5232         (setq mark (gnus-article-mark number))
5233         (push (gnus-data-make number mark (1+ (point)) header 0)
5234               gnus-newsgroup-data)
5235         (gnus-summary-insert-line
5236          header 0 number
5237          (memq number gnus-newsgroup-undownloaded)
5238          mark (memq number gnus-newsgroup-replied)
5239          (memq number gnus-newsgroup-expirable)
5240          (mail-header-subject header) nil
5241          (cdr (assq number gnus-newsgroup-scored))
5242          (memq number gnus-newsgroup-processable))))))
5243
5244 (defun gnus-summary-remove-list-identifiers ()
5245   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5246   (let ((regexp (if (consp gnus-list-identifiers)
5247                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5248                   gnus-list-identifiers))
5249         changed subject)
5250     (when regexp
5251       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5252       (dolist (header gnus-newsgroup-headers)
5253         (setq subject (mail-header-subject header)
5254               changed nil)
5255         (while (string-match regexp subject)
5256           (setq subject
5257                 (concat (substring subject 0 (match-beginning 1))
5258                         (substring subject (match-end 0)))
5259                 changed t))
5260         (when changed
5261           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5262             (setq subject
5263                   (concat (substring subject 0 (match-beginning 1))
5264                           (substring subject (match-end 1)))))
5265           (mail-header-set-subject header subject))))))
5266
5267 (defun gnus-fetch-headers (articles)
5268   "Fetch headers of ARTICLES."
5269   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5270     (gnus-message 5 "Fetching headers for %s..." name)
5271     (prog1
5272         (if (eq 'nov
5273                 (setq gnus-headers-retrieved-by
5274                       (gnus-retrieve-headers
5275                        articles gnus-newsgroup-name
5276                        ;; We might want to fetch old headers, but
5277                        ;; not if there is only 1 article.
5278                        (and (or (and
5279                                  (not (eq gnus-fetch-old-headers 'some))
5280                                  (not (numberp gnus-fetch-old-headers)))
5281                                 (> (length articles) 1))
5282                             gnus-fetch-old-headers))))
5283             (gnus-get-newsgroup-headers-xover
5284              articles nil nil gnus-newsgroup-name t)
5285           (gnus-get-newsgroup-headers))
5286       (gnus-message 5 "Fetching headers for %s...done" name))))
5287
5288 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5289   "Select newsgroup GROUP.
5290 If READ-ALL is non-nil, all articles in the group are selected.
5291 If SELECT-ARTICLES, only select those articles from GROUP."
5292   (let* ((entry (gnus-group-entry group))
5293          ;;!!! Dirty hack; should be removed.
5294          (gnus-summary-ignore-duplicates
5295           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5296               t
5297             gnus-summary-ignore-duplicates))
5298          (info (nth 2 entry))
5299          articles fetched-articles cached)
5300
5301     (unless (gnus-check-server
5302              (set (make-local-variable 'gnus-current-select-method)
5303                   (gnus-find-method-for-group group)))
5304       (error "Couldn't open server"))
5305
5306     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5307         (gnus-activate-group group)     ; Or we can activate it...
5308         (progn                          ; Or we bug out.
5309           (when (equal major-mode 'gnus-summary-mode)
5310             (gnus-kill-buffer (current-buffer)))
5311           (error "Couldn't activate group %s: %s"
5312                  group (gnus-status-message group))))
5313
5314     (unless (gnus-request-group group t)
5315       (when (equal major-mode 'gnus-summary-mode)
5316         (gnus-kill-buffer (current-buffer)))
5317       (error "Couldn't request group %s: %s"
5318              group (gnus-status-message group)))
5319
5320     (when gnus-agent
5321       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5322
5323       (setq gnus-summary-use-undownloaded-faces
5324             (gnus-agent-find-parameter
5325              group
5326              'agent-enable-undownloaded-faces)))
5327
5328     (setq gnus-newsgroup-name group
5329           gnus-newsgroup-unselected nil
5330           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5331
5332     (let ((display (gnus-group-find-parameter group 'display)))
5333       (setq gnus-newsgroup-display
5334             (cond
5335              ((not (zerop (or (car-safe read-all) 0)))
5336               ;; The user entered the group with C-u SPC/RET, let's show
5337               ;; all articles.
5338               'gnus-not-ignore)
5339              ((eq display 'all)
5340               'gnus-not-ignore)
5341              ((arrayp display)
5342               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5343              ((numberp display)
5344               ;; The following is probably the "correct" solution, but
5345               ;; it makes Gnus fetch all headers and then limit the
5346               ;; articles (which is slow), so instead we hack the
5347               ;; select-articles parameter instead. -- Simon Josefsson
5348               ;; <jas@kth.se>
5349               ;;
5350               ;; (gnus-byte-compile
5351               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5352               ;;                         display)))))
5353               (setq select-articles
5354                     (gnus-uncompress-range
5355                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5356                              (if (> tmp 0)
5357                                  tmp
5358                                1))
5359                            (cdr (gnus-active group)))))
5360               nil)
5361              (t
5362               nil))))
5363
5364     (gnus-summary-setup-default-charset)
5365
5366     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5367     (when (gnus-virtual-group-p group)
5368       (setq cached gnus-newsgroup-cached))
5369
5370     (setq gnus-newsgroup-unreads
5371           (gnus-sorted-ndifference
5372            (gnus-sorted-ndifference gnus-newsgroup-unreads
5373                                     gnus-newsgroup-marked)
5374            gnus-newsgroup-dormant))
5375
5376     (setq gnus-newsgroup-processable nil)
5377
5378     (gnus-update-read-articles group gnus-newsgroup-unreads)
5379
5380     ;; Adjust and set lists of article marks.
5381     (when info
5382       (gnus-adjust-marked-articles info))
5383     (if (setq articles select-articles)
5384         (setq gnus-newsgroup-unselected
5385               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5386       (setq articles (gnus-articles-to-read group read-all)))
5387
5388     (cond
5389      ((null articles)
5390       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5391       'quit)
5392      ((eq articles 0) nil)
5393      (t
5394       ;; Init the dependencies hash table.
5395       (setq gnus-newsgroup-dependencies
5396             (gnus-make-hashtable (length articles)))
5397       (gnus-set-global-variables)
5398       ;; Retrieve the headers and read them in.
5399
5400       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5401
5402       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5403       (when cached
5404         (setq gnus-newsgroup-cached cached))
5405
5406       ;; Suppress duplicates?
5407       (when gnus-suppress-duplicates
5408         (gnus-dup-suppress-articles))
5409
5410       ;; Set the initial limit.
5411       (setq gnus-newsgroup-limit (copy-sequence articles))
5412       ;; Remove canceled articles from the list of unread articles.
5413       (setq fetched-articles
5414             (mapcar (lambda (headers) (mail-header-number headers))
5415                     gnus-newsgroup-headers))
5416       (setq gnus-newsgroup-articles fetched-articles)
5417       (setq gnus-newsgroup-unreads
5418             (gnus-sorted-nintersection
5419              gnus-newsgroup-unreads fetched-articles))
5420       (gnus-compute-unseen-list)
5421
5422       ;; Removed marked articles that do not exist.
5423       (gnus-update-missing-marks
5424        (gnus-sorted-difference articles fetched-articles))
5425       ;; We might want to build some more threads first.
5426       (when (and gnus-fetch-old-headers
5427                  (eq gnus-headers-retrieved-by 'nov))
5428         (if (eq gnus-fetch-old-headers 'invisible)
5429             (gnus-build-all-threads)
5430           (gnus-build-old-threads)))
5431       ;; Let the Gnus agent mark articles as read.
5432       (when gnus-agent
5433         (gnus-agent-get-undownloaded-list))
5434       ;; Remove list identifiers from subject
5435       (when gnus-list-identifiers
5436         (gnus-summary-remove-list-identifiers))
5437       ;; Check whether auto-expire is to be done in this group.
5438       (setq gnus-newsgroup-auto-expire
5439             (gnus-group-auto-expirable-p group))
5440       ;; Set up the article buffer now, if necessary.
5441       (unless gnus-single-article-buffer
5442         (gnus-article-setup-buffer))
5443       ;; First and last article in this newsgroup.
5444       (when gnus-newsgroup-headers
5445         (setq gnus-newsgroup-begin
5446               (mail-header-number (car gnus-newsgroup-headers))
5447               gnus-newsgroup-end
5448               (mail-header-number
5449                (gnus-last-element gnus-newsgroup-headers))))
5450       ;; GROUP is successfully selected.
5451       (or gnus-newsgroup-headers t)))))
5452
5453 (defun gnus-compute-unseen-list ()
5454   ;; The `seen' marks are treated specially.
5455   (if (not gnus-newsgroup-seen)
5456       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5457     (setq gnus-newsgroup-unseen
5458           (gnus-inverse-list-range-intersection
5459            gnus-newsgroup-articles gnus-newsgroup-seen))))
5460
5461 (defun gnus-summary-display-make-predicate (display)
5462   (require 'gnus-agent)
5463   (when (= (length display) 1)
5464     (setq display (car display)))
5465   (unless gnus-summary-display-cache
5466     (dolist (elem (append '((unread . unread)
5467                             (read . read)
5468                             (unseen . unseen))
5469                           gnus-article-mark-lists))
5470       (push (cons (cdr elem)
5471                   (gnus-byte-compile
5472                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5473             gnus-summary-display-cache)))
5474   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5475         (gnus-category-predicate-cache gnus-summary-display-cache))
5476     (gnus-get-predicate display)))
5477
5478 ;; Uses the dynamically bound `number' variable.
5479 (eval-when-compile
5480   (defvar number))
5481 (defun gnus-article-marked-p (type &optional article)
5482   (let ((article (or article number)))
5483     (cond
5484      ((eq type 'tick)
5485       (memq article gnus-newsgroup-marked))
5486      ((eq type 'spam)
5487       (memq article gnus-newsgroup-spam-marked))
5488      ((eq type 'unsend)
5489       (memq article gnus-newsgroup-unsendable))
5490      ((eq type 'undownload)
5491       (memq article gnus-newsgroup-undownloaded))
5492      ((eq type 'download)
5493       (memq article gnus-newsgroup-downloadable))
5494      ((eq type 'unread)
5495       (memq article gnus-newsgroup-unreads))
5496      ((eq type 'read)
5497       (memq article gnus-newsgroup-reads))
5498      ((eq type 'dormant)
5499       (memq article gnus-newsgroup-dormant) )
5500      ((eq type 'expire)
5501       (memq article gnus-newsgroup-expirable))
5502      ((eq type 'reply)
5503       (memq article gnus-newsgroup-replied))
5504      ((eq type 'killed)
5505       (memq article gnus-newsgroup-killed))
5506      ((eq type 'bookmark)
5507       (assq article gnus-newsgroup-bookmarks))
5508      ((eq type 'score)
5509       (assq article gnus-newsgroup-scored))
5510      ((eq type 'save)
5511       (memq article gnus-newsgroup-saved))
5512      ((eq type 'cache)
5513       (memq article gnus-newsgroup-cached))
5514      ((eq type 'forward)
5515       (memq article gnus-newsgroup-forwarded))
5516      ((eq type 'seen)
5517       (not (memq article gnus-newsgroup-unseen)))
5518      ((eq type 'recent)
5519       (memq article gnus-newsgroup-recent))
5520      (t t))))
5521
5522 (defun gnus-articles-to-read (group &optional read-all)
5523   "Find out what articles the user wants to read."
5524   (let* ((articles
5525           ;; Select all articles if `read-all' is non-nil, or if there
5526           ;; are no unread articles.
5527           (if (or read-all
5528                   (and (zerop (length gnus-newsgroup-marked))
5529                        (zerop (length gnus-newsgroup-unreads)))
5530                   ;; Fetch all if the predicate is non-nil.
5531                   gnus-newsgroup-display)
5532               ;; We want to select the headers for all the articles in
5533               ;; the group, so we select either all the active
5534               ;; articles in the group, or (if that's nil), the
5535               ;; articles in the cache.
5536               (or
5537                (gnus-uncompress-range (gnus-active group))
5538                (gnus-cache-articles-in-group group))
5539             ;; Select only the "normal" subset of articles.
5540             (gnus-sorted-nunion
5541              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5542              gnus-newsgroup-unreads)))
5543          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5544          (scored (length scored-list))
5545          (number (length articles))
5546          (marked (+ (length gnus-newsgroup-marked)
5547                     (length gnus-newsgroup-dormant)))
5548          (select
5549           (cond
5550            ((numberp read-all)
5551             read-all)
5552            ((numberp gnus-newsgroup-display)
5553             gnus-newsgroup-display)
5554            (t
5555             (condition-case ()
5556                 (cond
5557                  ((and (or (<= scored marked) (= scored number))
5558                        (numberp gnus-large-newsgroup)
5559                        (> number gnus-large-newsgroup))
5560                   (let* ((cursor-in-echo-area nil)
5561                          (initial (gnus-parameter-large-newsgroup-initial
5562                                    gnus-newsgroup-name))
5563                          (input
5564                           (read-string
5565                            (format
5566                             "How many articles from %s (%s %d): "
5567                             (gnus-limit-string
5568                              (gnus-group-decoded-name gnus-newsgroup-name)
5569                              35)
5570                             (if initial "max" "default")
5571                             number)
5572                            (if initial
5573                                (cons (number-to-string initial)
5574                                      0)))))
5575                     (if (string-match "^[ \t]*$" input) number input)))
5576                  ((and (> scored marked) (< scored number)
5577                        (> (- scored number) 20))
5578                   (let ((input
5579                          (read-string
5580                           (format "%s %s (%d scored, %d total): "
5581                                   "How many articles from"
5582                                   (gnus-group-decoded-name group)
5583                                   scored number))))
5584                     (if (string-match "^[ \t]*$" input)
5585                         number input)))
5586                  (t number))
5587               (quit
5588                (message "Quit getting the articles to read")
5589                nil))))))
5590     (setq select (if (stringp select) (string-to-number select) select))
5591     (if (or (null select) (zerop select))
5592         select
5593       (if (and (not (zerop scored)) (<= (abs select) scored))
5594           (progn
5595             (setq articles (sort scored-list '<))
5596             (setq number (length articles)))
5597         (setq articles (copy-sequence articles)))
5598
5599       (when (< (abs select) number)
5600         (if (< select 0)
5601             ;; Select the N oldest articles.
5602             (setcdr (nthcdr (1- (abs select)) articles) nil)
5603           ;; Select the N most recent articles.
5604           (setq articles (nthcdr (- number select) articles))))
5605       (setq gnus-newsgroup-unselected
5606             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5607       (when gnus-alter-articles-to-read-function
5608         (setq articles
5609               (sort
5610                (funcall gnus-alter-articles-to-read-function
5611                         gnus-newsgroup-name articles)
5612                '<)))
5613       articles)))
5614
5615 (defun gnus-killed-articles (killed articles)
5616   (let (out)
5617     (while articles
5618       (when (inline (gnus-member-of-range (car articles) killed))
5619         (push (car articles) out))
5620       (setq articles (cdr articles)))
5621     out))
5622
5623 (defun gnus-uncompress-marks (marks)
5624   "Uncompress the mark ranges in MARKS."
5625   (let ((uncompressed '(score bookmark))
5626         out)
5627     (while marks
5628       (if (memq (caar marks) uncompressed)
5629           (push (car marks) out)
5630         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5631       (setq marks (cdr marks)))
5632     out))
5633
5634 (defun gnus-article-mark-to-type (mark)
5635   "Return the type of MARK."
5636   (or (cadr (assq mark gnus-article-special-mark-lists))
5637       'list))
5638
5639 (defun gnus-article-unpropagatable-p (mark)
5640   "Return whether MARK should be propagated to back end."
5641   (memq mark gnus-article-unpropagated-mark-lists))
5642
5643 (defun gnus-adjust-marked-articles (info)
5644   "Set all article lists and remove all marks that are no longer valid."
5645   (let* ((marked-lists (gnus-info-marks info))
5646          (active (gnus-active (gnus-info-group info)))
5647          (min (car active))
5648          (max (cdr active))
5649          (types gnus-article-mark-lists)
5650          marks var articles article mark mark-type
5651          bgn end)
5652
5653     (dolist (marks marked-lists)
5654       (setq mark (car marks)
5655             mark-type (gnus-article-mark-to-type mark)
5656             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5657
5658       ;; We set the variable according to the type of the marks list,
5659       ;; and then adjust the marks to a subset of the active articles.
5660       (cond
5661        ;; Adjust "simple" lists - compressed yet unsorted
5662        ((eq mark-type 'list)
5663         ;; Simultaneously uncompress and clip to active range
5664         ;; See gnus-uncompress-range for a description of possible marks
5665         (let (l lh)
5666           (if (not (cadr marks))
5667               (set var nil)
5668             (setq articles (if (numberp (cddr marks))
5669                                (list (cdr marks))
5670                              (cdr marks))
5671                   lh (cons nil nil)
5672                   l lh)
5673
5674             (while (setq article (pop articles))
5675               (cond ((consp article)
5676                      (setq bgn (max (car article) min)
5677                            end (min (cdr article) max))
5678                      (while (<= bgn end)
5679                        (setq l (setcdr l (cons bgn nil))
5680                              bgn (1+ bgn))))
5681                     ((and (<= min article)
5682                           (>= max article))
5683                      (setq l (setcdr l (cons article nil))))))
5684             (set var (cdr lh)))))
5685        ;; Adjust assocs.
5686        ((eq mark-type 'tuple)
5687         (set var (setq articles (cdr marks)))
5688         (when (not (listp (cdr (symbol-value var))))
5689           (set var (list (symbol-value var))))
5690         (when (not (listp (cdr articles)))
5691           (setq articles (list articles)))
5692         (while articles
5693           (when (or (not (consp (setq article (pop articles))))
5694                     (< (car article) min)
5695                     (> (car article) max))
5696             (set var (delq article (symbol-value var))))))
5697        ;; Adjust ranges (sloppily).
5698        ((eq mark-type 'range)
5699         (cond
5700          ((eq mark 'seen)
5701           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5702           ;; It should be (seen (NUM1 . NUM2)).
5703           (when (numberp (cddr marks))
5704             (setcdr marks (list (cdr marks))))
5705           (setq articles (cdr marks))
5706           (while (and articles
5707                       (or (and (consp (car articles))
5708                                (> min (cdar articles)))
5709                           (and (numberp (car articles))
5710                                (> min (car articles)))))
5711             (pop articles))
5712           (set var articles))))))))
5713
5714 (defun gnus-update-missing-marks (missing)
5715   "Go through the list of MISSING articles and remove them from the mark lists."
5716   (when missing
5717     (let (var m)
5718       ;; Go through all types.
5719       (dolist (elem gnus-article-mark-lists)
5720         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5721           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5722           (when (symbol-value var)
5723             ;; This list has articles.  So we delete all missing
5724             ;; articles from it.
5725             (setq m missing)
5726             (while m
5727               (set var (delq (pop m) (symbol-value var))))))))))
5728
5729 (defun gnus-update-marks ()
5730   "Enter the various lists of marked articles into the newsgroup info list."
5731   (let ((types gnus-article-mark-lists)
5732         (info (gnus-get-info gnus-newsgroup-name))
5733         type list newmarked symbol delta-marks)
5734     (when info
5735       ;; Add all marks lists to the list of marks lists.
5736       (while (setq type (pop types))
5737         (setq list (symbol-value
5738                     (setq symbol
5739                           (intern (format "gnus-newsgroup-%s" (car type))))))
5740
5741         (when list
5742           ;; Get rid of the entries of the articles that have the
5743           ;; default score.
5744           (when (and (eq (cdr type) 'score)
5745                      gnus-save-score
5746                      list)
5747             (let* ((arts list)
5748                    (prev (cons nil list))
5749                    (all prev))
5750               (while arts
5751                 (if (or (not (consp (car arts)))
5752                         (= (cdar arts) gnus-summary-default-score))
5753                     (setcdr prev (cdr arts))
5754                   (setq prev arts))
5755                 (setq arts (cdr arts)))
5756               (setq list (cdr all)))))
5757
5758         (when (eq (cdr type) 'seen)
5759           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5760
5761         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5762           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5763
5764         (when (and (gnus-check-backend-function
5765                     'request-set-mark gnus-newsgroup-name)
5766                    (not (gnus-article-unpropagatable-p (cdr type))))
5767           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5768                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5769                  (add (gnus-remove-from-range
5770                        (gnus-copy-sequence list) old)))
5771             (when add
5772               (push (list add 'add (list (cdr type))) delta-marks))
5773             (when del
5774               (push (list del 'del (list (cdr type))) delta-marks))))
5775
5776         (when list
5777           (push (cons (cdr type) list) newmarked)))
5778
5779       (when delta-marks
5780         (unless (gnus-check-group gnus-newsgroup-name)
5781           (error "Can't open server for %s" gnus-newsgroup-name))
5782         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5783
5784       ;; Enter these new marks into the info of the group.
5785       (if (nthcdr 3 info)
5786           (setcar (nthcdr 3 info) newmarked)
5787         ;; Add the marks lists to the end of the info.
5788         (when newmarked
5789           (setcdr (nthcdr 2 info) (list newmarked))))
5790
5791       ;; Cut off the end of the info if there's nothing else there.
5792       (let ((i 5))
5793         (while (and (> i 2)
5794                     (not (nth i info)))
5795           (when (nthcdr (decf i) info)
5796             (setcdr (nthcdr i info) nil)))))))
5797
5798 (defun gnus-set-mode-line (where)
5799   "Set the mode line of the article or summary buffers.
5800 If WHERE is `summary', the summary mode line format will be used."
5801   ;; Is this mode line one we keep updated?
5802   (when (and (memq where gnus-updated-mode-lines)
5803              (symbol-value
5804               (intern (format "gnus-%s-mode-line-format-spec" where))))
5805     (let (mode-string)
5806       (save-excursion
5807         ;; We evaluate this in the summary buffer since these
5808         ;; variables are buffer-local to that buffer.
5809         (set-buffer gnus-summary-buffer)
5810        ;; We bind all these variables that are used in the `eval' form
5811         ;; below.
5812         (let* ((mformat (symbol-value
5813                          (intern
5814                           (format "gnus-%s-mode-line-format-spec" where))))
5815                (gnus-tmp-group-name (gnus-group-decoded-name
5816                                      gnus-newsgroup-name))
5817                (gnus-tmp-article-number (or gnus-current-article 0))
5818                (gnus-tmp-unread gnus-newsgroup-unreads)
5819                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5820                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5821                (gnus-tmp-unread-and-unselected
5822                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5823                             (zerop gnus-tmp-unselected))
5824                        "")
5825                       ((zerop gnus-tmp-unselected)
5826                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5827                       (t (format "{%d(+%d) more}"
5828                                  gnus-tmp-unread-and-unticked
5829                                  gnus-tmp-unselected))))
5830                (gnus-tmp-subject
5831                 (if (and gnus-current-headers
5832                          (vectorp gnus-current-headers))
5833                     (gnus-mode-string-quote
5834                      (mail-header-subject gnus-current-headers))
5835                   ""))
5836                bufname-length max-len
5837                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5838           (setq mode-string (eval mformat))
5839           (setq bufname-length (if (string-match "%b" mode-string)
5840                                    (- (length
5841                                        (buffer-name
5842                                         (if (eq where 'summary)
5843                                             nil
5844                                           (get-buffer gnus-article-buffer))))
5845                                       2)
5846                                  0))
5847           (setq max-len (max 4 (if gnus-mode-non-string-length
5848                                    (- (window-width)
5849                                       gnus-mode-non-string-length
5850                                       bufname-length)
5851                                  (length mode-string))))
5852           ;; We might have to chop a bit of the string off...
5853           (when (> (length mode-string) max-len)
5854             (setq mode-string
5855                   (concat (truncate-string-to-width mode-string (- max-len 3))
5856                           "...")))
5857           ;; Pad the mode string a bit.
5858           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5859       ;; Update the mode line.
5860       (setq mode-line-buffer-identification
5861             (gnus-mode-line-buffer-identification (list mode-string)))
5862       (set-buffer-modified-p t))))
5863
5864 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5865   "Go through the HEADERS list and add all Xrefs to a hash table.
5866 The resulting hash table is returned, or nil if no Xrefs were found."
5867   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5868          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5869          (xref-hashtb (gnus-make-hashtable))
5870          start group entry number xrefs header)
5871     (while headers
5872       (setq header (pop headers))
5873       (when (and (setq xrefs (mail-header-xref header))
5874                  (not (memq (setq number (mail-header-number header))
5875                             unreads)))
5876         (setq start 0)
5877         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5878           (setq start (match-end 0))
5879           (setq group (if prefix
5880                           (concat prefix (substring xrefs (match-beginning 1)
5881                                                     (match-end 1)))
5882                         (substring xrefs (match-beginning 1) (match-end 1))))
5883           (setq number
5884                 (string-to-number (substring xrefs (match-beginning 2)
5885                                           (match-end 2))))
5886           (if (setq entry (gnus-gethash group xref-hashtb))
5887               (setcdr entry (cons number (cdr entry)))
5888             (gnus-sethash group (cons number nil) xref-hashtb)))))
5889     (and start xref-hashtb)))
5890
5891 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5892   "Look through all the headers and mark the Xrefs as read."
5893   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5894         name info xref-hashtb idlist method nth4)
5895     (save-excursion
5896       (set-buffer gnus-group-buffer)
5897       (when (setq xref-hashtb
5898                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5899         (mapatoms
5900          (lambda (group)
5901            (unless (string= from-newsgroup (setq name (symbol-name group)))
5902              (setq idlist (symbol-value group))
5903              ;; Dead groups are not updated.
5904              (and (prog1
5905                       (setq info (gnus-get-info name))
5906                     (when (stringp (setq nth4 (gnus-info-method info)))
5907                       (setq nth4 (gnus-server-to-method nth4))))
5908                   ;; Only do the xrefs if the group has the same
5909                   ;; select method as the group we have just read.
5910                   (or (gnus-methods-equal-p
5911                        nth4 (gnus-find-method-for-group from-newsgroup))
5912                       virtual
5913                       (equal nth4 (setq method (gnus-find-method-for-group
5914                                                 from-newsgroup)))
5915                       (and (equal (car nth4) (car method))
5916                            (equal (nth 1 nth4) (nth 1 method))))
5917                   gnus-use-cross-reference
5918                   (or (not (eq gnus-use-cross-reference t))
5919                       virtual
5920                       ;; Only do cross-references on subscribed
5921                       ;; groups, if that is what is wanted.
5922                       (<= (gnus-info-level info) gnus-level-subscribed))
5923                   (gnus-group-make-articles-read name idlist))))
5924          xref-hashtb)))))
5925
5926 (defun gnus-compute-read-articles (group articles)
5927   (let* ((entry (gnus-group-entry group))
5928          (info (nth 2 entry))
5929          (active (gnus-active group))
5930          ninfo)
5931     (when entry
5932       ;; First peel off all invalid article numbers.
5933       (when active
5934         (let ((ids articles)
5935               id first)
5936           (while (setq id (pop ids))
5937             (when (and first (> id (cdr active)))
5938               ;; We'll end up in this situation in one particular
5939               ;; obscure situation.  If you re-scan a group and get
5940               ;; a new article that is cross-posted to a different
5941               ;; group that has not been re-scanned, you might get
5942               ;; crossposted article that has a higher number than
5943               ;; Gnus believes possible.  So we re-activate this
5944               ;; group as well.  This might mean doing the
5945               ;; crossposting thingy will *increase* the number
5946               ;; of articles in some groups.  Tsk, tsk.
5947               (setq active (or (gnus-activate-group group) active)))
5948             (when (or (> id (cdr active))
5949                       (< id (car active)))
5950               (setq articles (delq id articles))))))
5951       ;; If the read list is nil, we init it.
5952       (if (and active
5953                (null (gnus-info-read info))
5954                (> (car active) 1))
5955           (setq ninfo (cons 1 (1- (car active))))
5956         (setq ninfo (gnus-info-read info)))
5957       ;; Then we add the read articles to the range.
5958       (gnus-add-to-range
5959        ninfo (setq articles (sort articles '<))))))
5960
5961 (defun gnus-group-make-articles-read (group articles)
5962   "Update the info of GROUP to say that ARTICLES are read."
5963   (let* ((num 0)
5964          (entry (gnus-group-entry group))
5965          (info (nth 2 entry))
5966          (active (gnus-active group))
5967          range)
5968     (when entry
5969       (setq range (gnus-compute-read-articles group articles))
5970       (with-current-buffer gnus-group-buffer
5971         (gnus-undo-register
5972           `(progn
5973              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5974              (gnus-info-set-read ',info ',(gnus-info-read info))
5975              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5976              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5977              (gnus-group-update-group ,group t))))
5978       ;; Add the read articles to the range.
5979       (gnus-info-set-read info range)
5980       (gnus-request-set-mark group (list (list range 'add '(read))))
5981       ;; Then we have to re-compute how many unread
5982       ;; articles there are in this group.
5983       (when active
5984         (cond
5985          ((not range)
5986           (setq num (- (1+ (cdr active)) (car active))))
5987          ((not (listp (cdr range)))
5988           (setq num (- (cdr active) (- (1+ (cdr range))
5989                                        (car range)))))
5990          (t
5991           (while range
5992             (if (numberp (car range))
5993                 (setq num (1+ num))
5994               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5995             (setq range (cdr range)))
5996           (setq num (- (cdr active) num))))
5997         ;; Update the number of unread articles.
5998         (setcar entry num)
5999         ;; Update the group buffer.
6000         (unless (gnus-ephemeral-group-p group)
6001           (gnus-group-update-group group t))))))
6002
6003 (defvar gnus-newsgroup-none-id 0)
6004
6005 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6006   (let ((cur nntp-server-buffer)
6007         (dependencies
6008          (or dependencies
6009              (with-current-buffer gnus-summary-buffer
6010                gnus-newsgroup-dependencies)))
6011         headers id end ref number
6012         (mail-parse-charset gnus-newsgroup-charset)
6013         (mail-parse-ignored-charsets
6014          (save-excursion (condition-case nil
6015                              (set-buffer gnus-summary-buffer)
6016                            (error))
6017                          gnus-newsgroup-ignored-charsets)))
6018     (save-excursion
6019       (set-buffer nntp-server-buffer)
6020       ;; Translate all TAB characters into SPACE characters.
6021       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6022       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6023       (ietf-drums-unfold-fws)
6024       (gnus-run-hooks 'gnus-parse-headers-hook)
6025       (let ((case-fold-search t)
6026             in-reply-to header p lines chars)
6027         (goto-char (point-min))
6028         ;; Search to the beginning of the next header.  Error messages
6029         ;; do not begin with 2 or 3.
6030         (while (re-search-forward "^[23][0-9]+ " nil t)
6031           (setq id nil
6032                 ref nil)
6033           ;; This implementation of this function, with nine
6034           ;; search-forwards instead of the one re-search-forward and
6035           ;; a case (which basically was the old function) is actually
6036           ;; about twice as fast, even though it looks messier.  You
6037           ;; can't have everything, I guess.  Speed and elegance
6038           ;; doesn't always go hand in hand.
6039           (setq
6040            header
6041            (vector
6042             ;; Number.
6043             (prog1
6044                 (setq number (read cur))
6045               (end-of-line)
6046               (setq p (point))
6047               (narrow-to-region (point)
6048                                 (or (and (search-forward "\n.\n" nil t)
6049                                          (- (point) 2))
6050                                     (point))))
6051             ;; Subject.
6052             (progn
6053               (goto-char p)
6054               (if (search-forward "\nsubject:" nil t)
6055                   (funcall gnus-decode-encoded-word-function
6056                            (nnheader-header-value))
6057                 "(none)"))
6058             ;; From.
6059             (progn
6060               (goto-char p)
6061               (if (search-forward "\nfrom:" nil t)
6062                   (funcall gnus-decode-encoded-word-function
6063                            (nnheader-header-value))
6064                 "(nobody)"))
6065             ;; Date.
6066             (progn
6067               (goto-char p)
6068               (if (search-forward "\ndate:" nil t)
6069                   (nnheader-header-value) ""))
6070             ;; Message-ID.
6071             (progn
6072               (goto-char p)
6073               (setq id (if (re-search-forward
6074                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6075                            ;; We do it this way to make sure the Message-ID
6076                            ;; is (somewhat) syntactically valid.
6077                            (buffer-substring (match-beginning 1)
6078                                              (match-end 1))
6079                          ;; If there was no message-id, we just fake one
6080                          ;; to make subsequent routines simpler.
6081                          (nnheader-generate-fake-message-id number))))
6082             ;; References.
6083             (progn
6084               (goto-char p)
6085               (if (search-forward "\nreferences:" nil t)
6086                   (progn
6087                     (setq end (point))
6088                     (prog1
6089                         (nnheader-header-value)
6090                       (setq ref
6091                             (buffer-substring
6092                              (progn
6093                                (end-of-line)
6094                                (search-backward ">" end t)
6095                                (1+ (point)))
6096                              (progn
6097                                (search-backward "<" end t)
6098                                (point))))))
6099                 ;; Get the references from the in-reply-to header if there
6100                 ;; were no references and the in-reply-to header looks
6101                 ;; promising.
6102                 (if (and (search-forward "\nin-reply-to:" nil t)
6103                          (setq in-reply-to (nnheader-header-value))
6104                          (string-match "<[^>]+>" in-reply-to))
6105                     (let (ref2)
6106                       (setq ref (substring in-reply-to (match-beginning 0)
6107                                            (match-end 0)))
6108                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6109                         (setq ref2 (substring in-reply-to (match-beginning 0)
6110                                               (match-end 0)))
6111                         (when (> (length ref2) (length ref))
6112                           (setq ref ref2)))
6113                       ref)
6114                   (setq ref nil))))
6115             ;; Chars.
6116             (progn
6117               (goto-char p)
6118               (if (search-forward "\nchars: " nil t)
6119                   (if (numberp (setq chars (ignore-errors (read cur))))
6120                       chars -1)
6121                 -1))
6122             ;; Lines.
6123             (progn
6124               (goto-char p)
6125               (if (search-forward "\nlines: " nil t)
6126                   (if (numberp (setq lines (ignore-errors (read cur))))
6127                       lines -1)
6128                 -1))
6129             ;; Xref.
6130             (progn
6131               (goto-char p)
6132               (and (search-forward "\nxref:" nil t)
6133                    (nnheader-header-value)))
6134             ;; Extra.
6135             (when gnus-extra-headers
6136               (let ((extra gnus-extra-headers)
6137                     out)
6138                 (while extra
6139                   (goto-char p)
6140                   (when (search-forward
6141                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6142                     (push (cons (car extra) (nnheader-header-value))
6143                           out))
6144                   (pop extra))
6145                 out))))
6146           (when (equal id ref)
6147             (setq ref nil))
6148
6149           (when gnus-alter-header-function
6150             (funcall gnus-alter-header-function header)
6151             (setq id (mail-header-id header)
6152                   ref (gnus-parent-id (mail-header-references header))))
6153
6154           (when (setq header
6155                       (gnus-dependencies-add-header
6156                        header dependencies force-new))
6157             (push header headers))
6158           (goto-char (point-max))
6159           (widen))
6160         (nreverse headers)))))
6161
6162 ;; Goes through the xover lines and returns a list of vectors
6163 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6164                                                   force-new dependencies
6165                                                   group also-fetch-heads)
6166   "Parse the news overview data in the server buffer.
6167 Return a list of headers that match SEQUENCE (see
6168 `nntp-retrieve-headers')."
6169   ;; Get the Xref when the users reads the articles since most/some
6170   ;; NNTP servers do not include Xrefs when using XOVER.
6171   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6172   (let ((mail-parse-charset gnus-newsgroup-charset)
6173         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6174         (cur nntp-server-buffer)
6175         (dependencies (or dependencies gnus-newsgroup-dependencies))
6176         (allp (cond
6177                ((eq gnus-read-all-available-headers t)
6178                 t)
6179                ((stringp gnus-read-all-available-headers)
6180                 (string-match gnus-read-all-available-headers group))
6181                (t
6182                 nil)))
6183         number headers header)
6184     (save-excursion
6185       (set-buffer nntp-server-buffer)
6186       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6187       ;; Allow the user to mangle the headers before parsing them.
6188       (gnus-run-hooks 'gnus-parse-headers-hook)
6189       (goto-char (point-min))
6190       (gnus-parse-without-error
6191         (while (and (or sequence allp)
6192                     (not (eobp)))
6193           (setq number (read cur))
6194           (when (not allp)
6195             (while (and sequence
6196                         (< (car sequence) number))
6197               (setq sequence (cdr sequence))))
6198           (when (and (or allp
6199                          (and sequence
6200                               (eq number (car sequence))))
6201                      (progn
6202                        (setq sequence (cdr sequence))
6203                        (setq header (inline
6204                                       (gnus-nov-parse-line
6205                                        number dependencies force-new)))))
6206             (push header headers))
6207           (forward-line 1)))
6208       ;; A common bug in inn is that if you have posted an article and
6209       ;; then retrieves the active file, it will answer correctly --
6210       ;; the new article is included.  However, a NOV entry for the
6211       ;; article may not have been generated yet, so this may fail.
6212       ;; We work around this problem by retrieving the last few
6213       ;; headers using HEAD.
6214       (if (or (not also-fetch-heads)
6215               (not sequence))
6216           ;; We (probably) got all the headers.
6217           (nreverse headers)
6218         (let ((gnus-nov-is-evil t))
6219           (nconc
6220            (nreverse headers)
6221            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6222              (gnus-get-newsgroup-headers))))))))
6223
6224 (defun gnus-article-get-xrefs ()
6225   "Fill in the Xref value in `gnus-current-headers', if necessary.
6226 This is meant to be called in `gnus-article-internal-prepare-hook'."
6227   (let ((headers (with-current-buffer gnus-summary-buffer
6228                    gnus-current-headers)))
6229     (or (not gnus-use-cross-reference)
6230         (not headers)
6231         (and (mail-header-xref headers)
6232              (not (string= (mail-header-xref headers) "")))
6233         (let ((case-fold-search t)
6234               xref)
6235           (save-restriction
6236             (nnheader-narrow-to-headers)
6237             (goto-char (point-min))
6238             (when (or (and (not (eobp))
6239                            (eq (downcase (char-after)) ?x)
6240                            (looking-at "Xref:"))
6241                       (search-forward "\nXref:" nil t))
6242               (goto-char (1+ (match-end 0)))
6243               (setq xref (buffer-substring (point) (point-at-eol)))
6244               (mail-header-set-xref headers xref)))))))
6245
6246 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6247   "Find article ID and insert the summary line for that article.
6248 OLD-HEADER can either be a header or a line number to insert
6249 the subject line on."
6250   (let* ((line (and (numberp old-header) old-header))
6251          (old-header (and (vectorp old-header) old-header))
6252          (header (cond ((and old-header use-old-header)
6253                         old-header)
6254                        ((and (numberp id)
6255                              (gnus-number-to-header id))
6256                         (gnus-number-to-header id))
6257                        (t
6258                         (gnus-read-header id))))
6259          (number (and (numberp id) id))
6260          d)
6261     (when header
6262       ;; Rebuild the thread that this article is part of and go to the
6263       ;; article we have fetched.
6264       (when (and (not gnus-show-threads)
6265                  old-header)
6266         (when (and number
6267                    (setq d (gnus-data-find (mail-header-number old-header))))
6268           (goto-char (gnus-data-pos d))
6269           (gnus-data-remove
6270            number
6271            (- (point-at-bol)
6272               (prog1
6273                   (1+ (point-at-eol))
6274                 (gnus-delete-line))))))
6275       ;; Remove list identifiers from subject.
6276       (when gnus-list-identifiers
6277         (let ((gnus-newsgroup-headers (list header)))
6278           (gnus-summary-remove-list-identifiers)))
6279       (when old-header
6280         (mail-header-set-number header (mail-header-number old-header)))
6281       (setq gnus-newsgroup-sparse
6282             (delq (setq number (mail-header-number header))
6283                   gnus-newsgroup-sparse))
6284       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6285       (push number gnus-newsgroup-limit)
6286       (gnus-rebuild-thread (mail-header-id header) line)
6287       (gnus-summary-goto-subject number nil t))
6288     (when (and (numberp number)
6289                (> number 0))
6290       ;; We have to update the boundaries even if we can't fetch the
6291       ;; article if ID is a number -- so that the next `P' or `N'
6292       ;; command will fetch the previous (or next) article even
6293       ;; if the one we tried to fetch this time has been canceled.
6294       (when (> number gnus-newsgroup-end)
6295         (setq gnus-newsgroup-end number))
6296       (when (< number gnus-newsgroup-begin)
6297         (setq gnus-newsgroup-begin number))
6298       (setq gnus-newsgroup-unselected
6299             (delq number gnus-newsgroup-unselected)))
6300     ;; Report back a success?
6301     (and header (mail-header-number header))))
6302
6303 ;;; Process/prefix in the summary buffer
6304
6305 (defun gnus-summary-work-articles (n)
6306   "Return a list of articles to be worked upon.
6307 The prefix argument, the list of process marked articles, and the
6308 current article will be taken into consideration."
6309   (save-excursion
6310     (set-buffer gnus-summary-buffer)
6311     (cond
6312      (n
6313       ;; A numerical prefix has been given.
6314       (setq n (prefix-numeric-value n))
6315       (let ((backward (< n 0))
6316             (n (abs (prefix-numeric-value n)))
6317             articles article)
6318         (save-excursion
6319           (while
6320               (and (> n 0)
6321                    (push (setq article (gnus-summary-article-number))
6322                          articles)
6323                    (if backward
6324                        (gnus-summary-find-prev nil article)
6325                      (gnus-summary-find-next nil article)))
6326             (decf n)))
6327         (nreverse articles)))
6328      ((and (gnus-region-active-p) (mark))
6329       (message "region active")
6330       ;; Work on the region between point and mark.
6331       (let ((max (max (point) (mark)))
6332             articles article)
6333         (save-excursion
6334           (goto-char (min (point) (mark)))
6335           (while
6336               (and
6337                (push (setq article (gnus-summary-article-number)) articles)
6338                (gnus-summary-find-next nil article)
6339                (< (point) max)))
6340           (nreverse articles))))
6341      (gnus-newsgroup-processable
6342       ;; There are process-marked articles present.
6343       ;; Save current state.
6344       (gnus-summary-save-process-mark)
6345       ;; Return the list.
6346       (reverse gnus-newsgroup-processable))
6347      (t
6348       ;; Just return the current article.
6349       (list (gnus-summary-article-number))))))
6350
6351 (defmacro gnus-summary-iterate (arg &rest forms)
6352   "Iterate over the process/prefixed articles and do FORMS.
6353 ARG is the interactive prefix given to the command.  FORMS will be
6354 executed with point over the summary line of the articles."
6355   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6356     `(let ((,articles (gnus-summary-work-articles ,arg)))
6357        (while ,articles
6358          (gnus-summary-goto-subject (car ,articles))
6359          ,@forms
6360          (pop ,articles)))))
6361
6362 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6363 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6364
6365 (defun gnus-summary-save-process-mark ()
6366   "Push the current set of process marked articles on the stack."
6367   (interactive)
6368   (push (copy-sequence gnus-newsgroup-processable)
6369         gnus-newsgroup-process-stack))
6370
6371 (defun gnus-summary-kill-process-mark ()
6372   "Push the current set of process marked articles on the stack and unmark."
6373   (interactive)
6374   (gnus-summary-save-process-mark)
6375   (gnus-summary-unmark-all-processable))
6376
6377 (defun gnus-summary-yank-process-mark ()
6378   "Pop the last process mark state off the stack and restore it."
6379   (interactive)
6380   (unless gnus-newsgroup-process-stack
6381     (error "Empty mark stack"))
6382   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6383
6384 (defun gnus-summary-process-mark-set (set)
6385   "Make SET into the current process marked articles."
6386   (gnus-summary-unmark-all-processable)
6387   (mapc 'gnus-summary-set-process-mark set))
6388
6389 ;;; Searching and stuff
6390
6391 (defun gnus-summary-search-group (&optional backward use-level)
6392   "Search for next unread newsgroup.
6393 If optional argument BACKWARD is non-nil, search backward instead."
6394   (save-excursion
6395     (set-buffer gnus-group-buffer)
6396     (when (gnus-group-search-forward
6397            backward nil (if use-level (gnus-group-group-level) nil))
6398       (gnus-group-group-name))))
6399
6400 (defun gnus-summary-best-group (&optional exclude-group)
6401   "Find the name of the best unread group.
6402 If EXCLUDE-GROUP, do not go to this group."
6403   (with-current-buffer gnus-group-buffer
6404     (save-excursion
6405       (gnus-group-best-unread-group exclude-group))))
6406
6407 (defun gnus-summary-find-next (&optional unread article backward)
6408   (if backward
6409       (gnus-summary-find-prev unread article)
6410     (let* ((dummy (gnus-summary-article-intangible-p))
6411            (article (or article (gnus-summary-article-number)))
6412            (data (gnus-data-find-list article))
6413            result)
6414       (when (and (not dummy)
6415                  (or (not gnus-summary-check-current)
6416                      (not unread)
6417                      (not (gnus-data-unread-p (car data)))))
6418         (setq data (cdr data)))
6419       (when (setq result
6420                   (if unread
6421                       (progn
6422                         (while data
6423                           (unless (memq (gnus-data-number (car data))
6424                                         (cond
6425                                          ((eq gnus-auto-goto-ignores
6426                                               'always-undownloaded)
6427                                           gnus-newsgroup-undownloaded)
6428                                          (gnus-plugged
6429                                           nil)
6430                                          ((eq gnus-auto-goto-ignores
6431                                               'unfetched)
6432                                           gnus-newsgroup-unfetched)
6433                                          ((eq gnus-auto-goto-ignores
6434                                               'undownloaded)
6435                                           gnus-newsgroup-undownloaded)))
6436                             (when (gnus-data-unread-p (car data))
6437                               (setq result (car data)
6438                                     data nil)))
6439                           (setq data (cdr data)))
6440                         result)
6441                     (car data)))
6442         (goto-char (gnus-data-pos result))
6443         (gnus-data-number result)))))
6444
6445 (defun gnus-summary-find-prev (&optional unread article)
6446   (let* ((eobp (eobp))
6447          (article (or article (gnus-summary-article-number)))
6448          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6449          result)
6450     (when (and (not eobp)
6451                (or (not gnus-summary-check-current)
6452                    (not unread)
6453                    (not (gnus-data-unread-p (car data)))))
6454       (setq data (cdr data)))
6455     (when (setq result
6456                 (if unread
6457                     (progn
6458                       (while data
6459                         (unless (memq (gnus-data-number (car data))
6460                                       (cond
6461                                        ((eq gnus-auto-goto-ignores
6462                                             'always-undownloaded)
6463                                         gnus-newsgroup-undownloaded)
6464                                        (gnus-plugged
6465                                         nil)
6466                                        ((eq gnus-auto-goto-ignores
6467                                             'unfetched)
6468                                         gnus-newsgroup-unfetched)
6469                                        ((eq gnus-auto-goto-ignores
6470                                             'undownloaded)
6471                                         gnus-newsgroup-undownloaded)))
6472                           (when (gnus-data-unread-p (car data))
6473                             (setq result (car data)
6474                                   data nil)))
6475                         (setq data (cdr data)))
6476                       result)
6477                   (car data)))
6478       (goto-char (gnus-data-pos result))
6479       (gnus-data-number result))))
6480
6481 (defun gnus-summary-find-subject (subject &optional unread backward article)
6482   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6483          (article (or article (gnus-summary-article-number)))
6484          (articles (gnus-data-list backward))
6485          (arts (gnus-data-find-list article articles))
6486          result)
6487     (when (or (not gnus-summary-check-current)
6488               (not unread)
6489               (not (gnus-data-unread-p (car arts))))
6490       (setq arts (cdr arts)))
6491     (while arts
6492       (and (or (not unread)
6493                (gnus-data-unread-p (car arts)))
6494            (vectorp (gnus-data-header (car arts)))
6495            (gnus-subject-equal
6496             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6497            (setq result (car arts)
6498                  arts nil))
6499       (setq arts (cdr arts)))
6500     (and result
6501          (goto-char (gnus-data-pos result))
6502          (gnus-data-number result))))
6503
6504 (defun gnus-summary-search-forward (&optional unread subject backward)
6505   "Search forward for an article.
6506 If UNREAD, look for unread articles.  If SUBJECT, look for
6507 articles with that subject.  If BACKWARD, search backward instead."
6508   (cond (subject (gnus-summary-find-subject subject unread backward))
6509         (backward (gnus-summary-find-prev unread))
6510         (t (gnus-summary-find-next unread))))
6511
6512 (defun gnus-recenter (&optional n)
6513   "Center point in window and redisplay frame.
6514 Also do horizontal recentering."
6515   (interactive "P")
6516   (when (and gnus-auto-center-summary
6517              (not (eq gnus-auto-center-summary 'vertical)))
6518     (gnus-horizontal-recenter))
6519   (recenter n))
6520
6521 (defun gnus-summary-recenter ()
6522   "Center point in the summary window.
6523 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6524 displayed, no centering will be performed."
6525   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6526   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6527   (interactive)
6528   ;; The user has to want it.
6529   (when gnus-auto-center-summary
6530     (let* ((top (cond ((< (window-height) 4) 0)
6531                       ((< (window-height) 7) 1)
6532                       (t (if (numberp gnus-auto-center-summary)
6533                              gnus-auto-center-summary
6534                            (/ (1- (window-height)) 2)))))
6535            (height (1- (window-height)))
6536            (bottom (save-excursion (goto-char (point-max))
6537                                    (forward-line (- height))
6538                                    (point)))
6539            (window (get-buffer-window (current-buffer))))
6540       (when (get-buffer-window gnus-article-buffer)
6541         ;; Only do recentering when the article buffer is displayed,
6542         ;; Set the window start to either `bottom', which is the biggest
6543         ;; possible valid number, or the second line from the top,
6544         ;; whichever is the least.
6545         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6546           (if (> bottom top-pos)
6547               ;; Keep the second line from the top visible
6548               (set-window-start window top-pos t)
6549             ;; Try to keep the bottom line visible; if it's partially
6550             ;; obscured, either scroll one more line to make it fully
6551             ;; visible, or revert to using TOP-POS.
6552             (save-excursion
6553               (goto-char (point-max))
6554               (forward-line -1)
6555               (let ((last-line-start (point)))
6556                 (goto-char bottom)
6557                 (set-window-start window (point) t)
6558                 (when (not (pos-visible-in-window-p last-line-start window))
6559                   (forward-line 1)
6560                   (set-window-start window (min (point) top-pos) t)))))))
6561       ;; Do horizontal recentering while we're at it.
6562       (when (and (get-buffer-window (current-buffer) t)
6563                  (not (eq gnus-auto-center-summary 'vertical)))
6564         (let ((selected (selected-window)))
6565           (select-window (get-buffer-window (current-buffer) t))
6566           (gnus-summary-position-point)
6567           (gnus-horizontal-recenter)
6568           (select-window selected))))))
6569
6570 (defun gnus-summary-jump-to-group (newsgroup)
6571   "Move point to NEWSGROUP in group mode buffer."
6572   ;; Keep update point of group mode buffer if visible.
6573   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6574       (save-window-excursion
6575         ;; Take care of tree window mode.
6576         (when (get-buffer-window gnus-group-buffer)
6577           (pop-to-buffer gnus-group-buffer))
6578         (gnus-group-jump-to-group newsgroup))
6579     (save-excursion
6580       ;; Take care of tree window mode.
6581       (if (get-buffer-window gnus-group-buffer)
6582           (pop-to-buffer gnus-group-buffer)
6583         (set-buffer gnus-group-buffer))
6584       (gnus-group-jump-to-group newsgroup))))
6585
6586 ;; This function returns a list of article numbers based on the
6587 ;; difference between the ranges of read articles in this group and
6588 ;; the range of active articles.
6589 (defun gnus-list-of-unread-articles (group)
6590   (let* ((read (gnus-info-read (gnus-get-info group)))
6591          (active (or (gnus-active group) (gnus-activate-group group)))
6592          (last (or (cdr active)
6593                    (error "Group %s couldn't be activated " group)))
6594          first nlast unread)
6595     ;; If none are read, then all are unread.
6596     (if (not read)
6597         (setq first (car active))
6598       ;; If the range of read articles is a single range, then the
6599       ;; first unread article is the article after the last read
6600       ;; article.  Sounds logical, doesn't it?
6601       (if (and (not (listp (cdr read)))
6602                (or (< (car read) (car active))
6603                    (progn (setq read (list read))
6604                           nil)))
6605           (setq first (max (car active) (1+ (cdr read))))
6606         ;; `read' is a list of ranges.
6607         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6608                                   (caar read)))
6609                   1)
6610           (setq first (car active)))
6611         (while read
6612           (when first
6613             (while (< first nlast)
6614               (setq unread (cons first unread)
6615                     first (1+ first))))
6616           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6617           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6618           (setq read (cdr read)))))
6619     ;; And add the last unread articles.
6620     (while (<= first last)
6621       (setq unread (cons first unread)
6622             first (1+ first)))
6623     ;; Return the list of unread articles.
6624     (delq 0 (nreverse unread))))
6625
6626 (defun gnus-list-of-read-articles (group)
6627   "Return a list of unread, unticked and non-dormant articles."
6628   (let* ((info (gnus-get-info group))
6629          (marked (gnus-info-marks info))
6630          (active (gnus-active group)))
6631     (and info active
6632          (gnus-list-range-difference
6633           (gnus-list-range-difference
6634            (gnus-sorted-complement
6635             (gnus-uncompress-range active)
6636             (gnus-list-of-unread-articles group))
6637            (cdr (assq 'dormant marked)))
6638           (cdr (assq 'tick marked))))))
6639
6640 ;; This function returns a sequence of article numbers based on the
6641 ;; difference between the ranges of read articles in this group and
6642 ;; the range of active articles.
6643 (defun gnus-sequence-of-unread-articles (group)
6644   (let* ((read (gnus-info-read (gnus-get-info group)))
6645          (active (or (gnus-active group) (gnus-activate-group group)))
6646          (last (cdr active))
6647          first nlast unread)
6648     ;; If none are read, then all are unread.
6649     (if (not read)
6650         (setq first (car active))
6651       ;; If the range of read articles is a single range, then the
6652       ;; first unread article is the article after the last read
6653       ;; article.  Sounds logical, doesn't it?
6654       (if (and (not (listp (cdr read)))
6655                (or (< (car read) (car active))
6656                    (progn (setq read (list read))
6657                           nil)))
6658           (setq first (max (car active) (1+ (cdr read))))
6659         ;; `read' is a list of ranges.
6660         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6661                                   (caar read)))
6662                   1)
6663           (setq first (car active)))
6664         (while read
6665           (when first
6666             (push (cons first nlast) unread))
6667           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6668           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6669           (setq read (cdr read)))))
6670     ;; And add the last unread articles.
6671     (cond ((not (and first last))
6672            nil)
6673           ((< first last)
6674            (push (cons first last) unread))
6675           ((= first last)
6676            (push first unread)))
6677     ;; Return the sequence of unread articles.
6678     (delq 0 (nreverse unread))))
6679
6680 ;; Various summary commands
6681
6682 (defun gnus-summary-select-article-buffer ()
6683   "Reconfigure windows to show article buffer."
6684   (interactive)
6685   (if (not (gnus-buffer-live-p gnus-article-buffer))
6686       (error "There is no article buffer for this summary buffer")
6687     (gnus-configure-windows 'article)
6688     (select-window (get-buffer-window gnus-article-buffer))))
6689
6690 (defun gnus-summary-universal-argument (arg)
6691   "Perform any operation on all articles that are process/prefixed."
6692   (interactive "P")
6693   (let ((articles (gnus-summary-work-articles arg))
6694         func article)
6695     (if (eq
6696          (setq
6697           func
6698           (key-binding
6699            (read-key-sequence
6700             (substitute-command-keys
6701              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6702          'undefined)
6703         (gnus-error 1 "Undefined key")
6704       (save-excursion
6705         (while articles
6706           (gnus-summary-goto-subject (setq article (pop articles)))
6707           (let (gnus-newsgroup-processable)
6708             (command-execute func))
6709           (gnus-summary-remove-process-mark article)))))
6710   (gnus-summary-position-point))
6711
6712 (defun gnus-summary-toggle-truncation (&optional arg)
6713   "Toggle truncation of summary lines.
6714 With ARG, turn line truncation on if ARG is positive."
6715   (interactive "P")
6716   (setq truncate-lines
6717         (if (null arg) (not truncate-lines)
6718           (> (prefix-numeric-value arg) 0)))
6719   (redraw-display))
6720
6721 (defun gnus-summary-find-for-reselect ()
6722   "Return the number of an article to stay on across a reselect.
6723 The current article is considered, then following articles, then previous
6724 articles.  An article is sought which is not cancelled and isn't a temporary
6725 insertion from another group.  If there's no such then return a dummy 0."
6726   (let (found)
6727     (dolist (rev '(nil t))
6728       (unless found      ; don't demand the reverse list if we don't need it
6729         (let ((data (gnus-data-find-list
6730                      (gnus-summary-article-number) (gnus-data-list rev))))
6731           (while (and data (not found))
6732             (if (and (< 0 (gnus-data-number (car data)))
6733                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6734                 (setq found (gnus-data-number (car data))))
6735             (setq data (cdr data))))))
6736     (or found 0)))
6737
6738 (defun gnus-summary-reselect-current-group (&optional all rescan)
6739   "Exit and then reselect the current newsgroup.
6740 The prefix argument ALL means to select all articles."
6741   (interactive "P")
6742   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6743     (error "Ephemeral groups can't be reselected"))
6744   (let ((current-subject (gnus-summary-find-for-reselect))
6745         (group gnus-newsgroup-name))
6746     (setq gnus-newsgroup-begin nil)
6747     (gnus-summary-exit nil 'leave-hidden)
6748     ;; We have to adjust the point of group mode buffer because
6749     ;; point was moved to the next unread newsgroup by exiting.
6750     (gnus-summary-jump-to-group group)
6751     (when rescan
6752       (save-excursion
6753         (gnus-group-get-new-news-this-group 1)))
6754     (gnus-group-read-group all t)
6755     (gnus-summary-goto-subject current-subject nil t)))
6756
6757 (defun gnus-summary-rescan-group (&optional all)
6758   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6759   (interactive "P")
6760   (gnus-summary-reselect-current-group all t))
6761
6762 (defun gnus-summary-update-info (&optional non-destructive)
6763   (save-excursion
6764     (let ((group gnus-newsgroup-name))
6765       (when group
6766         (when gnus-newsgroup-kill-headers
6767           (setq gnus-newsgroup-killed
6768                 (gnus-compress-sequence
6769                  (gnus-sorted-union
6770                   (gnus-list-range-intersection
6771                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6772                   gnus-newsgroup-unreads)
6773                  t)))
6774         (unless (listp (cdr gnus-newsgroup-killed))
6775           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6776         (let ((headers gnus-newsgroup-headers))
6777           ;; Set the new ranges of read articles.
6778           (with-current-buffer gnus-group-buffer
6779             (gnus-undo-force-boundary))
6780           (gnus-update-read-articles
6781            group (gnus-sorted-union
6782                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6783           ;; Set the current article marks.
6784           (let ((gnus-newsgroup-scored
6785                  (if (and (not gnus-save-score)
6786                           (not non-destructive))
6787                      nil
6788                    gnus-newsgroup-scored)))
6789             (save-excursion
6790               (gnus-update-marks)))
6791           ;; Do the cross-ref thing.
6792           (when gnus-use-cross-reference
6793             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6794           ;; Do not switch windows but change the buffer to work.
6795           (set-buffer gnus-group-buffer)
6796           (unless (gnus-ephemeral-group-p group)
6797             (gnus-group-update-group group)))))))
6798
6799 (defun gnus-summary-save-newsrc (&optional force)
6800   "Save the current number of read/marked articles in the dribble buffer.
6801 The dribble buffer will then be saved.
6802 If FORCE (the prefix), also save the .newsrc file(s)."
6803   (interactive "P")
6804   (gnus-summary-update-info t)
6805   (if force
6806       (gnus-save-newsrc-file)
6807     (gnus-dribble-save)))
6808
6809 (defun gnus-summary-exit (&optional temporary leave-hidden)
6810   "Exit reading current newsgroup, and then return to group selection mode.
6811 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6812   (interactive)
6813   (gnus-set-global-variables)
6814   (when (gnus-buffer-live-p gnus-article-buffer)
6815     (save-excursion
6816       (set-buffer gnus-article-buffer)
6817       (mm-destroy-parts gnus-article-mime-handles)
6818       ;; Set it to nil for safety reason.
6819       (setq gnus-article-mime-handle-alist nil)
6820       (setq gnus-article-mime-handles nil)))
6821   (gnus-kill-save-kill-buffer)
6822   (gnus-async-halt-prefetch)
6823   (let* ((group gnus-newsgroup-name)
6824          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6825          (gnus-group-is-exiting-p t)
6826          (mode major-mode)
6827          (group-point nil)
6828          (buf (current-buffer)))
6829     (unless quit-config
6830       ;; Do adaptive scoring, and possibly save score files.
6831       (when gnus-newsgroup-adaptive
6832         (gnus-score-adaptive))
6833       (when gnus-use-scoring
6834         (gnus-score-save)))
6835     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6836     ;; If we have several article buffers, we kill them at exit.
6837     (unless gnus-single-article-buffer
6838       (gnus-kill-buffer gnus-original-article-buffer)
6839       (setq gnus-article-current nil))
6840     (when gnus-use-cache
6841       (gnus-cache-possibly-remove-articles)
6842       (gnus-cache-save-buffers))
6843     (gnus-async-prefetch-remove-group group)
6844     (when gnus-suppress-duplicates
6845       (gnus-dup-enter-articles))
6846     (when gnus-use-trees
6847       (gnus-tree-close group))
6848     (when gnus-use-cache
6849       (gnus-cache-write-active))
6850     ;; Remove entries for this group.
6851     (nnmail-purge-split-history (gnus-group-real-name group))
6852     ;; Make all changes in this group permanent.
6853     (unless quit-config
6854       (gnus-run-hooks 'gnus-exit-group-hook)
6855       (gnus-summary-update-info))
6856     (gnus-close-group group)
6857     ;; Make sure where we were, and go to next newsgroup.
6858     (set-buffer gnus-group-buffer)
6859     (unless quit-config
6860       (gnus-group-jump-to-group group))
6861     (gnus-run-hooks 'gnus-summary-exit-hook)
6862     (unless (or quit-config
6863                 ;; If this group has disappeared from the summary
6864                 ;; buffer, don't skip forwards.
6865                 (not (string= group (gnus-group-group-name))))
6866       (gnus-group-next-unread-group 1))
6867     (setq group-point (point))
6868     (if temporary
6869         nil                             ;Nothing to do.
6870       ;; If we have several article buffers, we kill them at exit.
6871       (unless gnus-single-article-buffer
6872         (gnus-kill-buffer gnus-article-buffer)
6873         (gnus-kill-buffer gnus-original-article-buffer)
6874         (setq gnus-article-current nil))
6875       (set-buffer buf)
6876       (if (not gnus-kill-summary-on-exit)
6877           (progn
6878             (gnus-deaden-summary)
6879             (setq mode nil))
6880         ;; We set all buffer-local variables to nil.  It is unclear why
6881         ;; this is needed, but if we don't, buffer-local variables are
6882         ;; not garbage-collected, it seems.  This would the lead to en
6883         ;; ever-growing Emacs.
6884         (gnus-summary-clear-local-variables)
6885         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6886           (gnus-summary-clear-local-variables))
6887         (when (get-buffer gnus-article-buffer)
6888           (bury-buffer gnus-article-buffer))
6889         ;; Return to group mode buffer.
6890         (when (eq mode 'gnus-summary-mode)
6891           (gnus-kill-buffer buf)))
6892       (setq gnus-current-select-method gnus-select-method)
6893       (set-buffer gnus-group-buffer)
6894       (if quit-config
6895           (gnus-handle-ephemeral-exit quit-config)
6896         (goto-char group-point)
6897         ;; If gnus-group-buffer is already displayed, make sure we also move
6898         ;; the cursor in the window that displays it.
6899         (let ((win (get-buffer-window (current-buffer) 0)))
6900           (if win (set-window-point win (point))))
6901         (unless leave-hidden
6902           (gnus-configure-windows 'group 'force)))
6903       ;; Clear the current group name.
6904       (unless quit-config
6905         (setq gnus-newsgroup-name nil)))))
6906
6907 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6908 (defun gnus-summary-exit-no-update (&optional no-questions)
6909   "Quit reading current newsgroup without updating read article info."
6910   (interactive)
6911   (let* ((group gnus-newsgroup-name)
6912          (gnus-group-is-exiting-p t)
6913          (gnus-group-is-exiting-without-update-p t)
6914          (quit-config (gnus-group-quit-config group)))
6915     (when (or no-questions
6916               gnus-expert-user
6917               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6918       (gnus-async-halt-prefetch)
6919       (run-hooks 'gnus-summary-prepare-exit-hook)
6920       (when (gnus-buffer-live-p gnus-article-buffer)
6921         (save-excursion
6922           (set-buffer gnus-article-buffer)
6923           (mm-destroy-parts gnus-article-mime-handles)
6924           ;; Set it to nil for safety reason.
6925           (setq gnus-article-mime-handle-alist nil)
6926           (setq gnus-article-mime-handles nil)))
6927       ;; If we have several article buffers, we kill them at exit.
6928       (unless gnus-single-article-buffer
6929         (gnus-kill-buffer gnus-article-buffer)
6930         (gnus-kill-buffer gnus-original-article-buffer)
6931         (setq gnus-article-current nil))
6932       (if (not gnus-kill-summary-on-exit)
6933           (gnus-deaden-summary)
6934         (gnus-close-group group)
6935         (gnus-summary-clear-local-variables)
6936         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6937           (gnus-summary-clear-local-variables))
6938         (gnus-kill-buffer gnus-summary-buffer))
6939       (unless gnus-single-article-buffer
6940         (setq gnus-article-current nil))
6941       (when gnus-use-trees
6942         (gnus-tree-close group))
6943       (gnus-async-prefetch-remove-group group)
6944       (when (get-buffer gnus-article-buffer)
6945         (bury-buffer gnus-article-buffer))
6946       ;; Return to the group buffer.
6947       (gnus-configure-windows 'group 'force)
6948       ;; Clear the current group name.
6949       (setq gnus-newsgroup-name nil)
6950       (unless (gnus-ephemeral-group-p group)
6951         (gnus-group-update-group group))
6952       (when (equal (gnus-group-group-name) group)
6953         (gnus-group-next-unread-group 1))
6954       (when quit-config
6955         (gnus-handle-ephemeral-exit quit-config)))))
6956
6957 (defun gnus-handle-ephemeral-exit (quit-config)
6958   "Handle movement when leaving an ephemeral group.
6959 The state which existed when entering the ephemeral is reset."
6960   (if (not (buffer-name (car quit-config)))
6961       (gnus-configure-windows 'group 'force)
6962     (set-buffer (car quit-config))
6963     (cond ((eq major-mode 'gnus-summary-mode)
6964            (gnus-set-global-variables))
6965           ((eq major-mode 'gnus-article-mode)
6966            (save-excursion
6967              ;; The `gnus-summary-buffer' variable may point
6968              ;; to the old summary buffer when using a single
6969              ;; article buffer.
6970              (unless (gnus-buffer-live-p gnus-summary-buffer)
6971                (set-buffer gnus-group-buffer))
6972              (set-buffer gnus-summary-buffer)
6973              (gnus-set-global-variables))))
6974     (if (or (eq (cdr quit-config) 'article)
6975             (eq (cdr quit-config) 'pick))
6976         (progn
6977           ;; The current article may be from the ephemeral group
6978           ;; thus it is best that we reload this article
6979           ;;
6980           ;; If we're exiting from a large digest, this can be
6981           ;; extremely slow.  So, it's better not to reload it. -- jh.
6982           ;;(gnus-summary-show-article)
6983           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6984               (gnus-configure-windows 'pick 'force)
6985             (gnus-configure-windows (cdr quit-config) 'force)))
6986       (gnus-configure-windows (cdr quit-config) 'force))
6987     (when (eq major-mode 'gnus-summary-mode)
6988       (gnus-summary-next-subject 1 nil t)
6989       (gnus-summary-recenter)
6990       (gnus-summary-position-point))))
6991
6992 ;;; Dead summaries.
6993
6994 (defvar gnus-dead-summary-mode-map nil)
6995
6996 (unless gnus-dead-summary-mode-map
6997   (setq gnus-dead-summary-mode-map (make-keymap))
6998   (suppress-keymap gnus-dead-summary-mode-map)
6999   (substitute-key-definition
7000    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7001   (dolist (key '("\C-d" "\r" "\177" [delete]))
7002     (define-key gnus-dead-summary-mode-map
7003       key 'gnus-summary-wake-up-the-dead))
7004   (dolist (key '("q" "Q"))
7005     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7006
7007 (defvar gnus-dead-summary-mode nil
7008   "Minor mode for Gnus summary buffers.")
7009
7010 (defun gnus-dead-summary-mode (&optional arg)
7011   "Minor mode for Gnus summary buffers."
7012   (interactive "P")
7013   (when (eq major-mode 'gnus-summary-mode)
7014     (make-local-variable 'gnus-dead-summary-mode)
7015     (setq gnus-dead-summary-mode
7016           (if (null arg) (not gnus-dead-summary-mode)
7017             (> (prefix-numeric-value arg) 0)))
7018     (when gnus-dead-summary-mode
7019       (add-minor-mode
7020        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7021
7022 (defun gnus-deaden-summary ()
7023   "Make the current summary buffer into a dead summary buffer."
7024   ;; Kill any previous dead summary buffer.
7025   (when (and gnus-dead-summary
7026              (buffer-name gnus-dead-summary))
7027     (with-current-buffer gnus-dead-summary
7028       (when gnus-dead-summary-mode
7029         (kill-buffer (current-buffer)))))
7030   ;; Make this the current dead summary.
7031   (setq gnus-dead-summary (current-buffer))
7032   (gnus-dead-summary-mode 1)
7033   (let ((name (buffer-name)))
7034     (when (string-match "Summary" name)
7035       (rename-buffer
7036        (concat (substring name 0 (match-beginning 0)) "Dead "
7037                (substring name (match-beginning 0)))
7038        t)
7039       (bury-buffer))))
7040
7041 (defun gnus-kill-or-deaden-summary (buffer)
7042   "Kill or deaden the summary BUFFER."
7043   (save-excursion
7044     (when (and (buffer-name buffer)
7045                (not gnus-single-article-buffer))
7046       (with-current-buffer buffer
7047         (gnus-kill-buffer gnus-article-buffer)
7048         (gnus-kill-buffer gnus-original-article-buffer)))
7049     (cond
7050      ;; Kill the buffer.
7051      (gnus-kill-summary-on-exit
7052       (when (and gnus-use-trees
7053                  (gnus-buffer-exists-p buffer))
7054         (save-excursion
7055           (set-buffer buffer)
7056           (gnus-tree-close gnus-newsgroup-name)))
7057       (gnus-kill-buffer buffer))
7058      ;; Deaden the buffer.
7059      ((gnus-buffer-exists-p buffer)
7060       (save-excursion
7061         (set-buffer buffer)
7062         (gnus-deaden-summary))))))
7063
7064 (defun gnus-summary-wake-up-the-dead (&rest args)
7065   "Wake up the dead summary buffer."
7066   (interactive)
7067   (gnus-dead-summary-mode -1)
7068   (let ((name (buffer-name)))
7069     (when (string-match "Dead " name)
7070       (rename-buffer
7071        (concat (substring name 0 (match-beginning 0))
7072                (substring name (match-end 0)))
7073        t)))
7074   (gnus-message 3 "This dead summary is now alive again"))
7075
7076 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7077 (defun gnus-summary-fetch-faq (&optional faq-dir)
7078   "Fetch the FAQ for the current group.
7079 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7080 in."
7081   (interactive
7082    (list
7083     (when current-prefix-arg
7084       (completing-read
7085        "FAQ dir: " (and (listp gnus-group-faq-directory)
7086                         (mapcar 'list
7087                                 gnus-group-faq-directory))))))
7088   (let (gnus-faq-buffer)
7089     (when (setq gnus-faq-buffer
7090                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7091       (gnus-configure-windows 'summary-faq))))
7092
7093 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7094 (defun gnus-summary-describe-group (&optional force)
7095   "Describe the current newsgroup."
7096   (interactive "P")
7097   (gnus-group-describe-group force gnus-newsgroup-name))
7098
7099 (defun gnus-summary-describe-briefly ()
7100   "Describe summary mode commands briefly."
7101   (interactive)
7102   (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")))
7103
7104 ;; Walking around group mode buffer from summary mode.
7105
7106 (defun gnus-summary-next-group (&optional no-article target-group backward)
7107   "Exit current newsgroup and then select next unread newsgroup.
7108 If prefix argument NO-ARTICLE is non-nil, no article is selected
7109 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7110 previous group instead."
7111   (interactive "P")
7112   ;; Stop pre-fetching.
7113   (gnus-async-halt-prefetch)
7114   (let ((current-group gnus-newsgroup-name)
7115         (current-buffer (current-buffer))
7116         entered)
7117     ;; First we semi-exit this group to update Xrefs and all variables.
7118     ;; We can't do a real exit, because the window conf must remain
7119     ;; the same in case the user is prompted for info, and we don't
7120     ;; want the window conf to change before that...
7121     (gnus-summary-exit t)
7122     (while (not entered)
7123       ;; Then we find what group we are supposed to enter.
7124       (set-buffer gnus-group-buffer)
7125       (gnus-group-jump-to-group current-group)
7126       (setq target-group
7127             (or target-group
7128                 (if (eq gnus-keep-same-level 'best)
7129                     (gnus-summary-best-group gnus-newsgroup-name)
7130                   (gnus-summary-search-group backward gnus-keep-same-level))))
7131       (if (not target-group)
7132           ;; There are no further groups, so we return to the group
7133           ;; buffer.
7134           (progn
7135             (gnus-message 5 "Returning to the group buffer")
7136             (setq entered t)
7137             (when (gnus-buffer-live-p current-buffer)
7138               (set-buffer current-buffer)
7139               (gnus-summary-exit))
7140             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7141         ;; We try to enter the target group.
7142         (gnus-group-jump-to-group target-group)
7143         (let ((unreads (gnus-group-group-unread)))
7144           (if (and (or (eq t unreads)
7145                        (and unreads (not (zerop unreads))))
7146                    (gnus-summary-read-group
7147                     target-group nil no-article
7148                     (and (buffer-name current-buffer) current-buffer)
7149                     nil backward))
7150               (setq entered t)
7151             (setq current-group target-group
7152                   target-group nil)))))))
7153
7154 (defun gnus-summary-prev-group (&optional no-article)
7155   "Exit current newsgroup and then select previous unread newsgroup.
7156 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7157   (interactive "P")
7158   (gnus-summary-next-group no-article nil t))
7159
7160 ;; Walking around summary lines.
7161
7162 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7163   "Go to the first subject satisfying any non-nil constraint.
7164 If UNREAD is non-nil, the article should be unread.
7165 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7166 If UNSEEN is non-nil, the article should be unseen.
7167 Returns the article selected or nil if there are no matching articles."
7168   (interactive "P")
7169   (cond
7170    ;; Empty summary.
7171    ((null gnus-newsgroup-data)
7172     (gnus-message 3 "No articles in the group")
7173     nil)
7174    ;; Pick the first article.
7175    ((not (or unread undownloaded unseen))
7176     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7177     (gnus-data-number (car gnus-newsgroup-data)))
7178    ;; Find the first unread article.
7179    (t
7180     (let ((data gnus-newsgroup-data))
7181       (while (and data
7182                   (let ((num (gnus-data-number (car data))))
7183                     (or (memq num gnus-newsgroup-unfetched)
7184                         (not (or (and unread
7185                                       (memq num gnus-newsgroup-unreads))
7186                                  (and undownloaded
7187                                       (memq num gnus-newsgroup-undownloaded))
7188                                  (and unseen
7189                                       (memq num gnus-newsgroup-unseen)))))))
7190         (setq data (cdr data)))
7191       (prog1
7192           (if data
7193               (progn
7194                 (goto-char (gnus-data-pos (car data)))
7195                 (gnus-data-number (car data)))
7196             (gnus-message 3 "No more%s articles"
7197                           (let* ((r (when unread " unread"))
7198                                  (d (when undownloaded " undownloaded"))
7199                                  (s (when unseen " unseen"))
7200                                  (l (delq nil (list r d s))))
7201                             (cond ((= 3 (length l))
7202                                    (concat r "," d ", or" s))
7203                                   ((= 2 (length l))
7204                                    (concat (car l) ", or" (cadr l)))
7205                                   ((= 1 (length l))
7206                                    (car l))
7207                                   (t
7208                                    ""))))
7209             nil
7210             )
7211         (gnus-summary-position-point))))))
7212
7213 (defun gnus-summary-next-subject (n &optional unread dont-display)
7214   "Go to next N'th summary line.
7215 If N is negative, go to the previous N'th subject line.
7216 If UNREAD is non-nil, only unread articles are selected.
7217 The difference between N and the actual number of steps taken is
7218 returned."
7219   (interactive "p")
7220   (let ((backward (< n 0))
7221         (n (abs n)))
7222     (while (and (> n 0)
7223                 (if backward
7224                     (gnus-summary-find-prev unread)
7225                   (gnus-summary-find-next unread)))
7226       (unless (zerop (setq n (1- n)))
7227         (gnus-summary-show-thread)))
7228     (when (/= 0 n)
7229       (gnus-message 7 "No more%s articles"
7230                     (if unread " unread" "")))
7231     (unless dont-display
7232       (gnus-summary-recenter)
7233       (gnus-summary-position-point))
7234     n))
7235
7236 (defun gnus-summary-next-unread-subject (n)
7237   "Go to next N'th unread summary line."
7238   (interactive "p")
7239   (gnus-summary-next-subject n t))
7240
7241 (defun gnus-summary-prev-subject (n &optional unread)
7242   "Go to previous N'th summary line.
7243 If optional argument UNREAD is non-nil, only unread article is selected."
7244   (interactive "p")
7245   (gnus-summary-next-subject (- n) unread))
7246
7247 (defun gnus-summary-prev-unread-subject (n)
7248   "Go to previous N'th unread summary line."
7249   (interactive "p")
7250   (gnus-summary-next-subject (- n) t))
7251
7252 (defun gnus-summary-goto-subjects (articles)
7253   "Insert the subject header for ARTICLES in the current buffer."
7254   (save-excursion
7255     (dolist (article articles)
7256       (gnus-summary-goto-subject article t)))
7257   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7258   (gnus-summary-position-point))
7259
7260 (defun gnus-summary-goto-subject (article &optional force silent)
7261   "Go the subject line of ARTICLE.
7262 If FORCE, also allow jumping to articles not currently shown."
7263   (interactive "nArticle number: ")
7264   (unless (numberp article)
7265     (error "Article %s is not a number" article))
7266   (let ((b (point))
7267         (data (gnus-data-find article)))
7268     ;; We read in the article if we have to.
7269     (and (not data)
7270          force
7271          (gnus-summary-insert-subject
7272           article
7273           (if (or (numberp force) (vectorp force)) force)
7274           t)
7275          (setq data (gnus-data-find article)))
7276     (goto-char b)
7277     (if (not data)
7278         (progn
7279           (unless silent
7280             (gnus-message 3 "Can't find article %d" article))
7281           nil)
7282       (let ((pt (gnus-data-pos data)))
7283         (goto-char pt)
7284         (gnus-summary-set-article-display-arrow pt))
7285       (gnus-summary-position-point)
7286       article)))
7287
7288 ;; Walking around summary lines with displaying articles.
7289
7290 (defun gnus-summary-expand-window (&optional arg)
7291   "Make the summary buffer take up the entire Emacs frame.
7292 Given a prefix, will force an `article' buffer configuration."
7293   (interactive "P")
7294   (if arg
7295       (gnus-configure-windows 'article 'force)
7296     (gnus-configure-windows 'summary 'force)))
7297
7298 (defun gnus-summary-display-article (article &optional all-header)
7299   "Display ARTICLE in article buffer."
7300   (when (gnus-buffer-live-p gnus-article-buffer)
7301     (with-current-buffer gnus-article-buffer
7302       (mm-enable-multibyte)))
7303   (gnus-set-global-variables)
7304   (when (gnus-buffer-live-p gnus-article-buffer)
7305     (with-current-buffer gnus-article-buffer
7306       (setq gnus-article-charset gnus-newsgroup-charset)
7307       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7308       (mm-enable-multibyte)))
7309   (if (null article)
7310       nil
7311     (prog1
7312         (if gnus-summary-display-article-function
7313             (funcall gnus-summary-display-article-function article all-header)
7314           (gnus-article-prepare article all-header))
7315       (gnus-run-hooks 'gnus-select-article-hook)
7316       (when (and gnus-current-article
7317                  (not (zerop gnus-current-article)))
7318         (gnus-summary-goto-subject gnus-current-article))
7319       (gnus-summary-recenter)
7320       (when (and gnus-use-trees gnus-show-threads)
7321         (gnus-possibly-generate-tree article)
7322         (gnus-highlight-selected-tree article))
7323       ;; Successfully display article.
7324       (gnus-article-set-window-start
7325        (cdr (assq article gnus-newsgroup-bookmarks))))))
7326
7327 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7328   "Select the current article.
7329 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7330 non-nil, the article will be re-fetched even if it already present in
7331 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7332 be displayed."
7333   ;; Make sure we are in the summary buffer to work around bbdb bug.
7334   (unless (eq major-mode 'gnus-summary-mode)
7335     (set-buffer gnus-summary-buffer))
7336   (let ((article (or article (gnus-summary-article-number)))
7337         (all-headers (not (not all-headers))) ;Must be t or nil.
7338         gnus-summary-display-article-function)
7339     (and (not pseudo)
7340          (gnus-summary-article-pseudo-p article)
7341          (error "This is a pseudo-article"))
7342     (save-excursion
7343       (set-buffer gnus-summary-buffer)
7344       (if (or (and gnus-single-article-buffer
7345                    (or (null gnus-current-article)
7346                        (null gnus-article-current)
7347                        (null (get-buffer gnus-article-buffer))
7348                        (not (eq article (cdr gnus-article-current)))
7349                        (not (equal (car gnus-article-current)
7350                                    gnus-newsgroup-name))))
7351               (and (not gnus-single-article-buffer)
7352                    (or (null gnus-current-article)
7353                        (not (eq gnus-current-article article))))
7354               force)
7355           ;; The requested article is different from the current article.
7356           (progn
7357             (gnus-summary-display-article article all-headers)
7358             (when (gnus-buffer-live-p gnus-article-buffer)
7359               (with-current-buffer gnus-article-buffer
7360                 (if (not gnus-article-decoded-p) ;; a local variable
7361                     (mm-disable-multibyte))))
7362             (gnus-article-set-window-start
7363              (cdr (assq article gnus-newsgroup-bookmarks)))
7364             article)
7365         'old))))
7366
7367 (defun gnus-summary-force-verify-and-decrypt ()
7368   "Display buttons for signed/encrypted parts and verify/decrypt them."
7369   (interactive)
7370   (let ((mm-verify-option 'known)
7371         (mm-decrypt-option 'known)
7372         (gnus-article-emulate-mime t)
7373         (gnus-buttonized-mime-types (append (list "multipart/signed"
7374                                                   "multipart/encrypted")
7375                                             gnus-buttonized-mime-types)))
7376     (gnus-summary-select-article nil 'force)))
7377
7378 (defun gnus-summary-set-current-mark (&optional current-mark)
7379   "Obsolete function."
7380   nil)
7381
7382 (defun gnus-summary-next-article (&optional unread subject backward push)
7383   "Select the next article.
7384 If UNREAD, only unread articles are selected.
7385 If SUBJECT, only articles with SUBJECT are selected.
7386 If BACKWARD, the previous article is selected instead of the next."
7387   (interactive "P")
7388   (cond
7389    ;; Is there such an article?
7390    ((and (gnus-summary-search-forward unread subject backward)
7391          (or (gnus-summary-display-article (gnus-summary-article-number))
7392              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7393     (gnus-summary-position-point))
7394    ;; If not, we try the first unread, if that is wanted.
7395    ((and subject
7396          gnus-auto-select-same
7397          (gnus-summary-first-unread-article))
7398     (gnus-summary-position-point)
7399     (gnus-message 6 "Wrapped"))
7400    ;; Try to get next/previous article not displayed in this group.
7401    ((and gnus-auto-extend-newsgroup
7402          (not unread) (not subject))
7403     (gnus-summary-goto-article
7404      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7405      nil (count-lines (point-min) (point))))
7406    ;; Go to next/previous group.
7407    (t
7408     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7409       (gnus-summary-jump-to-group gnus-newsgroup-name))
7410     (let ((cmd last-command-char)
7411           (point
7412            (with-current-buffer gnus-group-buffer
7413              (point)))
7414           (group
7415            (if (eq gnus-keep-same-level 'best)
7416                (gnus-summary-best-group gnus-newsgroup-name)
7417              (gnus-summary-search-group backward gnus-keep-same-level))))
7418       ;; For some reason, the group window gets selected.  We change
7419       ;; it back.
7420       (select-window (get-buffer-window (current-buffer)))
7421       ;; Select next unread newsgroup automagically.
7422       (cond
7423        ((or (not gnus-auto-select-next)
7424             (not cmd))
7425         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7426        ((or (eq gnus-auto-select-next 'quietly)
7427             (and (eq gnus-auto-select-next 'slightly-quietly)
7428                  push)
7429             (and (eq gnus-auto-select-next 'almost-quietly)
7430                  (gnus-summary-last-article-p)))
7431         ;; Select quietly.
7432         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7433             (gnus-summary-exit)
7434           (gnus-message 7 "No more%s articles (%s)..."
7435                         (if unread " unread" "")
7436                         (if group (concat "selecting " group)
7437                           "exiting"))
7438           (gnus-summary-next-group nil group backward)))
7439        (t
7440         (when (gnus-key-press-event-p last-input-event)
7441           (gnus-summary-walk-group-buffer
7442            gnus-newsgroup-name cmd unread backward point))))))))
7443
7444 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7445   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7446                       (?\C-p (gnus-group-prev-unread-group 1))))
7447         (cursor-in-echo-area t)
7448         keve key group ended prompt)
7449     (save-excursion
7450       (set-buffer gnus-group-buffer)
7451       (goto-char start)
7452       (setq group
7453             (if (eq gnus-keep-same-level 'best)
7454                 (gnus-summary-best-group gnus-newsgroup-name)
7455               (gnus-summary-search-group backward gnus-keep-same-level))))
7456     (while (not ended)
7457       (setq prompt
7458             (format
7459              "No more%s articles%s " (if unread " unread" "")
7460              (if (and group
7461                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7462                  (format " (Type %s for %s [%s])"
7463                          (single-key-description cmd)
7464                          (gnus-group-decoded-name group)
7465                          (gnus-group-unread group))
7466                (format " (Type %s to exit %s)"
7467                        (single-key-description cmd)
7468                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7469       ;; Confirm auto selection.
7470       (setq key (car (setq keve (gnus-read-event-char prompt)))
7471             ended t)
7472       (cond
7473        ((assq key keystrokes)
7474         (let ((obuf (current-buffer)))
7475           (switch-to-buffer gnus-group-buffer)
7476           (when group
7477             (gnus-group-jump-to-group group))
7478           (eval (cadr (assq key keystrokes)))
7479           (setq group (gnus-group-group-name))
7480           (switch-to-buffer obuf))
7481         (setq ended nil))
7482        ((equal key cmd)
7483         (if (or (not group)
7484                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7485             (gnus-summary-exit)
7486           (gnus-summary-next-group nil group backward)))
7487        (t
7488         (push (cdr keve) unread-command-events))))))
7489
7490 (defun gnus-summary-next-unread-article ()
7491   "Select unread article after current one."
7492   (interactive)
7493   (gnus-summary-next-article
7494    (or (not (eq gnus-summary-goto-unread 'never))
7495        (gnus-summary-last-article-p (gnus-summary-article-number)))
7496    (and gnus-auto-select-same
7497         (gnus-summary-article-subject))))
7498
7499 (defun gnus-summary-prev-article (&optional unread subject)
7500   "Select the article after the current one.
7501 If UNREAD is non-nil, only unread articles are selected."
7502   (interactive "P")
7503   (gnus-summary-next-article unread subject t))
7504
7505 (defun gnus-summary-prev-unread-article ()
7506   "Select unread article before current one."
7507   (interactive)
7508   (gnus-summary-prev-article
7509    (or (not (eq gnus-summary-goto-unread 'never))
7510        (gnus-summary-first-article-p (gnus-summary-article-number)))
7511    (and gnus-auto-select-same
7512         (gnus-summary-article-subject))))
7513
7514 (defun gnus-summary-next-page (&optional lines circular stop)
7515   "Show next page of the selected article.
7516 If at the end of the current article, select the next article.
7517 LINES says how many lines should be scrolled up.
7518
7519 If CIRCULAR is non-nil, go to the start of the article instead of
7520 selecting the next article when reaching the end of the current
7521 article.
7522
7523 If STOP is non-nil, just stop when reaching the end of the message.
7524
7525 Also see the variable `gnus-article-skip-boring'."
7526   (interactive "P")
7527   (setq gnus-summary-buffer (current-buffer))
7528   (gnus-set-global-variables)
7529   (let ((article (gnus-summary-article-number))
7530         (article-window (get-buffer-window gnus-article-buffer t))
7531         endp)
7532     ;; If the buffer is empty, we have no article.
7533     (unless article
7534       (error "No article to select"))
7535     (gnus-configure-windows 'article)
7536     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7537         (if (and (eq gnus-summary-goto-unread 'never)
7538                  (not (gnus-summary-last-article-p article)))
7539             (gnus-summary-next-article)
7540           (gnus-summary-next-unread-article))
7541       (if (or (null gnus-current-article)
7542               (null gnus-article-current)
7543               (/= article (cdr gnus-article-current))
7544               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7545           ;; Selected subject is different from current article's.
7546           (gnus-summary-display-article article)
7547         (when article-window
7548           (gnus-eval-in-buffer-window gnus-article-buffer
7549             (setq endp (or (gnus-article-next-page lines)
7550                            (gnus-article-only-boring-p))))
7551           (when endp
7552             (cond (stop
7553                    (gnus-message 3 "End of message"))
7554                   (circular
7555                    (gnus-summary-beginning-of-article))
7556                   (lines
7557                    (gnus-message 3 "End of message"))
7558                   ((null lines)
7559                    (if (and (eq gnus-summary-goto-unread 'never)
7560                             (not (gnus-summary-last-article-p article)))
7561                        (gnus-summary-next-article)
7562                      (gnus-summary-next-unread-article))))))))
7563     (gnus-summary-recenter)
7564     (gnus-summary-position-point)))
7565
7566 (defun gnus-summary-prev-page (&optional lines move)
7567   "Show previous page of selected article.
7568 Argument LINES specifies lines to be scrolled down.
7569 If MOVE, move to the previous unread article if point is at
7570 the beginning of the buffer."
7571   (interactive "P")
7572   (let ((article (gnus-summary-article-number))
7573         (article-window (get-buffer-window gnus-article-buffer t))
7574         endp)
7575     (gnus-configure-windows 'article)
7576     (if (or (null gnus-current-article)
7577             (null gnus-article-current)
7578             (/= article (cdr gnus-article-current))
7579             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7580         ;; Selected subject is different from current article's.
7581         (gnus-summary-display-article article)
7582       (gnus-summary-recenter)
7583       (when article-window
7584         (gnus-eval-in-buffer-window gnus-article-buffer
7585           (setq endp (gnus-article-prev-page lines)))
7586         (when (and move endp)
7587           (cond (lines
7588                  (gnus-message 3 "Beginning of message"))
7589                 ((null lines)
7590                  (if (and (eq gnus-summary-goto-unread 'never)
7591                           (not (gnus-summary-first-article-p article)))
7592                      (gnus-summary-prev-article)
7593                    (gnus-summary-prev-unread-article))))))))
7594   (gnus-summary-position-point))
7595
7596 (defun gnus-summary-prev-page-or-article (&optional lines)
7597   "Show previous page of selected article.
7598 Argument LINES specifies lines to be scrolled down.
7599 If at the beginning of the article, go to the next article."
7600   (interactive "P")
7601   (gnus-summary-prev-page lines t))
7602
7603 (defun gnus-summary-scroll-up (lines)
7604   "Scroll up (or down) one line current article.
7605 Argument LINES specifies lines to be scrolled up (or down if negative)."
7606   (interactive "p")
7607   (gnus-configure-windows 'article)
7608   (gnus-summary-show-thread)
7609   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7610     (gnus-eval-in-buffer-window gnus-article-buffer
7611       (cond ((> lines 0)
7612              (when (gnus-article-next-page lines)
7613                (gnus-message 3 "End of message")))
7614             ((< lines 0)
7615              (gnus-article-prev-page (- lines))))))
7616   (gnus-summary-recenter)
7617   (gnus-summary-position-point))
7618
7619 (defun gnus-summary-scroll-down (lines)
7620   "Scroll down (or up) one line current article.
7621 Argument LINES specifies lines to be scrolled down (or up if negative)."
7622   (interactive "p")
7623   (gnus-summary-scroll-up (- lines)))
7624
7625 (defun gnus-summary-next-same-subject ()
7626   "Select next article which has the same subject as current one."
7627   (interactive)
7628   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7629
7630 (defun gnus-summary-prev-same-subject ()
7631   "Select previous article which has the same subject as current one."
7632   (interactive)
7633   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7634
7635 (defun gnus-summary-next-unread-same-subject ()
7636   "Select next unread article which has the same subject as current one."
7637   (interactive)
7638   (gnus-summary-next-article t (gnus-summary-article-subject)))
7639
7640 (defun gnus-summary-prev-unread-same-subject ()
7641   "Select previous unread article which has the same subject as current one."
7642   (interactive)
7643   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7644
7645 (defun gnus-summary-first-unread-article ()
7646   "Select the first unread article.
7647 Return nil if there are no unread articles."
7648   (interactive)
7649   (prog1
7650       (when (gnus-summary-first-subject t)
7651         (gnus-summary-show-thread)
7652         (gnus-summary-first-subject t)
7653         (gnus-summary-display-article (gnus-summary-article-number)))
7654     (gnus-summary-position-point)))
7655
7656 (defun gnus-summary-first-unread-subject ()
7657   "Place the point on the subject line of the first unread article.
7658 Return nil if there are no unread articles."
7659   (interactive)
7660   (prog1
7661       (when (gnus-summary-first-subject t)
7662         (gnus-summary-show-thread)
7663         (gnus-summary-first-subject t))
7664     (gnus-summary-position-point)))
7665
7666 (defun gnus-summary-first-unseen-subject ()
7667   "Place the point on the subject line of the first unseen article.
7668 Return nil if there are no unseen articles."
7669   (interactive)
7670   (prog1
7671       (when (gnus-summary-first-subject nil nil t)
7672         (gnus-summary-show-thread)
7673         (gnus-summary-first-subject nil nil t))
7674     (gnus-summary-position-point)))
7675
7676 (defun gnus-summary-first-unseen-or-unread-subject ()
7677   "Place the point on the subject line of the first unseen article or,
7678 if all article have been seen, on the subject line of the first unread
7679 article."
7680   (interactive)
7681   (prog1
7682       (unless (when (gnus-summary-first-subject nil nil t)
7683                 (gnus-summary-show-thread)
7684                 (gnus-summary-first-subject nil nil t))
7685         (when (gnus-summary-first-subject t)
7686           (gnus-summary-show-thread)
7687           (gnus-summary-first-subject t)))
7688     (gnus-summary-position-point)))
7689
7690 (defun gnus-summary-first-article ()
7691   "Select the first article.
7692 Return nil if there are no articles."
7693   (interactive)
7694   (prog1
7695       (when (gnus-summary-first-subject)
7696         (gnus-summary-show-thread)
7697         (gnus-summary-first-subject)
7698         (gnus-summary-display-article (gnus-summary-article-number)))
7699     (gnus-summary-position-point)))
7700
7701 (defun gnus-summary-best-unread-article (&optional arg)
7702   "Select the unread article with the highest score.
7703 If given a prefix argument, select the next unread article that has a
7704 score higher than the default score."
7705   (interactive "P")
7706   (let ((article (if arg
7707                      (gnus-summary-better-unread-subject)
7708                    (gnus-summary-best-unread-subject))))
7709     (if article
7710         (gnus-summary-goto-article article)
7711       (error "No unread articles"))))
7712
7713 (defun gnus-summary-best-unread-subject ()
7714   "Select the unread subject with the highest score."
7715   (interactive)
7716   (let ((best -1000000)
7717         (data gnus-newsgroup-data)
7718         article score)
7719     (while data
7720       (and (gnus-data-unread-p (car data))
7721            (> (setq score
7722                     (gnus-summary-article-score (gnus-data-number (car data))))
7723               best)
7724            (setq best score
7725                  article (gnus-data-number (car data))))
7726       (setq data (cdr data)))
7727     (when article
7728       (gnus-summary-goto-subject article))
7729     (gnus-summary-position-point)
7730     article))
7731
7732 (defun gnus-summary-better-unread-subject ()
7733   "Select the first unread subject that has a score over the default score."
7734   (interactive)
7735   (let ((data gnus-newsgroup-data)
7736         article score)
7737     (while (and (setq article (gnus-data-number (car data)))
7738                 (or (gnus-data-read-p (car data))
7739                     (not (> (gnus-summary-article-score article)
7740                             gnus-summary-default-score))))
7741       (setq data (cdr data)))
7742     (when article
7743       (gnus-summary-goto-subject article))
7744     (gnus-summary-position-point)
7745     article))
7746
7747 (defun gnus-summary-last-subject ()
7748   "Go to the last displayed subject line in the group."
7749   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7750     (when article
7751       (gnus-summary-goto-subject article))))
7752
7753 (defun gnus-summary-goto-article (article &optional all-headers force)
7754   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7755 If ALL-HEADERS is non-nil, no header lines are hidden.
7756 If FORCE, go to the article even if it isn't displayed.  If FORCE
7757 is a number, it is the line the article is to be displayed on."
7758   (interactive
7759    (list
7760     (completing-read
7761      "Article number or Message-ID: "
7762      (mapcar (lambda (number) (list (int-to-string number)))
7763              gnus-newsgroup-limit))
7764     current-prefix-arg
7765     t))
7766   (prog1
7767       (if (and (stringp article)
7768                (string-match "@\\|%40" article))
7769           (gnus-summary-refer-article article)
7770         (when (stringp article)
7771           (setq article (string-to-number article)))
7772         (if (gnus-summary-goto-subject article force)
7773             (gnus-summary-display-article article all-headers)
7774           (gnus-message 4 "Couldn't go to article %s" article) nil))
7775     (gnus-summary-position-point)))
7776
7777 (defun gnus-summary-goto-last-article ()
7778   "Go to the previously read article."
7779   (interactive)
7780   (prog1
7781       (when gnus-last-article
7782         (gnus-summary-goto-article gnus-last-article nil t))
7783     (gnus-summary-position-point)))
7784
7785 (defun gnus-summary-pop-article (number)
7786   "Pop one article off the history and go to the previous.
7787 NUMBER articles will be popped off."
7788   (interactive "p")
7789   (let (to)
7790     (setq gnus-newsgroup-history
7791           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7792     (if to
7793         (gnus-summary-goto-article (car to) nil t)
7794       (error "Article history empty")))
7795   (gnus-summary-position-point))
7796
7797 ;; Summary commands and functions for limiting the summary buffer.
7798
7799 (defun gnus-summary-limit-to-articles (n)
7800   "Limit the summary buffer to the next N articles.
7801 If not given a prefix, use the process marked articles instead."
7802   (interactive "P")
7803   (prog1
7804       (let ((articles (gnus-summary-work-articles n)))
7805         (setq gnus-newsgroup-processable nil)
7806         (gnus-summary-limit articles))
7807     (gnus-summary-position-point)))
7808
7809 (defun gnus-summary-pop-limit (&optional total)
7810   "Restore the previous limit.
7811 If given a prefix, remove all limits."
7812   (interactive "P")
7813   (when total
7814     (setq gnus-newsgroup-limits
7815           (list (mapcar (lambda (h) (mail-header-number h))
7816                         gnus-newsgroup-headers))))
7817   (unless gnus-newsgroup-limits
7818     (error "No limit to pop"))
7819   (prog1
7820       (gnus-summary-limit nil 'pop)
7821     (gnus-summary-position-point)))
7822
7823 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7824   "Limit the summary buffer to articles that have subjects that match a regexp.
7825 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7826   (interactive
7827    (list (read-string (if current-prefix-arg
7828                           "Exclude subject (regexp): "
7829                         "Limit to subject (regexp): "))
7830          nil current-prefix-arg))
7831   (unless header
7832     (setq header "subject"))
7833   (when (not (equal "" subject))
7834     (prog1
7835         (let ((articles (gnus-summary-find-matching
7836                          (or header "subject") subject 'all nil nil
7837                          not-matching)))
7838           (unless articles
7839             (error "Found no matches for \"%s\"" subject))
7840           (gnus-summary-limit articles))
7841       (gnus-summary-position-point))))
7842
7843 (defun gnus-summary-limit-to-author (from &optional not-matching)
7844   "Limit the summary buffer to articles that have authors that match a regexp.
7845 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7846   (interactive
7847    (list (read-string (if current-prefix-arg
7848                           "Exclude author (regexp): "
7849                         "Limit to author (regexp): "))
7850          current-prefix-arg))
7851   (gnus-summary-limit-to-subject from "from" not-matching))
7852
7853 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7854   "Limit the summary buffer to articles with the given RECIPIENT.
7855
7856 If NOT-MATCHING, exclude RECIPIENT.
7857
7858 To and Cc headers are checked.  You need to include them in
7859 `nnmail-extra-headers'."
7860   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7861   (interactive
7862    (list (read-string (format "%s recipient (regexp): "
7863                               (if current-prefix-arg "Exclude" "Limit to")))
7864          current-prefix-arg))
7865   (when (not (equal "" recipient))
7866     (prog1 (let* ((to
7867                    (if (memq 'To nnmail-extra-headers)
7868                        (gnus-summary-find-matching
7869                         (cons 'extra 'To) recipient 'all nil nil
7870                         not-matching)
7871                      (gnus-message
7872                       1 "`To' isn't present in `nnmail-extra-headers'")
7873                      (sit-for 1)
7874                      nil))
7875                   (cc
7876                    (if (memq 'Cc nnmail-extra-headers)
7877                        (gnus-summary-find-matching
7878                         (cons 'extra 'Cc) recipient 'all nil nil
7879                         not-matching)
7880                      (gnus-message
7881                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7882                      (sit-for 1)
7883                      nil))
7884                   (articles
7885                    (if not-matching
7886                        ;; We need the numbers that are in both lists:
7887                        (mapcar (lambda (a)
7888                                  (and (memq a to) a))
7889                                cc)
7890                      (nconc to cc))))
7891              (unless articles
7892                (error "Found no matches for \"%s\"" recipient))
7893              (gnus-summary-limit articles))
7894       (gnus-summary-position-point))))
7895
7896 (defun gnus-summary-limit-to-age (age &optional younger-p)
7897   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7898 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7899 articles that are younger than AGE days."
7900   (interactive
7901    (let ((younger current-prefix-arg)
7902          (days-got nil)
7903          days)
7904      (while (not days-got)
7905        (setq days (if younger
7906                       (read-string "Limit to articles younger than (in days, older when negative): ")
7907                     (read-string
7908                      "Limit to articles older than (in days, younger when negative): ")))
7909        (when (> (length days) 0)
7910          (setq days (read days)))
7911        (if (numberp days)
7912            (progn
7913              (setq days-got t)
7914              (when (< days 0)
7915                (setq younger (not younger))
7916                (setq days (* days -1))))
7917          (message "Please enter a number.")
7918          (sleep-for 1)))
7919      (list days younger)))
7920   (prog1
7921       (let ((data gnus-newsgroup-data)
7922             (cutoff (days-to-time age))
7923             articles d date is-younger)
7924         (while (setq d (pop data))
7925           (when (and (vectorp (gnus-data-header d))
7926                      (setq date (mail-header-date (gnus-data-header d))))
7927             (setq is-younger (time-less-p
7928                               (time-since (condition-case ()
7929                                               (date-to-time date)
7930                                             (error '(0 0))))
7931                               cutoff))
7932             (when (if younger-p
7933                       is-younger
7934                     (not is-younger))
7935               (push (gnus-data-number d) articles))))
7936         (gnus-summary-limit (nreverse articles)))
7937     (gnus-summary-position-point)))
7938
7939 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7940   "Limit the summary buffer to articles that match an 'extra' header."
7941   (interactive
7942    (let ((header
7943           (intern
7944            (gnus-completing-read-with-default
7945             (symbol-name (car gnus-extra-headers))
7946             (if current-prefix-arg
7947                 "Exclude extra header"
7948               "Limit extra header")
7949             (mapcar (lambda (x)
7950                       (cons (symbol-name x) x))
7951                     gnus-extra-headers)
7952             nil
7953             t))))
7954      (list header
7955            (read-string (format "%s header %s (regexp): "
7956                                 (if current-prefix-arg "Exclude" "Limit to")
7957                                 header))
7958            current-prefix-arg)))
7959   (when (not (equal "" regexp))
7960     (prog1
7961         (let ((articles (gnus-summary-find-matching
7962                          (cons 'extra header) regexp 'all nil nil
7963                          not-matching)))
7964           (unless articles
7965             (error "Found no matches for \"%s\"" regexp))
7966           (gnus-summary-limit articles))
7967       (gnus-summary-position-point))))
7968
7969 (defun gnus-summary-limit-to-display-predicate ()
7970   "Limit the summary buffer to the predicated in the `display' group parameter."
7971   (interactive)
7972   (unless gnus-newsgroup-display
7973     (error "There is no `display' group parameter"))
7974   (let (articles)
7975     (dolist (number gnus-newsgroup-articles)
7976       (when (funcall gnus-newsgroup-display)
7977         (push number articles)))
7978     (gnus-summary-limit articles))
7979   (gnus-summary-position-point))
7980
7981 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7982 (make-obsolete
7983  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7984
7985 (defun gnus-summary-limit-to-unread (&optional all)
7986   "Limit the summary buffer to articles that are not marked as read.
7987 If ALL is non-nil, limit strictly to unread articles."
7988   (interactive "P")
7989   (if all
7990       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7991     (gnus-summary-limit-to-marks
7992      ;; Concat all the marks that say that an article is read and have
7993      ;; those removed.
7994      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7995            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7996            gnus-low-score-mark gnus-expirable-mark
7997            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7998            gnus-duplicate-mark gnus-souped-mark)
7999      'reverse)))
8000
8001 (defun gnus-summary-limit-to-replied (&optional unreplied)
8002   "Limit the summary buffer to replied articles.
8003 If UNREPLIED (the prefix), limit to unreplied articles."
8004   (interactive "P")
8005   (if unreplied
8006       (gnus-summary-limit
8007        (gnus-set-difference gnus-newsgroup-articles
8008         gnus-newsgroup-replied))
8009     (gnus-summary-limit gnus-newsgroup-replied))
8010   (gnus-summary-position-point))
8011
8012 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8013 (make-obsolete 'gnus-summary-delete-marked-with
8014                'gnus-summary-limit-exclude-marks)
8015
8016 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8017   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8018 If REVERSE, limit the summary buffer to articles that are marked
8019 with MARKS.  MARKS can either be a string of marks or a list of marks.
8020 Returns how many articles were removed."
8021   (interactive "sMarks: ")
8022   (gnus-summary-limit-to-marks marks t))
8023
8024 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8025   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8026 If REVERSE (the prefix), limit the summary buffer to articles that are
8027 not marked with MARKS.  MARKS can either be a string of marks or a
8028 list of marks.
8029 Returns how many articles were removed."
8030   (interactive "sMarks: \nP")
8031   (prog1
8032       (let ((data gnus-newsgroup-data)
8033             (marks (if (listp marks) marks
8034                      (append marks nil))) ; Transform to list.
8035             articles)
8036         (while data
8037           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8038                   (memq (gnus-data-mark (car data)) marks))
8039             (push (gnus-data-number (car data)) articles))
8040           (setq data (cdr data)))
8041         (gnus-summary-limit articles))
8042     (gnus-summary-position-point)))
8043
8044 (defun gnus-summary-limit-to-score (score)
8045   "Limit to articles with score at or above SCORE."
8046   (interactive "NLimit to articles with score of at least: ")
8047   (let ((data gnus-newsgroup-data)
8048         articles)
8049     (while data
8050       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8051                 score)
8052         (push (gnus-data-number (car data)) articles))
8053       (setq data (cdr data)))
8054     (prog1
8055         (gnus-summary-limit articles)
8056       (gnus-summary-position-point))))
8057
8058 (defun gnus-summary-limit-to-unseen ()
8059   "Limit to unseen articles."
8060   (interactive)
8061   (prog1
8062       (gnus-summary-limit gnus-newsgroup-unseen)
8063     (gnus-summary-position-point)))
8064
8065 (defun gnus-summary-limit-include-thread (id)
8066   "Display all the hidden articles that is in the thread with ID in it.
8067 When called interactively, ID is the Message-ID of the current
8068 article."
8069   (interactive (list (mail-header-id (gnus-summary-article-header))))
8070   (let ((articles (gnus-articles-in-thread
8071                    (gnus-id-to-thread (gnus-root-id id)))))
8072     (prog1
8073         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8074       (gnus-summary-limit-include-matching-articles
8075        "subject"
8076        (regexp-quote (gnus-simplify-subject-re
8077                       (mail-header-subject (gnus-id-to-header id)))))
8078       (gnus-summary-position-point))))
8079
8080 (defun gnus-summary-limit-include-matching-articles (header regexp)
8081   "Display all the hidden articles that have HEADERs that match REGEXP."
8082   (interactive (list (read-string "Match on header: ")
8083                      (read-string "Regexp: ")))
8084   (let ((articles (gnus-find-matching-articles header regexp)))
8085     (prog1
8086         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8087       (gnus-summary-position-point))))
8088
8089 (defun gnus-summary-insert-dormant-articles ()
8090   "Insert all the dormant articles for this group into the current buffer."
8091   (interactive)
8092   (let ((gnus-verbose (max 6 gnus-verbose)))
8093     (if (not gnus-newsgroup-dormant)
8094         (gnus-message 3 "No cached articles for this group")
8095       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8096
8097 (defun gnus-summary-limit-include-dormant ()
8098   "Display all the hidden articles that are marked as dormant.
8099 Note that this command only works on a subset of the articles currently
8100 fetched for this group."
8101   (interactive)
8102   (unless gnus-newsgroup-dormant
8103     (error "There are no dormant articles in this group"))
8104   (prog1
8105       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8106     (gnus-summary-position-point)))
8107
8108 (defun gnus-summary-limit-exclude-dormant ()
8109   "Hide all dormant articles."
8110   (interactive)
8111   (prog1
8112       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8113     (gnus-summary-position-point)))
8114
8115 (defun gnus-summary-limit-exclude-childless-dormant ()
8116   "Hide all dormant articles that have no children."
8117   (interactive)
8118   (let ((data (gnus-data-list t))
8119         articles d children)
8120     ;; Find all articles that are either not dormant or have
8121     ;; children.
8122     (while (setq d (pop data))
8123       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8124                 (and (setq children
8125                            (gnus-article-children (gnus-data-number d)))
8126                      (let (found)
8127                        (while children
8128                          (when (memq (car children) articles)
8129                            (setq children nil
8130                                  found t))
8131                          (pop children))
8132                        found)))
8133         (push (gnus-data-number d) articles)))
8134     ;; Do the limiting.
8135     (prog1
8136         (gnus-summary-limit articles)
8137       (gnus-summary-position-point))))
8138
8139 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8140   "Mark all unread excluded articles as read.
8141 If ALL, mark even excluded ticked and dormants as read."
8142   (interactive "P")
8143   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8144   (let ((articles (gnus-sorted-ndifference
8145                    (sort
8146                     (mapcar (lambda (h) (mail-header-number h))
8147                             gnus-newsgroup-headers)
8148                     '<)
8149                    gnus-newsgroup-limit))
8150         article)
8151     (setq gnus-newsgroup-unreads
8152           (gnus-sorted-intersection gnus-newsgroup-unreads
8153                                     gnus-newsgroup-limit))
8154     (if all
8155         (setq gnus-newsgroup-dormant nil
8156               gnus-newsgroup-marked nil
8157               gnus-newsgroup-reads
8158               (nconc
8159                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8160                gnus-newsgroup-reads))
8161       (while (setq article (pop articles))
8162         (unless (or (memq article gnus-newsgroup-dormant)
8163                     (memq article gnus-newsgroup-marked))
8164           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8165
8166 (defun gnus-summary-limit (articles &optional pop)
8167   (if pop
8168       ;; We pop the previous limit off the stack and use that.
8169       (setq articles (car gnus-newsgroup-limits)
8170             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8171     ;; We use the new limit, so we push the old limit on the stack.
8172     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8173   ;; Set the limit.
8174   (setq gnus-newsgroup-limit articles)
8175   (let ((total (length gnus-newsgroup-data))
8176         (data (gnus-data-find-list (gnus-summary-article-number)))
8177         (gnus-summary-mark-below nil)   ; Inhibit this.
8178         found)
8179     ;; This will do all the work of generating the new summary buffer
8180     ;; according to the new limit.
8181     (gnus-summary-prepare)
8182     ;; Hide any threads, possibly.
8183     (gnus-summary-maybe-hide-threads)
8184     ;; Try to return to the article you were at, or one in the
8185     ;; neighborhood.
8186     (when data
8187       ;; We try to find some article after the current one.
8188       (while data
8189         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8190           (setq data nil
8191                 found t))
8192         (setq data (cdr data))))
8193     (unless found
8194       ;; If there is no data, that means that we were after the last
8195       ;; article.  The same goes when we can't find any articles
8196       ;; after the current one.
8197       (goto-char (point-max))
8198       (gnus-summary-find-prev))
8199     (gnus-set-mode-line 'summary)
8200     ;; We return how many articles were removed from the summary
8201     ;; buffer as a result of the new limit.
8202     (- total (length gnus-newsgroup-data))))
8203
8204 (defsubst gnus-invisible-cut-children (threads)
8205   (let ((num 0))
8206     (while threads
8207       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8208         (incf num))
8209       (pop threads))
8210     (< num 2)))
8211
8212 (defsubst gnus-cut-thread (thread)
8213   "Go forwards in the thread until we find an article that we want to display."
8214   (when (or (eq gnus-fetch-old-headers 'some)
8215             (eq gnus-fetch-old-headers 'invisible)
8216             (numberp gnus-fetch-old-headers)
8217             (eq gnus-build-sparse-threads 'some)
8218             (eq gnus-build-sparse-threads 'more))
8219     ;; Deal with old-fetched headers and sparse threads.
8220     (while (and
8221             thread
8222             (or
8223              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8224              (gnus-summary-article-ancient-p
8225               (mail-header-number (car thread))))
8226             (if (or (<= (length (cdr thread)) 1)
8227                     (eq gnus-fetch-old-headers 'invisible))
8228                 (setq gnus-newsgroup-limit
8229                       (delq (mail-header-number (car thread))
8230                             gnus-newsgroup-limit)
8231                       thread (cadr thread))
8232               (when (gnus-invisible-cut-children (cdr thread))
8233                 (let ((th (cdr thread)))
8234                   (while th
8235                     (if (memq (mail-header-number (caar th))
8236                               gnus-newsgroup-limit)
8237                         (setq thread (car th)
8238                               th nil)
8239                       (setq th (cdr th))))))))))
8240   thread)
8241
8242 (defun gnus-cut-threads (threads)
8243   "Cut off all uninteresting articles from the beginning of THREADS."
8244   (when (or (eq gnus-fetch-old-headers 'some)
8245             (eq gnus-fetch-old-headers 'invisible)
8246             (numberp gnus-fetch-old-headers)
8247             (eq gnus-build-sparse-threads 'some)
8248             (eq gnus-build-sparse-threads 'more))
8249     (let ((th threads))
8250       (while th
8251         (setcar th (gnus-cut-thread (car th)))
8252         (setq th (cdr th)))))
8253   ;; Remove nixed out threads.
8254   (delq nil threads))
8255
8256 (defun gnus-summary-initial-limit (&optional show-if-empty)
8257   "Figure out what the initial limit is supposed to be on group entry.
8258 This entails weeding out unwanted dormants, low-scored articles,
8259 fetch-old-headers verbiage, and so on."
8260   ;; Most groups have nothing to remove.
8261   (if (or gnus-inhibit-limiting
8262           (and (null gnus-newsgroup-dormant)
8263                (eq gnus-newsgroup-display 'gnus-not-ignore)
8264                (not (eq gnus-fetch-old-headers 'some))
8265                (not (numberp gnus-fetch-old-headers))
8266                (not (eq gnus-fetch-old-headers 'invisible))
8267                (null gnus-summary-expunge-below)
8268                (not (eq gnus-build-sparse-threads 'some))
8269                (not (eq gnus-build-sparse-threads 'more))
8270                (null gnus-thread-expunge-below)
8271                (not gnus-use-nocem)))
8272       ()                                ; Do nothing.
8273     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8274     (setq gnus-newsgroup-limit nil)
8275     (mapatoms
8276      (lambda (node)
8277        (unless (car (symbol-value node))
8278          ;; These threads have no parents -- they are roots.
8279          (let ((nodes (cdr (symbol-value node)))
8280                thread)
8281            (while nodes
8282              (if (and gnus-thread-expunge-below
8283                       (< (gnus-thread-total-score (car nodes))
8284                          gnus-thread-expunge-below))
8285                  (gnus-expunge-thread (pop nodes))
8286                (setq thread (pop nodes))
8287                (gnus-summary-limit-children thread))))))
8288      gnus-newsgroup-dependencies)
8289     ;; If this limitation resulted in an empty group, we might
8290     ;; pop the previous limit and use it instead.
8291     (when (and (not gnus-newsgroup-limit)
8292                show-if-empty)
8293       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8294     gnus-newsgroup-limit))
8295
8296 (defun gnus-summary-limit-children (thread)
8297   "Return 1 if this subthread is visible and 0 if it is not."
8298   ;; First we get the number of visible children to this thread.  This
8299   ;; is done by recursing down the thread using this function, so this
8300   ;; will really go down to a leaf article first, before slowly
8301   ;; working its way up towards the root.
8302   (when thread
8303     (let* ((max-lisp-eval-depth 5000)
8304            (children
8305            (if (cdr thread)
8306                (apply '+ (mapcar 'gnus-summary-limit-children
8307                                  (cdr thread)))
8308              0))
8309           (number (mail-header-number (car thread)))
8310           score)
8311       (if (and
8312            (not (memq number gnus-newsgroup-marked))
8313            (or
8314             ;; If this article is dormant and has absolutely no visible
8315             ;; children, then this article isn't visible.
8316             (and (memq number gnus-newsgroup-dormant)
8317                  (zerop children))
8318             ;; If this is "fetch-old-headered" and there is no
8319             ;; visible children, then we don't want this article.
8320             (and (or (eq gnus-fetch-old-headers 'some)
8321                      (numberp gnus-fetch-old-headers))
8322                  (gnus-summary-article-ancient-p number)
8323                  (zerop children))
8324             ;; If this is "fetch-old-headered" and `invisible', then
8325             ;; we don't want this article.
8326             (and (eq gnus-fetch-old-headers 'invisible)
8327                  (gnus-summary-article-ancient-p number))
8328             ;; If this is a sparsely inserted article with no children,
8329             ;; we don't want it.
8330             (and (eq gnus-build-sparse-threads 'some)
8331                  (gnus-summary-article-sparse-p number)
8332                  (zerop children))
8333             ;; If we use expunging, and this article is really
8334             ;; low-scored, then we don't want this article.
8335             (when (and gnus-summary-expunge-below
8336                        (< (setq score
8337                                 (or (cdr (assq number gnus-newsgroup-scored))
8338                                     gnus-summary-default-score))
8339                           gnus-summary-expunge-below))
8340               ;; We increase the expunge-tally here, but that has
8341               ;; nothing to do with the limits, really.
8342               (incf gnus-newsgroup-expunged-tally)
8343               ;; We also mark as read here, if that's wanted.
8344               (when (and gnus-summary-mark-below
8345                          (< score gnus-summary-mark-below))
8346                 (setq gnus-newsgroup-unreads
8347                       (delq number gnus-newsgroup-unreads))
8348                 (if gnus-newsgroup-auto-expire
8349                     (push number gnus-newsgroup-expirable)
8350                   (push (cons number gnus-low-score-mark)
8351                         gnus-newsgroup-reads)))
8352               t)
8353             ;; Do the `display' group parameter.
8354             (and gnus-newsgroup-display
8355                  (not (funcall gnus-newsgroup-display)))
8356             ;; Check NoCeM things.
8357             (when (and gnus-use-nocem
8358                        (gnus-nocem-unwanted-article-p
8359                         (mail-header-id (car thread))))
8360               (setq gnus-newsgroup-unreads
8361                     (delq number gnus-newsgroup-unreads))
8362               t)))
8363           ;; Nope, invisible article.
8364           0
8365         ;; Ok, this article is to be visible, so we add it to the limit
8366         ;; and return 1.
8367         (push number gnus-newsgroup-limit)
8368         1))))
8369
8370 (defun gnus-expunge-thread (thread)
8371   "Mark all articles in THREAD as read."
8372   (let* ((number (mail-header-number (car thread))))
8373     (incf gnus-newsgroup-expunged-tally)
8374     ;; We also mark as read here, if that's wanted.
8375     (setq gnus-newsgroup-unreads
8376           (delq number gnus-newsgroup-unreads))
8377     (if gnus-newsgroup-auto-expire
8378         (push number gnus-newsgroup-expirable)
8379       (push (cons number gnus-low-score-mark)
8380             gnus-newsgroup-reads)))
8381   ;; Go recursively through all subthreads.
8382   (mapcar 'gnus-expunge-thread (cdr thread)))
8383
8384 ;; Summary article oriented commands
8385
8386 (defun gnus-summary-refer-parent-article (n)
8387   "Refer parent article N times.
8388 If N is negative, go to ancestor -N instead.
8389 The difference between N and the number of articles fetched is returned."
8390   (interactive "p")
8391   (let ((skip 1)
8392         error header ref)
8393     (when (not (natnump n))
8394       (setq skip (abs n)
8395             n 1))
8396     (while (and (> n 0)
8397                 (not error))
8398       (setq header (gnus-summary-article-header))
8399       (if (and (eq (mail-header-number header)
8400                    (cdr gnus-article-current))
8401                (equal gnus-newsgroup-name
8402                       (car gnus-article-current)))
8403           ;; If we try to find the parent of the currently
8404           ;; displayed article, then we take a look at the actual
8405           ;; References header, since this is slightly more
8406           ;; reliable than the References field we got from the
8407           ;; server.
8408           (save-excursion
8409             (set-buffer gnus-original-article-buffer)
8410             (nnheader-narrow-to-headers)
8411             (unless (setq ref (message-fetch-field "references"))
8412               (when (setq ref (message-fetch-field "in-reply-to"))
8413                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8414             (widen))
8415         (setq ref
8416               ;; It's not the current article, so we take a bet on
8417               ;; the value we got from the server.
8418               (mail-header-references header)))
8419       (if (and ref
8420                (not (equal ref "")))
8421           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8422             (gnus-message 1 "Couldn't find parent"))
8423         (gnus-message 1 "No references in article %d"
8424                       (gnus-summary-article-number))
8425         (setq error t))
8426       (decf n))
8427     (gnus-summary-position-point)
8428     n))
8429
8430 (defun gnus-summary-refer-references ()
8431   "Fetch all articles mentioned in the References header.
8432 Return the number of articles fetched."
8433   (interactive)
8434   (let ((ref (mail-header-references (gnus-summary-article-header)))
8435         (current (gnus-summary-article-number))
8436         (n 0))
8437     (if (or (not ref)
8438             (equal ref ""))
8439         (error "No References in the current article")
8440       ;; For each Message-ID in the References header...
8441       (while (string-match "<[^>]*>" ref)
8442         (incf n)
8443         ;; ... fetch that article.
8444         (gnus-summary-refer-article
8445          (prog1 (match-string 0 ref)
8446            (setq ref (substring ref (match-end 0))))))
8447       (gnus-summary-goto-subject current)
8448       (gnus-summary-position-point)
8449       n)))
8450
8451 (defun gnus-summary-refer-thread (&optional limit)
8452   "Fetch all articles in the current thread.
8453 If LIMIT (the numerical prefix), fetch that many old headers instead
8454 of what's specified by the `gnus-refer-thread-limit' variable."
8455   (interactive "P")
8456   (let ((id (mail-header-id (gnus-summary-article-header)))
8457         (limit (if limit (prefix-numeric-value limit)
8458                  gnus-refer-thread-limit)))
8459     (unless (eq gnus-fetch-old-headers 'invisible)
8460       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8461       ;; Retrieve the headers and read them in.
8462       (if (eq (if (numberp limit)
8463                   (gnus-retrieve-headers
8464                    (list (min
8465                           (+ (mail-header-number
8466                               (gnus-summary-article-header))
8467                              limit)
8468                           gnus-newsgroup-end))
8469                    gnus-newsgroup-name (* limit 2))
8470                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8471                 ;; headers.
8472                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8473                                        gnus-newsgroup-name limit))
8474               'nov)
8475           (gnus-build-all-threads)
8476         (error "Can't fetch thread from back ends that don't support NOV"))
8477       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8478     (gnus-summary-limit-include-thread id)))
8479
8480 (defun gnus-summary-refer-article (message-id)
8481   "Fetch an article specified by MESSAGE-ID."
8482   (interactive "sMessage-ID: ")
8483   (when (and (stringp message-id)
8484              (not (zerop (length message-id))))
8485     (setq message-id (gnus-replace-in-string message-id " " ""))
8486     ;; Construct the correct Message-ID if necessary.
8487     ;; Suggested by tale@pawl.rpi.edu.
8488     (unless (string-match "^<" message-id)
8489       (setq message-id (concat "<" message-id)))
8490     (unless (string-match ">$" message-id)
8491       (setq message-id (concat message-id ">")))
8492     ;; People often post MIDs from URLs, so unhex it:
8493     (unless (string-match "@" message-id)
8494       (setq message-id (gnus-url-unhex-string message-id)))
8495     (let* ((header (gnus-id-to-header message-id))
8496            (sparse (and header
8497                         (gnus-summary-article-sparse-p
8498                          (mail-header-number header))
8499                         (memq (mail-header-number header)
8500                               gnus-newsgroup-limit)))
8501            number)
8502       (cond
8503        ;; If the article is present in the buffer we just go to it.
8504        ((and header
8505              (or (not (gnus-summary-article-sparse-p
8506                        (mail-header-number header)))
8507                  sparse))
8508         (prog1
8509             (gnus-summary-goto-article
8510              (mail-header-number header) nil t)
8511           (when sparse
8512             (gnus-summary-update-article (mail-header-number header)))))
8513        (t
8514         ;; We fetch the article.
8515         (catch 'found
8516           (dolist (gnus-override-method (gnus-refer-article-methods))
8517             (when (and (gnus-check-server gnus-override-method)
8518                        ;; Fetch the header,
8519                        (setq number (gnus-summary-insert-subject message-id)))
8520               ;; and display the article.
8521               (gnus-summary-select-article nil nil nil number)
8522               (throw 'found t)))
8523           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8524
8525 (defun gnus-refer-article-methods ()
8526   "Return a list of referable methods."
8527   (cond
8528    ;; No method, so we default to current and native.
8529    ((null gnus-refer-article-method)
8530     (list gnus-current-select-method gnus-select-method))
8531    ;; Current.
8532    ((eq 'current gnus-refer-article-method)
8533     (list gnus-current-select-method))
8534    ;; List of select methods.
8535    ((not (and (symbolp (car gnus-refer-article-method))
8536               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8537     (let (out)
8538       (dolist (method gnus-refer-article-method)
8539         (push (if (eq 'current method)
8540                   gnus-current-select-method
8541                 method)
8542               out))
8543       (nreverse out)))
8544    ;; One single select method.
8545    (t
8546     (list gnus-refer-article-method))))
8547
8548 (defun gnus-summary-edit-parameters ()
8549   "Edit the group parameters of the current group."
8550   (interactive)
8551   (gnus-group-edit-group gnus-newsgroup-name 'params))
8552
8553 (defun gnus-summary-customize-parameters ()
8554   "Customize the group parameters of the current group."
8555   (interactive)
8556   (gnus-group-customize gnus-newsgroup-name))
8557
8558 (defun gnus-summary-enter-digest-group (&optional force)
8559   "Enter an nndoc group based on the current article.
8560 If FORCE, force a digest interpretation.  If not, try
8561 to guess what the document format is."
8562   (interactive "P")
8563   (let ((conf gnus-current-window-configuration))
8564     (save-window-excursion
8565       (save-excursion
8566         (let (gnus-article-prepare-hook
8567               gnus-display-mime-function
8568               gnus-break-pages)
8569           (gnus-summary-select-article))))
8570     (setq gnus-current-window-configuration conf)
8571     (let* ((name (format "%s-%d"
8572                          (gnus-group-prefixed-name
8573                           gnus-newsgroup-name (list 'nndoc ""))
8574                          (with-current-buffer gnus-summary-buffer
8575                            gnus-current-article)))
8576            (ogroup gnus-newsgroup-name)
8577            (params (append (gnus-info-params (gnus-get-info ogroup))
8578                            (list (cons 'to-group ogroup))
8579                            (list (cons 'parent-group ogroup))
8580                            (list (cons 'save-article-group ogroup))))
8581            (case-fold-search t)
8582            (buf (current-buffer))
8583            dig to-address)
8584       (save-excursion
8585         (set-buffer gnus-original-article-buffer)
8586         ;; Have the digest group inherit the main mail address of
8587         ;; the parent article.
8588         (when (setq to-address (or (gnus-fetch-field "reply-to")
8589                                    (gnus-fetch-field "from")))
8590           (setq params (append
8591                         (list (cons 'to-address
8592                                     (funcall gnus-decode-encoded-word-function
8593                                              to-address))))))
8594         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8595         (insert-buffer-substring gnus-original-article-buffer)
8596         ;; Remove lines that may lead nndoc to misinterpret the
8597         ;; document type.
8598         (narrow-to-region
8599          (goto-char (point-min))
8600          (or (search-forward "\n\n" nil t) (point)))
8601         (goto-char (point-min))
8602         (delete-matching-lines "^Path:\\|^From ")
8603         (widen))
8604       (unwind-protect
8605           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8606                     (gnus-newsgroup-ephemeral-ignored-charsets
8607                      gnus-newsgroup-ignored-charsets))
8608                 (gnus-group-read-ephemeral-group
8609                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8610                               (nndoc-article-type
8611                                ,(if force 'mbox 'guess)))
8612                  t nil nil nil
8613                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8614                                                         "ADAPT")))))
8615               ;; Make all postings to this group go to the parent group.
8616               (nconc (gnus-info-params (gnus-get-info name))
8617                      params)
8618             ;; Couldn't select this doc group.
8619             (switch-to-buffer buf)
8620             (gnus-set-global-variables)
8621             (gnus-configure-windows 'summary)
8622             (gnus-message 3 "Article couldn't be entered?"))
8623         (kill-buffer dig)))))
8624
8625 (defun gnus-summary-read-document (n)
8626   "Open a new group based on the current article(s).
8627 This will allow you to read digests and other similar
8628 documents as newsgroups.
8629 Obeys the standard process/prefix convention."
8630   (interactive "P")
8631   (let* ((ogroup gnus-newsgroup-name)
8632          (params (append (gnus-info-params (gnus-get-info ogroup))
8633                          (list (cons 'to-group ogroup))))
8634          group egroup groups vgroup)
8635     (dolist (article (gnus-summary-work-articles n))
8636       (setq group (format "%s-%d" gnus-newsgroup-name article))
8637       (gnus-summary-remove-process-mark article)
8638       (when (gnus-summary-display-article article)
8639         (save-excursion
8640           (with-temp-buffer
8641             (insert-buffer-substring gnus-original-article-buffer)
8642             ;; Remove some headers that may lead nndoc to make
8643             ;; the wrong guess.
8644             (message-narrow-to-head)
8645             (goto-char (point-min))
8646             (delete-matching-lines "^Path:\\|^From ")
8647             (widen)
8648             (if (setq egroup
8649                       (gnus-group-read-ephemeral-group
8650                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8651                                      (nndoc-article-type guess))
8652                        t nil t))
8653                 (progn
8654             ;; Make all postings to this group go to the parent group.
8655                   (nconc (gnus-info-params (gnus-get-info egroup))
8656                          params)
8657                   (push egroup groups))
8658               ;; Couldn't select this doc group.
8659               (gnus-error 3 "Article couldn't be entered"))))))
8660     ;; Now we have selected all the documents.
8661     (cond
8662      ((not groups)
8663       (error "None of the articles could be interpreted as documents"))
8664      ((gnus-group-read-ephemeral-group
8665        (setq vgroup (format
8666                      "nnvirtual:%s-%s" gnus-newsgroup-name
8667                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8668        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8669        t
8670        (cons (current-buffer) 'summary)))
8671      (t
8672       (error "Couldn't select virtual nndoc group")))))
8673
8674 (defun gnus-summary-isearch-article (&optional regexp-p)
8675   "Do incremental search forward on the current article.
8676 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8677   (interactive "P")
8678   (gnus-summary-select-article)
8679   (gnus-configure-windows 'article)
8680   (gnus-eval-in-buffer-window gnus-article-buffer
8681     (save-restriction
8682       (widen)
8683       (isearch-forward regexp-p))))
8684
8685 (defun gnus-summary-search-article-forward (regexp &optional backward)
8686   "Search for an article containing REGEXP forward.
8687 If BACKWARD, search backward instead."
8688   (interactive
8689    (list (read-string
8690           (format "Search article %s (regexp%s): "
8691                   (if current-prefix-arg "backward" "forward")
8692                   (if gnus-last-search-regexp
8693                       (concat ", default " gnus-last-search-regexp)
8694                     "")))
8695          current-prefix-arg))
8696   (if (string-equal regexp "")
8697       (setq regexp (or gnus-last-search-regexp ""))
8698     (setq gnus-last-search-regexp regexp)
8699     (setq gnus-article-before-search gnus-current-article))
8700   ;; Intentionally set gnus-last-article.
8701   (setq gnus-last-article gnus-article-before-search)
8702   (let ((gnus-last-article gnus-last-article))
8703     (if (gnus-summary-search-article regexp backward)
8704         (gnus-summary-show-thread)
8705       (signal 'search-failed (list regexp)))))
8706
8707 (defun gnus-summary-search-article-backward (regexp)
8708   "Search for an article containing REGEXP backward."
8709   (interactive
8710    (list (read-string
8711           (format "Search article backward (regexp%s): "
8712                   (if gnus-last-search-regexp
8713                       (concat ", default " gnus-last-search-regexp)
8714                     "")))))
8715   (gnus-summary-search-article-forward regexp 'backward))
8716
8717 (defun gnus-summary-search-article (regexp &optional backward)
8718   "Search for an article containing REGEXP.
8719 Optional argument BACKWARD means do search for backward.
8720 `gnus-select-article-hook' is not called during the search."
8721   ;; We have to require this here to make sure that the following
8722   ;; dynamic binding isn't shadowed by autoloading.
8723   (require 'gnus-async)
8724   (require 'gnus-art)
8725   (let ((gnus-select-article-hook nil)  ;Disable hook.
8726         (gnus-article-prepare-hook nil)
8727         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8728         (gnus-use-article-prefetch nil)
8729         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8730         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8731         (gnus-visual nil)
8732         (gnus-keep-backlog nil)
8733         (gnus-break-pages nil)
8734         (gnus-summary-display-arrow nil)
8735         (gnus-updated-mode-lines nil)
8736         (gnus-auto-center-summary nil)
8737         (sum (current-buffer))
8738         (gnus-display-mime-function nil)
8739         (found nil)
8740         point)
8741     (gnus-save-hidden-threads
8742       (gnus-summary-select-article)
8743       (set-buffer gnus-article-buffer)
8744       (goto-char (window-point (get-buffer-window (current-buffer))))
8745       (when backward
8746         (forward-line -1))
8747       (while (not found)
8748         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8749         (if (if backward
8750                 (re-search-backward regexp nil t)
8751               (re-search-forward regexp nil t))
8752             ;; We found the regexp.
8753             (progn
8754               (setq found 'found)
8755               (beginning-of-line)
8756               (set-window-start
8757                (get-buffer-window (current-buffer))
8758                (point))
8759               (forward-line 1)
8760               (set-window-point
8761                (get-buffer-window (current-buffer))
8762                (point))
8763               (set-buffer sum)
8764               (setq point (point)))
8765           ;; We didn't find it, so we go to the next article.
8766           (set-buffer sum)
8767           (setq found 'not)
8768           (while (eq found 'not)
8769             (if (not (if backward (gnus-summary-find-prev)
8770                        (gnus-summary-find-next)))
8771                 ;; No more articles.
8772                 (setq found t)
8773               ;; Select the next article and adjust point.
8774               (unless (gnus-summary-article-sparse-p
8775                        (gnus-summary-article-number))
8776                 (setq found nil)
8777                 (gnus-summary-select-article)
8778                 (set-buffer gnus-article-buffer)
8779                 (widen)
8780                 (goto-char (if backward (point-max) (point-min))))))))
8781       (gnus-message 7 ""))
8782     ;; Return whether we found the regexp.
8783     (when (eq found 'found)
8784       (goto-char point)
8785       (gnus-summary-show-thread)
8786       (gnus-summary-goto-subject gnus-current-article)
8787       (gnus-summary-position-point)
8788       t)))
8789
8790 (defun gnus-find-matching-articles (header regexp)
8791   "Return a list of all articles that match REGEXP on HEADER.
8792 This search includes all articles in the current group that Gnus has
8793 fetched headers for, whether they are displayed or not."
8794   (let ((articles nil)
8795         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8796         (case-fold-search t))
8797     (dolist (header gnus-newsgroup-headers)
8798       (when (string-match regexp (funcall func header))
8799         (push (mail-header-number header) articles)))
8800     (nreverse articles)))
8801
8802 (defun gnus-summary-find-matching (header regexp &optional backward unread
8803                                           not-case-fold not-matching)
8804   "Return a list of all articles that match REGEXP on HEADER.
8805 The search stars on the current article and goes forwards unless
8806 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8807 If UNREAD is non-nil, only unread articles will
8808 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8809 in the comparisons. If NOT-MATCHING, return a list of all articles that
8810 not match REGEXP on HEADER."
8811   (let ((case-fold-search (not not-case-fold))
8812         articles d func)
8813     (if (consp header)
8814         (if (eq (car header) 'extra)
8815             (setq func
8816                   `(lambda (h)
8817                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8818                          "")))
8819           (error "%s is an invalid header" header))
8820       (unless (fboundp (intern (concat "mail-header-" header)))
8821         (error "%s is not a valid header" header))
8822       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8823     (dolist (d (if (eq backward 'all)
8824                    gnus-newsgroup-data
8825                  (gnus-data-find-list
8826                   (gnus-summary-article-number)
8827                   (gnus-data-list backward))))
8828       (when (and (or (not unread)       ; We want all articles...
8829                      (gnus-data-unread-p d)) ; Or just unreads.
8830                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8831                  (if not-matching
8832                      (not (string-match
8833                            regexp
8834                            (funcall func (gnus-data-header d))))
8835                    (string-match regexp
8836                                  (funcall func (gnus-data-header d)))))
8837         (push (gnus-data-number d) articles))) ; Success!
8838     (nreverse articles)))
8839
8840 (defun gnus-summary-execute-command (header regexp command &optional backward)
8841   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8842 If HEADER is an empty string (or nil), the match is done on the entire
8843 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8844   (interactive
8845    (list (let ((completion-ignore-case t))
8846            (completing-read
8847             "Header name: "
8848             (mapcar (lambda (header) (list (format "%s" header)))
8849                     (append
8850                      '("Number" "Subject" "From" "Lines" "Date"
8851                        "Message-ID" "Xref" "References" "Body")
8852                      gnus-extra-headers))
8853             nil 'require-match))
8854          (read-string "Regexp: ")
8855          (read-key-sequence "Command: ")
8856          current-prefix-arg))
8857   (when (equal header "Body")
8858     (setq header ""))
8859   ;; Hidden thread subtrees must be searched as well.
8860   (gnus-summary-show-all-threads)
8861   ;; We don't want to change current point nor window configuration.
8862   (save-excursion
8863     (save-window-excursion
8864       (let (gnus-visual
8865             gnus-treat-strip-trailing-blank-lines
8866             gnus-treat-strip-leading-blank-lines
8867             gnus-treat-strip-multiple-blank-lines
8868             gnus-treat-hide-boring-headers
8869             gnus-treat-fold-newsgroups
8870             gnus-article-prepare-hook)
8871         (gnus-message 6 "Executing %s..." (key-description command))
8872         ;; We'd like to execute COMMAND interactively so as to give arguments.
8873         (gnus-execute header regexp
8874                       `(call-interactively ',(key-binding command))
8875                       backward)
8876         (gnus-message 6 "Executing %s...done" (key-description command))))))
8877
8878 (defun gnus-summary-beginning-of-article ()
8879   "Scroll the article back to the beginning."
8880   (interactive)
8881   (gnus-summary-select-article)
8882   (gnus-configure-windows 'article)
8883   (gnus-eval-in-buffer-window gnus-article-buffer
8884     (widen)
8885     (goto-char (point-min))
8886     (when gnus-break-pages
8887       (gnus-narrow-to-page))))
8888
8889 (defun gnus-summary-end-of-article ()
8890   "Scroll to the end of the article."
8891   (interactive)
8892   (gnus-summary-select-article)
8893   (gnus-configure-windows 'article)
8894   (gnus-eval-in-buffer-window gnus-article-buffer
8895     (widen)
8896     (goto-char (point-max))
8897     (recenter -3)
8898     (when gnus-break-pages
8899       (when (re-search-backward page-delimiter nil t)
8900         (narrow-to-region (match-end 0) (point-max)))
8901       (gnus-narrow-to-page))))
8902
8903 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8904   "Truncate to LEN and quote all \"(\"'s in STRING."
8905   (gnus-replace-in-string (if (and len (> (length string) len))
8906                               (substring string 0 len)
8907                             string)
8908                           "[()]" "\\\\\\&"))
8909
8910 (defun gnus-summary-print-article (&optional filename n)
8911   "Generate and print a PostScript image of the process-marked (mail) articles.
8912
8913 If used interactively, print the current article if none are
8914 process-marked.  With prefix arg, prompt the user for the name of the
8915 file to save in.
8916
8917 When used from Lisp, accept two optional args FILENAME and N.  N means
8918 to print the next N articles.  If N is negative, print the N previous
8919 articles.  If N is nil and articles have been marked with the process
8920 mark, print these instead.
8921
8922 If the optional first argument FILENAME is nil, send the image to the
8923 printer.  If FILENAME is a string, save the PostScript image in a file with
8924 that name.  If FILENAME is a number, prompt the user for the name of the file
8925 to save in."
8926   (interactive (list (ps-print-preprint current-prefix-arg)))
8927   (dolist (article (gnus-summary-work-articles n))
8928     (gnus-summary-select-article nil nil 'pseudo article)
8929     (gnus-eval-in-buffer-window gnus-article-buffer
8930       (gnus-print-buffer))
8931     (gnus-summary-remove-process-mark article))
8932   (ps-despool filename))
8933
8934 (defun gnus-print-buffer ()
8935   (let ((buffer (generate-new-buffer " *print*")))
8936     (unwind-protect
8937         (progn
8938           (copy-to-buffer buffer (point-min) (point-max))
8939           (set-buffer buffer)
8940           (gnus-remove-text-with-property 'gnus-decoration)
8941           (when (gnus-visual-p 'article-highlight 'highlight)
8942             ;; Copy-to-buffer doesn't copy overlay.  So redo
8943             ;; highlight.
8944             (let ((gnus-article-buffer buffer))
8945               (gnus-article-highlight-citation t)
8946               (gnus-article-highlight-signature)
8947               (gnus-article-emphasize)
8948               (gnus-article-delete-invisible-text)))
8949           (let ((ps-left-header
8950                  (list
8951                   (concat "("
8952                           (gnus-summary-print-truncate-and-quote
8953                            (mail-header-subject gnus-current-headers)
8954                            66) ")")
8955                   (concat "("
8956                           (gnus-summary-print-truncate-and-quote
8957                            (mail-header-from gnus-current-headers)
8958                            45) ")")))
8959                 (ps-right-header
8960                  (list
8961                   "/pagenumberstring load"
8962                   (concat "("
8963                           (mail-header-date gnus-current-headers) ")"))))
8964             (gnus-run-hooks 'gnus-ps-print-hook)
8965             (save-excursion
8966               (if window-system
8967                   (ps-spool-buffer-with-faces)
8968                 (ps-spool-buffer)))))
8969       (kill-buffer buffer))))
8970
8971 (defun gnus-summary-show-article (&optional arg)
8972   "Force redisplaying of the current article.
8973 If ARG (the prefix) is a number, show the article with the charset
8974 defined in `gnus-summary-show-article-charset-alist', or the charset
8975 input.
8976 If ARG (the prefix) is non-nil and not a number, show the raw article
8977 without any article massaging functions being run.  Normally, the key
8978 strokes are `C-u g'."
8979   (interactive "P")
8980   (cond
8981    ((numberp arg)
8982     (gnus-summary-show-article t)
8983     (let ((gnus-newsgroup-charset
8984            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8985                (mm-read-coding-system
8986                 "View as charset: " ;; actually it is coding system.
8987                 (with-current-buffer gnus-article-buffer
8988                   (mm-detect-coding-region (point) (point-max))))))
8989           (gnus-newsgroup-ignored-charsets 'gnus-all))
8990       (gnus-summary-select-article nil 'force)
8991       (let ((deps gnus-newsgroup-dependencies)
8992             head header lines)
8993         (save-excursion
8994           (set-buffer gnus-original-article-buffer)
8995           (save-restriction
8996             (message-narrow-to-head)
8997             (setq head (buffer-string))
8998             (goto-char (point-min))
8999             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9000               (goto-char (point-max))
9001               (widen)
9002               (setq lines (1- (count-lines (point) (point-max))))))
9003           (with-temp-buffer
9004             (insert (format "211 %d Article retrieved.\n"
9005                             (cdr gnus-article-current)))
9006             (insert head)
9007             (if lines (insert (format "Lines: %d\n" lines)))
9008             (insert ".\n")
9009             (let ((nntp-server-buffer (current-buffer)))
9010               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9011         (gnus-data-set-header
9012          (gnus-data-find (cdr gnus-article-current))
9013          header)
9014         (gnus-summary-update-article-line
9015          (cdr gnus-article-current) header)
9016         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9017           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9018    ((not arg)
9019     ;; Select the article the normal way.
9020     (gnus-summary-select-article nil 'force))
9021    (t
9022     ;; We have to require this here to make sure that the following
9023     ;; dynamic binding isn't shadowed by autoloading.
9024     (require 'gnus-async)
9025     (require 'gnus-art)
9026     ;; Bind the article treatment functions to nil.
9027     (let ((gnus-have-all-headers t)
9028           gnus-article-prepare-hook
9029           gnus-article-decode-hook
9030           gnus-display-mime-function
9031           gnus-break-pages)
9032       ;; Destroy any MIME parts.
9033       (when (gnus-buffer-live-p gnus-article-buffer)
9034         (save-excursion
9035           (set-buffer gnus-article-buffer)
9036           (mm-destroy-parts gnus-article-mime-handles)
9037           ;; Set it to nil for safety reason.
9038           (setq gnus-article-mime-handle-alist nil)
9039           (setq gnus-article-mime-handles nil)))
9040       (gnus-summary-select-article nil 'force))))
9041   (gnus-summary-goto-subject gnus-current-article)
9042   (gnus-summary-position-point))
9043
9044 (defun gnus-summary-show-raw-article ()
9045   "Show the raw article without any article massaging functions being run."
9046   (interactive)
9047   (gnus-summary-show-article t))
9048
9049 (defun gnus-summary-verbose-headers (&optional arg)
9050   "Toggle permanent full header display.
9051 If ARG is a positive number, turn header display on.
9052 If ARG is a negative number, turn header display off."
9053   (interactive "P")
9054   (setq gnus-show-all-headers
9055         (cond ((or (not (numberp arg))
9056                    (zerop arg))
9057                (not gnus-show-all-headers))
9058               ((natnump arg)
9059                t)))
9060   (gnus-summary-show-article))
9061
9062 (defun gnus-summary-toggle-header (&optional arg)
9063   "Show the headers if they are hidden, or hide them if they are shown.
9064 If ARG is a positive number, show the entire header.
9065 If ARG is a negative number, hide the unwanted header lines."
9066   (interactive "P")
9067   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9068                      (get-buffer-window gnus-article-buffer t))))
9069     (with-current-buffer gnus-article-buffer
9070       (widen)
9071       (article-narrow-to-head)
9072       (let* ((buffer-read-only nil)
9073              (inhibit-point-motion-hooks t)
9074              (hidden (if (numberp arg)
9075                          (>= arg 0)
9076                        (or (not (looking-at "[^ \t\n]+:"))
9077                            (gnus-article-hidden-text-p 'headers))))
9078              s e)
9079         (delete-region (point-min) (point-max))
9080         (with-current-buffer gnus-original-article-buffer
9081           (goto-char (setq s (point-min)))
9082           (setq e (if (search-forward "\n\n" nil t)
9083                       (1- (point))
9084                     (point-max))))
9085         (insert-buffer-substring gnus-original-article-buffer s e)
9086         (run-hooks 'gnus-article-decode-hook)
9087         (if hidden
9088             (let ((gnus-treat-hide-headers nil)
9089                   (gnus-treat-hide-boring-headers nil))
9090               (gnus-delete-wash-type 'headers)
9091               (gnus-treat-article 'head))
9092           (gnus-treat-article 'head))
9093         (widen)
9094         (if window
9095             (set-window-start window (goto-char (point-min))))
9096         (if gnus-break-pages
9097             (gnus-narrow-to-page)
9098           (when (gnus-visual-p 'page-marker)
9099             (let ((buffer-read-only nil))
9100               (gnus-remove-text-with-property 'gnus-prev)
9101               (gnus-remove-text-with-property 'gnus-next))))
9102         (gnus-set-mode-line 'article)))))
9103
9104 (defun gnus-summary-show-all-headers ()
9105   "Make all header lines visible."
9106   (interactive)
9107   (gnus-summary-toggle-header 1))
9108
9109 (defun gnus-summary-caesar-message (&optional arg)
9110   "Caesar rotate the current article by 13.
9111 The numerical prefix specifies how many places to rotate each letter
9112 forward."
9113   (interactive "P")
9114   (gnus-summary-select-article)
9115   (let ((mail-header-separator ""))
9116     (gnus-eval-in-buffer-window gnus-article-buffer
9117       (save-restriction
9118         (widen)
9119         (let ((start (window-start))
9120               buffer-read-only)
9121           (message-caesar-buffer-body arg)
9122           (set-window-start (get-buffer-window (current-buffer)) start)))))
9123   ;; Create buttons and stuff...
9124   (gnus-treat-article nil))
9125
9126 (defun gnus-summary-idna-message (&optional arg)
9127   "Decode IDNA encoded domain names in the current articles.
9128 IDNA encoded domain names looks like `xn--bar'.  If a string
9129 remain unencoded after running this function, it is likely an
9130 invalid IDNA string (`xn--bar' is invalid).
9131
9132 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9133 installed for this command to work."
9134   (interactive "P")
9135   (if (not (and (condition-case nil (require 'idna)
9136                   (file-error))
9137                 (mm-coding-system-p 'utf-8)
9138                 (executable-find (symbol-value 'idna-program))))
9139       (gnus-message
9140        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9141     (gnus-summary-select-article)
9142     (let ((mail-header-separator ""))
9143       (gnus-eval-in-buffer-window gnus-article-buffer
9144         (save-restriction
9145           (widen)
9146           (let ((start (window-start))
9147                 buffer-read-only)
9148             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9149               (replace-match (idna-to-unicode (match-string 1))))
9150             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9151
9152 (autoload 'unmorse-region "morse"
9153   "Convert morse coded text in region to ordinary ASCII text."
9154   t)
9155
9156 (defun gnus-summary-morse-message (&optional arg)
9157   "Morse decode the current article."
9158   (interactive "P")
9159   (gnus-summary-select-article)
9160   (let ((mail-header-separator ""))
9161     (gnus-eval-in-buffer-window gnus-article-buffer
9162       (save-excursion
9163         (save-restriction
9164           (widen)
9165           (let ((pos (window-start))
9166                 buffer-read-only)
9167             (goto-char (point-min))
9168             (when (message-goto-body)
9169               (gnus-narrow-to-body))
9170             (goto-char (point-min))
9171             (while (search-forward "·" (point-max) t)
9172               (replace-match "."))
9173             (unmorse-region (point-min) (point-max))
9174             (widen)
9175             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9176
9177 (defun gnus-summary-stop-page-breaking ()
9178   "Stop page breaking in the current article."
9179   (interactive)
9180   (gnus-summary-select-article)
9181   (gnus-eval-in-buffer-window gnus-article-buffer
9182     (widen)
9183     (when (gnus-visual-p 'page-marker)
9184       (let ((buffer-read-only nil))
9185         (gnus-remove-text-with-property 'gnus-prev)
9186         (gnus-remove-text-with-property 'gnus-next))
9187       (setq gnus-page-broken nil))))
9188
9189 (defun gnus-summary-move-article (&optional n to-newsgroup
9190                                             select-method action)
9191   "Move the current article to a different newsgroup.
9192 If N is a positive number, move the N next articles.
9193 If N is a negative number, move the N previous articles.
9194 If N is nil and any articles have been marked with the process mark,
9195 move those articles instead.
9196 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9197 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9198 re-spool using this method.
9199
9200 When called interactively with TO-NEWSGROUP being nil, the value of
9201 the variable `gnus-move-split-methods' is used for finding a default
9202 for the target newsgroup.
9203
9204 For this function to work, both the current newsgroup and the
9205 newsgroup that you want to move to have to support the `request-move'
9206 and `request-accept' functions.
9207
9208 ACTION can be either `move' (the default), `crosspost' or `copy'."
9209   (interactive "P")
9210   (unless action
9211     (setq action 'move))
9212   ;; Check whether the source group supports the required functions.
9213   (cond ((and (eq action 'move)
9214               (not (gnus-check-backend-function
9215                     'request-move-article gnus-newsgroup-name)))
9216          (error "The current group does not support article moving"))
9217         ((and (eq action 'crosspost)
9218               (not (gnus-check-backend-function
9219                     'request-replace-article gnus-newsgroup-name)))
9220          (error "The current group does not support article editing")))
9221   (let ((articles (gnus-summary-work-articles n))
9222         (prefix (if (gnus-check-backend-function
9223                      'request-move-article gnus-newsgroup-name)
9224                     (funcall gnus-move-group-prefix-function
9225                              gnus-newsgroup-name)
9226                   ""))
9227         (names '((move "Move" "Moving")
9228                  (copy "Copy" "Copying")
9229                  (crosspost "Crosspost" "Crossposting")))
9230         (copy-buf (save-excursion
9231                     (nnheader-set-temp-buffer " *copy article*")))
9232         art-group to-method new-xref article to-groups articles-to-update-marks)
9233     (unless (assq action names)
9234       (error "Unknown action %s" action))
9235     ;; Read the newsgroup name.
9236     (when (and (not to-newsgroup)
9237                (not select-method))
9238       (if (and gnus-move-split-methods
9239                (not
9240                 (and (memq gnus-current-article articles)
9241                      (gnus-buffer-live-p gnus-original-article-buffer))))
9242           ;; When `gnus-move-split-methods' is non-nil, we have to
9243           ;; select an article to give `gnus-read-move-group-name' an
9244           ;; opportunity to suggest an appropriate default.  However,
9245           ;; we needn't render or mark the article.
9246           (let ((gnus-display-mime-function nil)
9247                 (gnus-article-prepare-hook nil)
9248                 (gnus-mark-article-hook nil))
9249             (gnus-summary-select-article nil nil nil (car articles))))
9250       (setq to-newsgroup
9251             (gnus-read-move-group-name
9252              (cadr (assq action names))
9253              (symbol-value (intern (format "gnus-current-%s-group" action)))
9254              articles prefix))
9255       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9256     (setq to-method (or select-method
9257                         (gnus-server-to-method
9258                          (gnus-group-method to-newsgroup))))
9259     ;; Check the method we are to move this article to...
9260     (unless (gnus-check-backend-function
9261              'request-accept-article (car to-method))
9262       (error "%s does not support article copying" (car to-method)))
9263     (unless (gnus-check-server to-method)
9264       (error "Can't open server %s" (car to-method)))
9265     (gnus-message 6 "%s to %s: %s..."
9266                   (caddr (assq action names))
9267                   (or (car select-method) to-newsgroup) articles)
9268     (while articles
9269       (setq article (pop articles))
9270       (setq
9271        art-group
9272        (cond
9273         ;; Move the article.
9274         ((eq action 'move)
9275          ;; Remove this article from future suppression.
9276          (gnus-dup-unsuppress-article article)
9277          (let* ((from-method (gnus-find-method-for-group
9278                               gnus-newsgroup-name))
9279                 (to-method (gnus-find-method-for-group
9280                             to-newsgroup))
9281                 (move-is-internal (gnus-method-equal from-method to-method)))
9282          (gnus-request-move-article
9283           article                       ; Article to move
9284           gnus-newsgroup-name           ; From newsgroup
9285           (nth 1 (gnus-find-method-for-group
9286                   gnus-newsgroup-name)) ; Server
9287           (list 'gnus-request-accept-article
9288                 to-newsgroup (list 'quote select-method)
9289                 (not articles) t)       ; Accept form
9290           (not articles)                ; Only save nov last time
9291           move-is-internal)))           ; is this move internal?
9292         ;; Copy the article.
9293         ((eq action 'copy)
9294          (save-excursion
9295            (set-buffer copy-buf)
9296            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9297              (save-restriction
9298                (nnheader-narrow-to-headers)
9299                (dolist (hdr gnus-copy-article-ignored-headers)
9300                  (message-remove-header hdr t)))
9301              (gnus-request-accept-article
9302               to-newsgroup select-method (not articles) t))))
9303         ;; Crosspost the article.
9304         ((eq action 'crosspost)
9305          (let ((xref (message-tokenize-header
9306                       (mail-header-xref (gnus-summary-article-header article))
9307                       " ")))
9308            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9309                                   ":" (number-to-string article)))
9310            (unless xref
9311              (setq xref (list (system-name))))
9312            (setq new-xref
9313                  (concat
9314                   (mapconcat 'identity
9315                              (delete "Xref:" (delete new-xref xref))
9316                              " ")
9317                   " " new-xref))
9318            (save-excursion
9319              (set-buffer copy-buf)
9320              ;; First put the article in the destination group.
9321              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9322              (when (consp (setq art-group
9323                                 (gnus-request-accept-article
9324                                  to-newsgroup select-method (not articles))))
9325                (setq new-xref (concat new-xref " " (car art-group)
9326                                       ":"
9327                                       (number-to-string (cdr art-group))))
9328                ;; Now we have the new Xrefs header, so we insert
9329                ;; it and replace the new article.
9330                (nnheader-replace-header "Xref" new-xref)
9331                (gnus-request-replace-article
9332                 (cdr art-group) to-newsgroup (current-buffer))
9333                art-group))))))
9334       (cond
9335        ((not art-group)
9336         (gnus-message 1 "Couldn't %s article %s: %s"
9337                       (cadr (assq action names)) article
9338                       (nnheader-get-report (car to-method))))
9339        ((eq art-group 'junk)
9340         (when (eq action 'move)
9341           (gnus-summary-mark-article article gnus-canceled-mark)
9342           (gnus-message 4 "Deleted article %s" article)
9343           ;; run the delete hook
9344           (run-hook-with-args 'gnus-summary-article-delete-hook
9345                               action
9346                               (gnus-data-header
9347                                (assoc article (gnus-data-list nil)))
9348                               gnus-newsgroup-name nil
9349                               select-method)))
9350        (t
9351         (let* ((pto-group (gnus-group-prefixed-name
9352                            (car art-group) to-method))
9353                (info (gnus-get-info pto-group))
9354                (to-group (gnus-info-group info))
9355                to-marks)
9356           ;; Update the group that has been moved to.
9357           (when (and info
9358                      (memq action '(move copy)))
9359             (unless (member to-group to-groups)
9360               (push to-group to-groups))
9361
9362             (unless (memq article gnus-newsgroup-unreads)
9363               (push 'read to-marks)
9364               (gnus-info-set-read
9365                info (gnus-add-to-range (gnus-info-read info)
9366                                        (list (cdr art-group)))))
9367
9368             ;; See whether the article is to be put in the cache.
9369             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9370                              gnus-article-mark-lists
9371                            (delete '(expirable . expire)
9372                                    (copy-sequence gnus-article-mark-lists))))
9373                   (to-article (cdr art-group)))
9374
9375               ;; Enter the article into the cache in the new group,
9376               ;; if that is required.
9377               (when gnus-use-cache
9378                 (gnus-cache-possibly-enter-article
9379                  to-group to-article
9380                  (memq article gnus-newsgroup-marked)
9381                  (memq article gnus-newsgroup-dormant)
9382                  (memq article gnus-newsgroup-unreads)))
9383
9384               (when gnus-preserve-marks
9385                 ;; Copy any marks over to the new group.
9386                 (when (and (equal to-group gnus-newsgroup-name)
9387                            (not (memq article gnus-newsgroup-unreads)))
9388                   ;; Mark this article as read in this group.
9389                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9390                   (setcdr (gnus-active to-group) to-article)
9391                   (setcdr gnus-newsgroup-active to-article))
9392
9393                 (while marks
9394                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9395                     (when (memq article (symbol-value
9396                                          (intern (format "gnus-newsgroup-%s"
9397                                                          (caar marks)))))
9398                       (push (cdar marks) to-marks)
9399                       ;; If the other group is the same as this group,
9400                       ;; then we have to add the mark to the list.
9401                       (when (equal to-group gnus-newsgroup-name)
9402                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9403                              (cons to-article
9404                                    (symbol-value
9405                                     (intern (format "gnus-newsgroup-%s"
9406                                                     (caar marks)))))))
9407                       ;; Copy the marks to other group.
9408                       (gnus-add-marked-articles
9409                        to-group (cdar marks) (list to-article) info)))
9410                   (setq marks (cdr marks)))
9411
9412                 (gnus-request-set-mark
9413                  to-group (list (list (list to-article) 'add to-marks))))
9414
9415               (gnus-dribble-enter
9416                (concat "(gnus-group-set-info '"
9417                        (gnus-prin1-to-string (gnus-get-info to-group))
9418                        ")"))))
9419
9420           ;; Update the Xref header in this article to point to
9421           ;; the new crossposted article we have just created.
9422           (when (eq action 'crosspost)
9423             (save-excursion
9424               (set-buffer copy-buf)
9425               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9426               (nnheader-replace-header "Xref" new-xref)
9427               (gnus-request-replace-article
9428                article gnus-newsgroup-name (current-buffer))))
9429
9430           ;; run the move/copy/crosspost/respool hook
9431           (run-hook-with-args 'gnus-summary-article-move-hook
9432                               action
9433                               (gnus-data-header
9434                                (assoc article (gnus-data-list nil)))
9435                               gnus-newsgroup-name
9436                               to-newsgroup
9437                               select-method))
9438
9439         ;;;!!!Why is this necessary?
9440         (set-buffer gnus-summary-buffer)
9441         
9442         (gnus-summary-goto-subject article)
9443         (when (eq action 'move)
9444           (gnus-summary-mark-article article gnus-canceled-mark))))
9445       (push article articles-to-update-marks))
9446
9447     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9448     ;; Re-activate all groups that have been moved to.
9449     (save-excursion
9450       (set-buffer gnus-group-buffer)
9451       (let ((gnus-group-marked to-groups))
9452         (gnus-group-get-new-news-this-group nil t)))
9453     
9454     (gnus-kill-buffer copy-buf)
9455     (gnus-summary-position-point)
9456     (gnus-set-mode-line 'summary)))
9457
9458 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9459   "Copy the current article to some other group.
9460 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9461 When called interactively, if TO-NEWSGROUP is nil, use the value of
9462 the variable `gnus-move-split-methods' for finding a default target
9463 newsgroup.
9464 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9465 re-spool using this method."
9466   (interactive "P")
9467   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9468
9469 (defun gnus-summary-crosspost-article (&optional n)
9470   "Crosspost the current article to some other group."
9471   (interactive "P")
9472   (gnus-summary-move-article n nil nil 'crosspost))
9473
9474 (defcustom gnus-summary-respool-default-method nil
9475   "Default method type for respooling an article.
9476 If nil, use to the current newsgroup method."
9477   :type 'symbol
9478   :group 'gnus-summary-mail)
9479
9480 (defcustom gnus-summary-display-while-building nil
9481   "If non-nil, show and update the summary buffer as it's being built.
9482 If the value is t, update the buffer after every line is inserted.  If
9483 the value is an integer (N), update the display every N lines."
9484   :version "22.1"
9485   :group 'gnus-thread
9486   :type '(choice (const :tag "off" nil)
9487                  number
9488                  (const :tag "frequently" t)))
9489
9490 (defun gnus-summary-respool-article (&optional n method)
9491   "Respool the current article.
9492 The article will be squeezed through the mail spooling process again,
9493 which means that it will be put in some mail newsgroup or other
9494 depending on `nnmail-split-methods'.
9495 If N is a positive number, respool the N next articles.
9496 If N is a negative number, respool the N previous articles.
9497 If N is nil and any articles have been marked with the process mark,
9498 respool those articles instead.
9499
9500 Respooling can be done both from mail groups and \"real\" newsgroups.
9501 In the former case, the articles in question will be moved from the
9502 current group into whatever groups they are destined to.  In the
9503 latter case, they will be copied into the relevant groups."
9504   (interactive
9505    (list current-prefix-arg
9506          (let* ((methods (gnus-methods-using 'respool))
9507                 (methname
9508                  (symbol-name (or gnus-summary-respool-default-method
9509                                   (car (gnus-find-method-for-group
9510                                         gnus-newsgroup-name)))))
9511                 (method
9512                  (gnus-completing-read-with-default
9513                   methname "Backend to use when respooling"
9514                   methods nil t nil 'gnus-mail-method-history))
9515                 ms)
9516            (cond
9517             ((zerop (length (setq ms (gnus-servers-using-backend
9518                                       (intern method)))))
9519              (list (intern method) ""))
9520             ((= 1 (length ms))
9521              (car ms))
9522             (t
9523              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9524                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9525                            ms-alist))))))))
9526   (unless method
9527     (error "No method given for respooling"))
9528   (if (assoc (symbol-name
9529               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9530              (gnus-methods-using 'respool))
9531       (gnus-summary-move-article n nil method)
9532     (gnus-summary-copy-article n nil method)))
9533
9534 (defun gnus-summary-import-article (file &optional edit)
9535   "Import an arbitrary file into a mail newsgroup."
9536   (interactive "fImport file: \nP")
9537   (let ((group gnus-newsgroup-name)
9538         (now (current-time))
9539         atts lines group-art)
9540     (unless (gnus-check-backend-function 'request-accept-article group)
9541       (error "%s does not support article importing" group))
9542     (or (file-readable-p file)
9543         (not (file-regular-p file))
9544         (error "Can't read %s" file))
9545     (save-excursion
9546       (set-buffer (gnus-get-buffer-create " *import file*"))
9547       (erase-buffer)
9548       (nnheader-insert-file-contents file)
9549       (goto-char (point-min))
9550       (if (nnheader-article-p)
9551           (save-restriction
9552             (goto-char (point-min))
9553             (search-forward "\n\n" nil t)
9554             (narrow-to-region (point-min) (1- (point)))
9555             (goto-char (point-min))
9556             (unless (re-search-forward "^date:" nil t)
9557               (goto-char (point-max))
9558               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9559        ;; This doesn't look like an article, so we fudge some headers.
9560         (setq atts (file-attributes file)
9561               lines (count-lines (point-min) (point-max)))
9562         (insert "From: " (read-string "From: ") "\n"
9563                 "Subject: " (read-string "Subject: ") "\n"
9564                 "Date: " (message-make-date (nth 5 atts)) "\n"
9565                 "Message-ID: " (message-make-message-id) "\n"
9566                 "Lines: " (int-to-string lines) "\n"
9567                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9568       (setq group-art (gnus-request-accept-article group nil t))
9569       (kill-buffer (current-buffer)))
9570     (setq gnus-newsgroup-active (gnus-activate-group group))
9571     (forward-line 1)
9572     (gnus-summary-goto-article (cdr group-art) nil t)
9573     (when edit
9574       (gnus-summary-edit-article))))
9575
9576 (defun gnus-summary-create-article ()
9577   "Create an article in a mail newsgroup."
9578   (interactive)
9579   (let ((group gnus-newsgroup-name)
9580         (now (current-time))
9581         group-art)
9582     (unless (gnus-check-backend-function 'request-accept-article group)
9583       (error "%s does not support article importing" group))
9584     (save-excursion
9585       (set-buffer (gnus-get-buffer-create " *import file*"))
9586       (erase-buffer)
9587       (goto-char (point-min))
9588       ;; This doesn't look like an article, so we fudge some headers.
9589       (insert "From: " (read-string "From: ") "\n"
9590               "Subject: " (read-string "Subject: ") "\n"
9591               "Date: " (message-make-date now) "\n"
9592               "Message-ID: " (message-make-message-id) "\n")
9593       (setq group-art (gnus-request-accept-article group nil t))
9594       (kill-buffer (current-buffer)))
9595     (setq gnus-newsgroup-active (gnus-activate-group group))
9596     (forward-line 1)
9597     (gnus-summary-goto-article (cdr group-art) nil t)
9598     (gnus-summary-edit-article)))
9599
9600 (defun gnus-summary-article-posted-p ()
9601   "Say whether the current (mail) article is available from news as well.
9602 This will be the case if the article has both been mailed and posted."
9603   (interactive)
9604   (let ((id (mail-header-references (gnus-summary-article-header)))
9605         (gnus-override-method (car (gnus-refer-article-methods))))
9606     (if (gnus-request-head id "")
9607         (gnus-message 2 "The current message was found on %s"
9608                       gnus-override-method)
9609       (gnus-message 2 "The current message couldn't be found on %s"
9610                     gnus-override-method)
9611       nil)))
9612
9613 (defun gnus-summary-expire-articles (&optional now)
9614   "Expire all articles that are marked as expirable in the current group."
9615   (interactive)
9616   (when (and (not gnus-group-is-exiting-without-update-p)
9617              (gnus-check-backend-function
9618               'request-expire-articles gnus-newsgroup-name))
9619     ;; This backend supports expiry.
9620     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9621            (expirable (if total
9622                           (progn
9623                             ;; We need to update the info for
9624                             ;; this group for `gnus-list-of-read-articles'
9625                             ;; to give us the right answer.
9626                             (gnus-run-hooks 'gnus-exit-group-hook)
9627                             (gnus-summary-update-info)
9628                             (gnus-list-of-read-articles gnus-newsgroup-name))
9629                         (setq gnus-newsgroup-expirable
9630                               (sort gnus-newsgroup-expirable '<))))
9631            (expiry-wait (if now 'immediate
9632                           (gnus-group-find-parameter
9633                            gnus-newsgroup-name 'expiry-wait)))
9634            (nnmail-expiry-target
9635             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9636                 nnmail-expiry-target))
9637            es)
9638       (when expirable
9639         ;; There are expirable articles in this group, so we run them
9640         ;; through the expiry process.
9641         (gnus-message 6 "Expiring articles...")
9642         (unless (gnus-check-group gnus-newsgroup-name)
9643           (error "Can't open server for %s" gnus-newsgroup-name))
9644         ;; The list of articles that weren't expired is returned.
9645         (save-excursion
9646           (if expiry-wait
9647               (let ((nnmail-expiry-wait-function nil)
9648                     (nnmail-expiry-wait expiry-wait))
9649                 (setq es (gnus-request-expire-articles
9650                           expirable gnus-newsgroup-name)))
9651             (setq es (gnus-request-expire-articles
9652                       expirable gnus-newsgroup-name)))
9653           (unless total
9654             (setq gnus-newsgroup-expirable es))
9655           ;; We go through the old list of expirable, and mark all
9656           ;; really expired articles as nonexistent.
9657           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9658             (let ((gnus-use-cache nil))
9659               (dolist (article expirable)
9660                 (when (and (not (memq article es))
9661                            (gnus-data-find article))
9662                   (gnus-summary-mark-article article gnus-canceled-mark)
9663                   (run-hook-with-args 'gnus-summary-article-expire-hook
9664                                       'delete
9665                                       (gnus-data-header
9666                                        (assoc article (gnus-data-list nil)))
9667                                       gnus-newsgroup-name
9668                                       nil
9669                                       nil))))))
9670         (gnus-message 6 "Expiring articles...done")))))
9671
9672 (defun gnus-summary-expire-articles-now ()
9673   "Expunge all expirable articles in the current group.
9674 This means that *all* articles that are marked as expirable will be
9675 deleted forever, right now."
9676   (interactive)
9677   (or gnus-expert-user
9678       (gnus-yes-or-no-p
9679        "Are you really, really, really sure you want to delete all these messages? ")
9680       (error "Phew!"))
9681   (gnus-summary-expire-articles t))
9682
9683 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9684 (defun gnus-summary-delete-article (&optional n)
9685   "Delete the N next (mail) articles.
9686 This command actually deletes articles.  This is not a marking
9687 command.  The article will disappear forever from your life, never to
9688 return.
9689
9690 If N is negative, delete backwards.
9691 If N is nil and articles have been marked with the process mark,
9692 delete these instead.
9693
9694 If `gnus-novice-user' is non-nil you will be asked for
9695 confirmation before the articles are deleted."
9696   (interactive "P")
9697   (unless (gnus-check-backend-function 'request-expire-articles
9698                                        gnus-newsgroup-name)
9699     (error "The current newsgroup does not support article deletion"))
9700   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9701     (error "Couldn't open server"))
9702   ;; Compute the list of articles to delete.
9703   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9704         (nnmail-expiry-target 'delete)
9705         not-deleted)
9706     (if (and gnus-novice-user
9707              (not (gnus-yes-or-no-p
9708                    (format "Do you really want to delete %s forever? "
9709                            (if (> (length articles) 1)
9710                                (format "these %s articles" (length articles))
9711                              "this article")))))
9712         ()
9713       ;; Delete the articles.
9714       (setq not-deleted (gnus-request-expire-articles
9715                          articles gnus-newsgroup-name 'force))
9716       (while articles
9717         (gnus-summary-remove-process-mark (car articles))
9718         ;; The backend might not have been able to delete the article
9719         ;; after all.
9720         (unless (memq (car articles) not-deleted)
9721           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9722         (let* ((article (car articles))
9723                (ghead  (gnus-data-header
9724                                     (assoc article (gnus-data-list nil)))))
9725           (run-hook-with-args 'gnus-summary-article-delete-hook
9726                               'delete ghead gnus-newsgroup-name nil
9727                               nil))
9728         (setq articles (cdr articles)))
9729       (when not-deleted
9730         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9731     (gnus-summary-position-point)
9732     (gnus-set-mode-line 'summary)
9733     not-deleted))
9734
9735 (defun gnus-summary-edit-article (&optional arg)
9736   "Edit the current article.
9737 This will have permanent effect only in mail groups.
9738 If ARG is nil, edit the decoded articles.
9739 If ARG is 1, edit the raw articles.
9740 If ARG is 2, edit the raw articles even in read-only groups.
9741 If ARG is 3, edit the articles with the current handles.
9742 Otherwise, allow editing of articles even in read-only
9743 groups."
9744   (interactive "P")
9745   (let (force raw current-handles)
9746     (cond
9747      ((null arg))
9748      ((eq arg 1)
9749       (setq raw t))
9750      ((eq arg 2)
9751       (setq raw t
9752             force t))
9753      ((eq arg 3)
9754       (setq current-handles
9755             (and (gnus-buffer-live-p gnus-article-buffer)
9756                  (with-current-buffer gnus-article-buffer
9757                    (prog1
9758                        gnus-article-mime-handles
9759                      (setq gnus-article-mime-handles nil))))))
9760      (t
9761       (setq force t)))
9762     (when (and raw (not force)
9763                (member gnus-newsgroup-name '("nndraft:delayed"
9764                                              "nndraft:drafts"
9765                                              "nndraft:queue")))
9766       (error "Can't edit the raw article in group %s"
9767              gnus-newsgroup-name))
9768     (save-excursion
9769       (set-buffer gnus-summary-buffer)
9770       (let ((mail-parse-charset gnus-newsgroup-charset)
9771             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9772         (gnus-set-global-variables)
9773         (when (and (not force)
9774                    (gnus-group-read-only-p))
9775           (error "The current newsgroup does not support article editing"))
9776         (gnus-summary-show-article t)
9777         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9778           (with-current-buffer gnus-article-buffer
9779             (mm-enable-multibyte)))
9780         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9781             (setq raw t))
9782         (gnus-article-edit-article
9783          (if raw 'ignore
9784            `(lambda ()
9785               (let ((mbl mml-buffer-list))
9786                 (setq mml-buffer-list nil)
9787                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9788                   (mime-to-mml ,'current-handles))
9789                 (let ((mbl1 mml-buffer-list))
9790                   (setq mml-buffer-list mbl)
9791                   (set (make-local-variable 'mml-buffer-list) mbl1))
9792                 (gnus-make-local-hook 'kill-buffer-hook)
9793                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9794          `(lambda (no-highlight)
9795             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9796                   (message-options message-options)
9797                   (message-options-set-recipient)
9798                   (mail-parse-ignored-charsets
9799                    ',gnus-newsgroup-ignored-charsets))
9800               ,(if (not raw) '(progn
9801                                 (mml-to-mime)
9802                                 (mml-destroy-buffers)
9803                                 (remove-hook 'kill-buffer-hook
9804                                              'mml-destroy-buffers t)
9805                                 (kill-local-variable 'mml-buffer-list)))
9806               (gnus-summary-edit-article-done
9807                ,(or (mail-header-references gnus-current-headers) "")
9808                ,(gnus-group-read-only-p)
9809                ,gnus-summary-buffer no-highlight))))))))
9810
9811 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9812
9813 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9814                                                  no-highlight)
9815   "Make edits to the current article permanent."
9816   (interactive)
9817   (save-excursion
9818    ;; The buffer restriction contains the entire article if it exists.
9819     (when (article-goto-body)
9820       (let ((lines (count-lines (point) (point-max)))
9821             (length (- (point-max) (point)))
9822             (case-fold-search t)
9823             (body (copy-marker (point))))
9824         (goto-char (point-min))
9825         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9826           (delete-region (match-beginning 1) (match-end 1))
9827           (insert (number-to-string length)))
9828         (goto-char (point-min))
9829         (when (re-search-forward
9830                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9831           (delete-region (match-beginning 1) (match-end 1))
9832           (insert (number-to-string length)))
9833         (goto-char (point-min))
9834         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9835           (delete-region (match-beginning 1) (match-end 1))
9836           (insert (number-to-string lines))))))
9837   ;; Replace the article.
9838   (let ((buf (current-buffer)))
9839     (with-temp-buffer
9840       (insert-buffer-substring buf)
9841
9842       (if (and (not read-only)
9843                (not (gnus-request-replace-article
9844                      (cdr gnus-article-current) (car gnus-article-current)
9845                      (current-buffer) t)))
9846           (error "Couldn't replace article")
9847         ;; Update the summary buffer.
9848         (if (and references
9849                  (equal (message-tokenize-header references " ")
9850                         (message-tokenize-header
9851                          (or (message-fetch-field "references") "") " ")))
9852             ;; We only have to update this line.
9853             (save-excursion
9854               (save-restriction
9855                 (message-narrow-to-head)
9856                 (let ((head (buffer-substring-no-properties
9857                              (point-min) (point-max)))
9858                       header)
9859                   (with-temp-buffer
9860                     (insert (format "211 %d Article retrieved.\n"
9861                                     (cdr gnus-article-current)))
9862                     (insert head)
9863                     (insert ".\n")
9864                     (let ((nntp-server-buffer (current-buffer)))
9865                       (setq header (car (gnus-get-newsgroup-headers
9866                                          nil t))))
9867                     (save-excursion
9868                       (set-buffer gnus-summary-buffer)
9869                       (gnus-data-set-header
9870                        (gnus-data-find (cdr gnus-article-current))
9871                        header)
9872                       (gnus-summary-update-article-line
9873                        (cdr gnus-article-current) header)
9874                       (if (gnus-summary-goto-subject
9875                            (cdr gnus-article-current) nil t)
9876                           (gnus-summary-update-secondary-mark
9877                            (cdr gnus-article-current))))))))
9878           ;; Update threads.
9879           (set-buffer (or buffer gnus-summary-buffer))
9880           (gnus-summary-update-article (cdr gnus-article-current))
9881           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9882               (gnus-summary-update-secondary-mark
9883                (cdr gnus-article-current))))
9884         ;; Prettify the article buffer again.
9885         (unless no-highlight
9886           (save-excursion
9887             (set-buffer gnus-article-buffer)
9888             ;;;!!! Fix this -- article should be rehighlighted.
9889             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9890             (set-buffer gnus-original-article-buffer)
9891             (gnus-request-article
9892              (cdr gnus-article-current)
9893              (car gnus-article-current) (current-buffer))))
9894         ;; Prettify the summary buffer line.
9895         (when (gnus-visual-p 'summary-highlight 'highlight)
9896           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9897
9898 (defun gnus-summary-edit-wash (key)
9899   "Perform editing command KEY in the article buffer."
9900   (interactive
9901    (list
9902     (progn
9903       (message "%s" (concat (this-command-keys) "- "))
9904       (read-char))))
9905   (message "")
9906   (gnus-summary-edit-article)
9907   (execute-kbd-macro (concat (this-command-keys) key))
9908   (gnus-article-edit-done))
9909
9910 ;;; Respooling
9911
9912 (defun gnus-summary-respool-query (&optional silent trace)
9913   "Query where the respool algorithm would put this article."
9914   (interactive)
9915   (let (gnus-mark-article-hook)
9916     (gnus-summary-select-article)
9917     (save-excursion
9918       (set-buffer gnus-original-article-buffer)
9919       (let ((groups (nnmail-article-group 'identity trace)))
9920         (unless silent
9921           (if groups
9922               (message "This message would go to %s"
9923                        (mapconcat 'car groups ", "))
9924             (message "This message would go to no groups"))
9925           groups)))))
9926
9927 (defun gnus-summary-respool-trace ()
9928   "Trace where the respool algorithm would put this article.
9929 Display a buffer showing all fancy splitting patterns which matched."
9930   (interactive)
9931   (gnus-summary-respool-query nil t))
9932
9933 ;; Summary marking commands.
9934
9935 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9936   "Mark articles which has the same subject as read, and then select the next.
9937 If UNMARK is positive, remove any kind of mark.
9938 If UNMARK is negative, tick articles."
9939   (interactive "P")
9940   (when unmark
9941     (setq unmark (prefix-numeric-value unmark)))
9942   (let ((count
9943          (gnus-summary-mark-same-subject
9944           (gnus-summary-article-subject) unmark)))
9945     ;; Select next unread article.  If auto-select-same mode, should
9946     ;; select the first unread article.
9947     (gnus-summary-next-article t (and gnus-auto-select-same
9948                                       (gnus-summary-article-subject)))
9949     (gnus-message 7 "%d article%s marked as %s"
9950                   count (if (= count 1) " is" "s are")
9951                   (if unmark "unread" "read"))))
9952
9953 (defun gnus-summary-kill-same-subject (&optional unmark)
9954   "Mark articles which has the same subject as read.
9955 If UNMARK is positive, remove any kind of mark.
9956 If UNMARK is negative, tick articles."
9957   (interactive "P")
9958   (when unmark
9959     (setq unmark (prefix-numeric-value unmark)))
9960   (let ((count
9961          (gnus-summary-mark-same-subject
9962           (gnus-summary-article-subject) unmark)))
9963     ;; If marked as read, go to next unread subject.
9964     (when (null unmark)
9965       ;; Go to next unread subject.
9966       (gnus-summary-next-subject 1 t))
9967     (gnus-message 7 "%d articles are marked as %s"
9968                   count (if unmark "unread" "read"))))
9969
9970 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9971   "Mark articles with same SUBJECT as read, and return marked number.
9972 If optional argument UNMARK is positive, remove any kinds of marks.
9973 If optional argument UNMARK is negative, mark articles as unread instead."
9974   (let ((count 1))
9975     (save-excursion
9976       (cond
9977        ((null unmark)                   ; Mark as read.
9978         (while (and
9979                 (progn
9980                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9981                   (gnus-summary-show-thread) t)
9982                 (gnus-summary-find-subject subject))
9983           (setq count (1+ count))))
9984        ((> unmark 0)                    ; Tick.
9985         (while (and
9986                 (progn
9987                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9988                   (gnus-summary-show-thread) t)
9989                 (gnus-summary-find-subject subject))
9990           (setq count (1+ count))))
9991        (t                               ; Mark as unread.
9992         (while (and
9993                 (progn
9994                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9995                   (gnus-summary-show-thread) t)
9996                 (gnus-summary-find-subject subject))
9997           (setq count (1+ count)))))
9998       (gnus-set-mode-line 'summary)
9999       ;; Return the number of marked articles.
10000       count)))
10001
10002 (defun gnus-summary-mark-as-processable (n &optional unmark)
10003   "Set the process mark on the next N articles.
10004 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10005 the process mark instead.  The difference between N and the actual
10006 number of articles marked is returned."
10007   (interactive "P")
10008   (if (and (null n) (gnus-region-active-p))
10009       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10010     (setq n (prefix-numeric-value n))
10011     (let ((backward (< n 0))
10012           (n (abs n)))
10013       (while (and
10014               (> n 0)
10015               (if unmark
10016                   (gnus-summary-remove-process-mark
10017                    (gnus-summary-article-number))
10018                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10019               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10020         (setq n (1- n)))
10021       (when (/= 0 n)
10022         (gnus-message 7 "No more articles"))
10023       (gnus-summary-recenter)
10024       (gnus-summary-position-point)
10025       n)))
10026
10027 (defun gnus-summary-unmark-as-processable (n)
10028   "Remove the process mark from the next N articles.
10029 If N is negative, unmark backward instead.  The difference between N and
10030 the actual number of articles unmarked is returned."
10031   (interactive "P")
10032   (gnus-summary-mark-as-processable n t))
10033
10034 (defun gnus-summary-unmark-all-processable ()
10035   "Remove the process mark from all articles."
10036   (interactive)
10037   (save-excursion
10038     (while gnus-newsgroup-processable
10039       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10040   (gnus-summary-position-point))
10041
10042 (defun gnus-summary-add-mark (article type)
10043   "Mark ARTICLE with a mark of TYPE."
10044   (let ((vtype (car (assq type gnus-article-mark-lists)))
10045         var)
10046     (if (not vtype)
10047         (error "No such mark type: %s" type)
10048       (setq var (intern (format "gnus-newsgroup-%s" type)))
10049       (set var (cons article (symbol-value var)))
10050       (if (memq type '(processable cached replied forwarded recent saved))
10051           (gnus-summary-update-secondary-mark article)
10052         ;;; !!! This is bogus.  We should find out what primary
10053         ;;; !!! mark we want to set.
10054         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10055
10056 (defun gnus-summary-mark-as-expirable (n)
10057   "Mark N articles forward as expirable.
10058 If N is negative, mark backward instead.  The difference between N and
10059 the actual number of articles marked is returned."
10060   (interactive "p")
10061   (gnus-summary-mark-forward n gnus-expirable-mark))
10062
10063 (defun gnus-summary-mark-as-spam (n)
10064   "Mark N articles forward as spam.
10065 If N is negative, mark backward instead.  The difference between N and
10066 the actual number of articles marked is returned."
10067   (interactive "p")
10068   (gnus-summary-mark-forward n gnus-spam-mark))
10069
10070 (defun gnus-summary-mark-article-as-replied (article)
10071   "Mark ARTICLE as replied to and update the summary line.
10072 ARTICLE can also be a list of articles."
10073   (interactive (list (gnus-summary-article-number)))
10074   (let ((articles (if (listp article) article (list article))))
10075     (dolist (article articles)
10076       (unless (numberp article)
10077         (error "%s is not a number" article))
10078       (push article gnus-newsgroup-replied)
10079       (let ((buffer-read-only nil))
10080         (when (gnus-summary-goto-subject article nil t)
10081           (gnus-summary-update-secondary-mark article))))))
10082
10083 (defun gnus-summary-mark-article-as-forwarded (article)
10084   "Mark ARTICLE as forwarded and update the summary line.
10085 ARTICLE can also be a list of articles."
10086   (let ((articles (if (listp article) article (list article))))
10087     (dolist (article articles)
10088       (push article gnus-newsgroup-forwarded)
10089       (let ((buffer-read-only nil))
10090         (when (gnus-summary-goto-subject article nil t)
10091           (gnus-summary-update-secondary-mark article))))))
10092
10093 (defun gnus-summary-set-bookmark (article)
10094   "Set a bookmark in current article."
10095   (interactive (list (gnus-summary-article-number)))
10096   (when (or (not (get-buffer gnus-article-buffer))
10097             (not gnus-current-article)
10098             (not gnus-article-current)
10099             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10100     (error "No current article selected"))
10101   ;; Remove old bookmark, if one exists.
10102   (gnus-pull article gnus-newsgroup-bookmarks)
10103   ;; Set the new bookmark, which is on the form
10104   ;; (article-number . line-number-in-body).
10105   (push
10106    (cons article
10107          (with-current-buffer gnus-article-buffer
10108            (count-lines
10109             (min (point)
10110                  (save-excursion
10111                    (article-goto-body)
10112                    (point)))
10113             (point))))
10114    gnus-newsgroup-bookmarks)
10115   (gnus-message 6 "A bookmark has been added to the current article."))
10116
10117 (defun gnus-summary-remove-bookmark (article)
10118   "Remove the bookmark from the current article."
10119   (interactive (list (gnus-summary-article-number)))
10120   ;; Remove old bookmark, if one exists.
10121   (if (not (assq article gnus-newsgroup-bookmarks))
10122       (gnus-message 6 "No bookmark in current article.")
10123     (gnus-pull article gnus-newsgroup-bookmarks)
10124     (gnus-message 6 "Removed bookmark.")))
10125
10126 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10127 (defun gnus-summary-mark-as-dormant (n)
10128   "Mark N articles forward as dormant.
10129 If N is negative, mark backward instead.  The difference between N and
10130 the actual number of articles marked is returned."
10131   (interactive "p")
10132   (gnus-summary-mark-forward n gnus-dormant-mark))
10133
10134 (defun gnus-summary-set-process-mark (article)
10135   "Set the process mark on ARTICLE and update the summary line."
10136   (setq gnus-newsgroup-processable
10137         (cons article
10138               (delq article gnus-newsgroup-processable)))
10139   (when (gnus-summary-goto-subject article)
10140     (gnus-summary-show-thread)
10141     (gnus-summary-goto-subject article)
10142     (gnus-summary-update-secondary-mark article)))
10143
10144 (defun gnus-summary-remove-process-mark (&rest articles)
10145   "Remove the process mark from ARTICLES and update the summary line."
10146   (dolist (article articles)
10147     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10148     (when (gnus-summary-goto-subject article)
10149       (gnus-summary-show-thread)
10150       (gnus-summary-goto-subject article)
10151       (gnus-summary-update-secondary-mark article)))
10152   t)
10153
10154 (defun gnus-summary-set-saved-mark (article)
10155   "Set the process mark on ARTICLE and update the summary line."
10156   (push article gnus-newsgroup-saved)
10157   (when (gnus-summary-goto-subject article)
10158     (gnus-summary-update-secondary-mark article)))
10159
10160 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10161   "Mark N articles as read forwards.
10162 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10163 The difference between N and the actual number of articles marked is
10164 returned.
10165 If NO-EXPIRE, auto-expiry will be inhibited."
10166   (interactive "p")
10167   (gnus-summary-show-thread)
10168   (let ((backward (< n 0))
10169         (gnus-summary-goto-unread
10170          (and gnus-summary-goto-unread
10171               (not (eq gnus-summary-goto-unread 'never))
10172               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10173                                     gnus-ticked-mark gnus-dormant-mark)))))
10174         (n (abs n))
10175         (mark (or mark gnus-del-mark)))
10176     (while (and (> n 0)
10177                 (gnus-summary-mark-article nil mark no-expire)
10178                 (zerop (gnus-summary-next-subject
10179                         (if backward -1 1)
10180                         (and gnus-summary-goto-unread
10181                              (not (eq gnus-summary-goto-unread 'never)))
10182                         t)))
10183       (setq n (1- n)))
10184     (when (/= 0 n)
10185       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10186     (gnus-summary-recenter)
10187     (gnus-summary-position-point)
10188     (gnus-set-mode-line 'summary)
10189     n))
10190
10191 (defun gnus-summary-mark-article-as-read (mark)
10192   "Mark the current article quickly as read with MARK."
10193   (let ((article (gnus-summary-article-number)))
10194     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10195     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10196     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10197     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10198     (push (cons article mark) gnus-newsgroup-reads)
10199     ;; Possibly remove from cache, if that is used.
10200     (when gnus-use-cache
10201       (gnus-cache-enter-remove-article article))
10202     ;; Allow the backend to change the mark.
10203     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10204     ;; Check for auto-expiry.
10205     (when (and gnus-newsgroup-auto-expire
10206                (memq mark gnus-auto-expirable-marks))
10207       (setq mark gnus-expirable-mark)
10208       ;; Let the backend know about the mark change.
10209       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10210       (push article gnus-newsgroup-expirable))
10211     ;; Set the mark in the buffer.
10212     (gnus-summary-update-mark mark 'unread)
10213     t))
10214
10215 (defun gnus-summary-mark-article-as-unread (mark)
10216   "Mark the current article quickly as unread with MARK."
10217   (let* ((article (gnus-summary-article-number))
10218          (old-mark (gnus-summary-article-mark article)))
10219     ;; Allow the backend to change the mark.
10220     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10221     (if (eq mark old-mark)
10222         t
10223       (if (<= article 0)
10224           (progn
10225             (gnus-error 1 "Can't mark negative article numbers")
10226             nil)
10227         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10228         (setq gnus-newsgroup-spam-marked
10229               (delq article gnus-newsgroup-spam-marked))
10230         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10231         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10232         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10233         (cond ((= mark gnus-ticked-mark)
10234                (setq gnus-newsgroup-marked
10235                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10236                                               article)))
10237               ((= mark gnus-spam-mark)
10238                (setq gnus-newsgroup-spam-marked
10239                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10240                                               article)))
10241               ((= mark gnus-dormant-mark)
10242                (setq gnus-newsgroup-dormant
10243                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10244                                               article)))
10245               (t
10246                (setq gnus-newsgroup-unreads
10247                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10248                                               article))))
10249         (gnus-pull article gnus-newsgroup-reads)
10250
10251         ;; See whether the article is to be put in the cache.
10252         (and gnus-use-cache
10253              (vectorp (gnus-summary-article-header article))
10254              (save-excursion
10255                (gnus-cache-possibly-enter-article
10256                 gnus-newsgroup-name article
10257                 (= mark gnus-ticked-mark)
10258                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10259
10260         ;; Fix the mark.
10261         (gnus-summary-update-mark mark 'unread)
10262         t))))
10263
10264 (defun gnus-summary-mark-article (&optional article mark no-expire)
10265   "Mark ARTICLE with MARK.  MARK can be any character.
10266 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10267 `??' (dormant) and `?E' (expirable).
10268 If MARK is nil, then the default character `?r' is used.
10269 If ARTICLE is nil, then the article on the current line will be
10270 marked.
10271 If NO-EXPIRE, auto-expiry will be inhibited."
10272   ;; The mark might be a string.
10273   (when (stringp mark)
10274     (setq mark (aref mark 0)))
10275   ;; If no mark is given, then we check auto-expiring.
10276   (when (null mark)
10277     (setq mark gnus-del-mark))
10278   (when (and (not no-expire)
10279              gnus-newsgroup-auto-expire
10280              (memq mark gnus-auto-expirable-marks))
10281     (setq mark gnus-expirable-mark))
10282   (let ((article (or article (gnus-summary-article-number)))
10283         (old-mark (gnus-summary-article-mark article)))
10284     ;; Allow the backend to change the mark.
10285     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10286     (if (eq mark old-mark)
10287         t
10288       (unless article
10289         (error "No article on current line"))
10290       (if (not (if (or (= mark gnus-unread-mark)
10291                        (= mark gnus-ticked-mark)
10292                        (= mark gnus-spam-mark)
10293                        (= mark gnus-dormant-mark))
10294                    (gnus-mark-article-as-unread article mark)
10295                  (gnus-mark-article-as-read article mark)))
10296           t
10297         ;; See whether the article is to be put in the cache.
10298         (and gnus-use-cache
10299              (not (= mark gnus-canceled-mark))
10300              (vectorp (gnus-summary-article-header article))
10301              (save-excursion
10302                (gnus-cache-possibly-enter-article
10303                 gnus-newsgroup-name article
10304                 (= mark gnus-ticked-mark)
10305                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10306
10307         (when (gnus-summary-goto-subject article nil t)
10308           (let ((buffer-read-only nil))
10309             (gnus-summary-show-thread)
10310             ;; Fix the mark.
10311             (gnus-summary-update-mark mark 'unread)
10312             t))))))
10313
10314 (defun gnus-summary-update-secondary-mark (article)
10315   "Update the secondary (read, process, cache) mark."
10316   (gnus-summary-update-mark
10317    (cond ((memq article gnus-newsgroup-processable)
10318           gnus-process-mark)
10319          ((memq article gnus-newsgroup-cached)
10320           gnus-cached-mark)
10321          ((memq article gnus-newsgroup-replied)
10322           gnus-replied-mark)
10323          ((memq article gnus-newsgroup-forwarded)
10324           gnus-forwarded-mark)
10325          ((memq article gnus-newsgroup-saved)
10326           gnus-saved-mark)
10327          ((memq article gnus-newsgroup-recent)
10328           gnus-recent-mark)
10329          ((memq article gnus-newsgroup-unseen)
10330           gnus-unseen-mark)
10331          (t gnus-no-mark))
10332    'replied)
10333   (when (gnus-visual-p 'summary-highlight 'highlight)
10334     (gnus-run-hooks 'gnus-summary-update-hook))
10335   t)
10336
10337 (defun gnus-summary-update-download-mark (article)
10338   "Update the download mark."
10339   (gnus-summary-update-mark
10340    (cond ((memq article gnus-newsgroup-undownloaded)
10341           gnus-undownloaded-mark)
10342          (gnus-newsgroup-agentized
10343           gnus-downloaded-mark)
10344          (t
10345           gnus-no-mark))
10346    'download)
10347   (gnus-summary-update-line t)
10348   t)
10349
10350 (defun gnus-summary-update-mark (mark type)
10351   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10352         (buffer-read-only nil))
10353     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10354     (when forward
10355       (when (looking-at "\r")
10356         (incf forward))
10357       (when (<= (+ forward (point)) (point-max))
10358         ;; Go to the right position on the line.
10359         (goto-char (+ forward (point)))
10360         ;; Replace the old mark with the new mark.
10361         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10362         ;; Optionally update the marks by some user rule.
10363         (when (eq type 'unread)
10364           (gnus-data-set-mark
10365            (gnus-data-find (gnus-summary-article-number)) mark)
10366           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10367
10368 (defun gnus-mark-article-as-read (article &optional mark)
10369   "Enter ARTICLE in the pertinent lists and remove it from others."
10370   ;; Make the article expirable.
10371   (let ((mark (or mark gnus-del-mark)))
10372     (setq gnus-newsgroup-expirable
10373           (if (= mark gnus-expirable-mark)
10374               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10375             (delq article gnus-newsgroup-expirable)))
10376     ;; Remove from unread and marked lists.
10377     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10378     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10379     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10380     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10381     (push (cons article mark) gnus-newsgroup-reads)
10382     ;; Possibly remove from cache, if that is used.
10383     (when gnus-use-cache
10384       (gnus-cache-enter-remove-article article))
10385     t))
10386
10387 (defun gnus-mark-article-as-unread (article &optional mark)
10388   "Enter ARTICLE in the pertinent lists and remove it from others."
10389   (let ((mark (or mark gnus-ticked-mark)))
10390     (if (<= article 0)
10391         (progn
10392           (gnus-error 1 "Can't mark negative article numbers")
10393           nil)
10394       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10395             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10396             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10397             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10398             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10399
10400       ;; Unsuppress duplicates?
10401       (when gnus-suppress-duplicates
10402         (gnus-dup-unsuppress-article article))
10403
10404       (cond ((= mark gnus-ticked-mark)
10405              (setq gnus-newsgroup-marked
10406                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10407             ((= mark gnus-spam-mark)
10408              (setq gnus-newsgroup-spam-marked
10409                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10410                                             article)))
10411             ((= mark gnus-dormant-mark)
10412              (setq gnus-newsgroup-dormant
10413                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10414             (t
10415              (setq gnus-newsgroup-unreads
10416                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10417       (gnus-pull article gnus-newsgroup-reads)
10418       t)))
10419
10420 (defalias 'gnus-summary-mark-as-unread-forward
10421   'gnus-summary-tick-article-forward)
10422 (make-obsolete 'gnus-summary-mark-as-unread-forward
10423                'gnus-summary-tick-article-forward)
10424 (defun gnus-summary-tick-article-forward (n)
10425   "Tick N articles forwards.
10426 If N is negative, tick backwards instead.
10427 The difference between N and the number of articles ticked is returned."
10428   (interactive "p")
10429   (gnus-summary-mark-forward n gnus-ticked-mark))
10430
10431 (defalias 'gnus-summary-mark-as-unread-backward
10432   'gnus-summary-tick-article-backward)
10433 (make-obsolete 'gnus-summary-mark-as-unread-backward
10434                'gnus-summary-tick-article-backward)
10435 (defun gnus-summary-tick-article-backward (n)
10436   "Tick N articles backwards.
10437 The difference between N and the number of articles ticked is returned."
10438   (interactive "p")
10439   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10440
10441 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10442 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10443 (defun gnus-summary-tick-article (&optional article clear-mark)
10444   "Mark current article as unread.
10445 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10446 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10447   (interactive)
10448   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10449                                        gnus-ticked-mark)))
10450
10451 (defun gnus-summary-mark-as-read-forward (n)
10452   "Mark N articles as read forwards.
10453 If N is negative, mark backwards instead.
10454 The difference between N and the actual number of articles marked is
10455 returned."
10456   (interactive "p")
10457   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10458
10459 (defun gnus-summary-mark-as-read-backward (n)
10460   "Mark the N articles as read backwards.
10461 The difference between N and the actual number of articles marked is
10462 returned."
10463   (interactive "p")
10464   (gnus-summary-mark-forward
10465    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10466
10467 (defun gnus-summary-mark-as-read (&optional article mark)
10468   "Mark current article as read.
10469 ARTICLE specifies the article to be marked as read.
10470 MARK specifies a string to be inserted at the beginning of the line."
10471   (gnus-summary-mark-article article mark))
10472
10473 (defun gnus-summary-clear-mark-forward (n)
10474   "Clear marks from N articles forward.
10475 If N is negative, clear backward instead.
10476 The difference between N and the number of marks cleared is returned."
10477   (interactive "p")
10478   (gnus-summary-mark-forward n gnus-unread-mark))
10479
10480 (defun gnus-summary-clear-mark-backward (n)
10481   "Clear marks from N articles backward.
10482 The difference between N and the number of marks cleared is returned."
10483   (interactive "p")
10484   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10485
10486 (defun gnus-summary-mark-unread-as-read ()
10487   "Intended to be used by `gnus-summary-mark-article-hook'."
10488   (when (memq gnus-current-article gnus-newsgroup-unreads)
10489     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10490
10491 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10492   "Intended to be used by `gnus-summary-mark-article-hook'."
10493   (let ((mark (gnus-summary-article-mark)))
10494     (when (or (gnus-unread-mark-p mark)
10495               (gnus-read-mark-p mark))
10496       (gnus-summary-mark-article gnus-current-article
10497                                  (or new-mark gnus-read-mark)))))
10498
10499 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10500   "Intended to be used by `gnus-summary-mark-article-hook'."
10501   (let ((mark (gnus-summary-article-mark)))
10502     (when (or (gnus-unread-mark-p mark)
10503               (gnus-read-mark-p mark))
10504       (gnus-summary-mark-article (gnus-summary-article-number)
10505                                  (or new-mark gnus-read-mark)))))
10506
10507 (defun gnus-summary-mark-unread-as-ticked ()
10508   "Intended to be used by `gnus-summary-mark-article-hook'."
10509   (when (memq gnus-current-article gnus-newsgroup-unreads)
10510     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10511
10512 (defun gnus-summary-mark-region-as-read (point mark all)
10513   "Mark all unread articles between point and mark as read.
10514 If given a prefix, mark all articles between point and mark as read,
10515 even ticked and dormant ones."
10516   (interactive "r\nP")
10517   (save-excursion
10518     (let (article)
10519       (goto-char point)
10520       (beginning-of-line)
10521       (while (and
10522               (< (point) mark)
10523               (progn
10524                 (when (or all
10525                           (memq (setq article (gnus-summary-article-number))
10526                                 gnus-newsgroup-unreads))
10527                   (gnus-summary-mark-article article gnus-del-mark))
10528                 t)
10529               (gnus-summary-find-next))))))
10530
10531 (defun gnus-summary-mark-below (score mark)
10532   "Mark articles with score less than SCORE with MARK."
10533   (interactive "P\ncMark: ")
10534   (setq score (if score
10535                   (prefix-numeric-value score)
10536                 (or gnus-summary-default-score 0)))
10537   (save-excursion
10538     (set-buffer gnus-summary-buffer)
10539     (goto-char (point-min))
10540     (while
10541         (progn
10542           (and (< (gnus-summary-article-score) score)
10543                (gnus-summary-mark-article nil mark))
10544           (gnus-summary-find-next)))))
10545
10546 (defun gnus-summary-kill-below (&optional score)
10547   "Mark articles with score below SCORE as read."
10548   (interactive "P")
10549   (gnus-summary-mark-below score gnus-killed-mark))
10550
10551 (defun gnus-summary-clear-above (&optional score)
10552   "Clear all marks from articles with score above SCORE."
10553   (interactive "P")
10554   (gnus-summary-mark-above score gnus-unread-mark))
10555
10556 (defun gnus-summary-tick-above (&optional score)
10557   "Tick all articles with score above SCORE."
10558   (interactive "P")
10559   (gnus-summary-mark-above score gnus-ticked-mark))
10560
10561 (defun gnus-summary-mark-above (score mark)
10562   "Mark articles with score over SCORE with MARK."
10563   (interactive "P\ncMark: ")
10564   (setq score (if score
10565                   (prefix-numeric-value score)
10566                 (or gnus-summary-default-score 0)))
10567   (save-excursion
10568     (set-buffer gnus-summary-buffer)
10569     (goto-char (point-min))
10570     (while (and (progn
10571                   (when (> (gnus-summary-article-score) score)
10572                     (gnus-summary-mark-article nil mark))
10573                   t)
10574                 (gnus-summary-find-next)))))
10575
10576 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10577 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10578 (defun gnus-summary-limit-include-expunged (&optional no-error)
10579   "Display all the hidden articles that were expunged for low scores."
10580   (interactive)
10581   (let ((buffer-read-only nil))
10582     (let ((scored gnus-newsgroup-scored)
10583           headers h)
10584       (while scored
10585         (unless (gnus-summary-article-header (caar scored))
10586           (and (setq h (gnus-number-to-header (caar scored)))
10587                (< (cdar scored) gnus-summary-expunge-below)
10588                (push h headers)))
10589         (setq scored (cdr scored)))
10590       (if (not headers)
10591           (when (not no-error)
10592             (error "No expunged articles hidden"))
10593         (goto-char (point-min))
10594         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10595         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10596         (mapcar (lambda (x) (push (mail-header-number x)
10597                                   gnus-newsgroup-limit))
10598                 headers)
10599         (gnus-summary-prepare-unthreaded (nreverse headers))
10600         (goto-char (point-min))
10601         (gnus-summary-position-point)
10602         t))))
10603
10604 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10605   "Mark all unread articles in this newsgroup as read.
10606 If prefix argument ALL is non-nil, ticked and dormant articles will
10607 also be marked as read.
10608 If QUIETLY is non-nil, no questions will be asked.
10609
10610 If TO-HERE is non-nil, it should be a point in the buffer.  All
10611 articles before (after, if REVERSE is set) this point will be marked
10612 as read.
10613
10614 Note that this function will only catch up the unread article
10615 in the current summary buffer limitation.
10616
10617 The number of articles marked as read is returned."
10618   (interactive "P")
10619   (prog1
10620       (save-excursion
10621         (when (or quietly
10622                   (not gnus-interactive-catchup) ;Without confirmation?
10623                   gnus-expert-user
10624                   (gnus-y-or-n-p
10625                    (if all
10626                        "Mark absolutely all articles as read? "
10627                      "Mark all unread articles as read? ")))
10628           (if (and not-mark
10629                    (not gnus-newsgroup-adaptive)
10630                    (not gnus-newsgroup-auto-expire)
10631                    (not gnus-suppress-duplicates)
10632                    (or (not gnus-use-cache)
10633                        (eq gnus-use-cache 'passive)))
10634               (progn
10635                 (when all
10636                   (setq gnus-newsgroup-marked nil
10637                         gnus-newsgroup-spam-marked nil
10638                         gnus-newsgroup-dormant nil))
10639                 (setq gnus-newsgroup-unreads
10640                       (gnus-sorted-nunion
10641                        (gnus-intersection gnus-newsgroup-unreads
10642                                           gnus-newsgroup-downloadable)
10643                        gnus-newsgroup-unfetched)))
10644             ;; We actually mark all articles as canceled, which we
10645             ;; have to do when using auto-expiry or adaptive scoring.
10646             (gnus-summary-show-all-threads)
10647             (if (and to-here reverse)
10648                 (progn
10649                   (goto-char to-here)
10650                   (gnus-summary-mark-current-read-and-unread-as-read
10651                    gnus-catchup-mark)
10652                   (while (gnus-summary-find-next (not all))
10653                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10654               (when (gnus-summary-first-subject (not all))
10655                 (while (and
10656                         (if to-here (< (point) to-here) t)
10657                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10658                         (gnus-summary-find-next (not all))))))
10659             (gnus-set-mode-line 'summary))
10660           t))
10661     (gnus-summary-position-point)))
10662
10663 (defun gnus-summary-catchup-to-here (&optional all)
10664   "Mark all unticked articles before the current one as read.
10665 If ALL is non-nil, also mark ticked and dormant articles as read."
10666   (interactive "P")
10667   (save-excursion
10668     (gnus-save-hidden-threads
10669       (let ((beg (point)))
10670         ;; We check that there are unread articles.
10671         (when (or all (gnus-summary-find-prev))
10672           (gnus-summary-catchup all t beg)))))
10673   (gnus-summary-position-point))
10674
10675 (defun gnus-summary-catchup-from-here (&optional all)
10676   "Mark all unticked articles after (and including) the current one as read.
10677 If ALL is non-nil, also mark ticked and dormant articles as read."
10678   (interactive "P")
10679   (save-excursion
10680     (gnus-save-hidden-threads
10681       (let ((beg (point)))
10682         ;; We check that there are unread articles.
10683         (when (or all (gnus-summary-find-next))
10684           (gnus-summary-catchup all t beg nil t)))))
10685   (gnus-summary-position-point))
10686
10687 (defun gnus-summary-catchup-all (&optional quietly)
10688   "Mark all articles in this newsgroup as read.
10689 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10690 instead, which marks only unread articles as read."
10691   (interactive "P")
10692   (gnus-summary-catchup t quietly))
10693
10694 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10695   "Mark all unread articles in this group as read, then exit.
10696 If prefix argument ALL is non-nil, all articles are marked as read.
10697 If QUIETLY is non-nil, no questions will be asked."
10698   (interactive "P")
10699   (when (gnus-summary-catchup all quietly nil 'fast)
10700     ;; Select next newsgroup or exit.
10701     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10702              (eq gnus-auto-select-next 'quietly))
10703         (gnus-summary-next-group nil)
10704       (gnus-summary-exit))))
10705
10706 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10707   "Mark all articles in this newsgroup as read, and then exit.
10708 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10709 instead, which marks only unread articles as read."
10710   (interactive "P")
10711   (gnus-summary-catchup-and-exit t quietly))
10712
10713 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10714   "Mark all articles in this group as read and select the next group.
10715 If given a prefix, mark all articles, unread as well as ticked, as
10716 read."
10717   (interactive "P")
10718   (save-excursion
10719     (gnus-summary-catchup all))
10720   (gnus-summary-next-group))
10721
10722 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10723   "Mark all articles in this group as read and select the previous group.
10724 If given a prefix, mark all articles, unread as well as ticked, as
10725 read."
10726   (interactive "P")
10727   (save-excursion
10728     (gnus-summary-catchup all))
10729   (gnus-summary-next-group nil nil t))
10730
10731 ;;;
10732 ;;; with article
10733 ;;;
10734
10735 (defmacro gnus-with-article (article &rest forms)
10736   "Select ARTICLE and perform FORMS in the original article buffer.
10737 Then replace the article with the result."
10738   `(progn
10739      ;; We don't want the article to be marked as read.
10740      (let (gnus-mark-article-hook)
10741        (gnus-summary-select-article t t nil ,article))
10742      (set-buffer gnus-original-article-buffer)
10743      ,@forms
10744      (if (not (gnus-check-backend-function
10745                'request-replace-article (car gnus-article-current)))
10746          (gnus-message 5 "Read-only group; not replacing")
10747        (unless (gnus-request-replace-article
10748                 ,article (car gnus-article-current)
10749                 (current-buffer) t)
10750          (error "Couldn't replace article")))
10751      ;; The cache and backlog have to be flushed somewhat.
10752      (when gnus-keep-backlog
10753        (gnus-backlog-remove-article
10754         (car gnus-article-current) (cdr gnus-article-current)))
10755      (when gnus-use-cache
10756        (gnus-cache-update-article
10757         (car gnus-article-current) (cdr gnus-article-current)))))
10758
10759 (put 'gnus-with-article 'lisp-indent-function 1)
10760 (put 'gnus-with-article 'edebug-form-spec '(form body))
10761
10762 ;; Thread-based commands.
10763
10764 (defun gnus-summary-articles-in-thread (&optional article)
10765   "Return a list of all articles in the current thread.
10766 If ARTICLE is non-nil, return all articles in the thread that starts
10767 with that article."
10768   (let* ((article (or article (gnus-summary-article-number)))
10769          (data (gnus-data-find-list article))
10770          (top-level (gnus-data-level (car data)))
10771          (top-subject
10772           (cond ((null gnus-thread-operation-ignore-subject)
10773                  (gnus-simplify-subject-re
10774                   (mail-header-subject (gnus-data-header (car data)))))
10775                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10776                  (gnus-simplify-subject-fuzzy
10777                   (mail-header-subject (gnus-data-header (car data)))))
10778                 (t nil)))
10779          (end-point (save-excursion
10780                       (if (gnus-summary-go-to-next-thread)
10781                           (point) (point-max))))
10782          articles)
10783     (while (and data
10784                 (< (gnus-data-pos (car data)) end-point))
10785       (when (or (not top-subject)
10786                 (string= top-subject
10787                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10788                              (gnus-simplify-subject-fuzzy
10789                               (mail-header-subject
10790                                (gnus-data-header (car data))))
10791                            (gnus-simplify-subject-re
10792                             (mail-header-subject
10793                              (gnus-data-header (car data)))))))
10794         (push (gnus-data-number (car data)) articles))
10795       (unless (and (setq data (cdr data))
10796                    (> (gnus-data-level (car data)) top-level))
10797         (setq data nil)))
10798     ;; Return the list of articles.
10799     (nreverse articles)))
10800
10801 (defun gnus-summary-rethread-current ()
10802   "Rethread the thread the current article is part of."
10803   (interactive)
10804   (let* ((gnus-show-threads t)
10805          (article (gnus-summary-article-number))
10806          (id (mail-header-id (gnus-summary-article-header)))
10807          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10808     (unless id
10809       (error "No article on the current line"))
10810     (gnus-rebuild-thread id)
10811     (gnus-summary-goto-subject article)))
10812
10813 (defun gnus-summary-reparent-thread ()
10814   "Make the current article child of the marked (or previous) article.
10815
10816 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10817 is non-nil or the Subject: of both articles are the same."
10818   (interactive)
10819   (unless (not (gnus-group-read-only-p))
10820     (error "The current newsgroup does not support article editing"))
10821   (unless (<= (length gnus-newsgroup-processable) 1)
10822     (error "No more than one article may be marked"))
10823   (save-window-excursion
10824     (let ((gnus-article-buffer " *reparent*")
10825           (current-article (gnus-summary-article-number))
10826           ;; First grab the marked article, otherwise one line up.
10827           (parent-article (if (not (null gnus-newsgroup-processable))
10828                               (car gnus-newsgroup-processable)
10829                             (save-excursion
10830                               (if (eq (forward-line -1) 0)
10831                                   (gnus-summary-article-number)
10832                                 (error "Beginning of summary buffer"))))))
10833       (unless (not (eq current-article parent-article))
10834         (error "An article may not be self-referential"))
10835       (let ((message-id (mail-header-id
10836                          (gnus-summary-article-header parent-article))))
10837         (unless (and message-id (not (equal message-id "")))
10838           (error "No message-id in desired parent"))
10839         (gnus-with-article current-article
10840           (save-restriction
10841             (goto-char (point-min))
10842             (message-narrow-to-head)
10843             (if (re-search-forward "^References: " nil t)
10844                 (progn
10845                   (re-search-forward "^[^ \t]" nil t)
10846                   (forward-line -1)
10847                   (end-of-line)
10848                   (insert " " message-id))
10849               (insert "References: " message-id "\n"))))
10850         (set-buffer gnus-summary-buffer)
10851         (gnus-summary-unmark-all-processable)
10852         (gnus-summary-update-article current-article)
10853         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10854             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10855         (gnus-summary-rethread-current)
10856         (gnus-message 3 "Article %d is now the child of article %d"
10857                       current-article parent-article)))))
10858
10859 (defun gnus-summary-toggle-threads (&optional arg)
10860   "Toggle showing conversation threads.
10861 If ARG is positive number, turn showing conversation threads on."
10862   (interactive "P")
10863   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10864     (setq gnus-show-threads
10865           (if (null arg) (not gnus-show-threads)
10866             (> (prefix-numeric-value arg) 0)))
10867     (gnus-summary-prepare)
10868     (gnus-summary-goto-subject current)
10869     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10870     (gnus-summary-position-point)))
10871
10872 (defun gnus-summary-show-all-threads ()
10873   "Show all threads."
10874   (interactive)
10875   (save-excursion
10876     (let ((buffer-read-only nil))
10877       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10878   (gnus-summary-position-point))
10879
10880 (defun gnus-summary-show-thread ()
10881   "Show thread subtrees.
10882 Returns nil if no thread was there to be shown."
10883   (interactive)
10884   (let ((buffer-read-only nil)
10885         (orig (point))
10886         (end (point-at-eol))
10887         ;; Leave point at bol
10888         (beg (progn (beginning-of-line) (point))))
10889     (prog1
10890         ;; Any hidden lines here?
10891         (search-forward "\r" end t)
10892       (subst-char-in-region beg end ?\^M ?\n t)
10893       (goto-char orig)
10894       (gnus-summary-position-point))))
10895
10896 (defun gnus-summary-maybe-hide-threads ()
10897   "If requested, hide the threads that should be hidden."
10898   (when (and gnus-show-threads
10899              gnus-thread-hide-subtree)
10900     (gnus-summary-hide-all-threads
10901      (if (or (consp gnus-thread-hide-subtree)
10902              (functionp gnus-thread-hide-subtree))
10903          (gnus-make-predicate gnus-thread-hide-subtree)
10904        nil))))
10905
10906 ;;; Hiding predicates.
10907
10908 (defun gnus-article-unread-p (header)
10909   (memq (mail-header-number header) gnus-newsgroup-unreads))
10910
10911 (defun gnus-article-unseen-p (header)
10912   (memq (mail-header-number header) gnus-newsgroup-unseen))
10913
10914 (defun gnus-map-articles (predicate articles)
10915   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10916   (apply 'gnus-or (mapcar predicate
10917                           (mapcar (lambda (number)
10918                                     (gnus-summary-article-header number))
10919                                   articles))))
10920
10921 (defun gnus-summary-hide-all-threads (&optional predicate)
10922   "Hide all thread subtrees.
10923 If PREDICATE is supplied, threads that satisfy this predicate
10924 will not be hidden."
10925   (interactive)
10926   (save-excursion
10927     (goto-char (point-min))
10928     (let ((end nil))
10929       (while (not end)
10930         (when (or (not predicate)
10931                   (gnus-map-articles
10932                    predicate (gnus-summary-article-children)))
10933             (gnus-summary-hide-thread))
10934         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10935   (gnus-summary-position-point))
10936
10937 (defun gnus-summary-hide-thread ()
10938   "Hide thread subtrees.
10939 If PREDICATE is supplied, threads that satisfy this predicate
10940 will not be hidden.
10941 Returns nil if no threads were there to be hidden."
10942   (interactive)
10943   (let ((buffer-read-only nil)
10944         (start (point))
10945         (article (gnus-summary-article-number)))
10946     (goto-char start)
10947     ;; Go forward until either the buffer ends or the subthread
10948     ;; ends.
10949     (when (and (not (eobp))
10950                (or (zerop (gnus-summary-next-thread 1 t))
10951                    (goto-char (point-max))))
10952       (prog1
10953           (if (and (> (point) start)
10954                    (search-backward "\n" start t))
10955               (progn
10956                 (subst-char-in-region start (point) ?\n ?\^M)
10957                 (gnus-summary-goto-subject article))
10958             (goto-char start)
10959             nil)))))
10960
10961 (defun gnus-summary-go-to-next-thread (&optional previous)
10962   "Go to the same level (or less) next thread.
10963 If PREVIOUS is non-nil, go to previous thread instead.
10964 Return the article number moved to, or nil if moving was impossible."
10965   (let ((level (gnus-summary-thread-level))
10966         (way (if previous -1 1))
10967         (beg (point)))
10968     (forward-line way)
10969     (while (and (not (eobp))
10970                 (< level (gnus-summary-thread-level)))
10971       (forward-line way))
10972     (if (eobp)
10973         (progn
10974           (goto-char beg)
10975           nil)
10976       (setq beg (point))
10977       (prog1
10978           (gnus-summary-article-number)
10979         (goto-char beg)))))
10980
10981 (defun gnus-summary-next-thread (n &optional silent)
10982   "Go to the same level next N'th thread.
10983 If N is negative, search backward instead.
10984 Returns the difference between N and the number of skips actually
10985 done.
10986
10987 If SILENT, don't output messages."
10988   (interactive "p")
10989   (let ((backward (< n 0))
10990         (n (abs n)))
10991     (while (and (> n 0)
10992                 (gnus-summary-go-to-next-thread backward))
10993       (decf n))
10994     (unless silent
10995       (gnus-summary-position-point))
10996     (when (and (not silent) (/= 0 n))
10997       (gnus-message 7 "No more threads"))
10998     n))
10999
11000 (defun gnus-summary-prev-thread (n)
11001   "Go to the same level previous N'th thread.
11002 Returns the difference between N and the number of skips actually
11003 done."
11004   (interactive "p")
11005   (gnus-summary-next-thread (- n)))
11006
11007 (defun gnus-summary-go-down-thread ()
11008   "Go down one level in the current thread."
11009   (let ((children (gnus-summary-article-children)))
11010     (when children
11011       (gnus-summary-goto-subject (car children)))))
11012
11013 (defun gnus-summary-go-up-thread ()
11014   "Go up one level in the current thread."
11015   (let ((parent (gnus-summary-article-parent)))
11016     (when parent
11017       (gnus-summary-goto-subject parent))))
11018
11019 (defun gnus-summary-down-thread (n)
11020   "Go down thread N steps.
11021 If N is negative, go up instead.
11022 Returns the difference between N and how many steps down that were
11023 taken."
11024   (interactive "p")
11025   (let ((up (< n 0))
11026         (n (abs n)))
11027     (while (and (> n 0)
11028                 (if up (gnus-summary-go-up-thread)
11029                   (gnus-summary-go-down-thread)))
11030       (setq n (1- n)))
11031     (gnus-summary-position-point)
11032     (when (/= 0 n)
11033       (gnus-message 7 "Can't go further"))
11034     n))
11035
11036 (defun gnus-summary-up-thread (n)
11037   "Go up thread N steps.
11038 If N is negative, go down instead.
11039 Returns the difference between N and how many steps down that were
11040 taken."
11041   (interactive "p")
11042   (gnus-summary-down-thread (- n)))
11043
11044 (defun gnus-summary-top-thread ()
11045   "Go to the top of the thread."
11046   (interactive)
11047   (while (gnus-summary-go-up-thread))
11048   (gnus-summary-article-number))
11049
11050 (defun gnus-summary-kill-thread (&optional unmark)
11051   "Mark articles under current thread as read.
11052 If the prefix argument is positive, remove any kinds of marks.
11053 If the prefix argument is negative, tick articles instead."
11054   (interactive "P")
11055   (when unmark
11056     (setq unmark (prefix-numeric-value unmark)))
11057   (let ((articles (gnus-summary-articles-in-thread)))
11058     (save-excursion
11059       ;; Expand the thread.
11060       (gnus-summary-show-thread)
11061       ;; Mark all the articles.
11062       (while articles
11063         (gnus-summary-goto-subject (car articles))
11064         (cond ((null unmark)
11065                (gnus-summary-mark-article-as-read gnus-killed-mark))
11066               ((> unmark 0)
11067                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11068               (t
11069                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11070         (setq articles (cdr articles))))
11071     ;; Hide killed subtrees.
11072     (and (null unmark)
11073          gnus-thread-hide-killed
11074          (gnus-summary-hide-thread))
11075     ;; If marked as read, go to next unread subject.
11076     (when (null unmark)
11077       ;; Go to next unread subject.
11078       (gnus-summary-next-subject 1 t)))
11079   (gnus-set-mode-line 'summary))
11080
11081 ;; Summary sorting commands
11082
11083 (defun gnus-summary-sort-by-number (&optional reverse)
11084   "Sort the summary buffer by article number.
11085 Argument REVERSE means reverse order."
11086   (interactive "P")
11087   (gnus-summary-sort 'number reverse))
11088
11089 (defun gnus-summary-sort-by-random (&optional reverse)
11090   "Randomize the order in the summary buffer.
11091 Argument REVERSE means to randomize in reverse order."
11092   (interactive "P")
11093   (gnus-summary-sort 'random reverse))
11094
11095 (defun gnus-summary-sort-by-author (&optional reverse)
11096   "Sort the summary buffer by author name alphabetically.
11097 If `case-fold-search' is non-nil, case of letters is ignored.
11098 Argument REVERSE means reverse order."
11099   (interactive "P")
11100   (gnus-summary-sort 'author reverse))
11101
11102 (defun gnus-summary-sort-by-recipient (&optional reverse)
11103   "Sort the summary buffer by recipient name alphabetically.
11104 If `case-fold-search' is non-nil, case of letters is ignored.
11105 Argument REVERSE means reverse order."
11106   (interactive "P")
11107   (gnus-summary-sort 'recipient reverse))
11108
11109 (defun gnus-summary-sort-by-subject (&optional reverse)
11110   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11111 If `case-fold-search' is non-nil, case of letters is ignored.
11112 Argument REVERSE means reverse order."
11113   (interactive "P")
11114   (gnus-summary-sort 'subject reverse))
11115
11116 (defun gnus-summary-sort-by-date (&optional reverse)
11117   "Sort the summary buffer by date.
11118 Argument REVERSE means reverse order."
11119   (interactive "P")
11120   (gnus-summary-sort 'date reverse))
11121
11122 (defun gnus-summary-sort-by-score (&optional reverse)
11123   "Sort the summary buffer by score.
11124 Argument REVERSE means reverse order."
11125   (interactive "P")
11126   (gnus-summary-sort 'score reverse))
11127
11128 (defun gnus-summary-sort-by-lines (&optional reverse)
11129   "Sort the summary buffer by the number of lines.
11130 Argument REVERSE means reverse order."
11131   (interactive "P")
11132   (gnus-summary-sort 'lines reverse))
11133
11134 (defun gnus-summary-sort-by-chars (&optional reverse)
11135   "Sort the summary buffer by article length.
11136 Argument REVERSE means reverse order."
11137   (interactive "P")
11138   (gnus-summary-sort 'chars reverse))
11139
11140 (defun gnus-summary-sort-by-original (&optional reverse)
11141   "Sort the summary buffer using the default sorting method.
11142 Argument REVERSE means reverse order."
11143   (interactive "P")
11144   (let* ((buffer-read-only)
11145          (gnus-summary-prepare-hook nil))
11146     ;; We do the sorting by regenerating the threads.
11147     (gnus-summary-prepare)
11148     ;; Hide subthreads if needed.
11149     (gnus-summary-maybe-hide-threads)))
11150
11151 (defun gnus-summary-sort (predicate reverse)
11152   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11153   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11154          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11155          (gnus-thread-sort-functions
11156           (if (not reverse)
11157               thread
11158             `(lambda (t1 t2)
11159                (,thread t2 t1))))
11160          (gnus-sort-gathered-threads-function
11161           gnus-thread-sort-functions)
11162          (gnus-article-sort-functions
11163           (if (not reverse)
11164               article
11165             `(lambda (t1 t2)
11166                (,article t2 t1))))
11167          (buffer-read-only)
11168          (gnus-summary-prepare-hook nil))
11169     ;; We do the sorting by regenerating the threads.
11170     (gnus-summary-prepare)
11171     ;; Hide subthreads if needed.
11172     (gnus-summary-maybe-hide-threads)))
11173
11174 ;; Summary saving commands.
11175
11176 (defun gnus-summary-save-article (&optional n not-saved)
11177   "Save the current article using the default saver function.
11178 If N is a positive number, save the N next articles.
11179 If N is a negative number, save the N previous articles.
11180 If N is nil and any articles have been marked with the process mark,
11181 save those articles instead.
11182 The variable `gnus-default-article-saver' specifies the saver function."
11183   (interactive "P")
11184   (let* ((articles (gnus-summary-work-articles n))
11185          (save-buffer (save-excursion
11186                         (nnheader-set-temp-buffer " *Gnus Save*")))
11187          (num (length articles))
11188          header file)
11189     (dolist (article articles)
11190       (setq header (gnus-summary-article-header article))
11191       (if (not (vectorp header))
11192           ;; This is a pseudo-article.
11193           (if (assq 'name header)
11194               (gnus-copy-file (cdr (assq 'name header)))
11195             (gnus-message 1 "Article %d is unsaveable" article))
11196         ;; This is a real article.
11197         (save-window-excursion
11198           (let ((gnus-display-mime-function nil)
11199                 (gnus-article-prepare-hook nil))
11200             (gnus-summary-select-article t nil nil article)))
11201         (save-excursion
11202           (set-buffer save-buffer)
11203           (erase-buffer)
11204           (insert-buffer-substring gnus-original-article-buffer))
11205         (setq file (gnus-article-save save-buffer file num))
11206         (gnus-summary-remove-process-mark article)
11207         (unless not-saved
11208           (gnus-summary-set-saved-mark article))))
11209     (gnus-kill-buffer save-buffer)
11210     (gnus-summary-position-point)
11211     (gnus-set-mode-line 'summary)
11212     n))
11213
11214 (defun gnus-summary-pipe-output (&optional arg headers)
11215   "Pipe the current article to a subprocess.
11216 If N is a positive number, pipe the N next articles.
11217 If N is a negative number, pipe the N previous articles.
11218 If N is nil and any articles have been marked with the process mark,
11219 pipe those articles instead.
11220 If HEADERS (the symbolic prefix), include the headers, too."
11221   (interactive (gnus-interactive "P\ny"))
11222   (require 'gnus-art)
11223   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11224         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11225     (gnus-summary-save-article arg t))
11226   (let ((buffer (get-buffer "*Shell Command Output*")))
11227     (when (and buffer
11228                (not (zerop (buffer-size buffer))))
11229       (gnus-configure-windows 'pipe))))
11230
11231 (defun gnus-summary-save-article-mail (&optional arg)
11232   "Append the current article to an mail file.
11233 If N is a positive number, save the N next articles.
11234 If N is a negative number, save the N previous articles.
11235 If N is nil and any articles have been marked with the process mark,
11236 save those articles instead."
11237   (interactive "P")
11238   (require 'gnus-art)
11239   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11240     (gnus-summary-save-article arg)))
11241
11242 (defun gnus-summary-save-article-rmail (&optional arg)
11243   "Append the current article to an rmail file.
11244 If N is a positive number, save the N next articles.
11245 If N is a negative number, save the N previous articles.
11246 If N is nil and any articles have been marked with the process mark,
11247 save those articles instead."
11248   (interactive "P")
11249   (require 'gnus-art)
11250   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11251     (gnus-summary-save-article arg)))
11252
11253 (defun gnus-summary-save-article-file (&optional arg)
11254   "Append the current article to a file.
11255 If N is a positive number, save the N next articles.
11256 If N is a negative number, save the N previous articles.
11257 If N is nil and any articles have been marked with the process mark,
11258 save those articles instead."
11259   (interactive "P")
11260   (require 'gnus-art)
11261   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11262     (gnus-summary-save-article arg)))
11263
11264 (defun gnus-summary-write-article-file (&optional arg)
11265   "Write the current article to a file, deleting the previous file.
11266 If N is a positive number, save the N next articles.
11267 If N is a negative number, save the N previous articles.
11268 If N is nil and any articles have been marked with the process mark,
11269 save those articles instead."
11270   (interactive "P")
11271   (require 'gnus-art)
11272   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11273     (gnus-summary-save-article arg)))
11274
11275 (defun gnus-summary-save-article-body-file (&optional arg)
11276   "Append the current article body to a file.
11277 If N is a positive number, save the N next articles.
11278 If N is a negative number, save the N previous articles.
11279 If N is nil and any articles have been marked with the process mark,
11280 save those articles instead."
11281   (interactive "P")
11282   (require 'gnus-art)
11283   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11284     (gnus-summary-save-article arg)))
11285
11286 (defun gnus-summary-muttprint (&optional arg)
11287   "Print the current article using Muttprint.
11288 If N is a positive number, save the N next articles.
11289 If N is a negative number, save the N previous articles.
11290 If N is nil and any articles have been marked with the process mark,
11291 save those articles instead."
11292   (interactive "P")
11293   (require 'gnus-art)
11294   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11295     (gnus-summary-save-article arg t)))
11296
11297 (defun gnus-summary-pipe-message (program)
11298   "Pipe the current article through PROGRAM."
11299   (interactive "sProgram: ")
11300   (gnus-summary-select-article)
11301   (let ((mail-header-separator ""))
11302     (gnus-eval-in-buffer-window gnus-article-buffer
11303       (save-restriction
11304         (widen)
11305         (let ((start (window-start))
11306               buffer-read-only)
11307           (message-pipe-buffer-body program)
11308           (set-window-start (get-buffer-window (current-buffer)) start))))))
11309
11310 (defun gnus-get-split-value (methods)
11311   "Return a value based on the split METHODS."
11312   (let (split-name method result match)
11313     (when methods
11314       (save-excursion
11315         (set-buffer gnus-original-article-buffer)
11316         (save-restriction
11317           (nnheader-narrow-to-headers)
11318           (while (and methods (not split-name))
11319             (goto-char (point-min))
11320             (setq method (pop methods))
11321             (setq match (car method))
11322             (when (cond
11323                    ((stringp match)
11324                     ;; Regular expression.
11325                     (ignore-errors
11326                       (re-search-forward match nil t)))
11327                    ((functionp match)
11328                     ;; Function.
11329                     (save-restriction
11330                       (widen)
11331                       (setq result (funcall match gnus-newsgroup-name))))
11332                    ((consp match)
11333                     ;; Form.
11334                     (save-restriction
11335                       (widen)
11336                       (setq result (eval match)))))
11337               (setq split-name (cdr method))
11338               (cond ((stringp result)
11339                      (push (expand-file-name
11340                             result gnus-article-save-directory)
11341                            split-name))
11342                     ((consp result)
11343                      (setq split-name (append result split-name)))))))))
11344     (nreverse split-name)))
11345
11346 (defun gnus-valid-move-group-p (group)
11347   (and (boundp group)
11348        (symbol-name group)
11349        (symbol-value group)
11350        (gnus-get-function (gnus-find-method-for-group
11351                            (symbol-name group)) 'request-accept-article t)))
11352
11353 (defun gnus-read-move-group-name (prompt default articles prefix)
11354   "Read a group name."
11355   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11356          (minibuffer-confirm-incomplete nil) ; XEmacs
11357          (prom
11358           (format "%s %s to"
11359                   prompt
11360                   (if (> (length articles) 1)
11361                       (format "these %d articles" (length articles))
11362                     "this article")))
11363          (to-newsgroup
11364           (cond
11365            ((null split-name)
11366             (gnus-completing-read-with-default
11367              default prom
11368              gnus-active-hashtb
11369              'gnus-valid-move-group-p
11370              nil prefix
11371              'gnus-group-history))
11372            ((= 1 (length split-name))
11373             (gnus-completing-read-with-default
11374              (car split-name) prom
11375              gnus-active-hashtb
11376              'gnus-valid-move-group-p
11377              nil nil
11378              'gnus-group-history))
11379            (t
11380             (gnus-completing-read-with-default
11381              nil prom
11382              (mapcar 'list (nreverse split-name))
11383              nil nil nil
11384              'gnus-group-history))))
11385          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11386     (when to-newsgroup
11387       (if (or (string= to-newsgroup "")
11388               (string= to-newsgroup prefix))
11389           (setq to-newsgroup default))
11390       (unless to-newsgroup
11391         (error "No group name entered"))
11392       (or (gnus-active to-newsgroup)
11393           (gnus-activate-group to-newsgroup nil nil to-method)
11394           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11395                                      to-newsgroup))
11396               (or (and (gnus-request-create-group to-newsgroup to-method)
11397                        (gnus-activate-group
11398                         to-newsgroup nil nil to-method)
11399                        (gnus-subscribe-group to-newsgroup))
11400                   (error "Couldn't create group %s" to-newsgroup)))
11401           (error "No such group: %s" to-newsgroup)))
11402     to-newsgroup))
11403
11404 (defun gnus-summary-save-parts (type dir n &optional reverse)
11405   "Save parts matching TYPE to DIR.
11406 If REVERSE, save parts that do not match TYPE."
11407   (interactive
11408    (list (read-string "Save parts of type: "
11409                       (or (car gnus-summary-save-parts-type-history)
11410                           gnus-summary-save-parts-default-mime)
11411                       'gnus-summary-save-parts-type-history)
11412          (setq gnus-summary-save-parts-last-directory
11413                (read-file-name "Save to directory: "
11414                                gnus-summary-save-parts-last-directory
11415                                nil t))
11416          current-prefix-arg))
11417   (gnus-summary-iterate n
11418     (let ((gnus-display-mime-function nil)
11419           (gnus-inhibit-treatment t))
11420       (gnus-summary-select-article))
11421     (save-excursion
11422       (set-buffer gnus-article-buffer)
11423       (let ((handles (or gnus-article-mime-handles
11424                          (mm-dissect-buffer nil gnus-article-loose-mime)
11425                          (and gnus-article-emulate-mime
11426                               (mm-uu-dissect)))))
11427         (when handles
11428           (gnus-summary-save-parts-1 type dir handles reverse)
11429           (unless gnus-article-mime-handles ;; Don't destroy this case.
11430             (mm-destroy-parts handles)))))))
11431
11432 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11433   (if (stringp (car handle))
11434       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11435               (cdr handle))
11436     (when (if reverse
11437               (not (string-match type (mm-handle-media-type handle)))
11438             (string-match type (mm-handle-media-type handle)))
11439       (let ((file (expand-file-name
11440                    (gnus-map-function
11441                     mm-file-name-rewrite-functions
11442                     (file-name-nondirectory
11443                      (or
11444                       (mail-content-type-get
11445                        (mm-handle-disposition handle) 'filename)
11446                       (mail-content-type-get
11447                        (mm-handle-type handle) 'name)
11448                       (concat gnus-newsgroup-name
11449                               "." (number-to-string
11450                                    (cdr gnus-article-current))))))
11451                    dir)))
11452         (unless (file-exists-p file)
11453           (mm-save-part-to-file handle file))))))
11454
11455 ;; Summary extract commands
11456
11457 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11458   (let ((buffer-read-only nil)
11459         (article (gnus-summary-article-number))
11460         after-article b e)
11461     (unless (gnus-summary-goto-subject article)
11462       (error "No such article: %d" article))
11463     (gnus-summary-position-point)
11464     ;; If all commands are to be bunched up on one line, we collect
11465     ;; them here.
11466     (unless gnus-view-pseudos-separately
11467       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11468             files action)
11469         (while ps
11470           (setq action (cdr (assq 'action (car ps))))
11471           (setq files (list (cdr (assq 'name (car ps)))))
11472           (while (and ps (cdr ps)
11473                       (string= (or action "1")
11474                                (or (cdr (assq 'action (cadr ps))) "2")))
11475             (push (cdr (assq 'name (cadr ps))) files)
11476             (setcdr ps (cddr ps)))
11477           (when files
11478             (when (not (string-match "%s" action))
11479               (push " " files))
11480             (push " " files)
11481             (when (assq 'execute (car ps))
11482               (setcdr (assq 'execute (car ps))
11483                       (funcall (if (string-match "%s" action)
11484                                    'format 'concat)
11485                                action
11486                                (mapconcat
11487                                 (lambda (f)
11488                                   (if (equal f " ")
11489                                       f
11490                                     (shell-quote-argument f)))
11491                                 files " ")))))
11492           (setq ps (cdr ps)))))
11493     (if (and gnus-view-pseudos (not not-view))
11494         (while pslist
11495           (when (assq 'execute (car pslist))
11496             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11497                                   (eq gnus-view-pseudos 'not-confirm)))
11498           (setq pslist (cdr pslist)))
11499       (save-excursion
11500         (while pslist
11501           (setq after-article (or (cdr (assq 'article (car pslist)))
11502                                   (gnus-summary-article-number)))
11503           (gnus-summary-goto-subject after-article)
11504           (forward-line 1)
11505           (setq b (point))
11506           (insert "    " (file-name-nondirectory
11507                           (cdr (assq 'name (car pslist))))
11508                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11509           (setq e (point))
11510           (forward-line -1)             ; back to `b'
11511           (gnus-add-text-properties
11512            b (1- e) (list 'gnus-number gnus-reffed-article-number
11513                           gnus-mouse-face-prop gnus-mouse-face))
11514           (gnus-data-enter
11515            after-article gnus-reffed-article-number
11516            gnus-unread-mark b (car pslist) 0 (- e b))
11517           (setq gnus-newsgroup-unreads
11518                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11519                                          gnus-reffed-article-number))
11520           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11521           (setq pslist (cdr pslist)))))))
11522
11523 (defun gnus-pseudos< (p1 p2)
11524   (let ((c1 (cdr (assq 'action p1)))
11525         (c2 (cdr (assq 'action p2))))
11526     (and c1 c2 (string< c1 c2))))
11527
11528 (defun gnus-request-pseudo-article (props)
11529   (cond ((assq 'execute props)
11530          (gnus-execute-command (cdr (assq 'execute props)))))
11531   (let ((gnus-current-article (gnus-summary-article-number)))
11532     (gnus-run-hooks 'gnus-mark-article-hook)))
11533
11534 (defun gnus-execute-command (command &optional automatic)
11535   (save-excursion
11536     (gnus-article-setup-buffer)
11537     (set-buffer gnus-article-buffer)
11538     (setq buffer-read-only nil)
11539     (let ((command (if automatic command
11540                      (read-string "Command: " (cons command 0)))))
11541       (erase-buffer)
11542       (insert "$ " command "\n\n")
11543       (if gnus-view-pseudo-asynchronously
11544           (start-process "gnus-execute" (current-buffer) shell-file-name
11545                          shell-command-switch command)
11546         (call-process shell-file-name nil t nil
11547                       shell-command-switch command)))))
11548
11549 ;; Summary kill commands.
11550
11551 (defun gnus-summary-edit-global-kill (article)
11552   "Edit the \"global\" kill file."
11553   (interactive (list (gnus-summary-article-number)))
11554   (gnus-group-edit-global-kill article))
11555
11556 (defun gnus-summary-edit-local-kill ()
11557   "Edit a local kill file applied to the current newsgroup."
11558   (interactive)
11559   (setq gnus-current-headers (gnus-summary-article-header))
11560   (gnus-group-edit-local-kill
11561    (gnus-summary-article-number) gnus-newsgroup-name))
11562
11563 ;;; Header reading.
11564
11565 (defun gnus-read-header (id &optional header)
11566   "Read the headers of article ID and enter them into the Gnus system."
11567   (let ((group gnus-newsgroup-name)
11568         (gnus-override-method
11569          (or
11570           gnus-override-method
11571           (and (gnus-news-group-p gnus-newsgroup-name)
11572                (car (gnus-refer-article-methods)))))
11573         where)
11574     ;; First we check to see whether the header in question is already
11575     ;; fetched.
11576     (if (stringp id)
11577         ;; This is a Message-ID.
11578         (setq header (or header (gnus-id-to-header id)))
11579       ;; This is an article number.
11580       (setq header (or header (gnus-summary-article-header id))))
11581     (if (and header
11582              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11583         ;; We have found the header.
11584         header
11585       ;; We have to really fetch the header to this article.
11586       (save-excursion
11587         (set-buffer nntp-server-buffer)
11588         (when (setq where (gnus-request-head id group))
11589           (nnheader-fold-continuation-lines)
11590           (goto-char (point-max))
11591           (insert ".\n")
11592           (goto-char (point-min))
11593           (insert "211 ")
11594           (princ (cond
11595                   ((numberp id) id)
11596                   ((cdr where) (cdr where))
11597                   (header (mail-header-number header))
11598                   (t gnus-reffed-article-number))
11599                  (current-buffer))
11600           (insert " Article retrieved.\n"))
11601         (if (or (not where)
11602                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11603             ()                          ; Malformed head.
11604           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11605             (when (and (stringp id)
11606                        (not (string= (gnus-group-real-name group)
11607                                      (car where))))
11608               ;; If we fetched by Message-ID and the article came
11609               ;; from a different group, we fudge some bogus article
11610               ;; numbers for this article.
11611               (mail-header-set-number header gnus-reffed-article-number))
11612             (save-excursion
11613               (set-buffer gnus-summary-buffer)
11614               (decf gnus-reffed-article-number)
11615               (gnus-remove-header (mail-header-number header))
11616               (push header gnus-newsgroup-headers)
11617               (setq gnus-current-headers header)
11618               (push (mail-header-number header) gnus-newsgroup-limit)))
11619           header)))))
11620
11621 (defun gnus-remove-header (number)
11622   "Remove header NUMBER from `gnus-newsgroup-headers'."
11623   (if (and gnus-newsgroup-headers
11624            (= number (mail-header-number (car gnus-newsgroup-headers))))
11625       (pop gnus-newsgroup-headers)
11626     (let ((headers gnus-newsgroup-headers))
11627       (while (and (cdr headers)
11628                   (not (= number (mail-header-number (cadr headers)))))
11629         (pop headers))
11630       (when (cdr headers)
11631         (setcdr headers (cddr headers))))))
11632
11633 ;;;
11634 ;;; summary highlights
11635 ;;;
11636
11637 (defun gnus-highlight-selected-summary ()
11638   "Highlight selected article in summary buffer."
11639   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11640   (when gnus-summary-selected-face
11641     (save-excursion
11642       (let* ((beg (point-at-bol))
11643              (end (point-at-eol))
11644              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11645              (from (if (get-text-property beg gnus-mouse-face-prop)
11646                        beg
11647                      (or (next-single-property-change
11648                           beg gnus-mouse-face-prop nil end)
11649                          beg)))
11650              (to
11651               (if (= from end)
11652                   (- from 2)
11653                 (or (next-single-property-change
11654                      from gnus-mouse-face-prop nil end)
11655                     end))))
11656         ;; If no mouse-face prop on line we will have to = from = end,
11657         ;; so we highlight the entire line instead.
11658         (when (= (+ to 2) from)
11659           (setq from beg)
11660           (setq to end))
11661         (if gnus-newsgroup-selected-overlay
11662             ;; Move old overlay.
11663             (gnus-move-overlay
11664              gnus-newsgroup-selected-overlay from to (current-buffer))
11665           ;; Create new overlay.
11666           (gnus-overlay-put
11667            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11668            'face gnus-summary-selected-face))))))
11669
11670 (defvar gnus-summary-highlight-line-cached nil)
11671 (defvar gnus-summary-highlight-line-trigger nil)
11672
11673 (defun gnus-summary-highlight-line-0 ()
11674   (if (and (eq gnus-summary-highlight-line-trigger
11675                gnus-summary-highlight)
11676            gnus-summary-highlight-line-cached)
11677       gnus-summary-highlight-line-cached
11678     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11679           gnus-summary-highlight-line-cached
11680           (let* ((cond (list 'cond))
11681                  (c cond)
11682                  (list gnus-summary-highlight))
11683             (while list
11684               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11685                               nil))
11686               (setq c (cdr c)
11687                     list (cdr list)))
11688             (gnus-byte-compile (list 'lambda nil cond))))))
11689
11690 (defun gnus-summary-highlight-line ()
11691   "Highlight current line according to `gnus-summary-highlight'."
11692   (let* ((beg (point-at-bol))
11693          (article (or (gnus-summary-article-number) gnus-current-article))
11694          (score (or (cdr (assq article
11695                                gnus-newsgroup-scored))
11696                     gnus-summary-default-score 0))
11697          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11698          (inhibit-read-only t)
11699          (default gnus-summary-default-score)
11700          (default-high gnus-summary-default-high-score)
11701          (default-low gnus-summary-default-low-score)
11702          (uncached (and gnus-summary-use-undownloaded-faces
11703                         (memq article gnus-newsgroup-undownloaded)
11704                         (not (memq article gnus-newsgroup-cached)))))
11705     (let ((face (funcall (gnus-summary-highlight-line-0))))
11706       (unless (eq face (get-text-property beg 'face))
11707         (gnus-put-text-property-excluding-characters-with-faces
11708          beg (point-at-eol) 'face
11709          (setq face (if (boundp face) (symbol-value face) face)))
11710         (when gnus-summary-highlight-line-function
11711           (funcall gnus-summary-highlight-line-function article face))))))
11712
11713 (defun gnus-update-read-articles (group unread &optional compute)
11714   "Update the list of read articles in GROUP.
11715 UNREAD is a sorted list."
11716   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11717         (info (gnus-get-info group))
11718         (prev 1)
11719         read)
11720     (if (or (not info) (not active))
11721         ;; There is no info on this group if it was, in fact,
11722         ;; killed.  Gnus stores no information on killed groups, so
11723         ;; there's nothing to be done.
11724         ;; One could store the information somewhere temporarily,
11725         ;; perhaps...  Hmmm...
11726         ()
11727       ;; Remove any negative articles numbers.
11728       (while (and unread (< (car unread) 0))
11729         (setq unread (cdr unread)))
11730       ;; Remove any expired article numbers
11731       (while (and unread (< (car unread) (car active)))
11732         (setq unread (cdr unread)))
11733       ;; Compute the ranges of read articles by looking at the list of
11734       ;; unread articles.
11735       (while unread
11736         (when (/= (car unread) prev)
11737           (push (if (= prev (1- (car unread))) prev
11738                   (cons prev (1- (car unread))))
11739                 read))
11740         (setq prev (1+ (car unread)))
11741         (setq unread (cdr unread)))
11742       (when (<= prev (cdr active))
11743         (push (cons prev (cdr active)) read))
11744       (setq read (if (> (length read) 1) (nreverse read) read))
11745       (if compute
11746           read
11747         (save-excursion
11748           (let (setmarkundo)
11749             ;; Propagate the read marks to the backend.
11750             (when (gnus-check-backend-function 'request-set-mark group)
11751               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11752                     (add (gnus-remove-from-range read (gnus-info-read info))))
11753                 (when (or add del)
11754                   (unless (gnus-check-group group)
11755                     (error "Can't open server for %s" group))
11756                   (gnus-request-set-mark
11757                    group (delq nil (list (if add (list add 'add '(read)))
11758                                          (if del (list del 'del '(read))))))
11759                   (setq setmarkundo
11760                         `(gnus-request-set-mark
11761                           ,group
11762                           ',(delq nil (list
11763                                        (if del (list del 'add '(read)))
11764                                        (if add (list add 'del '(read))))))))))
11765             (set-buffer gnus-group-buffer)
11766             (gnus-undo-register
11767               `(progn
11768                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11769                  (gnus-info-set-read ',info ',(gnus-info-read info))
11770                  (gnus-get-unread-articles-in-group ',info
11771                                                     (gnus-active ,group))
11772                  (gnus-group-update-group ,group t)
11773                  ,setmarkundo))))
11774         ;; Enter this list into the group info.
11775         (gnus-info-set-read info read)
11776         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11777         (gnus-get-unread-articles-in-group info (gnus-active group))
11778         t))))
11779
11780 (defun gnus-offer-save-summaries ()
11781   "Offer to save all active summary buffers."
11782   (let (buffers)
11783     ;; Go through all buffers and find all summaries.
11784     (dolist (buffer (buffer-list))
11785       (when (and (setq buffer (buffer-name buffer))
11786                  (string-match "Summary" buffer)
11787                  (with-current-buffer buffer
11788                    ;; We check that this is, indeed, a summary buffer.
11789                    (and (eq major-mode 'gnus-summary-mode)
11790                         ;; Also make sure this isn't bogus.
11791                         gnus-newsgroup-prepared
11792                         ;; Also make sure that this isn't a
11793                         ;; dead summary buffer.
11794                         (not gnus-dead-summary-mode))))
11795         (push buffer buffers)))
11796     ;; Go through all these summary buffers and offer to save them.
11797     (when buffers
11798       (save-excursion
11799         (map-y-or-n-p
11800          "Update summary buffer %s? "
11801          (lambda (buf)
11802            (switch-to-buffer buf)
11803            (gnus-summary-exit))
11804          buffers)))))
11805
11806 (defun gnus-summary-setup-default-charset ()
11807   "Setup newsgroup default charset."
11808   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11809       (setq gnus-newsgroup-charset nil)
11810     (let* ((ignored-charsets
11811             (or gnus-newsgroup-ephemeral-ignored-charsets
11812                 (append
11813                  (and gnus-newsgroup-name
11814                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11815                  gnus-newsgroup-ignored-charsets))))
11816       (setq gnus-newsgroup-charset
11817             (or gnus-newsgroup-ephemeral-charset
11818                 (and gnus-newsgroup-name
11819                      (gnus-parameter-charset gnus-newsgroup-name))
11820                 gnus-default-charset))
11821       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11822            ignored-charsets))))
11823
11824 ;;;
11825 ;;; Mime Commands
11826 ;;;
11827
11828 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11829   "Display the current article buffer fully MIME-buttonized.
11830 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11831 treated as multipart/mixed."
11832   (interactive "P")
11833   (require 'gnus-art)
11834   (let ((gnus-unbuttonized-mime-types nil)
11835         (gnus-mime-display-multipart-as-mixed show-all-parts))
11836     (gnus-summary-show-article)))
11837
11838 (defun gnus-summary-repair-multipart (article)
11839   "Add a Content-Type header to a multipart article without one."
11840   (interactive (list (gnus-summary-article-number)))
11841   (gnus-with-article article
11842     (message-narrow-to-head)
11843     (message-remove-header "Mime-Version")
11844     (goto-char (point-max))
11845     (insert "Mime-Version: 1.0\n")
11846     (widen)
11847     (when (search-forward "\n--" nil t)
11848       (let ((separator (buffer-substring (point) (point-at-eol))))
11849         (message-narrow-to-head)
11850         (message-remove-header "Content-Type")
11851         (goto-char (point-max))
11852         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11853                         separator))
11854         (widen))))
11855   (let (gnus-mark-article-hook)
11856     (gnus-summary-select-article t t nil article)))
11857
11858 (defun gnus-summary-toggle-display-buttonized ()
11859   "Toggle the buttonizing of the article buffer."
11860   (interactive)
11861   (require 'gnus-art)
11862   (if (setq gnus-inhibit-mime-unbuttonizing
11863             (not gnus-inhibit-mime-unbuttonizing))
11864       (let ((gnus-unbuttonized-mime-types nil))
11865         (gnus-summary-show-article))
11866     (gnus-summary-show-article)))
11867
11868 ;;;
11869 ;;; Generic summary marking commands
11870 ;;;
11871
11872 (defvar gnus-summary-marking-alist
11873   '((read gnus-del-mark "d")
11874     (unread gnus-unread-mark "u")
11875     (ticked gnus-ticked-mark "!")
11876     (dormant gnus-dormant-mark "?")
11877     (expirable gnus-expirable-mark "e"))
11878   "An alist of names/marks/keystrokes.")
11879
11880 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11881 (defvar gnus-summary-mark-map)
11882
11883 (defun gnus-summary-make-all-marking-commands ()
11884   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11885   (dolist (elem gnus-summary-marking-alist)
11886     (apply 'gnus-summary-make-marking-command elem)))
11887
11888 (defun gnus-summary-make-marking-command (name mark keystroke)
11889   (let ((map (make-sparse-keymap)))
11890     (define-key gnus-summary-generic-mark-map keystroke map)
11891     (dolist (lway `((next "next" next nil "n")
11892                     (next-unread "next unread" next t "N")
11893                     (prev "previous" prev nil "p")
11894                     (prev-unread "previous unread" prev t "P")
11895                     (nomove "" nil nil ,keystroke)))
11896       (let ((func (gnus-summary-make-marking-command-1
11897                    mark (car lway) lway name)))
11898         (setq func (eval func))
11899         (define-key map (nth 4 lway) func)))))
11900
11901 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11902   `(defun ,(intern
11903             (format "gnus-summary-put-mark-as-%s%s"
11904                     name (if (eq way 'nomove)
11905                              ""
11906                            (concat "-" (symbol-name way)))))
11907      (n)
11908      ,(format
11909        "Mark the current article as %s%s.
11910 If N, the prefix, then repeat N times.
11911 If N is negative, move in reverse order.
11912 The difference between N and the actual number of articles marked is
11913 returned."
11914        name (cadr lway))
11915      (interactive "p")
11916      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11917
11918 (defun gnus-summary-generic-mark (n mark move unread)
11919   "Mark N articles with MARK."
11920   (unless (eq major-mode 'gnus-summary-mode)
11921     (error "This command can only be used in the summary buffer"))
11922   (gnus-summary-show-thread)
11923   (let ((nummove
11924          (cond
11925           ((eq move 'next) 1)
11926           ((eq move 'prev) -1)
11927           (t 0))))
11928     (if (zerop nummove)
11929         (setq n 1)
11930       (when (< n 0)
11931         (setq n (abs n)
11932               nummove (* -1 nummove))))
11933     (while (and (> n 0)
11934                 (gnus-summary-mark-article nil mark)
11935                 (zerop (gnus-summary-next-subject nummove unread t)))
11936       (setq n (1- n)))
11937     (when (/= 0 n)
11938       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11939     (gnus-summary-recenter)
11940     (gnus-summary-position-point)
11941     (gnus-set-mode-line 'summary)
11942     n))
11943
11944 (defun gnus-summary-insert-articles (articles)
11945   (when (setq articles
11946               (gnus-sorted-difference articles
11947                                       (mapcar (lambda (h)
11948                                                 (mail-header-number h))
11949                                               gnus-newsgroup-headers)))
11950     (setq gnus-newsgroup-headers
11951           (gnus-merge 'list
11952                       gnus-newsgroup-headers
11953                       (gnus-fetch-headers articles)
11954                       'gnus-article-sort-by-number))
11955     ;; Suppress duplicates?
11956     (when gnus-suppress-duplicates
11957       (gnus-dup-suppress-articles))
11958
11959     ;; We might want to build some more threads first.
11960     (when (and gnus-fetch-old-headers
11961                (eq gnus-headers-retrieved-by 'nov))
11962       (if (eq gnus-fetch-old-headers 'invisible)
11963           (gnus-build-all-threads)
11964         (gnus-build-old-threads)))
11965     ;; Let the Gnus agent mark articles as read.
11966     (when gnus-agent
11967       (gnus-agent-get-undownloaded-list))
11968     ;; Remove list identifiers from subject
11969     (when gnus-list-identifiers
11970       (gnus-summary-remove-list-identifiers))
11971     ;; First and last article in this newsgroup.
11972     (when gnus-newsgroup-headers
11973       (setq gnus-newsgroup-begin
11974             (mail-header-number (car gnus-newsgroup-headers))
11975             gnus-newsgroup-end
11976             (mail-header-number
11977              (gnus-last-element gnus-newsgroup-headers))))
11978     (when gnus-use-scoring
11979       (gnus-possibly-score-headers))))
11980
11981 (defun gnus-summary-insert-old-articles (&optional all)
11982   "Insert all old articles in this group.
11983 If ALL is non-nil, already read articles become readable.
11984 If ALL is a number, fetch this number of articles."
11985   (interactive "P")
11986   (prog1
11987       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11988             older len)
11989         (setq older
11990               ;; Some nntp servers lie about their active range.  When
11991               ;; this happens, the active range can be in the millions.
11992               ;; Use a compressed range to avoid creating a huge list.
11993               (gnus-range-difference (list gnus-newsgroup-active) old))
11994         (setq len (gnus-range-length older))
11995         (cond
11996          ((null older) nil)
11997          ((numberp all)
11998           (if (< all len)
11999               (let ((older-range (nreverse older)))
12000                 (setq older nil)
12001
12002                 (while (> all 0)
12003                   (let* ((r (pop older-range))
12004                          (min (if (numberp r) r (car r)))
12005                          (max (if (numberp r) r (cdr r))))
12006                     (while (and (<= min max)
12007                                 (> all 0))
12008                       (push max older)
12009                       (setq all (1- all)
12010                             max (1- max))))))
12011             (setq older (gnus-uncompress-range older))))
12012          (all
12013           (setq older (gnus-uncompress-range older)))
12014          (t
12015           (when (and (numberp gnus-large-newsgroup)
12016                    (> len gnus-large-newsgroup))
12017               (let* ((cursor-in-echo-area nil)
12018                      (initial (gnus-parameter-large-newsgroup-initial
12019                                gnus-newsgroup-name))
12020                      (input
12021                       (read-string
12022                        (format
12023                         "How many articles from %s (%s %d): "
12024                         (gnus-limit-string
12025                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12026                         (if initial "max" "default")
12027                         len)
12028                        (if initial
12029                            (cons (number-to-string initial)
12030                                  0)))))
12031                 (unless (string-match "^[ \t]*$" input)
12032                   (setq all (string-to-number input))
12033                   (if (< all len)
12034                       (let ((older-range (nreverse older)))
12035                         (setq older nil)
12036
12037                         (while (> all 0)
12038                           (let* ((r (pop older-range))
12039                                  (min (if (numberp r) r (car r)))
12040                                  (max (if (numberp r) r (cdr r))))
12041                             (while (and (<= min max)
12042                                         (> all 0))
12043                               (push max older)
12044                               (setq all (1- all)
12045                                     max (1- max))))))))))
12046           (setq older (gnus-uncompress-range older))))
12047         (if (not older)
12048             (message "No old news.")
12049           (gnus-summary-insert-articles older)
12050           (gnus-summary-limit (gnus-sorted-nunion old older))))
12051     (gnus-summary-position-point)))
12052
12053 (defun gnus-summary-insert-new-articles ()
12054   "Insert all new articles in this group."
12055   (interactive)
12056   (prog1
12057       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12058             (old-active gnus-newsgroup-active)
12059             (nnmail-fetched-sources (list t))
12060             i new)
12061         (setq gnus-newsgroup-active
12062               (gnus-activate-group gnus-newsgroup-name 'scan))
12063         (setq i (cdr gnus-newsgroup-active))
12064         (while (> i (cdr old-active))
12065           (push i new)
12066           (decf i))
12067         (if (not new)
12068             (message "No gnus is bad news")
12069           (gnus-summary-insert-articles new)
12070           (setq gnus-newsgroup-unreads
12071                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12072           (gnus-summary-limit (gnus-sorted-nunion old new))))
12073     (gnus-summary-position-point)))
12074
12075 (gnus-summary-make-all-marking-commands)
12076
12077 (gnus-ems-redefine)
12078
12079 (provide 'gnus-sum)
12080
12081 (run-hooks 'gnus-sum-load-hook)
12082
12083 ;; Local Variables:
12084 ;; coding: iso-8859-1
12085 ;; End:
12086
12087 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12088 ;;; gnus-sum.el ends here