* gnus-agent.el (gnus-agent-read-agentview, gnus-agent-save-alist)
[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, 2007 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 3, 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-summary-next-group-on-exit t
66   "If non-nil, go to the next unread newsgroup on summary exit.
67 See `gnus-group-goto-unread'."
68   :link '(custom-manual "(gnus)Group Maneuvering")
69   :group 'gnus-summary-exit
70   :version "23.0" ;; No Gnus
71   :type 'boolean)
72
73 (defcustom gnus-fetch-old-headers nil
74   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
75 If an unread article in the group refers to an older, already
76 read (or just marked as read) article, the old article will not
77 normally be displayed in the Summary buffer.  If this variable is
78 t, Gnus will attempt to grab the headers to the old articles, and
79 thereby build complete threads.  If it has the value `some', all
80 old headers will be fetched but only enough headers to connect
81 otherwise loose threads will be displayed.  This variable can
82 also be a number.  In that case, no more than that number of old
83 headers will be fetched.  If it has the value `invisible', all
84 old headers will be fetched, but none will be displayed.
85
86 The server has to support NOV for any of this to work.
87
88 This feature can seriously impact performance it ignores all
89 locally cached header entries."
90   :group 'gnus-thread
91   :type '(choice (const :tag "off" nil)
92                  (const :tag "on" t)
93                  (const some)
94                  (const invisible)
95                  number
96                  (sexp :menu-tag "other" t)))
97
98 (defcustom gnus-refer-thread-limit 500
99   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
100 If t, fetch all the available old headers."
101   :group 'gnus-thread
102   :type '(choice number
103                  (sexp :menu-tag "other" t)))
104
105 (defcustom gnus-summary-make-false-root 'adopt
106   "*nil means that Gnus won't gather loose threads.
107 If the root of a thread has expired or been read in a previous
108 session, the information necessary to build a complete thread has been
109 lost.  Instead of having many small sub-threads from this original thread
110 scattered all over the summary buffer, Gnus can gather them.
111
112 If non-nil, Gnus will try to gather all loose sub-threads from an
113 original thread into one large thread.
114
115 If this variable is non-nil, it should be one of `none', `adopt',
116 `dummy' or `empty'.
117
118 If this variable is `none', Gnus will not make a false root, but just
119 present the sub-threads after another.
120 If this variable is `dummy', Gnus will create a dummy root that will
121 have all the sub-threads as children.
122 If this variable is `adopt', Gnus will make one of the \"children\"
123 the parent and mark all the step-children as such.
124 If this variable is `empty', the \"children\" are printed with empty
125 subject fields.  (Or rather, they will be printed with a string
126 given by the `gnus-summary-same-subject' variable.)"
127   :group 'gnus-thread
128   :type '(choice (const :tag "off" nil)
129                  (const none)
130                  (const dummy)
131                  (const adopt)
132                  (const empty)))
133
134 (defcustom gnus-summary-make-false-root-always nil
135   "Always make a false dummy root."
136   :version "22.1"
137   :group 'gnus-thread
138   :type 'boolean)
139
140 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
141   "*A regexp to match subjects to be excluded from loose thread gathering.
142 As loose thread gathering is done on subjects only, that means that
143 there can be many false gatherings performed.  By rooting out certain
144 common subjects, gathering might become saner."
145   :group 'gnus-thread
146   :type 'regexp)
147
148 (defcustom gnus-summary-gather-subject-limit nil
149   "*Maximum length of subject comparisons when gathering loose threads.
150 Use nil to compare full subjects.  Setting this variable to a low
151 number will help gather threads that have been corrupted by
152 newsreaders chopping off subject lines, but it might also mean that
153 unrelated articles that have subject that happen to begin with the
154 same few characters will be incorrectly gathered.
155
156 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
157 comparing subjects."
158   :group 'gnus-thread
159   :type '(choice (const :tag "off" nil)
160                  (const fuzzy)
161                  (sexp :menu-tag "on" t)))
162
163 (defcustom gnus-simplify-subject-functions nil
164   "List of functions taking a string argument that simplify subjects.
165 The functions are applied recursively.
166
167 Useful functions to put in this list include:
168 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
169 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
170   :group 'gnus-thread
171   :type '(repeat function))
172
173 (defcustom gnus-simplify-ignored-prefixes nil
174   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
175   :group 'gnus-thread
176   :type '(choice (const :tag "off" nil)
177                  regexp))
178
179 (defcustom gnus-build-sparse-threads nil
180   "*If non-nil, fill in the gaps in threads.
181 If `some', only fill in the gaps that are needed to tie loose threads
182 together.  If `more', fill in all leaf nodes that Gnus can find.  If
183 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
184   :group 'gnus-thread
185   :type '(choice (const :tag "off" nil)
186                  (const some)
187                  (const more)
188                  (sexp :menu-tag "all" t)))
189
190 (defcustom gnus-summary-thread-gathering-function
191   'gnus-gather-threads-by-subject
192   "*Function used for gathering loose threads.
193 There are two pre-defined functions: `gnus-gather-threads-by-subject',
194 which only takes Subjects into consideration; and
195 `gnus-gather-threads-by-references', which compared the References
196 headers of the articles to find matches."
197   :group 'gnus-thread
198   :type '(radio (function-item gnus-gather-threads-by-subject)
199                 (function-item gnus-gather-threads-by-references)
200                 (function :tag "other")))
201
202 (defcustom gnus-summary-same-subject ""
203   "*String indicating that the current article has the same subject as the previous.
204 This variable will only be used if the value of
205 `gnus-summary-make-false-root' is `empty'."
206   :group 'gnus-summary-format
207   :type 'string)
208
209 (defcustom gnus-summary-goto-unread t
210   "*If t, many commands will go to the next unread article.
211 This applies to marking commands as well as other commands that
212 \"naturally\" select the next article, like, for instance, `SPC' at
213 the end of an article.
214
215 If nil, the marking commands do NOT go to the next unread article
216 \(they go to the next article instead).  If `never', commands that
217 usually go to the next unread article, will go to the next article,
218 whether it is read or not."
219   :group 'gnus-summary-marks
220   :link '(custom-manual "(gnus)Setting Marks")
221   :type '(choice (const :tag "off" nil)
222                  (const never)
223                  (sexp :menu-tag "on" t)))
224
225 (defcustom gnus-summary-default-score 0
226   "*Default article score level.
227 All scores generated by the score files will be added to this score.
228 If this variable is nil, scoring will be disabled."
229   :group 'gnus-score-default
230   :type '(choice (const :tag "disable")
231                  integer))
232
233 (defcustom gnus-summary-default-high-score 0
234   "*Default threshold for a high scored article.
235 An article will be highlighted as high scored if its score is greater
236 than this score."
237   :version "22.1"
238   :group 'gnus-score-default
239   :type 'integer)
240
241 (defcustom gnus-summary-default-low-score 0
242   "*Default threshold for a low scored article.
243 An article will be highlighted as low scored if its score is smaller
244 than this score."
245   :version "22.1"
246   :group 'gnus-score-default
247   :type 'integer)
248
249 (defcustom gnus-summary-zcore-fuzz 0
250   "*Fuzziness factor for the zcore in the summary buffer.
251 Articles with scores closer than this to `gnus-summary-default-score'
252 will not be marked."
253   :group 'gnus-summary-format
254   :type 'integer)
255
256 (defcustom gnus-simplify-subject-fuzzy-regexp nil
257   "*Strings to be removed when doing fuzzy matches.
258 This can either be a regular expression or list of regular expressions
259 that will be removed from subject strings if fuzzy subject
260 simplification is selected."
261   :group 'gnus-thread
262   :type '(repeat regexp))
263
264 (defcustom gnus-show-threads t
265   "*If non-nil, display threads in summary mode."
266   :group 'gnus-thread
267   :type 'boolean)
268
269 (defcustom gnus-thread-hide-subtree nil
270   "*If non-nil, hide all threads initially.
271 This can be a predicate specifier which says which threads to hide.
272 If threads are hidden, you have to run the command
273 `gnus-summary-show-thread' by hand or select an article."
274   :group 'gnus-thread
275   :type '(radio (sexp :format "Non-nil\n"
276                       :match (lambda (widget value)
277                                (not (or (consp value) (functionp value))))
278                       :value t)
279                 (const nil)
280                 (sexp :tag "Predicate specifier")))
281
282 (defcustom gnus-thread-hide-killed t
283   "*If non-nil, hide killed threads automatically."
284   :group 'gnus-thread
285   :type 'boolean)
286
287 (defcustom gnus-thread-ignore-subject t
288   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
289 If nil, articles that have different subjects from their parents will
290 start separate threads."
291   :group 'gnus-thread
292   :type 'boolean)
293
294 (defcustom gnus-thread-operation-ignore-subject t
295   "*If non-nil, subjects will be ignored when doing thread commands.
296 This affects commands like `gnus-summary-kill-thread' and
297 `gnus-summary-lower-thread'.
298
299 If this variable is nil, articles in the same thread with different
300 subjects will not be included in the operation in question.  If this
301 variable is `fuzzy', only articles that have subjects that are fuzzily
302 equal will be included."
303   :group 'gnus-thread
304   :type '(choice (const :tag "off" nil)
305                  (const fuzzy)
306                  (sexp :tag "on" t)))
307
308 (defcustom gnus-thread-indent-level 4
309   "*Number that says how much each sub-thread should be indented."
310   :group 'gnus-thread
311   :type 'integer)
312
313 (defcustom gnus-auto-extend-newsgroup t
314   "*If non-nil, extend newsgroup forward and backward when requested."
315   :group 'gnus-summary-choose
316   :type 'boolean)
317
318 (defcustom gnus-auto-select-first t
319   "If non-nil, select an article on group entry.
320 An article is selected automatically when entering a group
321 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
322 `gnus-summary-catchup-and-goto-next-group'.
323
324 Which article is selected is controlled by the variable
325 `gnus-auto-select-subject'.
326
327 If you want to prevent automatic selection of articles in some
328 newsgroups, set the variable to nil in `gnus-select-group-hook'."
329   ;; Commands include...
330   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
331   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
332   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
333   :group 'gnus-group-select
334   :type '(choice (const :tag "none" nil)
335                  (sexp :menu-tag "first" t)))
336
337 (defcustom gnus-auto-select-subject 'unread
338   "*Says what subject to place under point when entering a group.
339
340 This variable can either be the symbols `first' (place point on the
341 first subject), `unread' (place point on the subject line of the first
342 unread article), `best' (place point on the subject line of the
343 higest-scored article), `unseen' (place point on the subject line of
344 the first unseen article), `unseen-or-unread' (place point on the subject
345 line of the first unseen article or, if all article have been seen, on the
346 subject line of the first unread article), or a function to be called to
347 place point on some subject line."
348   :version "22.1"
349   :group 'gnus-group-select
350   :type '(choice (const best)
351                  (const unread)
352                  (const first)
353                  (const unseen)
354                  (const unseen-or-unread)))
355
356 (defcustom gnus-auto-select-next t
357   "*If non-nil, offer to go to the next group from the end of the previous.
358 If the value is t and the next newsgroup is empty, Gnus will exit
359 summary mode and go back to group mode.  If the value is neither nil
360 nor t, Gnus will select the following unread newsgroup.  In
361 particular, if the value is the symbol `quietly', the next unread
362 newsgroup will be selected without any confirmation, and if it is
363 `almost-quietly', the next group will be selected without any
364 confirmation if you are located on the last article in the group.
365 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
366 will go to the next group without confirmation."
367   :group 'gnus-summary-maneuvering
368   :type '(choice (const :tag "off" nil)
369                  (const quietly)
370                  (const almost-quietly)
371                  (const slightly-quietly)
372                  (sexp :menu-tag "on" t)))
373
374 (defcustom gnus-auto-select-same nil
375   "*If non-nil, select the next article with the same subject.
376 If there are no more articles with the same subject, go to
377 the first unread article."
378   :group 'gnus-summary-maneuvering
379   :type 'boolean)
380
381 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
382   "What article should be selected after exiting an ephemeral group.
383 Valid values include:
384
385 `next'
386   Select the next article.
387 `next-unread'
388   Select the next unread article.
389 `next-noselect'
390   Move the cursor to the next article.  This is the default.
391 `next-unread-noselect'
392   Move the cursor to the next unread article.
393
394 If it has any other value or there is no next (unread) article, the
395 article selected before entering to the ephemeral group will appear."
396   :version "23.0" ;; No Gnus
397   :group 'gnus-summary-maneuvering
398   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
399                  (const next) (const next-unread)
400                  (const next-noselect) (const next-unread-noselect)
401                  (sexp :tag "other" :value nil)))
402
403 (defcustom gnus-auto-goto-ignores 'unfetched
404   "*Says how to handle unfetched articles when maneuvering.
405
406 This variable can either be the symbols nil (maneuver to any
407 article), `undownloaded' (maneuvering while unplugged ignores articles
408 that have not been fetched), `always-undownloaded' (maneuvering always
409 ignores articles that have not been fetched), `unfetched' (maneuvering
410 ignores articles whose headers have not been fetched).
411
412 NOTE: The list of unfetched articles will always be nil when plugged
413 and, when unplugged, a subset of the undownloaded article list."
414   :version "22.1"
415   :group 'gnus-summary-maneuvering
416   :type '(choice (const :tag "None" nil)
417                  (const :tag "Undownloaded when unplugged" undownloaded)
418                  (const :tag "Undownloaded" always-undownloaded)
419                  (const :tag "Unfetched" unfetched)))
420
421 (defcustom gnus-summary-check-current nil
422   "*If non-nil, consider the current article when moving.
423 The \"unread\" movement commands will stay on the same line if the
424 current article is unread."
425   :group 'gnus-summary-maneuvering
426   :type 'boolean)
427
428 (defcustom gnus-auto-center-summary 2
429   "*If non-nil, always center the current summary buffer.
430 In particular, if `vertical' do only vertical recentering.  If non-nil
431 and non-`vertical', do both horizontal and vertical recentering."
432   :group 'gnus-summary-maneuvering
433   :type '(choice (const :tag "none" nil)
434                  (const vertical)
435                  (integer :tag "height")
436                  (sexp :menu-tag "both" t)))
437
438 (defvar gnus-auto-center-group t
439   "*If non-nil, always center the group buffer.")
440
441 (defcustom gnus-show-all-headers nil
442   "*If non-nil, don't hide any headers."
443   :group 'gnus-article-hiding
444   :group 'gnus-article-headers
445   :type 'boolean)
446
447 (defcustom gnus-summary-ignore-duplicates nil
448   "*If non-nil, ignore articles with identical Message-ID headers."
449   :group 'gnus-summary
450   :type 'boolean)
451
452 (defcustom gnus-single-article-buffer t
453   "*If non-nil, display all articles in the same buffer.
454 If nil, each group will get its own article buffer."
455   :group 'gnus-article-various
456   :type 'boolean)
457
458 (defcustom gnus-break-pages t
459   "*If non-nil, do page breaking on articles.
460 The page delimiter is specified by the `gnus-page-delimiter'
461 variable."
462   :group 'gnus-article-various
463   :type 'boolean)
464
465 (defcustom gnus-move-split-methods nil
466   "*Variable used to suggest where articles are to be moved to.
467 It uses the same syntax as the `gnus-split-methods' variable.
468 However, whereas `gnus-split-methods' specifies file names as targets,
469 this variable specifies group names."
470   :group 'gnus-summary-mail
471   :type '(repeat (choice (list :value (fun) function)
472                          (cons :value ("" "") regexp (repeat string))
473                          (sexp :value nil))))
474
475 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
476   "Function used to compute default prefix for article move/copy/etc prompts.
477 The function should take one argument, a group name, and return a
478 string with the suggested prefix."
479   :group 'gnus-summary-mail
480   :type 'function)
481
482 ;; FIXME: Although the custom type is `character' for the following variables,
483 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
484
485 (defcustom gnus-unread-mark ?           ;Whitespace
486   "*Mark used for unread articles."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-ticked-mark ?!
491   "*Mark used for ticked articles."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-dormant-mark ??
496   "*Mark used for dormant articles."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-del-mark ?r
501   "*Mark used for del'd articles."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-read-mark ?R
506   "*Mark used for read articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-expirable-mark ?E
511   "*Mark used for expirable articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-killed-mark ?K
516   "*Mark used for killed articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-spam-mark ?$
521   "*Mark used for spam articles."
522   :version "22.1"
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-souped-mark ?F
527   "*Mark used for souped articles."
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-kill-file-mark ?X
532   "*Mark used for articles killed by kill files."
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-low-score-mark ?Y
537   "*Mark used for articles with a low score."
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-catchup-mark ?C
542   "*Mark used for articles that are caught up."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-replied-mark ?A
547   "*Mark used for articles that have been replied to."
548   :group 'gnus-summary-marks
549   :type 'character)
550
551 (defcustom gnus-forwarded-mark ?F
552   "*Mark used for articles that have been forwarded."
553   :version "22.1"
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-recent-mark ?N
558   "*Mark used for articles that are recent."
559   :version "22.1"
560   :group 'gnus-summary-marks
561   :type 'character)
562
563 (defcustom gnus-cached-mark ?*
564   "*Mark used for articles that are in the cache."
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-saved-mark ?S
569   "*Mark used for articles that have been saved."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-unseen-mark ?.
574   "*Mark used for articles that haven't been seen."
575   :version "22.1"
576   :group 'gnus-summary-marks
577   :type 'character)
578
579 (defcustom gnus-no-mark ?               ;Whitespace
580   "*Mark used for articles that have no other secondary mark."
581   :version "22.1"
582   :group 'gnus-summary-marks
583   :type 'character)
584
585 (defcustom gnus-ancient-mark ?O
586   "*Mark used for ancient articles."
587   :group 'gnus-summary-marks
588   :type 'character)
589
590 (defcustom gnus-sparse-mark ?Q
591   "*Mark used for sparsely reffed articles."
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-canceled-mark ?G
596   "*Mark used for canceled articles."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-duplicate-mark ?M
601   "*Mark used for duplicate articles."
602   :group 'gnus-summary-marks
603   :type 'character)
604
605 (defcustom gnus-undownloaded-mark ?-
606   "*Mark used for articles that weren't downloaded."
607   :version "22.1"
608   :group 'gnus-summary-marks
609   :type 'character)
610
611 (defcustom gnus-downloaded-mark ?+
612   "*Mark used for articles that were downloaded."
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-downloadable-mark ?%
617   "*Mark used for articles that are to be downloaded."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-unsendable-mark ?=
622   "*Mark used for articles that won't be sent."
623   :group 'gnus-summary-marks
624   :type 'character)
625
626 (defcustom gnus-score-over-mark ?+
627   "*Score mark used for articles with high scores."
628   :group 'gnus-summary-marks
629   :type 'character)
630
631 (defcustom gnus-score-below-mark ?-
632   "*Score mark used for articles with low scores."
633   :group 'gnus-summary-marks
634   :type 'character)
635
636 (defcustom gnus-empty-thread-mark ?     ;Whitespace
637   "*There is no thread under the article."
638   :group 'gnus-summary-marks
639   :type 'character)
640
641 (defcustom gnus-not-empty-thread-mark ?=
642   "*There is a thread under the article."
643   :group 'gnus-summary-marks
644   :type 'character)
645
646 (defcustom gnus-view-pseudo-asynchronously nil
647   "*If non-nil, Gnus will view pseudo-articles asynchronously."
648   :group 'gnus-extract-view
649   :type 'boolean)
650
651 (defcustom gnus-auto-expirable-marks
652   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
653         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
654         gnus-souped-mark gnus-duplicate-mark)
655   "*The list of marks converted into expiration if a group is auto-expirable."
656   :version "21.1"
657   :group 'gnus-summary
658   :type '(repeat character))
659
660 (defcustom gnus-inhibit-user-auto-expire t
661   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
662   :version "21.1"
663   :group 'gnus-summary
664   :type 'boolean)
665
666 (defcustom gnus-view-pseudos nil
667   "*If `automatic', pseudo-articles will be viewed automatically.
668 If `not-confirm', pseudos will be viewed automatically, and the user
669 will not be asked to confirm the command."
670   :group 'gnus-extract-view
671   :type '(choice (const :tag "off" nil)
672                  (const automatic)
673                  (const not-confirm)))
674
675 (defcustom gnus-view-pseudos-separately t
676   "*If non-nil, one pseudo-article will be created for each file to be viewed.
677 If nil, all files that use the same viewing command will be given as a
678 list of parameters to that command."
679   :group 'gnus-extract-view
680   :type 'boolean)
681
682 (defcustom gnus-insert-pseudo-articles t
683   "*If non-nil, insert pseudo-articles when decoding articles."
684   :group 'gnus-extract-view
685   :type 'boolean)
686
687 (defcustom gnus-summary-dummy-line-format
688   "   %(:                             :%) %S\n"
689   "*The format specification for the dummy roots in the summary buffer.
690 It works along the same lines as a normal formatting string,
691 with some simple extensions.
692
693 %S  The subject
694
695 General format specifiers can also be used.
696 See `(gnus)Formatting Variables'."
697   :link '(custom-manual "(gnus)Formatting Variables")
698   :group 'gnus-threading
699   :type 'string)
700
701 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
702   "*The format specification for the summary mode line.
703 It works along the same lines as a normal formatting string,
704 with some simple extensions:
705
706 %G  Group name
707 %p  Unprefixed group name
708 %A  Current article number
709 %z  Current article score
710 %V  Gnus version
711 %U  Number of unread articles in the group
712 %e  Number of unselected articles in the group
713 %Z  A string with unread/unselected article counts
714 %g  Shortish group name
715 %S  Subject of the current article
716 %u  User-defined spec
717 %s  Current score file name
718 %d  Number of dormant articles
719 %r  Number of articles that have been marked as read in this session
720 %E  Number of articles expunged by the score files"
721   :group 'gnus-summary-format
722   :type 'string)
723
724 (defcustom gnus-list-identifiers nil
725   "Regexp that matches list identifiers to be removed from subject.
726 This can also be a list of regexps."
727   :version "21.1"
728   :group 'gnus-summary-format
729   :group 'gnus-article-hiding
730   :type '(choice (const :tag "none" nil)
731                  (regexp :value ".*")
732                  (repeat :value (".*") regexp)))
733
734 (defcustom gnus-summary-mark-below 0
735   "*Mark all articles with a score below this variable as read.
736 This variable is local to each summary buffer and usually set by the
737 score file."
738   :group 'gnus-score-default
739   :type 'integer)
740
741 (defun gnus-widget-reversible-match (widget value)
742   "Ignoring WIDGET, convert VALUE to internal form.
743 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
744   ;; (debug value)
745   (or (symbolp value)
746       (and (listp value)
747            (eq (length value) 2)
748            (eq (nth 0 value) 'not)
749            (symbolp (nth 1 value)))))
750
751 (defun gnus-widget-reversible-to-internal (widget value)
752   "Ignoring WIDGET, convert VALUE to internal form.
753 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
754 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
755   ;; (debug value)
756   (if (atom value)
757       (list value nil)
758     (list (nth 1 value) t)))
759
760 (defun gnus-widget-reversible-to-external (widget value)
761   "Ignoring WIDGET, convert VALUE to external form.
762 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
763 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
764   ;; (debug value)
765   (if (nth 1 value)
766       (list 'not (nth 0 value))
767     (nth 0 value)))
768
769 (define-widget 'gnus-widget-reversible 'group
770   "A `group' that convert values."
771   :match 'gnus-widget-reversible-match
772   :value-to-internal 'gnus-widget-reversible-to-internal
773   :value-to-external 'gnus-widget-reversible-to-external)
774
775 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
776   "*List of functions used for sorting articles in the summary buffer.
777
778 Each function takes two articles and returns non-nil if the first
779 article should be sorted before the other.  If you use more than one
780 function, the primary sort function should be the last.  You should
781 probably always include `gnus-article-sort-by-number' in the list of
782 sorting functions -- preferably first.  Also note that sorting by date
783 is often much slower than sorting by number, and the sorting order is
784 very similar.  (Sorting by date means sorting by the time the message
785 was sent, sorting by number means sorting by arrival time.)
786
787 Each item can also be a list `(not F)' where F is a function;
788 this reverses the sort order.
789
790 Ready-made functions include `gnus-article-sort-by-number',
791 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
792 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
793 and `gnus-article-sort-by-score'.
794
795 When threading is turned on, the variable `gnus-thread-sort-functions'
796 controls how articles are sorted."
797   :group 'gnus-summary-sort
798   :type '(repeat (gnus-widget-reversible
799                   (choice (function-item gnus-article-sort-by-number)
800                           (function-item gnus-article-sort-by-author)
801                           (function-item gnus-article-sort-by-subject)
802                           (function-item gnus-article-sort-by-date)
803                           (function-item gnus-article-sort-by-score)
804                           (function-item gnus-article-sort-by-random)
805                           (function :tag "other"))
806                   (boolean :tag "Reverse order"))))
807
808
809 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
810   "*List of functions used for sorting threads in the summary buffer.
811 By default, threads are sorted by article number.
812
813 Each function takes two threads and returns non-nil if the first
814 thread should be sorted before the other.  If you use more than one
815 function, the primary sort function should be the last.  You should
816 probably always include `gnus-thread-sort-by-number' in the list of
817 sorting functions -- preferably first.  Also note that sorting by date
818 is often much slower than sorting by number, and the sorting order is
819 very similar.  (Sorting by date means sorting by the time the message
820 was sent, sorting by number means sorting by arrival time.)
821
822 Each list item can also be a list `(not F)' where F is a
823 function; this specifies reversed sort order.
824
825 Ready-made functions include `gnus-thread-sort-by-number',
826 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
827 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
828 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
829 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
830 and `gnus-thread-sort-by-total-score' (see
831 `gnus-thread-score-function').
832
833 When threading is turned off, the variable
834 `gnus-article-sort-functions' controls how articles are sorted."
835   :group 'gnus-summary-sort
836   :type '(repeat
837           (gnus-widget-reversible
838            (choice (function-item gnus-thread-sort-by-number)
839                    (function-item gnus-thread-sort-by-author)
840                    (function-item gnus-thread-sort-by-recipient)
841                    (function-item gnus-thread-sort-by-subject)
842                    (function-item gnus-thread-sort-by-date)
843                    (function-item gnus-thread-sort-by-score)
844                    (function-item gnus-thread-sort-by-most-recent-number)
845                    (function-item gnus-thread-sort-by-most-recent-date)
846                    (function-item gnus-thread-sort-by-random)
847                    (function-item gnus-thread-sort-by-total-score)
848                    (function :tag "other"))
849            (boolean :tag "Reverse order"))))
850
851 (defcustom gnus-thread-score-function '+
852   "*Function used for calculating the total score of a thread.
853
854 The function is called with the scores of the article and each
855 subthread and should then return the score of the thread.
856
857 Some functions you can use are `+', `max', or `min'."
858   :group 'gnus-summary-sort
859   :type 'function)
860
861 (defcustom gnus-summary-expunge-below nil
862   "All articles that have a score less than this variable will be expunged.
863 This variable is local to the summary buffers."
864   :group 'gnus-score-default
865   :type '(choice (const :tag "off" nil)
866                  integer))
867
868 (defcustom gnus-thread-expunge-below nil
869   "All threads that have a total score less than this variable will be expunged.
870 See `gnus-thread-score-function' for en explanation of what a
871 \"thread score\" is.
872
873 This variable is local to the summary buffers."
874   :group 'gnus-threading
875   :group 'gnus-score-default
876   :type '(choice (const :tag "off" nil)
877                  integer))
878
879 (defcustom gnus-summary-mode-hook nil
880   "*A hook for Gnus summary mode.
881 This hook is run before any variables are set in the summary buffer."
882   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
883   :group 'gnus-summary-various
884   :type 'hook)
885
886 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
887 (when (featurep 'xemacs)
888   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
889   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
890   (add-hook 'gnus-summary-mode-hook
891             'gnus-xmas-switch-horizontal-scrollbar-off))
892
893 (defcustom gnus-summary-menu-hook nil
894   "*Hook run after the creation of the summary mode menu."
895   :group 'gnus-summary-visual
896   :type 'hook)
897
898 (defcustom gnus-summary-exit-hook nil
899   "*A hook called on exit from the summary buffer.
900 It will be called with point in the group buffer."
901   :group 'gnus-summary-exit
902   :type 'hook)
903
904 (defcustom gnus-summary-prepare-hook nil
905   "*A hook called after the summary buffer has been generated.
906 If you want to modify the summary buffer, you can use this hook."
907   :group 'gnus-summary-various
908   :type 'hook)
909
910 (defcustom gnus-summary-prepared-hook nil
911   "*A hook called as the last thing after the summary buffer has been generated."
912   :group 'gnus-summary-various
913   :type 'hook)
914
915 (defcustom gnus-summary-generate-hook nil
916   "*A hook run just before generating the summary buffer.
917 This hook is commonly used to customize threading variables and the
918 like."
919   :group 'gnus-summary-various
920   :type 'hook)
921
922 (defcustom gnus-select-group-hook nil
923   "*A hook called when a newsgroup is selected.
924
925 If you'd like to simplify subjects like the
926 `gnus-summary-next-same-subject' command does, you can use the
927 following hook:
928
929  (add-hook gnus-select-group-hook
930            (lambda ()
931              (mapcar (lambda (header)
932                        (mail-header-set-subject
933                         header
934                         (gnus-simplify-subject
935                          (mail-header-subject header) 're-only)))
936                      gnus-newsgroup-headers)))"
937   :group 'gnus-group-select
938   :type 'hook)
939
940 (defcustom gnus-select-article-hook nil
941   "*A hook called when an article is selected."
942   :group 'gnus-summary-choose
943   :options '(gnus-agent-fetch-selected-article)
944   :type 'hook)
945
946 (defcustom gnus-visual-mark-article-hook
947   (list 'gnus-highlight-selected-summary)
948   "*Hook run after selecting an article in the summary buffer.
949 It is meant to be used for highlighting the article in some way.  It
950 is not run if `gnus-visual' is nil."
951   :group 'gnus-summary-visual
952   :type 'hook)
953
954 (defcustom gnus-parse-headers-hook nil
955   "*A hook called before parsing the headers."
956   :group 'gnus-various
957   :type 'hook)
958
959 (defcustom gnus-exit-group-hook nil
960   "*A hook called when exiting summary mode.
961 This hook is not called from the non-updating exit commands like `Q'."
962   :group 'gnus-various
963   :type 'hook)
964
965 (defcustom gnus-summary-update-hook
966   (list 'gnus-summary-highlight-line)
967   "*A hook called when a summary line is changed.
968 The hook will not be called if `gnus-visual' is nil.
969
970 The default function `gnus-summary-highlight-line' will
971 highlight the line according to the `gnus-summary-highlight'
972 variable."
973   :group 'gnus-summary-visual
974   :type 'hook)
975
976 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
977   "*A hook called when an article is selected for the first time.
978 The hook is intended to mark an article as read (or unread)
979 automatically when it is selected."
980   :group 'gnus-summary-choose
981   :type 'hook)
982
983 (defcustom gnus-group-no-more-groups-hook nil
984   "*A hook run when returning to group mode having no more (unread) groups."
985   :group 'gnus-group-select
986   :type 'hook)
987
988 (defcustom gnus-ps-print-hook nil
989   "*A hook run before ps-printing something from Gnus."
990   :group 'gnus-summary
991   :type 'hook)
992
993 (defcustom gnus-summary-article-move-hook nil
994   "*A hook called after an article is moved, copied, respooled, or crossposted."
995   :version "22.1"
996   :group 'gnus-summary
997   :type 'hook)
998
999 (defcustom gnus-summary-article-delete-hook nil
1000   "*A hook called after an article is deleted."
1001   :version "22.1"
1002   :group 'gnus-summary
1003   :type 'hook)
1004
1005 (defcustom gnus-summary-article-expire-hook nil
1006   "*A hook called after an article is expired."
1007   :version "22.1"
1008   :group 'gnus-summary
1009   :type 'hook)
1010
1011 (defcustom gnus-summary-display-arrow
1012   (and (fboundp 'display-graphic-p)
1013        (display-graphic-p))
1014   "*If non-nil, display an arrow highlighting the current article."
1015   :version "22.1"
1016   :group 'gnus-summary
1017   :type 'boolean)
1018
1019 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1020   "Face used for highlighting the current article in the summary buffer."
1021   :group 'gnus-summary-visual
1022   :type 'face)
1023
1024 (defvar gnus-tmp-downloaded nil)
1025
1026 (defcustom gnus-summary-highlight
1027   '(((eq mark gnus-canceled-mark)
1028      . gnus-summary-cancelled)
1029     ((and uncached (> score default-high))
1030      . gnus-summary-high-undownloaded)
1031     ((and uncached (< score default-low))
1032      . gnus-summary-low-undownloaded)
1033     (uncached
1034      . gnus-summary-normal-undownloaded)
1035     ((and (> score default-high)
1036           (or (eq mark gnus-dormant-mark)
1037               (eq mark gnus-ticked-mark)))
1038      . gnus-summary-high-ticked)
1039     ((and (< score default-low)
1040           (or (eq mark gnus-dormant-mark)
1041               (eq mark gnus-ticked-mark)))
1042      . gnus-summary-low-ticked)
1043     ((or (eq mark gnus-dormant-mark)
1044          (eq mark gnus-ticked-mark))
1045      . gnus-summary-normal-ticked)
1046     ((and (> score default-high) (eq mark gnus-ancient-mark))
1047      . gnus-summary-high-ancient)
1048     ((and (< score default-low) (eq mark gnus-ancient-mark))
1049      . gnus-summary-low-ancient)
1050     ((eq mark gnus-ancient-mark)
1051      . gnus-summary-normal-ancient)
1052     ((and (> score default-high) (eq mark gnus-unread-mark))
1053      . gnus-summary-high-unread)
1054     ((and (< score default-low) (eq mark gnus-unread-mark))
1055      . gnus-summary-low-unread)
1056     ((eq mark gnus-unread-mark)
1057      . gnus-summary-normal-unread)
1058     ((> score default-high)
1059      . gnus-summary-high-read)
1060     ((< score default-low)
1061      . gnus-summary-low-read)
1062     (t
1063      . gnus-summary-normal-read))
1064   "*Controls the highlighting of summary buffer lines.
1065
1066 A list of (FORM . FACE) pairs.  When deciding how a particular
1067 summary line should be displayed, each form is evaluated.  The content
1068 of the face field after the first true form is used.  You can change
1069 how those summary lines are displayed, by editing the face field.
1070
1071 You can use the following variables in the FORM field.
1072
1073 score:        The article's score.
1074 default:      The default article score.
1075 default-high: The default score for high scored articles.
1076 default-low:  The default score for low scored articles.
1077 below:        The score below which articles are automatically marked as read.
1078 mark:         The article's mark.
1079 uncached:     Non-nil if the article is uncached."
1080   :group 'gnus-summary-visual
1081   :type '(repeat (cons (sexp :tag "Form" nil)
1082                        face)))
1083
1084 (defcustom gnus-alter-header-function nil
1085   "Function called to allow alteration of article header structures.
1086 The function is called with one parameter, the article header vector,
1087 which it may alter in any way."
1088   :type '(choice (const :tag "None" nil)
1089                  function)
1090   :group 'gnus-summary)
1091
1092 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1093   "Function used to decode a string with encoded words.")
1094
1095 (defvar gnus-decode-encoded-address-function
1096   'mail-decode-encoded-address-string
1097   "Function used to decode addresses with encoded words.")
1098
1099 (defcustom gnus-extra-headers '(To Newsgroups)
1100   "*Extra headers to parse."
1101   :version "21.1"
1102   :group 'gnus-summary
1103   :type '(repeat symbol))
1104
1105 (defcustom gnus-ignored-from-addresses
1106   (and user-mail-address
1107        (not (string= user-mail-address ""))
1108        (regexp-quote user-mail-address))
1109   "*From headers that may be suppressed in favor of To headers.
1110 This can be a regexp or a list of regexps."
1111   :version "21.1"
1112   :group 'gnus-summary
1113   :type '(choice regexp
1114                  (repeat :tag "Regexp List" regexp)))
1115
1116 (defsubst gnus-ignored-from-addresses ()
1117   (gmm-regexp-concat gnus-ignored-from-addresses))
1118
1119 (defcustom gnus-summary-to-prefix "-> "
1120   "*String prefixed to the To field in the summary line when
1121 using `gnus-ignored-from-addresses'."
1122   :version "22.1"
1123   :group 'gnus-summary
1124   :type 'string)
1125
1126 (defcustom gnus-summary-newsgroup-prefix "=> "
1127   "*String prefixed to the Newsgroup field in the summary
1128 line when using `gnus-ignored-from-addresses'."
1129   :version "22.1"
1130   :group 'gnus-summary
1131   :type 'string)
1132
1133 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1134   "List of charsets that should be ignored.
1135 When these charsets are used in the \"charset\" parameter, the
1136 default charset will be used instead."
1137   :version "21.1"
1138   :type '(repeat symbol)
1139   :group 'gnus-charset)
1140
1141 (defcustom gnus-newsgroup-maximum-articles nil
1142   "The maximum number of articles a newsgroup.
1143 If this is a number, old articles in a newsgroup exceeding this number
1144 are silently ignored.  If it is nil, no article is ignored.  Note that
1145 setting this variable to a number might prevent you from reading very
1146 old articles."
1147   :group 'gnus-group-select
1148   :version "22.2"
1149   :type '(choice (const :tag "No limit" nil)
1150                  integer))
1151
1152 (gnus-define-group-parameter
1153  ignored-charsets
1154  :type list
1155  :function-document
1156  "Return the ignored charsets of GROUP."
1157  :variable gnus-group-ignored-charsets-alist
1158  :variable-default
1159  '(("alt\\.chinese\\.text" iso-8859-1))
1160  :variable-document
1161  "Alist of regexps (to match group names) and charsets that should be ignored.
1162 When these charsets are used in the \"charset\" parameter, the
1163 default charset will be used instead."
1164  :variable-group gnus-charset
1165  :variable-type '(repeat (cons (regexp :tag "Group")
1166                                (repeat symbol)))
1167  :parameter-type '(choice :tag "Ignored charsets"
1168                           :value nil
1169                           (repeat (symbol)))
1170  :parameter-document       "\
1171 List of charsets that should be ignored.
1172
1173 When these charsets are used in the \"charset\" parameter, the
1174 default charset will be used instead.")
1175
1176 (defcustom gnus-group-highlight-words-alist nil
1177   "Alist of group regexps and highlight regexps.
1178 This variable uses the same syntax as `gnus-emphasis-alist'."
1179   :version "21.1"
1180   :type '(repeat (cons (regexp :tag "Group")
1181                        (repeat (list (regexp :tag "Highlight regexp")
1182                                      (number :tag "Group for entire word" 0)
1183                                      (number :tag "Group for displayed part" 0)
1184                                      (symbol :tag "Face"
1185                                              gnus-emphasis-highlight-words)))))
1186   :group 'gnus-summary-visual)
1187
1188 (defcustom gnus-summary-show-article-charset-alist
1189   nil
1190   "Alist of number and charset.
1191 The article will be shown with the charset corresponding to the
1192 numbered argument.
1193 For example: ((1 . cn-gb-2312) (2 . big5))."
1194   :version "21.1"
1195   :type '(repeat (cons (number :tag "Argument" 1)
1196                        (symbol :tag "Charset")))
1197   :group 'gnus-charset)
1198
1199 (defcustom gnus-preserve-marks t
1200   "Whether marks are preserved when moving, copying and respooling messages."
1201   :version "21.1"
1202   :type 'boolean
1203   :group 'gnus-summary-marks)
1204
1205 (defcustom gnus-alter-articles-to-read-function nil
1206   "Function to be called to alter the list of articles to be selected."
1207   :type '(choice (const nil) function)
1208   :group 'gnus-summary)
1209
1210 (defcustom gnus-orphan-score nil
1211   "*All orphans get this score added.  Set in the score file."
1212   :group 'gnus-score-default
1213   :type '(choice (const nil)
1214                  integer))
1215
1216 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1217   "*A regexp to match MIME parts when saving multiple parts of a
1218 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1219 This regexp will be used by default when prompting the user for which
1220 type of files to save."
1221   :group 'gnus-summary
1222   :type 'regexp)
1223
1224 (defcustom gnus-read-all-available-headers nil
1225   "Whether Gnus should parse all headers made available to it.
1226 This is mostly relevant for slow back ends where the user may
1227 wish to widen the summary buffer to include all headers
1228 that were fetched.  Say, for nnultimate groups."
1229   :version "22.1"
1230   :group 'gnus-summary
1231   :type '(choice boolean regexp))
1232
1233 (defcustom gnus-summary-muttprint-program "muttprint"
1234   "Command (and optional arguments) used to run Muttprint."
1235   :version "22.1"
1236   :group 'gnus-summary
1237   :type 'string)
1238
1239 (defcustom gnus-article-loose-mime t
1240   "If non-nil, don't require MIME-Version header.
1241 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1242 supply the MIME-Version header or deliberately strip it from the mail.
1243 If non-nil (the default), Gnus will treat some articles as MIME
1244 even if the MIME-Version header is missing."
1245   :version "22.1"
1246   :type 'boolean
1247   :group 'gnus-article-mime)
1248
1249 (defcustom gnus-article-emulate-mime t
1250   "If non-nil, use MIME emulation for uuencode and the like.
1251 This means that Gnus will search message bodies for text that look
1252 like uuencoded bits, yEncoded bits, and so on, and present that using
1253 the normal Gnus MIME machinery."
1254   :version "22.1"
1255   :type 'boolean
1256   :group 'gnus-article-mime)
1257
1258 ;;; Internal variables
1259
1260 (defvar gnus-summary-display-cache nil)
1261 (defvar gnus-article-mime-handles nil)
1262 (defvar gnus-article-decoded-p nil)
1263 (defvar gnus-article-charset nil)
1264 (defvar gnus-article-ignored-charsets nil)
1265 (defvar gnus-scores-exclude-files nil)
1266 (defvar gnus-page-broken nil)
1267
1268 (defvar gnus-original-article nil)
1269 (defvar gnus-article-internal-prepare-hook nil)
1270 (defvar gnus-newsgroup-process-stack nil)
1271
1272 (defvar gnus-thread-indent-array nil)
1273 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1274 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1275   "Function called to sort the articles within a thread after it has been gathered together.")
1276
1277 (defvar gnus-summary-save-parts-type-history nil)
1278 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1279
1280 ;; Avoid highlighting in kill files.
1281 (defvar gnus-summary-inhibit-highlight nil)
1282 (defvar gnus-newsgroup-selected-overlay nil)
1283 (defvar gnus-inhibit-limiting nil)
1284 (defvar gnus-newsgroup-adaptive-score-file nil)
1285 (defvar gnus-current-score-file nil)
1286 (defvar gnus-current-move-group nil)
1287 (defvar gnus-current-copy-group nil)
1288 (defvar gnus-current-crosspost-group nil)
1289 (defvar gnus-newsgroup-display nil)
1290
1291 (defvar gnus-newsgroup-dependencies nil)
1292 (defvar gnus-newsgroup-adaptive nil)
1293 (defvar gnus-summary-display-article-function nil)
1294 (defvar gnus-summary-highlight-line-function nil
1295   "Function called after highlighting a summary line.")
1296
1297 (defvar gnus-summary-line-format-alist
1298   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1299     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1300     (?s gnus-tmp-subject-or-nil ?s)
1301     (?n gnus-tmp-name ?s)
1302     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1303         ?s)
1304     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1305             gnus-tmp-from) ?s)
1306     (?F gnus-tmp-from ?s)
1307     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1308     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1309     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1310     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1311     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1312     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1313     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1314     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1315     (?L gnus-tmp-lines ?s)
1316     (?O gnus-tmp-downloaded ?c)
1317     (?I gnus-tmp-indentation ?s)
1318     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1319     (?R gnus-tmp-replied ?c)
1320     (?\[ gnus-tmp-opening-bracket ?c)
1321     (?\] gnus-tmp-closing-bracket ?c)
1322     (?\> (make-string gnus-tmp-level ? ) ?s)
1323     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1324     (?i gnus-tmp-score ?d)
1325     (?z gnus-tmp-score-char ?c)
1326     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1327     (?U gnus-tmp-unread ?c)
1328     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1329         ?s)
1330     (?t (gnus-summary-number-of-articles-in-thread
1331          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1332         ?d)
1333     (?e (gnus-summary-number-of-articles-in-thread
1334          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1335         ?c)
1336     (?u gnus-tmp-user-defined ?s)
1337     (?P (gnus-pick-line-number) ?d)
1338     (?B gnus-tmp-thread-tree-header-string ?s)
1339     (user-date (gnus-user-date
1340                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1341   "An alist of format specifications that can appear in summary lines.
1342 These are paired with what variables they correspond with, along with
1343 the type of the variable (string, integer, character, etc).")
1344
1345 (defvar gnus-summary-dummy-line-format-alist
1346   `((?S gnus-tmp-subject ?s)
1347     (?N gnus-tmp-number ?d)
1348     (?u gnus-tmp-user-defined ?s)))
1349
1350 (defvar gnus-summary-mode-line-format-alist
1351   `((?G gnus-tmp-group-name ?s)
1352     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1353     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1354     (?A gnus-tmp-article-number ?d)
1355     (?Z gnus-tmp-unread-and-unselected ?s)
1356     (?V gnus-version ?s)
1357     (?U gnus-tmp-unread-and-unticked ?d)
1358     (?S gnus-tmp-subject ?s)
1359     (?e gnus-tmp-unselected ?d)
1360     (?u gnus-tmp-user-defined ?s)
1361     (?d (length gnus-newsgroup-dormant) ?d)
1362     (?t (length gnus-newsgroup-marked) ?d)
1363     (?h (length gnus-newsgroup-spam-marked) ?d)
1364     (?r (length gnus-newsgroup-reads) ?d)
1365     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1366     (?E gnus-newsgroup-expunged-tally ?d)
1367     (?s (gnus-current-score-file-nondirectory) ?s)))
1368
1369 (defvar gnus-last-search-regexp nil
1370   "Default regexp for article search command.")
1371
1372 (defvar gnus-last-shell-command nil
1373   "Default shell command on article.")
1374
1375 (defvar gnus-newsgroup-agentized nil
1376   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1377 (defvar gnus-newsgroup-begin nil)
1378 (defvar gnus-newsgroup-end nil)
1379 (defvar gnus-newsgroup-last-rmail nil)
1380 (defvar gnus-newsgroup-last-mail nil)
1381 (defvar gnus-newsgroup-last-folder nil)
1382 (defvar gnus-newsgroup-last-file nil)
1383 (defvar gnus-newsgroup-last-directory nil)
1384 (defvar gnus-newsgroup-auto-expire nil)
1385 (defvar gnus-newsgroup-active nil)
1386
1387 (defvar gnus-newsgroup-data nil)
1388 (defvar gnus-newsgroup-data-reverse nil)
1389 (defvar gnus-newsgroup-limit nil)
1390 (defvar gnus-newsgroup-limits nil)
1391 (defvar gnus-summary-use-undownloaded-faces nil)
1392
1393 (defvar gnus-newsgroup-unreads nil
1394   "Sorted list of unread articles in the current newsgroup.")
1395
1396 (defvar gnus-newsgroup-unselected nil
1397   "Sorted list of unselected unread articles in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-reads nil
1400   "Alist of read articles and article marks in the current newsgroup.")
1401
1402 (defvar gnus-newsgroup-expunged-tally nil)
1403
1404 (defvar gnus-newsgroup-marked nil
1405   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1406
1407 (defvar gnus-newsgroup-spam-marked nil
1408   "List of ranges of articles that have been marked as spam.")
1409
1410 (defvar gnus-newsgroup-killed nil
1411   "List of ranges of articles that have been through the scoring process.")
1412
1413 (defvar gnus-newsgroup-cached nil
1414   "Sorted list of articles that come from the article cache.")
1415
1416 (defvar gnus-newsgroup-saved nil
1417   "List of articles that have been saved.")
1418
1419 (defvar gnus-newsgroup-kill-headers nil)
1420
1421 (defvar gnus-newsgroup-replied nil
1422   "List of articles that have been replied to in the current newsgroup.")
1423
1424 (defvar gnus-newsgroup-forwarded nil
1425   "List of articles that have been forwarded in the current newsgroup.")
1426
1427 (defvar gnus-newsgroup-recent nil
1428   "List of articles that have are recent in the current newsgroup.")
1429
1430 (defvar gnus-newsgroup-expirable nil
1431   "Sorted list of articles in the current newsgroup that can be expired.")
1432
1433 (defvar gnus-newsgroup-processable nil
1434   "List of articles in the current newsgroup that can be processed.")
1435
1436 (defvar gnus-newsgroup-downloadable nil
1437   "Sorted list of articles in the current newsgroup that can be processed.")
1438
1439 (defvar gnus-newsgroup-unfetched nil
1440   "Sorted list of articles in the current newsgroup whose headers have
1441 not been fetched into the agent.
1442
1443 This list will always be a subset of gnus-newsgroup-undownloaded.")
1444
1445 (defvar gnus-newsgroup-undownloaded nil
1446   "List of articles in the current newsgroup that haven't been downloaded.")
1447
1448 (defvar gnus-newsgroup-unsendable nil
1449   "List of articles in the current newsgroup that won't be sent.")
1450
1451 (defvar gnus-newsgroup-bookmarks nil
1452   "List of articles in the current newsgroup that have bookmarks.")
1453
1454 (defvar gnus-newsgroup-dormant nil
1455   "Sorted list of dormant articles in the current newsgroup.")
1456
1457 (defvar gnus-newsgroup-unseen nil
1458   "List of unseen articles in the current newsgroup.")
1459
1460 (defvar gnus-newsgroup-seen nil
1461   "Range of seen articles in the current newsgroup.")
1462
1463 (defvar gnus-newsgroup-articles nil
1464   "List of articles in the current newsgroup.")
1465
1466 (defvar gnus-newsgroup-scored nil
1467   "List of scored articles in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-headers nil
1470   "List of article headers in the current newsgroup.")
1471
1472 (defvar gnus-newsgroup-threads nil)
1473
1474 (defvar gnus-newsgroup-prepared nil
1475   "Whether the current group has been prepared properly.")
1476
1477 (defvar gnus-newsgroup-ancient nil
1478   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1479
1480 (defvar gnus-newsgroup-sparse nil)
1481
1482 (defvar gnus-current-article nil)
1483 (defvar gnus-article-current nil)
1484 (defvar gnus-current-headers nil)
1485 (defvar gnus-have-all-headers nil)
1486 (defvar gnus-last-article nil)
1487 (defvar gnus-newsgroup-history nil)
1488 (defvar gnus-newsgroup-charset nil)
1489 (defvar gnus-newsgroup-ephemeral-charset nil)
1490 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1491
1492 (defvar gnus-article-before-search nil)
1493
1494 (defvar gnus-summary-local-variables
1495   '(gnus-newsgroup-name
1496     gnus-newsgroup-begin gnus-newsgroup-end
1497     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1498     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1499     gnus-newsgroup-last-directory
1500     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1501     gnus-newsgroup-unselected gnus-newsgroup-marked
1502     gnus-newsgroup-spam-marked
1503     gnus-newsgroup-reads gnus-newsgroup-saved
1504     gnus-newsgroup-replied gnus-newsgroup-forwarded
1505     gnus-newsgroup-recent
1506     gnus-newsgroup-expirable
1507     gnus-newsgroup-processable gnus-newsgroup-killed
1508     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1509     gnus-newsgroup-unfetched
1510     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1511     gnus-newsgroup-seen gnus-newsgroup-articles
1512     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1513     gnus-newsgroup-headers gnus-newsgroup-threads
1514     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1515     gnus-current-article gnus-current-headers gnus-have-all-headers
1516     gnus-last-article gnus-article-internal-prepare-hook
1517     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1518     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1519     gnus-thread-expunge-below
1520     gnus-score-alist gnus-current-score-file
1521     (gnus-summary-expunge-below . global)
1522     (gnus-summary-mark-below . global)
1523     (gnus-orphan-score . global)
1524     gnus-newsgroup-active gnus-scores-exclude-files
1525     gnus-newsgroup-history gnus-newsgroup-ancient
1526     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1527     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1528     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1529     (gnus-newsgroup-expunged-tally . 0)
1530     gnus-cache-removable-articles gnus-newsgroup-cached
1531     gnus-newsgroup-data gnus-newsgroup-data-reverse
1532     gnus-newsgroup-limit gnus-newsgroup-limits
1533     gnus-newsgroup-charset gnus-newsgroup-display
1534     gnus-summary-use-undownloaded-faces)
1535   "Variables that are buffer-local to the summary buffers.")
1536
1537 (defvar gnus-newsgroup-variables nil
1538   "A list of variables that have separate values in different newsgroups.
1539 A list of newsgroup (summary buffer) local variables, or cons of
1540 variables and their default expressions to be evalled (when the default
1541 values are not nil), that should be made global while the summary buffer
1542 is active.
1543
1544 Note: The default expressions will be evaluated (using function `eval')
1545 before assignment to the local variable rather than just assigned to it.
1546 If the default expression is the symbol `global', that symbol will not
1547 be evaluated but the global value of the local variable will be used
1548 instead.
1549
1550 These variables can be used to set variables in the group parameters
1551 while still allowing them to affect operations done in other buffers.
1552 For example:
1553
1554 \(setq gnus-newsgroup-variables
1555      '(message-use-followup-to
1556        (gnus-visible-headers .
1557          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1558 ")
1559
1560 ;; Byte-compiler warning.
1561 (eval-when-compile
1562   ;; Bind features so that require will believe that gnus-sum has
1563   ;; already been loaded (avoids infinite recursion)
1564   (let ((features (cons 'gnus-sum features)))
1565     ;; Several of the declarations in gnus-sum are needed to load the
1566     ;; following files. Right now, these definitions have been
1567     ;; compiled but not defined (evaluated).  We could either do a
1568     ;; eval-and-compile about all of the declarations or evaluate the
1569     ;; source file.
1570     (if (boundp 'gnus-newsgroup-variables)
1571         nil
1572       (load "gnus-sum.el" t t t))
1573     (require 'gnus)
1574     (require 'gnus-art)))
1575
1576 ;; MIME stuff.
1577
1578 (defvar gnus-decode-encoded-word-methods
1579   '(mail-decode-encoded-word-string)
1580   "List of methods used to decode encoded words.
1581
1582 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1583 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1584 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1585 whose names match REGEXP.
1586
1587 For example:
1588 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1589  mail-decode-encoded-word-string
1590  (\"chinese\" . rfc1843-decode-string))")
1591
1592 (defvar gnus-decode-encoded-word-methods-cache nil)
1593
1594 (defun gnus-multi-decode-encoded-word-string (string)
1595   "Apply the functions from `gnus-encoded-word-methods' that match."
1596   (unless (and gnus-decode-encoded-word-methods-cache
1597                (eq gnus-newsgroup-name
1598                    (car gnus-decode-encoded-word-methods-cache)))
1599     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1600     (dolist (method gnus-decode-encoded-word-methods)
1601       (if (symbolp method)
1602           (nconc gnus-decode-encoded-word-methods-cache (list method))
1603         (if (and gnus-newsgroup-name
1604                  (string-match (car method) gnus-newsgroup-name))
1605             (nconc gnus-decode-encoded-word-methods-cache
1606                    (list (cdr method)))))))
1607   (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1608     (setq string (funcall method string))))
1609
1610 ;; Subject simplification.
1611
1612 (defun gnus-simplify-whitespace (str)
1613   "Remove excessive whitespace from STR."
1614   ;; Multiple spaces.
1615   (while (string-match "[ \t][ \t]+" str)
1616     (setq str (concat (substring str 0 (match-beginning 0))
1617                         " "
1618                         (substring str (match-end 0)))))
1619   ;; Leading spaces.
1620   (when (string-match "^[ \t]+" str)
1621     (setq str (substring str (match-end 0))))
1622   ;; Trailing spaces.
1623   (when (string-match "[ \t]+$" str)
1624     (setq str (substring str 0 (match-beginning 0))))
1625   str)
1626
1627 (defun gnus-simplify-all-whitespace (str)
1628   "Remove all whitespace from STR."
1629   (while (string-match "[ \t\n]+" str)
1630     (setq str (replace-match "" nil nil str)))
1631   str)
1632
1633 (defsubst gnus-simplify-subject-re (subject)
1634   "Remove \"Re:\" from subject lines."
1635   (if (string-match message-subject-re-regexp subject)
1636       (substring subject (match-end 0))
1637     subject))
1638
1639 (defun gnus-simplify-subject (subject &optional re-only)
1640   "Remove `Re:' and words in parentheses.
1641 If RE-ONLY is non-nil, strip leading `Re:'s only."
1642   (let ((case-fold-search t))           ;Ignore case.
1643     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1644     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1645       (setq subject (substring subject (match-end 0))))
1646     ;; Remove uninteresting prefixes.
1647     (when (and (not re-only)
1648                gnus-simplify-ignored-prefixes
1649                (string-match gnus-simplify-ignored-prefixes subject))
1650       (setq subject (substring subject (match-end 0))))
1651     ;; Remove words in parentheses from end.
1652     (unless re-only
1653       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1654         (setq subject (substring subject 0 (match-beginning 0)))))
1655     ;; Return subject string.
1656     subject))
1657
1658 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1659 ;; all whitespace.
1660 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1661   (goto-char (point-min))
1662   (while (re-search-forward regexp nil t)
1663     (replace-match (or newtext ""))))
1664
1665 (defun gnus-simplify-buffer-fuzzy ()
1666   "Simplify string in the buffer fuzzily.
1667 The string in the accessible portion of the current buffer is simplified.
1668 It is assumed to be a single-line subject.
1669 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1670 matter is removed.  Additional things can be deleted by setting
1671 `gnus-simplify-subject-fuzzy-regexp'."
1672   (let ((case-fold-search t)
1673         (modified-tick))
1674     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1675
1676     (while (not (eq modified-tick (buffer-modified-tick)))
1677       (setq modified-tick (buffer-modified-tick))
1678       (cond
1679        ((listp gnus-simplify-subject-fuzzy-regexp)
1680         (mapc 'gnus-simplify-buffer-fuzzy-step
1681               gnus-simplify-subject-fuzzy-regexp))
1682        (gnus-simplify-subject-fuzzy-regexp
1683         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1684       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1685       (gnus-simplify-buffer-fuzzy-step
1686        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1687       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1688
1689     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1690     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1691     (gnus-simplify-buffer-fuzzy-step " $")
1692     (gnus-simplify-buffer-fuzzy-step "^ +")))
1693
1694 (defun gnus-simplify-subject-fuzzy (subject)
1695   "Simplify a subject string fuzzily.
1696 See `gnus-simplify-buffer-fuzzy' for details."
1697   (save-excursion
1698     (gnus-set-work-buffer)
1699     (let ((case-fold-search t))
1700       ;; Remove uninteresting prefixes.
1701       (when (and gnus-simplify-ignored-prefixes
1702                  (string-match gnus-simplify-ignored-prefixes subject))
1703         (setq subject (substring subject (match-end 0))))
1704       (insert subject)
1705       (inline (gnus-simplify-buffer-fuzzy))
1706       (buffer-string))))
1707
1708 (defsubst gnus-simplify-subject-fully (subject)
1709   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1710   (cond
1711    (gnus-simplify-subject-functions
1712     (gnus-map-function gnus-simplify-subject-functions subject))
1713    ((null gnus-summary-gather-subject-limit)
1714     (gnus-simplify-subject-re subject))
1715    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1716     (gnus-simplify-subject-fuzzy subject))
1717    ((numberp gnus-summary-gather-subject-limit)
1718     (truncate-string-to-width (gnus-simplify-subject-re subject)
1719                               gnus-summary-gather-subject-limit))
1720    (t
1721     subject)))
1722
1723 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1724   "Check whether two subjects are equal.
1725 If optional argument SIMPLE-FIRST is t, first argument is already
1726 simplified."
1727   (cond
1728    ((null simple-first)
1729     (equal (gnus-simplify-subject-fully s1)
1730            (gnus-simplify-subject-fully s2)))
1731    (t
1732     (equal s1
1733            (gnus-simplify-subject-fully s2)))))
1734
1735 (defun gnus-summary-bubble-group ()
1736   "Increase the score of the current group.
1737 This is a handy function to add to `gnus-summary-exit-hook' to
1738 increase the score of each group you read."
1739   (gnus-group-add-score gnus-newsgroup-name))
1740
1741 \f
1742 ;;;
1743 ;;; Gnus summary mode
1744 ;;;
1745
1746 (put 'gnus-summary-mode 'mode-class 'special)
1747
1748 (defvar gnus-article-commands-menu)
1749
1750 ;; Non-orthogonal keys
1751
1752 (gnus-define-keys gnus-summary-mode-map
1753   " " gnus-summary-next-page
1754   "\177" gnus-summary-prev-page
1755   [delete] gnus-summary-prev-page
1756   [backspace] gnus-summary-prev-page
1757   "\r" gnus-summary-scroll-up
1758   "\M-\r" gnus-summary-scroll-down
1759   "n" gnus-summary-next-unread-article
1760   "p" gnus-summary-prev-unread-article
1761   "N" gnus-summary-next-article
1762   "P" gnus-summary-prev-article
1763   "\M-\C-n" gnus-summary-next-same-subject
1764   "\M-\C-p" gnus-summary-prev-same-subject
1765   "\M-n" gnus-summary-next-unread-subject
1766   "\M-p" gnus-summary-prev-unread-subject
1767   "." gnus-summary-first-unread-article
1768   "," gnus-summary-best-unread-article
1769   "\M-s" gnus-summary-search-article-forward
1770   "\M-r" gnus-summary-search-article-backward
1771   "\M-S" gnus-summary-repeat-search-article-forward
1772   "\M-R" gnus-summary-repeat-search-article-backward
1773   "<" gnus-summary-beginning-of-article
1774   ">" gnus-summary-end-of-article
1775   "j" gnus-summary-goto-article
1776   "^" gnus-summary-refer-parent-article
1777   "\M-^" gnus-summary-refer-article
1778   "u" gnus-summary-tick-article-forward
1779   "!" gnus-summary-tick-article-forward
1780   "U" gnus-summary-tick-article-backward
1781   "d" gnus-summary-mark-as-read-forward
1782   "D" gnus-summary-mark-as-read-backward
1783   "E" gnus-summary-mark-as-expirable
1784   "\M-u" gnus-summary-clear-mark-forward
1785   "\M-U" gnus-summary-clear-mark-backward
1786   "k" gnus-summary-kill-same-subject-and-select
1787   "\C-k" gnus-summary-kill-same-subject
1788   "\M-\C-k" gnus-summary-kill-thread
1789   "\M-\C-l" gnus-summary-lower-thread
1790   "e" gnus-summary-edit-article
1791   "#" gnus-summary-mark-as-processable
1792   "\M-#" gnus-summary-unmark-as-processable
1793   "\M-\C-t" gnus-summary-toggle-threads
1794   "\M-\C-s" gnus-summary-show-thread
1795   "\M-\C-h" gnus-summary-hide-thread
1796   "\M-\C-f" gnus-summary-next-thread
1797   "\M-\C-b" gnus-summary-prev-thread
1798   [(meta down)] gnus-summary-next-thread
1799   [(meta up)] gnus-summary-prev-thread
1800   "\M-\C-u" gnus-summary-up-thread
1801   "\M-\C-d" gnus-summary-down-thread
1802   "&" gnus-summary-execute-command
1803   "c" gnus-summary-catchup-and-exit
1804   "\C-w" gnus-summary-mark-region-as-read
1805   "\C-t" gnus-summary-toggle-truncation
1806   "?" gnus-summary-mark-as-dormant
1807   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1808   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1809   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1810   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1811   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1812   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1813   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1814   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1815   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1816   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1817   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1818   "=" gnus-summary-expand-window
1819   "\C-x\C-s" gnus-summary-reselect-current-group
1820   "\M-g" gnus-summary-rescan-group
1821   "w" gnus-summary-stop-page-breaking
1822   "\C-c\C-r" gnus-summary-caesar-message
1823   "f" gnus-summary-followup
1824   "F" gnus-summary-followup-with-original
1825   "C" gnus-summary-cancel-article
1826   "r" gnus-summary-reply
1827   "R" gnus-summary-reply-with-original
1828   "\C-c\C-f" gnus-summary-mail-forward
1829   "o" gnus-summary-save-article
1830   "\C-o" gnus-summary-save-article-mail
1831   "|" gnus-summary-pipe-output
1832   "\M-k" gnus-summary-edit-local-kill
1833   "\M-K" gnus-summary-edit-global-kill
1834   ;; "V" gnus-version
1835   "\C-c\C-d" gnus-summary-describe-group
1836   "q" gnus-summary-exit
1837   "Q" gnus-summary-exit-no-update
1838   "\C-c\C-i" gnus-info-find-node
1839   gnus-mouse-2 gnus-mouse-pick-article
1840   [follow-link] mouse-face
1841   "m" gnus-summary-mail-other-window
1842   "a" gnus-summary-post-news
1843   "i" gnus-summary-news-other-window
1844   "x" gnus-summary-limit-to-unread
1845   "s" gnus-summary-isearch-article
1846   "t" gnus-summary-toggle-header
1847   "g" gnus-summary-show-article
1848   "l" gnus-summary-goto-last-article
1849   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1850   "\C-d" gnus-summary-enter-digest-group
1851   "\M-\C-d" gnus-summary-read-document
1852   "\M-\C-e" gnus-summary-edit-parameters
1853   "\M-\C-a" gnus-summary-customize-parameters
1854   "\C-c\C-b" gnus-bug
1855   "*" gnus-cache-enter-article
1856   "\M-*" gnus-cache-remove-article
1857   "\M-&" gnus-summary-universal-argument
1858   "\C-l" gnus-recenter
1859   "I" gnus-summary-increase-score
1860   "L" gnus-summary-lower-score
1861   "\M-i" gnus-symbolic-argument
1862   "h" gnus-summary-select-article-buffer
1863
1864   "b" gnus-article-view-part
1865   "\M-t" gnus-summary-toggle-display-buttonized
1866
1867   "V" gnus-summary-score-map
1868   "X" gnus-uu-extract-map
1869   "S" gnus-summary-send-map)
1870
1871 ;; Sort of orthogonal keymap
1872 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1873   "t" gnus-summary-tick-article-forward
1874   "!" gnus-summary-tick-article-forward
1875   "d" gnus-summary-mark-as-read-forward
1876   "r" gnus-summary-mark-as-read-forward
1877   "c" gnus-summary-clear-mark-forward
1878   " " gnus-summary-clear-mark-forward
1879   "e" gnus-summary-mark-as-expirable
1880   "x" gnus-summary-mark-as-expirable
1881   "?" gnus-summary-mark-as-dormant
1882   "b" gnus-summary-set-bookmark
1883   "B" gnus-summary-remove-bookmark
1884   "#" gnus-summary-mark-as-processable
1885   "\M-#" gnus-summary-unmark-as-processable
1886   "S" gnus-summary-limit-include-expunged
1887   "C" gnus-summary-catchup
1888   "H" gnus-summary-catchup-to-here
1889   "h" gnus-summary-catchup-from-here
1890   "\C-c" gnus-summary-catchup-all
1891   "k" gnus-summary-kill-same-subject-and-select
1892   "K" gnus-summary-kill-same-subject
1893   "P" gnus-uu-mark-map)
1894
1895 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1896   "c" gnus-summary-clear-above
1897   "u" gnus-summary-tick-above
1898   "m" gnus-summary-mark-above
1899   "k" gnus-summary-kill-below)
1900
1901 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1902   "/" gnus-summary-limit-to-subject
1903   "n" gnus-summary-limit-to-articles
1904   "b" gnus-summary-limit-to-bodies
1905   "h" gnus-summary-limit-to-headers
1906   "w" gnus-summary-pop-limit
1907   "s" gnus-summary-limit-to-subject
1908   "a" gnus-summary-limit-to-author
1909   "u" gnus-summary-limit-to-unread
1910   "m" gnus-summary-limit-to-marks
1911   "M" gnus-summary-limit-exclude-marks
1912   "v" gnus-summary-limit-to-score
1913   "*" gnus-summary-limit-include-cached
1914   "D" gnus-summary-limit-include-dormant
1915   "T" gnus-summary-limit-include-thread
1916   "d" gnus-summary-limit-exclude-dormant
1917   "t" gnus-summary-limit-to-age
1918   "." gnus-summary-limit-to-unseen
1919   "x" gnus-summary-limit-to-extra
1920   "p" gnus-summary-limit-to-display-predicate
1921   "E" gnus-summary-limit-include-expunged
1922   "c" gnus-summary-limit-exclude-childless-dormant
1923   "C" gnus-summary-limit-mark-excluded-as-read
1924   "o" gnus-summary-insert-old-articles
1925   "N" gnus-summary-insert-new-articles
1926   "S" gnus-summary-limit-to-singletons
1927   "r" gnus-summary-limit-to-replied
1928   "R" gnus-summary-limit-to-recipient
1929   "A" gnus-summary-limit-to-address)
1930
1931 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1932   "n" gnus-summary-next-unread-article
1933   "p" gnus-summary-prev-unread-article
1934   "N" gnus-summary-next-article
1935   "P" gnus-summary-prev-article
1936   "\C-n" gnus-summary-next-same-subject
1937   "\C-p" gnus-summary-prev-same-subject
1938   "\M-n" gnus-summary-next-unread-subject
1939   "\M-p" gnus-summary-prev-unread-subject
1940   "f" gnus-summary-first-unread-article
1941   "b" gnus-summary-best-unread-article
1942   "j" gnus-summary-goto-article
1943   "g" gnus-summary-goto-subject
1944   "l" gnus-summary-goto-last-article
1945   "o" gnus-summary-pop-article)
1946
1947 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1948   "k" gnus-summary-kill-thread
1949   "E" gnus-summary-expire-thread
1950   "l" gnus-summary-lower-thread
1951   "i" gnus-summary-raise-thread
1952   "T" gnus-summary-toggle-threads
1953   "t" gnus-summary-rethread-current
1954   "^" gnus-summary-reparent-thread
1955   "\M-^" gnus-summary-reparent-children
1956   "s" gnus-summary-show-thread
1957   "S" gnus-summary-show-all-threads
1958   "h" gnus-summary-hide-thread
1959   "H" gnus-summary-hide-all-threads
1960   "n" gnus-summary-next-thread
1961   "p" gnus-summary-prev-thread
1962   "u" gnus-summary-up-thread
1963   "o" gnus-summary-top-thread
1964   "d" gnus-summary-down-thread
1965   "#" gnus-uu-mark-thread
1966   "\M-#" gnus-uu-unmark-thread)
1967
1968 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1969   "g" gnus-summary-prepare
1970   "c" gnus-summary-insert-cached-articles
1971   "d" gnus-summary-insert-dormant-articles
1972   "t" gnus-summary-insert-ticked-articles)
1973
1974 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1975   "c" gnus-summary-catchup-and-exit
1976   "C" gnus-summary-catchup-all-and-exit
1977   "E" gnus-summary-exit-no-update
1978   "Q" gnus-summary-exit
1979   "Z" gnus-summary-exit
1980   "n" gnus-summary-catchup-and-goto-next-group
1981   "p" gnus-summary-catchup-and-goto-prev-group
1982   "R" gnus-summary-reselect-current-group
1983   "G" gnus-summary-rescan-group
1984   "N" gnus-summary-next-group
1985   "s" gnus-summary-save-newsrc
1986   "P" gnus-summary-prev-group)
1987
1988 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1989   " " gnus-summary-next-page
1990   "n" gnus-summary-next-page
1991   "\177" gnus-summary-prev-page
1992   [delete] gnus-summary-prev-page
1993   "p" gnus-summary-prev-page
1994   "\r" gnus-summary-scroll-up
1995   "\M-\r" gnus-summary-scroll-down
1996   "<" gnus-summary-beginning-of-article
1997   ">" gnus-summary-end-of-article
1998   "b" gnus-summary-beginning-of-article
1999   "e" gnus-summary-end-of-article
2000   "^" gnus-summary-refer-parent-article
2001   "r" gnus-summary-refer-parent-article
2002   "D" gnus-summary-enter-digest-group
2003   "R" gnus-summary-refer-references
2004   "T" gnus-summary-refer-thread
2005   "g" gnus-summary-show-article
2006   "s" gnus-summary-isearch-article
2007   "P" gnus-summary-print-article
2008   "S" gnus-sticky-article
2009   "M" gnus-mailing-list-insinuate
2010   "t" gnus-article-babel)
2011
2012 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2013   "b" gnus-article-add-buttons
2014   "B" gnus-article-add-buttons-to-head
2015   "o" gnus-article-treat-overstrike
2016   "e" gnus-article-emphasize
2017   "w" gnus-article-fill-cited-article
2018   "Q" gnus-article-fill-long-lines
2019   "L" gnus-article-toggle-truncate-lines
2020   "C" gnus-article-capitalize-sentences
2021   "c" gnus-article-remove-cr
2022   "q" gnus-article-de-quoted-unreadable
2023   "6" gnus-article-de-base64-unreadable
2024   "Z" gnus-article-decode-HZ
2025   "A" gnus-article-treat-ansi-sequences
2026   "h" gnus-article-wash-html
2027   "u" gnus-article-unsplit-urls
2028   "s" gnus-summary-force-verify-and-decrypt
2029   "f" gnus-article-display-x-face
2030   "l" gnus-summary-stop-page-breaking
2031   "r" gnus-summary-caesar-message
2032   "m" gnus-summary-morse-message
2033   "t" gnus-summary-toggle-header
2034   "g" gnus-treat-smiley
2035   "v" gnus-summary-verbose-headers
2036   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2037   "p" gnus-article-verify-x-pgp-sig
2038   "d" gnus-article-treat-dumbquotes
2039   "i" gnus-summary-idna-message)
2040
2041 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2042   ;; mnemonic: deuglif*Y*
2043   "u" gnus-article-outlook-unwrap-lines
2044   "a" gnus-article-outlook-repair-attribution
2045   "c" gnus-article-outlook-rearrange-citation
2046   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2047
2048 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2049   "a" gnus-article-hide
2050   "h" gnus-article-hide-headers
2051   "b" gnus-article-hide-boring-headers
2052   "s" gnus-article-hide-signature
2053   "c" gnus-article-hide-citation
2054   "C" gnus-article-hide-citation-in-followups
2055   "l" gnus-article-hide-list-identifiers
2056   "B" gnus-article-strip-banner
2057   "P" gnus-article-hide-pem
2058   "\C-c" gnus-article-hide-citation-maybe)
2059
2060 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2061   "a" gnus-article-highlight
2062   "h" gnus-article-highlight-headers
2063   "c" gnus-article-highlight-citation
2064   "s" gnus-article-highlight-signature)
2065
2066 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2067   "f" gnus-article-treat-fold-headers
2068   "u" gnus-article-treat-unfold-headers
2069   "n" gnus-article-treat-fold-newsgroups)
2070
2071 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2072   "x" gnus-article-display-x-face
2073   "d" gnus-article-display-face
2074   "s" gnus-treat-smiley
2075   "D" gnus-article-remove-images
2076   "f" gnus-treat-from-picon
2077   "m" gnus-treat-mail-picon
2078   "n" gnus-treat-newsgroups-picon)
2079
2080 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2081   "w" gnus-article-decode-mime-words
2082   "c" gnus-article-decode-charset
2083   "v" gnus-mime-view-all-parts
2084   "b" gnus-article-view-part)
2085
2086 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2087   "z" gnus-article-date-ut
2088   "u" gnus-article-date-ut
2089   "l" gnus-article-date-local
2090   "p" gnus-article-date-english
2091   "e" gnus-article-date-lapsed
2092   "o" gnus-article-date-original
2093   "i" gnus-article-date-iso8601
2094   "s" gnus-article-date-user)
2095
2096 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2097   "t" gnus-article-remove-trailing-blank-lines
2098   "l" gnus-article-strip-leading-blank-lines
2099   "m" gnus-article-strip-multiple-blank-lines
2100   "a" gnus-article-strip-blank-lines
2101   "A" gnus-article-strip-all-blank-lines
2102   "s" gnus-article-strip-leading-space
2103   "e" gnus-article-strip-trailing-space
2104   "w" gnus-article-remove-leading-whitespace)
2105
2106 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2107   "v" gnus-version
2108   "f" gnus-summary-fetch-faq
2109   "d" gnus-summary-describe-group
2110   "h" gnus-summary-describe-briefly
2111   "i" gnus-info-find-node
2112   "c" gnus-group-fetch-charter
2113   "C" gnus-group-fetch-control)
2114
2115 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2116   "e" gnus-summary-expire-articles
2117   "\M-\C-e" gnus-summary-expire-articles-now
2118   "\177" gnus-summary-delete-article
2119   [delete] gnus-summary-delete-article
2120   [backspace] gnus-summary-delete-article
2121   "m" gnus-summary-move-article
2122   "r" gnus-summary-respool-article
2123   "w" gnus-summary-edit-article
2124   "c" gnus-summary-copy-article
2125   "B" gnus-summary-crosspost-article
2126   "q" gnus-summary-respool-query
2127   "t" gnus-summary-respool-trace
2128   "i" gnus-summary-import-article
2129   "I" gnus-summary-create-article
2130   "p" gnus-summary-article-posted-p)
2131
2132 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2133   "o" gnus-summary-save-article
2134   "m" gnus-summary-save-article-mail
2135   "F" gnus-summary-write-article-file
2136   "r" gnus-summary-save-article-rmail
2137   "f" gnus-summary-save-article-file
2138   "b" gnus-summary-save-article-body-file
2139   "B" gnus-summary-write-article-body-file
2140   "h" gnus-summary-save-article-folder
2141   "v" gnus-summary-save-article-vm
2142   "p" gnus-summary-pipe-output
2143   "P" gnus-summary-muttprint
2144   "s" gnus-soup-add-article)
2145
2146 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2147   "b" gnus-summary-display-buttonized
2148   "m" gnus-summary-repair-multipart
2149   "v" gnus-article-view-part
2150   "o" gnus-article-save-part
2151   "O" gnus-article-save-part-and-strip
2152   "r" gnus-article-replace-part
2153   "d" gnus-article-delete-part
2154   "t" gnus-article-view-part-as-type
2155   "j" gnus-article-jump-to-part
2156   "c" gnus-article-copy-part
2157   "C" gnus-article-view-part-as-charset
2158   "e" gnus-article-view-part-externally
2159   "H" gnus-article-browse-html-article
2160   "E" gnus-article-encrypt-body
2161   "i" gnus-article-inline-part
2162   "|" gnus-article-pipe-part)
2163
2164 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2165   "p" gnus-summary-mark-as-processable
2166   "u" gnus-summary-unmark-as-processable
2167   "U" gnus-summary-unmark-all-processable
2168   "v" gnus-uu-mark-over
2169   "s" gnus-uu-mark-series
2170   "r" gnus-uu-mark-region
2171   "g" gnus-uu-unmark-region
2172   "R" gnus-uu-mark-by-regexp
2173   "G" gnus-uu-unmark-by-regexp
2174   "t" gnus-uu-mark-thread
2175   "T" gnus-uu-unmark-thread
2176   "a" gnus-uu-mark-all
2177   "b" gnus-uu-mark-buffer
2178   "S" gnus-uu-mark-sparse
2179   "k" gnus-summary-kill-process-mark
2180   "y" gnus-summary-yank-process-mark
2181   "w" gnus-summary-save-process-mark
2182   "i" gnus-uu-invert-processable)
2183
2184 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2185   ;;"x" gnus-uu-extract-any
2186   "m" gnus-summary-save-parts
2187   "u" gnus-uu-decode-uu
2188   "U" gnus-uu-decode-uu-and-save
2189   "s" gnus-uu-decode-unshar
2190   "S" gnus-uu-decode-unshar-and-save
2191   "o" gnus-uu-decode-save
2192   "O" gnus-uu-decode-save
2193   "b" gnus-uu-decode-binhex
2194   "B" gnus-uu-decode-binhex
2195   "p" gnus-uu-decode-postscript
2196   "P" gnus-uu-decode-postscript-and-save)
2197
2198 (gnus-define-keys
2199     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2200   "u" gnus-uu-decode-uu-view
2201   "U" gnus-uu-decode-uu-and-save-view
2202   "s" gnus-uu-decode-unshar-view
2203   "S" gnus-uu-decode-unshar-and-save-view
2204   "o" gnus-uu-decode-save-view
2205   "O" gnus-uu-decode-save-view
2206   "b" gnus-uu-decode-binhex-view
2207   "B" gnus-uu-decode-binhex-view
2208   "p" gnus-uu-decode-postscript-view
2209   "P" gnus-uu-decode-postscript-and-save-view)
2210
2211 (defvar gnus-article-post-menu nil)
2212
2213 (defconst gnus-summary-menu-maxlen 20)
2214
2215 (defun gnus-summary-menu-split (menu)
2216   ;; If we have lots of elements, divide them into groups of 20
2217   ;; and make a pane (or submenu) for each one.
2218   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2219       (let ((menu menu) sublists next
2220             (i 1))
2221         (while menu
2222           ;; Pull off the next gnus-summary-menu-maxlen elements
2223           ;; and make them the next element of sublist.
2224           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2225           (if next
2226               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2227                       nil))
2228           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2229                                              (aref (car (last menu)) 0)) menu)
2230                                sublists))
2231           (setq i (1+ i))
2232           (setq menu next))
2233         (nreverse sublists))
2234     ;; Few elements--put them all in one pane.
2235     menu))
2236
2237 (defun gnus-summary-make-menu-bar ()
2238   (gnus-turn-off-edit-menu 'summary)
2239
2240   (unless (boundp 'gnus-summary-misc-menu)
2241
2242     (easy-menu-define
2243       gnus-summary-kill-menu gnus-summary-mode-map ""
2244       (cons
2245        "Score"
2246        (nconc
2247         (list
2248          ["Customize" gnus-score-customize t])
2249         (gnus-make-score-map 'increase)
2250         (gnus-make-score-map 'lower)
2251         '(("Mark"
2252            ["Kill below" gnus-summary-kill-below t]
2253            ["Mark above" gnus-summary-mark-above t]
2254            ["Tick above" gnus-summary-tick-above t]
2255            ["Clear above" gnus-summary-clear-above t])
2256           ["Current score" gnus-summary-current-score t]
2257           ["Set score" gnus-summary-set-score t]
2258           ["Switch current score file..." gnus-score-change-score-file t]
2259           ["Set mark below..." gnus-score-set-mark-below t]
2260           ["Set expunge below..." gnus-score-set-expunge-below t]
2261           ["Edit current score file" gnus-score-edit-current-scores t]
2262           ["Edit score file" gnus-score-edit-file t]
2263           ["Trace score" gnus-score-find-trace t]
2264           ["Find words" gnus-score-find-favourite-words t]
2265           ["Rescore buffer" gnus-summary-rescore t]
2266           ["Increase score..." gnus-summary-increase-score t]
2267           ["Lower score..." gnus-summary-lower-score t]))))
2268
2269     ;; Define both the Article menu in the summary buffer and the
2270     ;; equivalent Commands menu in the article buffer here for
2271     ;; consistency.
2272     (let ((innards
2273            `(("Hide"
2274               ["All" gnus-article-hide t]
2275               ["Headers" gnus-article-hide-headers t]
2276               ["Signature" gnus-article-hide-signature t]
2277               ["Citation" gnus-article-hide-citation t]
2278               ["List identifiers" gnus-article-hide-list-identifiers t]
2279               ["Banner" gnus-article-strip-banner t]
2280               ["Boring headers" gnus-article-hide-boring-headers t])
2281              ("Highlight"
2282               ["All" gnus-article-highlight t]
2283               ["Headers" gnus-article-highlight-headers t]
2284               ["Signature" gnus-article-highlight-signature t]
2285               ["Citation" gnus-article-highlight-citation t])
2286              ("MIME"
2287               ["Words" gnus-article-decode-mime-words t]
2288               ["Charset" gnus-article-decode-charset t]
2289               ["QP" gnus-article-de-quoted-unreadable t]
2290               ["Base64" gnus-article-de-base64-unreadable t]
2291               ["View MIME buttons" gnus-summary-display-buttonized t]
2292               ["View all" gnus-mime-view-all-parts t]
2293               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2294               ["Encrypt body" gnus-article-encrypt-body
2295                :active (not (gnus-group-read-only-p))
2296                ,@(if (featurep 'xemacs) nil
2297                    '(:help "Encrypt the message body on disk"))]
2298               ["Extract all parts..." gnus-summary-save-parts t]
2299               ("Multipart"
2300                ["Repair multipart" gnus-summary-repair-multipart t]
2301                ["Pipe part..." gnus-article-pipe-part t]
2302                ["Inline part" gnus-article-inline-part t]
2303                ["View part as type..." gnus-article-view-part-as-type t]
2304                ["Encrypt body" gnus-article-encrypt-body
2305                 :active (not (gnus-group-read-only-p))
2306                ,@(if (featurep 'xemacs) nil
2307                    '(:help "Encrypt the message body on disk"))]
2308                ["View part externally" gnus-article-view-part-externally t]
2309                ["View HTML parts in browser" gnus-article-browse-html-article t]
2310                ["View part with charset..." gnus-article-view-part-as-charset t]
2311                ["Copy part" gnus-article-copy-part t]
2312                ["Save part..." gnus-article-save-part t]
2313                ["View part" gnus-article-view-part t]))
2314              ("Date"
2315               ["Local" gnus-article-date-local t]
2316               ["ISO8601" gnus-article-date-iso8601 t]
2317               ["UT" gnus-article-date-ut t]
2318               ["Original" gnus-article-date-original t]
2319               ["Lapsed" gnus-article-date-lapsed t]
2320               ["User-defined" gnus-article-date-user t])
2321              ("Display"
2322               ["Remove images" gnus-article-remove-images t]
2323               ["Toggle smiley" gnus-treat-smiley t]
2324               ["Show X-Face" gnus-article-display-x-face t]
2325               ["Show picons in From" gnus-treat-from-picon t]
2326               ["Show picons in mail headers" gnus-treat-mail-picon t]
2327               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2328               ("View as different encoding"
2329                ,@(gnus-summary-menu-split
2330                   (mapcar
2331                    (lambda (cs)
2332                      ;; Since easymenu under Emacs doesn't allow
2333                      ;; lambda forms for menu commands, we should
2334                      ;; provide intern'ed function symbols.
2335                      (let ((command (intern (format "\
2336 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2337                        (fset command
2338                              `(lambda ()
2339                                 (interactive)
2340                                 (let ((gnus-summary-show-article-charset-alist
2341                                        '((1 . ,cs))))
2342                                   (gnus-summary-show-article 1))))
2343                        `[,(symbol-name cs) ,command t]))
2344                    (sort (if (fboundp 'coding-system-list)
2345                              (coding-system-list)
2346                            (mapcar 'car mm-mime-mule-charset-alist))
2347                          'string<)))))
2348              ("Washing"
2349               ("Remove Blanks"
2350                ["Leading" gnus-article-strip-leading-blank-lines t]
2351                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2352                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2353                ["All of the above" gnus-article-strip-blank-lines t]
2354                ["All" gnus-article-strip-all-blank-lines t]
2355                ["Leading space" gnus-article-strip-leading-space t]
2356                ["Trailing space" gnus-article-strip-trailing-space t]
2357                ["Leading space in headers"
2358                 gnus-article-remove-leading-whitespace t])
2359               ["Overstrike" gnus-article-treat-overstrike t]
2360               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2361               ["Emphasis" gnus-article-emphasize t]
2362               ["Word wrap" gnus-article-fill-cited-article t]
2363               ["Fill long lines" gnus-article-fill-long-lines t]
2364               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2365               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2366               ["Remove CR" gnus-article-remove-cr t]
2367               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2368               ["Base64" gnus-article-de-base64-unreadable t]
2369               ["Rot 13" gnus-summary-caesar-message
2370                ,@(if (featurep 'xemacs) '(t)
2371                    '(:help "\"Caesar rotate\" article by 13"))]
2372               ["De-IDNA" gnus-summary-idna-message t]
2373               ["Morse decode" gnus-summary-morse-message t]
2374               ["Unix pipe..." gnus-summary-pipe-message t]
2375               ["Add buttons" gnus-article-add-buttons t]
2376               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2377               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2378               ["Verbose header" gnus-summary-verbose-headers t]
2379               ["Toggle header" gnus-summary-toggle-header t]
2380               ["Unfold headers" gnus-article-treat-unfold-headers t]
2381               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2382               ["Html" gnus-article-wash-html t]
2383               ["Unsplit URLs" gnus-article-unsplit-urls t]
2384               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2385               ["Decode HZ" gnus-article-decode-HZ t]
2386               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2387               ("(Outlook) Deuglify"
2388                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2389                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2390                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2391                ["Full (Outlook) deuglify"
2392                 gnus-article-outlook-deuglify-article t])
2393               )
2394              ("Output"
2395               ["Save in default format..." gnus-summary-save-article
2396                ,@(if (featurep 'xemacs) '(t)
2397                    '(:help "Save article using default method"))]
2398               ["Save in file..." gnus-summary-save-article-file
2399                ,@(if (featurep 'xemacs) '(t)
2400                    '(:help "Save article in file"))]
2401               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2402               ["Save in MH folder..." gnus-summary-save-article-folder t]
2403               ["Save in VM folder..." gnus-summary-save-article-vm t]
2404               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2405               ["Save body in file..." gnus-summary-save-article-body-file t]
2406               ["Pipe through a filter..." gnus-summary-pipe-output t]
2407               ["Add to SOUP packet" gnus-soup-add-article t]
2408               ["Print with Muttprint..." gnus-summary-muttprint t]
2409               ["Print" gnus-summary-print-article
2410                ,@(if (featurep 'xemacs) '(t)
2411                    '(:help "Generate and print a PostScript image"))])
2412              ("Copy, move,... (Backend)"
2413               ,@(if (featurep 'xemacs) nil
2414                   '(:help "Copying, moving, expiring articles..."))
2415               ["Respool article..." gnus-summary-respool-article t]
2416               ["Move article..." gnus-summary-move-article
2417                (gnus-check-backend-function
2418                 'request-move-article gnus-newsgroup-name)]
2419               ["Copy article..." gnus-summary-copy-article t]
2420               ["Crosspost article..." gnus-summary-crosspost-article
2421                (gnus-check-backend-function
2422                 'request-replace-article gnus-newsgroup-name)]
2423               ["Import file..." gnus-summary-import-article
2424                (gnus-check-backend-function
2425                 'request-accept-article gnus-newsgroup-name)]
2426               ["Create article..." gnus-summary-create-article
2427                (gnus-check-backend-function
2428                 'request-accept-article gnus-newsgroup-name)]
2429               ["Check if posted" gnus-summary-article-posted-p t]
2430               ["Edit article" gnus-summary-edit-article
2431                (not (gnus-group-read-only-p))]
2432               ["Delete article" gnus-summary-delete-article
2433                (gnus-check-backend-function
2434                 'request-expire-articles gnus-newsgroup-name)]
2435               ["Query respool" gnus-summary-respool-query t]
2436               ["Trace respool" gnus-summary-respool-trace t]
2437               ["Delete expirable articles" gnus-summary-expire-articles-now
2438                (gnus-check-backend-function
2439                 'request-expire-articles gnus-newsgroup-name)])
2440              ("Extract"
2441               ["Uudecode" gnus-uu-decode-uu
2442                ,@(if (featurep 'xemacs) '(t)
2443                    '(:help "Decode uuencoded article(s)"))]
2444               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2445               ["Unshar" gnus-uu-decode-unshar t]
2446               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2447               ["Save" gnus-uu-decode-save t]
2448               ["Binhex" gnus-uu-decode-binhex t]
2449               ["Postscript" gnus-uu-decode-postscript t]
2450               ["All MIME parts" gnus-summary-save-parts t])
2451              ("Cache"
2452               ["Enter article" gnus-cache-enter-article t]
2453               ["Remove article" gnus-cache-remove-article t])
2454              ["Translate" gnus-article-babel t]
2455              ["Select article buffer" gnus-summary-select-article-buffer t]
2456              ["Make article buffer sticky" gnus-sticky-article t]
2457              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2458              ["Isearch article..." gnus-summary-isearch-article t]
2459              ["Beginning of the article" gnus-summary-beginning-of-article t]
2460              ["End of the article" gnus-summary-end-of-article t]
2461              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2462              ["Fetch referenced articles" gnus-summary-refer-references t]
2463              ["Fetch current thread" gnus-summary-refer-thread t]
2464              ["Fetch article with id..." gnus-summary-refer-article t]
2465              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2466              ["Redisplay" gnus-summary-show-article t]
2467              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2468       (easy-menu-define
2469         gnus-summary-article-menu gnus-summary-mode-map ""
2470         (cons "Article" innards))
2471
2472       (if (not (keymapp gnus-summary-article-menu))
2473           (easy-menu-define
2474             gnus-article-commands-menu gnus-article-mode-map ""
2475             (cons "Commands" innards))
2476         ;; in Emacs, don't share menu.
2477         (setq gnus-article-commands-menu
2478               (copy-keymap gnus-summary-article-menu))
2479         (define-key gnus-article-mode-map [menu-bar commands]
2480           (cons "Commands" gnus-article-commands-menu))))
2481
2482     (easy-menu-define
2483       gnus-summary-thread-menu gnus-summary-mode-map ""
2484       '("Threads"
2485         ["Find all messages in thread" gnus-summary-refer-thread t]
2486         ["Toggle threading" gnus-summary-toggle-threads t]
2487         ["Hide threads" gnus-summary-hide-all-threads t]
2488         ["Show threads" gnus-summary-show-all-threads t]
2489         ["Hide thread" gnus-summary-hide-thread t]
2490         ["Show thread" gnus-summary-show-thread t]
2491         ["Go to next thread" gnus-summary-next-thread t]
2492         ["Go to previous thread" gnus-summary-prev-thread t]
2493         ["Go down thread" gnus-summary-down-thread t]
2494         ["Go up thread" gnus-summary-up-thread t]
2495         ["Top of thread" gnus-summary-top-thread t]
2496         ["Mark thread as read" gnus-summary-kill-thread t]
2497         ["Mark thread as expired" gnus-summary-expire-thread t]
2498         ["Lower thread score" gnus-summary-lower-thread t]
2499         ["Raise thread score" gnus-summary-raise-thread t]
2500         ["Rethread current" gnus-summary-rethread-current t]))
2501
2502     (easy-menu-define
2503       gnus-summary-post-menu gnus-summary-mode-map ""
2504       `("Post"
2505         ["Send a message (mail or news)" gnus-summary-post-news
2506          ,@(if (featurep 'xemacs) '(t)
2507              '(:help "Compose a new message (mail or news)"))]
2508         ["Followup" gnus-summary-followup
2509          ,@(if (featurep 'xemacs) '(t)
2510              '(:help "Post followup to this article"))]
2511         ["Followup and yank" gnus-summary-followup-with-original
2512          ,@(if (featurep 'xemacs) '(t)
2513              '(:help "Post followup to this article, quoting its contents"))]
2514         ["Supersede article" gnus-summary-supersede-article t]
2515         ["Cancel article" gnus-summary-cancel-article
2516          ,@(if (featurep 'xemacs) '(t)
2517              '(:help "Cancel an article you posted"))]
2518         ["Reply" gnus-summary-reply t]
2519         ["Reply and yank" gnus-summary-reply-with-original t]
2520         ["Wide reply" gnus-summary-wide-reply t]
2521         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2522          ,@(if (featurep 'xemacs) '(t)
2523              '(:help "Mail a reply, quoting this article"))]
2524         ["Very wide reply" gnus-summary-very-wide-reply t]
2525         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2526          ,@(if (featurep 'xemacs) '(t)
2527              '(:help "Mail a very wide reply, quoting this article"))]
2528         ["Mail forward" gnus-summary-mail-forward t]
2529         ["Post forward" gnus-summary-post-forward t]
2530         ["Digest and mail" gnus-uu-digest-mail-forward t]
2531         ["Digest and post" gnus-uu-digest-post-forward t]
2532         ["Resend message" gnus-summary-resend-message t]
2533         ["Resend message edit" gnus-summary-resend-message-edit t]
2534         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2535         ["Send a mail" gnus-summary-mail-other-window t]
2536         ["Create a local message" gnus-summary-news-other-window t]
2537         ["Uuencode and post" gnus-uu-post-news
2538          ,@(if (featurep 'xemacs) '(t)
2539              '(:help "Post a uuencoded article"))]
2540         ["Followup via news" gnus-summary-followup-to-mail t]
2541         ["Followup via news and yank"
2542          gnus-summary-followup-to-mail-with-original t]
2543         ;;("Draft"
2544         ;;["Send" gnus-summary-send-draft t]
2545         ;;["Send bounced" gnus-resend-bounced-mail t])
2546         ))
2547
2548     (cond
2549      ((not (keymapp gnus-summary-post-menu))
2550       (setq gnus-article-post-menu gnus-summary-post-menu))
2551      ((not gnus-article-post-menu)
2552       ;; Don't share post menu.
2553       (setq gnus-article-post-menu
2554             (copy-keymap gnus-summary-post-menu))))
2555     (define-key gnus-article-mode-map [menu-bar post]
2556       (cons "Post" gnus-article-post-menu))
2557
2558     (easy-menu-define
2559       gnus-summary-misc-menu gnus-summary-mode-map ""
2560       `("Gnus"
2561         ("Mark Read"
2562          ["Mark as read" gnus-summary-mark-as-read-forward t]
2563          ["Mark same subject and select"
2564           gnus-summary-kill-same-subject-and-select t]
2565          ["Mark same subject" gnus-summary-kill-same-subject t]
2566          ["Catchup" gnus-summary-catchup
2567           ,@(if (featurep 'xemacs) '(t)
2568               '(:help "Mark unread articles in this group as read"))]
2569          ["Catchup all" gnus-summary-catchup-all t]
2570          ["Catchup to here" gnus-summary-catchup-to-here t]
2571          ["Catchup from here" gnus-summary-catchup-from-here t]
2572          ["Catchup region" gnus-summary-mark-region-as-read
2573           (gnus-mark-active-p)]
2574          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2575         ("Mark Various"
2576          ["Tick" gnus-summary-tick-article-forward t]
2577          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2578          ["Remove marks" gnus-summary-clear-mark-forward t]
2579          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2580          ["Set bookmark" gnus-summary-set-bookmark t]
2581          ["Remove bookmark" gnus-summary-remove-bookmark t])
2582         ("Limit to"
2583          ["Marks..." gnus-summary-limit-to-marks t]
2584          ["Subject..." gnus-summary-limit-to-subject t]
2585          ["Author..." gnus-summary-limit-to-author t]
2586          ["Recipient..." gnus-summary-limit-to-recipient t]
2587          ["Address..." gnus-summary-limit-to-address t]
2588          ["Age..." gnus-summary-limit-to-age t]
2589          ["Extra..." gnus-summary-limit-to-extra t]
2590          ["Score..." gnus-summary-limit-to-score t]
2591          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2592          ["Unread" gnus-summary-limit-to-unread t]
2593          ["Unseen" gnus-summary-limit-to-unseen t]
2594          ["Singletons" gnus-summary-limit-to-singletons t]
2595          ["Replied" gnus-summary-limit-to-replied t]
2596          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2597          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2598          ["Pop limit" gnus-summary-pop-limit t]
2599          ["Show dormant" gnus-summary-limit-include-dormant t]
2600          ["Hide childless dormant"
2601           gnus-summary-limit-exclude-childless-dormant t]
2602          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2603          ["Hide marked" gnus-summary-limit-exclude-marks t]
2604          ["Show expunged" gnus-summary-limit-include-expunged t])
2605         ("Process Mark"
2606          ["Set mark" gnus-summary-mark-as-processable t]
2607          ["Remove mark" gnus-summary-unmark-as-processable t]
2608          ["Remove all marks" gnus-summary-unmark-all-processable t]
2609          ["Invert marks" gnus-uu-invert-processable t]
2610          ["Mark above" gnus-uu-mark-over t]
2611          ["Mark series" gnus-uu-mark-series t]
2612          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2613          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2614          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2615          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2616          ["Mark all" gnus-uu-mark-all t]
2617          ["Mark buffer" gnus-uu-mark-buffer t]
2618          ["Mark sparse" gnus-uu-mark-sparse t]
2619          ["Mark thread" gnus-uu-mark-thread t]
2620          ["Unmark thread" gnus-uu-unmark-thread t]
2621          ("Process Mark Sets"
2622           ["Kill" gnus-summary-kill-process-mark t]
2623           ["Yank" gnus-summary-yank-process-mark
2624            gnus-newsgroup-process-stack]
2625           ["Save" gnus-summary-save-process-mark t]
2626           ["Run command on marked..." gnus-summary-universal-argument t]))
2627         ("Scroll article"
2628          ["Page forward" gnus-summary-next-page
2629           ,@(if (featurep 'xemacs) '(t)
2630               '(:help "Show next page of article"))]
2631          ["Page backward" gnus-summary-prev-page
2632           ,@(if (featurep 'xemacs) '(t)
2633               '(:help "Show previous page of article"))]
2634          ["Line forward" gnus-summary-scroll-up t])
2635         ("Move"
2636          ["Next unread article" gnus-summary-next-unread-article t]
2637          ["Previous unread article" gnus-summary-prev-unread-article t]
2638          ["Next article" gnus-summary-next-article t]
2639          ["Previous article" gnus-summary-prev-article t]
2640          ["Next unread subject" gnus-summary-next-unread-subject t]
2641          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2642          ["Next article same subject" gnus-summary-next-same-subject t]
2643          ["Previous article same subject" gnus-summary-prev-same-subject t]
2644          ["First unread article" gnus-summary-first-unread-article t]
2645          ["Best unread article" gnus-summary-best-unread-article t]
2646          ["Go to subject number..." gnus-summary-goto-subject t]
2647          ["Go to article number..." gnus-summary-goto-article t]
2648          ["Go to the last article" gnus-summary-goto-last-article t]
2649          ["Pop article off history" gnus-summary-pop-article t])
2650         ("Sort"
2651          ["Sort by number" gnus-summary-sort-by-number t]
2652          ["Sort by author" gnus-summary-sort-by-author t]
2653          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2654          ["Sort by subject" gnus-summary-sort-by-subject t]
2655          ["Sort by date" gnus-summary-sort-by-date t]
2656          ["Sort by score" gnus-summary-sort-by-score t]
2657          ["Sort by lines" gnus-summary-sort-by-lines t]
2658          ["Sort by characters" gnus-summary-sort-by-chars t]
2659          ["Randomize" gnus-summary-sort-by-random t]
2660          ["Original sort" gnus-summary-sort-by-original t])
2661         ("Help"
2662          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2663          ["Describe group" gnus-summary-describe-group t]
2664          ["Fetch charter" gnus-group-fetch-charter
2665           ,@(if (featurep 'xemacs) nil
2666               '(:help "Display the charter of the current group"))]
2667          ["Fetch control message" gnus-group-fetch-control
2668           ,@(if (featurep 'xemacs) nil
2669               '(:help "Display the archived control message for the current group"))]
2670          ["Read manual" gnus-info-find-node t])
2671         ("Modes"
2672          ["Pick and read" gnus-pick-mode t]
2673          ["Binary" gnus-binary-mode t])
2674         ("Regeneration"
2675          ["Regenerate" gnus-summary-prepare t]
2676          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2677          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2678          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2679          ["Toggle threading" gnus-summary-toggle-threads t])
2680         ["See old articles" gnus-summary-insert-old-articles t]
2681         ["See new articles" gnus-summary-insert-new-articles t]
2682         ["Filter articles..." gnus-summary-execute-command t]
2683         ["Run command on articles..." gnus-summary-universal-argument t]
2684         ["Search articles forward..." gnus-summary-search-article-forward t]
2685         ["Search articles backward..." gnus-summary-search-article-backward t]
2686         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2687         ["Expand window" gnus-summary-expand-window t]
2688         ["Expire expirable articles" gnus-summary-expire-articles
2689          (gnus-check-backend-function
2690           'request-expire-articles gnus-newsgroup-name)]
2691         ["Edit local kill file" gnus-summary-edit-local-kill t]
2692         ["Edit main kill file" gnus-summary-edit-global-kill t]
2693         ["Edit group parameters" gnus-summary-edit-parameters t]
2694         ["Customize group parameters" gnus-summary-customize-parameters t]
2695         ["Send a bug report" gnus-bug t]
2696         ("Exit"
2697          ["Catchup and exit" gnus-summary-catchup-and-exit
2698           ,@(if (featurep 'xemacs) '(t)
2699               '(:help "Mark unread articles in this group as read, then exit"))]
2700          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2701          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2702          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2703          ["Exit group" gnus-summary-exit
2704           ,@(if (featurep 'xemacs) '(t)
2705               '(:help "Exit current group, return to group selection mode"))]
2706          ["Exit group without updating" gnus-summary-exit-no-update t]
2707          ["Exit and goto next group" gnus-summary-next-group t]
2708          ["Exit and goto prev group" gnus-summary-prev-group t]
2709          ["Reselect group" gnus-summary-reselect-current-group t]
2710          ["Rescan group" gnus-summary-rescan-group t]
2711          ["Update dribble" gnus-summary-save-newsrc t])))
2712
2713     (gnus-run-hooks 'gnus-summary-menu-hook)))
2714
2715 (defvar gnus-summary-tool-bar-map nil)
2716
2717 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2718 ;; affect _new_ message buffers.  We might add a function that walks thru all
2719 ;; summary-mode buffers and force the update.
2720 (defun gnus-summary-tool-bar-update (&optional symbol value)
2721   "Update summary mode toolbar.
2722 Setter function for custom variables."
2723   (setq-default gnus-summary-tool-bar-map nil)
2724   (when symbol
2725     ;; When used as ":set" function:
2726     (set-default symbol value))
2727   (when (gnus-buffer-live-p gnus-summary-buffer)
2728     (with-current-buffer gnus-summary-buffer
2729       (gnus-summary-make-tool-bar))))
2730
2731 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2732                                      'gnus-summary-tool-bar-gnome
2733                                    'gnus-summary-tool-bar-retro)
2734   "Specifies the Gnus summary tool bar.
2735
2736 It can be either a list or a symbol refering to a list.  See
2737 `gmm-tool-bar-from-list' for the format of the list.  The
2738 default key map is `gnus-summary-mode-map'.
2739
2740 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2741 `gnus-summary-tool-bar-retro'."
2742   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2743                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2744                  (repeat :tag "User defined list" gmm-tool-bar-item)
2745                  (symbol))
2746   :version "23.0" ;; No Gnus
2747   :initialize 'custom-initialize-default
2748   :set 'gnus-summary-tool-bar-update
2749   :group 'gnus-summary)
2750
2751 (defcustom gnus-summary-tool-bar-gnome
2752   '((gnus-summary-post-news "mail/compose" nil)
2753     (gnus-summary-insert-new-articles "mail/inbox" nil
2754                                       :visible (or (not gnus-agent)
2755                                                    gnus-plugged))
2756     (gnus-summary-reply-with-original "mail/reply")
2757     (gnus-summary-reply "mail/reply" nil :visible nil)
2758     (gnus-summary-followup-with-original "mail/reply-all")
2759     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2760     (gnus-summary-mail-forward "mail/forward")
2761     (gnus-summary-save-article "mail/save")
2762     (gnus-summary-search-article-forward "search" nil :visible nil)
2763     (gnus-summary-print-article "print")
2764     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2765     ;; Some new commands that may need more suitable icons:
2766     (gnus-summary-save-newsrc "save" nil :visible nil)
2767     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2768     (gnus-summary-prev-article "left-arrow")
2769     (gnus-summary-next-article "right-arrow")
2770     (gnus-summary-next-page "next-page")
2771     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2772     ;;
2773     ;; Maybe some sort-by-... could be added:
2774     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2775     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2776     (gnus-summary-mark-as-expirable
2777      "delete" nil
2778      :visible (gnus-check-backend-function 'request-expire-articles
2779                                            gnus-newsgroup-name))
2780     (gnus-summary-mark-as-spam
2781      "mail/spam" t
2782      :visible (and (fboundp 'spam-group-ham-contents-p)
2783                    (spam-group-ham-contents-p gnus-newsgroup-name))
2784      :help "Mark as spam")
2785     (gnus-summary-mark-as-read-forward
2786      "mail/not-spam" nil
2787      :visible (and (fboundp 'spam-group-spam-contents-p)
2788                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2789     ;;
2790     (gnus-summary-exit "exit")
2791     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2792     (gnus-info-find-node "help"))
2793   "List of functions for the summary tool bar (GNOME style).
2794
2795 See `gmm-tool-bar-from-list' for the format of the list."
2796   :type '(repeat gmm-tool-bar-item)
2797   :version "23.0" ;; No Gnus
2798   :initialize 'custom-initialize-default
2799   :set 'gnus-summary-tool-bar-update
2800   :group 'gnus-summary)
2801
2802 (defcustom gnus-summary-tool-bar-retro
2803   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2804     (gnus-summary-next-unread-article "gnus/next-ur")
2805     (gnus-summary-post-news "gnus/post")
2806     (gnus-summary-followup-with-original "gnus/fuwo")
2807     (gnus-summary-followup "gnus/followup")
2808     (gnus-summary-reply-with-original "gnus/reply-wo")
2809     (gnus-summary-reply "gnus/reply")
2810     (gnus-summary-caesar-message "gnus/rot13")
2811     (gnus-uu-decode-uu "gnus/uu-decode")
2812     (gnus-summary-save-article-file "gnus/save-aif")
2813     (gnus-summary-save-article "gnus/save-art")
2814     (gnus-uu-post-news "gnus/uu-post")
2815     (gnus-summary-catchup "gnus/catchup")
2816     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2817     (gnus-summary-exit "gnus/exit-summ")
2818     ;; Some new command that may need more suitable icons:
2819     (gnus-summary-print-article "gnus/print" nil :visible nil)
2820     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2821     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2822     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2823     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2824     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2825     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2826     ;;
2827     (gnus-info-find-node "gnus/help" nil :visible nil))
2828   "List of functions for the summary tool bar (retro look).
2829
2830 See `gmm-tool-bar-from-list' for the format of the list."
2831   :type '(repeat gmm-tool-bar-item)
2832   :version "23.0" ;; No Gnus
2833   :initialize 'custom-initialize-default
2834   :set 'gnus-summary-tool-bar-update
2835   :group 'gnus-summary)
2836
2837 (defcustom gnus-summary-tool-bar-zap-list t
2838   "List of icon items from the global tool bar.
2839 These items are not displayed in the Gnus summary mode tool bar.
2840
2841 See `gmm-tool-bar-from-list' for the format of the list."
2842   :type 'gmm-tool-bar-zap-list
2843   :version "23.0" ;; No Gnus
2844   :initialize 'custom-initialize-default
2845   :set 'gnus-summary-tool-bar-update
2846   :group 'gnus-summary)
2847
2848 (defvar image-load-path)
2849
2850 (defun gnus-summary-make-tool-bar (&optional force)
2851   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2852 When FORCE, rebuild the tool bar."
2853   (when (and (not (featurep 'xemacs))
2854              (boundp 'tool-bar-mode)
2855              tool-bar-mode
2856              (or (not gnus-summary-tool-bar-map) force))
2857     (let* ((load-path
2858             (gmm-image-load-path-for-library "gnus"
2859                                              "mail/save.xpm"
2860                                              nil t))
2861            (image-load-path (cons (car load-path)
2862                                   (when (boundp 'image-load-path)
2863                                     image-load-path)))
2864            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2865                                         gnus-summary-tool-bar-zap-list
2866                                         'gnus-summary-mode-map)))
2867       (when map
2868         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2869         ;; uses it's value.
2870         (setq gnus-summary-tool-bar-map map))))
2871   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2872
2873 (defun gnus-score-set-default (var value)
2874   "A version of set that updates the GNU Emacs menu-bar."
2875   (set var value)
2876   ;; It is the message that forces the active status to be updated.
2877   (message ""))
2878
2879 (defun gnus-make-score-map (type)
2880   "Make a summary score map of type TYPE."
2881   (if t
2882       nil
2883     (let ((headers '(("author" "from" string)
2884                      ("subject" "subject" string)
2885                      ("article body" "body" string)
2886                      ("article head" "head" string)
2887                      ("xref" "xref" string)
2888                      ("extra header" "extra" string)
2889                      ("lines" "lines" number)
2890                      ("followups to author" "followup" string)))
2891           (types '((number ("less than" <)
2892                            ("greater than" >)
2893                            ("equal" =))
2894                    (string ("substring" s)
2895                            ("exact string" e)
2896                            ("fuzzy string" f)
2897                            ("regexp" r))))
2898           (perms '(("temporary" (current-time-string))
2899                    ("permanent" nil)
2900                    ("immediate" now)))
2901           header)
2902       (list
2903        (apply
2904         'nconc
2905         (list
2906          (if (eq type 'lower)
2907              "Lower score"
2908            "Increase score"))
2909         (let (outh)
2910           (while headers
2911             (setq header (car headers))
2912             (setq outh
2913                   (cons
2914                    (apply
2915                     'nconc
2916                     (list (car header))
2917                     (let ((ts (cdr (assoc (nth 2 header) types)))
2918                           outt)
2919                       (while ts
2920                         (setq outt
2921                               (cons
2922                                (apply
2923                                 'nconc
2924                                 (list (caar ts))
2925                                 (let ((ps perms)
2926                                       outp)
2927                                   (while ps
2928                                     (setq outp
2929                                           (cons
2930                                            (vector
2931                                             (caar ps)
2932                                             (list
2933                                              'gnus-summary-score-entry
2934                                              (nth 1 header)
2935                                              (if (or (string= (nth 1 header)
2936                                                               "head")
2937                                                      (string= (nth 1 header)
2938                                                               "body"))
2939                                                  ""
2940                                                (list 'gnus-summary-header
2941                                                      (nth 1 header)))
2942                                              (list 'quote (nth 1 (car ts)))
2943                                              (list 'gnus-score-delta-default
2944                                                    nil)
2945                                              (nth 1 (car ps))
2946                                              t)
2947                                             t)
2948                                            outp))
2949                                     (setq ps (cdr ps)))
2950                                   (list (nreverse outp))))
2951                                outt))
2952                         (setq ts (cdr ts)))
2953                       (list (nreverse outt))))
2954                    outh))
2955             (setq headers (cdr headers)))
2956           (list (nreverse outh))))))))
2957
2958 \f
2959
2960 (defun gnus-summary-mode (&optional group)
2961   "Major mode for reading articles.
2962
2963 All normal editing commands are switched off.
2964 \\<gnus-summary-mode-map>
2965 Each line in this buffer represents one article.  To read an
2966 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2967 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2968 respectively.
2969
2970 You can also post articles and send mail from this buffer.  To
2971 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2972 of an article, type `\\[gnus-summary-reply]'.
2973
2974 There are approx. one gazillion commands you can execute in this
2975 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2976
2977 The following commands are available:
2978
2979 \\{gnus-summary-mode-map}"
2980   (interactive)
2981   (kill-all-local-variables)
2982   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2983     (gnus-summary-make-local-variables))
2984   (gnus-summary-make-local-variables)
2985   (setq gnus-newsgroup-name group)
2986   (when (gnus-visual-p 'summary-menu 'menu)
2987     (gnus-summary-make-menu-bar)
2988     (gnus-summary-make-tool-bar))
2989   (gnus-make-thread-indent-array)
2990   (gnus-simplify-mode-line)
2991   (setq major-mode 'gnus-summary-mode)
2992   (setq mode-name "Summary")
2993   (make-local-variable 'minor-mode-alist)
2994   (use-local-map gnus-summary-mode-map)
2995   (buffer-disable-undo)
2996   (setq buffer-read-only t              ;Disable modification
2997         show-trailing-whitespace nil)
2998   (setq truncate-lines t)
2999   (setq selective-display t)
3000   (setq selective-display-ellipses t)   ;Display `...'
3001   (gnus-summary-set-display-table)
3002   (gnus-set-default-directory)
3003   (make-local-variable 'gnus-summary-line-format)
3004   (make-local-variable 'gnus-summary-line-format-spec)
3005   (make-local-variable 'gnus-summary-dummy-line-format)
3006   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3007   (make-local-variable 'gnus-summary-mark-positions)
3008   (gnus-make-local-hook 'pre-command-hook)
3009   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3010   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3011   (turn-on-gnus-mailing-list-mode)
3012   (mm-enable-multibyte)
3013   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3014   (gnus-update-summary-mark-positions))
3015
3016 (defun gnus-summary-make-local-variables ()
3017   "Make all the local summary buffer variables."
3018   (let (global)
3019     (dolist (local gnus-summary-local-variables)
3020       (if (consp local)
3021           (progn
3022             (if (eq (cdr local) 'global)
3023                 ;; Copy the global value of the variable.
3024                 (setq global (symbol-value (car local)))
3025               ;; Use the value from the list.
3026               (setq global (eval (cdr local))))
3027             (set (make-local-variable (car local)) global))
3028         ;; Simple nil-valued local variable.
3029         (set (make-local-variable local) nil)))))
3030
3031 (defun gnus-summary-clear-local-variables ()
3032   (let ((locals gnus-summary-local-variables))
3033     (while locals
3034       (if (consp (car locals))
3035           (and (symbolp (caar locals))
3036                (set (caar locals) nil))
3037         (and (symbolp (car locals))
3038              (set (car locals) nil)))
3039       (setq locals (cdr locals)))))
3040
3041 ;; Summary data functions.
3042
3043 (defmacro gnus-data-number (data)
3044   `(car ,data))
3045
3046 (defmacro gnus-data-set-number (data number)
3047   `(setcar ,data ,number))
3048
3049 (defmacro gnus-data-mark (data)
3050   `(nth 1 ,data))
3051
3052 (defmacro gnus-data-set-mark (data mark)
3053   `(setcar (nthcdr 1 ,data) ,mark))
3054
3055 (defmacro gnus-data-pos (data)
3056   `(nth 2 ,data))
3057
3058 (defmacro gnus-data-set-pos (data pos)
3059   `(setcar (nthcdr 2 ,data) ,pos))
3060
3061 (defmacro gnus-data-header (data)
3062   `(nth 3 ,data))
3063
3064 (defmacro gnus-data-set-header (data header)
3065   `(setf (nth 3 ,data) ,header))
3066
3067 (defmacro gnus-data-level (data)
3068   `(nth 4 ,data))
3069
3070 (defmacro gnus-data-unread-p (data)
3071   `(= (nth 1 ,data) gnus-unread-mark))
3072
3073 (defmacro gnus-data-read-p (data)
3074   `(/= (nth 1 ,data) gnus-unread-mark))
3075
3076 (defmacro gnus-data-pseudo-p (data)
3077   `(consp (nth 3 ,data)))
3078
3079 (defmacro gnus-data-find (number)
3080   `(assq ,number gnus-newsgroup-data))
3081
3082 (defmacro gnus-data-find-list (number &optional data)
3083   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3084      (memq (assq ,number bdata)
3085            bdata)))
3086
3087 (defmacro gnus-data-make (number mark pos header level)
3088   `(list ,number ,mark ,pos ,header ,level))
3089
3090 (defun gnus-data-enter (after-article number mark pos header level offset)
3091   (let ((data (gnus-data-find-list after-article)))
3092     (unless data
3093       (error "No such article: %d" after-article))
3094     (setcdr data (cons (gnus-data-make number mark pos header level)
3095                        (cdr data)))
3096     (setq gnus-newsgroup-data-reverse nil)
3097     (gnus-data-update-list (cddr data) offset)))
3098
3099 (defun gnus-data-enter-list (after-article list &optional offset)
3100   (when list
3101     (let ((data (and after-article (gnus-data-find-list after-article)))
3102           (ilist list))
3103       (if (not (or data
3104                    after-article))
3105           (let ((odata gnus-newsgroup-data))
3106             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3107             (when offset
3108               (gnus-data-update-list odata offset)))
3109         ;; Find the last element in the list to be spliced into the main
3110         ;; list.
3111         (setq list (last list))
3112         (if (not data)
3113             (progn
3114               (setcdr list gnus-newsgroup-data)
3115               (setq gnus-newsgroup-data ilist)
3116               (when offset
3117                 (gnus-data-update-list (cdr list) offset)))
3118           (setcdr list (cdr data))
3119           (setcdr data ilist)
3120           (when offset
3121             (gnus-data-update-list (cdr list) offset))))
3122       (setq gnus-newsgroup-data-reverse nil))))
3123
3124 (defun gnus-data-remove (article &optional offset)
3125   (let ((data gnus-newsgroup-data))
3126     (if (= (gnus-data-number (car data)) article)
3127         (progn
3128           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3129                 gnus-newsgroup-data-reverse nil)
3130           (when offset
3131             (gnus-data-update-list gnus-newsgroup-data offset)))
3132       (while (cdr data)
3133         (when (= (gnus-data-number (cadr data)) article)
3134           (setcdr data (cddr data))
3135           (when offset
3136             (gnus-data-update-list (cdr data) offset))
3137           (setq data nil
3138                 gnus-newsgroup-data-reverse nil))
3139         (setq data (cdr data))))))
3140
3141 (defmacro gnus-data-list (backward)
3142   `(if ,backward
3143        (or gnus-newsgroup-data-reverse
3144            (setq gnus-newsgroup-data-reverse
3145                  (reverse gnus-newsgroup-data)))
3146      gnus-newsgroup-data))
3147
3148 (defun gnus-data-update-list (data offset)
3149   "Add OFFSET to the POS of all data entries in DATA."
3150   (setq gnus-newsgroup-data-reverse nil)
3151   (while data
3152     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3153     (setq data (cdr data))))
3154
3155 (defun gnus-summary-article-pseudo-p (article)
3156   "Say whether this article is a pseudo article or not."
3157   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3158
3159 (defmacro gnus-summary-article-sparse-p (article)
3160   "Say whether this article is a sparse article or not."
3161   `(memq ,article gnus-newsgroup-sparse))
3162
3163 (defmacro gnus-summary-article-ancient-p (article)
3164   "Say whether this article is a sparse article or not."
3165   `(memq ,article gnus-newsgroup-ancient))
3166
3167 (defun gnus-article-parent-p (number)
3168   "Say whether this article is a parent or not."
3169   (let ((data (gnus-data-find-list number)))
3170     (and (cdr data)              ; There has to be an article after...
3171          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3172             (gnus-data-level (nth 1 data))))))
3173
3174 (defun gnus-article-children (number)
3175   "Return a list of all children to NUMBER."
3176   (let* ((data (gnus-data-find-list number))
3177          (level (gnus-data-level (car data)))
3178          children)
3179     (setq data (cdr data))
3180     (while (and data
3181                 (= (gnus-data-level (car data)) (1+ level)))
3182       (push (gnus-data-number (car data)) children)
3183       (setq data (cdr data)))
3184     children))
3185
3186 (defmacro gnus-summary-skip-intangible ()
3187   "If the current article is intangible, then jump to a different article."
3188   '(let ((to (get-text-property (point) 'gnus-intangible)))
3189      (and to (gnus-summary-goto-subject to))))
3190
3191 (defmacro gnus-summary-article-intangible-p ()
3192   "Say whether this article is intangible or not."
3193   '(get-text-property (point) 'gnus-intangible))
3194
3195 (defun gnus-article-read-p (article)
3196   "Say whether ARTICLE is read or not."
3197   (not (or (memq article gnus-newsgroup-marked)
3198            (memq article gnus-newsgroup-spam-marked)
3199            (memq article gnus-newsgroup-unreads)
3200            (memq article gnus-newsgroup-unselected)
3201            (memq article gnus-newsgroup-dormant))))
3202
3203 ;; Some summary mode macros.
3204
3205 (defmacro gnus-summary-article-number ()
3206   "The article number of the article on the current line.
3207 If there isn't an article number here, then we return the current
3208 article number."
3209   '(progn
3210      (gnus-summary-skip-intangible)
3211      (or (get-text-property (point) 'gnus-number)
3212          (gnus-summary-last-subject))))
3213
3214 (defmacro gnus-summary-article-header (&optional number)
3215   "Return the header of article NUMBER."
3216   `(gnus-data-header (gnus-data-find
3217                       ,(or number '(gnus-summary-article-number)))))
3218
3219 (defmacro gnus-summary-thread-level (&optional number)
3220   "Return the level of thread that starts with article NUMBER."
3221   `(if (and (eq gnus-summary-make-false-root 'dummy)
3222             (get-text-property (point) 'gnus-intangible))
3223        0
3224      (gnus-data-level (gnus-data-find
3225                        ,(or number '(gnus-summary-article-number))))))
3226
3227 (defmacro gnus-summary-article-mark (&optional number)
3228   "Return the mark of article NUMBER."
3229   `(gnus-data-mark (gnus-data-find
3230                     ,(or number '(gnus-summary-article-number)))))
3231
3232 (defmacro gnus-summary-article-pos (&optional number)
3233   "Return the position of the line of article NUMBER."
3234   `(gnus-data-pos (gnus-data-find
3235                    ,(or number '(gnus-summary-article-number)))))
3236
3237 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3238 (defmacro gnus-summary-article-subject (&optional number)
3239   "Return current subject string or nil if nothing."
3240   `(let ((headers
3241           ,(if number
3242                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3243              '(gnus-data-header (assq (gnus-summary-article-number)
3244                                       gnus-newsgroup-data)))))
3245      (and headers
3246           (vectorp headers)
3247           (mail-header-subject headers))))
3248
3249 (defmacro gnus-summary-article-score (&optional number)
3250   "Return current article score."
3251   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3252                   gnus-newsgroup-scored))
3253        gnus-summary-default-score 0))
3254
3255 (defun gnus-summary-article-children (&optional number)
3256   "Return a list of article numbers that are children of article NUMBER."
3257   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3258          (level (gnus-data-level (car data)))
3259          l children)
3260     (while (and (setq data (cdr data))
3261                 (> (setq l (gnus-data-level (car data))) level))
3262       (and (= (1+ level) l)
3263            (push (gnus-data-number (car data))
3264                  children)))
3265     (nreverse children)))
3266
3267 (defun gnus-summary-article-parent (&optional number)
3268   "Return the article number of the parent of article NUMBER."
3269   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3270                                     (gnus-data-list t)))
3271          (level (gnus-data-level (car data))))
3272     (if (zerop level)
3273         ()                              ; This is a root.
3274       ;; We search until we find an article with a level less than
3275       ;; this one.  That function has to be the parent.
3276       (while (and (setq data (cdr data))
3277                   (not (< (gnus-data-level (car data)) level))))
3278       (and data (gnus-data-number (car data))))))
3279
3280 (defun gnus-unread-mark-p (mark)
3281   "Say whether MARK is the unread mark."
3282   (= mark gnus-unread-mark))
3283
3284 (defun gnus-read-mark-p (mark)
3285   "Say whether MARK is one of the marks that mark as read.
3286 This is all marks except unread, ticked, dormant, and expirable."
3287   (not (or (= mark gnus-unread-mark)
3288            (= mark gnus-ticked-mark)
3289            (= mark gnus-spam-mark)
3290            (= mark gnus-dormant-mark)
3291            (= mark gnus-expirable-mark))))
3292
3293 (defmacro gnus-article-mark (number)
3294   "Return the MARK of article NUMBER.
3295 This macro should only be used when computing the mark the \"first\"
3296 time; i.e., when generating the summary lines.  After that,
3297 `gnus-summary-article-mark' should be used to examine the
3298 marks of articles."
3299   `(cond
3300     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3301     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3302     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3303     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3304     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3305     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3306     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3307     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3308            gnus-ancient-mark))))
3309
3310 ;; Saving hidden threads.
3311
3312 (defmacro gnus-save-hidden-threads (&rest forms)
3313   "Save hidden threads, eval FORMS, and restore the hidden threads."
3314   (let ((config (make-symbol "config")))
3315     `(let ((,config (gnus-hidden-threads-configuration)))
3316        (unwind-protect
3317            (save-excursion
3318              ,@forms)
3319          (gnus-restore-hidden-threads-configuration ,config)))))
3320 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3321 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3322
3323 (defun gnus-data-compute-positions ()
3324   "Compute the positions of all articles."
3325   (setq gnus-newsgroup-data-reverse nil)
3326   (let ((data gnus-newsgroup-data))
3327     (save-excursion
3328       (gnus-save-hidden-threads
3329         (gnus-summary-show-all-threads)
3330         (goto-char (point-min))
3331         (while data
3332           (while (get-text-property (point) 'gnus-intangible)
3333             (forward-line 1))
3334           (gnus-data-set-pos (car data) (+ (point) 3))
3335           (setq data (cdr data))
3336           (forward-line 1))))))
3337
3338 (defun gnus-hidden-threads-configuration ()
3339   "Return the current hidden threads configuration."
3340   (save-excursion
3341     (let (config)
3342       (goto-char (point-min))
3343       (while (search-forward "\r" nil t)
3344         (push (1- (point)) config))
3345       config)))
3346
3347 (defun gnus-restore-hidden-threads-configuration (config)
3348   "Restore hidden threads configuration from CONFIG."
3349   (save-excursion
3350     (let (point buffer-read-only)
3351       (while (setq point (pop config))
3352         (when (and (< point (point-max))
3353                    (goto-char point)
3354                    (eq (char-after) ?\n))
3355           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3356
3357 ;; Various summary mode internalish functions.
3358
3359 (defun gnus-mouse-pick-article (e)
3360   (interactive "e")
3361   (mouse-set-point e)
3362   (gnus-summary-next-page nil t))
3363
3364 (defun gnus-summary-set-display-table ()
3365   "Change the display table.
3366 Odd characters have a tendency to mess
3367 up nicely formatted displays - we make all possible glyphs
3368 display only a single character."
3369
3370   ;; We start from the standard display table, if any.
3371   (let ((table (or (copy-sequence standard-display-table)
3372                    (make-display-table)))
3373         (i 32))
3374     ;; Nix out all the control chars...
3375     (while (>= (setq i (1- i)) 0)
3376       (aset table i [??]))
3377    ;; ... but not newline and cr, of course.  (cr is necessary for the
3378     ;; selective display).
3379     (aset table ?\n nil)
3380     (aset table ?\r nil)
3381     ;; We keep TAB as well.
3382     (aset table ?\t nil)
3383     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3384     ;; Emacs 23 (unicode), that are not set already.
3385     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3386                  160
3387                256)))
3388       (while (>= (setq i (1- i)) 127)
3389         ;; Only modify if the entry is nil.
3390         (unless (aref table i)
3391           (aset table i [??]))))
3392     (setq buffer-display-table table)))
3393
3394 (defun gnus-summary-set-article-display-arrow (pos)
3395   "Update the overlay arrow to point to line at position POS."
3396   (when (and gnus-summary-display-arrow
3397              (boundp 'overlay-arrow-position)
3398              (boundp 'overlay-arrow-string))
3399     (save-excursion
3400       (goto-char pos)
3401       (beginning-of-line)
3402       (unless overlay-arrow-position
3403         (setq overlay-arrow-position (make-marker)))
3404       (setq overlay-arrow-string "=>"
3405             overlay-arrow-position (set-marker overlay-arrow-position
3406                                                (point)
3407                                                (current-buffer))))))
3408
3409 (defun gnus-summary-setup-buffer (group)
3410   "Initialize summary buffer."
3411   (let ((buffer (gnus-summary-buffer-name group))
3412         (dead-name (concat "*Dead Summary "
3413                            (gnus-group-decoded-name group) "*")))
3414     ;; If a dead summary buffer exists, we kill it.
3415     (when (gnus-buffer-live-p dead-name)
3416       (gnus-kill-buffer dead-name))
3417     (if (get-buffer buffer)
3418         (progn
3419           (set-buffer buffer)
3420           (setq gnus-summary-buffer (current-buffer))
3421           (not gnus-newsgroup-prepared))
3422       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3423       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3424       (gnus-summary-mode group)
3425       (when gnus-carpal
3426         (gnus-carpal-setup-buffer 'summary))
3427       (when (gnus-group-quit-config group)
3428         (set (make-local-variable 'gnus-single-article-buffer) nil))
3429       (make-local-variable 'gnus-article-buffer)
3430       (make-local-variable 'gnus-article-current)
3431       (make-local-variable 'gnus-original-article-buffer)
3432       (setq gnus-newsgroup-name group)
3433       ;; Set any local variables in the group parameters.
3434       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3435       t)))
3436
3437 (defun gnus-set-global-variables ()
3438   "Set the global equivalents of the buffer-local variables.
3439 They are set to the latest values they had.  These reflect the summary
3440 buffer that was in action when the last article was fetched."
3441   (when (eq major-mode 'gnus-summary-mode)
3442     (setq gnus-summary-buffer (current-buffer))
3443     (let ((name gnus-newsgroup-name)
3444           (marked gnus-newsgroup-marked)
3445           (spam gnus-newsgroup-spam-marked)
3446           (unread gnus-newsgroup-unreads)
3447           (headers gnus-current-headers)
3448           (data gnus-newsgroup-data)
3449           (summary gnus-summary-buffer)
3450           (article-buffer gnus-article-buffer)
3451           (original gnus-original-article-buffer)
3452           (gac gnus-article-current)
3453           (reffed gnus-reffed-article-number)
3454           (score-file gnus-current-score-file)
3455           (default-charset gnus-newsgroup-charset)
3456           vlist)
3457       (let ((locals gnus-newsgroup-variables))
3458         (while locals
3459           (if (consp (car locals))
3460               (push (eval (caar locals)) vlist)
3461             (push (eval (car locals)) vlist))
3462           (setq locals (cdr locals)))
3463         (setq vlist (nreverse vlist)))
3464       (with-current-buffer gnus-group-buffer
3465         (setq gnus-newsgroup-name name
3466               gnus-newsgroup-marked marked
3467               gnus-newsgroup-spam-marked spam
3468               gnus-newsgroup-unreads unread
3469               gnus-current-headers headers
3470               gnus-newsgroup-data data
3471               gnus-article-current gac
3472               gnus-summary-buffer summary
3473               gnus-article-buffer article-buffer
3474               gnus-original-article-buffer original
3475               gnus-reffed-article-number reffed
3476               gnus-current-score-file score-file
3477               gnus-newsgroup-charset default-charset)
3478         (let ((locals gnus-newsgroup-variables))
3479           (while locals
3480             (if (consp (car locals))
3481                 (set (caar locals) (pop vlist))
3482               (set (car locals) (pop vlist)))
3483             (setq locals (cdr locals))))
3484         ;; The article buffer also has local variables.
3485         (when (gnus-buffer-live-p gnus-article-buffer)
3486           (set-buffer gnus-article-buffer)
3487           (setq gnus-summary-buffer summary))))))
3488
3489 (defun gnus-summary-article-unread-p (article)
3490   "Say whether ARTICLE is unread or not."
3491   (memq article gnus-newsgroup-unreads))
3492
3493 (defun gnus-summary-first-article-p (&optional article)
3494   "Return whether ARTICLE is the first article in the buffer."
3495   (if (not (setq article (or article (gnus-summary-article-number))))
3496       nil
3497     (eq article (caar gnus-newsgroup-data))))
3498
3499 (defun gnus-summary-last-article-p (&optional article)
3500   "Return whether ARTICLE is the last article in the buffer."
3501   (if (not (setq article (or article (gnus-summary-article-number))))
3502       ;; All non-existent numbers are the last article.  :-)
3503       t
3504     (not (cdr (gnus-data-find-list article)))))
3505
3506 (defun gnus-make-thread-indent-array (&optional n)
3507   (when (or n
3508             (progn (setq n 200) nil)
3509             (null gnus-thread-indent-array)
3510             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3511     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3512           gnus-thread-indent-array-level gnus-thread-indent-level)
3513     (while (>= n 0)
3514       (aset gnus-thread-indent-array n
3515             (make-string (* n gnus-thread-indent-level) ? ))
3516       (setq n (1- n)))))
3517
3518 (defun gnus-update-summary-mark-positions ()
3519   "Compute where the summary marks are to go."
3520   (save-excursion
3521     (when (gnus-buffer-exists-p gnus-summary-buffer)
3522       (set-buffer gnus-summary-buffer))
3523     (let ((spec gnus-summary-line-format-spec)
3524           pos)
3525       (save-excursion
3526         (gnus-set-work-buffer)
3527         (let ((gnus-tmp-unread ?Z)
3528               (gnus-replied-mark ?Z)
3529               (gnus-score-below-mark ?Z)
3530               (gnus-score-over-mark ?Z)
3531               (gnus-undownloaded-mark ?Z)
3532               (gnus-summary-line-format-spec spec)
3533               (gnus-newsgroup-downloadable '(0))
3534               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3535               case-fold-search ignores)
3536           ;; Here, all marks are bound to Z.
3537           (gnus-summary-insert-line header
3538                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3539           (goto-char (point-min))
3540           ;; Memorize the positions of the same characters as dummy marks.
3541           (while (re-search-forward "[A-D]" nil t)
3542             (push (point) ignores))
3543           (erase-buffer)
3544           ;; We use A-D as dummy marks in order to know column positions
3545           ;; where marks should be inserted.
3546           (setq gnus-tmp-unread ?A
3547                 gnus-replied-mark ?B
3548                 gnus-score-below-mark ?C
3549                 gnus-score-over-mark ?C
3550                 gnus-undownloaded-mark ?D)
3551           (gnus-summary-insert-line header
3552                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3553           ;; Ignore characters which aren't dummy marks.
3554           (dolist (p ignores)
3555             (delete-region (goto-char (1- p)) p)
3556             (insert ?Z))
3557           (goto-char (point-min))
3558           (setq pos (list (cons 'unread
3559                                 (and (search-forward "A" nil t)
3560                                      (- (point) (point-min) 1)))))
3561           (goto-char (point-min))
3562           (push (cons 'replied (and (search-forward "B" nil t)
3563                                     (- (point) (point-min) 1)))
3564                 pos)
3565           (goto-char (point-min))
3566           (push (cons 'score (and (search-forward "C" nil t)
3567                                   (- (point) (point-min) 1)))
3568                 pos)
3569           (goto-char (point-min))
3570           (push (cons 'download (and (search-forward "D" nil t)
3571                                      (- (point) (point-min) 1)))
3572                 pos)))
3573       (setq gnus-summary-mark-positions pos))))
3574
3575 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3576   "Insert a dummy root in the summary buffer."
3577   (beginning-of-line)
3578   (gnus-add-text-properties
3579    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3580    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3581
3582 (defun gnus-summary-extract-address-component (from)
3583   (or (car (funcall gnus-extract-address-components from))
3584       from))
3585
3586 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3587   (let ((mail-parse-charset gnus-newsgroup-charset)
3588         (ignored-from-addresses (gnus-ignored-from-addresses))
3589         ; Is it really necessary to do this next part for each summary line?
3590         ; Luckily, doesn't seem to slow things down much.
3591         (mail-parse-ignored-charsets
3592          (with-current-buffer gnus-summary-buffer
3593            gnus-newsgroup-ignored-charsets)))
3594     (or
3595      (and ignored-from-addresses
3596           (string-match ignored-from-addresses gnus-tmp-from)
3597           (let ((extra-headers (mail-header-extra header))
3598                 to
3599                 newsgroups)
3600             (cond
3601              ((setq to (cdr (assq 'To extra-headers)))
3602               (concat gnus-summary-to-prefix
3603                       (inline
3604                         (gnus-summary-extract-address-component
3605                          (funcall gnus-decode-encoded-address-function to)))))
3606              ((setq newsgroups
3607                     (or
3608                      (cdr (assq 'Newsgroups extra-headers))
3609                      (and
3610                       (memq 'Newsgroups gnus-extra-headers)
3611                       (eq (car (gnus-find-method-for-group
3612                                 gnus-newsgroup-name)) 'nntp)
3613                       (gnus-group-real-name gnus-newsgroup-name))))
3614               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3615      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3616
3617 (defun gnus-summary-insert-line (gnus-tmp-header
3618                                  gnus-tmp-level gnus-tmp-current
3619                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3620                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3621                                  &optional gnus-tmp-dummy gnus-tmp-score
3622                                  gnus-tmp-process)
3623   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3624       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3625                                           gnus-tmp-level)))
3626   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3627          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3628          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3629          (gnus-tmp-score-char
3630           (if (or (null gnus-summary-default-score)
3631                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3632                       gnus-summary-zcore-fuzz))
3633               ?                         ;Whitespace
3634             (if (< gnus-tmp-score gnus-summary-default-score)
3635                 gnus-score-below-mark gnus-score-over-mark)))
3636          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3637          (gnus-tmp-replied
3638           (cond (gnus-tmp-process gnus-process-mark)
3639                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3640                  gnus-cached-mark)
3641                 (gnus-tmp-replied gnus-replied-mark)
3642                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3643                  gnus-forwarded-mark)
3644                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3645                  gnus-saved-mark)
3646                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3647                  gnus-recent-mark)
3648                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3649                  gnus-unseen-mark)
3650                 (t gnus-no-mark)))
3651          (gnus-tmp-downloaded
3652           (cond (undownloaded
3653                  gnus-undownloaded-mark)
3654                 (gnus-newsgroup-agentized
3655                  gnus-downloaded-mark)
3656                 (t
3657                  gnus-no-mark)))
3658          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3659          (gnus-tmp-name
3660           (cond
3661            ((string-match "<[^>]+> *$" gnus-tmp-from)
3662             (let ((beg (match-beginning 0)))
3663               (or (and (string-match "^\".+\"" gnus-tmp-from)
3664                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3665                   (substring gnus-tmp-from 0 beg))))
3666            ((string-match "(.+)" gnus-tmp-from)
3667             (substring gnus-tmp-from
3668                        (1+ (match-beginning 0)) (1- (match-end 0))))
3669            (t gnus-tmp-from)))
3670          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3671          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3672          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3673          (buffer-read-only nil))
3674     (when (string= gnus-tmp-name "")
3675       (setq gnus-tmp-name gnus-tmp-from))
3676     (unless (numberp gnus-tmp-lines)
3677       (setq gnus-tmp-lines -1))
3678     (if (= gnus-tmp-lines -1)
3679         (setq gnus-tmp-lines "?")
3680       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3681       (gnus-put-text-property
3682      (point)
3683      (progn (eval gnus-summary-line-format-spec) (point))
3684        'gnus-number gnus-tmp-number)
3685     (when (gnus-visual-p 'summary-highlight 'highlight)
3686       (forward-line -1)
3687       (gnus-run-hooks 'gnus-summary-update-hook)
3688       (forward-line 1))))
3689
3690 (defun gnus-summary-update-line (&optional dont-update)
3691   "Update summary line after change."
3692   (when (and gnus-summary-default-score
3693              (not gnus-summary-inhibit-highlight))
3694     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3695            (article (gnus-summary-article-number))
3696            (score (gnus-summary-article-score article)))
3697       (unless dont-update
3698         (if (and gnus-summary-mark-below
3699                  (< (gnus-summary-article-score)
3700                     gnus-summary-mark-below))
3701             ;; This article has a low score, so we mark it as read.
3702             (when (memq article gnus-newsgroup-unreads)
3703               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3704           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3705             ;; This article was previously marked as read on account
3706             ;; of a low score, but now it has risen, so we mark it as
3707             ;; unread.
3708             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3709         (gnus-summary-update-mark
3710          (if (or (null gnus-summary-default-score)
3711                  (<= (abs (- score gnus-summary-default-score))
3712                      gnus-summary-zcore-fuzz))
3713              ?                          ;Whitespace
3714            (if (< score gnus-summary-default-score)
3715                gnus-score-below-mark gnus-score-over-mark))
3716          'score))
3717       ;; Do visual highlighting.
3718       (when (gnus-visual-p 'summary-highlight 'highlight)
3719         (gnus-run-hooks 'gnus-summary-update-hook)))))
3720
3721 (defvar gnus-tmp-new-adopts nil)
3722
3723 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3724   "Return the number of articles in THREAD.
3725 This may be 0 in some cases -- if none of the articles in
3726 the thread are to be displayed."
3727   (let* ((number
3728          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3729           (cond
3730            ((not (listp thread))
3731             1)
3732            ((and (consp thread) (cdr thread))
3733             (apply
3734              '+ 1 (mapcar
3735                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3736            ((null thread)
3737             1)
3738            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3739             1)
3740            (t 0))))
3741     (when (and level (zerop level) gnus-tmp-new-adopts)
3742       (incf number
3743             (apply '+ (mapcar
3744                        'gnus-summary-number-of-articles-in-thread
3745                        gnus-tmp-new-adopts))))
3746     (if char
3747         (if (> number 1) gnus-not-empty-thread-mark
3748           gnus-empty-thread-mark)
3749       number)))
3750
3751 (defsubst gnus-summary-line-message-size (head)
3752   "Return pretty-printed version of message size.
3753 This function is intended to be used in
3754 `gnus-summary-line-format-alist'."
3755   (let ((c (or (mail-header-chars head) -1)))
3756     (cond ((< c 0) "n/a")               ; chars not available
3757           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3758           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3759           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3760           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3761
3762
3763 (defun gnus-summary-set-local-parameters (group)
3764   "Go through the local params of GROUP and set all variable specs in that list."
3765   (let ((vars '(quit-config)))          ; Ignore quit-config.
3766     (dolist (elem (gnus-group-find-parameter group))
3767       (and (consp elem)                 ; Has to be a cons.
3768            (consp (cdr elem))           ; The cdr has to be a list.
3769            (symbolp (car elem))         ; Has to be a symbol in there.
3770            (not (memq (car elem) vars))
3771            (ignore-errors               ; So we set it.
3772              (push (car elem) vars)
3773              (make-local-variable (car elem))
3774              (set (car elem) (eval (nth 1 elem))))))))
3775
3776 (defun gnus-summary-read-group (group &optional show-all no-article
3777                                       kill-buffer no-display backward
3778                                       select-articles)
3779   "Start reading news in newsgroup GROUP.
3780 If SHOW-ALL is non-nil, already read articles are also listed.
3781 If NO-ARTICLE is non-nil, no article is selected initially.
3782 If NO-DISPLAY, don't generate a summary buffer."
3783   (let (result)
3784     (while (and group
3785                 (null (setq result
3786                             (let ((gnus-auto-select-next nil))
3787                               (or (gnus-summary-read-group-1
3788                                    group show-all no-article
3789                                    kill-buffer no-display
3790                                    select-articles)
3791                                   (setq show-all nil
3792                                         select-articles nil)))))
3793                 (eq gnus-auto-select-next 'quietly))
3794       (set-buffer gnus-group-buffer)
3795       ;; The entry function called above goes to the next
3796       ;; group automatically, so we go two groups back
3797       ;; if we are searching for the previous group.
3798       (when backward
3799         (gnus-group-prev-unread-group 2))
3800       (if (not (equal group (gnus-group-group-name)))
3801           (setq group (gnus-group-group-name))
3802         (setq group nil)))
3803     result))
3804
3805 (defun gnus-summary-read-group-1 (group show-all no-article
3806                                         kill-buffer no-display
3807                                         &optional select-articles)
3808   ;; Killed foreign groups can't be entered.
3809   ;;  (when (and (not (gnus-group-native-p group))
3810   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3811   ;;    (error "Dead non-native groups can't be entered"))
3812   (gnus-message 5 "Retrieving newsgroup: %s..."
3813                 (gnus-group-decoded-name group))
3814   (let* ((new-group (gnus-summary-setup-buffer group))
3815          (quit-config (gnus-group-quit-config group))
3816          (did-select (and new-group (gnus-select-newsgroup
3817                                      group show-all select-articles))))
3818     (cond
3819      ;; This summary buffer exists already, so we just select it.
3820      ((not new-group)
3821       (gnus-set-global-variables)
3822       (when kill-buffer
3823         (gnus-kill-or-deaden-summary kill-buffer))
3824       (gnus-configure-windows 'summary 'force)
3825       (gnus-set-mode-line 'summary)
3826       (gnus-summary-position-point)
3827       (message "")
3828       t)
3829      ;; We couldn't select this group.
3830      ((null did-select)
3831       (when (and (eq major-mode 'gnus-summary-mode)
3832                  (not (equal (current-buffer) kill-buffer)))
3833         (kill-buffer (current-buffer))
3834         (if (not quit-config)
3835             (progn
3836               ;; Update the info -- marks might need to be removed,
3837               ;; for instance.
3838               (gnus-summary-update-info)
3839               (set-buffer gnus-group-buffer)
3840               (gnus-group-jump-to-group group)
3841               (gnus-group-next-unread-group 1))
3842           (gnus-handle-ephemeral-exit quit-config)))
3843       (let ((grpinfo (gnus-get-info group)))
3844         (if (null (gnus-info-read grpinfo))
3845             (gnus-message 3 "Group %s contains no messages"
3846                           (gnus-group-decoded-name group))
3847           (gnus-message 3 "Can't select group")))
3848       nil)
3849      ;; The user did a `C-g' while prompting for number of articles,
3850      ;; so we exit this group.
3851      ((eq did-select 'quit)
3852       (and (eq major-mode 'gnus-summary-mode)
3853            (not (equal (current-buffer) kill-buffer))
3854            (kill-buffer (current-buffer)))
3855       (when kill-buffer
3856         (gnus-kill-or-deaden-summary kill-buffer))
3857       (if (not quit-config)
3858           (progn
3859             (set-buffer gnus-group-buffer)
3860             (gnus-group-jump-to-group group)
3861             (gnus-group-next-unread-group 1)
3862             (gnus-configure-windows 'group 'force))
3863         (gnus-handle-ephemeral-exit quit-config))
3864       ;; Finally signal the quit.
3865       (signal 'quit nil))
3866      ;; The group was successfully selected.
3867      (t
3868       (gnus-set-global-variables)
3869       ;; Save the active value in effect when the group was entered.
3870       (setq gnus-newsgroup-active
3871             (gnus-copy-sequence
3872              (gnus-active gnus-newsgroup-name)))
3873       ;; You can change the summary buffer in some way with this hook.
3874       (gnus-run-hooks 'gnus-select-group-hook)
3875       (when (memq 'summary (gnus-update-format-specifications
3876                             nil 'summary 'summary-mode 'summary-dummy))
3877         ;; The format specification for the summary line was updated,
3878         ;; so we need to update the mark positions as well.
3879         (gnus-update-summary-mark-positions))
3880       ;; Do score processing.
3881       (when gnus-use-scoring
3882         (gnus-possibly-score-headers))
3883       ;; Check whether to fill in the gaps in the threads.
3884       (when gnus-build-sparse-threads
3885         (gnus-build-sparse-threads))
3886       ;; Find the initial limit.
3887       (if show-all
3888           (let ((gnus-newsgroup-dormant nil))
3889             (gnus-summary-initial-limit show-all))
3890         (gnus-summary-initial-limit show-all))
3891       ;; Generate the summary buffer.
3892       (unless no-display
3893         (gnus-summary-prepare))
3894       (when gnus-use-trees
3895         (gnus-tree-open group)
3896         (setq gnus-summary-highlight-line-function
3897               'gnus-tree-highlight-article))
3898       ;; If the summary buffer is empty, but there are some low-scored
3899       ;; articles or some excluded dormants, we include these in the
3900       ;; buffer.
3901       (when (and (zerop (buffer-size))
3902                  (not no-display))
3903         (cond (gnus-newsgroup-dormant
3904                (gnus-summary-limit-include-dormant))
3905               ((and gnus-newsgroup-scored show-all)
3906                (gnus-summary-limit-include-expunged t))))
3907       ;; Function `gnus-apply-kill-file' must be called in this hook.
3908       (gnus-run-hooks 'gnus-apply-kill-hook)
3909       (if (and (zerop (buffer-size))
3910                (not no-display))
3911           (progn
3912             ;; This newsgroup is empty.
3913             (gnus-summary-catchup-and-exit nil t)
3914             (gnus-message 6 "No unread news")
3915             (when kill-buffer
3916               (gnus-kill-or-deaden-summary kill-buffer))
3917             ;; Return nil from this function.
3918             nil)
3919         ;; Hide conversation thread subtrees.  We cannot do this in
3920         ;; gnus-summary-prepare-hook since kill processing may not
3921         ;; work with hidden articles.
3922         (gnus-summary-maybe-hide-threads)
3923         (when kill-buffer
3924           (gnus-kill-or-deaden-summary kill-buffer))
3925         (gnus-summary-auto-select-subject)
3926         ;; Show first unread article if requested.
3927         (if (and (not no-article)
3928                  (not no-display)
3929                  gnus-newsgroup-unreads
3930                  gnus-auto-select-first)
3931             (progn
3932               (gnus-configure-windows 'summary)
3933               (let ((art (gnus-summary-article-number)))
3934                 (unless (and (not gnus-plugged)
3935                              (or (memq art gnus-newsgroup-undownloaded)
3936                                  (memq art gnus-newsgroup-downloadable)))
3937                   (gnus-summary-goto-article art))))
3938           ;; Don't select any articles.
3939           (gnus-summary-position-point)
3940           (gnus-configure-windows 'summary 'force)
3941           (gnus-set-mode-line 'summary))
3942         (when (and gnus-auto-center-group
3943                    (get-buffer-window gnus-group-buffer t))
3944           ;; Gotta use windows, because recenter does weird stuff if
3945           ;; the current buffer ain't the displayed window.
3946           (let ((owin (selected-window)))
3947             (select-window (get-buffer-window gnus-group-buffer t))
3948             (when (gnus-group-goto-group group)
3949               (recenter))
3950             (select-window owin)))
3951         ;; Mark this buffer as "prepared".
3952         (setq gnus-newsgroup-prepared t)
3953         (gnus-run-hooks 'gnus-summary-prepared-hook)
3954         (unless (gnus-ephemeral-group-p group)
3955           (gnus-group-update-group group))
3956         t)))))
3957
3958 (defun gnus-summary-auto-select-subject ()
3959   "Select the subject line on initial group entry."
3960   (goto-char (point-min))
3961   (cond
3962    ((eq gnus-auto-select-subject 'best)
3963     (gnus-summary-best-unread-subject))
3964    ((eq gnus-auto-select-subject 'unread)
3965     (gnus-summary-first-unread-subject))
3966    ((eq gnus-auto-select-subject 'unseen)
3967     (gnus-summary-first-unseen-subject))
3968    ((eq gnus-auto-select-subject 'unseen-or-unread)
3969     (gnus-summary-first-unseen-or-unread-subject))
3970    ((eq gnus-auto-select-subject 'first)
3971     ;; Do nothing.
3972     )
3973    ((functionp gnus-auto-select-subject)
3974     (funcall gnus-auto-select-subject))))
3975
3976 (defun gnus-summary-prepare ()
3977   "Generate the summary buffer."
3978   (interactive)
3979   (let ((buffer-read-only nil))
3980     (erase-buffer)
3981     (setq gnus-newsgroup-data nil
3982           gnus-newsgroup-data-reverse nil)
3983     (gnus-run-hooks 'gnus-summary-generate-hook)
3984     ;; Generate the buffer, either with threads or without.
3985     (when gnus-newsgroup-headers
3986       (gnus-summary-prepare-threads
3987        (if gnus-show-threads
3988            (gnus-sort-gathered-threads
3989             (funcall gnus-summary-thread-gathering-function
3990                      (gnus-sort-threads
3991                       (gnus-cut-threads (gnus-make-threads)))))
3992          ;; Unthreaded display.
3993          (gnus-sort-articles gnus-newsgroup-headers))))
3994     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3995     ;; Call hooks for modifying summary buffer.
3996     (goto-char (point-min))
3997     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3998
3999 (defsubst gnus-general-simplify-subject (subject)
4000   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4001   (setq subject
4002         (cond
4003          ;; Truncate the subject.
4004          (gnus-simplify-subject-functions
4005           (gnus-map-function gnus-simplify-subject-functions subject))
4006          ((numberp gnus-summary-gather-subject-limit)
4007           (setq subject (gnus-simplify-subject-re subject))
4008           (if (> (length subject) gnus-summary-gather-subject-limit)
4009               (substring subject 0 gnus-summary-gather-subject-limit)
4010             subject))
4011          ;; Fuzzily simplify it.
4012          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4013           (gnus-simplify-subject-fuzzy subject))
4014          ;; Just remove the leading "Re:".
4015          (t
4016           (gnus-simplify-subject-re subject))))
4017
4018   (if (and gnus-summary-gather-exclude-subject
4019            (string-match gnus-summary-gather-exclude-subject subject))
4020       nil                         ; This article shouldn't be gathered
4021     subject))
4022
4023 (defun gnus-summary-simplify-subject-query ()
4024   "Query where the respool algorithm would put this article."
4025   (interactive)
4026   (gnus-summary-select-article)
4027   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
4028
4029 (defun gnus-gather-threads-by-subject (threads)
4030   "Gather threads by looking at Subject headers."
4031   (if (not gnus-summary-make-false-root)
4032       threads
4033     (let ((hashtb (gnus-make-hashtable 1024))
4034           (prev threads)
4035           (result threads)
4036           subject hthread whole-subject)
4037       (while threads
4038         (setq subject (gnus-general-simplify-subject
4039                        (setq whole-subject (mail-header-subject
4040                                             (caar threads)))))
4041         (when subject
4042           (if (setq hthread (gnus-gethash subject hashtb))
4043               (progn
4044                 ;; We enter a dummy root into the thread, if we
4045                 ;; haven't done that already.
4046                 (unless (stringp (caar hthread))
4047                   (setcar hthread (list whole-subject (car hthread))))
4048                 ;; We add this new gathered thread to this gathered
4049                 ;; thread.
4050                 (setcdr (car hthread)
4051                         (nconc (cdar hthread) (list (car threads))))
4052                 ;; Remove it from the list of threads.
4053                 (setcdr prev (cdr threads))
4054                 (setq threads prev))
4055             ;; Enter this thread into the hash table.
4056             (gnus-sethash subject
4057                           (if gnus-summary-make-false-root-always
4058                               (progn
4059                                 ;; If you want a dummy root above all
4060                                 ;; threads...
4061                                 (setcar threads (list whole-subject
4062                                                       (car threads)))
4063                                 threads)
4064                             threads)
4065                           hashtb)))
4066         (setq prev threads)
4067         (setq threads (cdr threads)))
4068       result)))
4069
4070 (defun gnus-gather-threads-by-references (threads)
4071   "Gather threads by looking at References headers."
4072   (let ((idhashtb (gnus-make-hashtable 1024))
4073         (thhashtb (gnus-make-hashtable 1024))
4074         (prev threads)
4075         (result threads)
4076         ids references id gthread gid entered ref)
4077     (while threads
4078       (when (setq references (mail-header-references (caar threads)))
4079         (setq id (mail-header-id (caar threads))
4080               ids (inline (gnus-split-references references))
4081               entered nil)
4082         (while (setq ref (pop ids))
4083           (setq ids (delete ref ids))
4084           (if (not (setq gid (gnus-gethash ref idhashtb)))
4085               (progn
4086                 (gnus-sethash ref id idhashtb)
4087                 (gnus-sethash id threads thhashtb))
4088             (setq gthread (gnus-gethash gid thhashtb))
4089             (unless entered
4090               ;; We enter a dummy root into the thread, if we
4091               ;; haven't done that already.
4092               (unless (stringp (caar gthread))
4093                 (setcar gthread (list (mail-header-subject (caar gthread))
4094                                       (car gthread))))
4095               ;; We add this new gathered thread to this gathered
4096               ;; thread.
4097               (setcdr (car gthread)
4098                       (nconc (cdar gthread) (list (car threads)))))
4099             ;; Add it into the thread hash table.
4100             (gnus-sethash id gthread thhashtb)
4101             (setq entered t)
4102             ;; Remove it from the list of threads.
4103             (setcdr prev (cdr threads))
4104             (setq threads prev))))
4105       (setq prev threads)
4106       (setq threads (cdr threads)))
4107     result))
4108
4109 (defun gnus-sort-gathered-threads (threads)
4110   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4111   (let ((result threads))
4112     (while threads
4113       (when (stringp (caar threads))
4114         (setcdr (car threads)
4115                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4116       (setq threads (cdr threads)))
4117     result))
4118
4119 (defun gnus-thread-loop-p (root thread)
4120   "Say whether ROOT is in THREAD."
4121   (let ((stack (list thread))
4122         (infloop 0)
4123         th)
4124     (while (setq thread (pop stack))
4125       (setq th (cdr thread))
4126       (while (and th
4127                   (not (eq (caar th) root)))
4128         (pop th))
4129       (if th
4130           ;; We have found a loop.
4131           (let (ref-dep)
4132             (setcdr thread (delq (car th) (cdr thread)))
4133             (if (boundp (setq ref-dep (intern "none"
4134                                               gnus-newsgroup-dependencies)))
4135                 (setcdr (symbol-value ref-dep)
4136                         (nconc (cdr (symbol-value ref-dep))
4137                                (list (car th))))
4138               (set ref-dep (list nil (car th))))
4139             (setq infloop 1
4140                   stack nil))
4141         ;; Push all the subthreads onto the stack.
4142         (push (cdr thread) stack)))
4143     infloop))
4144
4145 (defun gnus-make-threads ()
4146   "Go through the dependency hashtb and find the roots.  Return all threads."
4147   (let (threads)
4148     (while (catch 'infloop
4149              (mapatoms
4150               (lambda (refs)
4151                 ;; Deal with self-referencing References loops.
4152                 (when (and (car (symbol-value refs))
4153                            (not (zerop
4154                                  (apply
4155                                   '+
4156                                   (mapcar
4157                                    (lambda (thread)
4158                                      (gnus-thread-loop-p
4159                                       (car (symbol-value refs)) thread))
4160                                    (cdr (symbol-value refs)))))))
4161                   (setq threads nil)
4162                   (throw 'infloop t))
4163                 (unless (car (symbol-value refs))
4164                   ;; These threads do not refer back to any other
4165                   ;; articles, so they're roots.
4166                   (setq threads (append (cdr (symbol-value refs)) threads))))
4167               gnus-newsgroup-dependencies)))
4168     threads))
4169
4170 ;; Build the thread tree.
4171 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4172   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4173
4174 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4175 if it was already present.
4176
4177 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4178 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4179 Message-IDs will be renamed to a unique Message-ID before being
4180 entered.
4181
4182 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4183   (let* ((id (mail-header-id header))
4184          (id-dep (and id (intern id dependencies)))
4185          parent-id ref ref-dep ref-header replaced)
4186     ;; Enter this `header' in the `dependencies' table.
4187     (cond
4188      ((not id-dep)
4189       (setq header nil))
4190      ;; The first two cases do the normal part: enter a new `header'
4191      ;; in the `dependencies' table.
4192      ((not (boundp id-dep))
4193       (set id-dep (list header)))
4194      ((null (car (symbol-value id-dep)))
4195       (setcar (symbol-value id-dep) header))
4196
4197      ;; From here the `header' was already present in the
4198      ;; `dependencies' table.
4199      (force-new
4200       ;; Overrides an existing entry;
4201       ;; just set the header part of the entry.
4202       (setcar (symbol-value id-dep) header)
4203       (setq replaced t))
4204
4205      ;; Renames the existing `header' to a unique Message-ID.
4206      ((not gnus-summary-ignore-duplicates)
4207       ;; An article with this Message-ID has already been seen.
4208       ;; We rename the Message-ID.
4209       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4210            (list header))
4211       (mail-header-set-id header id))
4212
4213      ;; The last case ignores an existing entry, except it adds any
4214      ;; additional Xrefs (in case the two articles came from different
4215      ;; servers.
4216      ;; Also sets `header' to `nil' meaning that the `dependencies'
4217      ;; table was *not* modified.
4218      (t
4219       (mail-header-set-xref
4220        (car (symbol-value id-dep))
4221        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4222                    "")
4223                (or (mail-header-xref header) "")))
4224       (setq header nil)))
4225
4226     (when (and header (not replaced))
4227       ;; First check that we are not creating a References loop.
4228       (setq parent-id (gnus-parent-id (mail-header-references header)))
4229       (setq ref parent-id)
4230       (while (and ref
4231                   (setq ref-dep (intern-soft ref dependencies))
4232                   (boundp ref-dep)
4233                   (setq ref-header (car (symbol-value ref-dep))))
4234         (if (string= id ref)
4235             ;; Yuk!  This is a reference loop.  Make the article be a
4236             ;; root article.
4237             (progn
4238               (mail-header-set-references (car (symbol-value id-dep)) "none")
4239               (setq ref nil)
4240               (setq parent-id nil))
4241           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4242       (setq ref-dep (intern (or parent-id "none") dependencies))
4243       (if (boundp ref-dep)
4244           (setcdr (symbol-value ref-dep)
4245                   (nconc (cdr (symbol-value ref-dep))
4246                          (list (symbol-value id-dep))))
4247         (set ref-dep (list nil (symbol-value id-dep)))))
4248     header))
4249
4250 (defun gnus-extract-message-id-from-in-reply-to (string)
4251   (if (string-match "<[^>]+>" string)
4252       (substring string (match-beginning 0) (match-end 0))
4253     nil))
4254
4255 (defun gnus-build-sparse-threads ()
4256   (let ((headers gnus-newsgroup-headers)
4257         (mail-parse-charset gnus-newsgroup-charset)
4258         (gnus-summary-ignore-duplicates t)
4259         header references generation relations
4260         subject child end new-child date)
4261     ;; First we create an alist of generations/relations, where
4262     ;; generations is how much we trust the relation, and the relation
4263     ;; is parent/child.
4264     (gnus-message 7 "Making sparse threads...")
4265     (save-excursion
4266       (nnheader-set-temp-buffer " *gnus sparse threads*")
4267       (while (setq header (pop headers))
4268         (when (and (setq references (mail-header-references header))
4269                    (not (string= references "")))
4270           (insert references)
4271           (setq child (mail-header-id header)
4272                 subject (mail-header-subject header)
4273                 date (mail-header-date header)
4274                 generation 0)
4275           (while (search-backward ">" nil t)
4276             (setq end (1+ (point)))
4277             (when (search-backward "<" nil t)
4278               (setq new-child (buffer-substring (point) end))
4279               (push (list (incf generation)
4280                           child (setq child new-child)
4281                           subject date)
4282                     relations)))
4283           (when child
4284             (push (list (1+ generation) child nil subject) relations))
4285           (erase-buffer)))
4286       (kill-buffer (current-buffer)))
4287     ;; Sort over trustworthiness.
4288     (dolist (relation (sort relations 'car-less-than-car))
4289       (when (gnus-dependencies-add-header
4290              (make-full-mail-header
4291               gnus-reffed-article-number
4292               (nth 3 relation) "" (or (nth 4 relation) "")
4293               (nth 1 relation)
4294               (or (nth 2 relation) "") 0 0 "")
4295              gnus-newsgroup-dependencies nil)
4296         (push gnus-reffed-article-number gnus-newsgroup-limit)
4297         (push gnus-reffed-article-number gnus-newsgroup-sparse)
4298         (push (cons gnus-reffed-article-number gnus-sparse-mark)
4299               gnus-newsgroup-reads)
4300         (decf gnus-reffed-article-number)))
4301     (gnus-message 7 "Making sparse threads...done")))
4302
4303 (defun gnus-build-old-threads ()
4304   ;; Look at all the articles that refer back to old articles, and
4305   ;; fetch the headers for the articles that aren't there.  This will
4306   ;; build complete threads - if the roots haven't been expired by the
4307   ;; server, that is.
4308   (let ((mail-parse-charset gnus-newsgroup-charset)
4309         id heads)
4310     (mapatoms
4311      (lambda (refs)
4312        (when (not (car (symbol-value refs)))
4313          (setq heads (cdr (symbol-value refs)))
4314          (while heads
4315            (if (memq (mail-header-number (caar heads))
4316                      gnus-newsgroup-dormant)
4317                (setq heads (cdr heads))
4318              (setq id (symbol-name refs))
4319              (while (and (setq id (gnus-build-get-header id))
4320                          (not (car (gnus-id-to-thread id)))))
4321              (setq heads nil)))))
4322      gnus-newsgroup-dependencies)))
4323
4324 (defsubst gnus-remove-odd-characters (string)
4325   "Translate STRING into something that doesn't contain weird characters."
4326   (mm-subst-char-in-string
4327    ?\r ?\-
4328    (mm-subst-char-in-string ?\n ?\- string t) t))
4329
4330 ;; This function has to be called with point after the article number
4331 ;; on the beginning of the line.
4332 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4333   (let ((eol (point-at-eol))
4334         (buffer (current-buffer))
4335         header references in-reply-to)
4336
4337     ;; overview: [num subject from date id refs chars lines misc]
4338     (unwind-protect
4339         (let (x)
4340           (narrow-to-region (point) eol)
4341           (unless (eobp)
4342             (forward-char))
4343
4344           (setq header
4345                 (make-full-mail-header
4346                  number                 ; number
4347                  (condition-case ()     ; subject
4348                      (gnus-remove-odd-characters
4349                       (funcall gnus-decode-encoded-word-function
4350                                (setq x (nnheader-nov-field))))
4351                    (error x))
4352                  (condition-case ()     ; from
4353                      (gnus-remove-odd-characters
4354                       (funcall gnus-decode-encoded-address-function
4355                                (setq x (nnheader-nov-field))))
4356                    (error x))
4357                  (nnheader-nov-field)   ; date
4358                  (nnheader-nov-read-message-id number)  ; id
4359                  (setq references (nnheader-nov-field)) ; refs
4360                  (nnheader-nov-read-integer) ; chars
4361                  (nnheader-nov-read-integer) ; lines
4362                  (unless (eobp)
4363                    (if (looking-at "Xref: ")
4364                        (goto-char (match-end 0)))
4365                    (nnheader-nov-field)) ; Xref
4366                  (nnheader-nov-parse-extra)))) ; extra
4367
4368       (widen))
4369
4370     (when (and (string= references "")
4371                (setq in-reply-to (mail-header-extra header))
4372                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4373       (mail-header-set-references
4374        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4375
4376     (when gnus-alter-header-function
4377       (funcall gnus-alter-header-function header))
4378     (gnus-dependencies-add-header header dependencies force-new)))
4379
4380 (defun gnus-build-get-header (id)
4381   "Look through the buffer of NOV lines and find the header to ID.
4382 Enter this line into the dependencies hash table, and return
4383 the id of the parent article (if any)."
4384   (let ((deps gnus-newsgroup-dependencies)
4385         found header)
4386     (prog1
4387         (save-excursion
4388           (set-buffer nntp-server-buffer)
4389           (let ((case-fold-search nil))
4390             (goto-char (point-min))
4391             (while (and (not found)
4392                         (search-forward id nil t))
4393               (beginning-of-line)
4394               (setq found (looking-at
4395                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4396                                    (regexp-quote id))))
4397               (or found (beginning-of-line 2)))
4398             (when found
4399               (beginning-of-line)
4400               (and
4401                (setq header (gnus-nov-parse-line
4402                              (read (current-buffer)) deps))
4403                (gnus-parent-id (mail-header-references header))))))
4404       (when header
4405         (let ((number (mail-header-number header)))
4406           (push number gnus-newsgroup-limit)
4407           (push header gnus-newsgroup-headers)
4408           (if (memq number gnus-newsgroup-unselected)
4409               (progn
4410                 (setq gnus-newsgroup-unreads
4411                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4412                                                number))
4413                 (setq gnus-newsgroup-unselected
4414                       (delq number gnus-newsgroup-unselected)))
4415             (push number gnus-newsgroup-ancient)))))))
4416
4417 (defun gnus-build-all-threads ()
4418   "Read all the headers."
4419   (let ((gnus-summary-ignore-duplicates t)
4420         (mail-parse-charset gnus-newsgroup-charset)
4421         (dependencies gnus-newsgroup-dependencies)
4422         header article)
4423     (save-excursion
4424       (set-buffer nntp-server-buffer)
4425       (let ((case-fold-search nil))
4426         (goto-char (point-min))
4427         (while (not (eobp))
4428           (ignore-errors
4429             (setq article (read (current-buffer))
4430                   header (gnus-nov-parse-line article dependencies)))
4431           (when header
4432             (with-current-buffer gnus-summary-buffer
4433               (push header gnus-newsgroup-headers)
4434               (if (memq (setq article (mail-header-number header))
4435                         gnus-newsgroup-unselected)
4436                   (progn
4437                     (setq gnus-newsgroup-unreads
4438                           (gnus-add-to-sorted-list
4439                            gnus-newsgroup-unreads article))
4440                     (setq gnus-newsgroup-unselected
4441                           (delq article gnus-newsgroup-unselected)))
4442                 (push article gnus-newsgroup-ancient)))
4443             (forward-line 1)))))))
4444
4445 (defun gnus-summary-update-article-line (article header)
4446   "Update the line for ARTICLE using HEADER."
4447   (let* ((id (mail-header-id header))
4448          (thread (gnus-id-to-thread id)))
4449     (unless thread
4450       (error "Article in no thread"))
4451     ;; Update the thread.
4452     (setcar thread header)
4453     (gnus-summary-goto-subject article)
4454     (let* ((datal (gnus-data-find-list article))
4455            (data (car datal))
4456            (buffer-read-only nil)
4457            (level (gnus-summary-thread-level)))
4458       (gnus-delete-line)
4459       (let ((inserted (- (point)
4460                          (progn
4461                            (gnus-summary-insert-line
4462                             header level nil
4463                             (memq article gnus-newsgroup-undownloaded)
4464                             (gnus-article-mark article)
4465                             (memq article gnus-newsgroup-replied)
4466                             (memq article gnus-newsgroup-expirable)
4467                             ;; Only insert the Subject string when it's different
4468                             ;; from the previous Subject string.
4469                             (if (and
4470                                  gnus-show-threads
4471                                  (gnus-subject-equal
4472                                   (condition-case ()
4473                                       (mail-header-subject
4474                                        (gnus-data-header
4475                                         (cadr
4476                                          (gnus-data-find-list
4477                                           article
4478                                           (gnus-data-list t)))))
4479                                     ;; Error on the side of excessive subjects.
4480                                     (error ""))
4481                                   (mail-header-subject header)))
4482                                 ""
4483                               (mail-header-subject header))
4484                             nil (cdr (assq article gnus-newsgroup-scored))
4485                             (memq article gnus-newsgroup-processable))
4486                            (point)))))
4487         (when (cdr datal)
4488           (gnus-data-update-list
4489            (cdr datal)
4490            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4491
4492 (defun gnus-summary-update-article (article &optional iheader)
4493   "Update ARTICLE in the summary buffer."
4494   (set-buffer gnus-summary-buffer)
4495   (let* ((header (gnus-summary-article-header article))
4496          (id (mail-header-id header))
4497          (data (gnus-data-find article))
4498          (thread (gnus-id-to-thread id))
4499          (references (mail-header-references header))
4500          (parent
4501           (gnus-id-to-thread
4502            (or (gnus-parent-id
4503                 (when (and references
4504                            (not (equal "" references)))
4505                   references))
4506                "none")))
4507          (buffer-read-only nil)
4508          (old (car thread)))
4509     (when thread
4510       (unless iheader
4511         (setcar thread nil)
4512         (when parent
4513           (delq thread parent)))
4514       (if (gnus-summary-insert-subject id header)
4515           ;; Set the (possibly) new article number in the data structure.
4516           (gnus-data-set-number data (gnus-id-to-article id))
4517         (setcar thread old)
4518         nil))))
4519
4520 (defun gnus-rebuild-thread (id &optional line)
4521   "Rebuild the thread containing ID.
4522 If LINE, insert the rebuilt thread starting on line LINE."
4523   (let ((buffer-read-only nil)
4524         old-pos current thread data)
4525     (if (not gnus-show-threads)
4526         (setq thread (list (car (gnus-id-to-thread id))))
4527       ;; Get the thread this article is part of.
4528       (setq thread (gnus-remove-thread id)))
4529     (setq old-pos (point-at-bol))
4530     (setq current (save-excursion
4531                     (and (re-search-backward "[\r\n]" nil t)
4532                          (gnus-summary-article-number))))
4533     ;; If this is a gathered thread, we have to go some re-gathering.
4534     (when (stringp (car thread))
4535       (let ((subject (car thread))
4536             roots thr)
4537         (setq thread (cdr thread))
4538         (while thread
4539           (unless (memq (setq thr (gnus-id-to-thread
4540                                    (gnus-root-id
4541                                     (mail-header-id (caar thread)))))
4542                         roots)
4543             (push thr roots))
4544           (setq thread (cdr thread)))
4545         ;; We now have all (unique) roots.
4546         (if (= (length roots) 1)
4547             ;; All the loose roots are now one solid root.
4548             (setq thread (car roots))
4549           (setq thread (cons subject (gnus-sort-threads roots))))))
4550     (let (threads)
4551       ;; We then insert this thread into the summary buffer.
4552       (when line
4553         (goto-char (point-min))
4554         (forward-line (1- line)))
4555       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4556         (if gnus-show-threads
4557             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4558           (gnus-summary-prepare-unthreaded thread))
4559         (setq data (nreverse gnus-newsgroup-data))
4560         (setq threads gnus-newsgroup-threads))
4561       ;; We splice the new data into the data structure.
4562       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4563       ;;!!! then we want to insert at the beginning of the buffer.
4564       ;;!!! That happens to be true with Gnus now, but that may
4565       ;;!!! change in the future.  Perhaps.
4566       (gnus-data-enter-list
4567        (if line nil current) data (- (point) old-pos))
4568       (setq gnus-newsgroup-threads
4569             (nconc threads gnus-newsgroup-threads))
4570       (gnus-data-compute-positions))))
4571
4572 (defun gnus-number-to-header (number)
4573   "Return the header for article NUMBER."
4574   (let ((headers gnus-newsgroup-headers))
4575     (while (and headers
4576                 (not (= number (mail-header-number (car headers)))))
4577       (pop headers))
4578     (when headers
4579       (car headers))))
4580
4581 (defun gnus-parent-headers (in-headers &optional generation)
4582   "Return the headers of the GENERATIONeth parent of HEADERS."
4583   (unless generation
4584     (setq generation 1))
4585   (let ((parent t)
4586         (headers in-headers)
4587         references)
4588     (while (and parent
4589                 (not (zerop generation))
4590                 (setq references (mail-header-references headers)))
4591       (setq headers (if (and references
4592                              (setq parent (gnus-parent-id references)))
4593                         (car (gnus-id-to-thread parent))
4594                       nil))
4595       (decf generation))
4596     (and (not (eq headers in-headers))
4597          headers)))
4598
4599 (defun gnus-id-to-thread (id)
4600   "Return the (sub-)thread where ID appears."
4601   (gnus-gethash id gnus-newsgroup-dependencies))
4602
4603 (defun gnus-id-to-article (id)
4604   "Return the article number of ID."
4605   (let ((thread (gnus-id-to-thread id)))
4606     (when (and thread
4607                (car thread))
4608       (mail-header-number (car thread)))))
4609
4610 (defun gnus-id-to-header (id)
4611   "Return the article headers of ID."
4612   (car (gnus-id-to-thread id)))
4613
4614 (defun gnus-article-displayed-root-p (article)
4615   "Say whether ARTICLE is a root(ish) article."
4616   (let ((level (gnus-summary-thread-level article))
4617         (refs (mail-header-references  (gnus-summary-article-header article)))
4618         particle)
4619     (cond
4620      ((null level) nil)
4621      ((zerop level) t)
4622      ((null refs) t)
4623      ((null (gnus-parent-id refs)) t)
4624      ((and (= 1 level)
4625            (null (setq particle (gnus-id-to-article
4626                                  (gnus-parent-id refs))))
4627            (null (gnus-summary-thread-level particle)))))))
4628
4629 (defun gnus-root-id (id)
4630   "Return the id of the root of the thread where ID appears."
4631   (let (last-id prev)
4632     (while (and id (setq prev (car (gnus-id-to-thread id))))
4633       (setq last-id id
4634             id (gnus-parent-id (mail-header-references prev))))
4635     last-id))
4636
4637 (defun gnus-articles-in-thread (thread)
4638   "Return the list of articles in THREAD."
4639   (cons (mail-header-number (car thread))
4640         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4641
4642 (defun gnus-remove-thread (id &optional dont-remove)
4643   "Remove the thread that has ID in it."
4644   (let (headers thread last-id)
4645     ;; First go up in this thread until we find the root.
4646     (setq last-id (gnus-root-id id)
4647           headers (message-flatten-list (gnus-id-to-thread last-id)))
4648     ;; We have now found the real root of this thread.  It might have
4649     ;; been gathered into some loose thread, so we have to search
4650     ;; through the threads to find the thread we wanted.
4651     (let ((threads gnus-newsgroup-threads)
4652           sub)
4653       (while threads
4654         (setq sub (car threads))
4655         (if (stringp (car sub))
4656             ;; This is a gathered thread, so we look at the roots
4657             ;; below it to find whether this article is in this
4658             ;; gathered root.
4659             (progn
4660               (setq sub (cdr sub))
4661               (while sub
4662                 (when (member (caar sub) headers)
4663                   (setq thread (car threads)
4664                         threads nil
4665                         sub nil))
4666                 (setq sub (cdr sub))))
4667           ;; It's an ordinary thread, so we check it.
4668           (when (eq (car sub) (car headers))
4669             (setq thread sub
4670                   threads nil)))
4671         (setq threads (cdr threads)))
4672       ;; If this article is in no thread, then it's a root.
4673       (if thread
4674           (unless dont-remove
4675             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4676         (setq thread (gnus-id-to-thread last-id)))
4677       (when thread
4678         (prog1
4679             thread                      ; We return this thread.
4680           (unless dont-remove
4681             (if (stringp (car thread))
4682                 (progn
4683                   ;; If we use dummy roots, then we have to remove the
4684                   ;; dummy root as well.
4685                   (when (eq gnus-summary-make-false-root 'dummy)
4686                     ;; We go to the dummy root by going to
4687                     ;; the first sub-"thread", and then one line up.
4688                     (gnus-summary-goto-article
4689                      (mail-header-number (caadr thread)))
4690                     (forward-line -1)
4691                     (gnus-delete-line)
4692                     (gnus-data-compute-positions))
4693                   (setq thread (cdr thread))
4694                   (while thread
4695                     (gnus-remove-thread-1 (car thread))
4696                     (setq thread (cdr thread))))
4697               (gnus-remove-thread-1 thread))))))))
4698
4699 (defun gnus-remove-thread-1 (thread)
4700   "Remove the thread THREAD recursively."
4701   (let ((number (mail-header-number (pop thread)))
4702         d)
4703     (setq thread (reverse thread))
4704     (while thread
4705       (gnus-remove-thread-1 (pop thread)))
4706     (when (setq d (gnus-data-find number))
4707       (goto-char (gnus-data-pos d))
4708       (gnus-summary-show-thread)
4709       (gnus-data-remove
4710        number
4711        (- (point-at-bol)
4712           (prog1
4713               (1+ (point-at-eol))
4714             (gnus-delete-line)))))))
4715
4716 (defun gnus-sort-threads-recursive (threads func)
4717   (sort (mapcar (lambda (thread)
4718                   (cons (car thread)
4719                         (and (cdr thread)
4720                              (gnus-sort-threads-recursive (cdr thread) func))))
4721                 threads) func))
4722
4723 (defun gnus-sort-threads-loop (threads func)
4724   (let* ((superthread (cons nil threads))
4725          (stack (list (cons superthread threads)))
4726          remaining-threads thread)
4727     (while stack
4728       (setq remaining-threads (cdr (car stack)))
4729       (if remaining-threads
4730           (progn (setq thread (car remaining-threads))
4731                  (setcdr (car stack) (cdr remaining-threads))
4732                  (if (cdr thread)
4733                      (push (cons thread (cdr thread)) stack)))
4734         (setq thread (caar stack))
4735         (setcdr thread (sort (cdr thread) func))
4736         (pop stack)))
4737     (cdr superthread)))
4738
4739 (defun gnus-sort-threads (threads)
4740   "Sort THREADS."
4741   (if (not gnus-thread-sort-functions)
4742       threads
4743     (gnus-message 8 "Sorting threads...")
4744     (prog1
4745         (condition-case nil
4746             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4747               (gnus-sort-threads-recursive
4748                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4749           ;; Even after binding max-lisp-eval-depth, the recursive
4750           ;; sorter might fail for very long threads.  In that case,
4751           ;; try using a (less well-tested) non-recursive sorter.
4752           (error (gnus-sort-threads-loop
4753                   threads (gnus-make-sort-function
4754                            gnus-thread-sort-functions))))
4755       (gnus-message 8 "Sorting threads...done"))))
4756
4757 (defun gnus-sort-articles (articles)
4758   "Sort ARTICLES."
4759   (when gnus-article-sort-functions
4760     (gnus-message 7 "Sorting articles...")
4761     (prog1
4762         (setq gnus-newsgroup-headers
4763               (sort articles (gnus-make-sort-function
4764                               gnus-article-sort-functions)))
4765       (gnus-message 7 "Sorting articles...done"))))
4766
4767 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4768 (defmacro gnus-thread-header (thread)
4769   "Return header of first article in THREAD.
4770 Note that THREAD must never, ever be anything else than a variable -
4771 using some other form will lead to serious barfage."
4772   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4773   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4774   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4775         (vector thread) 2))
4776
4777 (defsubst gnus-article-sort-by-number (h1 h2)
4778   "Sort articles by article number."
4779   (< (mail-header-number h1)
4780      (mail-header-number h2)))
4781
4782 (defun gnus-thread-sort-by-number (h1 h2)
4783   "Sort threads by root article number."
4784   (gnus-article-sort-by-number
4785    (gnus-thread-header h1) (gnus-thread-header h2)))
4786
4787 (defsubst gnus-article-sort-by-random (h1 h2)
4788   "Sort articles by article number."
4789   (zerop (random 2)))
4790
4791 (defun gnus-thread-sort-by-random (h1 h2)
4792   "Sort threads by root article number."
4793   (gnus-article-sort-by-random
4794    (gnus-thread-header h1) (gnus-thread-header h2)))
4795
4796 (defsubst gnus-article-sort-by-lines (h1 h2)
4797   "Sort articles by article Lines header."
4798   (< (mail-header-lines h1)
4799      (mail-header-lines h2)))
4800
4801 (defun gnus-thread-sort-by-lines (h1 h2)
4802   "Sort threads by root article Lines header."
4803   (gnus-article-sort-by-lines
4804    (gnus-thread-header h1) (gnus-thread-header h2)))
4805
4806 (defsubst gnus-article-sort-by-chars (h1 h2)
4807   "Sort articles by octet length."
4808   (< (mail-header-chars h1)
4809      (mail-header-chars h2)))
4810
4811 (defun gnus-thread-sort-by-chars (h1 h2)
4812   "Sort threads by root article octet length."
4813   (gnus-article-sort-by-chars
4814    (gnus-thread-header h1) (gnus-thread-header h2)))
4815
4816 (defsubst gnus-article-sort-by-author (h1 h2)
4817   "Sort articles by root author."
4818   (gnus-string<
4819    (let ((extract (funcall
4820                    gnus-extract-address-components
4821                    (mail-header-from h1))))
4822      (or (car extract) (cadr extract) ""))
4823    (let ((extract (funcall
4824                    gnus-extract-address-components
4825                    (mail-header-from h2))))
4826      (or (car extract) (cadr extract) ""))))
4827
4828 (defun gnus-thread-sort-by-author (h1 h2)
4829   "Sort threads by root author."
4830   (gnus-article-sort-by-author
4831    (gnus-thread-header h1)  (gnus-thread-header h2)))
4832
4833 (defsubst gnus-article-sort-by-recipient (h1 h2)
4834   "Sort articles by recipient."
4835   (gnus-string<
4836    (let ((extract (funcall
4837                    gnus-extract-address-components
4838                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4839      (or (car extract) (cadr extract)))
4840    (let ((extract (funcall
4841                    gnus-extract-address-components
4842                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4843      (or (car extract) (cadr extract)))))
4844
4845 (defun gnus-thread-sort-by-recipient (h1 h2)
4846   "Sort threads by root recipient."
4847   (gnus-article-sort-by-recipient
4848    (gnus-thread-header h1) (gnus-thread-header h2)))
4849
4850 (defsubst gnus-article-sort-by-subject (h1 h2)
4851   "Sort articles by root subject."
4852   (gnus-string<
4853    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4854    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4855
4856 (defun gnus-thread-sort-by-subject (h1 h2)
4857   "Sort threads by root subject."
4858   (gnus-article-sort-by-subject
4859    (gnus-thread-header h1) (gnus-thread-header h2)))
4860
4861 (defsubst gnus-article-sort-by-date (h1 h2)
4862   "Sort articles by root article date."
4863   (time-less-p
4864    (gnus-date-get-time (mail-header-date h1))
4865    (gnus-date-get-time (mail-header-date h2))))
4866
4867 (defun gnus-thread-sort-by-date (h1 h2)
4868   "Sort threads by root article date."
4869   (gnus-article-sort-by-date
4870    (gnus-thread-header h1) (gnus-thread-header h2)))
4871
4872 (defsubst gnus-article-sort-by-score (h1 h2)
4873   "Sort articles by root article score.
4874 Unscored articles will be counted as having a score of zero."
4875   (> (or (cdr (assq (mail-header-number h1)
4876                     gnus-newsgroup-scored))
4877          gnus-summary-default-score 0)
4878      (or (cdr (assq (mail-header-number h2)
4879                     gnus-newsgroup-scored))
4880          gnus-summary-default-score 0)))
4881
4882 (defun gnus-thread-sort-by-score (h1 h2)
4883   "Sort threads by root article score."
4884   (gnus-article-sort-by-score
4885    (gnus-thread-header h1) (gnus-thread-header h2)))
4886
4887 (defun gnus-thread-sort-by-total-score (h1 h2)
4888   "Sort threads by the sum of all scores in the thread.
4889 Unscored articles will be counted as having a score of zero."
4890   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4891
4892 (defun gnus-thread-total-score (thread)
4893   ;; This function find the total score of THREAD.
4894   (cond
4895    ((null thread)
4896     0)
4897    ((consp thread)
4898     (if (stringp (car thread))
4899         (apply gnus-thread-score-function 0
4900                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4901       (gnus-thread-total-score-1 thread)))
4902    (t
4903     (gnus-thread-total-score-1 (list thread)))))
4904
4905 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4906   "Sort threads such that the thread with the most recently arrived article comes first."
4907   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4908
4909 (defun gnus-thread-highest-number (thread)
4910   "Return the highest article number in THREAD."
4911   (apply 'max (mapcar (lambda (header)
4912                         (mail-header-number header))
4913                       (message-flatten-list thread))))
4914
4915 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4916   "Sort threads such that the thread with the most recently dated article comes first."
4917   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4918
4919 (defun gnus-thread-latest-date (thread)
4920   "Return the highest article date in THREAD."
4921   (let ((previous-time 0))
4922     (apply 'max
4923            (mapcar
4924             (lambda (header)
4925               (setq previous-time
4926                     (condition-case ()
4927                         (time-to-seconds (mail-header-parse-date
4928                                           (mail-header-date header)))
4929                       (error previous-time))))
4930             (sort
4931              (message-flatten-list thread)
4932              (lambda (h1 h2)
4933                (< (mail-header-number h1)
4934                   (mail-header-number h2))))))))
4935
4936 (defun gnus-thread-total-score-1 (root)
4937   ;; This function find the total score of the thread below ROOT.
4938   (setq root (car root))
4939   (apply gnus-thread-score-function
4940          (or (append
4941               (mapcar 'gnus-thread-total-score
4942                       (cdr (gnus-id-to-thread (mail-header-id root))))
4943               (when (> (mail-header-number root) 0)
4944                 (list (or (cdr (assq (mail-header-number root)
4945                                      gnus-newsgroup-scored))
4946                           gnus-summary-default-score 0))))
4947              (list gnus-summary-default-score)
4948              '(0))))
4949
4950 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4951 (defvar gnus-tmp-prev-subject nil)
4952 (defvar gnus-tmp-false-parent nil)
4953 (defvar gnus-tmp-root-expunged nil)
4954 (defvar gnus-tmp-dummy-line nil)
4955
4956 (eval-when-compile (defvar gnus-tmp-header))
4957 (defun gnus-extra-header (type &optional header)
4958   "Return the extra header of TYPE."
4959   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4960       ""))
4961
4962 (defvar gnus-tmp-thread-tree-header-string "")
4963
4964 (defcustom gnus-sum-thread-tree-root "> "
4965   "With %B spec, used for the root of a thread.
4966 If nil, use subject instead."
4967   :version "22.1"
4968   :type '(radio (const :format "%v  " nil) string)
4969   :group 'gnus-thread)
4970
4971 (defcustom gnus-sum-thread-tree-false-root "> "
4972   "With %B spec, used for a false root of a thread.
4973 If nil, use subject instead."
4974   :version "22.1"
4975   :type '(radio (const :format "%v  " nil) string)
4976   :group 'gnus-thread)
4977
4978 (defcustom gnus-sum-thread-tree-single-indent ""
4979   "With %B spec, used for a thread with just one message.
4980 If nil, use subject instead."
4981   :version "22.1"
4982   :type '(radio (const :format "%v  " nil) string)
4983   :group 'gnus-thread)
4984
4985 (defcustom gnus-sum-thread-tree-vertical "| "
4986   "With %B spec, used for drawing a vertical line."
4987   :version "22.1"
4988   :type 'string
4989   :group 'gnus-thread)
4990
4991 (defcustom gnus-sum-thread-tree-indent "  "
4992   "With %B spec, used for indenting."
4993   :version "22.1"
4994   :type 'string
4995   :group 'gnus-thread)
4996
4997 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4998   "With %B spec, used for a leaf with brothers."
4999   :version "22.1"
5000   :type 'string
5001   :group 'gnus-thread)
5002
5003 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5004   "With %B spec, used for a leaf without brothers."
5005   :version "22.1"
5006   :type 'string
5007   :group 'gnus-thread)
5008
5009 (defun gnus-summary-prepare-threads (threads)
5010   "Prepare summary buffer from THREADS and indentation LEVEL.
5011 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5012 or a straight list of headers."
5013   (gnus-message 7 "Generating summary...")
5014
5015   (setq gnus-newsgroup-threads threads)
5016   (beginning-of-line)
5017
5018   (let ((gnus-tmp-level 0)
5019         (default-score (or gnus-summary-default-score 0))
5020         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5021         (building-line-count gnus-summary-display-while-building)
5022         (building-count (integerp gnus-summary-display-while-building))
5023         thread number subject stack state gnus-tmp-gathered beg-match
5024         new-roots gnus-tmp-new-adopts thread-end simp-subject
5025         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5026         gnus-tmp-replied gnus-tmp-subject-or-nil
5027         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5028         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5029         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5030         tree-stack)
5031
5032     (setq gnus-tmp-prev-subject nil
5033           gnus-tmp-thread-tree-header-string "")
5034
5035     (if (vectorp (car threads))
5036         ;; If this is a straight (sic) list of headers, then a
5037         ;; threaded summary display isn't required, so we just create
5038         ;; an unthreaded one.
5039         (gnus-summary-prepare-unthreaded threads)
5040
5041       ;; Do the threaded display.
5042
5043       (if gnus-summary-display-while-building
5044           (switch-to-buffer (buffer-name)))
5045       (while (or threads stack gnus-tmp-new-adopts new-roots)
5046
5047         (if (and (= gnus-tmp-level 0)
5048                  (or (not stack)
5049                      (= (caar stack) 0))
5050                  (not gnus-tmp-false-parent)
5051                  (or gnus-tmp-new-adopts new-roots))
5052             (if gnus-tmp-new-adopts
5053                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5054                       thread (list (car gnus-tmp-new-adopts))
5055                       gnus-tmp-header (caar thread)
5056                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5057               (when new-roots
5058                 (setq thread (list (car new-roots))
5059                       gnus-tmp-header (caar thread)
5060                       new-roots (cdr new-roots))))
5061
5062           (if threads
5063               ;; If there are some threads, we do them before the
5064               ;; threads on the stack.
5065               (setq thread threads
5066                     gnus-tmp-header (caar thread))
5067             ;; There were no current threads, so we pop something off
5068             ;; the stack.
5069             (setq state (car stack)
5070                   gnus-tmp-level (car state)
5071                   tree-stack (cadr state)
5072                   thread (caddr state)
5073                   stack (cdr stack)
5074                   gnus-tmp-header (caar thread))))
5075
5076         (setq gnus-tmp-false-parent nil)
5077         (setq gnus-tmp-root-expunged nil)
5078         (setq thread-end nil)
5079
5080         (if (stringp gnus-tmp-header)
5081             ;; The header is a dummy root.
5082             (cond
5083              ((eq gnus-summary-make-false-root 'adopt)
5084               ;; We let the first article adopt the rest.
5085               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5086                                                (cddar thread)))
5087               (setq gnus-tmp-gathered
5088                     (nconc (mapcar
5089                             (lambda (h) (mail-header-number (car h)))
5090                             (cddar thread))
5091                            gnus-tmp-gathered))
5092               (setq thread (cons (list (caar thread)
5093                                        (cadar thread))
5094                                  (cdr thread)))
5095               (setq gnus-tmp-level -1
5096                     gnus-tmp-false-parent t))
5097              ((eq gnus-summary-make-false-root 'empty)
5098               ;; We print adopted articles with empty subject fields.
5099               (setq gnus-tmp-gathered
5100                     (nconc (mapcar
5101                             (lambda (h) (mail-header-number (car h)))
5102                             (cddar thread))
5103                            gnus-tmp-gathered))
5104               (setq gnus-tmp-level -1))
5105              ((eq gnus-summary-make-false-root 'dummy)
5106               ;; We remember that we probably want to output a dummy
5107               ;; root.
5108               (setq gnus-tmp-dummy-line gnus-tmp-header)
5109               (setq gnus-tmp-prev-subject gnus-tmp-header))
5110              (t
5111               ;; We do not make a root for the gathered
5112               ;; sub-threads at all.
5113               (setq gnus-tmp-level -1)))
5114
5115           (setq number (mail-header-number gnus-tmp-header)
5116                 subject (mail-header-subject gnus-tmp-header)
5117                 simp-subject (gnus-simplify-subject-fully subject))
5118
5119           (cond
5120            ;; If the thread has changed subject, we might want to make
5121            ;; this subthread into a root.
5122            ((and (null gnus-thread-ignore-subject)
5123                  (not (zerop gnus-tmp-level))
5124                  gnus-tmp-prev-subject
5125                  (not (string= gnus-tmp-prev-subject simp-subject)))
5126             (setq new-roots (nconc new-roots (list (car thread)))
5127                   thread-end t
5128                   gnus-tmp-header nil))
5129            ;; If the article lies outside the current limit,
5130            ;; then we do not display it.
5131            ((not (memq number gnus-newsgroup-limit))
5132             (setq gnus-tmp-gathered
5133                   (nconc (mapcar
5134                           (lambda (h) (mail-header-number (car h)))
5135                           (cdar thread))
5136                          gnus-tmp-gathered))
5137             (setq gnus-tmp-new-adopts (if (cdar thread)
5138                                           (append gnus-tmp-new-adopts
5139                                                   (cdar thread))
5140                                         gnus-tmp-new-adopts)
5141                   thread-end t
5142                   gnus-tmp-header nil)
5143             (when (zerop gnus-tmp-level)
5144               (setq gnus-tmp-root-expunged t)))
5145            ;; Perhaps this article is to be marked as read?
5146            ((and gnus-summary-mark-below
5147                  (< (or (cdr (assq number gnus-newsgroup-scored))
5148                         default-score)
5149                     gnus-summary-mark-below)
5150                  ;; Don't touch sparse articles.
5151                  (not (gnus-summary-article-sparse-p number))
5152                  (not (gnus-summary-article-ancient-p number)))
5153             (setq gnus-newsgroup-unreads
5154                   (delq number gnus-newsgroup-unreads))
5155             (if gnus-newsgroup-auto-expire
5156                 (setq gnus-newsgroup-expirable
5157                       (gnus-add-to-sorted-list
5158                        gnus-newsgroup-expirable number))
5159               (push (cons number gnus-low-score-mark)
5160                     gnus-newsgroup-reads))))
5161
5162           (when gnus-tmp-header
5163             ;; We may have an old dummy line to output before this
5164             ;; article.
5165             (when (and gnus-tmp-dummy-line
5166                        (gnus-subject-equal
5167                         gnus-tmp-dummy-line
5168                         (mail-header-subject gnus-tmp-header)))
5169               (gnus-summary-insert-dummy-line
5170                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5171               (setq gnus-tmp-dummy-line nil))
5172
5173             ;; Compute the mark.
5174             (setq gnus-tmp-unread (gnus-article-mark number))
5175
5176             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5177                                   gnus-tmp-header gnus-tmp-level)
5178                   gnus-newsgroup-data)
5179
5180             ;; Actually insert the line.
5181             (setq
5182              gnus-tmp-subject-or-nil
5183              (cond
5184               ((and gnus-thread-ignore-subject
5185                     gnus-tmp-prev-subject
5186                     (not (string= gnus-tmp-prev-subject simp-subject)))
5187                subject)
5188               ((zerop gnus-tmp-level)
5189                (if (and (eq gnus-summary-make-false-root 'empty)
5190                         (memq number gnus-tmp-gathered)
5191                         gnus-tmp-prev-subject
5192                         (string= gnus-tmp-prev-subject simp-subject))
5193                    gnus-summary-same-subject
5194                  subject))
5195               (t gnus-summary-same-subject)))
5196             (if (and (eq gnus-summary-make-false-root 'adopt)
5197                      (= gnus-tmp-level 1)
5198                      (memq number gnus-tmp-gathered))
5199                 (setq gnus-tmp-opening-bracket ?\<
5200                       gnus-tmp-closing-bracket ?\>)
5201               (setq gnus-tmp-opening-bracket ?\[
5202                     gnus-tmp-closing-bracket ?\]))
5203             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5204                 (gnus-make-thread-indent-array
5205                  (max (* 2 (length gnus-thread-indent-array))
5206                       gnus-tmp-level)))
5207             (setq
5208              gnus-tmp-indentation
5209              (aref gnus-thread-indent-array gnus-tmp-level)
5210              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5211              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5212                                 gnus-summary-default-score 0)
5213              gnus-tmp-score-char
5214              (if (or (null gnus-summary-default-score)
5215                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5216                          gnus-summary-zcore-fuzz))
5217                  ?                      ;Whitespace
5218                (if (< gnus-tmp-score gnus-summary-default-score)
5219                    gnus-score-below-mark gnus-score-over-mark))
5220              gnus-tmp-replied
5221              (cond ((memq number gnus-newsgroup-processable)
5222                     gnus-process-mark)
5223                    ((memq number gnus-newsgroup-cached)
5224                     gnus-cached-mark)
5225                    ((memq number gnus-newsgroup-replied)
5226                     gnus-replied-mark)
5227                    ((memq number gnus-newsgroup-forwarded)
5228                     gnus-forwarded-mark)
5229                    ((memq number gnus-newsgroup-saved)
5230                     gnus-saved-mark)
5231                    ((memq number gnus-newsgroup-recent)
5232                     gnus-recent-mark)
5233                    ((memq number gnus-newsgroup-unseen)
5234                     gnus-unseen-mark)
5235                    (t gnus-no-mark))
5236              gnus-tmp-downloaded
5237              (cond ((memq number gnus-newsgroup-undownloaded)
5238                     gnus-undownloaded-mark)
5239                    (gnus-newsgroup-agentized
5240                     gnus-downloaded-mark)
5241                    (t
5242                     gnus-no-mark))
5243              gnus-tmp-from (mail-header-from gnus-tmp-header)
5244              gnus-tmp-name
5245              (cond
5246               ((string-match "<[^>]+> *$" gnus-tmp-from)
5247                (setq beg-match (match-beginning 0))
5248                (or (and (string-match "^\".+\"" gnus-tmp-from)
5249                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5250                    (substring gnus-tmp-from 0 beg-match)))
5251               ((string-match "(.+)" gnus-tmp-from)
5252                (substring gnus-tmp-from
5253                           (1+ (match-beginning 0)) (1- (match-end 0))))
5254               (t gnus-tmp-from))
5255
5256              ;; Do the %B string
5257              gnus-tmp-thread-tree-header-string
5258              (cond
5259               ((not gnus-show-threads) "")
5260               ((zerop gnus-tmp-level)
5261                (cond ((cdar thread)
5262                       (or gnus-sum-thread-tree-root subject))
5263                      (gnus-tmp-new-adopts
5264                       (or gnus-sum-thread-tree-false-root subject))
5265                      (t
5266                       (or gnus-sum-thread-tree-single-indent subject))))
5267               (t
5268                (concat (apply 'concat
5269                               (mapcar (lambda (item)
5270                                         (if (= item 1)
5271                                             gnus-sum-thread-tree-vertical
5272                                           gnus-sum-thread-tree-indent))
5273                                       (cdr (reverse tree-stack))))
5274                        (if (nth 1 thread)
5275                            gnus-sum-thread-tree-leaf-with-other
5276                          gnus-sum-thread-tree-single-leaf)))))
5277             (when (string= gnus-tmp-name "")
5278               (setq gnus-tmp-name gnus-tmp-from))
5279             (unless (numberp gnus-tmp-lines)
5280               (setq gnus-tmp-lines -1))
5281             (if (= gnus-tmp-lines -1)
5282                 (setq gnus-tmp-lines "?")
5283               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5284               (gnus-put-text-property
5285              (point)
5286              (progn (eval gnus-summary-line-format-spec) (point))
5287                'gnus-number number)
5288             (when gnus-visual-p
5289               (forward-line -1)
5290               (gnus-run-hooks 'gnus-summary-update-hook)
5291               (forward-line 1))
5292
5293             (setq gnus-tmp-prev-subject simp-subject)))
5294
5295         (when (nth 1 thread)
5296           (push (list (max 0 gnus-tmp-level)
5297                       (copy-sequence tree-stack)
5298                       (nthcdr 1 thread))
5299                 stack))
5300         (push (if (nth 1 thread) 1 0) tree-stack)
5301         (incf gnus-tmp-level)
5302         (setq threads (if thread-end nil (cdar thread)))
5303         (if gnus-summary-display-while-building
5304             (if building-count
5305                 (progn
5306                   ;; use a set frequency
5307                   (setq building-line-count (1- building-line-count))
5308                   (when (= building-line-count 0)
5309                     (sit-for 0)
5310                     (setq building-line-count
5311                           gnus-summary-display-while-building)))
5312               ;; always
5313               (sit-for 0)))
5314         (unless threads
5315           (setq gnus-tmp-level 0)))))
5316   (gnus-message 7 "Generating summary...done"))
5317
5318 (defun gnus-summary-prepare-unthreaded (headers)
5319   "Generate an unthreaded summary buffer based on HEADERS."
5320   (let (header number mark)
5321
5322     (beginning-of-line)
5323
5324     (while headers
5325       ;; We may have to root out some bad articles...
5326       (when (memq (setq number (mail-header-number
5327                                 (setq header (pop headers))))
5328                   gnus-newsgroup-limit)
5329         ;; Mark article as read when it has a low score.
5330         (when (and gnus-summary-mark-below
5331                    (< (or (cdr (assq number gnus-newsgroup-scored))
5332                           gnus-summary-default-score 0)
5333                       gnus-summary-mark-below)
5334                    (not (gnus-summary-article-ancient-p number)))
5335           (setq gnus-newsgroup-unreads
5336                 (delq number gnus-newsgroup-unreads))
5337           (if gnus-newsgroup-auto-expire
5338               (push number gnus-newsgroup-expirable)
5339             (push (cons number gnus-low-score-mark)
5340                   gnus-newsgroup-reads)))
5341
5342         (setq mark (gnus-article-mark number))
5343         (push (gnus-data-make number mark (1+ (point)) header 0)
5344               gnus-newsgroup-data)
5345         (gnus-summary-insert-line
5346          header 0 number
5347          (memq number gnus-newsgroup-undownloaded)
5348          mark (memq number gnus-newsgroup-replied)
5349          (memq number gnus-newsgroup-expirable)
5350          (mail-header-subject header) nil
5351          (cdr (assq number gnus-newsgroup-scored))
5352          (memq number gnus-newsgroup-processable))))))
5353
5354 (defun gnus-summary-remove-list-identifiers ()
5355   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5356   (let ((regexp (if (consp gnus-list-identifiers)
5357                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5358                   gnus-list-identifiers))
5359         changed subject)
5360     (when regexp
5361       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5362       (dolist (header gnus-newsgroup-headers)
5363         (setq subject (mail-header-subject header)
5364               changed nil)
5365         (while (string-match regexp subject)
5366           (setq subject
5367                 (concat (substring subject 0 (match-beginning 1))
5368                         (substring subject (match-end 0)))
5369                 changed t))
5370         (when changed
5371           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5372             (setq subject
5373                   (concat (substring subject 0 (match-beginning 1))
5374                           (substring subject (match-end 1)))))
5375           (mail-header-set-subject header subject))))))
5376
5377 (defun gnus-fetch-headers (articles)
5378   "Fetch headers of ARTICLES."
5379   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5380     (gnus-message 5 "Fetching headers for %s..." name)
5381     (prog1
5382         (if (eq 'nov
5383                 (setq gnus-headers-retrieved-by
5384                       (gnus-retrieve-headers
5385                        articles gnus-newsgroup-name
5386                        ;; We might want to fetch old headers, but
5387                        ;; not if there is only 1 article.
5388                        (and (or (and
5389                                  (not (eq gnus-fetch-old-headers 'some))
5390                                  (not (numberp gnus-fetch-old-headers)))
5391                                 (> (length articles) 1))
5392                             gnus-fetch-old-headers))))
5393             (gnus-get-newsgroup-headers-xover
5394              articles nil nil gnus-newsgroup-name t)
5395           (gnus-get-newsgroup-headers))
5396       (gnus-message 5 "Fetching headers for %s...done" name))))
5397
5398 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5399   "Select newsgroup GROUP.
5400 If READ-ALL is non-nil, all articles in the group are selected.
5401 If SELECT-ARTICLES, only select those articles from GROUP."
5402   (let* ((entry (gnus-group-entry group))
5403          ;;!!! Dirty hack; should be removed.
5404          (gnus-summary-ignore-duplicates
5405           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5406               t
5407             gnus-summary-ignore-duplicates))
5408          (info (nth 2 entry))
5409          charset articles fetched-articles cached)
5410
5411     (unless (gnus-check-server
5412              (set (make-local-variable 'gnus-current-select-method)
5413                   (gnus-find-method-for-group group)))
5414       (error "Couldn't open server"))
5415     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5416
5417     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5418         (gnus-activate-group group)     ; Or we can activate it...
5419         (progn                          ; Or we bug out.
5420           (when (equal major-mode 'gnus-summary-mode)
5421             (gnus-kill-buffer (current-buffer)))
5422           (error
5423            "Couldn't activate group %s: %s"
5424            (mm-decode-coding-string group charset)
5425            (mm-decode-coding-string (gnus-status-message group) charset))))
5426
5427     (unless (gnus-request-group group t)
5428         (when (equal major-mode 'gnus-summary-mode)
5429           (gnus-kill-buffer (current-buffer)))
5430         (error "Couldn't request group %s: %s"
5431                (mm-decode-coding-string group charset)
5432                (mm-decode-coding-string (gnus-status-message group) charset)))
5433
5434     (when gnus-agent
5435       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5436
5437       (setq gnus-summary-use-undownloaded-faces
5438             (gnus-agent-find-parameter
5439              group
5440              'agent-enable-undownloaded-faces)))
5441
5442     (setq gnus-newsgroup-name group
5443           gnus-newsgroup-unselected nil
5444           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5445
5446     (let ((display (gnus-group-find-parameter group 'display)))
5447       (setq gnus-newsgroup-display
5448             (cond
5449              ((not (zerop (or (car-safe read-all) 0)))
5450               ;; The user entered the group with C-u SPC/RET, let's show
5451               ;; all articles.
5452               'gnus-not-ignore)
5453              ((eq display 'all)
5454               'gnus-not-ignore)
5455              ((arrayp display)
5456               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5457              ((numberp display)
5458               ;; The following is probably the "correct" solution, but
5459               ;; it makes Gnus fetch all headers and then limit the
5460               ;; articles (which is slow), so instead we hack the
5461               ;; select-articles parameter instead. -- Simon Josefsson
5462               ;; <jas@kth.se>
5463               ;;
5464               ;; (gnus-byte-compile
5465               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5466               ;;                         display)))))
5467               (setq select-articles
5468                     (gnus-uncompress-range
5469                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5470                              (if (> tmp 0)
5471                                  tmp
5472                                1))
5473                            (cdr (gnus-active group)))))
5474               nil)
5475              (t
5476               nil))))
5477
5478     (gnus-summary-setup-default-charset)
5479
5480     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5481     (when (gnus-virtual-group-p group)
5482       (setq cached gnus-newsgroup-cached))
5483
5484     (setq gnus-newsgroup-unreads
5485           (gnus-sorted-ndifference
5486            (gnus-sorted-ndifference gnus-newsgroup-unreads
5487                                     gnus-newsgroup-marked)
5488            gnus-newsgroup-dormant))
5489
5490     (setq gnus-newsgroup-processable nil)
5491
5492     (gnus-update-read-articles group gnus-newsgroup-unreads)
5493
5494     ;; Adjust and set lists of article marks.
5495     (when info
5496       (gnus-adjust-marked-articles info))
5497     (if (setq articles select-articles)
5498         (setq gnus-newsgroup-unselected
5499               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5500       (setq articles (gnus-articles-to-read group read-all)))
5501
5502     (cond
5503      ((null articles)
5504       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5505       'quit)
5506      ((eq articles 0) nil)
5507      (t
5508       ;; Init the dependencies hash table.
5509       (setq gnus-newsgroup-dependencies
5510             (gnus-make-hashtable (length articles)))
5511       (gnus-set-global-variables)
5512       ;; Retrieve the headers and read them in.
5513
5514       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5515
5516       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5517       (when cached
5518         (setq gnus-newsgroup-cached cached))
5519
5520       ;; Suppress duplicates?
5521       (when gnus-suppress-duplicates
5522         (gnus-dup-suppress-articles))
5523
5524       ;; Set the initial limit.
5525       (setq gnus-newsgroup-limit (copy-sequence articles))
5526       ;; Remove canceled articles from the list of unread articles.
5527       (setq fetched-articles
5528             (mapcar (lambda (headers) (mail-header-number headers))
5529                     gnus-newsgroup-headers))
5530       (setq gnus-newsgroup-articles fetched-articles)
5531       (setq gnus-newsgroup-unreads
5532             (gnus-sorted-nintersection
5533              gnus-newsgroup-unreads fetched-articles))
5534       (gnus-compute-unseen-list)
5535
5536       ;; Removed marked articles that do not exist.
5537       (gnus-update-missing-marks
5538        (gnus-sorted-difference articles fetched-articles))
5539       ;; We might want to build some more threads first.
5540       (when (and gnus-fetch-old-headers
5541                  (eq gnus-headers-retrieved-by 'nov))
5542         (if (eq gnus-fetch-old-headers 'invisible)
5543             (gnus-build-all-threads)
5544           (gnus-build-old-threads)))
5545       ;; Let the Gnus agent mark articles as read.
5546       (when gnus-agent
5547         (gnus-agent-get-undownloaded-list))
5548       ;; Remove list identifiers from subject
5549       (when gnus-list-identifiers
5550         (gnus-summary-remove-list-identifiers))
5551       ;; Check whether auto-expire is to be done in this group.
5552       (setq gnus-newsgroup-auto-expire
5553             (gnus-group-auto-expirable-p group))
5554       ;; Set up the article buffer now, if necessary.
5555       (unless (and gnus-single-article-buffer
5556                    (equal gnus-article-buffer "*Article*"))
5557         (gnus-article-setup-buffer))
5558       ;; First and last article in this newsgroup.
5559       (when gnus-newsgroup-headers
5560         (setq gnus-newsgroup-begin
5561               (mail-header-number (car gnus-newsgroup-headers))
5562               gnus-newsgroup-end
5563               (mail-header-number
5564                (gnus-last-element gnus-newsgroup-headers))))
5565       ;; GROUP is successfully selected.
5566       (or gnus-newsgroup-headers t)))))
5567
5568 (defun gnus-compute-unseen-list ()
5569   ;; The `seen' marks are treated specially.
5570   (if (not gnus-newsgroup-seen)
5571       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5572     (setq gnus-newsgroup-unseen
5573           (gnus-inverse-list-range-intersection
5574            gnus-newsgroup-articles gnus-newsgroup-seen))))
5575
5576 (defun gnus-summary-display-make-predicate (display)
5577   (require 'gnus-agent)
5578   (when (= (length display) 1)
5579     (setq display (car display)))
5580   (unless gnus-summary-display-cache
5581     (dolist (elem (append '((unread . unread)
5582                             (read . read)
5583                             (unseen . unseen))
5584                           gnus-article-mark-lists))
5585       (push (cons (cdr elem)
5586                   (gnus-byte-compile
5587                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5588             gnus-summary-display-cache)))
5589   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5590         (gnus-category-predicate-cache gnus-summary-display-cache))
5591     (gnus-get-predicate display)))
5592
5593 ;; Uses the dynamically bound `number' variable.
5594 (eval-when-compile
5595   (defvar number))
5596 (defun gnus-article-marked-p (type &optional article)
5597   (let ((article (or article number)))
5598     (cond
5599      ((eq type 'tick)
5600       (memq article gnus-newsgroup-marked))
5601      ((eq type 'spam)
5602       (memq article gnus-newsgroup-spam-marked))
5603      ((eq type 'unsend)
5604       (memq article gnus-newsgroup-unsendable))
5605      ((eq type 'undownload)
5606       (memq article gnus-newsgroup-undownloaded))
5607      ((eq type 'download)
5608       (memq article gnus-newsgroup-downloadable))
5609      ((eq type 'unread)
5610       (memq article gnus-newsgroup-unreads))
5611      ((eq type 'read)
5612       (memq article gnus-newsgroup-reads))
5613      ((eq type 'dormant)
5614       (memq article gnus-newsgroup-dormant) )
5615      ((eq type 'expire)
5616       (memq article gnus-newsgroup-expirable))
5617      ((eq type 'reply)
5618       (memq article gnus-newsgroup-replied))
5619      ((eq type 'killed)
5620       (memq article gnus-newsgroup-killed))
5621      ((eq type 'bookmark)
5622       (assq article gnus-newsgroup-bookmarks))
5623      ((eq type 'score)
5624       (assq article gnus-newsgroup-scored))
5625      ((eq type 'save)
5626       (memq article gnus-newsgroup-saved))
5627      ((eq type 'cache)
5628       (memq article gnus-newsgroup-cached))
5629      ((eq type 'forward)
5630       (memq article gnus-newsgroup-forwarded))
5631      ((eq type 'seen)
5632       (not (memq article gnus-newsgroup-unseen)))
5633      ((eq type 'recent)
5634       (memq article gnus-newsgroup-recent))
5635      (t t))))
5636
5637 (defun gnus-articles-to-read (group &optional read-all)
5638   "Find out what articles the user wants to read."
5639   (let* ((articles
5640           ;; Select all articles if `read-all' is non-nil, or if there
5641           ;; are no unread articles.
5642           (if (or read-all
5643                   (and (zerop (length gnus-newsgroup-marked))
5644                        (zerop (length gnus-newsgroup-unreads)))
5645                   ;; Fetch all if the predicate is non-nil.
5646                   gnus-newsgroup-display)
5647               ;; We want to select the headers for all the articles in
5648               ;; the group, so we select either all the active
5649               ;; articles in the group, or (if that's nil), the
5650               ;; articles in the cache.
5651               (or
5652                (if gnus-newsgroup-maximum-articles
5653                    (let ((active (gnus-active group)))
5654                      (gnus-uncompress-range
5655                       (cons (max (car active)
5656                                  (- (cdr active)
5657                                     gnus-newsgroup-maximum-articles
5658                                     -1))
5659                             (cdr active))))
5660                  (gnus-uncompress-range (gnus-active group)))
5661                (gnus-cache-articles-in-group group))
5662             ;; Select only the "normal" subset of articles.
5663             (gnus-sorted-nunion
5664              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5665              gnus-newsgroup-unreads)))
5666          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5667          (scored (length scored-list))
5668          (number (length articles))
5669          (marked (+ (length gnus-newsgroup-marked)
5670                     (length gnus-newsgroup-dormant)))
5671          (select
5672           (cond
5673            ((numberp read-all)
5674             read-all)
5675            ((numberp gnus-newsgroup-display)
5676             gnus-newsgroup-display)
5677            (t
5678             (condition-case ()
5679                 (cond
5680                  ((and (or (<= scored marked) (= scored number))
5681                        (numberp gnus-large-newsgroup)
5682                        (> number gnus-large-newsgroup))
5683                   (let* ((cursor-in-echo-area nil)
5684                          (initial (gnus-parameter-large-newsgroup-initial
5685                                    gnus-newsgroup-name))
5686                          (input
5687                           (read-string
5688                            (format
5689                             "How many articles from %s (%s %d): "
5690                             (gnus-group-decoded-name gnus-newsgroup-name)
5691                             (if initial "max" "default")
5692                             number)
5693                            (if initial
5694                                (cons (number-to-string initial)
5695                                      0)))))
5696                     (if (string-match "^[ \t]*$" input) number input)))
5697                  ((and (> scored marked) (< scored number)
5698                        (> (- scored number) 20))
5699                   (let ((input
5700                          (read-string
5701                           (format "%s %s (%d scored, %d total): "
5702                                   "How many articles from"
5703                                   (gnus-group-decoded-name group)
5704                                   scored number))))
5705                     (if (string-match "^[ \t]*$" input)
5706                         number input)))
5707                  (t number))
5708               (quit
5709                (message "Quit getting the articles to read")
5710                nil))))))
5711     (setq select (if (stringp select) (string-to-number select) select))
5712     (if (or (null select) (zerop select))
5713         select
5714       (if (and (not (zerop scored)) (<= (abs select) scored))
5715           (progn
5716             (setq articles (sort scored-list '<))
5717             (setq number (length articles)))
5718         (setq articles (copy-sequence articles)))
5719
5720       (when (< (abs select) number)
5721         (if (< select 0)
5722             ;; Select the N oldest articles.
5723             (setcdr (nthcdr (1- (abs select)) articles) nil)
5724           ;; Select the N most recent articles.
5725           (setq articles (nthcdr (- number select) articles))))
5726       (setq gnus-newsgroup-unselected
5727             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5728       (when gnus-alter-articles-to-read-function
5729         (setq articles
5730               (sort
5731                (funcall gnus-alter-articles-to-read-function
5732                         gnus-newsgroup-name articles)
5733                '<)))
5734       articles)))
5735
5736 (defun gnus-killed-articles (killed articles)
5737   (let (out)
5738     (while articles
5739       (when (inline (gnus-member-of-range (car articles) killed))
5740         (push (car articles) out))
5741       (setq articles (cdr articles)))
5742     out))
5743
5744 (defun gnus-uncompress-marks (marks)
5745   "Uncompress the mark ranges in MARKS."
5746   (let ((uncompressed '(score bookmark))
5747         out)
5748     (while marks
5749       (if (memq (caar marks) uncompressed)
5750           (push (car marks) out)
5751         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5752       (setq marks (cdr marks)))
5753     out))
5754
5755 (defun gnus-article-mark-to-type (mark)
5756   "Return the type of MARK."
5757   (or (cadr (assq mark gnus-article-special-mark-lists))
5758       'list))
5759
5760 (defun gnus-article-unpropagatable-p (mark)
5761   "Return whether MARK should be propagated to back end."
5762   (memq mark gnus-article-unpropagated-mark-lists))
5763
5764 (defun gnus-adjust-marked-articles (info)
5765   "Set all article lists and remove all marks that are no longer valid."
5766   (let* ((marked-lists (gnus-info-marks info))
5767          (active (gnus-active (gnus-info-group info)))
5768          (min (car active))
5769          (max (cdr active))
5770          (types gnus-article-mark-lists)
5771          marks var articles article mark mark-type
5772          bgn end)
5773
5774     (dolist (marks marked-lists)
5775       (setq mark (car marks)
5776             mark-type (gnus-article-mark-to-type mark)
5777             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5778
5779       ;; We set the variable according to the type of the marks list,
5780       ;; and then adjust the marks to a subset of the active articles.
5781       (cond
5782        ;; Adjust "simple" lists - compressed yet unsorted
5783        ((eq mark-type 'list)
5784         ;; Simultaneously uncompress and clip to active range
5785         ;; See gnus-uncompress-range for a description of possible marks
5786         (let (l lh)
5787           (if (not (cadr marks))
5788               (set var nil)
5789             (setq articles (if (numberp (cddr marks))
5790                                (list (cdr marks))
5791                              (cdr marks))
5792                   lh (cons nil nil)
5793                   l lh)
5794
5795             (while (setq article (pop articles))
5796               (cond ((consp article)
5797                      (setq bgn (max (car article) min)
5798                            end (min (cdr article) max))
5799                      (while (<= bgn end)
5800                        (setq l (setcdr l (cons bgn nil))
5801                              bgn (1+ bgn))))
5802                     ((and (<= min article)
5803                           (>= max article))
5804                      (setq l (setcdr l (cons article nil))))))
5805             (set var (cdr lh)))))
5806        ;; Adjust assocs.
5807        ((eq mark-type 'tuple)
5808         (set var (setq articles (cdr marks)))
5809         (when (not (listp (cdr (symbol-value var))))
5810           (set var (list (symbol-value var))))
5811         (when (not (listp (cdr articles)))
5812           (setq articles (list articles)))
5813         (while articles
5814           (when (or (not (consp (setq article (pop articles))))
5815                     (< (car article) min)
5816                     (> (car article) max))
5817             (set var (delq article (symbol-value var))))))
5818        ;; Adjust ranges (sloppily).
5819        ((eq mark-type 'range)
5820         (cond
5821          ((eq mark 'seen)
5822           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5823           ;; It should be (seen (NUM1 . NUM2)).
5824           (when (numberp (cddr marks))
5825             (setcdr marks (list (cdr marks))))
5826           (setq articles (cdr marks))
5827           (while (and articles
5828                       (or (and (consp (car articles))
5829                                (> min (cdar articles)))
5830                           (and (numberp (car articles))
5831                                (> min (car articles)))))
5832             (pop articles))
5833           (set var articles))))))))
5834
5835 (defun gnus-update-missing-marks (missing)
5836   "Go through the list of MISSING articles and remove them from the mark lists."
5837   (when missing
5838     (let (var m)
5839       ;; Go through all types.
5840       (dolist (elem gnus-article-mark-lists)
5841         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5842           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5843           (when (symbol-value var)
5844             ;; This list has articles.  So we delete all missing
5845             ;; articles from it.
5846             (setq m missing)
5847             (while m
5848               (set var (delq (pop m) (symbol-value var))))))))))
5849
5850 (defun gnus-update-marks ()
5851   "Enter the various lists of marked articles into the newsgroup info list."
5852   (let ((types gnus-article-mark-lists)
5853         (info (gnus-get-info gnus-newsgroup-name))
5854         type list newmarked symbol delta-marks)
5855     (when info
5856       ;; Add all marks lists to the list of marks lists.
5857       (while (setq type (pop types))
5858         (setq list (symbol-value
5859                     (setq symbol
5860                           (intern (format "gnus-newsgroup-%s" (car type))))))
5861
5862         (when list
5863           ;; Get rid of the entries of the articles that have the
5864           ;; default score.
5865           (when (and (eq (cdr type) 'score)
5866                      gnus-save-score
5867                      list)
5868             (let* ((arts list)
5869                    (prev (cons nil list))
5870                    (all prev))
5871               (while arts
5872                 (if (or (not (consp (car arts)))
5873                         (= (cdar arts) gnus-summary-default-score))
5874                     (setcdr prev (cdr arts))
5875                   (setq prev arts))
5876                 (setq arts (cdr arts)))
5877               (setq list (cdr all)))))
5878
5879         (when (eq (cdr type) 'seen)
5880           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5881
5882         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5883           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5884
5885         (when (and (gnus-check-backend-function
5886                     'request-set-mark gnus-newsgroup-name)
5887                    (not (gnus-article-unpropagatable-p (cdr type))))
5888           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5889                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5890                  (add (gnus-remove-from-range
5891                        (gnus-copy-sequence list) old)))
5892             (when add
5893               (push (list add 'add (list (cdr type))) delta-marks))
5894             (when del
5895               (push (list del 'del (list (cdr type))) delta-marks))))
5896
5897         (when list
5898           (push (cons (cdr type) list) newmarked)))
5899
5900       (when delta-marks
5901         (unless (gnus-check-group gnus-newsgroup-name)
5902           (error "Can't open server for %s" gnus-newsgroup-name))
5903         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5904
5905       ;; Enter these new marks into the info of the group.
5906       (if (nthcdr 3 info)
5907           (setcar (nthcdr 3 info) newmarked)
5908         ;; Add the marks lists to the end of the info.
5909         (when newmarked
5910           (setcdr (nthcdr 2 info) (list newmarked))))
5911
5912       ;; Cut off the end of the info if there's nothing else there.
5913       (let ((i 5))
5914         (while (and (> i 2)
5915                     (not (nth i info)))
5916           (when (nthcdr (decf i) info)
5917             (setcdr (nthcdr i info) nil)))))))
5918
5919 (defun gnus-set-mode-line (where)
5920   "Set the mode line of the article or summary buffers.
5921 If WHERE is `summary', the summary mode line format will be used."
5922   ;; Is this mode line one we keep updated?
5923   (when (and (memq where gnus-updated-mode-lines)
5924              (symbol-value
5925               (intern (format "gnus-%s-mode-line-format-spec" where))))
5926     (let (mode-string)
5927       (save-excursion
5928         ;; We evaluate this in the summary buffer since these
5929         ;; variables are buffer-local to that buffer.
5930         (set-buffer gnus-summary-buffer)
5931        ;; We bind all these variables that are used in the `eval' form
5932         ;; below.
5933         (let* ((mformat (symbol-value
5934                          (intern
5935                           (format "gnus-%s-mode-line-format-spec" where))))
5936                (gnus-tmp-group-name (gnus-mode-string-quote
5937                                      (gnus-group-decoded-name
5938                                       gnus-newsgroup-name)))
5939                (gnus-tmp-article-number (or gnus-current-article 0))
5940                (gnus-tmp-unread gnus-newsgroup-unreads)
5941                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5942                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5943                (gnus-tmp-unread-and-unselected
5944                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5945                             (zerop gnus-tmp-unselected))
5946                        "")
5947                       ((zerop gnus-tmp-unselected)
5948                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5949                       (t (format "{%d(+%d) more}"
5950                                  gnus-tmp-unread-and-unticked
5951                                  gnus-tmp-unselected))))
5952                (gnus-tmp-subject
5953                 (if (and gnus-current-headers
5954                          (vectorp gnus-current-headers))
5955                     (gnus-mode-string-quote
5956                      (mail-header-subject gnus-current-headers))
5957                   ""))
5958                bufname-length max-len
5959                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5960           (setq mode-string (eval mformat))
5961           (setq bufname-length (if (string-match "%b" mode-string)
5962                                    (- (length
5963                                        (buffer-name
5964                                         (if (eq where 'summary)
5965                                             nil
5966                                           (get-buffer gnus-article-buffer))))
5967                                       2)
5968                                  0))
5969           (setq max-len (max 4 (if gnus-mode-non-string-length
5970                                    (- (window-width)
5971                                       gnus-mode-non-string-length
5972                                       bufname-length)
5973                                  (length mode-string))))
5974           ;; We might have to chop a bit of the string off...
5975           (when (> (length mode-string) max-len)
5976             (setq mode-string
5977                   (concat (truncate-string-to-width mode-string (- max-len 3))
5978                           "...")))
5979           ;; Pad the mode string a bit.
5980           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5981       ;; Update the mode line.
5982       (setq mode-line-buffer-identification
5983             (gnus-mode-line-buffer-identification (list mode-string)))
5984       (set-buffer-modified-p t))))
5985
5986 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5987   "Go through the HEADERS list and add all Xrefs to a hash table.
5988 The resulting hash table is returned, or nil if no Xrefs were found."
5989   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5990          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5991          (xref-hashtb (gnus-make-hashtable))
5992          start group entry number xrefs header)
5993     (while headers
5994       (setq header (pop headers))
5995       (when (and (setq xrefs (mail-header-xref header))
5996                  (not (memq (setq number (mail-header-number header))
5997                             unreads)))
5998         (setq start 0)
5999         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6000           (setq start (match-end 0))
6001           (setq group (if prefix
6002                           (concat prefix (substring xrefs (match-beginning 1)
6003                                                     (match-end 1)))
6004                         (substring xrefs (match-beginning 1) (match-end 1))))
6005           (setq number
6006                 (string-to-number (substring xrefs (match-beginning 2)
6007                                           (match-end 2))))
6008           (if (setq entry (gnus-gethash group xref-hashtb))
6009               (setcdr entry (cons number (cdr entry)))
6010             (gnus-sethash group (cons number nil) xref-hashtb)))))
6011     (and start xref-hashtb)))
6012
6013 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6014   "Look through all the headers and mark the Xrefs as read."
6015   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6016         name info xref-hashtb idlist method nth4)
6017     (save-excursion
6018       (set-buffer gnus-group-buffer)
6019       (when (setq xref-hashtb
6020                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6021         (mapatoms
6022          (lambda (group)
6023            (unless (string= from-newsgroup (setq name (symbol-name group)))
6024              (setq idlist (symbol-value group))
6025              ;; Dead groups are not updated.
6026              (and (prog1
6027                       (setq info (gnus-get-info name))
6028                     (when (stringp (setq nth4 (gnus-info-method info)))
6029                       (setq nth4 (gnus-server-to-method nth4))))
6030                   ;; Only do the xrefs if the group has the same
6031                   ;; select method as the group we have just read.
6032                   (or (gnus-methods-equal-p
6033                        nth4 (gnus-find-method-for-group from-newsgroup))
6034                       virtual
6035                       (equal nth4 (setq method (gnus-find-method-for-group
6036                                                 from-newsgroup)))
6037                       (and (equal (car nth4) (car method))
6038                            (equal (nth 1 nth4) (nth 1 method))))
6039                   gnus-use-cross-reference
6040                   (or (not (eq gnus-use-cross-reference t))
6041                       virtual
6042                       ;; Only do cross-references on subscribed
6043                       ;; groups, if that is what is wanted.
6044                       (<= (gnus-info-level info) gnus-level-subscribed))
6045                   (gnus-group-make-articles-read name idlist))))
6046          xref-hashtb)))))
6047
6048 (defun gnus-compute-read-articles (group articles)
6049   (let* ((entry (gnus-group-entry group))
6050          (info (nth 2 entry))
6051          (active (gnus-active group))
6052          ninfo)
6053     (when entry
6054       ;; First peel off all invalid article numbers.
6055       (when active
6056         (let ((ids articles)
6057               id first)
6058           (while (setq id (pop ids))
6059             (when (and first (> id (cdr active)))
6060               ;; We'll end up in this situation in one particular
6061               ;; obscure situation.  If you re-scan a group and get
6062               ;; a new article that is cross-posted to a different
6063               ;; group that has not been re-scanned, you might get
6064               ;; crossposted article that has a higher number than
6065               ;; Gnus believes possible.  So we re-activate this
6066               ;; group as well.  This might mean doing the
6067               ;; crossposting thingy will *increase* the number
6068               ;; of articles in some groups.  Tsk, tsk.
6069               (setq active (or (gnus-activate-group group) active)))
6070             (when (or (> id (cdr active))
6071                       (< id (car active)))
6072               (setq articles (delq id articles))))))
6073       ;; If the read list is nil, we init it.
6074       (if (and active
6075                (null (gnus-info-read info))
6076                (> (car active) 1))
6077           (setq ninfo (cons 1 (1- (car active))))
6078         (setq ninfo (gnus-info-read info)))
6079       ;; Then we add the read articles to the range.
6080       (gnus-add-to-range
6081        ninfo (setq articles (sort articles '<))))))
6082
6083 (defun gnus-group-make-articles-read (group articles)
6084   "Update the info of GROUP to say that ARTICLES are read."
6085   (let* ((num 0)
6086          (entry (gnus-group-entry group))
6087          (info (nth 2 entry))
6088          (active (gnus-active group))
6089          range)
6090     (when entry
6091       (setq range (gnus-compute-read-articles group articles))
6092       (with-current-buffer gnus-group-buffer
6093         (gnus-undo-register
6094           `(progn
6095              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6096              (gnus-info-set-read ',info ',(gnus-info-read info))
6097              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6098              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6099              (gnus-group-update-group ,group t))))
6100       ;; Add the read articles to the range.
6101       (gnus-info-set-read info range)
6102       (gnus-request-set-mark group (list (list range 'add '(read))))
6103       ;; Then we have to re-compute how many unread
6104       ;; articles there are in this group.
6105       (when active
6106         (cond
6107          ((not range)
6108           (setq num (- (1+ (cdr active)) (car active))))
6109          ((not (listp (cdr range)))
6110           (setq num (- (cdr active) (- (1+ (cdr range))
6111                                        (car range)))))
6112          (t
6113           (while range
6114             (if (numberp (car range))
6115                 (setq num (1+ num))
6116               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6117             (setq range (cdr range)))
6118           (setq num (- (cdr active) num))))
6119         ;; Update the number of unread articles.
6120         (setcar entry num)
6121         ;; Update the group buffer.
6122         (unless (gnus-ephemeral-group-p group)
6123           (gnus-group-update-group group t))))))
6124
6125 (defvar gnus-newsgroup-none-id 0)
6126
6127 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6128   (let ((cur nntp-server-buffer)
6129         (dependencies
6130          (or dependencies
6131              (with-current-buffer gnus-summary-buffer
6132                gnus-newsgroup-dependencies)))
6133         headers id end ref number
6134         (mail-parse-charset gnus-newsgroup-charset)
6135         (mail-parse-ignored-charsets
6136          (save-excursion (condition-case nil
6137                              (set-buffer gnus-summary-buffer)
6138                            (error))
6139                          gnus-newsgroup-ignored-charsets)))
6140     (save-excursion
6141       (set-buffer nntp-server-buffer)
6142       ;; Translate all TAB characters into SPACE characters.
6143       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6144       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6145       (ietf-drums-unfold-fws)
6146       (gnus-run-hooks 'gnus-parse-headers-hook)
6147       (let ((case-fold-search t)
6148             in-reply-to header p lines chars)
6149         (goto-char (point-min))
6150         ;; Search to the beginning of the next header.  Error messages
6151         ;; do not begin with 2 or 3.
6152         (while (re-search-forward "^[23][0-9]+ " nil t)
6153           (setq id nil
6154                 ref nil)
6155           ;; This implementation of this function, with nine
6156           ;; search-forwards instead of the one re-search-forward and
6157           ;; a case (which basically was the old function) is actually
6158           ;; about twice as fast, even though it looks messier.  You
6159           ;; can't have everything, I guess.  Speed and elegance
6160           ;; doesn't always go hand in hand.
6161           (setq
6162            header
6163            (vector
6164             ;; Number.
6165             (prog1
6166                 (setq number (read cur))
6167               (end-of-line)
6168               (setq p (point))
6169               (narrow-to-region (point)
6170                                 (or (and (search-forward "\n.\n" nil t)
6171                                          (- (point) 2))
6172                                     (point))))
6173             ;; Subject.
6174             (progn
6175               (goto-char p)
6176               (if (search-forward "\nsubject:" nil t)
6177                   (funcall gnus-decode-encoded-word-function
6178                            (nnheader-header-value))
6179                 "(none)"))
6180             ;; From.
6181             (progn
6182               (goto-char p)
6183               (if (search-forward "\nfrom:" nil t)
6184                   (funcall gnus-decode-encoded-address-function
6185                            (nnheader-header-value))
6186                 "(nobody)"))
6187             ;; Date.
6188             (progn
6189               (goto-char p)
6190               (if (search-forward "\ndate:" nil t)
6191                   (nnheader-header-value) ""))
6192             ;; Message-ID.
6193             (progn
6194               (goto-char p)
6195               (setq id (if (re-search-forward
6196                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6197                            ;; We do it this way to make sure the Message-ID
6198                            ;; is (somewhat) syntactically valid.
6199                            (buffer-substring (match-beginning 1)
6200                                              (match-end 1))
6201                          ;; If there was no message-id, we just fake one
6202                          ;; to make subsequent routines simpler.
6203                          (nnheader-generate-fake-message-id number))))
6204             ;; References.
6205             (progn
6206               (goto-char p)
6207               (if (search-forward "\nreferences:" nil t)
6208                   (progn
6209                     (setq end (point))
6210                     (prog1
6211                         (nnheader-header-value)
6212                       (setq ref
6213                             (buffer-substring
6214                              (progn
6215                                (end-of-line)
6216                                (search-backward ">" end t)
6217                                (1+ (point)))
6218                              (progn
6219                                (search-backward "<" end t)
6220                                (point))))))
6221                 ;; Get the references from the in-reply-to header if there
6222                 ;; were no references and the in-reply-to header looks
6223                 ;; promising.
6224                 (if (and (search-forward "\nin-reply-to:" nil t)
6225                          (setq in-reply-to (nnheader-header-value))
6226                          (string-match "<[^>]+>" in-reply-to))
6227                     (let (ref2)
6228                       (setq ref (substring in-reply-to (match-beginning 0)
6229                                            (match-end 0)))
6230                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6231                         (setq ref2 (substring in-reply-to (match-beginning 0)
6232                                               (match-end 0)))
6233                         (when (> (length ref2) (length ref))
6234                           (setq ref ref2)))
6235                       ref)
6236                   (setq ref nil))))
6237             ;; Chars.
6238             (progn
6239               (goto-char p)
6240               (if (search-forward "\nchars: " nil t)
6241                   (if (numberp (setq chars (ignore-errors (read cur))))
6242                       chars -1)
6243                 -1))
6244             ;; Lines.
6245             (progn
6246               (goto-char p)
6247               (if (search-forward "\nlines: " nil t)
6248                   (if (numberp (setq lines (ignore-errors (read cur))))
6249                       lines -1)
6250                 -1))
6251             ;; Xref.
6252             (progn
6253               (goto-char p)
6254               (and (search-forward "\nxref:" nil t)
6255                    (nnheader-header-value)))
6256             ;; Extra.
6257             (when gnus-extra-headers
6258               (let ((extra gnus-extra-headers)
6259                     out)
6260                 (while extra
6261                   (goto-char p)
6262                   (when (search-forward
6263                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6264                     (push (cons (car extra) (nnheader-header-value))
6265                           out))
6266                   (pop extra))
6267                 out))))
6268           (when (equal id ref)
6269             (setq ref nil))
6270
6271           (when gnus-alter-header-function
6272             (funcall gnus-alter-header-function header)
6273             (setq id (mail-header-id header)
6274                   ref (gnus-parent-id (mail-header-references header))))
6275
6276           (when (setq header
6277                       (gnus-dependencies-add-header
6278                        header dependencies force-new))
6279             (push header headers))
6280           (goto-char (point-max))
6281           (widen))
6282         (nreverse headers)))))
6283
6284 ;; Goes through the xover lines and returns a list of vectors
6285 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6286                                                   force-new dependencies
6287                                                   group also-fetch-heads)
6288   "Parse the news overview data in the server buffer.
6289 Return a list of headers that match SEQUENCE (see
6290 `nntp-retrieve-headers')."
6291   ;; Get the Xref when the users reads the articles since most/some
6292   ;; NNTP servers do not include Xrefs when using XOVER.
6293   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6294   (let ((mail-parse-charset gnus-newsgroup-charset)
6295         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6296         (cur nntp-server-buffer)
6297         (dependencies (or dependencies gnus-newsgroup-dependencies))
6298         (allp (cond
6299                ((eq gnus-read-all-available-headers t)
6300                 t)
6301                ((and (stringp gnus-read-all-available-headers)
6302                      group)
6303                 (string-match gnus-read-all-available-headers group))
6304                (t
6305                 nil)))
6306         number headers header)
6307     (save-excursion
6308       (set-buffer nntp-server-buffer)
6309       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6310       ;; Allow the user to mangle the headers before parsing them.
6311       (gnus-run-hooks 'gnus-parse-headers-hook)
6312       (goto-char (point-min))
6313       (gnus-parse-without-error
6314         (while (and (or sequence allp)
6315                     (not (eobp)))
6316           (setq number (read cur))
6317           (when (not allp)
6318             (while (and sequence
6319                         (< (car sequence) number))
6320               (setq sequence (cdr sequence))))
6321           (when (and (or allp
6322                          (and sequence
6323                               (eq number (car sequence))))
6324                      (progn
6325                        (setq sequence (cdr sequence))
6326                        (setq header (inline
6327                                       (gnus-nov-parse-line
6328                                        number dependencies force-new)))))
6329             (push header headers))
6330           (forward-line 1)))
6331       ;; A common bug in inn is that if you have posted an article and
6332       ;; then retrieves the active file, it will answer correctly --
6333       ;; the new article is included.  However, a NOV entry for the
6334       ;; article may not have been generated yet, so this may fail.
6335       ;; We work around this problem by retrieving the last few
6336       ;; headers using HEAD.
6337       (if (or (not also-fetch-heads)
6338               (not sequence))
6339           ;; We (probably) got all the headers.
6340           (nreverse headers)
6341         (let ((gnus-nov-is-evil t))
6342           (nconc
6343            (nreverse headers)
6344            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6345              (gnus-get-newsgroup-headers))))))))
6346
6347 (defun gnus-article-get-xrefs ()
6348   "Fill in the Xref value in `gnus-current-headers', if necessary.
6349 This is meant to be called in `gnus-article-internal-prepare-hook'."
6350   (let ((headers (with-current-buffer gnus-summary-buffer
6351                    gnus-current-headers)))
6352     (or (not gnus-use-cross-reference)
6353         (not headers)
6354         (and (mail-header-xref headers)
6355              (not (string= (mail-header-xref headers) "")))
6356         (let ((case-fold-search t)
6357               xref)
6358           (save-restriction
6359             (nnheader-narrow-to-headers)
6360             (goto-char (point-min))
6361             (when (or (and (not (eobp))
6362                            (eq (downcase (char-after)) ?x)
6363                            (looking-at "Xref:"))
6364                       (search-forward "\nXref:" nil t))
6365               (goto-char (1+ (match-end 0)))
6366               (setq xref (buffer-substring (point) (point-at-eol)))
6367               (mail-header-set-xref headers xref)))))))
6368
6369 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6370   "Find article ID and insert the summary line for that article.
6371 OLD-HEADER can either be a header or a line number to insert
6372 the subject line on."
6373   (let* ((line (and (numberp old-header) old-header))
6374          (old-header (and (vectorp old-header) old-header))
6375          (header (cond ((and old-header use-old-header)
6376                         old-header)
6377                        ((and (numberp id)
6378                              (gnus-number-to-header id))
6379                         (gnus-number-to-header id))
6380                        (t
6381                         (gnus-read-header id))))
6382          (number (and (numberp id) id))
6383          d)
6384     (when header
6385       ;; Rebuild the thread that this article is part of and go to the
6386       ;; article we have fetched.
6387       (when (and (not gnus-show-threads)
6388                  old-header)
6389         (when (and number
6390                    (setq d (gnus-data-find (mail-header-number old-header))))
6391           (goto-char (gnus-data-pos d))
6392           (gnus-data-remove
6393            number
6394            (- (point-at-bol)
6395               (prog1
6396                   (1+ (point-at-eol))
6397                 (gnus-delete-line))))))
6398       ;; Remove list identifiers from subject.
6399       (when gnus-list-identifiers
6400         (let ((gnus-newsgroup-headers (list header)))
6401           (gnus-summary-remove-list-identifiers)))
6402       (when old-header
6403         (mail-header-set-number header (mail-header-number old-header)))
6404       (setq gnus-newsgroup-sparse
6405             (delq (setq number (mail-header-number header))
6406                   gnus-newsgroup-sparse))
6407       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6408       (push number gnus-newsgroup-limit)
6409       (gnus-rebuild-thread (mail-header-id header) line)
6410       (gnus-summary-goto-subject number nil t))
6411     (when (and (numberp number)
6412                (> number 0))
6413       ;; We have to update the boundaries even if we can't fetch the
6414       ;; article if ID is a number -- so that the next `P' or `N'
6415       ;; command will fetch the previous (or next) article even
6416       ;; if the one we tried to fetch this time has been canceled.
6417       (when (> number gnus-newsgroup-end)
6418         (setq gnus-newsgroup-end number))
6419       (when (< number gnus-newsgroup-begin)
6420         (setq gnus-newsgroup-begin number))
6421       (setq gnus-newsgroup-unselected
6422             (delq number gnus-newsgroup-unselected)))
6423     ;; Report back a success?
6424     (and header (mail-header-number header))))
6425
6426 ;;; Process/prefix in the summary buffer
6427
6428 (defun gnus-summary-work-articles (n)
6429   "Return a list of articles to be worked upon.
6430 The prefix argument, the list of process marked articles, and the
6431 current article will be taken into consideration."
6432   (save-excursion
6433     (set-buffer gnus-summary-buffer)
6434     (cond
6435      (n
6436       ;; A numerical prefix has been given.
6437       (setq n (prefix-numeric-value n))
6438       (let ((backward (< n 0))
6439             (n (abs (prefix-numeric-value n)))
6440             articles article)
6441         (save-excursion
6442           (while
6443               (and (> n 0)
6444                    (push (setq article (gnus-summary-article-number))
6445                          articles)
6446                    (if backward
6447                        (gnus-summary-find-prev nil article)
6448                      (gnus-summary-find-next nil article)))
6449             (decf n)))
6450         (nreverse articles)))
6451      ((and (gnus-region-active-p) (mark))
6452       (message "region active")
6453       ;; Work on the region between point and mark.
6454       (let ((max (max (point) (mark)))
6455             articles article)
6456         (save-excursion
6457           (goto-char (min (point) (mark)))
6458           (while
6459               (and
6460                (push (setq article (gnus-summary-article-number)) articles)
6461                (gnus-summary-find-next nil article)
6462                (< (point) max)))
6463           (nreverse articles))))
6464      (gnus-newsgroup-processable
6465       ;; There are process-marked articles present.
6466       ;; Save current state.
6467       (gnus-summary-save-process-mark)
6468       ;; Return the list.
6469       (reverse gnus-newsgroup-processable))
6470      (t
6471       ;; Just return the current article.
6472       (list (gnus-summary-article-number))))))
6473
6474 (defmacro gnus-summary-iterate (arg &rest forms)
6475   "Iterate over the process/prefixed articles and do FORMS.
6476 ARG is the interactive prefix given to the command.  FORMS will be
6477 executed with point over the summary line of the articles."
6478   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6479     `(let ((,articles (gnus-summary-work-articles ,arg)))
6480        (while ,articles
6481          (gnus-summary-goto-subject (car ,articles))
6482          ,@forms
6483          (pop ,articles)))))
6484
6485 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6486 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6487
6488 (defun gnus-summary-save-process-mark ()
6489   "Push the current set of process marked articles on the stack."
6490   (interactive)
6491   (push (copy-sequence gnus-newsgroup-processable)
6492         gnus-newsgroup-process-stack))
6493
6494 (defun gnus-summary-kill-process-mark ()
6495   "Push the current set of process marked articles on the stack and unmark."
6496   (interactive)
6497   (gnus-summary-save-process-mark)
6498   (gnus-summary-unmark-all-processable))
6499
6500 (defun gnus-summary-yank-process-mark ()
6501   "Pop the last process mark state off the stack and restore it."
6502   (interactive)
6503   (unless gnus-newsgroup-process-stack
6504     (error "Empty mark stack"))
6505   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6506
6507 (defun gnus-summary-process-mark-set (set)
6508   "Make SET into the current process marked articles."
6509   (gnus-summary-unmark-all-processable)
6510   (mapc 'gnus-summary-set-process-mark set))
6511
6512 ;;; Searching and stuff
6513
6514 (defun gnus-summary-search-group (&optional backward use-level)
6515   "Search for next unread newsgroup.
6516 If optional argument BACKWARD is non-nil, search backward instead."
6517   (save-excursion
6518     (set-buffer gnus-group-buffer)
6519     (when (gnus-group-search-forward
6520            backward nil (if use-level (gnus-group-group-level) nil))
6521       (gnus-group-group-name))))
6522
6523 (defun gnus-summary-best-group (&optional exclude-group)
6524   "Find the name of the best unread group.
6525 If EXCLUDE-GROUP, do not go to this group."
6526   (with-current-buffer gnus-group-buffer
6527     (save-excursion
6528       (gnus-group-best-unread-group exclude-group))))
6529
6530 (defun gnus-summary-find-next (&optional unread article backward)
6531   (if backward
6532       (gnus-summary-find-prev unread article)
6533     (let* ((dummy (gnus-summary-article-intangible-p))
6534            (article (or article (gnus-summary-article-number)))
6535            (data (gnus-data-find-list article))
6536            result)
6537       (when (and (not dummy)
6538                  (or (not gnus-summary-check-current)
6539                      (not unread)
6540                      (not (gnus-data-unread-p (car data)))))
6541         (setq data (cdr data)))
6542       (when (setq result
6543                   (if unread
6544                       (progn
6545                         (while data
6546                           (unless (memq (gnus-data-number (car data))
6547                                         (cond
6548                                          ((eq gnus-auto-goto-ignores
6549                                               'always-undownloaded)
6550                                           gnus-newsgroup-undownloaded)
6551                                          (gnus-plugged
6552                                           nil)
6553                                          ((eq gnus-auto-goto-ignores
6554                                               'unfetched)
6555                                           gnus-newsgroup-unfetched)
6556                                          ((eq gnus-auto-goto-ignores
6557                                               'undownloaded)
6558                                           gnus-newsgroup-undownloaded)))
6559                             (when (gnus-data-unread-p (car data))
6560                               (setq result (car data)
6561                                     data nil)))
6562                           (setq data (cdr data)))
6563                         result)
6564                     (car data)))
6565         (goto-char (gnus-data-pos result))
6566         (gnus-data-number result)))))
6567
6568 (defun gnus-summary-find-prev (&optional unread article)
6569   (let* ((eobp (eobp))
6570          (article (or article (gnus-summary-article-number)))
6571          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6572          result)
6573     (when (and (not eobp)
6574                (or (not gnus-summary-check-current)
6575                    (not unread)
6576                    (not (gnus-data-unread-p (car data)))))
6577       (setq data (cdr data)))
6578     (when (setq result
6579                 (if unread
6580                     (progn
6581                       (while data
6582                         (unless (memq (gnus-data-number (car data))
6583                                       (cond
6584                                        ((eq gnus-auto-goto-ignores
6585                                             'always-undownloaded)
6586                                         gnus-newsgroup-undownloaded)
6587                                        (gnus-plugged
6588                                         nil)
6589                                        ((eq gnus-auto-goto-ignores
6590                                             'unfetched)
6591                                         gnus-newsgroup-unfetched)
6592                                        ((eq gnus-auto-goto-ignores
6593                                             'undownloaded)
6594                                         gnus-newsgroup-undownloaded)))
6595                           (when (gnus-data-unread-p (car data))
6596                             (setq result (car data)
6597                                   data nil)))
6598                         (setq data (cdr data)))
6599                       result)
6600                   (car data)))
6601       (goto-char (gnus-data-pos result))
6602       (gnus-data-number result))))
6603
6604 (defun gnus-summary-find-subject (subject &optional unread backward article)
6605   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6606          (article (or article (gnus-summary-article-number)))
6607          (articles (gnus-data-list backward))
6608          (arts (gnus-data-find-list article articles))
6609          result)
6610     (when (or (not gnus-summary-check-current)
6611               (not unread)
6612               (not (gnus-data-unread-p (car arts))))
6613       (setq arts (cdr arts)))
6614     (while arts
6615       (and (or (not unread)
6616                (gnus-data-unread-p (car arts)))
6617            (vectorp (gnus-data-header (car arts)))
6618            (gnus-subject-equal
6619             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6620            (setq result (car arts)
6621                  arts nil))
6622       (setq arts (cdr arts)))
6623     (and result
6624          (goto-char (gnus-data-pos result))
6625          (gnus-data-number result))))
6626
6627 (defun gnus-summary-search-forward (&optional unread subject backward)
6628   "Search forward for an article.
6629 If UNREAD, look for unread articles.  If SUBJECT, look for
6630 articles with that subject.  If BACKWARD, search backward instead."
6631   (cond (subject (gnus-summary-find-subject subject unread backward))
6632         (backward (gnus-summary-find-prev unread))
6633         (t (gnus-summary-find-next unread))))
6634
6635 (defun gnus-recenter (&optional n)
6636   "Center point in window and redisplay frame.
6637 Also do horizontal recentering."
6638   (interactive "P")
6639   (when (and gnus-auto-center-summary
6640              (not (eq gnus-auto-center-summary 'vertical)))
6641     (gnus-horizontal-recenter))
6642   (recenter n))
6643
6644 (defun gnus-summary-recenter ()
6645   "Center point in the summary window.
6646 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6647 displayed, no centering will be performed."
6648   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6649   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6650   (interactive)
6651   ;; The user has to want it.
6652   (when gnus-auto-center-summary
6653     (let* ((top (cond ((< (window-height) 4) 0)
6654                       ((< (window-height) 7) 1)
6655                       (t (if (numberp gnus-auto-center-summary)
6656                              gnus-auto-center-summary
6657                            (/ (1- (window-height)) 2)))))
6658            (height (1- (window-height)))
6659            (bottom (save-excursion (goto-char (point-max))
6660                                    (forward-line (- height))
6661                                    (point)))
6662            (window (get-buffer-window (current-buffer))))
6663       (when (get-buffer-window gnus-article-buffer)
6664         ;; Only do recentering when the article buffer is displayed,
6665         ;; Set the window start to either `bottom', which is the biggest
6666         ;; possible valid number, or the second line from the top,
6667         ;; whichever is the least.
6668         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6669           (if (> bottom top-pos)
6670               ;; Keep the second line from the top visible
6671               (set-window-start window top-pos)
6672             ;; Try to keep the bottom line visible; if it's partially
6673             ;; obscured, either scroll one more line to make it fully
6674             ;; visible, or revert to using TOP-POS.
6675             (save-excursion
6676               (goto-char (point-max))
6677               (forward-line -1)
6678               (let ((last-line-start (point)))
6679                 (goto-char bottom)
6680                 (set-window-start window (point) t)
6681                 (when (not (pos-visible-in-window-p last-line-start window))
6682                   (forward-line 1)
6683                   (set-window-start window (min (point) top-pos) t)))))))
6684       ;; Do horizontal recentering while we're at it.
6685       (when (and (get-buffer-window (current-buffer) t)
6686                  (not (eq gnus-auto-center-summary 'vertical)))
6687         (let ((selected (selected-window)))
6688           (select-window (get-buffer-window (current-buffer) t))
6689           (gnus-summary-position-point)
6690           (gnus-horizontal-recenter)
6691           (select-window selected))))))
6692
6693 (defun gnus-summary-jump-to-group (newsgroup)
6694   "Move point to NEWSGROUP in group mode buffer."
6695   ;; Keep update point of group mode buffer if visible.
6696   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6697       (save-window-excursion
6698         ;; Take care of tree window mode.
6699         (when (get-buffer-window gnus-group-buffer)
6700           (pop-to-buffer gnus-group-buffer))
6701         (gnus-group-jump-to-group newsgroup))
6702     (save-excursion
6703       ;; Take care of tree window mode.
6704       (if (get-buffer-window gnus-group-buffer)
6705           (pop-to-buffer gnus-group-buffer)
6706         (set-buffer gnus-group-buffer))
6707       (gnus-group-jump-to-group newsgroup))))
6708
6709 ;; This function returns a list of article numbers based on the
6710 ;; difference between the ranges of read articles in this group and
6711 ;; the range of active articles.
6712 (defun gnus-list-of-unread-articles (group)
6713   (let* ((read (gnus-info-read (gnus-get-info group)))
6714          (active (or (gnus-active group) (gnus-activate-group group)))
6715          (last (or (cdr active)
6716                    (error "Group %s couldn't be activated " group)))
6717          (bottom (if gnus-newsgroup-maximum-articles
6718                      (max (car active)
6719                           (- last gnus-newsgroup-maximum-articles -1))
6720                    (car active)))
6721          first nlast unread)
6722     ;; If none are read, then all are unread.
6723     (if (not read)
6724         (setq first bottom)
6725       ;; If the range of read articles is a single range, then the
6726       ;; first unread article is the article after the last read
6727       ;; article.  Sounds logical, doesn't it?
6728       (if (and (not (listp (cdr read)))
6729                (or (< (car read) bottom)
6730                    (progn (setq read (list read))
6731                           nil)))
6732           (setq first (max bottom (1+ (cdr read))))
6733         ;; `read' is a list of ranges.
6734         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6735                                   (caar read)))
6736                   1)
6737           (setq first bottom))
6738         (while read
6739           (when first
6740             (while (< first nlast)
6741               (setq unread (cons first unread)
6742                     first (1+ first))))
6743           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6744           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6745           (setq read (cdr read)))))
6746     ;; And add the last unread articles.
6747     (while (<= first last)
6748       (setq unread (cons first unread)
6749             first (1+ first)))
6750     ;; Return the list of unread articles.
6751     (delq 0 (nreverse unread))))
6752
6753 (defun gnus-list-of-read-articles (group)
6754   "Return a list of unread, unticked and non-dormant articles."
6755   (let* ((info (gnus-get-info group))
6756          (marked (gnus-info-marks info))
6757          (active (gnus-active group)))
6758     (and info active
6759          (gnus-list-range-difference
6760           (gnus-list-range-difference
6761            (gnus-sorted-complement
6762             (gnus-uncompress-range
6763              (if gnus-newsgroup-maximum-articles
6764                  (cons (max (car active)
6765                             (- (cdr active)
6766                                gnus-newsgroup-maximum-articles
6767                                -1))
6768                        (cdr active))
6769                active))
6770             (gnus-list-of-unread-articles group))
6771            (cdr (assq 'dormant marked)))
6772           (cdr (assq 'tick marked))))))
6773
6774 ;; This function returns a sequence of article numbers based on the
6775 ;; difference between the ranges of read articles in this group and
6776 ;; the range of active articles.
6777 (defun gnus-sequence-of-unread-articles (group)
6778   (let* ((read (gnus-info-read (gnus-get-info group)))
6779          (active (or (gnus-active group) (gnus-activate-group group)))
6780          (last (cdr active))
6781          (bottom (if gnus-newsgroup-maximum-articles
6782                      (max (car active)
6783                           (- last gnus-newsgroup-maximum-articles -1))
6784                    (car active)))
6785          first nlast unread)
6786     ;; If none are read, then all are unread.
6787     (if (not read)
6788         (setq first bottom)
6789       ;; If the range of read articles is a single range, then the
6790       ;; first unread article is the article after the last read
6791       ;; article.  Sounds logical, doesn't it?
6792       (if (and (not (listp (cdr read)))
6793                (or (< (car read) bottom)
6794                    (progn (setq read (list read))
6795                           nil)))
6796           (setq first (max bottom (1+ (cdr read))))
6797         ;; `read' is a list of ranges.
6798         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6799                                   (caar read)))
6800                   1)
6801           (setq first bottom))
6802         (while read
6803           (when first
6804             (push (cons first nlast) unread))
6805           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6806           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6807           (setq read (cdr read)))))
6808     ;; And add the last unread articles.
6809     (cond ((not (and first last))
6810            nil)
6811           ((< first last)
6812            (push (cons first last) unread))
6813           ((= first last)
6814            (push first unread)))
6815     ;; Return the sequence of unread articles.
6816     (delq 0 (nreverse unread))))
6817
6818 ;; Various summary commands
6819
6820 (defun gnus-summary-select-article-buffer ()
6821   "Reconfigure windows to show article buffer."
6822   (interactive)
6823   (if (not (gnus-buffer-live-p gnus-article-buffer))
6824       (error "There is no article buffer for this summary buffer")
6825     (gnus-configure-windows 'article)
6826     (select-window (get-buffer-window gnus-article-buffer))))
6827
6828 (defun gnus-summary-universal-argument (arg)
6829   "Perform any operation on all articles that are process/prefixed."
6830   (interactive "P")
6831   (let ((articles (gnus-summary-work-articles arg))
6832         func article)
6833     (if (eq
6834          (setq
6835           func
6836           (key-binding
6837            (read-key-sequence
6838             (substitute-command-keys
6839              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6840          'undefined)
6841         (gnus-error 1 "Undefined key")
6842       (save-excursion
6843         (while articles
6844           (gnus-summary-goto-subject (setq article (pop articles)))
6845           (let (gnus-newsgroup-processable)
6846             (command-execute func))
6847           (gnus-summary-remove-process-mark article)))))
6848   (gnus-summary-position-point))
6849
6850 (defun gnus-summary-toggle-truncation (&optional arg)
6851   "Toggle truncation of summary lines.
6852 With ARG, turn line truncation on if ARG is positive."
6853   (interactive "P")
6854   (setq truncate-lines
6855         (if (null arg) (not truncate-lines)
6856           (> (prefix-numeric-value arg) 0)))
6857   (redraw-display))
6858
6859 (defun gnus-summary-find-for-reselect ()
6860   "Return the number of an article to stay on across a reselect.
6861 The current article is considered, then following articles, then previous
6862 articles.  An article is sought which is not cancelled and isn't a temporary
6863 insertion from another group.  If there's no such then return a dummy 0."
6864   (let (found)
6865     (dolist (rev '(nil t))
6866       (unless found      ; don't demand the reverse list if we don't need it
6867         (let ((data (gnus-data-find-list
6868                      (gnus-summary-article-number) (gnus-data-list rev))))
6869           (while (and data (not found))
6870             (if (and (< 0 (gnus-data-number (car data)))
6871                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6872                 (setq found (gnus-data-number (car data))))
6873             (setq data (cdr data))))))
6874     (or found 0)))
6875
6876 (defun gnus-summary-reselect-current-group (&optional all rescan)
6877   "Exit and then reselect the current newsgroup.
6878 The prefix argument ALL means to select all articles."
6879   (interactive "P")
6880   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6881     (error "Ephemeral groups can't be reselected"))
6882   (let ((current-subject (gnus-summary-find-for-reselect))
6883         (group gnus-newsgroup-name))
6884     (setq gnus-newsgroup-begin nil)
6885     (gnus-summary-exit nil 'leave-hidden)
6886     ;; We have to adjust the point of group mode buffer because
6887     ;; point was moved to the next unread newsgroup by exiting.
6888     (gnus-summary-jump-to-group group)
6889     (when rescan
6890       (save-excursion
6891         (gnus-group-get-new-news-this-group 1)))
6892     (gnus-group-read-group all t)
6893     (gnus-summary-goto-subject current-subject nil t)))
6894
6895 (defun gnus-summary-rescan-group (&optional all)
6896   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6897   (interactive "P")
6898   (gnus-summary-reselect-current-group all t))
6899
6900 (defun gnus-summary-update-info (&optional non-destructive)
6901   (save-excursion
6902     (let ((group gnus-newsgroup-name))
6903       (when group
6904         (when gnus-newsgroup-kill-headers
6905           (setq gnus-newsgroup-killed
6906                 (gnus-compress-sequence
6907                  (gnus-sorted-union
6908                   (gnus-list-range-intersection
6909                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6910                   gnus-newsgroup-unreads)
6911                  t)))
6912         (unless (listp (cdr gnus-newsgroup-killed))
6913           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6914         (let ((headers gnus-newsgroup-headers))
6915           ;; Set the new ranges of read articles.
6916           (with-current-buffer gnus-group-buffer
6917             (gnus-undo-force-boundary))
6918           (gnus-update-read-articles
6919            group (gnus-sorted-union
6920                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6921           ;; Set the current article marks.
6922           (let ((gnus-newsgroup-scored
6923                  (if (and (not gnus-save-score)
6924                           (not non-destructive))
6925                      nil
6926                    gnus-newsgroup-scored)))
6927             (save-excursion
6928               (gnus-update-marks)))
6929           ;; Do the cross-ref thing.
6930           (when gnus-use-cross-reference
6931             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6932           ;; Do not switch windows but change the buffer to work.
6933           (set-buffer gnus-group-buffer)
6934           (unless (gnus-ephemeral-group-p group)
6935             (gnus-group-update-group group)))))))
6936
6937 (defun gnus-summary-save-newsrc (&optional force)
6938   "Save the current number of read/marked articles in the dribble buffer.
6939 The dribble buffer will then be saved.
6940 If FORCE (the prefix), also save the .newsrc file(s)."
6941   (interactive "P")
6942   (gnus-summary-update-info t)
6943   (if force
6944       (gnus-save-newsrc-file)
6945     (gnus-dribble-save)))
6946
6947 (defun gnus-summary-exit (&optional temporary leave-hidden)
6948   "Exit reading current newsgroup, and then return to group selection mode.
6949 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6950   (interactive)
6951   (gnus-set-global-variables)
6952   (when (gnus-buffer-live-p gnus-article-buffer)
6953     (save-excursion
6954       (set-buffer gnus-article-buffer)
6955       (mm-destroy-parts gnus-article-mime-handles)
6956       ;; Set it to nil for safety reason.
6957       (setq gnus-article-mime-handle-alist nil)
6958       (setq gnus-article-mime-handles nil)))
6959   (gnus-kill-save-kill-buffer)
6960   (gnus-async-halt-prefetch)
6961   (let* ((group gnus-newsgroup-name)
6962          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6963          (gnus-group-is-exiting-p t)
6964          (mode major-mode)
6965          (group-point nil)
6966          (buf (current-buffer)))
6967     (unless quit-config
6968       ;; Do adaptive scoring, and possibly save score files.
6969       (when gnus-newsgroup-adaptive
6970         (gnus-score-adaptive))
6971       (when gnus-use-scoring
6972         (gnus-score-save)))
6973     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6974     ;; If we have several article buffers, we kill them at exit.
6975     (unless gnus-single-article-buffer
6976       (when (gnus-buffer-live-p gnus-article-buffer)
6977         (with-current-buffer gnus-article-buffer
6978           ;; Don't kill sticky article buffers
6979           (unless (eq major-mode 'gnus-sticky-article-mode)
6980             (gnus-kill-buffer gnus-article-buffer)
6981             (setq gnus-article-current nil))))
6982       (gnus-kill-buffer gnus-original-article-buffer))
6983     (when gnus-use-cache
6984       (gnus-cache-possibly-remove-articles)
6985       (gnus-cache-save-buffers))
6986     (gnus-async-prefetch-remove-group group)
6987     (when gnus-suppress-duplicates
6988       (gnus-dup-enter-articles))
6989     (when gnus-use-trees
6990       (gnus-tree-close group))
6991     (when gnus-use-cache
6992       (gnus-cache-write-active))
6993     ;; Remove entries for this group.
6994     (nnmail-purge-split-history (gnus-group-real-name group))
6995     ;; Make all changes in this group permanent.
6996     (unless quit-config
6997       (gnus-run-hooks 'gnus-exit-group-hook)
6998       (gnus-summary-update-info))
6999     (gnus-close-group group)
7000     ;; Make sure where we were, and go to next newsgroup.
7001     (set-buffer gnus-group-buffer)
7002     (unless quit-config
7003       (gnus-group-jump-to-group group))
7004     (gnus-run-hooks 'gnus-summary-exit-hook)
7005     (unless (or quit-config
7006                 (not gnus-summary-next-group-on-exit)
7007                 ;; If this group has disappeared from the summary
7008                 ;; buffer, don't skip forwards.
7009                 (not (string= group (gnus-group-group-name))))
7010       (gnus-group-next-unread-group 1))
7011     (setq group-point (point))
7012     (if temporary
7013         nil                             ;Nothing to do.
7014       (set-buffer buf)
7015       (if (not gnus-kill-summary-on-exit)
7016           (progn
7017             (gnus-deaden-summary)
7018             (setq mode nil))
7019         ;; We set all buffer-local variables to nil.  It is unclear why
7020         ;; this is needed, but if we don't, buffer-local variables are
7021         ;; not garbage-collected, it seems.  This would the lead to en
7022         ;; ever-growing Emacs.
7023         (gnus-summary-clear-local-variables)
7024         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7025           (gnus-summary-clear-local-variables))
7026         (when (get-buffer gnus-article-buffer)
7027           (bury-buffer gnus-article-buffer))
7028         ;; Return to group mode buffer.
7029         (when (eq mode 'gnus-summary-mode)
7030           (gnus-kill-buffer buf)))
7031       (setq gnus-current-select-method gnus-select-method)
7032       (set-buffer gnus-group-buffer)
7033       (if quit-config
7034           (gnus-handle-ephemeral-exit quit-config)
7035         (goto-char group-point)
7036         ;; If gnus-group-buffer is already displayed, make sure we also move
7037         ;; the cursor in the window that displays it.
7038         (let ((win (get-buffer-window (current-buffer) 0)))
7039           (if win (set-window-point win (point))))
7040         (unless leave-hidden
7041           (gnus-configure-windows 'group 'force)))
7042       ;; Clear the current group name.
7043       (unless quit-config
7044         (setq gnus-newsgroup-name nil)))))
7045
7046 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7047 (defun gnus-summary-exit-no-update (&optional no-questions)
7048   "Quit reading current newsgroup without updating read article info."
7049   (interactive)
7050   (let* ((group gnus-newsgroup-name)
7051          (gnus-group-is-exiting-p t)
7052          (gnus-group-is-exiting-without-update-p t)
7053          (quit-config (gnus-group-quit-config group)))
7054     (when (or no-questions
7055               gnus-expert-user
7056               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7057       (gnus-async-halt-prefetch)
7058       (run-hooks 'gnus-summary-prepare-exit-hook)
7059       (when (gnus-buffer-live-p gnus-article-buffer)
7060         (save-excursion
7061           (set-buffer gnus-article-buffer)
7062           (mm-destroy-parts gnus-article-mime-handles)
7063           ;; Set it to nil for safety reason.
7064           (setq gnus-article-mime-handle-alist nil)
7065           (setq gnus-article-mime-handles nil)))
7066       ;; If we have several article buffers, we kill them at exit.
7067       (unless gnus-single-article-buffer
7068         (gnus-kill-buffer gnus-article-buffer)
7069         (gnus-kill-buffer gnus-original-article-buffer)
7070         (setq gnus-article-current nil))
7071       (if (not gnus-kill-summary-on-exit)
7072           (gnus-deaden-summary)
7073         (gnus-close-group group)
7074         (gnus-summary-clear-local-variables)
7075         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7076           (gnus-summary-clear-local-variables))
7077         (gnus-kill-buffer gnus-summary-buffer))
7078       (unless gnus-single-article-buffer
7079         (setq gnus-article-current nil))
7080       (when gnus-use-trees
7081         (gnus-tree-close group))
7082       (gnus-async-prefetch-remove-group group)
7083       (when (get-buffer gnus-article-buffer)
7084         (bury-buffer gnus-article-buffer))
7085       ;; Return to the group buffer.
7086       (gnus-configure-windows 'group 'force)
7087       ;; Clear the current group name.
7088       (setq gnus-newsgroup-name nil)
7089       (unless (gnus-ephemeral-group-p group)
7090         (gnus-group-update-group group))
7091       (when (equal (gnus-group-group-name) group)
7092         (gnus-group-next-unread-group 1))
7093       (when quit-config
7094         (gnus-handle-ephemeral-exit quit-config)))))
7095
7096 (defun gnus-handle-ephemeral-exit (quit-config)
7097   "Handle movement when leaving an ephemeral group.
7098 The state which existed when entering the ephemeral is reset."
7099   (if (not (buffer-name (car quit-config)))
7100       (gnus-configure-windows 'group 'force)
7101     (set-buffer (car quit-config))
7102     (cond ((eq major-mode 'gnus-summary-mode)
7103            (gnus-set-global-variables))
7104           ((eq major-mode 'gnus-article-mode)
7105            (save-excursion
7106              ;; The `gnus-summary-buffer' variable may point
7107              ;; to the old summary buffer when using a single
7108              ;; article buffer.
7109              (unless (gnus-buffer-live-p gnus-summary-buffer)
7110                (set-buffer gnus-group-buffer))
7111              (set-buffer gnus-summary-buffer)
7112              (gnus-set-global-variables))))
7113     (if (or (eq (cdr quit-config) 'article)
7114             (eq (cdr quit-config) 'pick))
7115         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7116             (gnus-configure-windows 'pick 'force)
7117           (gnus-configure-windows (cdr quit-config) 'force))
7118       (gnus-configure-windows (cdr quit-config) 'force))
7119     (when (eq major-mode 'gnus-summary-mode)
7120       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7121                                                      next-unread-noselect))
7122           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7123                                   'next-noselect)
7124                               (gnus-summary-next-subject 1 nil t))
7125                              ((eq gnus-auto-select-on-ephemeral-exit
7126                                   'next-unread-noselect)
7127                               (gnus-summary-next-subject 1 t t))))
7128             ;; Hide the article buffer which displays the article different
7129             ;; from the one that the cursor points to in the summary buffer.
7130             (gnus-configure-windows 'summary 'force))
7131         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7132                (gnus-summary-next-subject 1))
7133               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7134                (gnus-summary-next-subject 1 t))))
7135       (gnus-summary-recenter)
7136       (gnus-summary-position-point))))
7137
7138 ;;; Dead summaries.
7139
7140 (defvar gnus-dead-summary-mode-map nil)
7141
7142 (unless gnus-dead-summary-mode-map
7143   (setq gnus-dead-summary-mode-map (make-keymap))
7144   (suppress-keymap gnus-dead-summary-mode-map)
7145   (substitute-key-definition
7146    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7147   (dolist (key '("\C-d" "\r" "\177" [delete]))
7148     (define-key gnus-dead-summary-mode-map
7149       key 'gnus-summary-wake-up-the-dead))
7150   (dolist (key '("q" "Q"))
7151     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7152
7153 (defvar gnus-dead-summary-mode nil
7154   "Minor mode for Gnus summary buffers.")
7155
7156 (defun gnus-dead-summary-mode (&optional arg)
7157   "Minor mode for Gnus summary buffers."
7158   (interactive "P")
7159   (when (eq major-mode 'gnus-summary-mode)
7160     (make-local-variable 'gnus-dead-summary-mode)
7161     (setq gnus-dead-summary-mode
7162           (if (null arg) (not gnus-dead-summary-mode)
7163             (> (prefix-numeric-value arg) 0)))
7164     (when gnus-dead-summary-mode
7165       (add-minor-mode
7166        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7167
7168 (defun gnus-deaden-summary ()
7169   "Make the current summary buffer into a dead summary buffer."
7170   ;; Kill any previous dead summary buffer.
7171   (when (and gnus-dead-summary
7172              (buffer-name gnus-dead-summary))
7173     (with-current-buffer gnus-dead-summary
7174       (when gnus-dead-summary-mode
7175         (kill-buffer (current-buffer)))))
7176   ;; Make this the current dead summary.
7177   (setq gnus-dead-summary (current-buffer))
7178   (gnus-dead-summary-mode 1)
7179   (let ((name (buffer-name)))
7180     (when (string-match "Summary" name)
7181       (rename-buffer
7182        (concat (substring name 0 (match-beginning 0)) "Dead "
7183                (substring name (match-beginning 0)))
7184        t)
7185       (bury-buffer))))
7186
7187 (defun gnus-kill-or-deaden-summary (buffer)
7188   "Kill or deaden the summary BUFFER."
7189   (save-excursion
7190     (when (and (buffer-name buffer)
7191                (not gnus-single-article-buffer))
7192       (with-current-buffer buffer
7193         (gnus-kill-buffer gnus-article-buffer)
7194         (gnus-kill-buffer gnus-original-article-buffer)))
7195     (cond
7196      ;; Kill the buffer.
7197      (gnus-kill-summary-on-exit
7198       (when (and gnus-use-trees
7199                  (gnus-buffer-exists-p buffer))
7200         (save-excursion
7201           (set-buffer buffer)
7202           (gnus-tree-close gnus-newsgroup-name)))
7203       (gnus-kill-buffer buffer))
7204      ;; Deaden the buffer.
7205      ((gnus-buffer-exists-p buffer)
7206       (save-excursion
7207         (set-buffer buffer)
7208         (gnus-deaden-summary))))))
7209
7210 (defun gnus-summary-wake-up-the-dead (&rest args)
7211   "Wake up the dead summary buffer."
7212   (interactive)
7213   (gnus-dead-summary-mode -1)
7214   (let ((name (buffer-name)))
7215     (when (string-match "Dead " name)
7216       (rename-buffer
7217        (concat (substring name 0 (match-beginning 0))
7218                (substring name (match-end 0)))
7219        t)))
7220   (gnus-message 3 "This dead summary is now alive again"))
7221
7222 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7223 (defun gnus-summary-fetch-faq (&optional faq-dir)
7224   "Fetch the FAQ for the current group.
7225 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7226 in."
7227   (interactive
7228    (list
7229     (when current-prefix-arg
7230       (completing-read
7231        "FAQ dir: " (and (listp gnus-group-faq-directory)
7232                         (mapcar 'list
7233                                 gnus-group-faq-directory))))))
7234   (let (gnus-faq-buffer)
7235     (when (setq gnus-faq-buffer
7236                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7237       (gnus-configure-windows 'summary-faq))))
7238
7239 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7240 (defun gnus-summary-describe-group (&optional force)
7241   "Describe the current newsgroup."
7242   (interactive "P")
7243   (gnus-group-describe-group force gnus-newsgroup-name))
7244
7245 (defun gnus-summary-describe-briefly ()
7246   "Describe summary mode commands briefly."
7247   (interactive)
7248   (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")))
7249
7250 ;; Walking around group mode buffer from summary mode.
7251
7252 (defun gnus-summary-next-group (&optional no-article target-group backward)
7253   "Exit current newsgroup and then select next unread newsgroup.
7254 If prefix argument NO-ARTICLE is non-nil, no article is selected
7255 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7256 previous group instead."
7257   (interactive "P")
7258   ;; Stop pre-fetching.
7259   (gnus-async-halt-prefetch)
7260   (let ((current-group gnus-newsgroup-name)
7261         (current-buffer (current-buffer))
7262         entered)
7263     ;; First we semi-exit this group to update Xrefs and all variables.
7264     ;; We can't do a real exit, because the window conf must remain
7265     ;; the same in case the user is prompted for info, and we don't
7266     ;; want the window conf to change before that...
7267     (gnus-summary-exit t)
7268     (while (not entered)
7269       ;; Then we find what group we are supposed to enter.
7270       (set-buffer gnus-group-buffer)
7271       (gnus-group-jump-to-group current-group)
7272       (setq target-group
7273             (or target-group
7274                 (if (eq gnus-keep-same-level 'best)
7275                     (gnus-summary-best-group gnus-newsgroup-name)
7276                   (gnus-summary-search-group backward gnus-keep-same-level))))
7277       (if (not target-group)
7278           ;; There are no further groups, so we return to the group
7279           ;; buffer.
7280           (progn
7281             (gnus-message 5 "Returning to the group buffer")
7282             (setq entered t)
7283             (when (gnus-buffer-live-p current-buffer)
7284               (set-buffer current-buffer)
7285               (gnus-summary-exit))
7286             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7287         ;; We try to enter the target group.
7288         (gnus-group-jump-to-group target-group)
7289         (let ((unreads (gnus-group-group-unread)))
7290           (if (and (or (eq t unreads)
7291                        (and unreads (not (zerop unreads))))
7292                    (gnus-summary-read-group
7293                     target-group nil no-article
7294                     (and (buffer-name current-buffer) current-buffer)
7295                     nil backward))
7296               (setq entered t)
7297             (setq current-group target-group
7298                   target-group nil)))))))
7299
7300 (defun gnus-summary-prev-group (&optional no-article)
7301   "Exit current newsgroup and then select previous unread newsgroup.
7302 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7303   (interactive "P")
7304   (gnus-summary-next-group no-article nil t))
7305
7306 ;; Walking around summary lines.
7307
7308 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7309   "Go to the first subject satisfying any non-nil constraint.
7310 If UNREAD is non-nil, the article should be unread.
7311 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7312 If UNSEEN is non-nil, the article should be unseen.
7313 Returns the article selected or nil if there are no matching articles."
7314   (interactive "P")
7315   (cond
7316    ;; Empty summary.
7317    ((null gnus-newsgroup-data)
7318     (gnus-message 3 "No articles in the group")
7319     nil)
7320    ;; Pick the first article.
7321    ((not (or unread undownloaded unseen))
7322     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7323     (gnus-data-number (car gnus-newsgroup-data)))
7324    ;; Find the first unread article.
7325    (t
7326     (let ((data gnus-newsgroup-data))
7327       (while (and data
7328                   (let ((num (gnus-data-number (car data))))
7329                     (or (memq num gnus-newsgroup-unfetched)
7330                         (not (or (and unread
7331                                       (memq num gnus-newsgroup-unreads))
7332                                  (and undownloaded
7333                                       (memq num gnus-newsgroup-undownloaded))
7334                                  (and unseen
7335                                       (memq num gnus-newsgroup-unseen)))))))
7336         (setq data (cdr data)))
7337       (prog1
7338           (if data
7339               (progn
7340                 (goto-char (gnus-data-pos (car data)))
7341                 (gnus-data-number (car data)))
7342             (gnus-message 3 "No more%s articles"
7343                           (let* ((r (when unread " unread"))
7344                                  (d (when undownloaded " undownloaded"))
7345                                  (s (when unseen " unseen"))
7346                                  (l (delq nil (list r d s))))
7347                             (cond ((= 3 (length l))
7348                                    (concat r "," d ", or" s))
7349                                   ((= 2 (length l))
7350                                    (concat (car l) ", or" (cadr l)))
7351                                   ((= 1 (length l))
7352                                    (car l))
7353                                   (t
7354                                    ""))))
7355             nil
7356             )
7357         (gnus-summary-position-point))))))
7358
7359 (defun gnus-summary-next-subject (n &optional unread dont-display)
7360   "Go to next N'th summary line.
7361 If N is negative, go to the previous N'th subject line.
7362 If UNREAD is non-nil, only unread articles are selected.
7363 The difference between N and the actual number of steps taken is
7364 returned."
7365   (interactive "p")
7366   (let ((backward (< n 0))
7367         (n (abs n)))
7368     (while (and (> n 0)
7369                 (if backward
7370                     (gnus-summary-find-prev unread)
7371                   (gnus-summary-find-next unread)))
7372       (unless (zerop (setq n (1- n)))
7373         (gnus-summary-show-thread)))
7374     (when (/= 0 n)
7375       (gnus-message 7 "No more%s articles"
7376                     (if unread " unread" "")))
7377     (unless dont-display
7378       (gnus-summary-recenter)
7379       (gnus-summary-position-point))
7380     n))
7381
7382 (defun gnus-summary-next-unread-subject (n)
7383   "Go to next N'th unread summary line."
7384   (interactive "p")
7385   (gnus-summary-next-subject n t))
7386
7387 (defun gnus-summary-prev-subject (n &optional unread)
7388   "Go to previous N'th summary line.
7389 If optional argument UNREAD is non-nil, only unread article is selected."
7390   (interactive "p")
7391   (gnus-summary-next-subject (- n) unread))
7392
7393 (defun gnus-summary-prev-unread-subject (n)
7394   "Go to previous N'th unread summary line."
7395   (interactive "p")
7396   (gnus-summary-next-subject (- n) t))
7397
7398 (defun gnus-summary-goto-subjects (articles)
7399   "Insert the subject header for ARTICLES in the current buffer."
7400   (save-excursion
7401     (dolist (article articles)
7402       (gnus-summary-goto-subject article t)))
7403   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7404   (gnus-summary-position-point))
7405
7406 (defun gnus-summary-goto-subject (article &optional force silent)
7407   "Go the subject line of ARTICLE.
7408 If FORCE, also allow jumping to articles not currently shown."
7409   (interactive "nArticle number: ")
7410   (unless (numberp article)
7411     (error "Article %s is not a number" article))
7412   (let ((b (point))
7413         (data (gnus-data-find article)))
7414     ;; We read in the article if we have to.
7415     (and (not data)
7416          force
7417          (gnus-summary-insert-subject
7418           article
7419           (if (or (numberp force) (vectorp force)) force)
7420           t)
7421          (setq data (gnus-data-find article)))
7422     (goto-char b)
7423     (if (not data)
7424         (progn
7425           (unless silent
7426             (gnus-message 3 "Can't find article %d" article))
7427           nil)
7428       (let ((pt (gnus-data-pos data)))
7429         (goto-char pt)
7430         (gnus-summary-set-article-display-arrow pt))
7431       (gnus-summary-position-point)
7432       article)))
7433
7434 ;; Walking around summary lines with displaying articles.
7435
7436 (defun gnus-summary-expand-window (&optional arg)
7437   "Make the summary buffer take up the entire Emacs frame.
7438 Given a prefix, will force an `article' buffer configuration."
7439   (interactive "P")
7440   (if arg
7441       (gnus-configure-windows 'article 'force)
7442     (gnus-configure-windows 'summary 'force)))
7443
7444 (defun gnus-summary-display-article (article &optional all-header)
7445   "Display ARTICLE in article buffer."
7446   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7447                (with-current-buffer gnus-article-buffer
7448                  (eq major-mode 'gnus-article-mode)))
7449     (gnus-article-setup-buffer))
7450   (gnus-set-global-variables)
7451   (with-current-buffer gnus-article-buffer
7452     (setq gnus-article-charset gnus-newsgroup-charset)
7453     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7454     (mm-enable-multibyte))
7455   (if (null article)
7456       nil
7457     (prog1
7458         (if gnus-summary-display-article-function
7459             (funcall gnus-summary-display-article-function article all-header)
7460           (gnus-article-prepare article all-header))
7461       (gnus-run-hooks 'gnus-select-article-hook)
7462       (when (and gnus-current-article
7463                  (not (zerop gnus-current-article)))
7464         (gnus-summary-goto-subject gnus-current-article))
7465       (gnus-summary-recenter)
7466       (when (and gnus-use-trees gnus-show-threads)
7467         (gnus-possibly-generate-tree article)
7468         (gnus-highlight-selected-tree article))
7469       ;; Successfully display article.
7470       (gnus-article-set-window-start
7471        (cdr (assq article gnus-newsgroup-bookmarks))))))
7472
7473 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7474   "Select the current article.
7475 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7476 non-nil, the article will be re-fetched even if it already present in
7477 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7478 be displayed."
7479   ;; Make sure we are in the summary buffer to work around bbdb bug.
7480   (unless (eq major-mode 'gnus-summary-mode)
7481     (set-buffer gnus-summary-buffer))
7482   (let ((article (or article (gnus-summary-article-number)))
7483         (all-headers (not (not all-headers))) ;Must be t or nil.
7484         gnus-summary-display-article-function)
7485     (and (not pseudo)
7486          (gnus-summary-article-pseudo-p article)
7487          (error "This is a pseudo-article"))
7488     (save-excursion
7489       (set-buffer gnus-summary-buffer)
7490       (if (or (and gnus-single-article-buffer
7491                    (or (null gnus-current-article)
7492                        (null gnus-article-current)
7493                        (null (get-buffer gnus-article-buffer))
7494                        (not (eq article (cdr gnus-article-current)))
7495                        (not (equal (car gnus-article-current)
7496                                    gnus-newsgroup-name))))
7497               (and (not gnus-single-article-buffer)
7498                    (or (null gnus-current-article)
7499                        (not (eq gnus-current-article article))))
7500               force)
7501           ;; The requested article is different from the current article.
7502           (progn
7503             (gnus-summary-display-article article all-headers)
7504             (when (gnus-buffer-live-p gnus-article-buffer)
7505               (with-current-buffer gnus-article-buffer
7506                 (if (not gnus-article-decoded-p) ;; a local variable
7507                     (mm-disable-multibyte))))
7508             (gnus-article-set-window-start
7509              (cdr (assq article gnus-newsgroup-bookmarks)))
7510             article)
7511         'old))))
7512
7513 (defun gnus-summary-force-verify-and-decrypt ()
7514   "Display buttons for signed/encrypted parts and verify/decrypt them."
7515   (interactive)
7516   (let ((mm-verify-option 'known)
7517         (mm-decrypt-option 'known)
7518         (gnus-article-emulate-mime t)
7519         (gnus-buttonized-mime-types (append (list "multipart/signed"
7520                                                   "multipart/encrypted")
7521                                             gnus-buttonized-mime-types)))
7522     (gnus-summary-select-article nil 'force)))
7523
7524 (defun gnus-summary-set-current-mark (&optional current-mark)
7525   "Obsolete function."
7526   nil)
7527
7528 (defun gnus-summary-next-article (&optional unread subject backward push)
7529   "Select the next article.
7530 If UNREAD, only unread articles are selected.
7531 If SUBJECT, only articles with SUBJECT are selected.
7532 If BACKWARD, the previous article is selected instead of the next."
7533   (interactive "P")
7534   ;; Make sure we are in the summary buffer.
7535   (unless (eq major-mode 'gnus-summary-mode)
7536     (set-buffer gnus-summary-buffer))
7537   (cond
7538    ;; Is there such an article?
7539    ((and (gnus-summary-search-forward unread subject backward)
7540          (or (gnus-summary-display-article (gnus-summary-article-number))
7541              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7542     (gnus-summary-position-point))
7543    ;; If not, we try the first unread, if that is wanted.
7544    ((and subject
7545          gnus-auto-select-same
7546          (gnus-summary-first-unread-article))
7547     (gnus-summary-position-point)
7548     (gnus-message 6 "Wrapped"))
7549    ;; Try to get next/previous article not displayed in this group.
7550    ((and gnus-auto-extend-newsgroup
7551          (not unread) (not subject))
7552     (gnus-summary-goto-article
7553      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7554      nil (count-lines (point-min) (point))))
7555    ;; Go to next/previous group.
7556    (t
7557     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7558       (gnus-summary-jump-to-group gnus-newsgroup-name))
7559     (let ((cmd last-command-char)
7560           (point
7561            (with-current-buffer gnus-group-buffer
7562              (point)))
7563           (group
7564            (if (eq gnus-keep-same-level 'best)
7565                (gnus-summary-best-group gnus-newsgroup-name)
7566              (gnus-summary-search-group backward gnus-keep-same-level))))
7567       ;; For some reason, the group window gets selected.  We change
7568       ;; it back.
7569       (select-window (get-buffer-window (current-buffer)))
7570       ;; Select next unread newsgroup automagically.
7571       (cond
7572        ((or (not gnus-auto-select-next)
7573             (not cmd))
7574         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7575        ((or (eq gnus-auto-select-next 'quietly)
7576             (and (eq gnus-auto-select-next 'slightly-quietly)
7577                  push)
7578             (and (eq gnus-auto-select-next 'almost-quietly)
7579                  (gnus-summary-last-article-p)))
7580         ;; Select quietly.
7581         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7582             (gnus-summary-exit)
7583           (gnus-message 7 "No more%s articles (%s)..."
7584                         (if unread " unread" "")
7585                         (if group (concat "selecting " group)
7586                           "exiting"))
7587           (gnus-summary-next-group nil group backward)))
7588        (t
7589         (when (gnus-key-press-event-p last-input-event)
7590           (gnus-summary-walk-group-buffer
7591            gnus-newsgroup-name cmd unread backward point))))))))
7592
7593 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7594   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7595                       (?\C-p (gnus-group-prev-unread-group 1))))
7596         (cursor-in-echo-area t)
7597         keve key group ended prompt)
7598     (save-excursion
7599       (set-buffer gnus-group-buffer)
7600       (goto-char start)
7601       (setq group
7602             (if (eq gnus-keep-same-level 'best)
7603                 (gnus-summary-best-group gnus-newsgroup-name)
7604               (gnus-summary-search-group backward gnus-keep-same-level))))
7605     (while (not ended)
7606       (setq prompt
7607             (format
7608              "No more%s articles%s " (if unread " unread" "")
7609              (if (and group
7610                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7611                  (format " (Type %s for %s [%s])"
7612                          (single-key-description cmd)
7613                          (gnus-group-decoded-name group)
7614                          (gnus-group-unread group))
7615                (format " (Type %s to exit %s)"
7616                        (single-key-description cmd)
7617                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7618       ;; Confirm auto selection.
7619       (setq key (car (setq keve (gnus-read-event-char prompt)))
7620             ended t)
7621       (cond
7622        ((assq key keystrokes)
7623         (let ((obuf (current-buffer)))
7624           (switch-to-buffer gnus-group-buffer)
7625           (when group
7626             (gnus-group-jump-to-group group))
7627           (eval (cadr (assq key keystrokes)))
7628           (setq group (gnus-group-group-name))
7629           (switch-to-buffer obuf))
7630         (setq ended nil))
7631        ((equal key cmd)
7632         (if (or (not group)
7633                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7634             (gnus-summary-exit)
7635           (gnus-summary-next-group nil group backward)))
7636        (t
7637         (push (cdr keve) unread-command-events))))))
7638
7639 (defun gnus-summary-next-unread-article ()
7640   "Select unread article after current one."
7641   (interactive)
7642   (gnus-summary-next-article
7643    (or (not (eq gnus-summary-goto-unread 'never))
7644        (gnus-summary-last-article-p (gnus-summary-article-number)))
7645    (and gnus-auto-select-same
7646         (gnus-summary-article-subject))))
7647
7648 (defun gnus-summary-prev-article (&optional unread subject)
7649   "Select the article after the current one.
7650 If UNREAD is non-nil, only unread articles are selected."
7651   (interactive "P")
7652   (gnus-summary-next-article unread subject t))
7653
7654 (defun gnus-summary-prev-unread-article ()
7655   "Select unread article before current one."
7656   (interactive)
7657   (gnus-summary-prev-article
7658    (or (not (eq gnus-summary-goto-unread 'never))
7659        (gnus-summary-first-article-p (gnus-summary-article-number)))
7660    (and gnus-auto-select-same
7661         (gnus-summary-article-subject))))
7662
7663 (defun gnus-summary-next-page (&optional lines circular stop)
7664   "Show next page of the selected article.
7665 If at the end of the current article, select the next article.
7666 LINES says how many lines should be scrolled up.
7667
7668 If CIRCULAR is non-nil, go to the start of the article instead of
7669 selecting the next article when reaching the end of the current
7670 article.
7671
7672 If STOP is non-nil, just stop when reaching the end of the message.
7673
7674 Also see the variable `gnus-article-skip-boring'."
7675   (interactive "P")
7676   (setq gnus-summary-buffer (current-buffer))
7677   (gnus-set-global-variables)
7678   (let ((article (gnus-summary-article-number))
7679         (article-window (get-buffer-window gnus-article-buffer t))
7680         endp)
7681     ;; If the buffer is empty, we have no article.
7682     (unless article
7683       (error "No article to select"))
7684     (gnus-configure-windows 'article)
7685     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7686         (if (and (eq gnus-summary-goto-unread 'never)
7687                  (not (gnus-summary-last-article-p article)))
7688             (gnus-summary-next-article)
7689           (gnus-summary-next-unread-article))
7690       (if (or (null gnus-current-article)
7691               (null gnus-article-current)
7692               (/= article (cdr gnus-article-current))
7693               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7694           ;; Selected subject is different from current article's.
7695           (gnus-summary-display-article article)
7696         (when article-window
7697           (gnus-eval-in-buffer-window gnus-article-buffer
7698             (setq endp (or (gnus-article-next-page lines)
7699                            (gnus-article-only-boring-p))))
7700           (when endp
7701             (cond (stop
7702                    (gnus-message 3 "End of message"))
7703                   (circular
7704                    (gnus-summary-beginning-of-article))
7705                   (lines
7706                    (gnus-message 3 "End of message"))
7707                   ((null lines)
7708                    (if (and (eq gnus-summary-goto-unread 'never)
7709                             (not (gnus-summary-last-article-p article)))
7710                        (gnus-summary-next-article)
7711                      (gnus-summary-next-unread-article))))))))
7712     (gnus-summary-recenter)
7713     (gnus-summary-position-point)))
7714
7715 (defun gnus-summary-prev-page (&optional lines move)
7716   "Show previous page of selected article.
7717 Argument LINES specifies lines to be scrolled down.
7718 If MOVE, move to the previous unread article if point is at
7719 the beginning of the buffer."
7720   (interactive "P")
7721   (let ((article (gnus-summary-article-number))
7722         (article-window (get-buffer-window gnus-article-buffer t))
7723         endp)
7724     (gnus-configure-windows 'article)
7725     (if (or (null gnus-current-article)
7726             (null gnus-article-current)
7727             (/= article (cdr gnus-article-current))
7728             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7729         ;; Selected subject is different from current article's.
7730         (gnus-summary-display-article article)
7731       (gnus-summary-recenter)
7732       (when article-window
7733         (gnus-eval-in-buffer-window gnus-article-buffer
7734           (setq endp (gnus-article-prev-page lines)))
7735         (when (and move endp)
7736           (cond (lines
7737                  (gnus-message 3 "Beginning of message"))
7738                 ((null lines)
7739                  (if (and (eq gnus-summary-goto-unread 'never)
7740                           (not (gnus-summary-first-article-p article)))
7741                      (gnus-summary-prev-article)
7742                    (gnus-summary-prev-unread-article))))))))
7743   (gnus-summary-position-point))
7744
7745 (defun gnus-summary-prev-page-or-article (&optional lines)
7746   "Show previous page of selected article.
7747 Argument LINES specifies lines to be scrolled down.
7748 If at the beginning of the article, go to the next article."
7749   (interactive "P")
7750   (gnus-summary-prev-page lines t))
7751
7752 (defun gnus-summary-scroll-up (lines)
7753   "Scroll up (or down) one line current article.
7754 Argument LINES specifies lines to be scrolled up (or down if negative)."
7755   (interactive "p")
7756   (gnus-configure-windows 'article)
7757   (gnus-summary-show-thread)
7758   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7759     (gnus-eval-in-buffer-window gnus-article-buffer
7760       (cond ((> lines 0)
7761              (when (gnus-article-next-page lines)
7762                (gnus-message 3 "End of message")))
7763             ((< lines 0)
7764              (gnus-article-prev-page (- lines))))))
7765   (gnus-summary-recenter)
7766   (gnus-summary-position-point))
7767
7768 (defun gnus-summary-scroll-down (lines)
7769   "Scroll down (or up) one line current article.
7770 Argument LINES specifies lines to be scrolled down (or up if negative)."
7771   (interactive "p")
7772   (gnus-summary-scroll-up (- lines)))
7773
7774 (defun gnus-summary-next-same-subject ()
7775   "Select next article which has the same subject as current one."
7776   (interactive)
7777   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7778
7779 (defun gnus-summary-prev-same-subject ()
7780   "Select previous article which has the same subject as current one."
7781   (interactive)
7782   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7783
7784 (defun gnus-summary-next-unread-same-subject ()
7785   "Select next unread article which has the same subject as current one."
7786   (interactive)
7787   (gnus-summary-next-article t (gnus-summary-article-subject)))
7788
7789 (defun gnus-summary-prev-unread-same-subject ()
7790   "Select previous unread article which has the same subject as current one."
7791   (interactive)
7792   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7793
7794 (defun gnus-summary-first-unread-article ()
7795   "Select the first unread article.
7796 Return nil if there are no unread articles."
7797   (interactive)
7798   (prog1
7799       (when (gnus-summary-first-subject t)
7800         (gnus-summary-show-thread)
7801         (gnus-summary-first-subject t)
7802         (gnus-summary-display-article (gnus-summary-article-number)))
7803     (gnus-summary-position-point)))
7804
7805 (defun gnus-summary-first-unread-subject ()
7806   "Place the point on the subject line of the first unread article.
7807 Return nil if there are no unread articles."
7808   (interactive)
7809   (prog1
7810       (when (gnus-summary-first-subject t)
7811         (gnus-summary-show-thread)
7812         (gnus-summary-first-subject t))
7813     (gnus-summary-position-point)))
7814
7815 (defun gnus-summary-first-unseen-subject ()
7816   "Place the point on the subject line of the first unseen article.
7817 Return nil if there are no unseen articles."
7818   (interactive)
7819   (prog1
7820       (when (gnus-summary-first-subject nil nil t)
7821         (gnus-summary-show-thread)
7822         (gnus-summary-first-subject nil nil t))
7823     (gnus-summary-position-point)))
7824
7825 (defun gnus-summary-first-unseen-or-unread-subject ()
7826   "Place the point on the subject line of the first unseen article or,
7827 if all article have been seen, on the subject line of the first unread
7828 article."
7829   (interactive)
7830   (prog1
7831       (unless (when (gnus-summary-first-subject nil nil t)
7832                 (gnus-summary-show-thread)
7833                 (gnus-summary-first-subject nil nil t))
7834         (when (gnus-summary-first-subject t)
7835           (gnus-summary-show-thread)
7836           (gnus-summary-first-subject t)))
7837     (gnus-summary-position-point)))
7838
7839 (defun gnus-summary-first-article ()
7840   "Select the first article.
7841 Return nil if there are no articles."
7842   (interactive)
7843   (prog1
7844       (when (gnus-summary-first-subject)
7845         (gnus-summary-show-thread)
7846         (gnus-summary-first-subject)
7847         (gnus-summary-display-article (gnus-summary-article-number)))
7848     (gnus-summary-position-point)))
7849
7850 (defun gnus-summary-best-unread-article (&optional arg)
7851   "Select the unread article with the highest score.
7852 If given a prefix argument, select the next unread article that has a
7853 score higher than the default score."
7854   (interactive "P")
7855   (let ((article (if arg
7856                      (gnus-summary-better-unread-subject)
7857                    (gnus-summary-best-unread-subject))))
7858     (if article
7859         (gnus-summary-goto-article article)
7860       (error "No unread articles"))))
7861
7862 (defun gnus-summary-best-unread-subject ()
7863   "Select the unread subject with the highest score."
7864   (interactive)
7865   (let ((best -1000000)
7866         (data gnus-newsgroup-data)
7867         article score)
7868     (while data
7869       (and (gnus-data-unread-p (car data))
7870            (> (setq score
7871                     (gnus-summary-article-score (gnus-data-number (car data))))
7872               best)
7873            (setq best score
7874                  article (gnus-data-number (car data))))
7875       (setq data (cdr data)))
7876     (when article
7877       (gnus-summary-goto-subject article))
7878     (gnus-summary-position-point)
7879     article))
7880
7881 (defun gnus-summary-better-unread-subject ()
7882   "Select the first unread subject that has a score over the default score."
7883   (interactive)
7884   (let ((data gnus-newsgroup-data)
7885         article score)
7886     (while (and (setq article (gnus-data-number (car data)))
7887                 (or (gnus-data-read-p (car data))
7888                     (not (> (gnus-summary-article-score article)
7889                             gnus-summary-default-score))))
7890       (setq data (cdr data)))
7891     (when article
7892       (gnus-summary-goto-subject article))
7893     (gnus-summary-position-point)
7894     article))
7895
7896 (defun gnus-summary-last-subject ()
7897   "Go to the last displayed subject line in the group."
7898   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7899     (when article
7900       (gnus-summary-goto-subject article))))
7901
7902 (defun gnus-summary-goto-article (article &optional all-headers force)
7903   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7904 If ALL-HEADERS is non-nil, no header lines are hidden.
7905 If FORCE, go to the article even if it isn't displayed.  If FORCE
7906 is a number, it is the line the article is to be displayed on."
7907   (interactive
7908    (list
7909     (completing-read
7910      "Article number or Message-ID: "
7911      (mapcar (lambda (number) (list (int-to-string number)))
7912              gnus-newsgroup-limit))
7913     current-prefix-arg
7914     t))
7915   (prog1
7916       (if (and (stringp article)
7917                (string-match "@\\|%40" article))
7918           (gnus-summary-refer-article article)
7919         (when (stringp article)
7920           (setq article (string-to-number article)))
7921         (if (gnus-summary-goto-subject article force)
7922             (gnus-summary-display-article article all-headers)
7923           (gnus-message 4 "Couldn't go to article %s" article) nil))
7924     (gnus-summary-position-point)))
7925
7926 (defun gnus-summary-goto-last-article ()
7927   "Go to the previously read article."
7928   (interactive)
7929   (prog1
7930       (when gnus-last-article
7931         (gnus-summary-goto-article gnus-last-article nil t))
7932     (gnus-summary-position-point)))
7933
7934 (defun gnus-summary-pop-article (number)
7935   "Pop one article off the history and go to the previous.
7936 NUMBER articles will be popped off."
7937   (interactive "p")
7938   (let (to)
7939     (setq gnus-newsgroup-history
7940           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7941     (if to
7942         (gnus-summary-goto-article (car to) nil t)
7943       (error "Article history empty")))
7944   (gnus-summary-position-point))
7945
7946 ;; Summary commands and functions for limiting the summary buffer.
7947
7948 (defun gnus-summary-limit-to-articles (n)
7949   "Limit the summary buffer to the next N articles.
7950 If not given a prefix, use the process marked articles instead."
7951   (interactive "P")
7952   (prog1
7953       (let ((articles (gnus-summary-work-articles n)))
7954         (setq gnus-newsgroup-processable nil)
7955         (gnus-summary-limit articles))
7956     (gnus-summary-position-point)))
7957
7958 (defun gnus-summary-pop-limit (&optional total)
7959   "Restore the previous limit.
7960 If given a prefix, remove all limits."
7961   (interactive "P")
7962   (when total
7963     (setq gnus-newsgroup-limits
7964           (list (mapcar (lambda (h) (mail-header-number h))
7965                         gnus-newsgroup-headers))))
7966   (unless gnus-newsgroup-limits
7967     (error "No limit to pop"))
7968   (prog1
7969       (gnus-summary-limit nil 'pop)
7970     (gnus-summary-position-point)))
7971
7972 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7973   "Limit the summary buffer to articles that have subjects that match a regexp.
7974 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7975   (interactive
7976    (list (read-string (if current-prefix-arg
7977                           "Exclude subject (regexp): "
7978                         "Limit to subject (regexp): "))
7979          nil current-prefix-arg))
7980   (unless header
7981     (setq header "subject"))
7982   (when (not (equal "" subject))
7983     (prog1
7984         (let ((articles (gnus-summary-find-matching
7985                          (or header "subject") subject 'all nil nil
7986                          not-matching)))
7987           (unless articles
7988             (error "Found no matches for \"%s\"" subject))
7989           (gnus-summary-limit articles))
7990       (gnus-summary-position-point))))
7991
7992 (defun gnus-summary-limit-to-author (from &optional not-matching)
7993   "Limit the summary buffer to articles that have authors that match a regexp.
7994 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7995   (interactive
7996    (list (read-string (if current-prefix-arg
7997                           "Exclude author (regexp): "
7998                         "Limit to author (regexp): "))
7999          current-prefix-arg))
8000   (gnus-summary-limit-to-subject from "from" not-matching))
8001
8002 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8003   "Limit the summary buffer to articles with the given RECIPIENT.
8004
8005 If NOT-MATCHING, exclude RECIPIENT.
8006
8007 To and Cc headers are checked.  You need to include them in
8008 `nnmail-extra-headers'."
8009   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8010   (interactive
8011    (list (read-string (format "%s recipient (regexp): "
8012                               (if current-prefix-arg "Exclude" "Limit to")))
8013          current-prefix-arg))
8014   (when (not (equal "" recipient))
8015     (prog1 (let* ((to
8016                    (if (memq 'To nnmail-extra-headers)
8017                        (gnus-summary-find-matching
8018                         (cons 'extra 'To) recipient 'all nil nil
8019                         not-matching)
8020                      (gnus-message
8021                       1 "`To' isn't present in `nnmail-extra-headers'")
8022                      (sit-for 1)
8023                      nil))
8024                   (cc
8025                    (if (memq 'Cc nnmail-extra-headers)
8026                        (gnus-summary-find-matching
8027                         (cons 'extra 'Cc) recipient 'all nil nil
8028                         not-matching)
8029                      (gnus-message
8030                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8031                      (sit-for 1)
8032                      nil))
8033                   (articles
8034                    (if not-matching
8035                        ;; We need the numbers that are in both lists:
8036                        (mapcar (lambda (a)
8037                                  (and (memq a to) a))
8038                                cc)
8039                      (nconc to cc))))
8040              (unless articles
8041                (error "Found no matches for \"%s\"" recipient))
8042              (gnus-summary-limit articles))
8043       (gnus-summary-position-point))))
8044
8045 (defun gnus-summary-limit-to-address (address &optional not-matching)
8046   "Limit the summary buffer to articles with the given ADDRESS.
8047
8048 If NOT-MATCHING, exclude ADDRESS.
8049
8050 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8051 in `nnmail-extra-headers'."
8052   (interactive
8053    (list (read-string (format "%s address (regexp): "
8054                               (if current-prefix-arg "Exclude" "Limit to")))
8055          current-prefix-arg))
8056   (when (not (equal "" address))
8057     (prog1 (let* ((to
8058                    (if (memq 'To nnmail-extra-headers)
8059                        (gnus-summary-find-matching
8060                         (cons 'extra 'To) address 'all nil nil
8061                         not-matching)
8062                      (gnus-message
8063                       1 "`To' isn't present in `nnmail-extra-headers'")
8064                      (sit-for 1)
8065                      t))
8066                   (cc
8067                    (if (memq 'Cc nnmail-extra-headers)
8068                        (gnus-summary-find-matching
8069                         (cons 'extra 'Cc) address 'all nil nil
8070                         not-matching)
8071                      (gnus-message
8072                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8073                      (sit-for 1)
8074                      t))
8075                   (from
8076                    (gnus-summary-find-matching "from" address
8077                                                'all nil nil not-matching))
8078                   (articles
8079                    (if not-matching
8080                        ;; We need the numbers that are in all lists:
8081                        (if (eq cc t)
8082                            (if (eq to t)
8083                                from
8084                              (mapcar (lambda (a) (car (memq a from))) to))
8085                          (if (eq to t)
8086                              (mapcar (lambda (a) (car (memq a from))) cc)
8087                            (mapcar (lambda (a) (car (memq a from)))
8088                                    (mapcar (lambda (a) (car (memq a to)))
8089                                            cc))))
8090                      (nconc (if (eq to t) nil to)
8091                             (if (eq cc t) nil cc)
8092                             from))))
8093              (unless articles
8094                (error "Found no matches for \"%s\"" address))
8095              (gnus-summary-limit articles))
8096       (gnus-summary-position-point))))
8097
8098 (defun gnus-summary-limit-strange-charsets-predicate (header)
8099   (let ((string (concat (mail-header-subject header)
8100                         (mail-header-from header)))
8101         charset found)
8102     (dotimes (i (1- (length string)))
8103       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8104       (when (string-match "unicode\\|big\\|japanese" charset)
8105         (setq found t)))
8106     found))
8107
8108 (defun gnus-summary-limit-to-predicate (predicate)
8109   "Limit to articles where PREDICATE returns non-nil.
8110 PREDICATE will be called with the header structures of the
8111 articles."
8112   (let ((articles nil)
8113         (case-fold-search t))
8114     (dolist (header gnus-newsgroup-headers)
8115       (when (funcall predicate header)
8116         (push (mail-header-number header) articles)))
8117     (gnus-summary-limit (nreverse articles))))
8118
8119 (defun gnus-summary-limit-to-age (age &optional younger-p)
8120   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8121 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8122 articles that are younger than AGE days."
8123   (interactive
8124    (let ((younger current-prefix-arg)
8125          (days-got nil)
8126          days)
8127      (while (not days-got)
8128        (setq days (if younger
8129                       (read-string "Limit to articles younger than (in days, older when negative): ")
8130                     (read-string
8131                      "Limit to articles older than (in days, younger when negative): ")))
8132        (when (> (length days) 0)
8133          (setq days (read days)))
8134        (if (numberp days)
8135            (progn
8136              (setq days-got t)
8137              (when (< days 0)
8138                (setq younger (not younger))
8139                (setq days (* days -1))))
8140          (message "Please enter a number.")
8141          (sleep-for 1)))
8142      (list days younger)))
8143   (prog1
8144       (let ((data gnus-newsgroup-data)
8145             (cutoff (days-to-time age))
8146             articles d date is-younger)
8147         (while (setq d (pop data))
8148           (when (and (vectorp (gnus-data-header d))
8149                      (setq date (mail-header-date (gnus-data-header d))))
8150             (setq is-younger (time-less-p
8151                               (time-since (condition-case ()
8152                                               (date-to-time date)
8153                                             (error '(0 0))))
8154                               cutoff))
8155             (when (if younger-p
8156                       is-younger
8157                     (not is-younger))
8158               (push (gnus-data-number d) articles))))
8159         (gnus-summary-limit (nreverse articles)))
8160     (gnus-summary-position-point)))
8161
8162 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8163   "Limit the summary buffer to articles that match an 'extra' header."
8164   (interactive
8165    (let ((header
8166           (intern
8167            (gnus-completing-read-with-default
8168             (symbol-name (car gnus-extra-headers))
8169             (if current-prefix-arg
8170                 "Exclude extra header"
8171               "Limit extra header")
8172             (mapcar (lambda (x)
8173                       (cons (symbol-name x) x))
8174                     gnus-extra-headers)
8175             nil
8176             t))))
8177      (list header
8178            (read-string (format "%s header %s (regexp): "
8179                                 (if current-prefix-arg "Exclude" "Limit to")
8180                                 header))
8181            current-prefix-arg)))
8182   (when (not (equal "" regexp))
8183     (prog1
8184         (let ((articles (gnus-summary-find-matching
8185                          (cons 'extra header) regexp 'all nil nil
8186                          not-matching)))
8187           (unless articles
8188             (error "Found no matches for \"%s\"" regexp))
8189           (gnus-summary-limit articles))
8190       (gnus-summary-position-point))))
8191
8192 (defun gnus-summary-limit-to-display-predicate ()
8193   "Limit the summary buffer to the predicated in the `display' group parameter."
8194   (interactive)
8195   (unless gnus-newsgroup-display
8196     (error "There is no `display' group parameter"))
8197   (let (articles)
8198     (dolist (number gnus-newsgroup-articles)
8199       (when (funcall gnus-newsgroup-display)
8200         (push number articles)))
8201     (gnus-summary-limit articles))
8202   (gnus-summary-position-point))
8203
8204 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8205 (make-obsolete
8206  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8207
8208 (defun gnus-summary-limit-to-unread (&optional all)
8209   "Limit the summary buffer to articles that are not marked as read.
8210 If ALL is non-nil, limit strictly to unread articles."
8211   (interactive "P")
8212   (if all
8213       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8214     (gnus-summary-limit-to-marks
8215      ;; Concat all the marks that say that an article is read and have
8216      ;; those removed.
8217      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8218            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8219            gnus-low-score-mark gnus-expirable-mark
8220            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8221            gnus-duplicate-mark gnus-souped-mark)
8222      'reverse)))
8223
8224 (defun gnus-summary-limit-to-headers (match &optional reverse)
8225   "Limit the summary buffer to articles that have headers that match MATCH.
8226 If REVERSE (the prefix), limit to articles that don't match."
8227   (interactive "sMatch headers (regexp): \nP")
8228   (gnus-summary-limit-to-bodies match reverse t))
8229
8230 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8231   "Limit the summary buffer to articles that have bodies that match MATCH.
8232 If REVERSE (the prefix), limit to articles that don't match."
8233   (interactive "sMatch body (regexp): \nP")
8234   (let ((articles nil)
8235         (gnus-select-article-hook nil)  ;Disable hook.
8236         (gnus-article-prepare-hook nil)
8237         (gnus-use-article-prefetch nil)
8238         (gnus-keep-backlog nil)
8239         (gnus-break-pages nil)
8240         (gnus-summary-display-arrow nil)
8241         (gnus-updated-mode-lines nil)
8242         (gnus-auto-center-summary nil)
8243         (gnus-display-mime-function nil))
8244     (dolist (data gnus-newsgroup-data)
8245       (let (gnus-mark-article-hook)
8246         (gnus-summary-select-article t t nil (gnus-data-number data)))
8247       (save-excursion
8248         (set-buffer gnus-article-buffer)
8249         (article-goto-body)
8250         (let* ((case-fold-search t)
8251                (found (if headersp
8252                           (re-search-backward match nil t)
8253                         (re-search-forward match nil t))))
8254           (when (or (and found
8255                          (not reverse))
8256                     (and (not found)
8257                          reverse))
8258             (push (gnus-data-number data) articles)))))
8259     (if (not articles)
8260         (message "No messages matched")
8261       (gnus-summary-limit articles)))
8262   (gnus-summary-position-point))
8263
8264 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8265   "Limit the summary buffer to articles that aren't part on any thread.
8266 If THREADSP (the prefix), limit to articles that are in threads."
8267   (interactive "P")
8268   (let ((articles nil)
8269         thread-articles
8270         threads)
8271     (dolist (thread gnus-newsgroup-threads)
8272       (if (stringp (car thread))
8273           (dolist (thread (cdr thread))
8274             (push thread threads))
8275         (push thread threads)))
8276     (dolist (thread threads)
8277       (setq thread-articles (gnus-articles-in-thread thread))
8278       (when (or (and threadsp
8279                      (> (length thread-articles) 1))
8280                 (and (not threadsp)
8281                      (= (length thread-articles) 1)))
8282         (setq articles (nconc thread-articles articles))))
8283     (if (not articles)
8284         (message "No messages matched")
8285       (gnus-summary-limit articles))
8286     (gnus-summary-position-point)))
8287
8288 (defun gnus-summary-limit-to-replied (&optional unreplied)
8289   "Limit the summary buffer to replied articles.
8290 If UNREPLIED (the prefix), limit to unreplied articles."
8291   (interactive "P")
8292   (if unreplied
8293       (gnus-summary-limit
8294        (gnus-set-difference gnus-newsgroup-articles
8295         gnus-newsgroup-replied))
8296     (gnus-summary-limit gnus-newsgroup-replied))
8297   (gnus-summary-position-point))
8298
8299 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8300 (make-obsolete 'gnus-summary-delete-marked-with
8301                'gnus-summary-limit-exclude-marks)
8302
8303 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8304   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8305 If REVERSE, limit the summary buffer to articles that are marked
8306 with MARKS.  MARKS can either be a string of marks or a list of marks.
8307 Returns how many articles were removed."
8308   (interactive "sMarks: ")
8309   (gnus-summary-limit-to-marks marks t))
8310
8311 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8312   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8313 If REVERSE (the prefix), limit the summary buffer to articles that are
8314 not marked with MARKS.  MARKS can either be a string of marks or a
8315 list of marks.
8316 Returns how many articles were removed."
8317   (interactive "sMarks: \nP")
8318   (prog1
8319       (let ((data gnus-newsgroup-data)
8320             (marks (if (listp marks) marks
8321                      (append marks nil))) ; Transform to list.
8322             articles)
8323         (while data
8324           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8325                   (memq (gnus-data-mark (car data)) marks))
8326             (push (gnus-data-number (car data)) articles))
8327           (setq data (cdr data)))
8328         (gnus-summary-limit articles))
8329     (gnus-summary-position-point)))
8330
8331 (defun gnus-summary-limit-to-score (score)
8332   "Limit to articles with score at or above SCORE."
8333   (interactive "NLimit to articles with score of at least: ")
8334   (let ((data gnus-newsgroup-data)
8335         articles)
8336     (while data
8337       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8338                 score)
8339         (push (gnus-data-number (car data)) articles))
8340       (setq data (cdr data)))
8341     (prog1
8342         (gnus-summary-limit articles)
8343       (gnus-summary-position-point))))
8344
8345 (defun gnus-summary-limit-to-unseen ()
8346   "Limit to unseen articles."
8347   (interactive)
8348   (prog1
8349       (gnus-summary-limit gnus-newsgroup-unseen)
8350     (gnus-summary-position-point)))
8351
8352 (defun gnus-summary-limit-include-thread (id)
8353   "Display all the hidden articles that is in the thread with ID in it.
8354 When called interactively, ID is the Message-ID of the current
8355 article."
8356   (interactive (list (mail-header-id (gnus-summary-article-header))))
8357   (let ((articles (gnus-articles-in-thread
8358                    (gnus-id-to-thread (gnus-root-id id)))))
8359     (prog1
8360         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8361       (gnus-summary-limit-include-matching-articles
8362        "subject"
8363        (regexp-quote (gnus-simplify-subject-re
8364                       (mail-header-subject (gnus-id-to-header id)))))
8365       (gnus-summary-position-point))))
8366
8367 (defun gnus-summary-limit-include-matching-articles (header regexp)
8368   "Display all the hidden articles that have HEADERs that match REGEXP."
8369   (interactive (list (read-string "Match on header: ")
8370                      (read-string "Regexp: ")))
8371   (let ((articles (gnus-find-matching-articles header regexp)))
8372     (prog1
8373         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8374       (gnus-summary-position-point))))
8375
8376 (defun gnus-summary-insert-dormant-articles ()
8377   "Insert all the dormant articles for this group into the current buffer."
8378   (interactive)
8379   (let ((gnus-verbose (max 6 gnus-verbose)))
8380     (if (not gnus-newsgroup-dormant)
8381         (gnus-message 3 "No dormant articles for this group")
8382       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8383
8384 (defun gnus-summary-insert-ticked-articles ()
8385   "Insert ticked articles for this group into the current buffer."
8386   (interactive)
8387   (let ((gnus-verbose (max 6 gnus-verbose)))
8388     (if (not gnus-newsgroup-marked)
8389         (gnus-message 3 "No ticked articles for this group")
8390       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8391
8392 (defun gnus-summary-limit-include-dormant ()
8393   "Display all the hidden articles that are marked as dormant.
8394 Note that this command only works on a subset of the articles currently
8395 fetched for this group."
8396   (interactive)
8397   (unless gnus-newsgroup-dormant
8398     (error "There are no dormant articles in this group"))
8399   (prog1
8400       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8401     (gnus-summary-position-point)))
8402
8403 (defun gnus-summary-limit-exclude-dormant ()
8404   "Hide all dormant articles."
8405   (interactive)
8406   (prog1
8407       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8408     (gnus-summary-position-point)))
8409
8410 (defun gnus-summary-limit-exclude-childless-dormant ()
8411   "Hide all dormant articles that have no children."
8412   (interactive)
8413   (let ((data (gnus-data-list t))
8414         articles d children)
8415     ;; Find all articles that are either not dormant or have
8416     ;; children.
8417     (while (setq d (pop data))
8418       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8419                 (and (setq children
8420                            (gnus-article-children (gnus-data-number d)))
8421                      (let (found)
8422                        (while children
8423                          (when (memq (car children) articles)
8424                            (setq children nil
8425                                  found t))
8426                          (pop children))
8427                        found)))
8428         (push (gnus-data-number d) articles)))
8429     ;; Do the limiting.
8430     (prog1
8431         (gnus-summary-limit articles)
8432       (gnus-summary-position-point))))
8433
8434 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8435   "Mark all unread excluded articles as read.
8436 If ALL, mark even excluded ticked and dormants as read."
8437   (interactive "P")
8438   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8439   (let ((articles (gnus-sorted-ndifference
8440                    (sort
8441                     (mapcar (lambda (h) (mail-header-number h))
8442                             gnus-newsgroup-headers)
8443                     '<)
8444                    gnus-newsgroup-limit))
8445         article)
8446     (setq gnus-newsgroup-unreads
8447           (gnus-sorted-intersection gnus-newsgroup-unreads
8448                                     gnus-newsgroup-limit))
8449     (if all
8450         (setq gnus-newsgroup-dormant nil
8451               gnus-newsgroup-marked nil
8452               gnus-newsgroup-reads
8453               (nconc
8454                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8455                gnus-newsgroup-reads))
8456       (while (setq article (pop articles))
8457         (unless (or (memq article gnus-newsgroup-dormant)
8458                     (memq article gnus-newsgroup-marked))
8459           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8460
8461 (defun gnus-summary-limit (articles &optional pop)
8462   (if pop
8463       ;; We pop the previous limit off the stack and use that.
8464       (setq articles (car gnus-newsgroup-limits)
8465             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8466     ;; We use the new limit, so we push the old limit on the stack.
8467     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8468   ;; Set the limit.
8469   (setq gnus-newsgroup-limit articles)
8470   (let ((total (length gnus-newsgroup-data))
8471         (data (gnus-data-find-list (gnus-summary-article-number)))
8472         (gnus-summary-mark-below nil)   ; Inhibit this.
8473         found)
8474     ;; This will do all the work of generating the new summary buffer
8475     ;; according to the new limit.
8476     (gnus-summary-prepare)
8477     ;; Hide any threads, possibly.
8478     (gnus-summary-maybe-hide-threads)
8479     ;; Try to return to the article you were at, or one in the
8480     ;; neighborhood.
8481     (when data
8482       ;; We try to find some article after the current one.
8483       (while data
8484         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8485           (setq data nil
8486                 found t))
8487         (setq data (cdr data))))
8488     (unless found
8489       ;; If there is no data, that means that we were after the last
8490       ;; article.  The same goes when we can't find any articles
8491       ;; after the current one.
8492       (goto-char (point-max))
8493       (gnus-summary-find-prev))
8494     (gnus-set-mode-line 'summary)
8495     ;; We return how many articles were removed from the summary
8496     ;; buffer as a result of the new limit.
8497     (- total (length gnus-newsgroup-data))))
8498
8499 (defsubst gnus-invisible-cut-children (threads)
8500   (let ((num 0))
8501     (while threads
8502       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8503         (incf num))
8504       (pop threads))
8505     (< num 2)))
8506
8507 (defsubst gnus-cut-thread (thread)
8508   "Go forwards in the thread until we find an article that we want to display."
8509   (when (or (eq gnus-fetch-old-headers 'some)
8510             (eq gnus-fetch-old-headers 'invisible)
8511             (numberp gnus-fetch-old-headers)
8512             (eq gnus-build-sparse-threads 'some)
8513             (eq gnus-build-sparse-threads 'more))
8514     ;; Deal with old-fetched headers and sparse threads.
8515     (while (and
8516             thread
8517             (or
8518              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8519              (gnus-summary-article-ancient-p
8520               (mail-header-number (car thread))))
8521             (if (or (<= (length (cdr thread)) 1)
8522                     (eq gnus-fetch-old-headers 'invisible))
8523                 (setq gnus-newsgroup-limit
8524                       (delq (mail-header-number (car thread))
8525                             gnus-newsgroup-limit)
8526                       thread (cadr thread))
8527               (when (gnus-invisible-cut-children (cdr thread))
8528                 (let ((th (cdr thread)))
8529                   (while th
8530                     (if (memq (mail-header-number (caar th))
8531                               gnus-newsgroup-limit)
8532                         (setq thread (car th)
8533                               th nil)
8534                       (setq th (cdr th))))))))))
8535   thread)
8536
8537 (defun gnus-cut-threads (threads)
8538   "Cut off all uninteresting articles from the beginning of THREADS."
8539   (when (or (eq gnus-fetch-old-headers 'some)
8540             (eq gnus-fetch-old-headers 'invisible)
8541             (numberp gnus-fetch-old-headers)
8542             (eq gnus-build-sparse-threads 'some)
8543             (eq gnus-build-sparse-threads 'more))
8544     (let ((th threads))
8545       (while th
8546         (setcar th (gnus-cut-thread (car th)))
8547         (setq th (cdr th)))))
8548   ;; Remove nixed out threads.
8549   (delq nil threads))
8550
8551 (defun gnus-summary-initial-limit (&optional show-if-empty)
8552   "Figure out what the initial limit is supposed to be on group entry.
8553 This entails weeding out unwanted dormants, low-scored articles,
8554 fetch-old-headers verbiage, and so on."
8555   ;; Most groups have nothing to remove.
8556   (if (or gnus-inhibit-limiting
8557           (and (null gnus-newsgroup-dormant)
8558                (eq gnus-newsgroup-display 'gnus-not-ignore)
8559                (not (eq gnus-fetch-old-headers 'some))
8560                (not (numberp gnus-fetch-old-headers))
8561                (not (eq gnus-fetch-old-headers 'invisible))
8562                (null gnus-summary-expunge-below)
8563                (not (eq gnus-build-sparse-threads 'some))
8564                (not (eq gnus-build-sparse-threads 'more))
8565                (null gnus-thread-expunge-below)
8566                (not gnus-use-nocem)))
8567       ()                                ; Do nothing.
8568     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8569     (setq gnus-newsgroup-limit nil)
8570     (mapatoms
8571      (lambda (node)
8572        (unless (car (symbol-value node))
8573          ;; These threads have no parents -- they are roots.
8574          (let ((nodes (cdr (symbol-value node)))
8575                thread)
8576            (while nodes
8577              (if (and gnus-thread-expunge-below
8578                       (< (gnus-thread-total-score (car nodes))
8579                          gnus-thread-expunge-below))
8580                  (gnus-expunge-thread (pop nodes))
8581                (setq thread (pop nodes))
8582                (gnus-summary-limit-children thread))))))
8583      gnus-newsgroup-dependencies)
8584     ;; If this limitation resulted in an empty group, we might
8585     ;; pop the previous limit and use it instead.
8586     (when (and (not gnus-newsgroup-limit)
8587                show-if-empty)
8588       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8589     gnus-newsgroup-limit))
8590
8591 (defun gnus-summary-limit-children (thread)
8592   "Return 1 if this subthread is visible and 0 if it is not."
8593   ;; First we get the number of visible children to this thread.  This
8594   ;; is done by recursing down the thread using this function, so this
8595   ;; will really go down to a leaf article first, before slowly
8596   ;; working its way up towards the root.
8597   (when thread
8598     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8599            (children
8600            (if (cdr thread)
8601                (apply '+ (mapcar 'gnus-summary-limit-children
8602                                  (cdr thread)))
8603              0))
8604           (number (mail-header-number (car thread)))
8605           score)
8606       (if (and
8607            (not (memq number gnus-newsgroup-marked))
8608            (or
8609             ;; If this article is dormant and has absolutely no visible
8610             ;; children, then this article isn't visible.
8611             (and (memq number gnus-newsgroup-dormant)
8612                  (zerop children))
8613             ;; If this is "fetch-old-headered" and there is no
8614             ;; visible children, then we don't want this article.
8615             (and (or (eq gnus-fetch-old-headers 'some)
8616                      (numberp gnus-fetch-old-headers))
8617                  (gnus-summary-article-ancient-p number)
8618                  (zerop children))
8619             ;; If this is "fetch-old-headered" and `invisible', then
8620             ;; we don't want this article.
8621             (and (eq gnus-fetch-old-headers 'invisible)
8622                  (gnus-summary-article-ancient-p number))
8623             ;; If this is a sparsely inserted article with no children,
8624             ;; we don't want it.
8625             (and (eq gnus-build-sparse-threads 'some)
8626                  (gnus-summary-article-sparse-p number)
8627                  (zerop children))
8628             ;; If we use expunging, and this article is really
8629             ;; low-scored, then we don't want this article.
8630             (when (and gnus-summary-expunge-below
8631                        (< (setq score
8632                                 (or (cdr (assq number gnus-newsgroup-scored))
8633                                     gnus-summary-default-score))
8634                           gnus-summary-expunge-below))
8635               ;; We increase the expunge-tally here, but that has
8636               ;; nothing to do with the limits, really.
8637               (incf gnus-newsgroup-expunged-tally)
8638               ;; We also mark as read here, if that's wanted.
8639               (when (and gnus-summary-mark-below
8640                          (< score gnus-summary-mark-below))
8641                 (setq gnus-newsgroup-unreads
8642                       (delq number gnus-newsgroup-unreads))
8643                 (if gnus-newsgroup-auto-expire
8644                     (push number gnus-newsgroup-expirable)
8645                   (push (cons number gnus-low-score-mark)
8646                         gnus-newsgroup-reads)))
8647               t)
8648             ;; Do the `display' group parameter.
8649             (and gnus-newsgroup-display
8650                  (not (funcall gnus-newsgroup-display)))
8651             ;; Check NoCeM things.
8652             (when (and gnus-use-nocem
8653                        (gnus-nocem-unwanted-article-p
8654                         (mail-header-id (car thread))))
8655               (setq gnus-newsgroup-unreads
8656                     (delq number gnus-newsgroup-unreads))
8657               t)))
8658           ;; Nope, invisible article.
8659           0
8660         ;; Ok, this article is to be visible, so we add it to the limit
8661         ;; and return 1.
8662         (push number gnus-newsgroup-limit)
8663         1))))
8664
8665 (defun gnus-expunge-thread (thread)
8666   "Mark all articles in THREAD as read."
8667   (let* ((number (mail-header-number (car thread))))
8668     (incf gnus-newsgroup-expunged-tally)
8669     ;; We also mark as read here, if that's wanted.
8670     (setq gnus-newsgroup-unreads
8671           (delq number gnus-newsgroup-unreads))
8672     (if gnus-newsgroup-auto-expire
8673         (push number gnus-newsgroup-expirable)
8674       (push (cons number gnus-low-score-mark)
8675             gnus-newsgroup-reads)))
8676   ;; Go recursively through all subthreads.
8677   (mapcar 'gnus-expunge-thread (cdr thread)))
8678
8679 ;; Summary article oriented commands
8680
8681 (defun gnus-summary-refer-parent-article (n)
8682   "Refer parent article N times.
8683 If N is negative, go to ancestor -N instead.
8684 The difference between N and the number of articles fetched is returned."
8685   (interactive "p")
8686   (let ((skip 1)
8687         error header ref)
8688     (when (not (natnump n))
8689       (setq skip (abs n)
8690             n 1))
8691     (while (and (> n 0)
8692                 (not error))
8693       (setq header (gnus-summary-article-header))
8694       (if (and (eq (mail-header-number header)
8695                    (cdr gnus-article-current))
8696                (equal gnus-newsgroup-name
8697                       (car gnus-article-current)))
8698           ;; If we try to find the parent of the currently
8699           ;; displayed article, then we take a look at the actual
8700           ;; References header, since this is slightly more
8701           ;; reliable than the References field we got from the
8702           ;; server.
8703           (save-excursion
8704             (set-buffer gnus-original-article-buffer)
8705             (nnheader-narrow-to-headers)
8706             (unless (setq ref (message-fetch-field "references"))
8707               (when (setq ref (message-fetch-field "in-reply-to"))
8708                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8709             (widen))
8710         (setq ref
8711               ;; It's not the current article, so we take a bet on
8712               ;; the value we got from the server.
8713               (mail-header-references header)))
8714       (if (and ref
8715                (not (equal ref "")))
8716           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8717             (gnus-message 1 "Couldn't find parent"))
8718         (gnus-message 1 "No references in article %d"
8719                       (gnus-summary-article-number))
8720         (setq error t))
8721       (decf n))
8722     (gnus-summary-position-point)
8723     n))
8724
8725 (defun gnus-summary-refer-references ()
8726   "Fetch all articles mentioned in the References header.
8727 Return the number of articles fetched."
8728   (interactive)
8729   (let ((ref (mail-header-references (gnus-summary-article-header)))
8730         (current (gnus-summary-article-number))
8731         (n 0))
8732     (if (or (not ref)
8733             (equal ref ""))
8734         (error "No References in the current article")
8735       ;; For each Message-ID in the References header...
8736       (while (string-match "<[^>]*>" ref)
8737         (incf n)
8738         ;; ... fetch that article.
8739         (gnus-summary-refer-article
8740          (prog1 (match-string 0 ref)
8741            (setq ref (substring ref (match-end 0))))))
8742       (gnus-summary-goto-subject current)
8743       (gnus-summary-position-point)
8744       n)))
8745
8746 (defun gnus-summary-refer-thread (&optional limit)
8747   "Fetch all articles in the current thread.
8748 If LIMIT (the numerical prefix), fetch that many old headers instead
8749 of what's specified by the `gnus-refer-thread-limit' variable."
8750   (interactive "P")
8751   (let ((id (mail-header-id (gnus-summary-article-header)))
8752         (limit (if limit (prefix-numeric-value limit)
8753                  gnus-refer-thread-limit)))
8754     (unless (eq gnus-fetch-old-headers 'invisible)
8755       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8756       ;; Retrieve the headers and read them in.
8757       (if (eq (if (numberp limit)
8758                   (gnus-retrieve-headers
8759                    (list (min
8760                           (+ (mail-header-number
8761                               (gnus-summary-article-header))
8762                              limit)
8763                           gnus-newsgroup-end))
8764                    gnus-newsgroup-name (* limit 2))
8765                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8766                 ;; headers.
8767                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8768                                        gnus-newsgroup-name limit))
8769               'nov)
8770           (gnus-build-all-threads)
8771         (error "Can't fetch thread from back ends that don't support NOV"))
8772       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8773     (gnus-summary-limit-include-thread id)))
8774
8775 (defun gnus-summary-refer-article (message-id)
8776   "Fetch an article specified by MESSAGE-ID."
8777   (interactive "sMessage-ID: ")
8778   (when (and (stringp message-id)
8779              (not (zerop (length message-id))))
8780     (setq message-id (gnus-replace-in-string message-id " " ""))
8781     ;; Construct the correct Message-ID if necessary.
8782     ;; Suggested by tale@pawl.rpi.edu.
8783     (unless (string-match "^<" message-id)
8784       (setq message-id (concat "<" message-id)))
8785     (unless (string-match ">$" message-id)
8786       (setq message-id (concat message-id ">")))
8787     ;; People often post MIDs from URLs, so unhex it:
8788     (unless (string-match "@" message-id)
8789       (setq message-id (gnus-url-unhex-string message-id)))
8790     (let* ((header (gnus-id-to-header message-id))
8791            (sparse (and header
8792                         (gnus-summary-article-sparse-p
8793                          (mail-header-number header))
8794                         (memq (mail-header-number header)
8795                               gnus-newsgroup-limit)))
8796            number)
8797       (cond
8798        ;; If the article is present in the buffer we just go to it.
8799        ((and header
8800              (or (not (gnus-summary-article-sparse-p
8801                        (mail-header-number header)))
8802                  sparse))
8803         (prog1
8804             (gnus-summary-goto-article
8805              (mail-header-number header) nil t)
8806           (when sparse
8807             (gnus-summary-update-article (mail-header-number header)))))
8808        (t
8809         ;; We fetch the article.
8810         (catch 'found
8811           (dolist (gnus-override-method (gnus-refer-article-methods))
8812             (when (and (gnus-check-server gnus-override-method)
8813                        ;; Fetch the header,
8814                        (setq number (gnus-summary-insert-subject message-id)))
8815               ;; and display the article.
8816               (gnus-summary-select-article nil nil nil number)
8817               (throw 'found t)))
8818           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8819
8820 (defun gnus-refer-article-methods ()
8821   "Return a list of referable methods."
8822   (cond
8823    ;; No method, so we default to current and native.
8824    ((null gnus-refer-article-method)
8825     (list gnus-current-select-method gnus-select-method))
8826    ;; Current.
8827    ((eq 'current gnus-refer-article-method)
8828     (list gnus-current-select-method))
8829    ;; List of select methods.
8830    ((not (and (symbolp (car gnus-refer-article-method))
8831               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8832     (let (out)
8833       (dolist (method gnus-refer-article-method)
8834         (push (if (eq 'current method)
8835                   gnus-current-select-method
8836                 method)
8837               out))
8838       (nreverse out)))
8839    ;; One single select method.
8840    (t
8841     (list gnus-refer-article-method))))
8842
8843 (defun gnus-summary-edit-parameters ()
8844   "Edit the group parameters of the current group."
8845   (interactive)
8846   (gnus-group-edit-group gnus-newsgroup-name 'params))
8847
8848 (defun gnus-summary-customize-parameters ()
8849   "Customize the group parameters of the current group."
8850   (interactive)
8851   (gnus-group-customize gnus-newsgroup-name))
8852
8853 (defun gnus-summary-enter-digest-group (&optional force)
8854   "Enter an nndoc group based on the current article.
8855 If FORCE, force a digest interpretation.  If not, try
8856 to guess what the document format is."
8857   (interactive "P")
8858   (let ((conf gnus-current-window-configuration))
8859     (save-window-excursion
8860       (save-excursion
8861         (let (gnus-article-prepare-hook
8862               gnus-display-mime-function
8863               gnus-break-pages)
8864           (gnus-summary-select-article))))
8865     (setq gnus-current-window-configuration conf)
8866     (let* ((name (format "%s-%d"
8867                          (gnus-group-prefixed-name
8868                           gnus-newsgroup-name (list 'nndoc ""))
8869                          (with-current-buffer gnus-summary-buffer
8870                            gnus-current-article)))
8871            (ogroup gnus-newsgroup-name)
8872            (params (append (gnus-info-params (gnus-get-info ogroup))
8873                            (list (cons 'to-group ogroup))
8874                            (list (cons 'parent-group ogroup))
8875                            (list (cons 'save-article-group ogroup))))
8876            (case-fold-search t)
8877            (buf (current-buffer))
8878            dig to-address)
8879       (save-excursion
8880         (set-buffer gnus-original-article-buffer)
8881         ;; Have the digest group inherit the main mail address of
8882         ;; the parent article.
8883         (when (setq to-address (or (gnus-fetch-field "reply-to")
8884                                    (gnus-fetch-field "from")))
8885           (setq params
8886                 (append
8887                  (list (cons 'to-address
8888                              (funcall gnus-decode-encoded-address-function
8889                                       to-address))))))
8890         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8891         (insert-buffer-substring gnus-original-article-buffer)
8892         ;; Remove lines that may lead nndoc to misinterpret the
8893         ;; document type.
8894         (narrow-to-region
8895          (goto-char (point-min))
8896          (or (search-forward "\n\n" nil t) (point)))
8897         (goto-char (point-min))
8898         (delete-matching-lines "^Path:\\|^From ")
8899         (widen))
8900       (unwind-protect
8901           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8902                     (gnus-newsgroup-ephemeral-ignored-charsets
8903                      gnus-newsgroup-ignored-charsets))
8904                 (gnus-group-read-ephemeral-group
8905                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8906                               (nndoc-article-type
8907                                ,(if force 'mbox 'guess)))
8908                  t nil nil nil
8909                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8910                                                         "ADAPT")))))
8911               ;; Make all postings to this group go to the parent group.
8912               (nconc (gnus-info-params (gnus-get-info name))
8913                      params)
8914             ;; Couldn't select this doc group.
8915             (switch-to-buffer buf)
8916             (gnus-set-global-variables)
8917             (gnus-configure-windows 'summary)
8918             (gnus-message 3 "Article couldn't be entered?"))
8919         (kill-buffer dig)))))
8920
8921 (defun gnus-summary-read-document (n)
8922   "Open a new group based on the current article(s).
8923 This will allow you to read digests and other similar
8924 documents as newsgroups.
8925 Obeys the standard process/prefix convention."
8926   (interactive "P")
8927   (let* ((ogroup gnus-newsgroup-name)
8928          (params (append (gnus-info-params (gnus-get-info ogroup))
8929                          (list (cons 'to-group ogroup))))
8930          group egroup groups vgroup)
8931     (dolist (article (gnus-summary-work-articles n))
8932       (setq group (format "%s-%d" gnus-newsgroup-name article))
8933       (gnus-summary-remove-process-mark article)
8934       (when (gnus-summary-display-article article)
8935         (save-excursion
8936           (with-temp-buffer
8937             (insert-buffer-substring gnus-original-article-buffer)
8938             ;; Remove some headers that may lead nndoc to make
8939             ;; the wrong guess.
8940             (message-narrow-to-head)
8941             (goto-char (point-min))
8942             (delete-matching-lines "^Path:\\|^From ")
8943             (widen)
8944             (if (setq egroup
8945                       (gnus-group-read-ephemeral-group
8946                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8947                                      (nndoc-article-type guess))
8948                        t nil t))
8949                 (progn
8950             ;; Make all postings to this group go to the parent group.
8951                   (nconc (gnus-info-params (gnus-get-info egroup))
8952                          params)
8953                   (push egroup groups))
8954               ;; Couldn't select this doc group.
8955               (gnus-error 3 "Article couldn't be entered"))))))
8956     ;; Now we have selected all the documents.
8957     (cond
8958      ((not groups)
8959       (error "None of the articles could be interpreted as documents"))
8960      ((gnus-group-read-ephemeral-group
8961        (setq vgroup (format
8962                      "nnvirtual:%s-%s" gnus-newsgroup-name
8963                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8964        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8965        t
8966        (cons (current-buffer) 'summary)))
8967      (t
8968       (error "Couldn't select virtual nndoc group")))))
8969
8970 (defun gnus-summary-isearch-article (&optional regexp-p)
8971   "Do incremental search forward on the current article.
8972 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8973   (interactive "P")
8974   (gnus-summary-select-article)
8975   (gnus-configure-windows 'article)
8976   (gnus-eval-in-buffer-window gnus-article-buffer
8977     (save-restriction
8978       (widen)
8979       (isearch-forward regexp-p))))
8980
8981 (defun gnus-summary-repeat-search-article-forward ()
8982   "Repeat the previous search forwards."
8983   (interactive)
8984   (unless gnus-last-search-regexp
8985     (error "No previous search"))
8986   (gnus-summary-search-article-forward gnus-last-search-regexp))
8987
8988 (defun gnus-summary-repeat-search-article-backward ()
8989   "Repeat the previous search backwards."
8990   (interactive)
8991   (unless gnus-last-search-regexp
8992     (error "No previous search"))
8993   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8994
8995 (defun gnus-summary-search-article-forward (regexp &optional backward)
8996   "Search for an article containing REGEXP forward.
8997 If BACKWARD, search backward instead."
8998   (interactive
8999    (list (read-string
9000           (format "Search article %s (regexp%s): "
9001                   (if current-prefix-arg "backward" "forward")
9002                   (if gnus-last-search-regexp
9003                       (concat ", default " gnus-last-search-regexp)
9004                     "")))
9005          current-prefix-arg))
9006   (if (string-equal regexp "")
9007       (setq regexp (or gnus-last-search-regexp ""))
9008     (setq gnus-last-search-regexp regexp)
9009     (setq gnus-article-before-search gnus-current-article))
9010   ;; Intentionally set gnus-last-article.
9011   (setq gnus-last-article gnus-article-before-search)
9012   (let ((gnus-last-article gnus-last-article))
9013     (if (gnus-summary-search-article regexp backward)
9014         (gnus-summary-show-thread)
9015       (signal 'search-failed (list regexp)))))
9016
9017 (defun gnus-summary-search-article-backward (regexp)
9018   "Search for an article containing REGEXP backward."
9019   (interactive
9020    (list (read-string
9021           (format "Search article backward (regexp%s): "
9022                   (if gnus-last-search-regexp
9023                       (concat ", default " gnus-last-search-regexp)
9024                     "")))))
9025   (gnus-summary-search-article-forward regexp 'backward))
9026
9027 (defun gnus-summary-search-article (regexp &optional backward)
9028   "Search for an article containing REGEXP.
9029 Optional argument BACKWARD means do search for backward.
9030 `gnus-select-article-hook' is not called during the search."
9031   ;; We have to require this here to make sure that the following
9032   ;; dynamic binding isn't shadowed by autoloading.
9033   (require 'gnus-async)
9034   (require 'gnus-art)
9035   (let ((gnus-select-article-hook nil)  ;Disable hook.
9036         (gnus-article-prepare-hook nil)
9037         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9038         (gnus-use-article-prefetch nil)
9039         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9040         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9041         (gnus-visual nil)
9042         (gnus-keep-backlog nil)
9043         (gnus-break-pages nil)
9044         (gnus-summary-display-arrow nil)
9045         (gnus-updated-mode-lines nil)
9046         (gnus-auto-center-summary nil)
9047         (sum (current-buffer))
9048         (gnus-display-mime-function nil)
9049         (found nil)
9050         point)
9051     (gnus-save-hidden-threads
9052       (gnus-summary-select-article)
9053       (set-buffer gnus-article-buffer)
9054       (goto-char (window-point (get-buffer-window (current-buffer))))
9055       (when backward
9056         (forward-line -1))
9057       (while (not found)
9058         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9059         (if (if backward
9060                 (re-search-backward regexp nil t)
9061               (re-search-forward regexp nil t))
9062             ;; We found the regexp.
9063             (progn
9064               (setq found 'found)
9065               (beginning-of-line)
9066               (set-window-start
9067                (get-buffer-window (current-buffer))
9068                (point))
9069               (forward-line 1)
9070               (set-window-point
9071                (get-buffer-window (current-buffer))
9072                (point))
9073               (set-buffer sum)
9074               (setq point (point)))
9075           ;; We didn't find it, so we go to the next article.
9076           (set-buffer sum)
9077           (setq found 'not)
9078           (while (eq found 'not)
9079             (if (not (if backward (gnus-summary-find-prev)
9080                        (gnus-summary-find-next)))
9081                 ;; No more articles.
9082                 (setq found t)
9083               ;; Select the next article and adjust point.
9084               (unless (gnus-summary-article-sparse-p
9085                        (gnus-summary-article-number))
9086                 (setq found nil)
9087                 (gnus-summary-select-article)
9088                 (set-buffer gnus-article-buffer)
9089                 (widen)
9090                 (goto-char (if backward (point-max) (point-min))))))))
9091       (gnus-message 7 ""))
9092     ;; Return whether we found the regexp.
9093     (when (eq found 'found)
9094       (goto-char point)
9095       (gnus-summary-show-thread)
9096       (gnus-summary-goto-subject gnus-current-article)
9097       (gnus-summary-position-point)
9098       t)))
9099
9100 (defun gnus-find-matching-articles (header regexp)
9101   "Return a list of all articles that match REGEXP on HEADER.
9102 This search includes all articles in the current group that Gnus has
9103 fetched headers for, whether they are displayed or not."
9104   (let ((articles nil)
9105         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9106         (case-fold-search t))
9107     (dolist (header gnus-newsgroup-headers)
9108       (when (string-match regexp (funcall func header))
9109         (push (mail-header-number header) articles)))
9110     (nreverse articles)))
9111
9112 (defun gnus-summary-find-matching (header regexp &optional backward unread
9113                                           not-case-fold not-matching)
9114   "Return a list of all articles that match REGEXP on HEADER.
9115 The search stars on the current article and goes forwards unless
9116 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9117 If UNREAD is non-nil, only unread articles will
9118 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9119 in the comparisons. If NOT-MATCHING, return a list of all articles that
9120 not match REGEXP on HEADER."
9121   (let ((case-fold-search (not not-case-fold))
9122         articles d func)
9123     (if (consp header)
9124         (if (eq (car header) 'extra)
9125             (setq func
9126                   `(lambda (h)
9127                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9128                          "")))
9129           (error "%s is an invalid header" header))
9130       (unless (fboundp (intern (concat "mail-header-" header)))
9131         (error "%s is not a valid header" header))
9132       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9133     (dolist (d (if (eq backward 'all)
9134                    gnus-newsgroup-data
9135                  (gnus-data-find-list
9136                   (gnus-summary-article-number)
9137                   (gnus-data-list backward))))
9138       (when (and (or (not unread)       ; We want all articles...
9139                      (gnus-data-unread-p d)) ; Or just unreads.
9140                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9141                  (if not-matching
9142                      (not (string-match
9143                            regexp
9144                            (funcall func (gnus-data-header d))))
9145                    (string-match regexp
9146                                  (funcall func (gnus-data-header d)))))
9147         (push (gnus-data-number d) articles))) ; Success!
9148     (nreverse articles)))
9149
9150 (defun gnus-summary-execute-command (header regexp command &optional backward)
9151   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9152 If HEADER is an empty string (or nil), the match is done on the entire
9153 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9154   (interactive
9155    (list (let ((completion-ignore-case t))
9156            (completing-read
9157             "Header name: "
9158             (mapcar (lambda (header) (list (format "%s" header)))
9159                     (append
9160                      '("Number" "Subject" "From" "Lines" "Date"
9161                        "Message-ID" "Xref" "References" "Body")
9162                      gnus-extra-headers))
9163             nil 'require-match))
9164          (read-string "Regexp: ")
9165          (read-key-sequence "Command: ")
9166          current-prefix-arg))
9167   (when (equal header "Body")
9168     (setq header ""))
9169   ;; Hidden thread subtrees must be searched as well.
9170   (gnus-summary-show-all-threads)
9171   ;; We don't want to change current point nor window configuration.
9172   (save-excursion
9173     (save-window-excursion
9174       (let (gnus-visual
9175             gnus-treat-strip-trailing-blank-lines
9176             gnus-treat-strip-leading-blank-lines
9177             gnus-treat-strip-multiple-blank-lines
9178             gnus-treat-hide-boring-headers
9179             gnus-treat-fold-newsgroups
9180             gnus-article-prepare-hook)
9181         (gnus-message 6 "Executing %s..." (key-description command))
9182         ;; We'd like to execute COMMAND interactively so as to give arguments.
9183         (gnus-execute header regexp
9184                       `(call-interactively ',(key-binding command))
9185                       backward)
9186         (gnus-message 6 "Executing %s...done" (key-description command))))))
9187
9188 (defun gnus-summary-beginning-of-article ()
9189   "Scroll the article back to the beginning."
9190   (interactive)
9191   (gnus-summary-select-article)
9192   (gnus-configure-windows 'article)
9193   (gnus-eval-in-buffer-window gnus-article-buffer
9194     (widen)
9195     (goto-char (point-min))
9196     (when gnus-break-pages
9197       (gnus-narrow-to-page))))
9198
9199 (defun gnus-summary-end-of-article ()
9200   "Scroll to the end of the article."
9201   (interactive)
9202   (gnus-summary-select-article)
9203   (gnus-configure-windows 'article)
9204   (gnus-eval-in-buffer-window gnus-article-buffer
9205     (widen)
9206     (goto-char (point-max))
9207     (recenter -3)
9208     (when gnus-break-pages
9209       (when (re-search-backward page-delimiter nil t)
9210         (narrow-to-region (match-end 0) (point-max)))
9211       (gnus-narrow-to-page))))
9212
9213 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9214   "Truncate to LEN and quote all \"(\"'s in STRING."
9215   (gnus-replace-in-string (if (and len (> (length string) len))
9216                               (substring string 0 len)
9217                             string)
9218                           "[()]" "\\\\\\&"))
9219
9220 (defun gnus-summary-print-article (&optional filename n)
9221   "Generate and print a PostScript image of the process-marked (mail) articles.
9222
9223 If used interactively, print the current article if none are
9224 process-marked.  With prefix arg, prompt the user for the name of the
9225 file to save in.
9226
9227 When used from Lisp, accept two optional args FILENAME and N.  N means
9228 to print the next N articles.  If N is negative, print the N previous
9229 articles.  If N is nil and articles have been marked with the process
9230 mark, print these instead.
9231
9232 If the optional first argument FILENAME is nil, send the image to the
9233 printer.  If FILENAME is a string, save the PostScript image in a file with
9234 that name.  If FILENAME is a number, prompt the user for the name of the file
9235 to save in."
9236   (interactive (list (ps-print-preprint current-prefix-arg)))
9237   (dolist (article (gnus-summary-work-articles n))
9238     (gnus-summary-select-article nil nil 'pseudo article)
9239     (gnus-eval-in-buffer-window gnus-article-buffer
9240       (gnus-print-buffer))
9241     (gnus-summary-remove-process-mark article))
9242   (ps-despool filename))
9243
9244 (defun gnus-print-buffer ()
9245   (let ((buffer (generate-new-buffer " *print*")))
9246     (unwind-protect
9247         (progn
9248           (copy-to-buffer buffer (point-min) (point-max))
9249           (set-buffer buffer)
9250           (gnus-remove-text-with-property 'gnus-decoration)
9251           (when (gnus-visual-p 'article-highlight 'highlight)
9252             ;; Copy-to-buffer doesn't copy overlay.  So redo
9253             ;; highlight.
9254             (let ((gnus-article-buffer buffer))
9255               (gnus-article-highlight-citation t)
9256               (gnus-article-highlight-signature)
9257               (gnus-article-emphasize)
9258               (gnus-article-delete-invisible-text)))
9259           (let ((ps-left-header
9260                  (list
9261                   (concat "("
9262                           (gnus-summary-print-truncate-and-quote
9263                            (mail-header-subject gnus-current-headers)
9264                            66) ")")
9265                   (concat "("
9266                           (gnus-summary-print-truncate-and-quote
9267                            (mail-header-from gnus-current-headers)
9268                            45) ")")))
9269                 (ps-right-header
9270                  (list
9271                   "/pagenumberstring load"
9272                   (concat "("
9273                           (mail-header-date gnus-current-headers) ")"))))
9274             (gnus-run-hooks 'gnus-ps-print-hook)
9275             (save-excursion
9276               (if window-system
9277                   (ps-spool-buffer-with-faces)
9278                 (ps-spool-buffer)))))
9279       (kill-buffer buffer))))
9280
9281 (defun gnus-summary-show-article (&optional arg)
9282   "Force redisplaying of the current article.
9283 If ARG (the prefix) is a number, show the article with the charset
9284 defined in `gnus-summary-show-article-charset-alist', or the charset
9285 input.
9286 If ARG (the prefix) is non-nil and not a number, show the raw article
9287 without any article massaging functions being run.  Normally, the key
9288 strokes are `C-u g'."
9289   (interactive "P")
9290   (cond
9291    ((numberp arg)
9292     (gnus-summary-show-article t)
9293     (let ((gnus-newsgroup-charset
9294            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9295                (mm-read-coding-system
9296                 "View as charset: " ;; actually it is coding system.
9297                 (with-current-buffer gnus-article-buffer
9298                   (mm-detect-coding-region (point) (point-max))))))
9299           (gnus-newsgroup-ignored-charsets 'gnus-all))
9300       (gnus-summary-select-article nil 'force)
9301       (let ((deps gnus-newsgroup-dependencies)
9302             head header lines)
9303         (save-excursion
9304           (set-buffer gnus-original-article-buffer)
9305           (save-restriction
9306             (message-narrow-to-head)
9307             (setq head (buffer-string))
9308             (goto-char (point-min))
9309             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9310               (goto-char (point-max))
9311               (widen)
9312               (setq lines (1- (count-lines (point) (point-max))))))
9313           (with-temp-buffer
9314             (insert (format "211 %d Article retrieved.\n"
9315                             (cdr gnus-article-current)))
9316             (insert head)
9317             (if lines (insert (format "Lines: %d\n" lines)))
9318             (insert ".\n")
9319             (let ((nntp-server-buffer (current-buffer)))
9320               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9321         (gnus-data-set-header
9322          (gnus-data-find (cdr gnus-article-current))
9323          header)
9324         (gnus-summary-update-article-line
9325          (cdr gnus-article-current) header)
9326         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9327           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9328    ((not arg)
9329     ;; Select the article the normal way.
9330     (gnus-summary-select-article nil 'force))
9331    (t
9332     ;; We have to require this here to make sure that the following
9333     ;; dynamic binding isn't shadowed by autoloading.
9334     (require 'gnus-async)
9335     (require 'gnus-art)
9336     ;; Bind the article treatment functions to nil.
9337     (let ((gnus-have-all-headers t)
9338           gnus-article-prepare-hook
9339           gnus-article-decode-hook
9340           gnus-display-mime-function
9341           gnus-break-pages)
9342       ;; Destroy any MIME parts.
9343       (when (gnus-buffer-live-p gnus-article-buffer)
9344         (save-excursion
9345           (set-buffer gnus-article-buffer)
9346           (mm-destroy-parts gnus-article-mime-handles)
9347           ;; Set it to nil for safety reason.
9348           (setq gnus-article-mime-handle-alist nil)
9349           (setq gnus-article-mime-handles nil)))
9350       (gnus-summary-select-article nil 'force))))
9351   (gnus-summary-goto-subject gnus-current-article)
9352   (gnus-summary-position-point))
9353
9354 (defun gnus-summary-show-raw-article ()
9355   "Show the raw article without any article massaging functions being run."
9356   (interactive)
9357   (gnus-summary-show-article t))
9358
9359 (defun gnus-summary-verbose-headers (&optional arg)
9360   "Toggle permanent full header display.
9361 If ARG is a positive number, turn header display on.
9362 If ARG is a negative number, turn header display off."
9363   (interactive "P")
9364   (setq gnus-show-all-headers
9365         (cond ((or (not (numberp arg))
9366                    (zerop arg))
9367                (not gnus-show-all-headers))
9368               ((natnump arg)
9369                t)))
9370   (gnus-summary-show-article))
9371
9372 (defun gnus-summary-toggle-header (&optional arg)
9373   "Show the headers if they are hidden, or hide them if they are shown.
9374 If ARG is a positive number, show the entire header.
9375 If ARG is a negative number, hide the unwanted header lines."
9376   (interactive "P")
9377   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9378                      (get-buffer-window gnus-article-buffer t))))
9379     (with-current-buffer gnus-article-buffer
9380       (widen)
9381       (article-narrow-to-head)
9382       (let* ((buffer-read-only nil)
9383              (inhibit-point-motion-hooks t)
9384              (hidden (if (numberp arg)
9385                          (>= arg 0)
9386                        (or (not (looking-at "[^ \t\n]+:"))
9387                            (gnus-article-hidden-text-p 'headers))))
9388              s e)
9389         (delete-region (point-min) (point-max))
9390         (with-current-buffer gnus-original-article-buffer
9391           (goto-char (setq s (point-min)))
9392           (setq e (if (search-forward "\n\n" nil t)
9393                       (1- (point))
9394                     (point-max))))
9395         (insert-buffer-substring gnus-original-article-buffer s e)
9396         (run-hooks 'gnus-article-decode-hook)
9397         (if hidden
9398             (let ((gnus-treat-hide-headers nil)
9399                   (gnus-treat-hide-boring-headers nil))
9400               (gnus-delete-wash-type 'headers)
9401               (gnus-treat-article 'head))
9402           (gnus-treat-article 'head))
9403         (widen)
9404         (if window
9405             (set-window-start window (goto-char (point-min))))
9406         (if gnus-break-pages
9407             (gnus-narrow-to-page)
9408           (when (gnus-visual-p 'page-marker)
9409             (let ((buffer-read-only nil))
9410               (gnus-remove-text-with-property 'gnus-prev)
9411               (gnus-remove-text-with-property 'gnus-next))))
9412         (gnus-set-mode-line 'article)))))
9413
9414 (defun gnus-summary-show-all-headers ()
9415   "Make all header lines visible."
9416   (interactive)
9417   (gnus-summary-toggle-header 1))
9418
9419 (defun gnus-summary-caesar-message (&optional arg)
9420   "Caesar rotate the current article by 13.
9421 With a non-numerical prefix, also rotate headers.  A numerical
9422 prefix specifies how many places to rotate each letter forward."
9423   (interactive "P")
9424   (gnus-summary-select-article)
9425   (let ((mail-header-separator ""))
9426     (gnus-eval-in-buffer-window gnus-article-buffer
9427       (save-restriction
9428         (widen)
9429         (let ((start (window-start))
9430               buffer-read-only)
9431           (if (equal arg '(4))
9432               (message-caesar-buffer-body nil t)
9433             (message-caesar-buffer-body arg))
9434           (set-window-start (get-buffer-window (current-buffer)) start)))))
9435   ;; Create buttons and stuff...
9436   (gnus-treat-article nil))
9437
9438 (defun gnus-summary-idna-message (&optional arg)
9439   "Decode IDNA encoded domain names in the current articles.
9440 IDNA encoded domain names looks like `xn--bar'.  If a string
9441 remain unencoded after running this function, it is likely an
9442 invalid IDNA string (`xn--bar' is invalid).
9443
9444 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9445 installed for this command to work."
9446   (interactive "P")
9447   (if (not (and (condition-case nil (require 'idna)
9448                   (file-error))
9449                 (mm-coding-system-p 'utf-8)
9450                 (executable-find (symbol-value 'idna-program))))
9451       (gnus-message
9452        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9453     (gnus-summary-select-article)
9454     (let ((mail-header-separator ""))
9455       (gnus-eval-in-buffer-window gnus-article-buffer
9456         (save-restriction
9457           (widen)
9458           (let ((start (window-start))
9459                 buffer-read-only)
9460             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9461               (replace-match (idna-to-unicode (match-string 1))))
9462             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9463
9464 (defun gnus-summary-morse-message (&optional arg)
9465   "Morse decode the current article."
9466   (interactive "P")
9467   (gnus-summary-select-article)
9468   (let ((mail-header-separator ""))
9469     (gnus-eval-in-buffer-window gnus-article-buffer
9470       (save-excursion
9471         (save-restriction
9472           (widen)
9473           (let ((pos (window-start))
9474                 buffer-read-only)
9475             (goto-char (point-min))
9476             (when (message-goto-body)
9477               (gnus-narrow-to-body))
9478             (goto-char (point-min))
9479             (while (search-forward "·" (point-max) t)
9480               (replace-match "."))
9481             (unmorse-region (point-min) (point-max))
9482             (widen)
9483             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9484
9485 (defun gnus-summary-stop-page-breaking ()
9486   "Stop page breaking in the current article."
9487   (interactive)
9488   (gnus-summary-select-article)
9489   (gnus-eval-in-buffer-window gnus-article-buffer
9490     (widen)
9491     (when (gnus-visual-p 'page-marker)
9492       (let ((buffer-read-only nil))
9493         (gnus-remove-text-with-property 'gnus-prev)
9494         (gnus-remove-text-with-property 'gnus-next))
9495       (setq gnus-page-broken nil))))
9496
9497 (defun gnus-summary-move-article (&optional n to-newsgroup
9498                                             select-method action)
9499   "Move the current article to a different newsgroup.
9500 If N is a positive number, move the N next articles.
9501 If N is a negative number, move the N previous articles.
9502 If N is nil and any articles have been marked with the process mark,
9503 move those articles instead.
9504 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9505 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9506 re-spool using this method.
9507
9508 When called interactively with TO-NEWSGROUP being nil, the value of
9509 the variable `gnus-move-split-methods' is used for finding a default
9510 for the target newsgroup.
9511
9512 For this function to work, both the current newsgroup and the
9513 newsgroup that you want to move to have to support the `request-move'
9514 and `request-accept' functions.
9515
9516 ACTION can be either `move' (the default), `crosspost' or `copy'."
9517   (interactive "P")
9518   (unless action
9519     (setq action 'move))
9520   ;; Check whether the source group supports the required functions.
9521   (cond ((and (eq action 'move)
9522               (not (gnus-check-backend-function
9523                     'request-move-article gnus-newsgroup-name)))
9524          (error "The current group does not support article moving"))
9525         ((and (eq action 'crosspost)
9526               (not (gnus-check-backend-function
9527                     'request-replace-article gnus-newsgroup-name)))
9528          (error "The current group does not support article editing")))
9529   (let ((articles (gnus-summary-work-articles n))
9530         (prefix (if (gnus-check-backend-function
9531                      'request-move-article gnus-newsgroup-name)
9532                     (funcall gnus-move-group-prefix-function
9533                              gnus-newsgroup-name)
9534                   ""))
9535         (names '((move "Move" "Moving")
9536                  (copy "Copy" "Copying")
9537                  (crosspost "Crosspost" "Crossposting")))
9538         (copy-buf (save-excursion
9539                     (nnheader-set-temp-buffer " *copy article*")))
9540         art-group to-method new-xref article to-groups
9541         articles-to-update-marks encoded)
9542     (unless (assq action names)
9543       (error "Unknown action %s" action))
9544     ;; Read the newsgroup name.
9545     (when (and (not to-newsgroup)
9546                (not select-method))
9547       (if (and gnus-move-split-methods
9548                (not
9549                 (and (memq gnus-current-article articles)
9550                      (gnus-buffer-live-p gnus-original-article-buffer))))
9551           ;; When `gnus-move-split-methods' is non-nil, we have to
9552           ;; select an article to give `gnus-read-move-group-name' an
9553           ;; opportunity to suggest an appropriate default.  However,
9554           ;; we needn't render or mark the article.
9555           (let ((gnus-display-mime-function nil)
9556                 (gnus-article-prepare-hook nil)
9557                 (gnus-mark-article-hook nil))
9558             (gnus-summary-select-article nil nil nil (car articles))))
9559       (setq to-newsgroup (gnus-read-move-group-name
9560                           (cadr (assq action names))
9561                           (symbol-value
9562                            (intern (format "gnus-current-%s-group" action)))
9563                           articles prefix)
9564             encoded to-newsgroup
9565             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9566       (set (intern (format "gnus-current-%s-group" action))
9567            (mm-decode-coding-string
9568             to-newsgroup
9569             (gnus-group-name-charset to-method to-newsgroup))))
9570     (unless to-method
9571       (setq to-method (or select-method
9572                           (gnus-server-to-method
9573                            (gnus-group-method to-newsgroup)))))
9574     (setq to-newsgroup
9575           (or encoded
9576               (and to-newsgroup
9577                    (mm-encode-coding-string
9578                     to-newsgroup
9579                     (gnus-group-name-charset to-method to-newsgroup)))))
9580     ;; Check the method we are to move this article to...
9581     (unless (gnus-check-backend-function
9582              'request-accept-article (car to-method))
9583       (error "%s does not support article copying" (car to-method)))
9584     (unless (gnus-check-server to-method)
9585       (error "Can't open server %s" (car to-method)))
9586     (gnus-message 6 "%s to %s: %s..."
9587                   (caddr (assq action names))
9588                   (or (car select-method)
9589                       (gnus-group-decoded-name to-newsgroup))
9590                   articles)
9591     (while articles
9592       (setq article (pop articles))
9593       (setq
9594        art-group
9595        (cond
9596         ;; Move the article.
9597         ((eq action 'move)
9598          ;; Remove this article from future suppression.
9599          (gnus-dup-unsuppress-article article)
9600          (let* ((from-method (gnus-find-method-for-group
9601                               gnus-newsgroup-name))
9602                 (to-method (or select-method
9603                                (gnus-find-method-for-group to-newsgroup)))
9604                 (move-is-internal (gnus-method-equal from-method to-method)))
9605            (gnus-request-move-article
9606             article                     ; Article to move
9607             gnus-newsgroup-name         ; From newsgroup
9608             (nth 1 (gnus-find-method-for-group
9609                     gnus-newsgroup-name)) ; Server
9610             (list 'gnus-request-accept-article
9611                   to-newsgroup (list 'quote select-method)
9612                   (not articles) t)     ; Accept form
9613             (not articles)              ; Only save nov last time
9614             move-is-internal)))         ; is this move internal?
9615         ;; Copy the article.
9616         ((eq action 'copy)
9617          (save-excursion
9618            (set-buffer copy-buf)
9619            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9620              (save-restriction
9621                (nnheader-narrow-to-headers)
9622                (dolist (hdr gnus-copy-article-ignored-headers)
9623                  (message-remove-header hdr t)))
9624              (gnus-request-accept-article
9625               to-newsgroup select-method (not articles) t))))
9626         ;; Crosspost the article.
9627         ((eq action 'crosspost)
9628          (let ((xref (message-tokenize-header
9629                       (mail-header-xref (gnus-summary-article-header article))
9630                       " ")))
9631            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9632                                   ":" (number-to-string article)))
9633            (unless xref
9634              (setq xref (list (system-name))))
9635            (setq new-xref
9636                  (concat
9637                   (mapconcat 'identity
9638                              (delete "Xref:" (delete new-xref xref))
9639                              " ")
9640                   " " new-xref))
9641            (save-excursion
9642              (set-buffer copy-buf)
9643              ;; First put the article in the destination group.
9644              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9645              (when (consp (setq art-group
9646                                 (gnus-request-accept-article
9647                                  to-newsgroup select-method (not articles) t)))
9648                (setq new-xref (concat new-xref " " (car art-group)
9649                                       ":"
9650                                       (number-to-string (cdr art-group))))
9651                ;; Now we have the new Xrefs header, so we insert
9652                ;; it and replace the new article.
9653                (nnheader-replace-header "Xref" new-xref)
9654                (gnus-request-replace-article
9655                 (cdr art-group) to-newsgroup (current-buffer) t)
9656                art-group))))))
9657       (cond
9658        ((not art-group)
9659         (gnus-message 1 "Couldn't %s article %s: %s"
9660                       (cadr (assq action names)) article
9661                       (nnheader-get-report (car to-method))))
9662        ((eq art-group 'junk)
9663         (when (eq action 'move)
9664           (gnus-summary-mark-article article gnus-canceled-mark)
9665           (gnus-message 4 "Deleted article %s" article)
9666           ;; run the delete hook
9667           (run-hook-with-args 'gnus-summary-article-delete-hook
9668                               action
9669                               (gnus-data-header
9670                                (assoc article (gnus-data-list nil)))
9671                               gnus-newsgroup-name nil
9672                               select-method)))
9673        (t
9674         (let* ((pto-group (gnus-group-prefixed-name
9675                            (car art-group) to-method))
9676                (info (gnus-get-info pto-group))
9677                (to-group (gnus-info-group info))
9678                to-marks)
9679           ;; Update the group that has been moved to.
9680           (when (and info
9681                      (memq action '(move copy)))
9682             (unless (member to-group to-groups)
9683               (push to-group to-groups))
9684
9685             (unless (memq article gnus-newsgroup-unreads)
9686               (push 'read to-marks)
9687               (gnus-info-set-read
9688                info (gnus-add-to-range (gnus-info-read info)
9689                                        (list (cdr art-group)))))
9690
9691             ;; See whether the article is to be put in the cache.
9692             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9693                              gnus-article-mark-lists
9694                            (delete '(expirable . expire)
9695                                    (copy-sequence gnus-article-mark-lists))))
9696                   (to-article (cdr art-group)))
9697
9698               ;; Enter the article into the cache in the new group,
9699               ;; if that is required.
9700               (when gnus-use-cache
9701                 (gnus-cache-possibly-enter-article
9702                  to-group to-article
9703                  (memq article gnus-newsgroup-marked)
9704                  (memq article gnus-newsgroup-dormant)
9705                  (memq article gnus-newsgroup-unreads)))
9706
9707               (when gnus-preserve-marks
9708                 ;; Copy any marks over to the new group.
9709                 (when (and (equal to-group gnus-newsgroup-name)
9710                            (not (memq article gnus-newsgroup-unreads)))
9711                   ;; Mark this article as read in this group.
9712                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9713                   (setcdr (gnus-active to-group) to-article)
9714                   (setcdr gnus-newsgroup-active to-article))
9715
9716                 (while marks
9717                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9718                     (when (memq article (symbol-value
9719                                          (intern (format "gnus-newsgroup-%s"
9720                                                          (caar marks)))))
9721                       (push (cdar marks) to-marks)
9722                       ;; If the other group is the same as this group,
9723                       ;; then we have to add the mark to the list.
9724                       (when (equal to-group gnus-newsgroup-name)
9725                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9726                              (cons to-article
9727                                    (symbol-value
9728                                     (intern (format "gnus-newsgroup-%s"
9729                                                     (caar marks)))))))
9730                       ;; Copy the marks to other group.
9731                       (gnus-add-marked-articles
9732                        to-group (cdar marks) (list to-article) info)))
9733                   (setq marks (cdr marks)))
9734
9735                 (gnus-request-set-mark
9736                  to-group (list (list (list to-article) 'add to-marks))))
9737
9738               (gnus-dribble-enter
9739                (concat "(gnus-group-set-info '"
9740                        (gnus-prin1-to-string (gnus-get-info to-group))
9741                        ")"))))
9742
9743           ;; Update the Xref header in this article to point to
9744           ;; the new crossposted article we have just created.
9745           (when (eq action 'crosspost)
9746             (save-excursion
9747               (set-buffer copy-buf)
9748               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9749               (nnheader-replace-header "Xref" new-xref)
9750               (gnus-request-replace-article
9751                article gnus-newsgroup-name (current-buffer) t)))
9752
9753           ;; run the move/copy/crosspost/respool hook
9754           (run-hook-with-args 'gnus-summary-article-move-hook
9755                               action
9756                               (gnus-data-header
9757                                (assoc article (gnus-data-list nil)))
9758                               gnus-newsgroup-name
9759                               to-newsgroup
9760                               select-method))
9761
9762         ;;;!!!Why is this necessary?
9763         (set-buffer gnus-summary-buffer)
9764
9765         (gnus-summary-goto-subject article)
9766         (when (eq action 'move)
9767           (gnus-summary-mark-article article gnus-canceled-mark))))
9768       (push article articles-to-update-marks))
9769
9770     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9771     ;; Re-activate all groups that have been moved to.
9772     (save-excursion
9773       (set-buffer gnus-group-buffer)
9774       (let ((gnus-group-marked to-groups))
9775         (gnus-group-get-new-news-this-group nil t)))
9776
9777     (gnus-kill-buffer copy-buf)
9778     (gnus-summary-position-point)
9779     (gnus-set-mode-line 'summary)))
9780
9781 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9782   "Copy the current article to some other group.
9783 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9784 When called interactively, if TO-NEWSGROUP is nil, use the value of
9785 the variable `gnus-move-split-methods' for finding a default target
9786 newsgroup.
9787 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9788 re-spool using this method."
9789   (interactive "P")
9790   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9791
9792 (defun gnus-summary-crosspost-article (&optional n)
9793   "Crosspost the current article to some other group."
9794   (interactive "P")
9795   (gnus-summary-move-article n nil nil 'crosspost))
9796
9797 (defcustom gnus-summary-respool-default-method nil
9798   "Default method type for respooling an article.
9799 If nil, use to the current newsgroup method."
9800   :type 'symbol
9801   :group 'gnus-summary-mail)
9802
9803 (defcustom gnus-summary-display-while-building nil
9804   "If non-nil, show and update the summary buffer as it's being built.
9805 If the value is t, update the buffer after every line is inserted.  If
9806 the value is an integer (N), update the display every N lines."
9807   :version "22.1"
9808   :group 'gnus-thread
9809   :type '(choice (const :tag "off" nil)
9810                  number
9811                  (const :tag "frequently" t)))
9812
9813 (defun gnus-summary-respool-article (&optional n method)
9814   "Respool the current article.
9815 The article will be squeezed through the mail spooling process again,
9816 which means that it will be put in some mail newsgroup or other
9817 depending on `nnmail-split-methods'.
9818 If N is a positive number, respool the N next articles.
9819 If N is a negative number, respool the N previous articles.
9820 If N is nil and any articles have been marked with the process mark,
9821 respool those articles instead.
9822
9823 Respooling can be done both from mail groups and \"real\" newsgroups.
9824 In the former case, the articles in question will be moved from the
9825 current group into whatever groups they are destined to.  In the
9826 latter case, they will be copied into the relevant groups."
9827   (interactive
9828    (list current-prefix-arg
9829          (let* ((methods (gnus-methods-using 'respool))
9830                 (methname
9831                  (symbol-name (or gnus-summary-respool-default-method
9832                                   (car (gnus-find-method-for-group
9833                                         gnus-newsgroup-name)))))
9834                 (method
9835                  (gnus-completing-read-with-default
9836                   methname "Backend to use when respooling"
9837                   methods nil t nil 'gnus-mail-method-history))
9838                 ms)
9839            (cond
9840             ((zerop (length (setq ms (gnus-servers-using-backend
9841                                       (intern method)))))
9842              (list (intern method) ""))
9843             ((= 1 (length ms))
9844              (car ms))
9845             (t
9846              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9847                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9848                            ms-alist))))))))
9849   (unless method
9850     (error "No method given for respooling"))
9851   (if (assoc (symbol-name
9852               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9853              (gnus-methods-using 'respool))
9854       (gnus-summary-move-article n nil method)
9855     (gnus-summary-copy-article n nil method)))
9856
9857 (defun gnus-summary-import-article (file &optional edit)
9858   "Import an arbitrary file into a mail newsgroup."
9859   (interactive "fImport file: \nP")
9860   (let ((group gnus-newsgroup-name)
9861         (now (current-time))
9862         atts lines group-art)
9863     (unless (gnus-check-backend-function 'request-accept-article group)
9864       (error "%s does not support article importing" group))
9865     (or (file-readable-p file)
9866         (not (file-regular-p file))
9867         (error "Can't read %s" file))
9868     (save-excursion
9869       (set-buffer (gnus-get-buffer-create " *import file*"))
9870       (erase-buffer)
9871       (nnheader-insert-file-contents file)
9872       (goto-char (point-min))
9873       (if (nnheader-article-p)
9874           (save-restriction
9875             (goto-char (point-min))
9876             (search-forward "\n\n" nil t)
9877             (narrow-to-region (point-min) (1- (point)))
9878             (goto-char (point-min))
9879             (unless (re-search-forward "^date:" nil t)
9880               (goto-char (point-max))
9881               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9882        ;; This doesn't look like an article, so we fudge some headers.
9883         (setq atts (file-attributes file)
9884               lines (count-lines (point-min) (point-max)))
9885         (insert "From: " (read-string "From: ") "\n"
9886                 "Subject: " (read-string "Subject: ") "\n"
9887                 "Date: " (message-make-date (nth 5 atts)) "\n"
9888                 "Message-ID: " (message-make-message-id) "\n"
9889                 "Lines: " (int-to-string lines) "\n"
9890                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9891       (setq group-art (gnus-request-accept-article group nil t))
9892       (kill-buffer (current-buffer)))
9893     (setq gnus-newsgroup-active (gnus-activate-group group))
9894     (forward-line 1)
9895     (gnus-summary-goto-article (cdr group-art) nil t)
9896     (when edit
9897       (gnus-summary-edit-article))))
9898
9899 (defun gnus-summary-create-article ()
9900   "Create an article in a mail newsgroup."
9901   (interactive)
9902   (let ((group gnus-newsgroup-name)
9903         (now (current-time))
9904         group-art)
9905     (unless (gnus-check-backend-function 'request-accept-article group)
9906       (error "%s does not support article importing" group))
9907     (save-excursion
9908       (set-buffer (gnus-get-buffer-create " *import file*"))
9909       (erase-buffer)
9910       (goto-char (point-min))
9911       ;; This doesn't look like an article, so we fudge some headers.
9912       (insert "From: " (read-string "From: ") "\n"
9913               "Subject: " (read-string "Subject: ") "\n"
9914               "Date: " (message-make-date now) "\n"
9915               "Message-ID: " (message-make-message-id) "\n")
9916       (setq group-art (gnus-request-accept-article group nil t))
9917       (kill-buffer (current-buffer)))
9918     (setq gnus-newsgroup-active (gnus-activate-group group))
9919     (forward-line 1)
9920     (gnus-summary-goto-article (cdr group-art) nil t)
9921     (gnus-summary-edit-article)))
9922
9923 (defun gnus-summary-article-posted-p ()
9924   "Say whether the current (mail) article is available from news as well.
9925 This will be the case if the article has both been mailed and posted."
9926   (interactive)
9927   (let ((id (mail-header-references (gnus-summary-article-header)))
9928         (gnus-override-method (car (gnus-refer-article-methods))))
9929     (if (gnus-request-head id "")
9930         (gnus-message 2 "The current message was found on %s"
9931                       gnus-override-method)
9932       (gnus-message 2 "The current message couldn't be found on %s"
9933                     gnus-override-method)
9934       nil)))
9935
9936 (defun gnus-summary-expire-articles (&optional now)
9937   "Expire all articles that are marked as expirable in the current group."
9938   (interactive)
9939   (when (and (not gnus-group-is-exiting-without-update-p)
9940              (gnus-check-backend-function
9941               'request-expire-articles gnus-newsgroup-name))
9942     ;; This backend supports expiry.
9943     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9944            (expirable (if total
9945                           (progn
9946                             ;; We need to update the info for
9947                             ;; this group for `gnus-list-of-read-articles'
9948                             ;; to give us the right answer.
9949                             (gnus-run-hooks 'gnus-exit-group-hook)
9950                             (gnus-summary-update-info)
9951                             (gnus-list-of-read-articles gnus-newsgroup-name))
9952                         (setq gnus-newsgroup-expirable
9953                               (sort gnus-newsgroup-expirable '<))))
9954            (expiry-wait (if now 'immediate
9955                           (gnus-group-find-parameter
9956                            gnus-newsgroup-name 'expiry-wait)))
9957            (nnmail-expiry-target
9958             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9959                 nnmail-expiry-target))
9960            es)
9961       (when expirable
9962         ;; There are expirable articles in this group, so we run them
9963         ;; through the expiry process.
9964         (gnus-message 6 "Expiring articles...")
9965         (unless (gnus-check-group gnus-newsgroup-name)
9966           (error "Can't open server for %s" gnus-newsgroup-name))
9967         ;; The list of articles that weren't expired is returned.
9968         (save-excursion
9969           (if expiry-wait
9970               (let ((nnmail-expiry-wait-function nil)
9971                     (nnmail-expiry-wait expiry-wait))
9972                 (setq es (gnus-request-expire-articles
9973                           expirable gnus-newsgroup-name)))
9974             (setq es (gnus-request-expire-articles
9975                       expirable gnus-newsgroup-name)))
9976           (unless total
9977             (setq gnus-newsgroup-expirable es))
9978           ;; We go through the old list of expirable, and mark all
9979           ;; really expired articles as nonexistent.
9980           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9981             (let ((gnus-use-cache nil))
9982               (dolist (article expirable)
9983                 (when (and (not (memq article es))
9984                            (gnus-data-find article))
9985                   (gnus-summary-mark-article article gnus-canceled-mark)
9986                   (run-hook-with-args 'gnus-summary-article-expire-hook
9987                                       'delete
9988                                       (gnus-data-header
9989                                        (assoc article (gnus-data-list nil)))
9990                                       gnus-newsgroup-name
9991                                       nil
9992                                       nil))))))
9993         (gnus-message 6 "Expiring articles...done")))))
9994
9995 (defun gnus-summary-expire-articles-now ()
9996   "Expunge all expirable articles in the current group.
9997 This means that *all* articles that are marked as expirable will be
9998 deleted forever, right now."
9999   (interactive)
10000   (or gnus-expert-user
10001       (gnus-yes-or-no-p
10002        "Are you really, really sure you want to delete all expirable messages? ")
10003       (error "Phew!"))
10004   (gnus-summary-expire-articles t))
10005
10006 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10007 (defun gnus-summary-delete-article (&optional n)
10008   "Delete the N next (mail) articles.
10009 This command actually deletes articles.  This is not a marking
10010 command.  The article will disappear forever from your life, never to
10011 return.
10012
10013 If N is negative, delete backwards.
10014 If N is nil and articles have been marked with the process mark,
10015 delete these instead.
10016
10017 If `gnus-novice-user' is non-nil you will be asked for
10018 confirmation before the articles are deleted."
10019   (interactive "P")
10020   (unless (gnus-check-backend-function 'request-expire-articles
10021                                        gnus-newsgroup-name)
10022     (error "The current newsgroup does not support article deletion"))
10023   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10024     (error "Couldn't open server"))
10025   ;; Compute the list of articles to delete.
10026   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10027         (nnmail-expiry-target 'delete)
10028         not-deleted)
10029     (if (and gnus-novice-user
10030              (not (gnus-yes-or-no-p
10031                    (format "Do you really want to delete %s forever? "
10032                            (if (> (length articles) 1)
10033                                (format "these %s articles" (length articles))
10034                              "this article")))))
10035         ()
10036       ;; Delete the articles.
10037       (setq not-deleted (gnus-request-expire-articles
10038                          articles gnus-newsgroup-name 'force))
10039       (while articles
10040         (gnus-summary-remove-process-mark (car articles))
10041         ;; The backend might not have been able to delete the article
10042         ;; after all.
10043         (unless (memq (car articles) not-deleted)
10044           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10045         (let* ((article (car articles))
10046                (ghead  (gnus-data-header
10047                                     (assoc article (gnus-data-list nil)))))
10048           (run-hook-with-args 'gnus-summary-article-delete-hook
10049                               'delete ghead gnus-newsgroup-name nil
10050                               nil))
10051         (setq articles (cdr articles)))
10052       (when not-deleted
10053         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10054     (gnus-summary-position-point)
10055     (gnus-set-mode-line 'summary)
10056     not-deleted))
10057
10058 (defun gnus-summary-edit-article (&optional arg)
10059   "Edit the current article.
10060 This will have permanent effect only in mail groups.
10061 If ARG is nil, edit the decoded articles.
10062 If ARG is 1, edit the raw articles.
10063 If ARG is 2, edit the raw articles even in read-only groups.
10064 If ARG is 3, edit the articles with the current handles.
10065 Otherwise, allow editing of articles even in read-only
10066 groups."
10067   (interactive "P")
10068   (let (force raw current-handles)
10069     (cond
10070      ((null arg))
10071      ((eq arg 1)
10072       (setq raw t))
10073      ((eq arg 2)
10074       (setq raw t
10075             force t))
10076      ((eq arg 3)
10077       (setq current-handles
10078             (and (gnus-buffer-live-p gnus-article-buffer)
10079                  (with-current-buffer gnus-article-buffer
10080                    (prog1
10081                        gnus-article-mime-handles
10082                      (setq gnus-article-mime-handles nil))))))
10083      (t
10084       (setq force t)))
10085     (when (and raw (not force)
10086                (member gnus-newsgroup-name '("nndraft:delayed"
10087                                              "nndraft:drafts"
10088                                              "nndraft:queue")))
10089       (error "Can't edit the raw article in group %s"
10090              gnus-newsgroup-name))
10091     (save-excursion
10092       (set-buffer gnus-summary-buffer)
10093       (let ((mail-parse-charset gnus-newsgroup-charset)
10094             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10095         (gnus-set-global-variables)
10096         (when (and (not force)
10097                    (gnus-group-read-only-p))
10098           (error "The current newsgroup does not support article editing"))
10099         (gnus-summary-show-article t)
10100         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10101           (with-current-buffer gnus-article-buffer
10102             (mm-enable-multibyte)))
10103         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10104             (setq raw t))
10105         (gnus-article-edit-article
10106          (if raw 'ignore
10107            `(lambda ()
10108               (let ((mbl mml-buffer-list))
10109                 (setq mml-buffer-list nil)
10110                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10111                   (mime-to-mml ,'current-handles))
10112                 (let ((mbl1 mml-buffer-list))
10113                   (setq mml-buffer-list mbl)
10114                   (set (make-local-variable 'mml-buffer-list) mbl1))
10115                 (gnus-make-local-hook 'kill-buffer-hook)
10116                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10117          `(lambda (no-highlight)
10118             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10119                   (message-options message-options)
10120                   (message-options-set-recipient)
10121                   (mail-parse-ignored-charsets
10122                    ',gnus-newsgroup-ignored-charsets)
10123                   (rfc2047-header-encoding-alist
10124                    ',(let ((charset (gnus-group-name-charset
10125                                      (gnus-find-method-for-group
10126                                       gnus-newsgroup-name)
10127                                      gnus-newsgroup-name)))
10128                        (append (list (cons "Newsgroups" charset)
10129                                      (cons "Followup-To" charset)
10130                                      (cons "Xref" charset))
10131                                rfc2047-header-encoding-alist))))
10132               ,(if (not raw) '(progn
10133                                 (mml-to-mime)
10134                                 (mml-destroy-buffers)
10135                                 (remove-hook 'kill-buffer-hook
10136                                              'mml-destroy-buffers t)
10137                                 (kill-local-variable 'mml-buffer-list)))
10138               (gnus-summary-edit-article-done
10139                ,(or (mail-header-references gnus-current-headers) "")
10140                ,(gnus-group-read-only-p)
10141                ,gnus-summary-buffer no-highlight))))))))
10142
10143 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10144
10145 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10146                                                  no-highlight)
10147   "Make edits to the current article permanent."
10148   (interactive)
10149   (save-excursion
10150    ;; The buffer restriction contains the entire article if it exists.
10151     (when (article-goto-body)
10152       (let ((lines (count-lines (point) (point-max)))
10153             (length (- (point-max) (point)))
10154             (case-fold-search t)
10155             (body (copy-marker (point))))
10156         (goto-char (point-min))
10157         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10158           (delete-region (match-beginning 1) (match-end 1))
10159           (insert (number-to-string length)))
10160         (goto-char (point-min))
10161         (when (re-search-forward
10162                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10163           (delete-region (match-beginning 1) (match-end 1))
10164           (insert (number-to-string length)))
10165         (goto-char (point-min))
10166         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10167           (delete-region (match-beginning 1) (match-end 1))
10168           (insert (number-to-string lines))))))
10169   ;; Replace the article.
10170   (let ((buf (current-buffer)))
10171     (with-temp-buffer
10172       (insert-buffer-substring buf)
10173
10174       (if (and (not read-only)
10175                (not (gnus-request-replace-article
10176                      (cdr gnus-article-current) (car gnus-article-current)
10177                      (current-buffer) t)))
10178           (error "Couldn't replace article")
10179         ;; Update the summary buffer.
10180         (if (and references
10181                  (equal (message-tokenize-header references " ")
10182                         (message-tokenize-header
10183                          (or (message-fetch-field "references") "") " ")))
10184             ;; We only have to update this line.
10185             (save-excursion
10186               (save-restriction
10187                 (message-narrow-to-head)
10188                 (let ((head (buffer-substring-no-properties
10189                              (point-min) (point-max)))
10190                       header)
10191                   (with-temp-buffer
10192                     (insert (format "211 %d Article retrieved.\n"
10193                                     (cdr gnus-article-current)))
10194                     (insert head)
10195                     (insert ".\n")
10196                     (let ((nntp-server-buffer (current-buffer)))
10197                       (setq header (car (gnus-get-newsgroup-headers
10198                                          nil t))))
10199                     (save-excursion
10200                       (set-buffer gnus-summary-buffer)
10201                       (gnus-data-set-header
10202                        (gnus-data-find (cdr gnus-article-current))
10203                        header)
10204                       (gnus-summary-update-article-line
10205                        (cdr gnus-article-current) header)
10206                       (if (gnus-summary-goto-subject
10207                            (cdr gnus-article-current) nil t)
10208                           (gnus-summary-update-secondary-mark
10209                            (cdr gnus-article-current))))))))
10210           ;; Update threads.
10211           (set-buffer (or buffer gnus-summary-buffer))
10212           (gnus-summary-update-article (cdr gnus-article-current))
10213           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10214               (gnus-summary-update-secondary-mark
10215                (cdr gnus-article-current))))
10216         ;; Prettify the article buffer again.
10217         (unless no-highlight
10218           (save-excursion
10219             (set-buffer gnus-article-buffer)
10220             ;;;!!! Fix this -- article should be rehighlighted.
10221             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10222             (set-buffer gnus-original-article-buffer)
10223             (gnus-request-article
10224              (cdr gnus-article-current)
10225              (car gnus-article-current) (current-buffer))))
10226         ;; Prettify the summary buffer line.
10227         (when (gnus-visual-p 'summary-highlight 'highlight)
10228           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10229
10230 (defun gnus-summary-edit-wash (key)
10231   "Perform editing command KEY in the article buffer."
10232   (interactive
10233    (list
10234     (progn
10235       (message "%s" (concat (this-command-keys) "- "))
10236       (read-char))))
10237   (message "")
10238   (gnus-summary-edit-article)
10239   (execute-kbd-macro (concat (this-command-keys) key))
10240   (gnus-article-edit-done))
10241
10242 ;;; Respooling
10243
10244 (defun gnus-summary-respool-query (&optional silent trace)
10245   "Query where the respool algorithm would put this article."
10246   (interactive)
10247   (let (gnus-mark-article-hook)
10248     (gnus-summary-select-article)
10249     (save-excursion
10250       (set-buffer gnus-original-article-buffer)
10251       (let ((groups (nnmail-article-group 'identity trace)))
10252         (unless silent
10253           (if groups
10254               (message "This message would go to %s"
10255                        (mapconcat 'car groups ", "))
10256             (message "This message would go to no groups"))
10257           groups)))))
10258
10259 (defun gnus-summary-respool-trace ()
10260   "Trace where the respool algorithm would put this article.
10261 Display a buffer showing all fancy splitting patterns which matched."
10262   (interactive)
10263   (gnus-summary-respool-query nil t))
10264
10265 ;; Summary marking commands.
10266
10267 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10268   "Mark articles which has the same subject as read, and then select the next.
10269 If UNMARK is positive, remove any kind of mark.
10270 If UNMARK is negative, tick articles."
10271   (interactive "P")
10272   (when unmark
10273     (setq unmark (prefix-numeric-value unmark)))
10274   (let ((count
10275          (gnus-summary-mark-same-subject
10276           (gnus-summary-article-subject) unmark)))
10277     ;; Select next unread article.  If auto-select-same mode, should
10278     ;; select the first unread article.
10279     (gnus-summary-next-article t (and gnus-auto-select-same
10280                                       (gnus-summary-article-subject)))
10281     (gnus-message 7 "%d article%s marked as %s"
10282                   count (if (= count 1) " is" "s are")
10283                   (if unmark "unread" "read"))))
10284
10285 (defun gnus-summary-kill-same-subject (&optional unmark)
10286   "Mark articles which has the same subject as read.
10287 If UNMARK is positive, remove any kind of mark.
10288 If UNMARK is negative, tick articles."
10289   (interactive "P")
10290   (when unmark
10291     (setq unmark (prefix-numeric-value unmark)))
10292   (let ((count
10293          (gnus-summary-mark-same-subject
10294           (gnus-summary-article-subject) unmark)))
10295     ;; If marked as read, go to next unread subject.
10296     (when (null unmark)
10297       ;; Go to next unread subject.
10298       (gnus-summary-next-subject 1 t))
10299     (gnus-message 7 "%d articles are marked as %s"
10300                   count (if unmark "unread" "read"))))
10301
10302 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10303   "Mark articles with same SUBJECT as read, and return marked number.
10304 If optional argument UNMARK is positive, remove any kinds of marks.
10305 If optional argument UNMARK is negative, mark articles as unread instead."
10306   (let ((count 1))
10307     (save-excursion
10308       (cond
10309        ((null unmark)                   ; Mark as read.
10310         (while (and
10311                 (progn
10312                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10313                   (gnus-summary-show-thread) t)
10314                 (gnus-summary-find-subject subject))
10315           (setq count (1+ count))))
10316        ((> unmark 0)                    ; Tick.
10317         (while (and
10318                 (progn
10319                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10320                   (gnus-summary-show-thread) t)
10321                 (gnus-summary-find-subject subject))
10322           (setq count (1+ count))))
10323        (t                               ; Mark as unread.
10324         (while (and
10325                 (progn
10326                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10327                   (gnus-summary-show-thread) t)
10328                 (gnus-summary-find-subject subject))
10329           (setq count (1+ count)))))
10330       (gnus-set-mode-line 'summary)
10331       ;; Return the number of marked articles.
10332       count)))
10333
10334 (defun gnus-summary-mark-as-processable (n &optional unmark)
10335   "Set the process mark on the next N articles.
10336 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10337 the process mark instead.  The difference between N and the actual
10338 number of articles marked is returned."
10339   (interactive "P")
10340   (if (and (null n) (gnus-region-active-p))
10341       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10342     (setq n (prefix-numeric-value n))
10343     (let ((backward (< n 0))
10344           (n (abs n)))
10345       (while (and
10346               (> n 0)
10347               (if unmark
10348                   (gnus-summary-remove-process-mark
10349                    (gnus-summary-article-number))
10350                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10351               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10352         (setq n (1- n)))
10353       (when (/= 0 n)
10354         (gnus-message 7 "No more articles"))
10355       (gnus-summary-recenter)
10356       (gnus-summary-position-point)
10357       n)))
10358
10359 (defun gnus-summary-unmark-as-processable (n)
10360   "Remove the process mark from the next N articles.
10361 If N is negative, unmark backward instead.  The difference between N and
10362 the actual number of articles unmarked is returned."
10363   (interactive "P")
10364   (gnus-summary-mark-as-processable n t))
10365
10366 (defun gnus-summary-unmark-all-processable ()
10367   "Remove the process mark from all articles."
10368   (interactive)
10369   (save-excursion
10370     (while gnus-newsgroup-processable
10371       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10372   (gnus-summary-position-point))
10373
10374 (defun gnus-summary-add-mark (article type)
10375   "Mark ARTICLE with a mark of TYPE."
10376   (let ((vtype (car (assq type gnus-article-mark-lists)))
10377         var)
10378     (if (not vtype)
10379         (error "No such mark type: %s" type)
10380       (setq var (intern (format "gnus-newsgroup-%s" type)))
10381       (set var (cons article (symbol-value var)))
10382       (if (memq type '(processable cached replied forwarded recent saved))
10383           (gnus-summary-update-secondary-mark article)
10384         ;;; !!! This is bogus.  We should find out what primary
10385         ;;; !!! mark we want to set.
10386         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10387
10388 (defun gnus-summary-mark-as-expirable (n)
10389   "Mark N articles forward as expirable.
10390 If N is negative, mark backward instead.  The difference between N and
10391 the actual number of articles marked is returned."
10392   (interactive "p")
10393   (gnus-summary-mark-forward n gnus-expirable-mark))
10394
10395 (defun gnus-summary-mark-as-spam (n)
10396   "Mark N articles forward as spam.
10397 If N is negative, mark backward instead.  The difference between N and
10398 the actual number of articles marked is returned."
10399   (interactive "p")
10400   (gnus-summary-mark-forward n gnus-spam-mark))
10401
10402 (defun gnus-summary-mark-article-as-replied (article)
10403   "Mark ARTICLE as replied to and update the summary line.
10404 ARTICLE can also be a list of articles."
10405   (interactive (list (gnus-summary-article-number)))
10406   (let ((articles (if (listp article) article (list article))))
10407     (dolist (article articles)
10408       (unless (numberp article)
10409         (error "%s is not a number" article))
10410       (push article gnus-newsgroup-replied)
10411       (let ((buffer-read-only nil))
10412         (when (gnus-summary-goto-subject article nil t)
10413           (gnus-summary-update-secondary-mark article))))))
10414
10415 (defun gnus-summary-mark-article-as-forwarded (article)
10416   "Mark ARTICLE as forwarded and update the summary line.
10417 ARTICLE can also be a list of articles."
10418   (let ((articles (if (listp article) article (list article))))
10419     (dolist (article articles)
10420       (push article gnus-newsgroup-forwarded)
10421       (let ((buffer-read-only nil))
10422         (when (gnus-summary-goto-subject article nil t)
10423           (gnus-summary-update-secondary-mark article))))))
10424
10425 (defun gnus-summary-set-bookmark (article)
10426   "Set a bookmark in current article."
10427   (interactive (list (gnus-summary-article-number)))
10428   (when (or (not (get-buffer gnus-article-buffer))
10429             (not gnus-current-article)
10430             (not gnus-article-current)
10431             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10432     (error "No current article selected"))
10433   ;; Remove old bookmark, if one exists.
10434   (gnus-pull article gnus-newsgroup-bookmarks)
10435   ;; Set the new bookmark, which is on the form
10436   ;; (article-number . line-number-in-body).
10437   (push
10438    (cons article
10439          (with-current-buffer gnus-article-buffer
10440            (count-lines
10441             (min (point)
10442                  (save-excursion
10443                    (article-goto-body)
10444                    (point)))
10445             (point))))
10446    gnus-newsgroup-bookmarks)
10447   (gnus-message 6 "A bookmark has been added to the current article."))
10448
10449 (defun gnus-summary-remove-bookmark (article)
10450   "Remove the bookmark from the current article."
10451   (interactive (list (gnus-summary-article-number)))
10452   ;; Remove old bookmark, if one exists.
10453   (if (not (assq article gnus-newsgroup-bookmarks))
10454       (gnus-message 6 "No bookmark in current article.")
10455     (gnus-pull article gnus-newsgroup-bookmarks)
10456     (gnus-message 6 "Removed bookmark.")))
10457
10458 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10459 (defun gnus-summary-mark-as-dormant (n)
10460   "Mark N articles forward as dormant.
10461 If N is negative, mark backward instead.  The difference between N and
10462 the actual number of articles marked is returned."
10463   (interactive "p")
10464   (gnus-summary-mark-forward n gnus-dormant-mark))
10465
10466 (defun gnus-summary-set-process-mark (article)
10467   "Set the process mark on ARTICLE and update the summary line."
10468   (setq gnus-newsgroup-processable
10469         (cons article
10470               (delq article gnus-newsgroup-processable)))
10471   (when (gnus-summary-goto-subject article)
10472     (gnus-summary-show-thread)
10473     (gnus-summary-goto-subject article)
10474     (gnus-summary-update-secondary-mark article)))
10475
10476 (defun gnus-summary-remove-process-mark (&rest articles)
10477   "Remove the process mark from ARTICLES and update the summary line."
10478   (dolist (article articles)
10479     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10480     (when (gnus-summary-goto-subject article)
10481       (gnus-summary-show-thread)
10482       (gnus-summary-goto-subject article)
10483       (gnus-summary-update-secondary-mark article)))
10484   t)
10485
10486 (defun gnus-summary-set-saved-mark (article)
10487   "Set the process mark on ARTICLE and update the summary line."
10488   (push article gnus-newsgroup-saved)
10489   (when (gnus-summary-goto-subject article)
10490     (gnus-summary-update-secondary-mark article)))
10491
10492 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10493   "Mark N articles as read forwards.
10494 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10495 The difference between N and the actual number of articles marked is
10496 returned.
10497 If NO-EXPIRE, auto-expiry will be inhibited."
10498   (interactive "p")
10499   (gnus-summary-show-thread)
10500   (let ((backward (< n 0))
10501         (gnus-summary-goto-unread
10502          (and gnus-summary-goto-unread
10503               (not (eq gnus-summary-goto-unread 'never))
10504               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10505                                     gnus-ticked-mark gnus-dormant-mark)))))
10506         (n (abs n))
10507         (mark (or mark gnus-del-mark)))
10508     (while (and (> n 0)
10509                 (gnus-summary-mark-article nil mark no-expire)
10510                 (zerop (gnus-summary-next-subject
10511                         (if backward -1 1)
10512                         (and gnus-summary-goto-unread
10513                              (not (eq gnus-summary-goto-unread 'never)))
10514                         t)))
10515       (setq n (1- n)))
10516     (when (/= 0 n)
10517       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10518     (gnus-summary-recenter)
10519     (gnus-summary-position-point)
10520     (gnus-set-mode-line 'summary)
10521     n))
10522
10523 (defun gnus-summary-mark-article-as-read (mark)
10524   "Mark the current article quickly as read with MARK."
10525   (let ((article (gnus-summary-article-number)))
10526     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10527     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10528     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10529     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10530     (push (cons article mark) gnus-newsgroup-reads)
10531     ;; Possibly remove from cache, if that is used.
10532     (when gnus-use-cache
10533       (gnus-cache-enter-remove-article article))
10534     ;; Allow the backend to change the mark.
10535     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10536     ;; Check for auto-expiry.
10537     (when (and gnus-newsgroup-auto-expire
10538                (memq mark gnus-auto-expirable-marks))
10539       (setq mark gnus-expirable-mark)
10540       ;; Let the backend know about the mark change.
10541       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10542       (push article gnus-newsgroup-expirable))
10543     ;; Set the mark in the buffer.
10544     (gnus-summary-update-mark mark 'unread)
10545     t))
10546
10547 (defun gnus-summary-mark-article-as-unread (mark)
10548   "Mark the current article quickly as unread with MARK."
10549   (let* ((article (gnus-summary-article-number))
10550          (old-mark (gnus-summary-article-mark article)))
10551     ;; Allow the backend to change the mark.
10552     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10553     (if (eq mark old-mark)
10554         t
10555       (if (<= article 0)
10556           (progn
10557             (gnus-error 1 "Can't mark negative article numbers")
10558             nil)
10559         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10560         (setq gnus-newsgroup-spam-marked
10561               (delq article gnus-newsgroup-spam-marked))
10562         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10563         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10564         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10565         (cond ((= mark gnus-ticked-mark)
10566                (setq gnus-newsgroup-marked
10567                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10568                                               article)))
10569               ((= mark gnus-spam-mark)
10570                (setq gnus-newsgroup-spam-marked
10571                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10572                                               article)))
10573               ((= mark gnus-dormant-mark)
10574                (setq gnus-newsgroup-dormant
10575                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10576                                               article)))
10577               (t
10578                (setq gnus-newsgroup-unreads
10579                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10580                                               article))))
10581         (gnus-pull article gnus-newsgroup-reads)
10582
10583         ;; See whether the article is to be put in the cache.
10584         (and gnus-use-cache
10585              (vectorp (gnus-summary-article-header article))
10586              (save-excursion
10587                (gnus-cache-possibly-enter-article
10588                 gnus-newsgroup-name article
10589                 (= mark gnus-ticked-mark)
10590                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10591
10592         ;; Fix the mark.
10593         (gnus-summary-update-mark mark 'unread)
10594         t))))
10595
10596 (defun gnus-summary-mark-article (&optional article mark no-expire)
10597   "Mark ARTICLE with MARK.  MARK can be any character.
10598 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10599 `??' (dormant) and `?E' (expirable).
10600 If MARK is nil, then the default character `?r' is used.
10601 If ARTICLE is nil, then the article on the current line will be
10602 marked.
10603 If NO-EXPIRE, auto-expiry will be inhibited."
10604   ;; The mark might be a string.
10605   (when (stringp mark)
10606     (setq mark (aref mark 0)))
10607   ;; If no mark is given, then we check auto-expiring.
10608   (when (null mark)
10609     (setq mark gnus-del-mark))
10610   (when (and (not no-expire)
10611              gnus-newsgroup-auto-expire
10612              (memq mark gnus-auto-expirable-marks))
10613     (setq mark gnus-expirable-mark))
10614   (let ((article (or article (gnus-summary-article-number)))
10615         (old-mark (gnus-summary-article-mark article)))
10616     ;; Allow the backend to change the mark.
10617     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10618     (if (eq mark old-mark)
10619         t
10620       (unless article
10621         (error "No article on current line"))
10622       (if (not (if (or (= mark gnus-unread-mark)
10623                        (= mark gnus-ticked-mark)
10624                        (= mark gnus-spam-mark)
10625                        (= mark gnus-dormant-mark))
10626                    (gnus-mark-article-as-unread article mark)
10627                  (gnus-mark-article-as-read article mark)))
10628           t
10629         ;; See whether the article is to be put in the cache.
10630         (and gnus-use-cache
10631              (not (= mark gnus-canceled-mark))
10632              (vectorp (gnus-summary-article-header article))
10633              (save-excursion
10634                (gnus-cache-possibly-enter-article
10635                 gnus-newsgroup-name article
10636                 (= mark gnus-ticked-mark)
10637                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10638
10639         (when (gnus-summary-goto-subject article nil t)
10640           (let ((buffer-read-only nil))
10641             (gnus-summary-show-thread)
10642             ;; Fix the mark.
10643             (gnus-summary-update-mark mark 'unread)
10644             t))))))
10645
10646 (defun gnus-summary-update-secondary-mark (article)
10647   "Update the secondary (read, process, cache) mark."
10648   (gnus-summary-update-mark
10649    (cond ((memq article gnus-newsgroup-processable)
10650           gnus-process-mark)
10651          ((memq article gnus-newsgroup-cached)
10652           gnus-cached-mark)
10653          ((memq article gnus-newsgroup-replied)
10654           gnus-replied-mark)
10655          ((memq article gnus-newsgroup-forwarded)
10656           gnus-forwarded-mark)
10657          ((memq article gnus-newsgroup-saved)
10658           gnus-saved-mark)
10659          ((memq article gnus-newsgroup-recent)
10660           gnus-recent-mark)
10661          ((memq article gnus-newsgroup-unseen)
10662           gnus-unseen-mark)
10663          (t gnus-no-mark))
10664    'replied)
10665   (when (gnus-visual-p 'summary-highlight 'highlight)
10666     (gnus-run-hooks 'gnus-summary-update-hook))
10667   t)
10668
10669 (defun gnus-summary-update-download-mark (article)
10670   "Update the download mark."
10671   (gnus-summary-update-mark
10672    (cond ((memq article gnus-newsgroup-undownloaded)
10673           gnus-undownloaded-mark)
10674          (gnus-newsgroup-agentized
10675           gnus-downloaded-mark)
10676          (t
10677           gnus-no-mark))
10678    'download)
10679   (gnus-summary-update-line t)
10680   t)
10681
10682 (defun gnus-summary-update-mark (mark type)
10683   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10684         (buffer-read-only nil))
10685     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10686     (when forward
10687       (when (looking-at "\r")
10688         (incf forward))
10689       (when (<= (+ forward (point)) (point-max))
10690         ;; Go to the right position on the line.
10691         (goto-char (+ forward (point)))
10692         ;; Replace the old mark with the new mark.
10693         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10694         ;; Optionally update the marks by some user rule.
10695         (when (eq type 'unread)
10696           (gnus-data-set-mark
10697            (gnus-data-find (gnus-summary-article-number)) mark)
10698           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10699
10700 (defun gnus-mark-article-as-read (article &optional mark)
10701   "Enter ARTICLE in the pertinent lists and remove it from others."
10702   ;; Make the article expirable.
10703   (let ((mark (or mark gnus-del-mark)))
10704     (setq gnus-newsgroup-expirable
10705           (if (= mark gnus-expirable-mark)
10706               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10707             (delq article gnus-newsgroup-expirable)))
10708     ;; Remove from unread and marked lists.
10709     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10710     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10711     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10712     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10713     (push (cons article mark) gnus-newsgroup-reads)
10714     ;; Possibly remove from cache, if that is used.
10715     (when gnus-use-cache
10716       (gnus-cache-enter-remove-article article))
10717     t))
10718
10719 (defun gnus-mark-article-as-unread (article &optional mark)
10720   "Enter ARTICLE in the pertinent lists and remove it from others."
10721   (let ((mark (or mark gnus-ticked-mark)))
10722     (if (<= article 0)
10723         (progn
10724           (gnus-error 1 "Can't mark negative article numbers")
10725           nil)
10726       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10727             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10728             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10729             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10730             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10731
10732       ;; Unsuppress duplicates?
10733       (when gnus-suppress-duplicates
10734         (gnus-dup-unsuppress-article article))
10735
10736       (cond ((= mark gnus-ticked-mark)
10737              (setq gnus-newsgroup-marked
10738                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10739             ((= mark gnus-spam-mark)
10740              (setq gnus-newsgroup-spam-marked
10741                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10742                                             article)))
10743             ((= mark gnus-dormant-mark)
10744              (setq gnus-newsgroup-dormant
10745                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10746             (t
10747              (setq gnus-newsgroup-unreads
10748                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10749       (gnus-pull article gnus-newsgroup-reads)
10750       t)))
10751
10752 (defalias 'gnus-summary-mark-as-unread-forward
10753   'gnus-summary-tick-article-forward)
10754 (make-obsolete 'gnus-summary-mark-as-unread-forward
10755                'gnus-summary-tick-article-forward)
10756 (defun gnus-summary-tick-article-forward (n)
10757   "Tick N articles forwards.
10758 If N is negative, tick backwards instead.
10759 The difference between N and the number of articles ticked is returned."
10760   (interactive "p")
10761   (gnus-summary-mark-forward n gnus-ticked-mark))
10762
10763 (defalias 'gnus-summary-mark-as-unread-backward
10764   'gnus-summary-tick-article-backward)
10765 (make-obsolete 'gnus-summary-mark-as-unread-backward
10766                'gnus-summary-tick-article-backward)
10767 (defun gnus-summary-tick-article-backward (n)
10768   "Tick N articles backwards.
10769 The difference between N and the number of articles ticked is returned."
10770   (interactive "p")
10771   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10772
10773 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10774 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10775 (defun gnus-summary-tick-article (&optional article clear-mark)
10776   "Mark current article as unread.
10777 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10778 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10779   (interactive)
10780   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10781                                        gnus-ticked-mark)))
10782
10783 (defun gnus-summary-mark-as-read-forward (n)
10784   "Mark N articles as read forwards.
10785 If N is negative, mark backwards instead.
10786 The difference between N and the actual number of articles marked is
10787 returned."
10788   (interactive "p")
10789   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10790
10791 (defun gnus-summary-mark-as-read-backward (n)
10792   "Mark the N articles as read backwards.
10793 The difference between N and the actual number of articles marked is
10794 returned."
10795   (interactive "p")
10796   (gnus-summary-mark-forward
10797    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10798
10799 (defun gnus-summary-mark-as-read (&optional article mark)
10800   "Mark current article as read.
10801 ARTICLE specifies the article to be marked as read.
10802 MARK specifies a string to be inserted at the beginning of the line."
10803   (gnus-summary-mark-article article mark))
10804
10805 (defun gnus-summary-clear-mark-forward (n)
10806   "Clear marks from N articles forward.
10807 If N is negative, clear backward instead.
10808 The difference between N and the number of marks cleared is returned."
10809   (interactive "p")
10810   (gnus-summary-mark-forward n gnus-unread-mark))
10811
10812 (defun gnus-summary-clear-mark-backward (n)
10813   "Clear marks from N articles backward.
10814 The difference between N and the number of marks cleared is returned."
10815   (interactive "p")
10816   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10817
10818 (defun gnus-summary-mark-unread-as-read ()
10819   "Intended to be used by `gnus-summary-mark-article-hook'."
10820   (when (memq gnus-current-article gnus-newsgroup-unreads)
10821     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10822
10823 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10824   "Intended to be used by `gnus-summary-mark-article-hook'."
10825   (let ((mark (gnus-summary-article-mark)))
10826     (when (or (gnus-unread-mark-p mark)
10827               (gnus-read-mark-p mark))
10828       (gnus-summary-mark-article gnus-current-article
10829                                  (or new-mark gnus-read-mark)))))
10830
10831 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10832   "Intended to be used by `gnus-summary-mark-article-hook'."
10833   (let ((mark (gnus-summary-article-mark)))
10834     (when (or (gnus-unread-mark-p mark)
10835               (gnus-read-mark-p mark))
10836       (gnus-summary-mark-article (gnus-summary-article-number)
10837                                  (or new-mark gnus-read-mark)))))
10838
10839 (defun gnus-summary-mark-unread-as-ticked ()
10840   "Intended to be used by `gnus-summary-mark-article-hook'."
10841   (when (memq gnus-current-article gnus-newsgroup-unreads)
10842     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10843
10844 (defun gnus-summary-mark-region-as-read (point mark all)
10845   "Mark all unread articles between point and mark as read.
10846 If given a prefix, mark all articles between point and mark as read,
10847 even ticked and dormant ones."
10848   (interactive "r\nP")
10849   (save-excursion
10850     (let (article)
10851       (goto-char point)
10852       (beginning-of-line)
10853       (while (and
10854               (< (point) mark)
10855               (progn
10856                 (when (or all
10857                           (memq (setq article (gnus-summary-article-number))
10858                                 gnus-newsgroup-unreads))
10859                   (gnus-summary-mark-article article gnus-del-mark))
10860                 t)
10861               (gnus-summary-find-next))))))
10862
10863 (defun gnus-summary-mark-below (score mark)
10864   "Mark articles with score less than SCORE with MARK."
10865   (interactive "P\ncMark: ")
10866   (setq score (if score
10867                   (prefix-numeric-value score)
10868                 (or gnus-summary-default-score 0)))
10869   (save-excursion
10870     (set-buffer gnus-summary-buffer)
10871     (goto-char (point-min))
10872     (while
10873         (progn
10874           (and (< (gnus-summary-article-score) score)
10875                (gnus-summary-mark-article nil mark))
10876           (gnus-summary-find-next)))))
10877
10878 (defun gnus-summary-kill-below (&optional score)
10879   "Mark articles with score below SCORE as read."
10880   (interactive "P")
10881   (gnus-summary-mark-below score gnus-killed-mark))
10882
10883 (defun gnus-summary-clear-above (&optional score)
10884   "Clear all marks from articles with score above SCORE."
10885   (interactive "P")
10886   (gnus-summary-mark-above score gnus-unread-mark))
10887
10888 (defun gnus-summary-tick-above (&optional score)
10889   "Tick all articles with score above SCORE."
10890   (interactive "P")
10891   (gnus-summary-mark-above score gnus-ticked-mark))
10892
10893 (defun gnus-summary-mark-above (score mark)
10894   "Mark articles with score over SCORE with MARK."
10895   (interactive "P\ncMark: ")
10896   (setq score (if score
10897                   (prefix-numeric-value score)
10898                 (or gnus-summary-default-score 0)))
10899   (save-excursion
10900     (set-buffer gnus-summary-buffer)
10901     (goto-char (point-min))
10902     (while (and (progn
10903                   (when (> (gnus-summary-article-score) score)
10904                     (gnus-summary-mark-article nil mark))
10905                   t)
10906                 (gnus-summary-find-next)))))
10907
10908 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10909 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10910 (defun gnus-summary-limit-include-expunged (&optional no-error)
10911   "Display all the hidden articles that were expunged for low scores."
10912   (interactive)
10913   (let ((buffer-read-only nil))
10914     (let ((scored gnus-newsgroup-scored)
10915           headers h)
10916       (while scored
10917         (unless (gnus-summary-article-header (caar scored))
10918           (and (setq h (gnus-number-to-header (caar scored)))
10919                (< (cdar scored) gnus-summary-expunge-below)
10920                (push h headers)))
10921         (setq scored (cdr scored)))
10922       (if (not headers)
10923           (when (not no-error)
10924             (error "No expunged articles hidden"))
10925         (goto-char (point-min))
10926         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10927         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10928         (dolist (x headers)
10929           (push (mail-header-number x) gnus-newsgroup-limit))
10930         (gnus-summary-prepare-unthreaded (nreverse headers))
10931         (goto-char (point-min))
10932         (gnus-summary-position-point)
10933         t))))
10934
10935 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10936   "Mark all unread articles in this newsgroup as read.
10937 If prefix argument ALL is non-nil, ticked and dormant articles will
10938 also be marked as read.
10939 If QUIETLY is non-nil, no questions will be asked.
10940
10941 If TO-HERE is non-nil, it should be a point in the buffer.  All
10942 articles before (after, if REVERSE is set) this point will be marked
10943 as read.
10944
10945 Note that this function will only catch up the unread article
10946 in the current summary buffer limitation.
10947
10948 The number of articles marked as read is returned."
10949   (interactive "P")
10950   (prog1
10951       (save-excursion
10952         (when (or quietly
10953                   (not gnus-interactive-catchup) ;Without confirmation?
10954                   gnus-expert-user
10955                   (gnus-y-or-n-p
10956                    (if all
10957                        "Mark absolutely all articles as read? "
10958                      "Mark all unread articles as read? ")))
10959           (if (and not-mark
10960                    (not gnus-newsgroup-adaptive)
10961                    (not gnus-newsgroup-auto-expire)
10962                    (not gnus-suppress-duplicates)
10963                    (or (not gnus-use-cache)
10964                        (eq gnus-use-cache 'passive)))
10965               (progn
10966                 (when all
10967                   (setq gnus-newsgroup-marked nil
10968                         gnus-newsgroup-spam-marked nil
10969                         gnus-newsgroup-dormant nil))
10970                 (setq gnus-newsgroup-unreads
10971                       (gnus-sorted-nunion
10972                        (gnus-sorted-intersection gnus-newsgroup-unreads
10973                                                  gnus-newsgroup-downloadable)
10974                        (gnus-sorted-difference gnus-newsgroup-unfetched
10975                                                gnus-newsgroup-cached))))
10976             ;; We actually mark all articles as canceled, which we
10977             ;; have to do when using auto-expiry or adaptive scoring.
10978             (gnus-summary-show-all-threads)
10979             (if (and to-here reverse)
10980                 (progn
10981                   (goto-char to-here)
10982                   (gnus-summary-mark-current-read-and-unread-as-read
10983                    gnus-catchup-mark)
10984                   (while (gnus-summary-find-next (not all))
10985                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10986               (when (gnus-summary-first-subject (not all))
10987                 (while (and
10988                         (if to-here (< (point) to-here) t)
10989                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10990                         (gnus-summary-find-next (not all))))))
10991             (gnus-set-mode-line 'summary))
10992           t))
10993     (gnus-summary-position-point)))
10994
10995 (defun gnus-summary-catchup-to-here (&optional all)
10996   "Mark all unticked articles before the current one as read.
10997 If ALL is non-nil, also mark ticked and dormant articles as read."
10998   (interactive "P")
10999   (save-excursion
11000     (gnus-save-hidden-threads
11001       (let ((beg (point)))
11002         ;; We check that there are unread articles.
11003         (when (or all (gnus-summary-find-prev))
11004           (gnus-summary-catchup all t beg)))))
11005   (gnus-summary-position-point))
11006
11007 (defun gnus-summary-catchup-from-here (&optional all)
11008   "Mark all unticked articles after (and including) the current one as read.
11009 If ALL is non-nil, also mark ticked and dormant articles as read."
11010   (interactive "P")
11011   (save-excursion
11012     (gnus-save-hidden-threads
11013       (let ((beg (point)))
11014         ;; We check that there are unread articles.
11015         (when (or all (gnus-summary-find-next))
11016           (gnus-summary-catchup all t beg nil t)))))
11017   (gnus-summary-position-point))
11018
11019 (defun gnus-summary-catchup-all (&optional quietly)
11020   "Mark all articles in this newsgroup as read.
11021 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11022 instead, which marks only unread articles as read."
11023   (interactive "P")
11024   (gnus-summary-catchup t quietly))
11025
11026 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11027   "Mark all unread articles in this group as read, then exit.
11028 If prefix argument ALL is non-nil, all articles are marked as read.
11029 If QUIETLY is non-nil, no questions will be asked."
11030   (interactive "P")
11031   (when (gnus-summary-catchup all quietly nil 'fast)
11032     ;; Select next newsgroup or exit.
11033     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11034              (eq gnus-auto-select-next 'quietly))
11035         (gnus-summary-next-group nil)
11036       (gnus-summary-exit))))
11037
11038 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11039   "Mark all articles in this newsgroup as read, and then exit.
11040 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11041 instead, which marks only unread articles as read."
11042   (interactive "P")
11043   (gnus-summary-catchup-and-exit t quietly))
11044
11045 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11046   "Mark all articles in this group as read and select the next group.
11047 If given a prefix, mark all articles, unread as well as ticked, as
11048 read."
11049   (interactive "P")
11050   (save-excursion
11051     (gnus-summary-catchup all))
11052   (gnus-summary-next-group))
11053
11054 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11055   "Mark all articles in this group as read and select the previous group.
11056 If given a prefix, mark all articles, unread as well as ticked, as
11057 read."
11058   (interactive "P")
11059   (save-excursion
11060     (gnus-summary-catchup all))
11061   (gnus-summary-next-group nil nil t))
11062
11063 ;;;
11064 ;;; with article
11065 ;;;
11066
11067 (defmacro gnus-with-article (article &rest forms)
11068   "Select ARTICLE and perform FORMS in the original article buffer.
11069 Then replace the article with the result."
11070   `(progn
11071      ;; We don't want the article to be marked as read.
11072      (let (gnus-mark-article-hook)
11073        (gnus-summary-select-article t t nil ,article))
11074      (set-buffer gnus-original-article-buffer)
11075      ,@forms
11076      (if (not (gnus-check-backend-function
11077                'request-replace-article (car gnus-article-current)))
11078          (gnus-message 5 "Read-only group; not replacing")
11079        (unless (gnus-request-replace-article
11080                 ,article (car gnus-article-current)
11081                 (current-buffer) t)
11082          (error "Couldn't replace article")))
11083      ;; The cache and backlog have to be flushed somewhat.
11084      (when gnus-keep-backlog
11085        (gnus-backlog-remove-article
11086         (car gnus-article-current) (cdr gnus-article-current)))
11087      (when gnus-use-cache
11088        (gnus-cache-update-article
11089         (car gnus-article-current) (cdr gnus-article-current)))))
11090
11091 (put 'gnus-with-article 'lisp-indent-function 1)
11092 (put 'gnus-with-article 'edebug-form-spec '(form body))
11093
11094 ;; Thread-based commands.
11095
11096 (defun gnus-summary-articles-in-thread (&optional article)
11097   "Return a list of all articles in the current thread.
11098 If ARTICLE is non-nil, return all articles in the thread that starts
11099 with that article."
11100   (let* ((article (or article (gnus-summary-article-number)))
11101          (data (gnus-data-find-list article))
11102          (top-level (gnus-data-level (car data)))
11103          (top-subject
11104           (cond ((null gnus-thread-operation-ignore-subject)
11105                  (gnus-simplify-subject-re
11106                   (mail-header-subject (gnus-data-header (car data)))))
11107                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11108                  (gnus-simplify-subject-fuzzy
11109                   (mail-header-subject (gnus-data-header (car data)))))
11110                 (t nil)))
11111          (end-point (save-excursion
11112                       (if (gnus-summary-go-to-next-thread)
11113                           (point) (point-max))))
11114          articles)
11115     (while (and data
11116                 (< (gnus-data-pos (car data)) end-point))
11117       (when (or (not top-subject)
11118                 (string= top-subject
11119                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11120                              (gnus-simplify-subject-fuzzy
11121                               (mail-header-subject
11122                                (gnus-data-header (car data))))
11123                            (gnus-simplify-subject-re
11124                             (mail-header-subject
11125                              (gnus-data-header (car data)))))))
11126         (push (gnus-data-number (car data)) articles))
11127       (unless (and (setq data (cdr data))
11128                    (> (gnus-data-level (car data)) top-level))
11129         (setq data nil)))
11130     ;; Return the list of articles.
11131     (nreverse articles)))
11132
11133 (defun gnus-summary-rethread-current ()
11134   "Rethread the thread the current article is part of."
11135   (interactive)
11136   (let* ((gnus-show-threads t)
11137          (article (gnus-summary-article-number))
11138          (id (mail-header-id (gnus-summary-article-header)))
11139          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11140     (unless id
11141       (error "No article on the current line"))
11142     (gnus-rebuild-thread id)
11143     (gnus-summary-goto-subject article)))
11144
11145 (defun gnus-summary-reparent-thread ()
11146   "Make the current article child of the marked (or previous) article.
11147
11148 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11149 is non-nil or the Subject: of both articles are the same."
11150   (interactive)
11151   (unless (not (gnus-group-read-only-p))
11152     (error "The current newsgroup does not support article editing"))
11153   (unless (<= (length gnus-newsgroup-processable) 1)
11154     (error "No more than one article may be marked"))
11155   (let ((child (gnus-summary-article-number))
11156         ;; First grab the marked article, otherwise one line up.
11157         (parent (if (not (null gnus-newsgroup-processable))
11158                     (car gnus-newsgroup-processable)
11159                   (save-excursion
11160                     (if (eq (forward-line -1) 0)
11161                         (gnus-summary-article-number)
11162                       (error "Beginning of summary buffer"))))))
11163     (gnus-summary-reparent-children parent (list child))))
11164
11165 (defun gnus-summary-reparent-children (parent children)
11166   "Make PARENT the parent of CHILDREN.
11167 When called interactively, PARENT is the current article and CHILDREN
11168 are the process-marked articles."
11169   (interactive
11170    (list (gnus-summary-article-number)
11171          (gnus-summary-work-articles nil)))
11172   (dolist (child children)
11173     (save-window-excursion
11174       (let ((gnus-article-buffer " *reparent*"))
11175         (unless (not (eq parent child))
11176           (error "An article may not be self-referential"))
11177         (let ((message-id (mail-header-id
11178                            (gnus-summary-article-header parent))))
11179           (unless (and message-id (not (equal message-id "")))
11180             (error "No message-id in desired parent"))
11181           (gnus-with-article child
11182             (save-restriction
11183               (goto-char (point-min))
11184               (message-narrow-to-head)
11185               (if (re-search-forward "^References: " nil t)
11186                   (progn
11187                     (re-search-forward "^[^ \t]" nil t)
11188                     (forward-line -1)
11189                     (end-of-line)
11190                     (insert " " message-id))
11191                 (insert "References: " message-id "\n"))))
11192           (set-buffer gnus-summary-buffer)
11193           (gnus-summary-unmark-all-processable)
11194           (gnus-summary-update-article child)
11195           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11196             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11197           (gnus-summary-rethread-current)
11198           (gnus-message 3 "Article %d is now the child of article %d"
11199                         child parent))))))
11200
11201 (defun gnus-summary-toggle-threads (&optional arg)
11202   "Toggle showing conversation threads.
11203 If ARG is positive number, turn showing conversation threads on."
11204   (interactive "P")
11205   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11206     (setq gnus-show-threads
11207           (if (null arg) (not gnus-show-threads)
11208             (> (prefix-numeric-value arg) 0)))
11209     (gnus-summary-prepare)
11210     (gnus-summary-goto-subject current)
11211     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11212     (gnus-summary-position-point)))
11213
11214 (defun gnus-summary-show-all-threads ()
11215   "Show all threads."
11216   (interactive)
11217   (save-excursion
11218     (let ((buffer-read-only nil))
11219       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11220   (gnus-summary-position-point))
11221
11222 (defun gnus-summary-show-thread ()
11223   "Show thread subtrees.
11224 Returns nil if no thread was there to be shown."
11225   (interactive)
11226   (let ((buffer-read-only nil)
11227         (orig (point))
11228         (end (point-at-eol))
11229         ;; Leave point at bol
11230         (beg (progn (beginning-of-line) (point))))
11231     (prog1
11232         ;; Any hidden lines here?
11233         (search-forward "\r" end t)
11234       (subst-char-in-region beg end ?\^M ?\n t)
11235       (goto-char orig)
11236       (gnus-summary-position-point))))
11237
11238 (defun gnus-summary-maybe-hide-threads ()
11239   "If requested, hide the threads that should be hidden."
11240   (when (and gnus-show-threads
11241              gnus-thread-hide-subtree)
11242     (gnus-summary-hide-all-threads
11243      (if (or (consp gnus-thread-hide-subtree)
11244              (functionp gnus-thread-hide-subtree))
11245          (gnus-make-predicate gnus-thread-hide-subtree)
11246        nil))))
11247
11248 ;;; Hiding predicates.
11249
11250 (defun gnus-article-unread-p (header)
11251   (memq (mail-header-number header) gnus-newsgroup-unreads))
11252
11253 (defun gnus-article-unseen-p (header)
11254   (memq (mail-header-number header) gnus-newsgroup-unseen))
11255
11256 (defun gnus-map-articles (predicate articles)
11257   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11258   (apply 'gnus-or (mapcar predicate
11259                           (mapcar (lambda (number)
11260                                     (gnus-summary-article-header number))
11261                                   articles))))
11262
11263 (defun gnus-summary-hide-all-threads (&optional predicate)
11264   "Hide all thread subtrees.
11265 If PREDICATE is supplied, threads that satisfy this predicate
11266 will not be hidden."
11267   (interactive)
11268   (save-excursion
11269     (goto-char (point-min))
11270     (let ((end nil))
11271       (while (not end)
11272         (when (or (not predicate)
11273                   (gnus-map-articles
11274                    predicate (gnus-summary-article-children)))
11275             (gnus-summary-hide-thread))
11276         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11277   (gnus-summary-position-point))
11278
11279 (defun gnus-summary-hide-thread ()
11280   "Hide thread subtrees.
11281 If PREDICATE is supplied, threads that satisfy this predicate
11282 will not be hidden.
11283 Returns nil if no threads were there to be hidden."
11284   (interactive)
11285   (let ((buffer-read-only nil)
11286         (start (point))
11287         (article (gnus-summary-article-number)))
11288     (goto-char start)
11289     ;; Go forward until either the buffer ends or the subthread
11290     ;; ends.
11291     (when (and (not (eobp))
11292                (or (zerop (gnus-summary-next-thread 1 t))
11293                    (goto-char (point-max))))
11294       (prog1
11295           (if (and (> (point) start)
11296                    (search-backward "\n" start t))
11297               (progn
11298                 (subst-char-in-region start (point) ?\n ?\^M)
11299                 (gnus-summary-goto-subject article))
11300             (goto-char start)
11301             nil)))))
11302
11303 (defun gnus-summary-go-to-next-thread (&optional previous)
11304   "Go to the same level (or less) next thread.
11305 If PREVIOUS is non-nil, go to previous thread instead.
11306 Return the article number moved to, or nil if moving was impossible."
11307   (let ((level (gnus-summary-thread-level))
11308         (way (if previous -1 1))
11309         (beg (point)))
11310     (forward-line way)
11311     (while (and (not (eobp))
11312                 (< level (gnus-summary-thread-level)))
11313       (forward-line way))
11314     (if (eobp)
11315         (progn
11316           (goto-char beg)
11317           nil)
11318       (setq beg (point))
11319       (prog1
11320           (gnus-summary-article-number)
11321         (goto-char beg)))))
11322
11323 (defun gnus-summary-next-thread (n &optional silent)
11324   "Go to the same level next N'th thread.
11325 If N is negative, search backward instead.
11326 Returns the difference between N and the number of skips actually
11327 done.
11328
11329 If SILENT, don't output messages."
11330   (interactive "p")
11331   (let ((backward (< n 0))
11332         (n (abs n)))
11333     (while (and (> n 0)
11334                 (gnus-summary-go-to-next-thread backward))
11335       (decf n))
11336     (unless silent
11337       (gnus-summary-position-point))
11338     (when (and (not silent) (/= 0 n))
11339       (gnus-message 7 "No more threads"))
11340     n))
11341
11342 (defun gnus-summary-prev-thread (n)
11343   "Go to the same level previous N'th thread.
11344 Returns the difference between N and the number of skips actually
11345 done."
11346   (interactive "p")
11347   (gnus-summary-next-thread (- n)))
11348
11349 (defun gnus-summary-go-down-thread ()
11350   "Go down one level in the current thread."
11351   (let ((children (gnus-summary-article-children)))
11352     (when children
11353       (gnus-summary-goto-subject (car children)))))
11354
11355 (defun gnus-summary-go-up-thread ()
11356   "Go up one level in the current thread."
11357   (let ((parent (gnus-summary-article-parent)))
11358     (when parent
11359       (gnus-summary-goto-subject parent))))
11360
11361 (defun gnus-summary-down-thread (n)
11362   "Go down thread N steps.
11363 If N is negative, go up instead.
11364 Returns the difference between N and how many steps down that were
11365 taken."
11366   (interactive "p")
11367   (let ((up (< n 0))
11368         (n (abs n)))
11369     (while (and (> n 0)
11370                 (if up (gnus-summary-go-up-thread)
11371                   (gnus-summary-go-down-thread)))
11372       (setq n (1- n)))
11373     (gnus-summary-position-point)
11374     (when (/= 0 n)
11375       (gnus-message 7 "Can't go further"))
11376     n))
11377
11378 (defun gnus-summary-up-thread (n)
11379   "Go up thread N steps.
11380 If N is negative, go down instead.
11381 Returns the difference between N and how many steps down that were
11382 taken."
11383   (interactive "p")
11384   (gnus-summary-down-thread (- n)))
11385
11386 (defun gnus-summary-top-thread ()
11387   "Go to the top of the thread."
11388   (interactive)
11389   (while (gnus-summary-go-up-thread))
11390   (gnus-summary-article-number))
11391
11392 (defun gnus-summary-expire-thread ()
11393   "Mark articles under current thread as expired."
11394   (interactive)
11395   (gnus-summary-kill-thread 0))
11396
11397 (defun gnus-summary-kill-thread (&optional unmark)
11398   "Mark articles under current thread as read.
11399 If the prefix argument is positive, remove any kinds of marks.
11400 If the prefix argument is zero, mark thread as expired.
11401 If the prefix argument is negative, tick articles instead."
11402   (interactive "P")
11403   (when unmark
11404     (setq unmark (prefix-numeric-value unmark)))
11405   (let ((articles (gnus-summary-articles-in-thread))
11406         (hide (or (null unmark) (= unmark 0))))
11407     (save-excursion
11408       ;; Expand the thread.
11409       (gnus-summary-show-thread)
11410       ;; Mark all the articles.
11411       (while articles
11412         (gnus-summary-goto-subject (car articles))
11413         (cond ((null unmark)
11414                (gnus-summary-mark-article-as-read gnus-killed-mark))
11415               ((> unmark 0)
11416                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11417               ((= unmark 0)
11418                (gnus-summary-mark-article-as-unread gnus-expirable-mark))
11419               (t
11420                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11421         (setq articles (cdr articles))))
11422     ;; Hide killed subtrees when hide is true.
11423     (and hide
11424          gnus-thread-hide-killed
11425          (gnus-summary-hide-thread))
11426     ;; If hide is t, go to next unread subject.
11427     (when hide
11428       ;; Go to next unread subject.
11429       (gnus-summary-next-subject 1 t)))
11430   (gnus-set-mode-line 'summary))
11431
11432 ;; Summary sorting commands
11433
11434 (defun gnus-summary-sort-by-number (&optional reverse)
11435   "Sort the summary buffer by article number.
11436 Argument REVERSE means reverse order."
11437   (interactive "P")
11438   (gnus-summary-sort 'number reverse))
11439
11440 (defun gnus-summary-sort-by-random (&optional reverse)
11441   "Randomize the order in the summary buffer.
11442 Argument REVERSE means to randomize in reverse order."
11443   (interactive "P")
11444   (gnus-summary-sort 'random reverse))
11445
11446 (defun gnus-summary-sort-by-author (&optional reverse)
11447   "Sort the summary buffer by author name alphabetically.
11448 If `case-fold-search' is non-nil, case of letters is ignored.
11449 Argument REVERSE means reverse order."
11450   (interactive "P")
11451   (gnus-summary-sort 'author reverse))
11452
11453 (defun gnus-summary-sort-by-recipient (&optional reverse)
11454   "Sort the summary buffer by recipient name alphabetically.
11455 If `case-fold-search' is non-nil, case of letters is ignored.
11456 Argument REVERSE means reverse order."
11457   (interactive "P")
11458   (gnus-summary-sort 'recipient reverse))
11459
11460 (defun gnus-summary-sort-by-subject (&optional reverse)
11461   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11462 If `case-fold-search' is non-nil, case of letters is ignored.
11463 Argument REVERSE means reverse order."
11464   (interactive "P")
11465   (gnus-summary-sort 'subject reverse))
11466
11467 (defun gnus-summary-sort-by-date (&optional reverse)
11468   "Sort the summary buffer by date.
11469 Argument REVERSE means reverse order."
11470   (interactive "P")
11471   (gnus-summary-sort 'date reverse))
11472
11473 (defun gnus-summary-sort-by-score (&optional reverse)
11474   "Sort the summary buffer by score.
11475 Argument REVERSE means reverse order."
11476   (interactive "P")
11477   (gnus-summary-sort 'score reverse))
11478
11479 (defun gnus-summary-sort-by-lines (&optional reverse)
11480   "Sort the summary buffer by the number of lines.
11481 Argument REVERSE means reverse order."
11482   (interactive "P")
11483   (gnus-summary-sort 'lines reverse))
11484
11485 (defun gnus-summary-sort-by-chars (&optional reverse)
11486   "Sort the summary buffer by article length.
11487 Argument REVERSE means reverse order."
11488   (interactive "P")
11489   (gnus-summary-sort 'chars reverse))
11490
11491 (defun gnus-summary-sort-by-original (&optional reverse)
11492   "Sort the summary buffer using the default sorting method.
11493 Argument REVERSE means reverse order."
11494   (interactive "P")
11495   (let* ((buffer-read-only)
11496          (gnus-summary-prepare-hook nil))
11497     ;; We do the sorting by regenerating the threads.
11498     (gnus-summary-prepare)
11499     ;; Hide subthreads if needed.
11500     (gnus-summary-maybe-hide-threads)))
11501
11502 (defun gnus-summary-sort (predicate reverse)
11503   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11504   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11505          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11506          (gnus-thread-sort-functions
11507           (if (not reverse)
11508               thread
11509             `(lambda (t1 t2)
11510                (,thread t2 t1))))
11511          (gnus-sort-gathered-threads-function
11512           gnus-thread-sort-functions)
11513          (gnus-article-sort-functions
11514           (if (not reverse)
11515               article
11516             `(lambda (t1 t2)
11517                (,article t2 t1))))
11518          (buffer-read-only)
11519          (gnus-summary-prepare-hook nil))
11520     ;; We do the sorting by regenerating the threads.
11521     (gnus-summary-prepare)
11522     ;; Hide subthreads if needed.
11523     (gnus-summary-maybe-hide-threads)))
11524
11525 ;; Summary saving commands.
11526
11527 (defun gnus-summary-save-article (&optional n not-saved)
11528   "Save the current article using the default saver function.
11529 If N is a positive number, save the N next articles.
11530 If N is a negative number, save the N previous articles.
11531 If N is nil and any articles have been marked with the process mark,
11532 save those articles instead.
11533 The variable `gnus-default-article-saver' specifies the saver function.
11534
11535 If the optional second argument NOT-SAVED is non-nil, articles saved
11536 will not be marked as saved."
11537   (interactive "P")
11538   (require 'gnus-art)
11539   (let* ((articles (gnus-summary-work-articles n))
11540          (save-buffer (save-excursion
11541                         (nnheader-set-temp-buffer " *Gnus Save*")))
11542          (num (length articles))
11543          ;; Whether to save decoded articles or raw articles.
11544          (decode (when gnus-article-save-coding-system
11545                    (get gnus-default-article-saver :decode)))
11546          ;; When saving many articles in a single file, use the other
11547          ;; function to save articles other than the first one.
11548          (saver2 (get gnus-default-article-saver :function))
11549          (gnus-prompt-before-saving (if saver2
11550                                         t
11551                                       gnus-prompt-before-saving))
11552          (gnus-default-article-saver gnus-default-article-saver)
11553          header file)
11554     (dolist (article articles)
11555       (setq header (gnus-summary-article-header article))
11556       (if (not (vectorp header))
11557           ;; This is a pseudo-article.
11558           (if (assq 'name header)
11559               (gnus-copy-file (cdr (assq 'name header)))
11560             (gnus-message 1 "Article %d is unsaveable" article))
11561         ;; This is a real article.
11562         (save-window-excursion
11563           (let ((gnus-display-mime-function (when decode
11564                                               gnus-display-mime-function))
11565                 (gnus-article-prepare-hook (when decode
11566                                              gnus-article-prepare-hook)))
11567             (gnus-summary-select-article t nil nil article)
11568             (gnus-summary-goto-subject article)))
11569         (save-excursion
11570           (set-buffer save-buffer)
11571           (erase-buffer)
11572           (insert-buffer-substring (if decode
11573                                        gnus-article-buffer
11574                                      gnus-original-article-buffer)))
11575         (setq file (gnus-article-save save-buffer file num))
11576         (gnus-summary-remove-process-mark article)
11577         (unless not-saved
11578           (gnus-summary-set-saved-mark article)))
11579       (when saver2
11580         (setq gnus-default-article-saver saver2
11581               saver2 nil)))
11582     (gnus-kill-buffer save-buffer)
11583     (gnus-summary-position-point)
11584     (gnus-set-mode-line 'summary)
11585     n))
11586
11587 (defun gnus-summary-pipe-output (&optional arg headers)
11588   "Pipe the current article to a subprocess.
11589 If N is a positive number, pipe the N next articles.
11590 If N is a negative number, pipe the N previous articles.
11591 If N is nil and any articles have been marked with the process mark,
11592 pipe those articles instead.
11593 If HEADERS (the symbolic prefix), include the headers, too."
11594   (interactive (gnus-interactive "P\ny"))
11595   (require 'gnus-art)
11596   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11597         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11598     (gnus-summary-save-article arg t))
11599   (let ((buffer (get-buffer "*Shell Command Output*")))
11600     (when (and buffer
11601                (not (zerop (buffer-size buffer))))
11602       (gnus-configure-windows 'pipe))))
11603
11604 (defun gnus-summary-save-article-mail (&optional arg)
11605   "Append the current article to a Unix mail box file.
11606 If N is a positive number, save the N next articles.
11607 If N is a negative number, save the N previous articles.
11608 If N is nil and any articles have been marked with the process mark,
11609 save those articles instead."
11610   (interactive "P")
11611   (require 'gnus-art)
11612   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11613     (gnus-summary-save-article arg)))
11614
11615 (defun gnus-summary-save-article-rmail (&optional arg)
11616   "Append the current article to an rmail file.
11617 If N is a positive number, save the N next articles.
11618 If N is a negative number, save the N previous articles.
11619 If N is nil and any articles have been marked with the process mark,
11620 save those articles instead."
11621   (interactive "P")
11622   (require 'gnus-art)
11623   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11624     (gnus-summary-save-article arg)))
11625
11626 (defun gnus-summary-save-article-file (&optional arg)
11627   "Append the current article to a file.
11628 If N is a positive number, save the N next articles.
11629 If N is a negative number, save the N previous articles.
11630 If N is nil and any articles have been marked with the process mark,
11631 save those articles instead."
11632   (interactive "P")
11633   (require 'gnus-art)
11634   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11635     (gnus-summary-save-article arg)))
11636
11637 (defun gnus-summary-write-article-file (&optional arg)
11638   "Write the current article to a file, deleting the previous file.
11639 If N is a positive number, save the N next articles.
11640 If N is a negative number, save the N previous articles.
11641 If N is nil and any articles have been marked with the process mark,
11642 save those articles instead."
11643   (interactive "P")
11644   (require 'gnus-art)
11645   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11646     (gnus-summary-save-article arg)))
11647
11648 (defun gnus-summary-save-article-body-file (&optional arg)
11649   "Append the current article body to a file.
11650 If N is a positive number, save the N next articles.
11651 If N is a negative number, save the N previous articles.
11652 If N is nil and any articles have been marked with the process mark,
11653 save those articles instead."
11654   (interactive "P")
11655   (require 'gnus-art)
11656   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11657     (gnus-summary-save-article arg)))
11658
11659 (defun gnus-summary-write-article-body-file (&optional arg)
11660   "Write the current article body to a file, deleting the previous file.
11661 If N is a positive number, save the N next articles.
11662 If N is a negative number, save the N previous articles.
11663 If N is nil and any articles have been marked with the process mark,
11664 save those articles instead."
11665   (interactive "P")
11666   (require 'gnus-art)
11667   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11668     (gnus-summary-save-article arg)))
11669
11670 (defun gnus-summary-muttprint (&optional arg)
11671   "Print the current article using Muttprint.
11672 If N is a positive number, save the N next articles.
11673 If N is a negative number, save the N previous articles.
11674 If N is nil and any articles have been marked with the process mark,
11675 save those articles instead."
11676   (interactive "P")
11677   (require 'gnus-art)
11678   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11679     (gnus-summary-save-article arg t)))
11680
11681 (defun gnus-summary-pipe-message (program)
11682   "Pipe the current article through PROGRAM."
11683   (interactive "sProgram: ")
11684   (gnus-summary-select-article)
11685   (let ((mail-header-separator ""))
11686     (gnus-eval-in-buffer-window gnus-article-buffer
11687       (save-restriction
11688         (widen)
11689         (let ((start (window-start))
11690               buffer-read-only)
11691           (message-pipe-buffer-body program)
11692           (set-window-start (get-buffer-window (current-buffer)) start))))))
11693
11694 (defun gnus-get-split-value (methods)
11695   "Return a value based on the split METHODS."
11696   (let (split-name method result match)
11697     (when methods
11698       (save-excursion
11699         (set-buffer gnus-original-article-buffer)
11700         (save-restriction
11701           (nnheader-narrow-to-headers)
11702           (while (and methods (not split-name))
11703             (goto-char (point-min))
11704             (setq method (pop methods))
11705             (setq match (car method))
11706             (when (cond
11707                    ((stringp match)
11708                     ;; Regular expression.
11709                     (ignore-errors
11710                       (re-search-forward match nil t)))
11711                    ((functionp match)
11712                     ;; Function.
11713                     (save-restriction
11714                       (widen)
11715                       (setq result (funcall match gnus-newsgroup-name))))
11716                    ((consp match)
11717                     ;; Form.
11718                     (save-restriction
11719                       (widen)
11720                       (setq result (eval match)))))
11721               (setq split-name (cdr method))
11722               (cond ((stringp result)
11723                      (push (expand-file-name
11724                             result gnus-article-save-directory)
11725                            split-name))
11726                     ((consp result)
11727                      (setq split-name (append result split-name)))))))))
11728     (nreverse split-name)))
11729
11730 (defun gnus-valid-move-group-p (group)
11731   (and (boundp group)
11732        (symbol-name group)
11733        (symbol-value group)
11734        (gnus-get-function (gnus-find-method-for-group
11735                            (symbol-name group)) 'request-accept-article t)))
11736
11737 (defun gnus-read-move-group-name (prompt default articles prefix)
11738   "Read a group name."
11739   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11740          (minibuffer-confirm-incomplete nil) ; XEmacs
11741          (prom
11742           (format "%s %s to"
11743                   prompt
11744                   (if (> (length articles) 1)
11745                       (format "these %d articles" (length articles))
11746                     "this article")))
11747          (to-newsgroup
11748           (let (active group)
11749             (when (or (null split-name) (= 1 (length split-name)))
11750               (setq active (gnus-make-hashtable (length gnus-active-hashtb)))
11751               (mapatoms (lambda (symbol)
11752                           (setq group (symbol-name symbol))
11753                           (when (string-match "[^\000-\177]" group)
11754                             (setq group (gnus-group-decoded-name group)))
11755                           (set (intern group active) group))
11756                         gnus-active-hashtb))
11757             (cond
11758              ((null split-name)
11759               (gnus-completing-read-with-default
11760                default prom active 'gnus-valid-move-group-p nil prefix
11761                'gnus-group-history))
11762              ((= 1 (length split-name))
11763               (gnus-completing-read-with-default
11764                (car split-name) prom active 'gnus-valid-move-group-p nil nil
11765                'gnus-group-history))
11766              (t
11767               (gnus-completing-read-with-default
11768                nil prom (mapcar 'list (nreverse split-name)) nil nil nil
11769                'gnus-group-history)))))
11770          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
11771          encoded)
11772     (when to-newsgroup
11773       (if (or (string= to-newsgroup "")
11774               (string= to-newsgroup prefix))
11775           (setq to-newsgroup default))
11776       (unless to-newsgroup
11777         (error "No group name entered"))
11778       (setq encoded (mm-encode-coding-string
11779                      to-newsgroup
11780                      (gnus-group-name-charset to-method to-newsgroup)))
11781       (or (gnus-active encoded)
11782           (gnus-activate-group encoded nil nil to-method)
11783           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11784                                      to-newsgroup))
11785               (or (and (gnus-request-create-group encoded to-method)
11786                        (gnus-activate-group encoded nil nil to-method)
11787                        (gnus-subscribe-group encoded))
11788                   (error "Couldn't create group %s" to-newsgroup)))
11789           (error "No such group: %s" to-newsgroup))
11790       encoded)))
11791
11792 (defvar gnus-summary-save-parts-counter)
11793
11794 (defun gnus-summary-save-parts (type dir n &optional reverse)
11795   "Save parts matching TYPE to DIR.
11796 If REVERSE, save parts that do not match TYPE."
11797   (interactive
11798    (list (read-string "Save parts of type: "
11799                       (or (car gnus-summary-save-parts-type-history)
11800                           gnus-summary-save-parts-default-mime)
11801                       'gnus-summary-save-parts-type-history)
11802          (setq gnus-summary-save-parts-last-directory
11803                (read-file-name "Save to directory: "
11804                                gnus-summary-save-parts-last-directory
11805                                nil t))
11806          current-prefix-arg))
11807   (gnus-summary-iterate n
11808     (let ((gnus-display-mime-function nil)
11809           (gnus-inhibit-treatment t))
11810       (gnus-summary-select-article))
11811     (save-excursion
11812       (set-buffer gnus-article-buffer)
11813       (let ((handles (or gnus-article-mime-handles
11814                          (mm-dissect-buffer nil gnus-article-loose-mime)
11815                          (and gnus-article-emulate-mime
11816                               (mm-uu-dissect))))
11817             (gnus-summary-save-parts-counter 1))
11818         (when handles
11819           (gnus-summary-save-parts-1 type dir handles reverse)
11820           (unless gnus-article-mime-handles ;; Don't destroy this case.
11821             (mm-destroy-parts handles)))))))
11822
11823 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11824   (if (stringp (car handle))
11825       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11826               (cdr handle))
11827     (when (if reverse
11828               (not (string-match type (mm-handle-media-type handle)))
11829             (string-match type (mm-handle-media-type handle)))
11830       (let ((file (expand-file-name
11831                    (gnus-map-function
11832                     mm-file-name-rewrite-functions
11833                     (file-name-nondirectory
11834                      (or
11835                       (mail-content-type-get
11836                        (mm-handle-disposition handle) 'filename)
11837                       (mail-content-type-get
11838                        (mm-handle-type handle) 'name)
11839                       (format "%s.%d.%d" gnus-newsgroup-name
11840                               (cdr gnus-article-current)
11841                               gnus-summary-save-parts-counter))))
11842                    dir)))
11843         (incf gnus-summary-save-parts-counter)
11844         (unless (file-exists-p file)
11845           (mm-save-part-to-file handle file))))))
11846
11847 ;; Summary extract commands
11848
11849 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11850   (let ((buffer-read-only nil)
11851         (article (gnus-summary-article-number))
11852         after-article b e)
11853     (unless (gnus-summary-goto-subject article)
11854       (error "No such article: %d" article))
11855     (gnus-summary-position-point)
11856     ;; If all commands are to be bunched up on one line, we collect
11857     ;; them here.
11858     (unless gnus-view-pseudos-separately
11859       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11860             files action)
11861         (while ps
11862           (setq action (cdr (assq 'action (car ps))))
11863           (setq files (list (cdr (assq 'name (car ps)))))
11864           (while (and ps (cdr ps)
11865                       (string= (or action "1")
11866                                (or (cdr (assq 'action (cadr ps))) "2")))
11867             (push (cdr (assq 'name (cadr ps))) files)
11868             (setcdr ps (cddr ps)))
11869           (when files
11870             (when (not (string-match "%s" action))
11871               (push " " files))
11872             (push " " files)
11873             (when (assq 'execute (car ps))
11874               (setcdr (assq 'execute (car ps))
11875                       (funcall (if (string-match "%s" action)
11876                                    'format 'concat)
11877                                action
11878                                (mapconcat
11879                                 (lambda (f)
11880                                   (if (equal f " ")
11881                                       f
11882                                     (shell-quote-argument f)))
11883                                 files " ")))))
11884           (setq ps (cdr ps)))))
11885     (if (and gnus-view-pseudos (not not-view))
11886         (while pslist
11887           (when (assq 'execute (car pslist))
11888             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11889                                   (eq gnus-view-pseudos 'not-confirm)))
11890           (setq pslist (cdr pslist)))
11891       (save-excursion
11892         (while pslist
11893           (setq after-article (or (cdr (assq 'article (car pslist)))
11894                                   (gnus-summary-article-number)))
11895           (gnus-summary-goto-subject after-article)
11896           (forward-line 1)
11897           (setq b (point))
11898           (insert "    " (file-name-nondirectory
11899                           (cdr (assq 'name (car pslist))))
11900                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11901           (setq e (point))
11902           (forward-line -1)             ; back to `b'
11903           (gnus-add-text-properties
11904            b (1- e) (list 'gnus-number gnus-reffed-article-number
11905                           gnus-mouse-face-prop gnus-mouse-face))
11906           (gnus-data-enter
11907            after-article gnus-reffed-article-number
11908            gnus-unread-mark b (car pslist) 0 (- e b))
11909           (setq gnus-newsgroup-unreads
11910                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11911                                          gnus-reffed-article-number))
11912           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11913           (setq pslist (cdr pslist)))))))
11914
11915 (defun gnus-pseudos< (p1 p2)
11916   (let ((c1 (cdr (assq 'action p1)))
11917         (c2 (cdr (assq 'action p2))))
11918     (and c1 c2 (string< c1 c2))))
11919
11920 (defun gnus-request-pseudo-article (props)
11921   (cond ((assq 'execute props)
11922          (gnus-execute-command (cdr (assq 'execute props)))))
11923   (let ((gnus-current-article (gnus-summary-article-number)))
11924     (gnus-run-hooks 'gnus-mark-article-hook)))
11925
11926 (defun gnus-execute-command (command &optional automatic)
11927   (save-excursion
11928     (gnus-article-setup-buffer)
11929     (set-buffer gnus-article-buffer)
11930     (setq buffer-read-only nil)
11931     (let ((command (if automatic command
11932                      (read-string "Command: " (cons command 0)))))
11933       (erase-buffer)
11934       (insert "$ " command "\n\n")
11935       (if gnus-view-pseudo-asynchronously
11936           (start-process "gnus-execute" (current-buffer) shell-file-name
11937                          shell-command-switch command)
11938         (call-process shell-file-name nil t nil
11939                       shell-command-switch command)))))
11940
11941 ;; Summary kill commands.
11942
11943 (defun gnus-summary-edit-global-kill (article)
11944   "Edit the \"global\" kill file."
11945   (interactive (list (gnus-summary-article-number)))
11946   (gnus-group-edit-global-kill article))
11947
11948 (defun gnus-summary-edit-local-kill ()
11949   "Edit a local kill file applied to the current newsgroup."
11950   (interactive)
11951   (setq gnus-current-headers (gnus-summary-article-header))
11952   (gnus-group-edit-local-kill
11953    (gnus-summary-article-number) gnus-newsgroup-name))
11954
11955 ;;; Header reading.
11956
11957 (defun gnus-read-header (id &optional header)
11958   "Read the headers of article ID and enter them into the Gnus system."
11959   (let ((group gnus-newsgroup-name)
11960         (gnus-override-method
11961          (or
11962           gnus-override-method
11963           (and (gnus-news-group-p gnus-newsgroup-name)
11964                (car (gnus-refer-article-methods)))))
11965         where)
11966     ;; First we check to see whether the header in question is already
11967     ;; fetched.
11968     (if (stringp id)
11969         ;; This is a Message-ID.
11970         (setq header (or header (gnus-id-to-header id)))
11971       ;; This is an article number.
11972       (setq header (or header (gnus-summary-article-header id))))
11973     (if (and header
11974              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11975         ;; We have found the header.
11976         header
11977       ;; We have to really fetch the header to this article.
11978       (save-excursion
11979         (set-buffer nntp-server-buffer)
11980         (when (setq where (gnus-request-head id group))
11981           (nnheader-fold-continuation-lines)
11982           (goto-char (point-max))
11983           (insert ".\n")
11984           (goto-char (point-min))
11985           (insert "211 ")
11986           (princ (cond
11987                   ((numberp id) id)
11988                   ((cdr where) (cdr where))
11989                   (header (mail-header-number header))
11990                   (t gnus-reffed-article-number))
11991                  (current-buffer))
11992           (insert " Article retrieved.\n"))
11993         (if (or (not where)
11994                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11995             ()                          ; Malformed head.
11996           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11997             (when (and (stringp id)
11998                        (or
11999                         (not (string= (gnus-group-real-name group)
12000                                       (car where)))
12001                         (not (gnus-server-equal gnus-override-method
12002                                                 (gnus-group-method group)))))
12003               ;; If we fetched by Message-ID and the article came from
12004               ;; a different group (or server), we fudge some bogus
12005               ;; article numbers for this article.
12006               (mail-header-set-number header gnus-reffed-article-number))
12007             (save-excursion
12008               (set-buffer gnus-summary-buffer)
12009               (decf gnus-reffed-article-number)
12010               (gnus-remove-header (mail-header-number header))
12011               (push header gnus-newsgroup-headers)
12012               (setq gnus-current-headers header)
12013               (push (mail-header-number header) gnus-newsgroup-limit)))
12014           header)))))
12015
12016 (defun gnus-remove-header (number)
12017   "Remove header NUMBER from `gnus-newsgroup-headers'."
12018   (if (and gnus-newsgroup-headers
12019            (= number (mail-header-number (car gnus-newsgroup-headers))))
12020       (pop gnus-newsgroup-headers)
12021     (let ((headers gnus-newsgroup-headers))
12022       (while (and (cdr headers)
12023                   (not (= number (mail-header-number (cadr headers)))))
12024         (pop headers))
12025       (when (cdr headers)
12026         (setcdr headers (cddr headers))))))
12027
12028 ;;;
12029 ;;; summary highlights
12030 ;;;
12031
12032 (defun gnus-highlight-selected-summary ()
12033   "Highlight selected article in summary buffer."
12034   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12035   (when gnus-summary-selected-face
12036     (save-excursion
12037       (let* ((beg (point-at-bol))
12038              (end (point-at-eol))
12039              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12040              (from (if (get-text-property beg gnus-mouse-face-prop)
12041                        beg
12042                      (or (next-single-property-change
12043                           beg gnus-mouse-face-prop nil end)
12044                          beg)))
12045              (to
12046               (if (= from end)
12047                   (- from 2)
12048                 (or (next-single-property-change
12049                      from gnus-mouse-face-prop nil end)
12050                     end))))
12051         ;; If no mouse-face prop on line we will have to = from = end,
12052         ;; so we highlight the entire line instead.
12053         (when (= (+ to 2) from)
12054           (setq from beg)
12055           (setq to end))
12056         (if gnus-newsgroup-selected-overlay
12057             ;; Move old overlay.
12058             (gnus-move-overlay
12059              gnus-newsgroup-selected-overlay from to (current-buffer))
12060           ;; Create new overlay.
12061           (gnus-overlay-put
12062            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12063            'face gnus-summary-selected-face))))))
12064
12065 (defvar gnus-summary-highlight-line-cached nil)
12066 (defvar gnus-summary-highlight-line-trigger nil)
12067
12068 (defun gnus-summary-highlight-line-0 ()
12069   (if (and (eq gnus-summary-highlight-line-trigger
12070                gnus-summary-highlight)
12071            gnus-summary-highlight-line-cached)
12072       gnus-summary-highlight-line-cached
12073     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12074           gnus-summary-highlight-line-cached
12075           (let* ((cond (list 'cond))
12076                  (c cond)
12077                  (list gnus-summary-highlight))
12078             (while list
12079               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12080                               nil))
12081               (setq c (cdr c)
12082                     list (cdr list)))
12083             (gnus-byte-compile (list 'lambda nil cond))))))
12084
12085 (defun gnus-summary-highlight-line ()
12086   "Highlight current line according to `gnus-summary-highlight'."
12087   (let* ((beg (point-at-bol))
12088          (article (or (gnus-summary-article-number) gnus-current-article))
12089          (score (or (cdr (assq article
12090                                gnus-newsgroup-scored))
12091                     gnus-summary-default-score 0))
12092          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12093          (inhibit-read-only t)
12094          (default gnus-summary-default-score)
12095          (default-high gnus-summary-default-high-score)
12096          (default-low gnus-summary-default-low-score)
12097          (uncached (and gnus-summary-use-undownloaded-faces
12098                         (memq article gnus-newsgroup-undownloaded)
12099                         (not (memq article gnus-newsgroup-cached)))))
12100     (let ((face (funcall (gnus-summary-highlight-line-0))))
12101       (unless (eq face (get-text-property beg 'face))
12102         (gnus-put-text-property-excluding-characters-with-faces
12103          beg (point-at-eol) 'face
12104          (setq face (if (boundp face) (symbol-value face) face)))
12105         (when gnus-summary-highlight-line-function
12106           (funcall gnus-summary-highlight-line-function article face))))))
12107
12108 (defun gnus-update-read-articles (group unread &optional compute)
12109   "Update the list of read articles in GROUP.
12110 UNREAD is a sorted list."
12111   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12112         (info (gnus-get-info group))
12113         (prev 1)
12114         read)
12115     (if (or (not info) (not active))
12116         ;; There is no info on this group if it was, in fact,
12117         ;; killed.  Gnus stores no information on killed groups, so
12118         ;; there's nothing to be done.
12119         ;; One could store the information somewhere temporarily,
12120         ;; perhaps...  Hmmm...
12121         ()
12122       ;; Remove any negative articles numbers.
12123       (while (and unread (< (car unread) 0))
12124         (setq unread (cdr unread)))
12125       ;; Remove any expired article numbers
12126       (while (and unread (< (car unread) (car active)))
12127         (setq unread (cdr unread)))
12128       ;; Compute the ranges of read articles by looking at the list of
12129       ;; unread articles.
12130       (while unread
12131         (when (/= (car unread) prev)
12132           (push (if (= prev (1- (car unread))) prev
12133                   (cons prev (1- (car unread))))
12134                 read))
12135         (setq prev (1+ (car unread)))
12136         (setq unread (cdr unread)))
12137       (when (<= prev (cdr active))
12138         (push (cons prev (cdr active)) read))
12139       (setq read (if (> (length read) 1) (nreverse read) read))
12140       (if compute
12141           read
12142         (save-excursion
12143           (let (setmarkundo)
12144             ;; Propagate the read marks to the backend.
12145             (when (gnus-check-backend-function 'request-set-mark group)
12146               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12147                     (add (gnus-remove-from-range read (gnus-info-read info))))
12148                 (when (or add del)
12149                   (unless (gnus-check-group group)
12150                     (error "Can't open server for %s" group))
12151                   (gnus-request-set-mark
12152                    group (delq nil (list (if add (list add 'add '(read)))
12153                                          (if del (list del 'del '(read))))))
12154                   (setq setmarkundo
12155                         `(gnus-request-set-mark
12156                           ,group
12157                           ',(delq nil (list
12158                                        (if del (list del 'add '(read)))
12159                                        (if add (list add 'del '(read))))))))))
12160             (set-buffer gnus-group-buffer)
12161             (gnus-undo-register
12162               `(progn
12163                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12164                  (gnus-info-set-read ',info ',(gnus-info-read info))
12165                  (gnus-get-unread-articles-in-group ',info
12166                                                     (gnus-active ,group))
12167                  (gnus-group-update-group ,group t)
12168                  ,setmarkundo))))
12169         ;; Enter this list into the group info.
12170         (gnus-info-set-read info read)
12171         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12172         (gnus-get-unread-articles-in-group info (gnus-active group))
12173         t))))
12174
12175 (defun gnus-offer-save-summaries ()
12176   "Offer to save all active summary buffers."
12177   (let (buffers)
12178     ;; Go through all buffers and find all summaries.
12179     (dolist (buffer (buffer-list))
12180       (when (and (setq buffer (buffer-name buffer))
12181                  (string-match "Summary" buffer)
12182                  (with-current-buffer buffer
12183                    ;; We check that this is, indeed, a summary buffer.
12184                    (and (eq major-mode 'gnus-summary-mode)
12185                         ;; Also make sure this isn't bogus.
12186                         gnus-newsgroup-prepared
12187                         ;; Also make sure that this isn't a
12188                         ;; dead summary buffer.
12189                         (not gnus-dead-summary-mode))))
12190         (push buffer buffers)))
12191     ;; Go through all these summary buffers and offer to save them.
12192     (when buffers
12193       (save-excursion
12194         (map-y-or-n-p
12195          "Update summary buffer %s? "
12196          (lambda (buf)
12197            (switch-to-buffer buf)
12198            (gnus-summary-exit))
12199          buffers)))))
12200
12201 (defun gnus-summary-setup-default-charset ()
12202   "Setup newsgroup default charset."
12203   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12204       (setq gnus-newsgroup-charset nil)
12205     (let* ((ignored-charsets
12206             (or gnus-newsgroup-ephemeral-ignored-charsets
12207                 (append
12208                  (and gnus-newsgroup-name
12209                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12210                  gnus-newsgroup-ignored-charsets))))
12211       (setq gnus-newsgroup-charset
12212             (or gnus-newsgroup-ephemeral-charset
12213                 (and gnus-newsgroup-name
12214                      (gnus-parameter-charset gnus-newsgroup-name))
12215                 gnus-default-charset))
12216       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12217            ignored-charsets))))
12218
12219 ;;;
12220 ;;; Mime Commands
12221 ;;;
12222
12223 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12224   "Display the current article buffer fully MIME-buttonized.
12225 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12226 treated as multipart/mixed."
12227   (interactive "P")
12228   (require 'gnus-art)
12229   (let ((gnus-unbuttonized-mime-types nil)
12230         (gnus-mime-display-multipart-as-mixed show-all-parts))
12231     (gnus-summary-show-article)))
12232
12233 (defun gnus-summary-repair-multipart (article)
12234   "Add a Content-Type header to a multipart article without one."
12235   (interactive (list (gnus-summary-article-number)))
12236   (gnus-with-article article
12237     (message-narrow-to-head)
12238     (message-remove-header "Mime-Version")
12239     (goto-char (point-max))
12240     (insert "Mime-Version: 1.0\n")
12241     (widen)
12242     (when (search-forward "\n--" nil t)
12243       (let ((separator (buffer-substring (point) (point-at-eol))))
12244         (message-narrow-to-head)
12245         (message-remove-header "Content-Type")
12246         (goto-char (point-max))
12247         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12248                         separator))
12249         (widen))))
12250   (let (gnus-mark-article-hook)
12251     (gnus-summary-select-article t t nil article)))
12252
12253 (defun gnus-summary-toggle-display-buttonized ()
12254   "Toggle the buttonizing of the article buffer."
12255   (interactive)
12256   (require 'gnus-art)
12257   (if (setq gnus-inhibit-mime-unbuttonizing
12258             (not gnus-inhibit-mime-unbuttonizing))
12259       (let ((gnus-unbuttonized-mime-types nil))
12260         (gnus-summary-show-article))
12261     (gnus-summary-show-article)))
12262
12263 ;;;
12264 ;;; Generic summary marking commands
12265 ;;;
12266
12267 (defvar gnus-summary-marking-alist
12268   '((read gnus-del-mark "d")
12269     (unread gnus-unread-mark "u")
12270     (ticked gnus-ticked-mark "!")
12271     (dormant gnus-dormant-mark "?")
12272     (expirable gnus-expirable-mark "e"))
12273   "An alist of names/marks/keystrokes.")
12274
12275 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12276 (defvar gnus-summary-mark-map)
12277
12278 (defun gnus-summary-make-all-marking-commands ()
12279   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12280   (dolist (elem gnus-summary-marking-alist)
12281     (apply 'gnus-summary-make-marking-command elem)))
12282
12283 (defun gnus-summary-make-marking-command (name mark keystroke)
12284   (let ((map (make-sparse-keymap)))
12285     (define-key gnus-summary-generic-mark-map keystroke map)
12286     (dolist (lway `((next "next" next nil "n")
12287                     (next-unread "next unread" next t "N")
12288                     (prev "previous" prev nil "p")
12289                     (prev-unread "previous unread" prev t "P")
12290                     (nomove "" nil nil ,keystroke)))
12291       (let ((func (gnus-summary-make-marking-command-1
12292                    mark (car lway) lway name)))
12293         (setq func (eval func))
12294         (define-key map (nth 4 lway) func)))))
12295
12296 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12297   `(defun ,(intern
12298             (format "gnus-summary-put-mark-as-%s%s"
12299                     name (if (eq way 'nomove)
12300                              ""
12301                            (concat "-" (symbol-name way)))))
12302      (n)
12303      ,(format
12304        "Mark the current article as %s%s.
12305 If N, the prefix, then repeat N times.
12306 If N is negative, move in reverse order.
12307 The difference between N and the actual number of articles marked is
12308 returned."
12309        name (cadr lway))
12310      (interactive "p")
12311      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12312
12313 (defun gnus-summary-generic-mark (n mark move unread)
12314   "Mark N articles with MARK."
12315   (unless (eq major-mode 'gnus-summary-mode)
12316     (error "This command can only be used in the summary buffer"))
12317   (gnus-summary-show-thread)
12318   (let ((nummove
12319          (cond
12320           ((eq move 'next) 1)
12321           ((eq move 'prev) -1)
12322           (t 0))))
12323     (if (zerop nummove)
12324         (setq n 1)
12325       (when (< n 0)
12326         (setq n (abs n)
12327               nummove (* -1 nummove))))
12328     (while (and (> n 0)
12329                 (gnus-summary-mark-article nil mark)
12330                 (zerop (gnus-summary-next-subject nummove unread t)))
12331       (setq n (1- n)))
12332     (when (/= 0 n)
12333       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12334     (gnus-summary-recenter)
12335     (gnus-summary-position-point)
12336     (gnus-set-mode-line 'summary)
12337     n))
12338
12339 (defun gnus-summary-insert-articles (articles)
12340   (when (setq articles
12341               (gnus-sorted-difference articles
12342                                       (mapcar (lambda (h)
12343                                                 (mail-header-number h))
12344                                               gnus-newsgroup-headers)))
12345     (setq gnus-newsgroup-headers
12346           (gnus-merge 'list
12347                       gnus-newsgroup-headers
12348                       (gnus-fetch-headers articles)
12349                       'gnus-article-sort-by-number))
12350     ;; Suppress duplicates?
12351     (when gnus-suppress-duplicates
12352       (gnus-dup-suppress-articles))
12353
12354     (if (and gnus-fetch-old-headers
12355              (eq gnus-headers-retrieved-by 'nov))
12356         ;; We might want to build some more threads first.
12357         (if (eq gnus-fetch-old-headers 'invisible)
12358             (gnus-build-all-threads)
12359           (gnus-build-old-threads))
12360       ;; Mark the inserted articles that are unread as unread.
12361       (setq gnus-newsgroup-unreads
12362             (gnus-sorted-nunion
12363              gnus-newsgroup-unreads
12364              (gnus-sorted-nintersection
12365               (gnus-list-of-unread-articles gnus-newsgroup-name)
12366               articles)))
12367       ;; Mark the inserted articles as selected so that the information
12368       ;; of the marks having been changed by a user may be updated when
12369       ;; exiting this group.  See `gnus-summary-update-info'.
12370       (dolist (art articles)
12371         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12372     ;; Let the Gnus agent mark articles as read.
12373     (when gnus-agent
12374       (gnus-agent-get-undownloaded-list))
12375     ;; Remove list identifiers from subject
12376     (when gnus-list-identifiers
12377       (gnus-summary-remove-list-identifiers))
12378     ;; First and last article in this newsgroup.
12379     (when gnus-newsgroup-headers
12380       (setq gnus-newsgroup-begin
12381             (mail-header-number (car gnus-newsgroup-headers))
12382             gnus-newsgroup-end
12383             (mail-header-number
12384              (gnus-last-element gnus-newsgroup-headers))))
12385     (when gnus-use-scoring
12386       (gnus-possibly-score-headers))))
12387
12388 (defun gnus-summary-insert-old-articles (&optional all)
12389   "Insert all old articles in this group.
12390 If ALL is non-nil, already read articles become readable.
12391 If ALL is a number, fetch this number of articles."
12392   (interactive "P")
12393   (prog1
12394       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12395             older len)
12396         (setq older
12397               ;; Some nntp servers lie about their active range.  When
12398               ;; this happens, the active range can be in the millions.
12399               ;; Use a compressed range to avoid creating a huge list.
12400               (gnus-range-difference (list gnus-newsgroup-active) old))
12401         (setq len (gnus-range-length older))
12402         (cond
12403          ((null older) nil)
12404          ((numberp all)
12405           (if (< all len)
12406               (let ((older-range (nreverse older)))
12407                 (setq older nil)
12408
12409                 (while (> all 0)
12410                   (let* ((r (pop older-range))
12411                          (min (if (numberp r) r (car r)))
12412                          (max (if (numberp r) r (cdr r))))
12413                     (while (and (<= min max)
12414                                 (> all 0))
12415                       (push max older)
12416                       (setq all (1- all)
12417                             max (1- max))))))
12418             (setq older (gnus-uncompress-range older))))
12419          (all
12420           (setq older (gnus-uncompress-range older)))
12421          (t
12422           (when (and (numberp gnus-large-newsgroup)
12423                    (> len gnus-large-newsgroup))
12424               (let* ((cursor-in-echo-area nil)
12425                      (initial (gnus-parameter-large-newsgroup-initial
12426                                gnus-newsgroup-name))
12427                      (input
12428                       (read-string
12429                        (format
12430                         "How many articles from %s (%s %d): "
12431                         (gnus-group-decoded-name gnus-newsgroup-name)
12432                         (if initial "max" "default")
12433                         len)
12434                        (if initial
12435                            (cons (number-to-string initial)
12436                                  0)))))
12437                 (unless (string-match "^[ \t]*$" input)
12438                   (setq all (string-to-number input))
12439                   (if (< all len)
12440                       (let ((older-range (nreverse older)))
12441                         (setq older nil)
12442
12443                         (while (> all 0)
12444                           (let* ((r (pop older-range))
12445                                  (min (if (numberp r) r (car r)))
12446                                  (max (if (numberp r) r (cdr r))))
12447                             (while (and (<= min max)
12448                                         (> all 0))
12449                               (push max older)
12450                               (setq all (1- all)
12451                                     max (1- max))))))))))
12452           (setq older (gnus-uncompress-range older))))
12453         (if (not older)
12454             (message "No old news.")
12455           (gnus-summary-insert-articles older)
12456           (gnus-summary-limit (gnus-sorted-nunion old older))))
12457     (gnus-summary-position-point)))
12458
12459 (defun gnus-summary-insert-new-articles ()
12460   "Insert all new articles in this group."
12461   (interactive)
12462   (prog1
12463       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12464             (old-active gnus-newsgroup-active)
12465             (nnmail-fetched-sources (list t))
12466             i new)
12467         (setq gnus-newsgroup-active
12468               (gnus-activate-group gnus-newsgroup-name 'scan))
12469         (setq i (cdr gnus-newsgroup-active))
12470         (while (> i (cdr old-active))
12471           (push i new)
12472           (decf i))
12473         (if (not new)
12474             (message "No gnus is bad news")
12475           (gnus-summary-insert-articles new)
12476           (setq gnus-newsgroup-unreads
12477                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12478           (gnus-summary-limit (gnus-sorted-nunion old new))))
12479     (gnus-summary-position-point)))
12480
12481 (gnus-summary-make-all-marking-commands)
12482
12483 (gnus-ems-redefine)
12484
12485 (provide 'gnus-sum)
12486
12487 (run-hooks 'gnus-sum-load-hook)
12488
12489 ;; Local Variables:
12490 ;; coding: iso-8859-1
12491 ;; End:
12492
12493 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12494 ;;; gnus-sum.el ends here