bdf411e4815f48a8423c842f3e8074133d69b135
[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, 2008 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 ;; For Emacs < 22.2.
31 (eval-and-compile
32   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
33 (eval-when-compile
34   (require 'cl))
35
36 (defvar tool-bar-mode)
37 (defvar gnus-tmp-header)
38
39 (require 'gnus)
40 (require 'gnus-group)
41 (require 'gnus-spec)
42 (require 'gnus-range)
43 (require 'gnus-int)
44 (require 'gnus-undo)
45 (require 'gnus-util)
46 (require 'gmm-utils)
47 (require 'mm-decode)
48 (require 'nnoo)
49
50 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
51 (autoload 'gnus-cache-write-active "gnus-cache")
52 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
53 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
54 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
55 (autoload 'mm-uu-dissect "mm-uu")
56 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
57   "Deuglify broken Outlook (Express) articles and redisplay."
58   t)
59 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
60 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
61 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
62
63 (defcustom gnus-kill-summary-on-exit t
64   "*If non-nil, kill the summary buffer when you exit from it.
65 If nil, the summary will become a \"*Dead Summary*\" buffer, and
66 it will be killed sometime later."
67   :group 'gnus-summary-exit
68   :type 'boolean)
69
70 (defcustom gnus-summary-next-group-on-exit t
71   "If non-nil, go to the next unread newsgroup on summary exit.
72 See `gnus-group-goto-unread'."
73   :link '(custom-manual "(gnus)Group Maneuvering")
74   :group 'gnus-summary-exit
75   :version "23.1" ;; No Gnus
76   :type 'boolean)
77
78 (defcustom gnus-fetch-old-headers nil
79   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
80 If an unread article in the group refers to an older, already
81 read (or just marked as read) article, the old article will not
82 normally be displayed in the Summary buffer.  If this variable is
83 t, Gnus will attempt to grab the headers to the old articles, and
84 thereby build complete threads.  If it has the value `some', all
85 old headers will be fetched but only enough headers to connect
86 otherwise loose threads will be displayed.  This variable can
87 also be a number.  In that case, no more than that number of old
88 headers will be fetched.  If it has the value `invisible', all
89 old headers will be fetched, but none will be displayed.
90
91 The server has to support NOV for any of this to work.
92
93 This feature can seriously impact performance it ignores all
94 locally cached header entries."
95   :group 'gnus-thread
96   :type '(choice (const :tag "off" nil)
97                  (const :tag "on" t)
98                  (const some)
99                  (const invisible)
100                  number
101                  (sexp :menu-tag "other" t)))
102
103 (defcustom gnus-refer-thread-limit 500
104   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
105 If t, fetch all the available old headers."
106   :group 'gnus-thread
107   :type '(choice number
108                  (sexp :menu-tag "other" t)))
109
110 (defcustom gnus-summary-make-false-root 'adopt
111   "*nil means that Gnus won't gather loose threads.
112 If the root of a thread has expired or been read in a previous
113 session, the information necessary to build a complete thread has been
114 lost.  Instead of having many small sub-threads from this original thread
115 scattered all over the summary buffer, Gnus can gather them.
116
117 If non-nil, Gnus will try to gather all loose sub-threads from an
118 original thread into one large thread.
119
120 If this variable is non-nil, it should be one of `none', `adopt',
121 `dummy' or `empty'.
122
123 If this variable is `none', Gnus will not make a false root, but just
124 present the sub-threads after another.
125 If this variable is `dummy', Gnus will create a dummy root that will
126 have all the sub-threads as children.
127 If this variable is `adopt', Gnus will make one of the \"children\"
128 the parent and mark all the step-children as such.
129 If this variable is `empty', the \"children\" are printed with empty
130 subject fields.  (Or rather, they will be printed with a string
131 given by the `gnus-summary-same-subject' variable.)"
132   :group 'gnus-thread
133   :type '(choice (const :tag "off" nil)
134                  (const none)
135                  (const dummy)
136                  (const adopt)
137                  (const empty)))
138
139 (defcustom gnus-summary-make-false-root-always nil
140   "Always make a false dummy root."
141   :version "22.1"
142   :group 'gnus-thread
143   :type 'boolean)
144
145 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
146   "*A regexp to match subjects to be excluded from loose thread gathering.
147 As loose thread gathering is done on subjects only, that means that
148 there can be many false gatherings performed.  By rooting out certain
149 common subjects, gathering might become saner."
150   :group 'gnus-thread
151   :type 'regexp)
152
153 (defcustom gnus-summary-gather-subject-limit nil
154   "*Maximum length of subject comparisons when gathering loose threads.
155 Use nil to compare full subjects.  Setting this variable to a low
156 number will help gather threads that have been corrupted by
157 newsreaders chopping off subject lines, but it might also mean that
158 unrelated articles that have subject that happen to begin with the
159 same few characters will be incorrectly gathered.
160
161 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
162 comparing subjects."
163   :group 'gnus-thread
164   :type '(choice (const :tag "off" nil)
165                  (const fuzzy)
166                  (sexp :menu-tag "on" t)))
167
168 (defcustom gnus-simplify-subject-functions nil
169   "List of functions taking a string argument that simplify subjects.
170 The functions are applied recursively.
171
172 Useful functions to put in this list include:
173 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
174 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
175   :group 'gnus-thread
176   :type '(repeat function))
177
178 (defcustom gnus-simplify-ignored-prefixes nil
179   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
180   :group 'gnus-thread
181   :type '(choice (const :tag "off" nil)
182                  regexp))
183
184 (defcustom gnus-build-sparse-threads nil
185   "*If non-nil, fill in the gaps in threads.
186 If `some', only fill in the gaps that are needed to tie loose threads
187 together.  If `more', fill in all leaf nodes that Gnus can find.  If
188 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
189   :group 'gnus-thread
190   :type '(choice (const :tag "off" nil)
191                  (const some)
192                  (const more)
193                  (sexp :menu-tag "all" t)))
194
195 (defcustom gnus-summary-thread-gathering-function
196   'gnus-gather-threads-by-subject
197   "*Function used for gathering loose threads.
198 There are two pre-defined functions: `gnus-gather-threads-by-subject',
199 which only takes Subjects into consideration; and
200 `gnus-gather-threads-by-references', which compared the References
201 headers of the articles to find matches."
202   :group 'gnus-thread
203   :type '(radio (function-item gnus-gather-threads-by-subject)
204                 (function-item gnus-gather-threads-by-references)
205                 (function :tag "other")))
206
207 (defcustom gnus-summary-same-subject ""
208   "*String indicating that the current article has the same subject as the previous.
209 This variable will only be used if the value of
210 `gnus-summary-make-false-root' is `empty'."
211   :group 'gnus-summary-format
212   :type 'string)
213
214 (defcustom gnus-summary-goto-unread t
215   "*If t, many commands will go to the next unread article.
216 This applies to marking commands as well as other commands that
217 \"naturally\" select the next article, like, for instance, `SPC' at
218 the end of an article.
219
220 If nil, the marking commands do NOT go to the next unread article
221 \(they go to the next article instead).  If `never', commands that
222 usually go to the next unread article, will go to the next article,
223 whether it is read or not."
224   :group 'gnus-summary-marks
225   :link '(custom-manual "(gnus)Setting Marks")
226   :type '(choice (const :tag "off" nil)
227                  (const never)
228                  (sexp :menu-tag "on" t)))
229
230 (defcustom gnus-summary-default-score 0
231   "*Default article score level.
232 All scores generated by the score files will be added to this score.
233 If this variable is nil, scoring will be disabled."
234   :group 'gnus-score-default
235   :type '(choice (const :tag "disable")
236                  integer))
237
238 (defcustom gnus-summary-default-high-score 0
239   "*Default threshold for a high scored article.
240 An article will be highlighted as high scored if its score is greater
241 than this score."
242   :version "22.1"
243   :group 'gnus-score-default
244   :type 'integer)
245
246 (defcustom gnus-summary-default-low-score 0
247   "*Default threshold for a low scored article.
248 An article will be highlighted as low scored if its score is smaller
249 than this score."
250   :version "22.1"
251   :group 'gnus-score-default
252   :type 'integer)
253
254 (defcustom gnus-summary-zcore-fuzz 0
255   "*Fuzziness factor for the zcore in the summary buffer.
256 Articles with scores closer than this to `gnus-summary-default-score'
257 will not be marked."
258   :group 'gnus-summary-format
259   :type 'integer)
260
261 (defcustom gnus-simplify-subject-fuzzy-regexp nil
262   "*Strings to be removed when doing fuzzy matches.
263 This can either be a regular expression or list of regular expressions
264 that will be removed from subject strings if fuzzy subject
265 simplification is selected."
266   :group 'gnus-thread
267   :type '(repeat regexp))
268
269 (defcustom gnus-show-threads t
270   "*If non-nil, display threads in summary mode."
271   :group 'gnus-thread
272   :type 'boolean)
273
274 (defcustom gnus-thread-hide-subtree nil
275   "*If non-nil, hide all threads initially.
276 This can be a predicate specifier which says which threads to hide.
277 If threads are hidden, you have to run the command
278 `gnus-summary-show-thread' by hand or select an article."
279   :group 'gnus-thread
280   :type '(radio (sexp :format "Non-nil\n"
281                       :match (lambda (widget value)
282                                (not (or (consp value) (functionp value))))
283                       :value t)
284                 (const nil)
285                 (sexp :tag "Predicate specifier")))
286
287 (defcustom gnus-thread-hide-killed t
288   "*If non-nil, hide killed threads automatically."
289   :group 'gnus-thread
290   :type 'boolean)
291
292 (defcustom gnus-thread-ignore-subject t
293   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
294 If nil, articles that have different subjects from their parents will
295 start separate threads."
296   :group 'gnus-thread
297   :type 'boolean)
298
299 (defcustom gnus-thread-operation-ignore-subject t
300   "*If non-nil, subjects will be ignored when doing thread commands.
301 This affects commands like `gnus-summary-kill-thread' and
302 `gnus-summary-lower-thread'.
303
304 If this variable is nil, articles in the same thread with different
305 subjects will not be included in the operation in question.  If this
306 variable is `fuzzy', only articles that have subjects that are fuzzily
307 equal will be included."
308   :group 'gnus-thread
309   :type '(choice (const :tag "off" nil)
310                  (const fuzzy)
311                  (sexp :tag "on" t)))
312
313 (defcustom gnus-thread-indent-level 4
314   "*Number that says how much each sub-thread should be indented."
315   :group 'gnus-thread
316   :type 'integer)
317
318 (defcustom gnus-auto-extend-newsgroup t
319   "*If non-nil, extend newsgroup forward and backward when requested."
320   :group 'gnus-summary-choose
321   :type 'boolean)
322
323 (defcustom gnus-auto-select-first t
324   "If non-nil, select an article on group entry.
325 An article is selected automatically when entering a group
326 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
327 `gnus-summary-catchup-and-goto-next-group'.
328
329 Which article is selected is controlled by the variable
330 `gnus-auto-select-subject'.
331
332 If you want to prevent automatic selection of articles in some
333 newsgroups, set the variable to nil in `gnus-select-group-hook'."
334   ;; Commands include...
335   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
336   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
337   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
338   :group 'gnus-group-select
339   :type '(choice (const :tag "none" nil)
340                  (sexp :menu-tag "first" t)))
341
342 (defcustom gnus-auto-select-subject 'unread
343   "*Says what subject to place under point when entering a group.
344
345 This variable can either be the symbols `first' (place point on the
346 first subject), `unread' (place point on the subject line of the first
347 unread article), `best' (place point on the subject line of the
348 higest-scored article), `unseen' (place point on the subject line of
349 the first unseen article), `unseen-or-unread' (place point on the subject
350 line of the first unseen article or, if all article have been seen, on the
351 subject line of the first unread article), or a function to be called to
352 place point on some subject line."
353   :version "22.1"
354   :group 'gnus-group-select
355   :type '(choice (const best)
356                  (const unread)
357                  (const first)
358                  (const unseen)
359                  (const unseen-or-unread)))
360
361 (defcustom gnus-auto-select-next t
362   "*If non-nil, offer to go to the next group from the end of the previous.
363 If the value is t and the next newsgroup is empty, Gnus will exit
364 summary mode and go back to group mode.  If the value is neither nil
365 nor t, Gnus will select the following unread newsgroup.  In
366 particular, if the value is the symbol `quietly', the next unread
367 newsgroup will be selected without any confirmation, and if it is
368 `almost-quietly', the next group will be selected without any
369 confirmation if you are located on the last article in the group.
370 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
371 will go to the next group without confirmation."
372   :group 'gnus-summary-maneuvering
373   :type '(choice (const :tag "off" nil)
374                  (const quietly)
375                  (const almost-quietly)
376                  (const slightly-quietly)
377                  (sexp :menu-tag "on" t)))
378
379 (defcustom gnus-auto-select-same nil
380   "*If non-nil, select the next article with the same subject.
381 If there are no more articles with the same subject, go to
382 the first unread article."
383   :group 'gnus-summary-maneuvering
384   :type 'boolean)
385
386 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
387   "What article should be selected after exiting an ephemeral group.
388 Valid values include:
389
390 `next'
391   Select the next article.
392 `next-unread'
393   Select the next unread article.
394 `next-noselect'
395   Move the cursor to the next article.  This is the default.
396 `next-unread-noselect'
397   Move the cursor to the next unread article.
398
399 If it has any other value or there is no next (unread) article, the
400 article selected before entering to the ephemeral group will appear."
401   :version "23.1" ;; No Gnus
402   :group 'gnus-summary-maneuvering
403   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
404                  (const next) (const next-unread)
405                  (const next-noselect) (const next-unread-noselect)
406                  (sexp :tag "other" :value nil)))
407
408 (defcustom gnus-auto-goto-ignores 'unfetched
409   "*Says how to handle unfetched articles when maneuvering.
410
411 This variable can either be the symbols nil (maneuver to any
412 article), `undownloaded' (maneuvering while unplugged ignores articles
413 that have not been fetched), `always-undownloaded' (maneuvering always
414 ignores articles that have not been fetched), `unfetched' (maneuvering
415 ignores articles whose headers have not been fetched).
416
417 NOTE: The list of unfetched articles will always be nil when plugged
418 and, when unplugged, a subset of the undownloaded article list."
419   :version "22.1"
420   :group 'gnus-summary-maneuvering
421   :type '(choice (const :tag "None" nil)
422                  (const :tag "Undownloaded when unplugged" undownloaded)
423                  (const :tag "Undownloaded" always-undownloaded)
424                  (const :tag "Unfetched" unfetched)))
425
426 (defcustom gnus-summary-check-current nil
427   "*If non-nil, consider the current article when moving.
428 The \"unread\" movement commands will stay on the same line if the
429 current article is unread."
430   :group 'gnus-summary-maneuvering
431   :type 'boolean)
432
433 (defcustom gnus-auto-center-summary 2
434   "*If non-nil, always center the current summary buffer.
435 In particular, if `vertical' do only vertical recentering.  If non-nil
436 and non-`vertical', do both horizontal and vertical recentering."
437   :group 'gnus-summary-maneuvering
438   :type '(choice (const :tag "none" nil)
439                  (const vertical)
440                  (integer :tag "height")
441                  (sexp :menu-tag "both" t)))
442
443 (defvar gnus-auto-center-group t
444   "*If non-nil, always center the group buffer.")
445
446 (defcustom gnus-show-all-headers nil
447   "*If non-nil, don't hide any headers."
448   :group 'gnus-article-hiding
449   :group 'gnus-article-headers
450   :type 'boolean)
451
452 (defcustom gnus-summary-ignore-duplicates nil
453   "*If non-nil, ignore articles with identical Message-ID headers."
454   :group 'gnus-summary
455   :type 'boolean)
456
457 (defcustom gnus-single-article-buffer t
458   "*If non-nil, display all articles in the same buffer.
459 If nil, each group will get its own article buffer."
460   :group 'gnus-article-various
461   :type 'boolean)
462
463 (defcustom gnus-break-pages t
464   "*If non-nil, do page breaking on articles.
465 The page delimiter is specified by the `gnus-page-delimiter'
466 variable."
467   :group 'gnus-article-various
468   :type 'boolean)
469
470 (defcustom gnus-move-split-methods nil
471   "*Variable used to suggest where articles are to be moved to.
472 It uses the same syntax as the `gnus-split-methods' variable.
473 However, whereas `gnus-split-methods' specifies file names as targets,
474 this variable specifies group names."
475   :group 'gnus-summary-mail
476   :type '(repeat (choice (list :value (fun) function)
477                          (cons :value ("" "") regexp (repeat string))
478                          (sexp :value nil))))
479
480 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
481   "Function used to compute default prefix for article move/copy/etc prompts.
482 The function should take one argument, a group name, and return a
483 string with the suggested prefix."
484   :group 'gnus-summary-mail
485   :type 'function)
486
487 ;; FIXME: Although the custom type is `character' for the following variables,
488 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
489
490 (defcustom gnus-unread-mark ?           ;Whitespace
491   "*Mark used for unread articles."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-ticked-mark ?!
496   "*Mark used for ticked articles."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-dormant-mark ??
501   "*Mark used for dormant articles."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-del-mark ?r
506   "*Mark used for del'd articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-read-mark ?R
511   "*Mark used for read articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-expirable-mark ?E
516   "*Mark used for expirable articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-killed-mark ?K
521   "*Mark used for killed articles."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-spam-mark ?$
526   "*Mark used for spam articles."
527   :version "22.1"
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-souped-mark ?F
532   "*Mark used for souped articles."
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-kill-file-mark ?X
537   "*Mark used for articles killed by kill files."
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-low-score-mark ?Y
542   "*Mark used for articles with a low score."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-catchup-mark ?C
547   "*Mark used for articles that are caught up."
548   :group 'gnus-summary-marks
549   :type 'character)
550
551 (defcustom gnus-replied-mark ?A
552   "*Mark used for articles that have been replied to."
553   :group 'gnus-summary-marks
554   :type 'character)
555
556 (defcustom gnus-forwarded-mark ?F
557   "*Mark used for articles that have been forwarded."
558   :version "22.1"
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-recent-mark ?N
563   "*Mark used for articles that are recent."
564   :version "22.1"
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-cached-mark ?*
569   "*Mark used for articles that are in the cache."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-saved-mark ?S
574   "*Mark used for articles that have been saved."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-unseen-mark ?.
579   "*Mark used for articles that haven't been seen."
580   :version "22.1"
581   :group 'gnus-summary-marks
582   :type 'character)
583
584 (defcustom gnus-no-mark ?               ;Whitespace
585   "*Mark used for articles that have no other secondary mark."
586   :version "22.1"
587   :group 'gnus-summary-marks
588   :type 'character)
589
590 (defcustom gnus-ancient-mark ?O
591   "*Mark used for ancient articles."
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-sparse-mark ?Q
596   "*Mark used for sparsely reffed articles."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-canceled-mark ?G
601   "*Mark used for canceled articles."
602   :group 'gnus-summary-marks
603   :type 'character)
604
605 (defcustom gnus-duplicate-mark ?M
606   "*Mark used for duplicate articles."
607   :group 'gnus-summary-marks
608   :type 'character)
609
610 (defcustom gnus-undownloaded-mark ?-
611   "*Mark used for articles that weren't downloaded."
612   :version "22.1"
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-downloaded-mark ?+
617   "*Mark used for articles that were downloaded."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-downloadable-mark ?%
622   "*Mark used for articles that are to be downloaded."
623   :group 'gnus-summary-marks
624   :type 'character)
625
626 (defcustom gnus-unsendable-mark ?=
627   "*Mark used for articles that won't be sent."
628   :group 'gnus-summary-marks
629   :type 'character)
630
631 (defcustom gnus-score-over-mark ?+
632   "*Score mark used for articles with high scores."
633   :group 'gnus-summary-marks
634   :type 'character)
635
636 (defcustom gnus-score-below-mark ?-
637   "*Score mark used for articles with low scores."
638   :group 'gnus-summary-marks
639   :type 'character)
640
641 (defcustom gnus-empty-thread-mark ?     ;Whitespace
642   "*There is no thread under the article."
643   :group 'gnus-summary-marks
644   :type 'character)
645
646 (defcustom gnus-not-empty-thread-mark ?=
647   "*There is a thread under the article."
648   :group 'gnus-summary-marks
649   :type 'character)
650
651 (defcustom gnus-view-pseudo-asynchronously nil
652   "*If non-nil, Gnus will view pseudo-articles asynchronously."
653   :group 'gnus-extract-view
654   :type 'boolean)
655
656 (defcustom gnus-auto-expirable-marks
657   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
658         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
659         gnus-souped-mark gnus-duplicate-mark)
660   "*The list of marks converted into expiration if a group is auto-expirable."
661   :version "21.1"
662   :group 'gnus-summary
663   :type '(repeat character))
664
665 (defcustom gnus-inhibit-user-auto-expire t
666   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
667   :version "21.1"
668   :group 'gnus-summary
669   :type 'boolean)
670
671 (defcustom gnus-view-pseudos nil
672   "*If `automatic', pseudo-articles will be viewed automatically.
673 If `not-confirm', pseudos will be viewed automatically, and the user
674 will not be asked to confirm the command."
675   :group 'gnus-extract-view
676   :type '(choice (const :tag "off" nil)
677                  (const automatic)
678                  (const not-confirm)))
679
680 (defcustom gnus-view-pseudos-separately t
681   "*If non-nil, one pseudo-article will be created for each file to be viewed.
682 If nil, all files that use the same viewing command will be given as a
683 list of parameters to that command."
684   :group 'gnus-extract-view
685   :type 'boolean)
686
687 (defcustom gnus-insert-pseudo-articles t
688   "*If non-nil, insert pseudo-articles when decoding articles."
689   :group 'gnus-extract-view
690   :type 'boolean)
691
692 (defcustom gnus-summary-dummy-line-format
693   "   %(:                             :%) %S\n"
694   "*The format specification for the dummy roots in the summary buffer.
695 It works along the same lines as a normal formatting string,
696 with some simple extensions.
697
698 %S  The subject
699
700 General format specifiers can also be used.
701 See `(gnus)Formatting Variables'."
702   :link '(custom-manual "(gnus)Formatting Variables")
703   :group 'gnus-threading
704   :type 'string)
705
706 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
707   "*The format specification for the summary mode line.
708 It works along the same lines as a normal formatting string,
709 with some simple extensions:
710
711 %G  Group name
712 %p  Unprefixed group name
713 %A  Current article number
714 %z  Current article score
715 %V  Gnus version
716 %U  Number of unread articles in the group
717 %e  Number of unselected articles in the group
718 %Z  A string with unread/unselected article counts
719 %g  Shortish group name
720 %S  Subject of the current article
721 %u  User-defined spec
722 %s  Current score file name
723 %d  Number of dormant articles
724 %r  Number of articles that have been marked as read in this session
725 %E  Number of articles expunged by the score files"
726   :group 'gnus-summary-format
727   :type 'string)
728
729 (defcustom gnus-list-identifiers nil
730   "Regexp that matches list identifiers to be removed from subject.
731 This can also be a list of regexps."
732   :version "21.1"
733   :group 'gnus-summary-format
734   :group 'gnus-article-hiding
735   :type '(choice (const :tag "none" nil)
736                  (regexp :value ".*")
737                  (repeat :value (".*") regexp)))
738
739 (defcustom gnus-summary-mark-below 0
740   "*Mark all articles with a score below this variable as read.
741 This variable is local to each summary buffer and usually set by the
742 score file."
743   :group 'gnus-score-default
744   :type 'integer)
745
746 (defun gnus-widget-reversible-match (widget value)
747   "Ignoring WIDGET, convert VALUE to internal form.
748 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
749   ;; (debug value)
750   (or (symbolp value)
751       (and (listp value)
752            (eq (length value) 2)
753            (eq (nth 0 value) 'not)
754            (symbolp (nth 1 value)))))
755
756 (defun gnus-widget-reversible-to-internal (widget value)
757   "Ignoring WIDGET, convert VALUE to internal form.
758 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
759 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
760   ;; (debug value)
761   (if (atom value)
762       (list value nil)
763     (list (nth 1 value) t)))
764
765 (defun gnus-widget-reversible-to-external (widget value)
766   "Ignoring WIDGET, convert VALUE to external form.
767 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
768 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
769   ;; (debug value)
770   (if (nth 1 value)
771       (list 'not (nth 0 value))
772     (nth 0 value)))
773
774 (define-widget 'gnus-widget-reversible 'group
775   "A `group' that convert values."
776   :match 'gnus-widget-reversible-match
777   :value-to-internal 'gnus-widget-reversible-to-internal
778   :value-to-external 'gnus-widget-reversible-to-external)
779
780 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
781   "*List of functions used for sorting articles in the summary buffer.
782
783 Each function takes two articles and returns non-nil if the first
784 article should be sorted before the other.  If you use more than one
785 function, the primary sort function should be the last.  You should
786 probably always include `gnus-article-sort-by-number' in the list of
787 sorting functions -- preferably first.  Also note that sorting by date
788 is often much slower than sorting by number, and the sorting order is
789 very similar.  (Sorting by date means sorting by the time the message
790 was sent, sorting by number means sorting by arrival time.)
791
792 Each item can also be a list `(not F)' where F is a function;
793 this reverses the sort order.
794
795 Ready-made functions include `gnus-article-sort-by-number',
796 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
797 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
798 and `gnus-article-sort-by-score'.
799
800 When threading is turned on, the variable `gnus-thread-sort-functions'
801 controls how articles are sorted."
802   :group 'gnus-summary-sort
803   :type '(repeat (gnus-widget-reversible
804                   (choice (function-item gnus-article-sort-by-number)
805                           (function-item gnus-article-sort-by-author)
806                           (function-item gnus-article-sort-by-subject)
807                           (function-item gnus-article-sort-by-date)
808                           (function-item gnus-article-sort-by-score)
809                           (function-item gnus-article-sort-by-random)
810                           (function :tag "other"))
811                   (boolean :tag "Reverse order"))))
812
813
814 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
815   "*List of functions used for sorting threads in the summary buffer.
816 By default, threads are sorted by article number.
817
818 Each function takes two threads and returns non-nil if the first
819 thread should be sorted before the other.  If you use more than one
820 function, the primary sort function should be the last.  You should
821 probably always include `gnus-thread-sort-by-number' in the list of
822 sorting functions -- preferably first.  Also note that sorting by date
823 is often much slower than sorting by number, and the sorting order is
824 very similar.  (Sorting by date means sorting by the time the message
825 was sent, sorting by number means sorting by arrival time.)
826
827 Each list item can also be a list `(not F)' where F is a
828 function; this specifies reversed sort order.
829
830 Ready-made functions include `gnus-thread-sort-by-number',
831 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
832 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
833 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
834 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
835 and `gnus-thread-sort-by-total-score' (see
836 `gnus-thread-score-function').
837
838 When threading is turned off, the variable
839 `gnus-article-sort-functions' controls how articles are sorted."
840   :group 'gnus-summary-sort
841   :type '(repeat
842           (gnus-widget-reversible
843            (choice (function-item gnus-thread-sort-by-number)
844                    (function-item gnus-thread-sort-by-author)
845                    (function-item gnus-thread-sort-by-recipient)
846                    (function-item gnus-thread-sort-by-subject)
847                    (function-item gnus-thread-sort-by-date)
848                    (function-item gnus-thread-sort-by-score)
849                    (function-item gnus-thread-sort-by-most-recent-number)
850                    (function-item gnus-thread-sort-by-most-recent-date)
851                    (function-item gnus-thread-sort-by-random)
852                    (function-item gnus-thread-sort-by-total-score)
853                    (function :tag "other"))
854            (boolean :tag "Reverse order"))))
855
856 (defcustom gnus-thread-score-function '+
857   "*Function used for calculating the total score of a thread.
858
859 The function is called with the scores of the article and each
860 subthread and should then return the score of the thread.
861
862 Some functions you can use are `+', `max', or `min'."
863   :group 'gnus-summary-sort
864   :type 'function)
865
866 (defcustom gnus-summary-expunge-below nil
867   "All articles that have a score less than this variable will be expunged.
868 This variable is local to the summary buffers."
869   :group 'gnus-score-default
870   :type '(choice (const :tag "off" nil)
871                  integer))
872
873 (defcustom gnus-thread-expunge-below nil
874   "All threads that have a total score less than this variable will be expunged.
875 See `gnus-thread-score-function' for en explanation of what a
876 \"thread score\" is.
877
878 This variable is local to the summary buffers."
879   :group 'gnus-threading
880   :group 'gnus-score-default
881   :type '(choice (const :tag "off" nil)
882                  integer))
883
884 (defcustom gnus-summary-mode-hook nil
885   "*A hook for Gnus summary mode.
886 This hook is run before any variables are set in the summary buffer."
887   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
888   :group 'gnus-summary-various
889   :type 'hook)
890
891 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
892 (when (featurep 'xemacs)
893   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
894   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
895   (add-hook 'gnus-summary-mode-hook
896             'gnus-xmas-switch-horizontal-scrollbar-off))
897
898 (defcustom gnus-summary-menu-hook nil
899   "*Hook run after the creation of the summary mode menu."
900   :group 'gnus-summary-visual
901   :type 'hook)
902
903 (defcustom gnus-summary-exit-hook nil
904   "*A hook called on exit from the summary buffer.
905 It will be called with point in the group buffer."
906   :group 'gnus-summary-exit
907   :type 'hook)
908
909 (defcustom gnus-summary-prepare-hook nil
910   "*A hook called after the summary buffer has been generated.
911 If you want to modify the summary buffer, you can use this hook."
912   :group 'gnus-summary-various
913   :type 'hook)
914
915 (defcustom gnus-summary-prepared-hook nil
916   "*A hook called as the last thing after the summary buffer has been generated."
917   :group 'gnus-summary-various
918   :type 'hook)
919
920 (defcustom gnus-summary-generate-hook nil
921   "*A hook run just before generating the summary buffer.
922 This hook is commonly used to customize threading variables and the
923 like."
924   :group 'gnus-summary-various
925   :type 'hook)
926
927 (defcustom gnus-select-group-hook nil
928   "*A hook called when a newsgroup is selected.
929
930 If you'd like to simplify subjects like the
931 `gnus-summary-next-same-subject' command does, you can use the
932 following hook:
933
934  (add-hook gnus-select-group-hook
935            (lambda ()
936              (mapcar (lambda (header)
937                        (mail-header-set-subject
938                         header
939                         (gnus-simplify-subject
940                          (mail-header-subject header) 're-only)))
941                      gnus-newsgroup-headers)))"
942   :group 'gnus-group-select
943   :type 'hook)
944
945 (defcustom gnus-select-article-hook nil
946   "*A hook called when an article is selected."
947   :group 'gnus-summary-choose
948   :options '(gnus-agent-fetch-selected-article)
949   :type 'hook)
950
951 (defcustom gnus-visual-mark-article-hook
952   (list 'gnus-highlight-selected-summary)
953   "*Hook run after selecting an article in the summary buffer.
954 It is meant to be used for highlighting the article in some way.  It
955 is not run if `gnus-visual' is nil."
956   :group 'gnus-summary-visual
957   :type 'hook)
958
959 (defcustom gnus-parse-headers-hook nil
960   "*A hook called before parsing the headers."
961   :group 'gnus-various
962   :type 'hook)
963
964 (defcustom gnus-exit-group-hook nil
965   "*A hook called when exiting summary mode.
966 This hook is not called from the non-updating exit commands like `Q'."
967   :group 'gnus-various
968   :type 'hook)
969
970 (defcustom gnus-summary-update-hook
971   (list 'gnus-summary-highlight-line)
972   "*A hook called when a summary line is changed.
973 The hook will not be called if `gnus-visual' is nil.
974
975 The default function `gnus-summary-highlight-line' will
976 highlight the line according to the `gnus-summary-highlight'
977 variable."
978   :group 'gnus-summary-visual
979   :type 'hook)
980
981 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
982   "*A hook called when an article is selected for the first time.
983 The hook is intended to mark an article as read (or unread)
984 automatically when it is selected."
985   :group 'gnus-summary-choose
986   :type 'hook)
987
988 (defcustom gnus-group-no-more-groups-hook nil
989   "*A hook run when returning to group mode having no more (unread) groups."
990   :group 'gnus-group-select
991   :type 'hook)
992
993 (defcustom gnus-ps-print-hook nil
994   "*A hook run before ps-printing something from Gnus."
995   :group 'gnus-summary
996   :type 'hook)
997
998 (defcustom gnus-summary-article-move-hook nil
999   "*A hook called after an article is moved, copied, respooled, or crossposted."
1000   :version "22.1"
1001   :group 'gnus-summary
1002   :type 'hook)
1003
1004 (defcustom gnus-summary-article-delete-hook nil
1005   "*A hook called after an article is deleted."
1006   :version "22.1"
1007   :group 'gnus-summary
1008   :type 'hook)
1009
1010 (defcustom gnus-summary-article-expire-hook nil
1011   "*A hook called after an article is expired."
1012   :version "22.1"
1013   :group 'gnus-summary
1014   :type 'hook)
1015
1016 (defcustom gnus-summary-display-arrow
1017   (and (fboundp 'display-graphic-p)
1018        (display-graphic-p))
1019   "*If non-nil, display an arrow highlighting the current article."
1020   :version "22.1"
1021   :group 'gnus-summary
1022   :type 'boolean)
1023
1024 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1025   "Face used for highlighting the current article in the summary buffer."
1026   :group 'gnus-summary-visual
1027   :type 'face)
1028
1029 (defvar gnus-tmp-downloaded nil)
1030
1031 (defcustom gnus-summary-highlight
1032   '(((eq mark gnus-canceled-mark)
1033      . gnus-summary-cancelled)
1034     ((and uncached (> score default-high))
1035      . gnus-summary-high-undownloaded)
1036     ((and uncached (< score default-low))
1037      . gnus-summary-low-undownloaded)
1038     (uncached
1039      . gnus-summary-normal-undownloaded)
1040     ((and (> score default-high)
1041           (or (eq mark gnus-dormant-mark)
1042               (eq mark gnus-ticked-mark)))
1043      . gnus-summary-high-ticked)
1044     ((and (< score default-low)
1045           (or (eq mark gnus-dormant-mark)
1046               (eq mark gnus-ticked-mark)))
1047      . gnus-summary-low-ticked)
1048     ((or (eq mark gnus-dormant-mark)
1049          (eq mark gnus-ticked-mark))
1050      . gnus-summary-normal-ticked)
1051     ((and (> score default-high) (eq mark gnus-ancient-mark))
1052      . gnus-summary-high-ancient)
1053     ((and (< score default-low) (eq mark gnus-ancient-mark))
1054      . gnus-summary-low-ancient)
1055     ((eq mark gnus-ancient-mark)
1056      . gnus-summary-normal-ancient)
1057     ((and (> score default-high) (eq mark gnus-unread-mark))
1058      . gnus-summary-high-unread)
1059     ((and (< score default-low) (eq mark gnus-unread-mark))
1060      . gnus-summary-low-unread)
1061     ((eq mark gnus-unread-mark)
1062      . gnus-summary-normal-unread)
1063     ((> score default-high)
1064      . gnus-summary-high-read)
1065     ((< score default-low)
1066      . gnus-summary-low-read)
1067     (t
1068      . gnus-summary-normal-read))
1069   "*Controls the highlighting of summary buffer lines.
1070
1071 A list of (FORM . FACE) pairs.  When deciding how a particular
1072 summary line should be displayed, each form is evaluated.  The content
1073 of the face field after the first true form is used.  You can change
1074 how those summary lines are displayed, by editing the face field.
1075
1076 You can use the following variables in the FORM field.
1077
1078 score:        The article's score.
1079 default:      The default article score.
1080 default-high: The default score for high scored articles.
1081 default-low:  The default score for low scored articles.
1082 below:        The score below which articles are automatically marked as read.
1083 mark:         The article's mark.
1084 uncached:     Non-nil if the article is uncached."
1085   :group 'gnus-summary-visual
1086   :type '(repeat (cons (sexp :tag "Form" nil)
1087                        face)))
1088 (put 'gnus-summary-highlight 'risky-local-variable t)
1089
1090 (defcustom gnus-alter-header-function nil
1091   "Function called to allow alteration of article header structures.
1092 The function is called with one parameter, the article header vector,
1093 which it may alter in any way."
1094   :type '(choice (const :tag "None" nil)
1095                  function)
1096   :group 'gnus-summary)
1097
1098 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1099   "Function used to decode a string with encoded words.")
1100
1101 (defvar gnus-decode-encoded-address-function
1102   'mail-decode-encoded-address-string
1103   "Function used to decode addresses with encoded words.")
1104
1105 (defcustom gnus-extra-headers '(To Newsgroups)
1106   "*Extra headers to parse."
1107   :version "21.1"
1108   :group 'gnus-summary
1109   :type '(repeat symbol))
1110
1111 (defcustom gnus-ignored-from-addresses
1112   (and user-mail-address
1113        (not (string= user-mail-address ""))
1114        (regexp-quote user-mail-address))
1115   "*From headers that may be suppressed in favor of To headers.
1116 This can be a regexp or a list of regexps."
1117   :version "21.1"
1118   :group 'gnus-summary
1119   :type '(choice regexp
1120                  (repeat :tag "Regexp List" regexp)))
1121
1122 (defsubst gnus-ignored-from-addresses ()
1123   (gmm-regexp-concat gnus-ignored-from-addresses))
1124
1125 (defcustom gnus-summary-to-prefix "-> "
1126   "*String prefixed to the To field in the summary line when
1127 using `gnus-ignored-from-addresses'."
1128   :version "22.1"
1129   :group 'gnus-summary
1130   :type 'string)
1131
1132 (defcustom gnus-summary-newsgroup-prefix "=> "
1133   "*String prefixed to the Newsgroup field in the summary
1134 line when using `gnus-ignored-from-addresses'."
1135   :version "22.1"
1136   :group 'gnus-summary
1137   :type 'string)
1138
1139 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1140   "List of charsets that should be ignored.
1141 When these charsets are used in the \"charset\" parameter, the
1142 default charset will be used instead."
1143   :version "21.1"
1144   :type '(repeat symbol)
1145   :group 'gnus-charset)
1146
1147 (defcustom gnus-newsgroup-maximum-articles nil
1148   "The maximum number of articles a newsgroup.
1149 If this is a number, old articles in a newsgroup exceeding this number
1150 are silently ignored.  If it is nil, no article is ignored.  Note that
1151 setting this variable to a number might prevent you from reading very
1152 old articles."
1153   :group 'gnus-group-select
1154   :version "22.2"
1155   :type '(choice (const :tag "No limit" nil)
1156                  integer))
1157
1158 (gnus-define-group-parameter
1159  ignored-charsets
1160  :type list
1161  :function-document
1162  "Return the ignored charsets of GROUP."
1163  :variable gnus-group-ignored-charsets-alist
1164  :variable-default
1165  '(("alt\\.chinese\\.text" iso-8859-1))
1166  :variable-document
1167  "Alist of regexps (to match group names) and charsets that should be ignored.
1168 When these charsets are used in the \"charset\" parameter, the
1169 default charset will be used instead."
1170  :variable-group gnus-charset
1171  :variable-type '(repeat (cons (regexp :tag "Group")
1172                                (repeat symbol)))
1173  :parameter-type '(choice :tag "Ignored charsets"
1174                           :value nil
1175                           (repeat (symbol)))
1176  :parameter-document       "\
1177 List of charsets that should be ignored.
1178
1179 When these charsets are used in the \"charset\" parameter, the
1180 default charset will be used instead.")
1181
1182 (defcustom gnus-group-highlight-words-alist nil
1183   "Alist of group regexps and highlight regexps.
1184 This variable uses the same syntax as `gnus-emphasis-alist'."
1185   :version "21.1"
1186   :type '(repeat (cons (regexp :tag "Group")
1187                        (repeat (list (regexp :tag "Highlight regexp")
1188                                      (number :tag "Group for entire word" 0)
1189                                      (number :tag "Group for displayed part" 0)
1190                                      (symbol :tag "Face"
1191                                              gnus-emphasis-highlight-words)))))
1192   :group 'gnus-summary-visual)
1193
1194 (defcustom gnus-summary-show-article-charset-alist
1195   nil
1196   "Alist of number and charset.
1197 The article will be shown with the charset corresponding to the
1198 numbered argument.
1199 For example: ((1 . cn-gb-2312) (2 . big5))."
1200   :version "21.1"
1201   :type '(repeat (cons (number :tag "Argument" 1)
1202                        (symbol :tag "Charset")))
1203   :group 'gnus-charset)
1204
1205 (defcustom gnus-preserve-marks t
1206   "Whether marks are preserved when moving, copying and respooling messages."
1207   :version "21.1"
1208   :type 'boolean
1209   :group 'gnus-summary-marks)
1210
1211 (defcustom gnus-alter-articles-to-read-function nil
1212   "Function to be called to alter the list of articles to be selected."
1213   :type '(choice (const nil) function)
1214   :group 'gnus-summary)
1215
1216 (defcustom gnus-orphan-score nil
1217   "*All orphans get this score added.  Set in the score file."
1218   :group 'gnus-score-default
1219   :type '(choice (const nil)
1220                  integer))
1221
1222 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1223   "*A regexp to match MIME parts when saving multiple parts of a
1224 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1225 This regexp will be used by default when prompting the user for which
1226 type of files to save."
1227   :group 'gnus-summary
1228   :type 'regexp)
1229
1230 (defcustom gnus-read-all-available-headers nil
1231   "Whether Gnus should parse all headers made available to it.
1232 This is mostly relevant for slow back ends where the user may
1233 wish to widen the summary buffer to include all headers
1234 that were fetched.  Say, for nnultimate groups."
1235   :version "22.1"
1236   :group 'gnus-summary
1237   :type '(choice boolean regexp))
1238
1239 (defcustom gnus-summary-muttprint-program "muttprint"
1240   "Command (and optional arguments) used to run Muttprint."
1241   :version "22.1"
1242   :group 'gnus-summary
1243   :type 'string)
1244
1245 (defcustom gnus-article-loose-mime t
1246   "If non-nil, don't require MIME-Version header.
1247 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1248 supply the MIME-Version header or deliberately strip it from the mail.
1249 If non-nil (the default), Gnus will treat some articles as MIME
1250 even if the MIME-Version header is missing."
1251   :version "22.1"
1252   :type 'boolean
1253   :group 'gnus-article-mime)
1254
1255 (defcustom gnus-article-emulate-mime t
1256   "If non-nil, use MIME emulation for uuencode and the like.
1257 This means that Gnus will search message bodies for text that look
1258 like uuencoded bits, yEncoded bits, and so on, and present that using
1259 the normal Gnus MIME machinery."
1260   :version "22.1"
1261   :type 'boolean
1262   :group 'gnus-article-mime)
1263
1264 ;;; Internal variables
1265
1266 (defvar gnus-summary-display-cache nil)
1267 (defvar gnus-article-mime-handles nil)
1268 (defvar gnus-article-decoded-p nil)
1269 (defvar gnus-article-charset nil)
1270 (defvar gnus-article-ignored-charsets nil)
1271 (defvar gnus-scores-exclude-files nil)
1272 (defvar gnus-page-broken nil)
1273
1274 (defvar gnus-original-article nil)
1275 (defvar gnus-article-internal-prepare-hook nil)
1276 (defvar gnus-newsgroup-process-stack nil)
1277
1278 (defvar gnus-thread-indent-array nil)
1279 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1280 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1281   "Function called to sort the articles within a thread after it has been gathered together.")
1282
1283 (defvar gnus-summary-save-parts-type-history nil)
1284 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1285
1286 ;; Avoid highlighting in kill files.
1287 (defvar gnus-summary-inhibit-highlight nil)
1288 (defvar gnus-newsgroup-selected-overlay nil)
1289 (defvar gnus-inhibit-limiting nil)
1290 (defvar gnus-newsgroup-adaptive-score-file nil)
1291 (defvar gnus-current-score-file nil)
1292 (defvar gnus-current-move-group nil)
1293 (defvar gnus-current-copy-group nil)
1294 (defvar gnus-current-crosspost-group nil)
1295 (defvar gnus-newsgroup-display nil)
1296
1297 (defvar gnus-newsgroup-dependencies nil)
1298 (defvar gnus-newsgroup-adaptive nil)
1299 (defvar gnus-summary-display-article-function nil)
1300 (defvar gnus-summary-highlight-line-function nil
1301   "Function called after highlighting a summary line.")
1302
1303 (defvar gnus-summary-line-format-alist
1304   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1305     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1306     (?s gnus-tmp-subject-or-nil ?s)
1307     (?n gnus-tmp-name ?s)
1308     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1309         ?s)
1310     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1311             gnus-tmp-from) ?s)
1312     (?F gnus-tmp-from ?s)
1313     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1314     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1315     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1316     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1317     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1318     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1319     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1320     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1321     (?L gnus-tmp-lines ?s)
1322     (?O gnus-tmp-downloaded ?c)
1323     (?I gnus-tmp-indentation ?s)
1324     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1325     (?R gnus-tmp-replied ?c)
1326     (?\[ gnus-tmp-opening-bracket ?c)
1327     (?\] gnus-tmp-closing-bracket ?c)
1328     (?\> (make-string gnus-tmp-level ? ) ?s)
1329     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1330     (?i gnus-tmp-score ?d)
1331     (?z gnus-tmp-score-char ?c)
1332     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1333     (?U gnus-tmp-unread ?c)
1334     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1335         ?s)
1336     (?t (gnus-summary-number-of-articles-in-thread
1337          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1338         ?d)
1339     (?e (gnus-summary-number-of-articles-in-thread
1340          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1341         ?c)
1342     (?u gnus-tmp-user-defined ?s)
1343     (?P (gnus-pick-line-number) ?d)
1344     (?B gnus-tmp-thread-tree-header-string ?s)
1345     (user-date (gnus-user-date
1346                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1347   "An alist of format specifications that can appear in summary lines.
1348 These are paired with what variables they correspond with, along with
1349 the type of the variable (string, integer, character, etc).")
1350
1351 (defvar gnus-summary-dummy-line-format-alist
1352   `((?S gnus-tmp-subject ?s)
1353     (?N gnus-tmp-number ?d)
1354     (?u gnus-tmp-user-defined ?s)))
1355
1356 (defvar gnus-summary-mode-line-format-alist
1357   `((?G gnus-tmp-group-name ?s)
1358     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1359     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1360     (?A gnus-tmp-article-number ?d)
1361     (?Z gnus-tmp-unread-and-unselected ?s)
1362     (?V gnus-version ?s)
1363     (?U gnus-tmp-unread-and-unticked ?d)
1364     (?S gnus-tmp-subject ?s)
1365     (?e gnus-tmp-unselected ?d)
1366     (?u gnus-tmp-user-defined ?s)
1367     (?d (length gnus-newsgroup-dormant) ?d)
1368     (?t (length gnus-newsgroup-marked) ?d)
1369     (?h (length gnus-newsgroup-spam-marked) ?d)
1370     (?r (length gnus-newsgroup-reads) ?d)
1371     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1372     (?E gnus-newsgroup-expunged-tally ?d)
1373     (?s (gnus-current-score-file-nondirectory) ?s)))
1374
1375 (defvar gnus-last-search-regexp nil
1376   "Default regexp for article search command.")
1377
1378 (defvar gnus-last-shell-command nil
1379   "Default shell command on article.")
1380
1381 (defvar gnus-newsgroup-agentized nil
1382   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1383 (defvar gnus-newsgroup-begin nil)
1384 (defvar gnus-newsgroup-end nil)
1385 (defvar gnus-newsgroup-last-rmail nil)
1386 (defvar gnus-newsgroup-last-mail nil)
1387 (defvar gnus-newsgroup-last-folder nil)
1388 (defvar gnus-newsgroup-last-file nil)
1389 (defvar gnus-newsgroup-last-directory nil)
1390 (defvar gnus-newsgroup-auto-expire nil)
1391 (defvar gnus-newsgroup-active nil)
1392
1393 (defvar gnus-newsgroup-data nil)
1394 (defvar gnus-newsgroup-data-reverse nil)
1395 (defvar gnus-newsgroup-limit nil)
1396 (defvar gnus-newsgroup-limits nil)
1397 (defvar gnus-summary-use-undownloaded-faces nil)
1398
1399 (defvar gnus-newsgroup-unreads nil
1400   "Sorted list of unread articles in the current newsgroup.")
1401
1402 (defvar gnus-newsgroup-unselected nil
1403   "Sorted list of unselected unread articles in the current newsgroup.")
1404
1405 (defvar gnus-newsgroup-reads nil
1406   "Alist of read articles and article marks in the current newsgroup.")
1407
1408 (defvar gnus-newsgroup-expunged-tally nil)
1409
1410 (defvar gnus-newsgroup-marked nil
1411   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1412
1413 (defvar gnus-newsgroup-spam-marked nil
1414   "List of ranges of articles that have been marked as spam.")
1415
1416 (defvar gnus-newsgroup-killed nil
1417   "List of ranges of articles that have been through the scoring process.")
1418
1419 (defvar gnus-newsgroup-cached nil
1420   "Sorted list of articles that come from the article cache.")
1421
1422 (defvar gnus-newsgroup-saved nil
1423   "List of articles that have been saved.")
1424
1425 (defvar gnus-newsgroup-kill-headers nil)
1426
1427 (defvar gnus-newsgroup-replied nil
1428   "List of articles that have been replied to in the current newsgroup.")
1429
1430 (defvar gnus-newsgroup-forwarded nil
1431   "List of articles that have been forwarded in the current newsgroup.")
1432
1433 (defvar gnus-newsgroup-recent nil
1434   "List of articles that have are recent in the current newsgroup.")
1435
1436 (defvar gnus-newsgroup-expirable nil
1437   "Sorted list of articles in the current newsgroup that can be expired.")
1438
1439 (defvar gnus-newsgroup-processable nil
1440   "List of articles in the current newsgroup that can be processed.")
1441
1442 (defvar gnus-newsgroup-downloadable nil
1443   "Sorted list of articles in the current newsgroup that can be processed.")
1444
1445 (defvar gnus-newsgroup-unfetched nil
1446   "Sorted list of articles in the current newsgroup whose headers have
1447 not been fetched into the agent.
1448
1449 This list will always be a subset of gnus-newsgroup-undownloaded.")
1450
1451 (defvar gnus-newsgroup-undownloaded nil
1452   "List of articles in the current newsgroup that haven't been downloaded.")
1453
1454 (defvar gnus-newsgroup-unsendable nil
1455   "List of articles in the current newsgroup that won't be sent.")
1456
1457 (defvar gnus-newsgroup-bookmarks nil
1458   "List of articles in the current newsgroup that have bookmarks.")
1459
1460 (defvar gnus-newsgroup-dormant nil
1461   "Sorted list of dormant articles in the current newsgroup.")
1462
1463 (defvar gnus-newsgroup-unseen nil
1464   "List of unseen articles in the current newsgroup.")
1465
1466 (defvar gnus-newsgroup-seen nil
1467   "Range of seen articles in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-articles nil
1470   "List of articles in the current newsgroup.")
1471
1472 (defvar gnus-newsgroup-scored nil
1473   "List of scored articles in the current newsgroup.")
1474
1475 (defvar gnus-newsgroup-headers nil
1476   "List of article headers in the current newsgroup.")
1477
1478 (defvar gnus-newsgroup-threads nil)
1479
1480 (defvar gnus-newsgroup-prepared nil
1481   "Whether the current group has been prepared properly.")
1482
1483 (defvar gnus-newsgroup-ancient nil
1484   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1485
1486 (defvar gnus-newsgroup-sparse nil)
1487
1488 (defvar gnus-current-article nil)
1489 (defvar gnus-article-current nil)
1490 (defvar gnus-current-headers nil)
1491 (defvar gnus-have-all-headers nil)
1492 (defvar gnus-last-article nil)
1493 (defvar gnus-newsgroup-history nil)
1494 (defvar gnus-newsgroup-charset nil)
1495 (defvar gnus-newsgroup-ephemeral-charset nil)
1496 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1497
1498 (defvar gnus-article-before-search nil)
1499
1500 (defvar gnus-summary-local-variables
1501   '(gnus-newsgroup-name
1502     gnus-newsgroup-begin gnus-newsgroup-end
1503     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1504     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1505     gnus-newsgroup-last-directory
1506     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1507     gnus-newsgroup-unselected gnus-newsgroup-marked
1508     gnus-newsgroup-spam-marked
1509     gnus-newsgroup-reads gnus-newsgroup-saved
1510     gnus-newsgroup-replied gnus-newsgroup-forwarded
1511     gnus-newsgroup-recent
1512     gnus-newsgroup-expirable
1513     gnus-newsgroup-processable gnus-newsgroup-killed
1514     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1515     gnus-newsgroup-unfetched
1516     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1517     gnus-newsgroup-seen gnus-newsgroup-articles
1518     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1519     gnus-newsgroup-headers gnus-newsgroup-threads
1520     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1521     gnus-current-article gnus-current-headers gnus-have-all-headers
1522     gnus-last-article gnus-article-internal-prepare-hook
1523     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1524     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1525     gnus-thread-expunge-below
1526     gnus-score-alist gnus-current-score-file
1527     (gnus-summary-expunge-below . global)
1528     (gnus-summary-mark-below . global)
1529     (gnus-orphan-score . global)
1530     gnus-newsgroup-active gnus-scores-exclude-files
1531     gnus-newsgroup-history gnus-newsgroup-ancient
1532     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1533     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1534     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1535     (gnus-newsgroup-expunged-tally . 0)
1536     gnus-cache-removable-articles gnus-newsgroup-cached
1537     gnus-newsgroup-data gnus-newsgroup-data-reverse
1538     gnus-newsgroup-limit gnus-newsgroup-limits
1539     gnus-newsgroup-charset gnus-newsgroup-display
1540     gnus-summary-use-undownloaded-faces)
1541   "Variables that are buffer-local to the summary buffers.")
1542
1543 (defvar gnus-newsgroup-variables nil
1544   "A list of variables that have separate values in different newsgroups.
1545 A list of newsgroup (summary buffer) local variables, or cons of
1546 variables and their default expressions to be evalled (when the default
1547 values are not nil), that should be made global while the summary buffer
1548 is active.
1549
1550 Note: The default expressions will be evaluated (using function `eval')
1551 before assignment to the local variable rather than just assigned to it.
1552 If the default expression is the symbol `global', that symbol will not
1553 be evaluated but the global value of the local variable will be used
1554 instead.
1555
1556 These variables can be used to set variables in the group parameters
1557 while still allowing them to affect operations done in other buffers.
1558 For example:
1559
1560 \(setq gnus-newsgroup-variables
1561      '(message-use-followup-to
1562        (gnus-visible-headers .
1563          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1564 ")
1565
1566 ;; Byte-compiler warning.  Specifically, this is responsible for:
1567 ;; "Warning: the following functions might not be defined at runtime:
1568 ;; gnus-build-sparse-threads, gnus-dead-summary-mode, gnus-summary-mark-below".
1569 (eval-when-compile
1570   ;; Bind features so that require will believe that gnus-sum has
1571   ;; already been loaded (avoids infinite recursion)
1572   (let ((features (cons 'gnus-sum features)))
1573     ;; Several of the declarations in gnus-sum are needed to load the
1574     ;; following files. Right now, these definitions have been
1575     ;; compiled but not defined (evaluated).  We could either do a
1576     ;; eval-and-compile about all of the declarations or evaluate the
1577     ;; source file.
1578     (if (boundp 'gnus-newsgroup-variables)
1579         nil
1580       (load "gnus-sum.el" t t t))
1581     (require 'gnus)
1582     (require 'gnus-art)))
1583
1584 ;; MIME stuff.
1585
1586 (defvar gnus-decode-encoded-word-methods
1587   '(mail-decode-encoded-word-string)
1588   "List of methods used to decode encoded words.
1589
1590 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1591 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1592 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1593 whose names match REGEXP.
1594
1595 For example:
1596 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1597  mail-decode-encoded-word-string
1598  (\"chinese\" . rfc1843-decode-string))")
1599
1600 (defvar gnus-decode-encoded-word-methods-cache nil)
1601
1602 (defun gnus-multi-decode-encoded-word-string (string)
1603   "Apply the functions from `gnus-encoded-word-methods' that match."
1604   (unless (and gnus-decode-encoded-word-methods-cache
1605                (eq gnus-newsgroup-name
1606                    (car gnus-decode-encoded-word-methods-cache)))
1607     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1608     (dolist (method gnus-decode-encoded-word-methods)
1609       (if (symbolp method)
1610           (nconc gnus-decode-encoded-word-methods-cache (list method))
1611         (if (and gnus-newsgroup-name
1612                  (string-match (car method) gnus-newsgroup-name))
1613             (nconc gnus-decode-encoded-word-methods-cache
1614                    (list (cdr method)))))))
1615   (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1616     (setq string (funcall method string))))
1617
1618 ;; Subject simplification.
1619
1620 (defun gnus-simplify-whitespace (str)
1621   "Remove excessive whitespace from STR."
1622   ;; Multiple spaces.
1623   (while (string-match "[ \t][ \t]+" str)
1624     (setq str (concat (substring str 0 (match-beginning 0))
1625                         " "
1626                         (substring str (match-end 0)))))
1627   ;; Leading spaces.
1628   (when (string-match "^[ \t]+" str)
1629     (setq str (substring str (match-end 0))))
1630   ;; Trailing spaces.
1631   (when (string-match "[ \t]+$" str)
1632     (setq str (substring str 0 (match-beginning 0))))
1633   str)
1634
1635 (defun gnus-simplify-all-whitespace (str)
1636   "Remove all whitespace from STR."
1637   (while (string-match "[ \t\n]+" str)
1638     (setq str (replace-match "" nil nil str)))
1639   str)
1640
1641 (defsubst gnus-simplify-subject-re (subject)
1642   "Remove \"Re:\" from subject lines."
1643   (if (string-match message-subject-re-regexp subject)
1644       (substring subject (match-end 0))
1645     subject))
1646
1647 (defun gnus-simplify-subject (subject &optional re-only)
1648   "Remove `Re:' and words in parentheses.
1649 If RE-ONLY is non-nil, strip leading `Re:'s only."
1650   (let ((case-fold-search t))           ;Ignore case.
1651     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1652     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1653       (setq subject (substring subject (match-end 0))))
1654     ;; Remove uninteresting prefixes.
1655     (when (and (not re-only)
1656                gnus-simplify-ignored-prefixes
1657                (string-match gnus-simplify-ignored-prefixes subject))
1658       (setq subject (substring subject (match-end 0))))
1659     ;; Remove words in parentheses from end.
1660     (unless re-only
1661       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1662         (setq subject (substring subject 0 (match-beginning 0)))))
1663     ;; Return subject string.
1664     subject))
1665
1666 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1667 ;; all whitespace.
1668 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1669   (goto-char (point-min))
1670   (while (re-search-forward regexp nil t)
1671     (replace-match (or newtext ""))))
1672
1673 (defun gnus-simplify-buffer-fuzzy ()
1674   "Simplify string in the buffer fuzzily.
1675 The string in the accessible portion of the current buffer is simplified.
1676 It is assumed to be a single-line subject.
1677 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1678 matter is removed.  Additional things can be deleted by setting
1679 `gnus-simplify-subject-fuzzy-regexp'."
1680   (let ((case-fold-search t)
1681         (modified-tick))
1682     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1683
1684     (while (not (eq modified-tick (buffer-modified-tick)))
1685       (setq modified-tick (buffer-modified-tick))
1686       (cond
1687        ((listp gnus-simplify-subject-fuzzy-regexp)
1688         (mapc 'gnus-simplify-buffer-fuzzy-step
1689               gnus-simplify-subject-fuzzy-regexp))
1690        (gnus-simplify-subject-fuzzy-regexp
1691         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1692       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1693       (gnus-simplify-buffer-fuzzy-step
1694        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1695       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1696
1697     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1698     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1699     (gnus-simplify-buffer-fuzzy-step " $")
1700     (gnus-simplify-buffer-fuzzy-step "^ +")))
1701
1702 (defun gnus-simplify-subject-fuzzy (subject)
1703   "Simplify a subject string fuzzily.
1704 See `gnus-simplify-buffer-fuzzy' for details."
1705   (save-excursion
1706     (gnus-set-work-buffer)
1707     (let ((case-fold-search t))
1708       ;; Remove uninteresting prefixes.
1709       (when (and gnus-simplify-ignored-prefixes
1710                  (string-match gnus-simplify-ignored-prefixes subject))
1711         (setq subject (substring subject (match-end 0))))
1712       (insert subject)
1713       (inline (gnus-simplify-buffer-fuzzy))
1714       (buffer-string))))
1715
1716 (defsubst gnus-simplify-subject-fully (subject)
1717   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1718   (cond
1719    (gnus-simplify-subject-functions
1720     (gnus-map-function gnus-simplify-subject-functions subject))
1721    ((null gnus-summary-gather-subject-limit)
1722     (gnus-simplify-subject-re subject))
1723    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1724     (gnus-simplify-subject-fuzzy subject))
1725    ((numberp gnus-summary-gather-subject-limit)
1726     (truncate-string-to-width (gnus-simplify-subject-re subject)
1727                               gnus-summary-gather-subject-limit))
1728    (t
1729     subject)))
1730
1731 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1732   "Check whether two subjects are equal.
1733 If optional argument SIMPLE-FIRST is t, first argument is already
1734 simplified."
1735   (cond
1736    ((null simple-first)
1737     (equal (gnus-simplify-subject-fully s1)
1738            (gnus-simplify-subject-fully s2)))
1739    (t
1740     (equal s1
1741            (gnus-simplify-subject-fully s2)))))
1742
1743 (defun gnus-summary-bubble-group ()
1744   "Increase the score of the current group.
1745 This is a handy function to add to `gnus-summary-exit-hook' to
1746 increase the score of each group you read."
1747   (gnus-group-add-score gnus-newsgroup-name))
1748
1749 \f
1750 ;;;
1751 ;;; Gnus summary mode
1752 ;;;
1753
1754 (put 'gnus-summary-mode 'mode-class 'special)
1755
1756 (defvar gnus-article-commands-menu)
1757
1758 ;; Non-orthogonal keys
1759
1760 (gnus-define-keys gnus-summary-mode-map
1761   " " gnus-summary-next-page
1762   "\177" gnus-summary-prev-page
1763   [delete] gnus-summary-prev-page
1764   [backspace] gnus-summary-prev-page
1765   "\r" gnus-summary-scroll-up
1766   "\M-\r" gnus-summary-scroll-down
1767   "n" gnus-summary-next-unread-article
1768   "p" gnus-summary-prev-unread-article
1769   "N" gnus-summary-next-article
1770   "P" gnus-summary-prev-article
1771   "\M-\C-n" gnus-summary-next-same-subject
1772   "\M-\C-p" gnus-summary-prev-same-subject
1773   "\M-n" gnus-summary-next-unread-subject
1774   "\M-p" gnus-summary-prev-unread-subject
1775   "." gnus-summary-first-unread-article
1776   "," gnus-summary-best-unread-article
1777   "\M-s" gnus-summary-search-article-forward
1778   "\M-r" gnus-summary-search-article-backward
1779   "\M-S" gnus-summary-repeat-search-article-forward
1780   "\M-R" gnus-summary-repeat-search-article-backward
1781   "<" gnus-summary-beginning-of-article
1782   ">" gnus-summary-end-of-article
1783   "j" gnus-summary-goto-article
1784   "^" gnus-summary-refer-parent-article
1785   "\M-^" gnus-summary-refer-article
1786   "u" gnus-summary-tick-article-forward
1787   "!" gnus-summary-tick-article-forward
1788   "U" gnus-summary-tick-article-backward
1789   "d" gnus-summary-mark-as-read-forward
1790   "D" gnus-summary-mark-as-read-backward
1791   "E" gnus-summary-mark-as-expirable
1792   "\M-u" gnus-summary-clear-mark-forward
1793   "\M-U" gnus-summary-clear-mark-backward
1794   "k" gnus-summary-kill-same-subject-and-select
1795   "\C-k" gnus-summary-kill-same-subject
1796   "\M-\C-k" gnus-summary-kill-thread
1797   "\M-\C-l" gnus-summary-lower-thread
1798   "e" gnus-summary-edit-article
1799   "#" gnus-summary-mark-as-processable
1800   "\M-#" gnus-summary-unmark-as-processable
1801   "\M-\C-t" gnus-summary-toggle-threads
1802   "\M-\C-s" gnus-summary-show-thread
1803   "\M-\C-h" gnus-summary-hide-thread
1804   "\M-\C-f" gnus-summary-next-thread
1805   "\M-\C-b" gnus-summary-prev-thread
1806   [(meta down)] gnus-summary-next-thread
1807   [(meta up)] gnus-summary-prev-thread
1808   "\M-\C-u" gnus-summary-up-thread
1809   "\M-\C-d" gnus-summary-down-thread
1810   "&" gnus-summary-execute-command
1811   "c" gnus-summary-catchup-and-exit
1812   "\C-w" gnus-summary-mark-region-as-read
1813   "\C-t" gnus-summary-toggle-truncation
1814   "?" gnus-summary-mark-as-dormant
1815   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1816   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1817   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1818   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1819   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1820   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1821   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1822   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1823   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1824   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1825   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1826   "=" gnus-summary-expand-window
1827   "\C-x\C-s" gnus-summary-reselect-current-group
1828   "\M-g" gnus-summary-rescan-group
1829   "w" gnus-summary-stop-page-breaking
1830   "\C-c\C-r" gnus-summary-caesar-message
1831   "f" gnus-summary-followup
1832   "F" gnus-summary-followup-with-original
1833   "C" gnus-summary-cancel-article
1834   "r" gnus-summary-reply
1835   "R" gnus-summary-reply-with-original
1836   "\C-c\C-f" gnus-summary-mail-forward
1837   "o" gnus-summary-save-article
1838   "\C-o" gnus-summary-save-article-mail
1839   "|" gnus-summary-pipe-output
1840   "\M-k" gnus-summary-edit-local-kill
1841   "\M-K" gnus-summary-edit-global-kill
1842   ;; "V" gnus-version
1843   "\C-c\C-d" gnus-summary-describe-group
1844   "q" gnus-summary-exit
1845   "Q" gnus-summary-exit-no-update
1846   "\C-c\C-i" gnus-info-find-node
1847   gnus-mouse-2 gnus-mouse-pick-article
1848   [follow-link] mouse-face
1849   "m" gnus-summary-mail-other-window
1850   "a" gnus-summary-post-news
1851   "i" gnus-summary-news-other-window
1852   "x" gnus-summary-limit-to-unread
1853   "s" gnus-summary-isearch-article
1854   "t" gnus-summary-toggle-header
1855   "g" gnus-summary-show-article
1856   "l" gnus-summary-goto-last-article
1857   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1858   "\C-d" gnus-summary-enter-digest-group
1859   "\M-\C-d" gnus-summary-read-document
1860   "\M-\C-e" gnus-summary-edit-parameters
1861   "\M-\C-a" gnus-summary-customize-parameters
1862   "\C-c\C-b" gnus-bug
1863   "*" gnus-cache-enter-article
1864   "\M-*" gnus-cache-remove-article
1865   "\M-&" gnus-summary-universal-argument
1866   "\C-l" gnus-recenter
1867   "I" gnus-summary-increase-score
1868   "L" gnus-summary-lower-score
1869   "\M-i" gnus-symbolic-argument
1870   "h" gnus-summary-select-article-buffer
1871
1872   "b" gnus-article-view-part
1873   "\M-t" gnus-summary-toggle-display-buttonized
1874
1875   "V" gnus-summary-score-map
1876   "X" gnus-uu-extract-map
1877   "S" gnus-summary-send-map)
1878
1879 ;; Sort of orthogonal keymap
1880 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1881   "t" gnus-summary-tick-article-forward
1882   "!" gnus-summary-tick-article-forward
1883   "d" gnus-summary-mark-as-read-forward
1884   "r" gnus-summary-mark-as-read-forward
1885   "c" gnus-summary-clear-mark-forward
1886   " " gnus-summary-clear-mark-forward
1887   "e" gnus-summary-mark-as-expirable
1888   "x" gnus-summary-mark-as-expirable
1889   "?" gnus-summary-mark-as-dormant
1890   "b" gnus-summary-set-bookmark
1891   "B" gnus-summary-remove-bookmark
1892   "#" gnus-summary-mark-as-processable
1893   "\M-#" gnus-summary-unmark-as-processable
1894   "S" gnus-summary-limit-include-expunged
1895   "C" gnus-summary-catchup
1896   "H" gnus-summary-catchup-to-here
1897   "h" gnus-summary-catchup-from-here
1898   "\C-c" gnus-summary-catchup-all
1899   "k" gnus-summary-kill-same-subject-and-select
1900   "K" gnus-summary-kill-same-subject
1901   "P" gnus-uu-mark-map)
1902
1903 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1904   "c" gnus-summary-clear-above
1905   "u" gnus-summary-tick-above
1906   "m" gnus-summary-mark-above
1907   "k" gnus-summary-kill-below)
1908
1909 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1910   "/" gnus-summary-limit-to-subject
1911   "n" gnus-summary-limit-to-articles
1912   "b" gnus-summary-limit-to-bodies
1913   "h" gnus-summary-limit-to-headers
1914   "w" gnus-summary-pop-limit
1915   "s" gnus-summary-limit-to-subject
1916   "a" gnus-summary-limit-to-author
1917   "u" gnus-summary-limit-to-unread
1918   "m" gnus-summary-limit-to-marks
1919   "M" gnus-summary-limit-exclude-marks
1920   "v" gnus-summary-limit-to-score
1921   "*" gnus-summary-limit-include-cached
1922   "D" gnus-summary-limit-include-dormant
1923   "T" gnus-summary-limit-include-thread
1924   "d" gnus-summary-limit-exclude-dormant
1925   "t" gnus-summary-limit-to-age
1926   "." gnus-summary-limit-to-unseen
1927   "x" gnus-summary-limit-to-extra
1928   "p" gnus-summary-limit-to-display-predicate
1929   "E" gnus-summary-limit-include-expunged
1930   "c" gnus-summary-limit-exclude-childless-dormant
1931   "C" gnus-summary-limit-mark-excluded-as-read
1932   "o" gnus-summary-insert-old-articles
1933   "N" gnus-summary-insert-new-articles
1934   "S" gnus-summary-limit-to-singletons
1935   "r" gnus-summary-limit-to-replied
1936   "R" gnus-summary-limit-to-recipient
1937   "A" gnus-summary-limit-to-address)
1938
1939 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1940   "n" gnus-summary-next-unread-article
1941   "p" gnus-summary-prev-unread-article
1942   "N" gnus-summary-next-article
1943   "P" gnus-summary-prev-article
1944   "\C-n" gnus-summary-next-same-subject
1945   "\C-p" gnus-summary-prev-same-subject
1946   "\M-n" gnus-summary-next-unread-subject
1947   "\M-p" gnus-summary-prev-unread-subject
1948   "f" gnus-summary-first-unread-article
1949   "b" gnus-summary-best-unread-article
1950   "j" gnus-summary-goto-article
1951   "g" gnus-summary-goto-subject
1952   "l" gnus-summary-goto-last-article
1953   "o" gnus-summary-pop-article)
1954
1955 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1956   "k" gnus-summary-kill-thread
1957   "E" gnus-summary-expire-thread
1958   "l" gnus-summary-lower-thread
1959   "i" gnus-summary-raise-thread
1960   "T" gnus-summary-toggle-threads
1961   "t" gnus-summary-rethread-current
1962   "^" gnus-summary-reparent-thread
1963   "\M-^" gnus-summary-reparent-children
1964   "s" gnus-summary-show-thread
1965   "S" gnus-summary-show-all-threads
1966   "h" gnus-summary-hide-thread
1967   "H" gnus-summary-hide-all-threads
1968   "n" gnus-summary-next-thread
1969   "p" gnus-summary-prev-thread
1970   "u" gnus-summary-up-thread
1971   "o" gnus-summary-top-thread
1972   "d" gnus-summary-down-thread
1973   "#" gnus-uu-mark-thread
1974   "\M-#" gnus-uu-unmark-thread)
1975
1976 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1977   "g" gnus-summary-prepare
1978   "c" gnus-summary-insert-cached-articles
1979   "d" gnus-summary-insert-dormant-articles
1980   "t" gnus-summary-insert-ticked-articles)
1981
1982 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1983   "c" gnus-summary-catchup-and-exit
1984   "C" gnus-summary-catchup-all-and-exit
1985   "E" gnus-summary-exit-no-update
1986   "Q" gnus-summary-exit
1987   "Z" gnus-summary-exit
1988   "n" gnus-summary-catchup-and-goto-next-group
1989   "p" gnus-summary-catchup-and-goto-prev-group
1990   "R" gnus-summary-reselect-current-group
1991   "G" gnus-summary-rescan-group
1992   "N" gnus-summary-next-group
1993   "s" gnus-summary-save-newsrc
1994   "P" gnus-summary-prev-group)
1995
1996 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1997   " " gnus-summary-next-page
1998   "n" gnus-summary-next-page
1999   "\177" gnus-summary-prev-page
2000   [delete] gnus-summary-prev-page
2001   "p" gnus-summary-prev-page
2002   "\r" gnus-summary-scroll-up
2003   "\M-\r" gnus-summary-scroll-down
2004   "<" gnus-summary-beginning-of-article
2005   ">" gnus-summary-end-of-article
2006   "b" gnus-summary-beginning-of-article
2007   "e" gnus-summary-end-of-article
2008   "^" gnus-summary-refer-parent-article
2009   "r" gnus-summary-refer-parent-article
2010   "D" gnus-summary-enter-digest-group
2011   "R" gnus-summary-refer-references
2012   "T" gnus-summary-refer-thread
2013   "g" gnus-summary-show-article
2014   "s" gnus-summary-isearch-article
2015   "P" gnus-summary-print-article
2016   "S" gnus-sticky-article
2017   "M" gnus-mailing-list-insinuate
2018   "t" gnus-article-babel)
2019
2020 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2021   "b" gnus-article-add-buttons
2022   "B" gnus-article-add-buttons-to-head
2023   "o" gnus-article-treat-overstrike
2024   "e" gnus-article-emphasize
2025   "w" gnus-article-fill-cited-article
2026   "Q" gnus-article-fill-long-lines
2027   "L" gnus-article-toggle-truncate-lines
2028   "C" gnus-article-capitalize-sentences
2029   "c" gnus-article-remove-cr
2030   "q" gnus-article-de-quoted-unreadable
2031   "6" gnus-article-de-base64-unreadable
2032   "Z" gnus-article-decode-HZ
2033   "A" gnus-article-treat-ansi-sequences
2034   "h" gnus-article-wash-html
2035   "u" gnus-article-unsplit-urls
2036   "s" gnus-summary-force-verify-and-decrypt
2037   "f" gnus-article-display-x-face
2038   "l" gnus-summary-stop-page-breaking
2039   "r" gnus-summary-caesar-message
2040   "m" gnus-summary-morse-message
2041   "t" gnus-summary-toggle-header
2042   "g" gnus-treat-smiley
2043   "v" gnus-summary-verbose-headers
2044   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2045   "p" gnus-article-verify-x-pgp-sig
2046   "d" gnus-article-treat-dumbquotes
2047   "i" gnus-summary-idna-message)
2048
2049 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2050   ;; mnemonic: deuglif*Y*
2051   "u" gnus-article-outlook-unwrap-lines
2052   "a" gnus-article-outlook-repair-attribution
2053   "c" gnus-article-outlook-rearrange-citation
2054   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2055
2056 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2057   "a" gnus-article-hide
2058   "h" gnus-article-hide-headers
2059   "b" gnus-article-hide-boring-headers
2060   "s" gnus-article-hide-signature
2061   "c" gnus-article-hide-citation
2062   "C" gnus-article-hide-citation-in-followups
2063   "l" gnus-article-hide-list-identifiers
2064   "B" gnus-article-strip-banner
2065   "P" gnus-article-hide-pem
2066   "\C-c" gnus-article-hide-citation-maybe)
2067
2068 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2069   "a" gnus-article-highlight
2070   "h" gnus-article-highlight-headers
2071   "c" gnus-article-highlight-citation
2072   "s" gnus-article-highlight-signature)
2073
2074 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2075   "f" gnus-article-treat-fold-headers
2076   "u" gnus-article-treat-unfold-headers
2077   "n" gnus-article-treat-fold-newsgroups)
2078
2079 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2080   "x" gnus-article-display-x-face
2081   "d" gnus-article-display-face
2082   "s" gnus-treat-smiley
2083   "D" gnus-article-remove-images
2084   "f" gnus-treat-from-picon
2085   "m" gnus-treat-mail-picon
2086   "n" gnus-treat-newsgroups-picon)
2087
2088 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2089   "w" gnus-article-decode-mime-words
2090   "c" gnus-article-decode-charset
2091   "v" gnus-mime-view-all-parts
2092   "b" gnus-article-view-part)
2093
2094 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2095   "z" gnus-article-date-ut
2096   "u" gnus-article-date-ut
2097   "l" gnus-article-date-local
2098   "p" gnus-article-date-english
2099   "e" gnus-article-date-lapsed
2100   "o" gnus-article-date-original
2101   "i" gnus-article-date-iso8601
2102   "s" gnus-article-date-user)
2103
2104 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2105   "t" gnus-article-remove-trailing-blank-lines
2106   "l" gnus-article-strip-leading-blank-lines
2107   "m" gnus-article-strip-multiple-blank-lines
2108   "a" gnus-article-strip-blank-lines
2109   "A" gnus-article-strip-all-blank-lines
2110   "s" gnus-article-strip-leading-space
2111   "e" gnus-article-strip-trailing-space
2112   "w" gnus-article-remove-leading-whitespace)
2113
2114 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2115   "v" gnus-version
2116   "f" gnus-summary-fetch-faq
2117   "d" gnus-summary-describe-group
2118   "h" gnus-summary-describe-briefly
2119   "i" gnus-info-find-node
2120   "c" gnus-group-fetch-charter
2121   "C" gnus-group-fetch-control)
2122
2123 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2124   "e" gnus-summary-expire-articles
2125   "\M-\C-e" gnus-summary-expire-articles-now
2126   "\177" gnus-summary-delete-article
2127   [delete] gnus-summary-delete-article
2128   [backspace] gnus-summary-delete-article
2129   "m" gnus-summary-move-article
2130   "r" gnus-summary-respool-article
2131   "w" gnus-summary-edit-article
2132   "c" gnus-summary-copy-article
2133   "B" gnus-summary-crosspost-article
2134   "q" gnus-summary-respool-query
2135   "t" gnus-summary-respool-trace
2136   "i" gnus-summary-import-article
2137   "I" gnus-summary-create-article
2138   "p" gnus-summary-article-posted-p)
2139
2140 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2141   "o" gnus-summary-save-article
2142   "m" gnus-summary-save-article-mail
2143   "F" gnus-summary-write-article-file
2144   "r" gnus-summary-save-article-rmail
2145   "f" gnus-summary-save-article-file
2146   "b" gnus-summary-save-article-body-file
2147   "B" gnus-summary-write-article-body-file
2148   "h" gnus-summary-save-article-folder
2149   "v" gnus-summary-save-article-vm
2150   "p" gnus-summary-pipe-output
2151   "P" gnus-summary-muttprint
2152   "s" gnus-soup-add-article)
2153
2154 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2155   "b" gnus-summary-display-buttonized
2156   "m" gnus-summary-repair-multipart
2157   "v" gnus-article-view-part
2158   "o" gnus-article-save-part
2159   "O" gnus-article-save-part-and-strip
2160   "r" gnus-article-replace-part
2161   "d" gnus-article-delete-part
2162   "t" gnus-article-view-part-as-type
2163   "j" gnus-article-jump-to-part
2164   "c" gnus-article-copy-part
2165   "C" gnus-article-view-part-as-charset
2166   "e" gnus-article-view-part-externally
2167   "H" gnus-article-browse-html-article
2168   "E" gnus-article-encrypt-body
2169   "i" gnus-article-inline-part
2170   "|" gnus-article-pipe-part)
2171
2172 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2173   "p" gnus-summary-mark-as-processable
2174   "u" gnus-summary-unmark-as-processable
2175   "U" gnus-summary-unmark-all-processable
2176   "v" gnus-uu-mark-over
2177   "s" gnus-uu-mark-series
2178   "r" gnus-uu-mark-region
2179   "g" gnus-uu-unmark-region
2180   "R" gnus-uu-mark-by-regexp
2181   "G" gnus-uu-unmark-by-regexp
2182   "t" gnus-uu-mark-thread
2183   "T" gnus-uu-unmark-thread
2184   "a" gnus-uu-mark-all
2185   "b" gnus-uu-mark-buffer
2186   "S" gnus-uu-mark-sparse
2187   "k" gnus-summary-kill-process-mark
2188   "y" gnus-summary-yank-process-mark
2189   "w" gnus-summary-save-process-mark
2190   "i" gnus-uu-invert-processable)
2191
2192 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2193   ;;"x" gnus-uu-extract-any
2194   "m" gnus-summary-save-parts
2195   "u" gnus-uu-decode-uu
2196   "U" gnus-uu-decode-uu-and-save
2197   "s" gnus-uu-decode-unshar
2198   "S" gnus-uu-decode-unshar-and-save
2199   "o" gnus-uu-decode-save
2200   "O" gnus-uu-decode-save
2201   "b" gnus-uu-decode-binhex
2202   "B" gnus-uu-decode-binhex
2203   "Y" gnus-uu-decode-yenc
2204   "p" gnus-uu-decode-postscript
2205   "P" gnus-uu-decode-postscript-and-save)
2206
2207 (gnus-define-keys
2208     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2209   "u" gnus-uu-decode-uu-view
2210   "U" gnus-uu-decode-uu-and-save-view
2211   "s" gnus-uu-decode-unshar-view
2212   "S" gnus-uu-decode-unshar-and-save-view
2213   "o" gnus-uu-decode-save-view
2214   "O" gnus-uu-decode-save-view
2215   "b" gnus-uu-decode-binhex-view
2216   "B" gnus-uu-decode-binhex-view
2217   "p" gnus-uu-decode-postscript-view
2218   "P" gnus-uu-decode-postscript-and-save-view)
2219
2220 (defvar gnus-article-post-menu nil)
2221
2222 (defconst gnus-summary-menu-maxlen 20)
2223
2224 (defun gnus-summary-menu-split (menu)
2225   ;; If we have lots of elements, divide them into groups of 20
2226   ;; and make a pane (or submenu) for each one.
2227   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2228       (let ((menu menu) sublists next
2229             (i 1))
2230         (while menu
2231           ;; Pull off the next gnus-summary-menu-maxlen elements
2232           ;; and make them the next element of sublist.
2233           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2234           (if next
2235               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2236                       nil))
2237           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2238                                              (aref (car (last menu)) 0)) menu)
2239                                sublists))
2240           (setq i (1+ i))
2241           (setq menu next))
2242         (nreverse sublists))
2243     ;; Few elements--put them all in one pane.
2244     menu))
2245
2246 (defun gnus-summary-make-menu-bar ()
2247   (gnus-turn-off-edit-menu 'summary)
2248
2249   (unless (boundp 'gnus-summary-misc-menu)
2250
2251     (easy-menu-define
2252       gnus-summary-kill-menu gnus-summary-mode-map ""
2253       (cons
2254        "Score"
2255        (nconc
2256         (list
2257          ["Customize" gnus-score-customize t])
2258         (gnus-make-score-map 'increase)
2259         (gnus-make-score-map 'lower)
2260         '(("Mark"
2261            ["Kill below" gnus-summary-kill-below t]
2262            ["Mark above" gnus-summary-mark-above t]
2263            ["Tick above" gnus-summary-tick-above t]
2264            ["Clear above" gnus-summary-clear-above t])
2265           ["Current score" gnus-summary-current-score t]
2266           ["Set score" gnus-summary-set-score t]
2267           ["Switch current score file..." gnus-score-change-score-file t]
2268           ["Set mark below..." gnus-score-set-mark-below t]
2269           ["Set expunge below..." gnus-score-set-expunge-below t]
2270           ["Edit current score file" gnus-score-edit-current-scores t]
2271           ["Edit score file..." gnus-score-edit-file t]
2272           ["Trace score" gnus-score-find-trace t]
2273           ["Find words" gnus-score-find-favourite-words t]
2274           ["Rescore buffer" gnus-summary-rescore t]
2275           ["Increase score..." gnus-summary-increase-score t]
2276           ["Lower score..." gnus-summary-lower-score t]))))
2277
2278     ;; Define both the Article menu in the summary buffer and the
2279     ;; equivalent Commands menu in the article buffer here for
2280     ;; consistency.
2281     (let ((innards
2282            `(("Hide"
2283               ["All" gnus-article-hide t]
2284               ["Headers" gnus-article-hide-headers t]
2285               ["Signature" gnus-article-hide-signature t]
2286               ["Citation" gnus-article-hide-citation t]
2287               ["List identifiers" gnus-article-hide-list-identifiers t]
2288               ["Banner" gnus-article-strip-banner t]
2289               ["Boring headers" gnus-article-hide-boring-headers t])
2290              ("Highlight"
2291               ["All" gnus-article-highlight t]
2292               ["Headers" gnus-article-highlight-headers t]
2293               ["Signature" gnus-article-highlight-signature t]
2294               ["Citation" gnus-article-highlight-citation t])
2295              ("MIME"
2296               ["Words" gnus-article-decode-mime-words t]
2297               ["Charset" gnus-article-decode-charset t]
2298               ["QP" gnus-article-de-quoted-unreadable t]
2299               ["Base64" gnus-article-de-base64-unreadable t]
2300               ["View MIME buttons" gnus-summary-display-buttonized t]
2301               ["View all" gnus-mime-view-all-parts t]
2302               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2303               ["Encrypt body" gnus-article-encrypt-body
2304                :active (not (gnus-group-read-only-p))
2305                ,@(if (featurep 'xemacs) nil
2306                    '(:help "Encrypt the message body on disk"))]
2307               ["Extract all parts..." gnus-summary-save-parts t]
2308               ("Multipart"
2309                ["Repair multipart" gnus-summary-repair-multipart t]
2310                ["Pipe part..." gnus-article-pipe-part t]
2311                ["Inline part" gnus-article-inline-part t]
2312                ["View part as type..." gnus-article-view-part-as-type t]
2313                ["Encrypt body" gnus-article-encrypt-body
2314                 :active (not (gnus-group-read-only-p))
2315                ,@(if (featurep 'xemacs) nil
2316                    '(:help "Encrypt the message body on disk"))]
2317                ["View part externally" gnus-article-view-part-externally t]
2318                ["View HTML parts in browser" gnus-article-browse-html-article t]
2319                ["View part with charset..." gnus-article-view-part-as-charset t]
2320                ["Copy part" gnus-article-copy-part t]
2321                ["Save part..." gnus-article-save-part t]
2322                ["View part" gnus-article-view-part t]))
2323              ("Date"
2324               ["Local" gnus-article-date-local t]
2325               ["ISO8601" gnus-article-date-iso8601 t]
2326               ["UT" gnus-article-date-ut t]
2327               ["Original" gnus-article-date-original t]
2328               ["Lapsed" gnus-article-date-lapsed t]
2329               ["User-defined" gnus-article-date-user t])
2330              ("Display"
2331               ["Remove images" gnus-article-remove-images t]
2332               ["Toggle smiley" gnus-treat-smiley t]
2333               ["Show X-Face" gnus-article-display-x-face t]
2334               ["Show picons in From" gnus-treat-from-picon t]
2335               ["Show picons in mail headers" gnus-treat-mail-picon t]
2336               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2337               ("View as different encoding"
2338                ,@(gnus-summary-menu-split
2339                   (mapcar
2340                    (lambda (cs)
2341                      ;; Since easymenu under Emacs doesn't allow
2342                      ;; lambda forms for menu commands, we should
2343                      ;; provide intern'ed function symbols.
2344                      (let ((command (intern (format "\
2345 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2346                        (fset command
2347                              `(lambda ()
2348                                 (interactive)
2349                                 (let ((gnus-summary-show-article-charset-alist
2350                                        '((1 . ,cs))))
2351                                   (gnus-summary-show-article 1))))
2352                        `[,(symbol-name cs) ,command t]))
2353                    (sort (if (fboundp 'coding-system-list)
2354                              (coding-system-list)
2355                            (mapcar 'car mm-mime-mule-charset-alist))
2356                          'string<)))))
2357              ("Washing"
2358               ("Remove Blanks"
2359                ["Leading" gnus-article-strip-leading-blank-lines t]
2360                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2361                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2362                ["All of the above" gnus-article-strip-blank-lines t]
2363                ["All" gnus-article-strip-all-blank-lines t]
2364                ["Leading space" gnus-article-strip-leading-space t]
2365                ["Trailing space" gnus-article-strip-trailing-space t]
2366                ["Leading space in headers"
2367                 gnus-article-remove-leading-whitespace t])
2368               ["Overstrike" gnus-article-treat-overstrike t]
2369               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2370               ["Emphasis" gnus-article-emphasize t]
2371               ["Word wrap" gnus-article-fill-cited-article t]
2372               ["Fill long lines" gnus-article-fill-long-lines t]
2373               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2374               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2375               ["Remove CR" gnus-article-remove-cr t]
2376               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2377               ["Base64" gnus-article-de-base64-unreadable t]
2378               ["Rot 13" gnus-summary-caesar-message
2379                ,@(if (featurep 'xemacs) '(t)
2380                    '(:help "\"Caesar rotate\" article by 13"))]
2381               ["De-IDNA" gnus-summary-idna-message t]
2382               ["Morse decode" gnus-summary-morse-message t]
2383               ["Unix pipe..." gnus-summary-pipe-message t]
2384               ["Add buttons" gnus-article-add-buttons t]
2385               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2386               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2387               ["Verbose header" gnus-summary-verbose-headers t]
2388               ["Toggle header" gnus-summary-toggle-header t]
2389               ["Unfold headers" gnus-article-treat-unfold-headers t]
2390               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2391               ["Html" gnus-article-wash-html t]
2392               ["Unsplit URLs" gnus-article-unsplit-urls t]
2393               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2394               ["Decode HZ" gnus-article-decode-HZ t]
2395               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2396               ("(Outlook) Deuglify"
2397                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2398                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2399                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2400                ["Full (Outlook) deuglify"
2401                 gnus-article-outlook-deuglify-article t])
2402               )
2403              ("Output"
2404               ["Save in default format..." gnus-summary-save-article
2405                ,@(if (featurep 'xemacs) '(t)
2406                    '(:help "Save article using default method"))]
2407               ["Save in file..." gnus-summary-save-article-file
2408                ,@(if (featurep 'xemacs) '(t)
2409                    '(:help "Save article in file"))]
2410               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2411               ["Save in MH folder..." gnus-summary-save-article-folder t]
2412               ["Save in VM folder..." gnus-summary-save-article-vm t]
2413               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2414               ["Save body in file..." gnus-summary-save-article-body-file t]
2415               ["Pipe through a filter..." gnus-summary-pipe-output t]
2416               ["Add to SOUP packet" gnus-soup-add-article t]
2417               ["Print with Muttprint..." gnus-summary-muttprint t]
2418               ["Print" gnus-summary-print-article
2419                ,@(if (featurep 'xemacs) '(t)
2420                    '(:help "Generate and print a PostScript image"))])
2421              ("Copy, move,... (Backend)"
2422               ,@(if (featurep 'xemacs) nil
2423                   '(:help "Copying, moving, expiring articles..."))
2424               ["Respool article..." gnus-summary-respool-article t]
2425               ["Move article..." gnus-summary-move-article
2426                (gnus-check-backend-function
2427                 'request-move-article gnus-newsgroup-name)]
2428               ["Copy article..." gnus-summary-copy-article t]
2429               ["Crosspost article..." gnus-summary-crosspost-article
2430                (gnus-check-backend-function
2431                 'request-replace-article gnus-newsgroup-name)]
2432               ["Import file..." gnus-summary-import-article
2433                (gnus-check-backend-function
2434                 'request-accept-article gnus-newsgroup-name)]
2435               ["Create article..." gnus-summary-create-article
2436                (gnus-check-backend-function
2437                 'request-accept-article gnus-newsgroup-name)]
2438               ["Check if posted" gnus-summary-article-posted-p t]
2439               ["Edit article" gnus-summary-edit-article
2440                (not (gnus-group-read-only-p))]
2441               ["Delete article" gnus-summary-delete-article
2442                (gnus-check-backend-function
2443                 'request-expire-articles gnus-newsgroup-name)]
2444               ["Query respool" gnus-summary-respool-query t]
2445               ["Trace respool" gnus-summary-respool-trace t]
2446               ["Delete expirable articles" gnus-summary-expire-articles-now
2447                (gnus-check-backend-function
2448                 'request-expire-articles gnus-newsgroup-name)])
2449              ("Extract"
2450               ["Uudecode" gnus-uu-decode-uu
2451                ,@(if (featurep 'xemacs) '(t)
2452                    '(:help "Decode uuencoded article(s)"))]
2453               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2454               ["Unshar" gnus-uu-decode-unshar t]
2455               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2456               ["Save" gnus-uu-decode-save t]
2457               ["Binhex" gnus-uu-decode-binhex t]
2458               ["Postscript" gnus-uu-decode-postscript t]
2459               ["All MIME parts" gnus-summary-save-parts t])
2460              ("Cache"
2461               ["Enter article" gnus-cache-enter-article t]
2462               ["Remove article" gnus-cache-remove-article t])
2463              ["Translate" gnus-article-babel t]
2464              ["Select article buffer" gnus-summary-select-article-buffer t]
2465              ["Make article buffer sticky" gnus-sticky-article t]
2466              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2467              ["Isearch article..." gnus-summary-isearch-article t]
2468              ["Beginning of the article" gnus-summary-beginning-of-article t]
2469              ["End of the article" gnus-summary-end-of-article t]
2470              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2471              ["Fetch referenced articles" gnus-summary-refer-references t]
2472              ["Fetch current thread" gnus-summary-refer-thread t]
2473              ["Fetch article with id..." gnus-summary-refer-article t]
2474              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2475              ["Redisplay" gnus-summary-show-article t]
2476              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2477       (easy-menu-define
2478         gnus-summary-article-menu gnus-summary-mode-map ""
2479         (cons "Article" innards))
2480
2481       (if (not (keymapp gnus-summary-article-menu))
2482           (easy-menu-define
2483             gnus-article-commands-menu gnus-article-mode-map ""
2484             (cons "Commands" innards))
2485         ;; in Emacs, don't share menu.
2486         (setq gnus-article-commands-menu
2487               (copy-keymap gnus-summary-article-menu))
2488         (define-key gnus-article-mode-map [menu-bar commands]
2489           (cons "Commands" gnus-article-commands-menu))))
2490
2491     (easy-menu-define
2492       gnus-summary-thread-menu gnus-summary-mode-map ""
2493       '("Threads"
2494         ["Find all messages in thread" gnus-summary-refer-thread t]
2495         ["Toggle threading" gnus-summary-toggle-threads t]
2496         ["Hide threads" gnus-summary-hide-all-threads t]
2497         ["Show threads" gnus-summary-show-all-threads t]
2498         ["Hide thread" gnus-summary-hide-thread t]
2499         ["Show thread" gnus-summary-show-thread t]
2500         ["Go to next thread" gnus-summary-next-thread t]
2501         ["Go to previous thread" gnus-summary-prev-thread t]
2502         ["Go down thread" gnus-summary-down-thread t]
2503         ["Go up thread" gnus-summary-up-thread t]
2504         ["Top of thread" gnus-summary-top-thread t]
2505         ["Mark thread as read" gnus-summary-kill-thread t]
2506         ["Mark thread as expired" gnus-summary-expire-thread t]
2507         ["Lower thread score" gnus-summary-lower-thread t]
2508         ["Raise thread score" gnus-summary-raise-thread t]
2509         ["Rethread current" gnus-summary-rethread-current t]))
2510
2511     (easy-menu-define
2512       gnus-summary-post-menu gnus-summary-mode-map ""
2513       `("Post"
2514         ["Send a message (mail or news)" gnus-summary-post-news
2515          ,@(if (featurep 'xemacs) '(t)
2516              '(:help "Compose a new message (mail or news)"))]
2517         ["Followup" gnus-summary-followup
2518          ,@(if (featurep 'xemacs) '(t)
2519              '(:help "Post followup to this article"))]
2520         ["Followup and yank" gnus-summary-followup-with-original
2521          ,@(if (featurep 'xemacs) '(t)
2522              '(:help "Post followup to this article, quoting its contents"))]
2523         ["Supersede article" gnus-summary-supersede-article t]
2524         ["Cancel article" gnus-summary-cancel-article
2525          ,@(if (featurep 'xemacs) '(t)
2526              '(:help "Cancel an article you posted"))]
2527         ["Reply" gnus-summary-reply t]
2528         ["Reply and yank" gnus-summary-reply-with-original t]
2529         ["Wide reply" gnus-summary-wide-reply t]
2530         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2531          ,@(if (featurep 'xemacs) '(t)
2532              '(:help "Mail a reply, quoting this article"))]
2533         ["Very wide reply" gnus-summary-very-wide-reply t]
2534         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2535          ,@(if (featurep 'xemacs) '(t)
2536              '(:help "Mail a very wide reply, quoting this article"))]
2537         ["Mail forward" gnus-summary-mail-forward t]
2538         ["Post forward" gnus-summary-post-forward t]
2539         ["Digest and mail" gnus-uu-digest-mail-forward t]
2540         ["Digest and post" gnus-uu-digest-post-forward t]
2541         ["Resend message" gnus-summary-resend-message t]
2542         ["Resend message edit" gnus-summary-resend-message-edit t]
2543         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2544         ["Send a mail" gnus-summary-mail-other-window t]
2545         ["Create a local message" gnus-summary-news-other-window t]
2546         ["Uuencode and post" gnus-uu-post-news
2547          ,@(if (featurep 'xemacs) '(t)
2548              '(:help "Post a uuencoded article"))]
2549         ["Followup via news" gnus-summary-followup-to-mail t]
2550         ["Followup via news and yank"
2551          gnus-summary-followup-to-mail-with-original t]
2552         ["Strip signature on reply"
2553          (lambda ()
2554            (interactive)
2555            (if (not (memq message-cite-function
2556                           '(message-cite-original-without-signature
2557                             message-cite-original)))
2558                ;; Stupid workaround for XEmacs not honoring :visible.
2559                (message "Can't toggle this value of `message-cite-function'")
2560              (setq message-cite-function
2561                    (if (eq message-cite-function
2562                            'message-cite-original-without-signature)
2563                        'message-cite-original
2564                      'message-cite-original-without-signature))))
2565          ;; XEmacs barfs on :visible.
2566          ,@(if (featurep 'xemacs) nil
2567              '(:visible (memq message-cite-function
2568                               '(message-cite-original-without-signature
2569                                 message-cite-original))))
2570          :style toggle
2571          :selected (eq message-cite-function
2572                        'message-cite-original-without-signature)
2573          ,@(if (featurep 'xemacs) nil
2574              '(:help "Strip signature from cited article when replying."))]
2575         ;;("Draft"
2576         ;;["Send" gnus-summary-send-draft t]
2577         ;;["Send bounced" gnus-resend-bounced-mail t])
2578         ))
2579
2580     (cond
2581      ((not (keymapp gnus-summary-post-menu))
2582       (setq gnus-article-post-menu gnus-summary-post-menu))
2583      ((not gnus-article-post-menu)
2584       ;; Don't share post menu.
2585       (setq gnus-article-post-menu
2586             (copy-keymap gnus-summary-post-menu))))
2587     (define-key gnus-article-mode-map [menu-bar post]
2588       (cons "Post" gnus-article-post-menu))
2589
2590     (easy-menu-define
2591       gnus-summary-misc-menu gnus-summary-mode-map ""
2592       `("Gnus"
2593         ("Mark Read"
2594          ["Mark as read" gnus-summary-mark-as-read-forward t]
2595          ["Mark same subject and select"
2596           gnus-summary-kill-same-subject-and-select t]
2597          ["Mark same subject" gnus-summary-kill-same-subject t]
2598          ["Catchup" gnus-summary-catchup
2599           ,@(if (featurep 'xemacs) '(t)
2600               '(:help "Mark unread articles in this group as read"))]
2601          ["Catchup all" gnus-summary-catchup-all t]
2602          ["Catchup to here" gnus-summary-catchup-to-here t]
2603          ["Catchup from here" gnus-summary-catchup-from-here t]
2604          ["Catchup region" gnus-summary-mark-region-as-read
2605           (gnus-mark-active-p)]
2606          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2607         ("Mark Various"
2608          ["Tick" gnus-summary-tick-article-forward t]
2609          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2610          ["Remove marks" gnus-summary-clear-mark-forward t]
2611          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2612          ["Set bookmark" gnus-summary-set-bookmark t]
2613          ["Remove bookmark" gnus-summary-remove-bookmark t])
2614         ("Registry Mark"
2615          ["Important"     gnus-registry-set-article-Important-mark    t]
2616          ["Not Important" gnus-registry-remove-article-Important-mark t]
2617          ["Work"          gnus-registry-set-article-Work-mark         t]
2618          ["Not Work"      gnus-registry-remove-article-Work-mark      t]
2619          ["Later"         gnus-registry-set-article-Later-mark        t]
2620          ["Not Later"     gnus-registry-remove-article-Later-mark     t]
2621          ["Personal"      gnus-registry-set-article-Personal-mark     t]
2622          ["Not Personal"  gnus-registry-remove-article-Personal-mark  t]
2623          ["To Do"         gnus-registry-set-article-To-Do-mark        t]
2624          ["Not To Do"     gnus-registry-remove-article-To-Do-mark     t])
2625         ("Limit to"
2626          ["Marks..." gnus-summary-limit-to-marks t]
2627          ["Subject..." gnus-summary-limit-to-subject t]
2628          ["Author..." gnus-summary-limit-to-author t]
2629          ["Recipient..." gnus-summary-limit-to-recipient t]
2630          ["Address..." gnus-summary-limit-to-address t]
2631          ["Age..." gnus-summary-limit-to-age t]
2632          ["Extra..." gnus-summary-limit-to-extra t]
2633          ["Score..." gnus-summary-limit-to-score t]
2634          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2635          ["Unread" gnus-summary-limit-to-unread t]
2636          ["Unseen" gnus-summary-limit-to-unseen t]
2637          ["Singletons" gnus-summary-limit-to-singletons t]
2638          ["Replied" gnus-summary-limit-to-replied t]
2639          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2640          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2641          ["Pop limit" gnus-summary-pop-limit t]
2642          ["Show dormant" gnus-summary-limit-include-dormant t]
2643          ["Hide childless dormant"
2644           gnus-summary-limit-exclude-childless-dormant t]
2645          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2646          ["Hide marked" gnus-summary-limit-exclude-marks t]
2647          ["Show expunged" gnus-summary-limit-include-expunged t])
2648         ("Process Mark"
2649          ["Set mark" gnus-summary-mark-as-processable t]
2650          ["Remove mark" gnus-summary-unmark-as-processable t]
2651          ["Remove all marks" gnus-summary-unmark-all-processable t]
2652          ["Invert marks" gnus-uu-invert-processable t]
2653          ["Mark above" gnus-uu-mark-over t]
2654          ["Mark series" gnus-uu-mark-series t]
2655          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2656          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2657          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2658          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2659          ["Mark all" gnus-uu-mark-all t]
2660          ["Mark buffer" gnus-uu-mark-buffer t]
2661          ["Mark sparse" gnus-uu-mark-sparse t]
2662          ["Mark thread" gnus-uu-mark-thread t]
2663          ["Unmark thread" gnus-uu-unmark-thread t]
2664          ("Process Mark Sets"
2665           ["Kill" gnus-summary-kill-process-mark t]
2666           ["Yank" gnus-summary-yank-process-mark
2667            gnus-newsgroup-process-stack]
2668           ["Save" gnus-summary-save-process-mark t]
2669           ["Run command on marked..." gnus-summary-universal-argument t]))
2670         ("Scroll article"
2671          ["Page forward" gnus-summary-next-page
2672           ,@(if (featurep 'xemacs) '(t)
2673               '(:help "Show next page of article"))]
2674          ["Page backward" gnus-summary-prev-page
2675           ,@(if (featurep 'xemacs) '(t)
2676               '(:help "Show previous page of article"))]
2677          ["Line forward" gnus-summary-scroll-up t])
2678         ("Move"
2679          ["Next unread article" gnus-summary-next-unread-article t]
2680          ["Previous unread article" gnus-summary-prev-unread-article t]
2681          ["Next article" gnus-summary-next-article t]
2682          ["Previous article" gnus-summary-prev-article t]
2683          ["Next unread subject" gnus-summary-next-unread-subject t]
2684          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2685          ["Next article same subject" gnus-summary-next-same-subject t]
2686          ["Previous article same subject" gnus-summary-prev-same-subject t]
2687          ["First unread article" gnus-summary-first-unread-article t]
2688          ["Best unread article" gnus-summary-best-unread-article t]
2689          ["Go to subject number..." gnus-summary-goto-subject t]
2690          ["Go to article number..." gnus-summary-goto-article t]
2691          ["Go to the last article" gnus-summary-goto-last-article t]
2692          ["Pop article off history" gnus-summary-pop-article t])
2693         ("Sort"
2694          ["Sort by number" gnus-summary-sort-by-number t]
2695          ["Sort by author" gnus-summary-sort-by-author t]
2696          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2697          ["Sort by subject" gnus-summary-sort-by-subject t]
2698          ["Sort by date" gnus-summary-sort-by-date t]
2699          ["Sort by score" gnus-summary-sort-by-score t]
2700          ["Sort by lines" gnus-summary-sort-by-lines t]
2701          ["Sort by characters" gnus-summary-sort-by-chars t]
2702          ["Randomize" gnus-summary-sort-by-random t]
2703          ["Original sort" gnus-summary-sort-by-original t])
2704         ("Help"
2705          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2706          ["Describe group" gnus-summary-describe-group t]
2707          ["Fetch charter" gnus-group-fetch-charter
2708           ,@(if (featurep 'xemacs) nil
2709               '(:help "Display the charter of the current group"))]
2710          ["Fetch control message" gnus-group-fetch-control
2711           ,@(if (featurep 'xemacs) nil
2712               '(:help "Display the archived control message for the current group"))]
2713          ["Read manual" gnus-info-find-node t])
2714         ("Modes"
2715          ["Pick and read" gnus-pick-mode t]
2716          ["Binary" gnus-binary-mode t])
2717         ("Regeneration"
2718          ["Regenerate" gnus-summary-prepare t]
2719          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2720          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2721          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2722          ["Toggle threading" gnus-summary-toggle-threads t])
2723         ["See old articles" gnus-summary-insert-old-articles t]
2724         ["See new articles" gnus-summary-insert-new-articles t]
2725         ["Filter articles..." gnus-summary-execute-command t]
2726         ["Run command on articles..." gnus-summary-universal-argument t]
2727         ["Search articles forward..." gnus-summary-search-article-forward t]
2728         ["Search articles backward..." gnus-summary-search-article-backward t]
2729         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2730         ["Expand window" gnus-summary-expand-window t]
2731         ["Expire expirable articles" gnus-summary-expire-articles
2732          (gnus-check-backend-function
2733           'request-expire-articles gnus-newsgroup-name)]
2734         ["Edit local kill file" gnus-summary-edit-local-kill t]
2735         ["Edit main kill file" gnus-summary-edit-global-kill t]
2736         ["Edit group parameters" gnus-summary-edit-parameters t]
2737         ["Customize group parameters" gnus-summary-customize-parameters t]
2738         ["Send a bug report" gnus-bug t]
2739         ("Exit"
2740          ["Catchup and exit" gnus-summary-catchup-and-exit
2741           ,@(if (featurep 'xemacs) '(t)
2742               '(:help "Mark unread articles in this group as read, then exit"))]
2743          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2744          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2745          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2746          ["Exit group" gnus-summary-exit
2747           ,@(if (featurep 'xemacs) '(t)
2748               '(:help "Exit current group, return to group selection mode"))]
2749          ["Exit group without updating" gnus-summary-exit-no-update t]
2750          ["Exit and goto next group" gnus-summary-next-group t]
2751          ["Exit and goto prev group" gnus-summary-prev-group t]
2752          ["Reselect group" gnus-summary-reselect-current-group t]
2753          ["Rescan group" gnus-summary-rescan-group t]
2754          ["Update dribble" gnus-summary-save-newsrc t])))
2755
2756     (gnus-run-hooks 'gnus-summary-menu-hook)))
2757
2758 (defvar gnus-summary-tool-bar-map nil)
2759
2760 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2761 ;; affect _new_ message buffers.  We might add a function that walks thru all
2762 ;; summary-mode buffers and force the update.
2763 (defun gnus-summary-tool-bar-update (&optional symbol value)
2764   "Update summary mode toolbar.
2765 Setter function for custom variables."
2766   (setq-default gnus-summary-tool-bar-map nil)
2767   (when symbol
2768     ;; When used as ":set" function:
2769     (set-default symbol value))
2770   (when (gnus-buffer-live-p gnus-summary-buffer)
2771     (with-current-buffer gnus-summary-buffer
2772       (gnus-summary-make-tool-bar))))
2773
2774 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2775                                      'gnus-summary-tool-bar-gnome
2776                                    'gnus-summary-tool-bar-retro)
2777   "Specifies the Gnus summary tool bar.
2778
2779 It can be either a list or a symbol refering to a list.  See
2780 `gmm-tool-bar-from-list' for the format of the list.  The
2781 default key map is `gnus-summary-mode-map'.
2782
2783 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2784 `gnus-summary-tool-bar-retro'."
2785   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2786                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2787                  (repeat :tag "User defined list" gmm-tool-bar-item)
2788                  (symbol))
2789   :version "23.1" ;; No Gnus
2790   :initialize 'custom-initialize-default
2791   :set 'gnus-summary-tool-bar-update
2792   :group 'gnus-summary)
2793
2794 (defcustom gnus-summary-tool-bar-gnome
2795   '((gnus-summary-post-news "mail/compose" nil)
2796     (gnus-summary-insert-new-articles "mail/inbox" nil
2797                                       :visible (or (not gnus-agent)
2798                                                    gnus-plugged))
2799     (gnus-summary-reply-with-original "mail/reply")
2800     (gnus-summary-reply "mail/reply" nil :visible nil)
2801     (gnus-summary-followup-with-original "mail/reply-all")
2802     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2803     (gnus-summary-mail-forward "mail/forward")
2804     (gnus-summary-save-article "mail/save")
2805     (gnus-summary-search-article-forward "search" nil :visible nil)
2806     (gnus-summary-print-article "print")
2807     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2808     ;; Some new commands that may need more suitable icons:
2809     (gnus-summary-save-newsrc "save" nil :visible nil)
2810     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2811     (gnus-summary-prev-article "left-arrow")
2812     (gnus-summary-next-article "right-arrow")
2813     (gnus-summary-next-page "next-page")
2814     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2815     ;;
2816     ;; Maybe some sort-by-... could be added:
2817     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2818     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2819     (gnus-summary-mark-as-expirable
2820      "delete" nil
2821      :visible (gnus-check-backend-function 'request-expire-articles
2822                                            gnus-newsgroup-name))
2823     (gnus-summary-mark-as-spam
2824      "mail/spam" t
2825      :visible (and (fboundp 'spam-group-ham-contents-p)
2826                    (spam-group-ham-contents-p gnus-newsgroup-name))
2827      :help "Mark as spam")
2828     (gnus-summary-mark-as-read-forward
2829      "mail/not-spam" nil
2830      :visible (and (fboundp 'spam-group-spam-contents-p)
2831                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2832     ;;
2833     (gnus-summary-exit "exit")
2834     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2835     (gnus-info-find-node "help"))
2836   "List of functions for the summary tool bar (GNOME style).
2837
2838 See `gmm-tool-bar-from-list' for the format of the list."
2839   :type '(repeat gmm-tool-bar-item)
2840   :version "23.1" ;; No Gnus
2841   :initialize 'custom-initialize-default
2842   :set 'gnus-summary-tool-bar-update
2843   :group 'gnus-summary)
2844
2845 (defcustom gnus-summary-tool-bar-retro
2846   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2847     (gnus-summary-next-unread-article "gnus/next-ur")
2848     (gnus-summary-post-news "gnus/post")
2849     (gnus-summary-followup-with-original "gnus/fuwo")
2850     (gnus-summary-followup "gnus/followup")
2851     (gnus-summary-reply-with-original "gnus/reply-wo")
2852     (gnus-summary-reply "gnus/reply")
2853     (gnus-summary-caesar-message "gnus/rot13")
2854     (gnus-uu-decode-uu "gnus/uu-decode")
2855     (gnus-summary-save-article-file "gnus/save-aif")
2856     (gnus-summary-save-article "gnus/save-art")
2857     (gnus-uu-post-news "gnus/uu-post")
2858     (gnus-summary-catchup "gnus/catchup")
2859     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2860     (gnus-summary-exit "gnus/exit-summ")
2861     ;; Some new command that may need more suitable icons:
2862     (gnus-summary-print-article "gnus/print" nil :visible nil)
2863     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2864     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2865     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2866     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2867     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2868     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2869     ;;
2870     (gnus-info-find-node "gnus/help" nil :visible nil))
2871   "List of functions for the summary tool bar (retro look).
2872
2873 See `gmm-tool-bar-from-list' for the format of the list."
2874   :type '(repeat gmm-tool-bar-item)
2875   :version "23.1" ;; No Gnus
2876   :initialize 'custom-initialize-default
2877   :set 'gnus-summary-tool-bar-update
2878   :group 'gnus-summary)
2879
2880 (defcustom gnus-summary-tool-bar-zap-list t
2881   "List of icon items from the global tool bar.
2882 These items are not displayed in the Gnus summary mode tool bar.
2883
2884 See `gmm-tool-bar-from-list' for the format of the list."
2885   :type 'gmm-tool-bar-zap-list
2886   :version "23.1" ;; No Gnus
2887   :initialize 'custom-initialize-default
2888   :set 'gnus-summary-tool-bar-update
2889   :group 'gnus-summary)
2890
2891 (defvar image-load-path)
2892
2893 (defun gnus-summary-make-tool-bar (&optional force)
2894   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2895 When FORCE, rebuild the tool bar."
2896   (when (and (not (featurep 'xemacs))
2897              (boundp 'tool-bar-mode)
2898              tool-bar-mode
2899              (or (not gnus-summary-tool-bar-map) force))
2900     (let* ((load-path
2901             (gmm-image-load-path-for-library "gnus"
2902                                              "mail/save.xpm"
2903                                              nil t))
2904            (image-load-path (cons (car load-path)
2905                                   (when (boundp 'image-load-path)
2906                                     image-load-path)))
2907            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2908                                         gnus-summary-tool-bar-zap-list
2909                                         'gnus-summary-mode-map)))
2910       (when map
2911         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2912         ;; uses it's value.
2913         (setq gnus-summary-tool-bar-map map))))
2914   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2915
2916 (defun gnus-score-set-default (var value)
2917   "A version of set that updates the GNU Emacs menu-bar."
2918   (set var value)
2919   ;; It is the message that forces the active status to be updated.
2920   (message ""))
2921
2922 (defun gnus-make-score-map (type)
2923   "Make a summary score map of type TYPE."
2924   (if t
2925       nil
2926     (let ((headers '(("author" "from" string)
2927                      ("subject" "subject" string)
2928                      ("article body" "body" string)
2929                      ("article head" "head" string)
2930                      ("xref" "xref" string)
2931                      ("extra header" "extra" string)
2932                      ("lines" "lines" number)
2933                      ("followups to author" "followup" string)))
2934           (types '((number ("less than" <)
2935                            ("greater than" >)
2936                            ("equal" =))
2937                    (string ("substring" s)
2938                            ("exact string" e)
2939                            ("fuzzy string" f)
2940                            ("regexp" r))))
2941           (perms '(("temporary" (current-time-string))
2942                    ("permanent" nil)
2943                    ("immediate" now)))
2944           header)
2945       (list
2946        (apply
2947         'nconc
2948         (list
2949          (if (eq type 'lower)
2950              "Lower score"
2951            "Increase score"))
2952         (let (outh)
2953           (while headers
2954             (setq header (car headers))
2955             (setq outh
2956                   (cons
2957                    (apply
2958                     'nconc
2959                     (list (car header))
2960                     (let ((ts (cdr (assoc (nth 2 header) types)))
2961                           outt)
2962                       (while ts
2963                         (setq outt
2964                               (cons
2965                                (apply
2966                                 'nconc
2967                                 (list (caar ts))
2968                                 (let ((ps perms)
2969                                       outp)
2970                                   (while ps
2971                                     (setq outp
2972                                           (cons
2973                                            (vector
2974                                             (caar ps)
2975                                             (list
2976                                              'gnus-summary-score-entry
2977                                              (nth 1 header)
2978                                              (if (or (string= (nth 1 header)
2979                                                               "head")
2980                                                      (string= (nth 1 header)
2981                                                               "body"))
2982                                                  ""
2983                                                (list 'gnus-summary-header
2984                                                      (nth 1 header)))
2985                                              (list 'quote (nth 1 (car ts)))
2986                                              (list 'gnus-score-delta-default
2987                                                    nil)
2988                                              (nth 1 (car ps))
2989                                              t)
2990                                             t)
2991                                            outp))
2992                                     (setq ps (cdr ps)))
2993                                   (list (nreverse outp))))
2994                                outt))
2995                         (setq ts (cdr ts)))
2996                       (list (nreverse outt))))
2997                    outh))
2998             (setq headers (cdr headers)))
2999           (list (nreverse outh))))))))
3000
3001
3002 (declare-function turn-on-gnus-mailing-list-mode "gnus-ml" ())
3003
3004 \f
3005
3006 (defun gnus-summary-mode (&optional group)
3007   "Major mode for reading articles.
3008
3009 All normal editing commands are switched off.
3010 \\<gnus-summary-mode-map>
3011 Each line in this buffer represents one article.  To read an
3012 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
3013 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
3014 respectively.
3015
3016 You can also post articles and send mail from this buffer.  To
3017 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
3018 of an article, type `\\[gnus-summary-reply]'.
3019
3020 There are approx. one gazillion commands you can execute in this
3021 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
3022
3023 The following commands are available:
3024
3025 \\{gnus-summary-mode-map}"
3026   (interactive)
3027   (kill-all-local-variables)
3028   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
3029     (gnus-summary-make-local-variables))
3030   (gnus-summary-make-local-variables)
3031   (setq gnus-newsgroup-name group)
3032   (when (gnus-visual-p 'summary-menu 'menu)
3033     (gnus-summary-make-menu-bar)
3034     (gnus-summary-make-tool-bar))
3035   (gnus-make-thread-indent-array)
3036   (gnus-simplify-mode-line)
3037   (setq major-mode 'gnus-summary-mode)
3038   (setq mode-name "Summary")
3039   (make-local-variable 'minor-mode-alist)
3040   (use-local-map gnus-summary-mode-map)
3041   (buffer-disable-undo)
3042   (setq buffer-read-only t              ;Disable modification
3043         show-trailing-whitespace nil)
3044   (setq truncate-lines t)
3045   (setq selective-display t)
3046   (setq selective-display-ellipses t)   ;Display `...'
3047   (gnus-summary-set-display-table)
3048   (gnus-set-default-directory)
3049   (make-local-variable 'gnus-summary-line-format)
3050   (make-local-variable 'gnus-summary-line-format-spec)
3051   (make-local-variable 'gnus-summary-dummy-line-format)
3052   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3053   (make-local-variable 'gnus-summary-mark-positions)
3054   (gnus-make-local-hook 'pre-command-hook)
3055   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3056   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3057   (turn-on-gnus-mailing-list-mode)
3058   (mm-enable-multibyte)
3059   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3060   (gnus-update-summary-mark-positions))
3061
3062 (defun gnus-summary-make-local-variables ()
3063   "Make all the local summary buffer variables."
3064   (let (global)
3065     (dolist (local gnus-summary-local-variables)
3066       (if (consp local)
3067           (progn
3068             (if (eq (cdr local) 'global)
3069                 ;; Copy the global value of the variable.
3070                 (setq global (symbol-value (car local)))
3071               ;; Use the value from the list.
3072               (setq global (eval (cdr local))))
3073             (set (make-local-variable (car local)) global))
3074         ;; Simple nil-valued local variable.
3075         (set (make-local-variable local) nil)))))
3076
3077 (defun gnus-summary-clear-local-variables ()
3078   (let ((locals gnus-summary-local-variables))
3079     (while locals
3080       (if (consp (car locals))
3081           (and (symbolp (caar locals))
3082                (set (caar locals) nil))
3083         (and (symbolp (car locals))
3084              (set (car locals) nil)))
3085       (setq locals (cdr locals)))))
3086
3087 ;; Summary data functions.
3088
3089 (defmacro gnus-data-number (data)
3090   `(car ,data))
3091
3092 (defmacro gnus-data-set-number (data number)
3093   `(setcar ,data ,number))
3094
3095 (defmacro gnus-data-mark (data)
3096   `(nth 1 ,data))
3097
3098 (defmacro gnus-data-set-mark (data mark)
3099   `(setcar (nthcdr 1 ,data) ,mark))
3100
3101 (defmacro gnus-data-pos (data)
3102   `(nth 2 ,data))
3103
3104 (defmacro gnus-data-set-pos (data pos)
3105   `(setcar (nthcdr 2 ,data) ,pos))
3106
3107 (defmacro gnus-data-header (data)
3108   `(nth 3 ,data))
3109
3110 (defmacro gnus-data-set-header (data header)
3111   `(setf (nth 3 ,data) ,header))
3112
3113 (defmacro gnus-data-level (data)
3114   `(nth 4 ,data))
3115
3116 (defmacro gnus-data-unread-p (data)
3117   `(= (nth 1 ,data) gnus-unread-mark))
3118
3119 (defmacro gnus-data-read-p (data)
3120   `(/= (nth 1 ,data) gnus-unread-mark))
3121
3122 (defmacro gnus-data-pseudo-p (data)
3123   `(consp (nth 3 ,data)))
3124
3125 (defmacro gnus-data-find (number)
3126   `(assq ,number gnus-newsgroup-data))
3127
3128 (defmacro gnus-data-find-list (number &optional data)
3129   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3130      (memq (assq ,number bdata)
3131            bdata)))
3132
3133 (defmacro gnus-data-make (number mark pos header level)
3134   `(list ,number ,mark ,pos ,header ,level))
3135
3136 (defun gnus-data-enter (after-article number mark pos header level offset)
3137   (let ((data (gnus-data-find-list after-article)))
3138     (unless data
3139       (error "No such article: %d" after-article))
3140     (setcdr data (cons (gnus-data-make number mark pos header level)
3141                        (cdr data)))
3142     (setq gnus-newsgroup-data-reverse nil)
3143     (gnus-data-update-list (cddr data) offset)))
3144
3145 (defun gnus-data-enter-list (after-article list &optional offset)
3146   (when list
3147     (let ((data (and after-article (gnus-data-find-list after-article)))
3148           (ilist list))
3149       (if (not (or data
3150                    after-article))
3151           (let ((odata gnus-newsgroup-data))
3152             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3153             (when offset
3154               (gnus-data-update-list odata offset)))
3155         ;; Find the last element in the list to be spliced into the main
3156         ;; list.
3157         (setq list (last list))
3158         (if (not data)
3159             (progn
3160               (setcdr list gnus-newsgroup-data)
3161               (setq gnus-newsgroup-data ilist)
3162               (when offset
3163                 (gnus-data-update-list (cdr list) offset)))
3164           (setcdr list (cdr data))
3165           (setcdr data ilist)
3166           (when offset
3167             (gnus-data-update-list (cdr list) offset))))
3168       (setq gnus-newsgroup-data-reverse nil))))
3169
3170 (defun gnus-data-remove (article &optional offset)
3171   (let ((data gnus-newsgroup-data))
3172     (if (= (gnus-data-number (car data)) article)
3173         (progn
3174           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3175                 gnus-newsgroup-data-reverse nil)
3176           (when offset
3177             (gnus-data-update-list gnus-newsgroup-data offset)))
3178       (while (cdr data)
3179         (when (= (gnus-data-number (cadr data)) article)
3180           (setcdr data (cddr data))
3181           (when offset
3182             (gnus-data-update-list (cdr data) offset))
3183           (setq data nil
3184                 gnus-newsgroup-data-reverse nil))
3185         (setq data (cdr data))))))
3186
3187 (defmacro gnus-data-list (backward)
3188   `(if ,backward
3189        (or gnus-newsgroup-data-reverse
3190            (setq gnus-newsgroup-data-reverse
3191                  (reverse gnus-newsgroup-data)))
3192      gnus-newsgroup-data))
3193
3194 (defun gnus-data-update-list (data offset)
3195   "Add OFFSET to the POS of all data entries in DATA."
3196   (setq gnus-newsgroup-data-reverse nil)
3197   (while data
3198     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3199     (setq data (cdr data))))
3200
3201 (defun gnus-summary-article-pseudo-p (article)
3202   "Say whether this article is a pseudo article or not."
3203   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3204
3205 (defmacro gnus-summary-article-sparse-p (article)
3206   "Say whether this article is a sparse article or not."
3207   `(memq ,article gnus-newsgroup-sparse))
3208
3209 (defmacro gnus-summary-article-ancient-p (article)
3210   "Say whether this article is a sparse article or not."
3211   `(memq ,article gnus-newsgroup-ancient))
3212
3213 (defun gnus-article-parent-p (number)
3214   "Say whether this article is a parent or not."
3215   (let ((data (gnus-data-find-list number)))
3216     (and (cdr data)              ; There has to be an article after...
3217          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3218             (gnus-data-level (nth 1 data))))))
3219
3220 (defun gnus-article-children (number)
3221   "Return a list of all children to NUMBER."
3222   (let* ((data (gnus-data-find-list number))
3223          (level (gnus-data-level (car data)))
3224          children)
3225     (setq data (cdr data))
3226     (while (and data
3227                 (= (gnus-data-level (car data)) (1+ level)))
3228       (push (gnus-data-number (car data)) children)
3229       (setq data (cdr data)))
3230     children))
3231
3232 (defmacro gnus-summary-skip-intangible ()
3233   "If the current article is intangible, then jump to a different article."
3234   '(let ((to (get-text-property (point) 'gnus-intangible)))
3235      (and to (gnus-summary-goto-subject to))))
3236
3237 (defmacro gnus-summary-article-intangible-p ()
3238   "Say whether this article is intangible or not."
3239   '(get-text-property (point) 'gnus-intangible))
3240
3241 (defun gnus-article-read-p (article)
3242   "Say whether ARTICLE is read or not."
3243   (not (or (memq article gnus-newsgroup-marked)
3244            (memq article gnus-newsgroup-spam-marked)
3245            (memq article gnus-newsgroup-unreads)
3246            (memq article gnus-newsgroup-unselected)
3247            (memq article gnus-newsgroup-dormant))))
3248
3249 ;; Some summary mode macros.
3250
3251 (defmacro gnus-summary-article-number ()
3252   "The article number of the article on the current line.
3253 If there isn't an article number here, then we return the current
3254 article number."
3255   '(progn
3256      (gnus-summary-skip-intangible)
3257      (or (get-text-property (point) 'gnus-number)
3258          (gnus-summary-last-subject))))
3259
3260 (defmacro gnus-summary-article-header (&optional number)
3261   "Return the header of article NUMBER."
3262   `(gnus-data-header (gnus-data-find
3263                       ,(or number '(gnus-summary-article-number)))))
3264
3265 (defmacro gnus-summary-thread-level (&optional number)
3266   "Return the level of thread that starts with article NUMBER."
3267   `(if (and (eq gnus-summary-make-false-root 'dummy)
3268             (get-text-property (point) 'gnus-intangible))
3269        0
3270      (gnus-data-level (gnus-data-find
3271                        ,(or number '(gnus-summary-article-number))))))
3272
3273 (defmacro gnus-summary-article-mark (&optional number)
3274   "Return the mark of article NUMBER."
3275   `(gnus-data-mark (gnus-data-find
3276                     ,(or number '(gnus-summary-article-number)))))
3277
3278 (defmacro gnus-summary-article-pos (&optional number)
3279   "Return the position of the line of article NUMBER."
3280   `(gnus-data-pos (gnus-data-find
3281                    ,(or number '(gnus-summary-article-number)))))
3282
3283 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3284 (defmacro gnus-summary-article-subject (&optional number)
3285   "Return current subject string or nil if nothing."
3286   `(let ((headers
3287           ,(if number
3288                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3289              '(gnus-data-header (assq (gnus-summary-article-number)
3290                                       gnus-newsgroup-data)))))
3291      (and headers
3292           (vectorp headers)
3293           (mail-header-subject headers))))
3294
3295 (defmacro gnus-summary-article-score (&optional number)
3296   "Return current article score."
3297   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3298                   gnus-newsgroup-scored))
3299        gnus-summary-default-score 0))
3300
3301 (defun gnus-summary-article-children (&optional number)
3302   "Return a list of article numbers that are children of article NUMBER."
3303   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3304          (level (gnus-data-level (car data)))
3305          l children)
3306     (while (and (setq data (cdr data))
3307                 (> (setq l (gnus-data-level (car data))) level))
3308       (and (= (1+ level) l)
3309            (push (gnus-data-number (car data))
3310                  children)))
3311     (nreverse children)))
3312
3313 (defun gnus-summary-article-parent (&optional number)
3314   "Return the article number of the parent of article NUMBER."
3315   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3316                                     (gnus-data-list t)))
3317          (level (gnus-data-level (car data))))
3318     (if (zerop level)
3319         ()                              ; This is a root.
3320       ;; We search until we find an article with a level less than
3321       ;; this one.  That function has to be the parent.
3322       (while (and (setq data (cdr data))
3323                   (not (< (gnus-data-level (car data)) level))))
3324       (and data (gnus-data-number (car data))))))
3325
3326 (defun gnus-unread-mark-p (mark)
3327   "Say whether MARK is the unread mark."
3328   (= mark gnus-unread-mark))
3329
3330 (defun gnus-read-mark-p (mark)
3331   "Say whether MARK is one of the marks that mark as read.
3332 This is all marks except unread, ticked, dormant, and expirable."
3333   (not (or (= mark gnus-unread-mark)
3334            (= mark gnus-ticked-mark)
3335            (= mark gnus-spam-mark)
3336            (= mark gnus-dormant-mark)
3337            (= mark gnus-expirable-mark))))
3338
3339 (defmacro gnus-article-mark (number)
3340   "Return the MARK of article NUMBER.
3341 This macro should only be used when computing the mark the \"first\"
3342 time; i.e., when generating the summary lines.  After that,
3343 `gnus-summary-article-mark' should be used to examine the
3344 marks of articles."
3345   `(cond
3346     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3347     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3348     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3349     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3350     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3351     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3352     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3353     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3354            gnus-ancient-mark))))
3355
3356 ;; Saving hidden threads.
3357
3358 (defmacro gnus-save-hidden-threads (&rest forms)
3359   "Save hidden threads, eval FORMS, and restore the hidden threads."
3360   (let ((config (make-symbol "config")))
3361     `(let ((,config (gnus-hidden-threads-configuration)))
3362        (unwind-protect
3363            (save-excursion
3364              ,@forms)
3365          (gnus-restore-hidden-threads-configuration ,config)))))
3366 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3367 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3368
3369 (defun gnus-data-compute-positions ()
3370   "Compute the positions of all articles."
3371   (setq gnus-newsgroup-data-reverse nil)
3372   (let ((data gnus-newsgroup-data))
3373     (save-excursion
3374       (gnus-save-hidden-threads
3375         (gnus-summary-show-all-threads)
3376         (goto-char (point-min))
3377         (while data
3378           (while (get-text-property (point) 'gnus-intangible)
3379             (forward-line 1))
3380           (gnus-data-set-pos (car data) (+ (point) 3))
3381           (setq data (cdr data))
3382           (forward-line 1))))))
3383
3384 (defun gnus-hidden-threads-configuration ()
3385   "Return the current hidden threads configuration."
3386   (save-excursion
3387     (let (config)
3388       (goto-char (point-min))
3389       (while (search-forward "\r" nil t)
3390         (push (1- (point)) config))
3391       config)))
3392
3393 (defun gnus-restore-hidden-threads-configuration (config)
3394   "Restore hidden threads configuration from CONFIG."
3395   (save-excursion
3396     (let (point buffer-read-only)
3397       (while (setq point (pop config))
3398         (when (and (< point (point-max))
3399                    (goto-char point)
3400                    (eq (char-after) ?\n))
3401           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3402
3403 ;; Various summary mode internalish functions.
3404
3405 (defun gnus-mouse-pick-article (e)
3406   (interactive "e")
3407   (mouse-set-point e)
3408   (gnus-summary-next-page nil t))
3409
3410 (defun gnus-summary-set-display-table ()
3411   "Change the display table.
3412 Odd characters have a tendency to mess
3413 up nicely formatted displays - we make all possible glyphs
3414 display only a single character."
3415
3416   ;; We start from the standard display table, if any.
3417   (let ((table (or (copy-sequence standard-display-table)
3418                    (make-display-table)))
3419         (i 32))
3420     ;; Nix out all the control chars...
3421     (while (>= (setq i (1- i)) 0)
3422       (aset table i [??]))
3423    ;; ... but not newline and cr, of course.  (cr is necessary for the
3424     ;; selective display).
3425     (aset table ?\n nil)
3426     (aset table ?\r nil)
3427     ;; We keep TAB as well.
3428     (aset table ?\t nil)
3429     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3430     ;; Emacs 23 (unicode), that are not set already.
3431     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3432                  160
3433                256)))
3434       (while (>= (setq i (1- i)) 127)
3435         ;; Only modify if the entry is nil.
3436         (unless (aref table i)
3437           (aset table i [??]))))
3438     (setq buffer-display-table table)))
3439
3440 (defun gnus-summary-set-article-display-arrow (pos)
3441   "Update the overlay arrow to point to line at position POS."
3442   (when (and gnus-summary-display-arrow
3443              (boundp 'overlay-arrow-position)
3444              (boundp 'overlay-arrow-string))
3445     (save-excursion
3446       (goto-char pos)
3447       (beginning-of-line)
3448       (unless overlay-arrow-position
3449         (setq overlay-arrow-position (make-marker)))
3450       (setq overlay-arrow-string "=>"
3451             overlay-arrow-position (set-marker overlay-arrow-position
3452                                                (point)
3453                                                (current-buffer))))))
3454
3455 (defun gnus-summary-setup-buffer (group)
3456   "Initialize summary buffer."
3457   (let ((buffer (gnus-summary-buffer-name group))
3458         (dead-name (concat "*Dead Summary "
3459                            (gnus-group-decoded-name group) "*")))
3460     ;; If a dead summary buffer exists, we kill it.
3461     (when (gnus-buffer-live-p dead-name)
3462       (gnus-kill-buffer dead-name))
3463     (if (get-buffer buffer)
3464         (progn
3465           (set-buffer buffer)
3466           (setq gnus-summary-buffer (current-buffer))
3467           (not gnus-newsgroup-prepared))
3468       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3469       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3470       (gnus-summary-mode group)
3471       (when gnus-carpal
3472         (gnus-carpal-setup-buffer 'summary))
3473       (when (gnus-group-quit-config group)
3474         (set (make-local-variable 'gnus-single-article-buffer) nil))
3475       (make-local-variable 'gnus-article-buffer)
3476       (make-local-variable 'gnus-article-current)
3477       (make-local-variable 'gnus-original-article-buffer)
3478       (setq gnus-newsgroup-name group)
3479       ;; Set any local variables in the group parameters.
3480       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3481       t)))
3482
3483 (defun gnus-set-global-variables ()
3484   "Set the global equivalents of the buffer-local variables.
3485 They are set to the latest values they had.  These reflect the summary
3486 buffer that was in action when the last article was fetched."
3487   (when (eq major-mode 'gnus-summary-mode)
3488     (setq gnus-summary-buffer (current-buffer))
3489     (let ((name gnus-newsgroup-name)
3490           (marked gnus-newsgroup-marked)
3491           (spam gnus-newsgroup-spam-marked)
3492           (unread gnus-newsgroup-unreads)
3493           (headers gnus-current-headers)
3494           (data gnus-newsgroup-data)
3495           (summary gnus-summary-buffer)
3496           (article-buffer gnus-article-buffer)
3497           (original gnus-original-article-buffer)
3498           (gac gnus-article-current)
3499           (reffed gnus-reffed-article-number)
3500           (score-file gnus-current-score-file)
3501           (default-charset gnus-newsgroup-charset)
3502           vlist)
3503       (let ((locals gnus-newsgroup-variables))
3504         (while locals
3505           (if (consp (car locals))
3506               (push (eval (caar locals)) vlist)
3507             (push (eval (car locals)) vlist))
3508           (setq locals (cdr locals)))
3509         (setq vlist (nreverse vlist)))
3510       (with-current-buffer gnus-group-buffer
3511         (setq gnus-newsgroup-name name
3512               gnus-newsgroup-marked marked
3513               gnus-newsgroup-spam-marked spam
3514               gnus-newsgroup-unreads unread
3515               gnus-current-headers headers
3516               gnus-newsgroup-data data
3517               gnus-article-current gac
3518               gnus-summary-buffer summary
3519               gnus-article-buffer article-buffer
3520               gnus-original-article-buffer original
3521               gnus-reffed-article-number reffed
3522               gnus-current-score-file score-file
3523               gnus-newsgroup-charset default-charset)
3524         (let ((locals gnus-newsgroup-variables))
3525           (while locals
3526             (if (consp (car locals))
3527                 (set (caar locals) (pop vlist))
3528               (set (car locals) (pop vlist)))
3529             (setq locals (cdr locals))))
3530         ;; The article buffer also has local variables.
3531         (when (gnus-buffer-live-p gnus-article-buffer)
3532           (set-buffer gnus-article-buffer)
3533           (setq gnus-summary-buffer summary))))))
3534
3535 (defun gnus-summary-article-unread-p (article)
3536   "Say whether ARTICLE is unread or not."
3537   (memq article gnus-newsgroup-unreads))
3538
3539 (defun gnus-summary-first-article-p (&optional article)
3540   "Return whether ARTICLE is the first article in the buffer."
3541   (if (not (setq article (or article (gnus-summary-article-number))))
3542       nil
3543     (eq article (caar gnus-newsgroup-data))))
3544
3545 (defun gnus-summary-last-article-p (&optional article)
3546   "Return whether ARTICLE is the last article in the buffer."
3547   (if (not (setq article (or article (gnus-summary-article-number))))
3548       ;; All non-existent numbers are the last article.  :-)
3549       t
3550     (not (cdr (gnus-data-find-list article)))))
3551
3552 (defun gnus-make-thread-indent-array (&optional n)
3553   (when (or n
3554             (progn (setq n 200) nil)
3555             (null gnus-thread-indent-array)
3556             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3557     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3558           gnus-thread-indent-array-level gnus-thread-indent-level)
3559     (while (>= n 0)
3560       (aset gnus-thread-indent-array n
3561             (make-string (* n gnus-thread-indent-level) ? ))
3562       (setq n (1- n)))))
3563
3564 (defun gnus-update-summary-mark-positions ()
3565   "Compute where the summary marks are to go."
3566   (save-excursion
3567     (when (gnus-buffer-exists-p gnus-summary-buffer)
3568       (set-buffer gnus-summary-buffer))
3569     (let ((spec gnus-summary-line-format-spec)
3570           pos)
3571       (save-excursion
3572         (gnus-set-work-buffer)
3573         (let ((gnus-tmp-unread ?Z)
3574               (gnus-replied-mark ?Z)
3575               (gnus-score-below-mark ?Z)
3576               (gnus-score-over-mark ?Z)
3577               (gnus-undownloaded-mark ?Z)
3578               (gnus-summary-line-format-spec spec)
3579               (gnus-newsgroup-downloadable '(0))
3580               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3581               case-fold-search ignores)
3582           ;; Here, all marks are bound to Z.
3583           (gnus-summary-insert-line header
3584                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3585           (goto-char (point-min))
3586           ;; Memorize the positions of the same characters as dummy marks.
3587           (while (re-search-forward "[A-D]" nil t)
3588             (push (point) ignores))
3589           (erase-buffer)
3590           ;; We use A-D as dummy marks in order to know column positions
3591           ;; where marks should be inserted.
3592           (setq gnus-tmp-unread ?A
3593                 gnus-replied-mark ?B
3594                 gnus-score-below-mark ?C
3595                 gnus-score-over-mark ?C
3596                 gnus-undownloaded-mark ?D)
3597           (gnus-summary-insert-line header
3598                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3599           ;; Ignore characters which aren't dummy marks.
3600           (dolist (p ignores)
3601             (delete-region (goto-char (1- p)) p)
3602             (insert ?Z))
3603           (goto-char (point-min))
3604           (setq pos (list (cons 'unread
3605                                 (and (search-forward "A" nil t)
3606                                      (- (point) (point-min) 1)))))
3607           (goto-char (point-min))
3608           (push (cons 'replied (and (search-forward "B" nil t)
3609                                     (- (point) (point-min) 1)))
3610                 pos)
3611           (goto-char (point-min))
3612           (push (cons 'score (and (search-forward "C" nil t)
3613                                   (- (point) (point-min) 1)))
3614                 pos)
3615           (goto-char (point-min))
3616           (push (cons 'download (and (search-forward "D" nil t)
3617                                      (- (point) (point-min) 1)))
3618                 pos)))
3619       (setq gnus-summary-mark-positions pos))))
3620
3621 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3622   "Insert a dummy root in the summary buffer."
3623   (beginning-of-line)
3624   (gnus-add-text-properties
3625    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3626    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3627
3628 (defun gnus-summary-extract-address-component (from)
3629   (or (car (funcall gnus-extract-address-components from))
3630       from))
3631
3632 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3633   (let ((mail-parse-charset gnus-newsgroup-charset)
3634         (ignored-from-addresses (gnus-ignored-from-addresses))
3635         ; Is it really necessary to do this next part for each summary line?
3636         ; Luckily, doesn't seem to slow things down much.
3637         (mail-parse-ignored-charsets
3638          (with-current-buffer gnus-summary-buffer
3639            gnus-newsgroup-ignored-charsets)))
3640     (or
3641      (and ignored-from-addresses
3642           (string-match ignored-from-addresses gnus-tmp-from)
3643           (let ((extra-headers (mail-header-extra header))
3644                 to
3645                 newsgroups)
3646             (cond
3647              ((setq to (cdr (assq 'To extra-headers)))
3648               (concat gnus-summary-to-prefix
3649                       (inline
3650                         (gnus-summary-extract-address-component
3651                          (funcall gnus-decode-encoded-address-function to)))))
3652              ((setq newsgroups
3653                     (or
3654                      (cdr (assq 'Newsgroups extra-headers))
3655                      (and
3656                       (memq 'Newsgroups gnus-extra-headers)
3657                       (eq (car (gnus-find-method-for-group
3658                                 gnus-newsgroup-name)) 'nntp)
3659                       (gnus-group-real-name gnus-newsgroup-name))))
3660               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3661      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3662
3663 (defun gnus-summary-insert-line (gnus-tmp-header
3664                                  gnus-tmp-level gnus-tmp-current
3665                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3666                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3667                                  &optional gnus-tmp-dummy gnus-tmp-score
3668                                  gnus-tmp-process)
3669   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3670       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3671                                           gnus-tmp-level)))
3672   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3673          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3674          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3675          (gnus-tmp-score-char
3676           (if (or (null gnus-summary-default-score)
3677                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3678                       gnus-summary-zcore-fuzz))
3679               ?                         ;Whitespace
3680             (if (< gnus-tmp-score gnus-summary-default-score)
3681                 gnus-score-below-mark gnus-score-over-mark)))
3682          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3683          (gnus-tmp-replied
3684           (cond (gnus-tmp-process gnus-process-mark)
3685                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3686                  gnus-cached-mark)
3687                 (gnus-tmp-replied gnus-replied-mark)
3688                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3689                  gnus-forwarded-mark)
3690                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3691                  gnus-saved-mark)
3692                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3693                  gnus-recent-mark)
3694                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3695                  gnus-unseen-mark)
3696                 (t gnus-no-mark)))
3697          (gnus-tmp-downloaded
3698           (cond (undownloaded
3699                  gnus-undownloaded-mark)
3700                 (gnus-newsgroup-agentized
3701                  gnus-downloaded-mark)
3702                 (t
3703                  gnus-no-mark)))
3704          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3705          (gnus-tmp-name
3706           (cond
3707            ((string-match "<[^>]+> *$" gnus-tmp-from)
3708             (let ((beg (match-beginning 0)))
3709               (or (and (string-match "^\".+\"" gnus-tmp-from)
3710                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3711                   (substring gnus-tmp-from 0 beg))))
3712            ((string-match "(.+)" gnus-tmp-from)
3713             (substring gnus-tmp-from
3714                        (1+ (match-beginning 0)) (1- (match-end 0))))
3715            (t gnus-tmp-from)))
3716          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3717          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3718          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3719          (buffer-read-only nil))
3720     (when (string= gnus-tmp-name "")
3721       (setq gnus-tmp-name gnus-tmp-from))
3722     (unless (numberp gnus-tmp-lines)
3723       (setq gnus-tmp-lines -1))
3724     (if (= gnus-tmp-lines -1)
3725         (setq gnus-tmp-lines "?")
3726       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3727       (gnus-put-text-property
3728      (point)
3729      (progn (eval gnus-summary-line-format-spec) (point))
3730        'gnus-number gnus-tmp-number)
3731     (when (gnus-visual-p 'summary-highlight 'highlight)
3732       (forward-line -1)
3733       (gnus-run-hooks 'gnus-summary-update-hook)
3734       (forward-line 1))))
3735
3736 (defun gnus-summary-update-line (&optional dont-update)
3737   "Update summary line after change."
3738   (when (and gnus-summary-default-score
3739              (not gnus-summary-inhibit-highlight))
3740     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3741            (article (gnus-summary-article-number))
3742            (score (gnus-summary-article-score article)))
3743       (unless dont-update
3744         (if (and gnus-summary-mark-below
3745                  (< (gnus-summary-article-score)
3746                     gnus-summary-mark-below))
3747             ;; This article has a low score, so we mark it as read.
3748             (when (memq article gnus-newsgroup-unreads)
3749               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3750           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3751             ;; This article was previously marked as read on account
3752             ;; of a low score, but now it has risen, so we mark it as
3753             ;; unread.
3754             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3755         (gnus-summary-update-mark
3756          (if (or (null gnus-summary-default-score)
3757                  (<= (abs (- score gnus-summary-default-score))
3758                      gnus-summary-zcore-fuzz))
3759              ?                          ;Whitespace
3760            (if (< score gnus-summary-default-score)
3761                gnus-score-below-mark gnus-score-over-mark))
3762          'score))
3763       ;; Do visual highlighting.
3764       (when (gnus-visual-p 'summary-highlight 'highlight)
3765         (gnus-run-hooks 'gnus-summary-update-hook)))))
3766
3767 (defvar gnus-tmp-new-adopts nil)
3768
3769 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3770   "Return the number of articles in THREAD.
3771 This may be 0 in some cases -- if none of the articles in
3772 the thread are to be displayed."
3773   (let* ((number
3774          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3775           (cond
3776            ((not (listp thread))
3777             1)
3778            ((and (consp thread) (cdr thread))
3779             (apply
3780              '+ 1 (mapcar
3781                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3782            ((null thread)
3783             1)
3784            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3785             1)
3786            (t 0))))
3787     (when (and level (zerop level) gnus-tmp-new-adopts)
3788       (incf number
3789             (apply '+ (mapcar
3790                        'gnus-summary-number-of-articles-in-thread
3791                        gnus-tmp-new-adopts))))
3792     (if char
3793         (if (> number 1) gnus-not-empty-thread-mark
3794           gnus-empty-thread-mark)
3795       number)))
3796
3797 (defsubst gnus-summary-line-message-size (head)
3798   "Return pretty-printed version of message size.
3799 This function is intended to be used in
3800 `gnus-summary-line-format-alist'."
3801   (let ((c (or (mail-header-chars head) -1)))
3802     (cond ((< c 0) "n/a")               ; chars not available
3803           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3804           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3805           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3806           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3807
3808
3809 (defun gnus-summary-set-local-parameters (group)
3810   "Go through the local params of GROUP and set all variable specs in that list."
3811   (let ((vars '(quit-config)))          ; Ignore quit-config.
3812     (dolist (elem (gnus-group-find-parameter group))
3813       (and (consp elem)                 ; Has to be a cons.
3814            (consp (cdr elem))           ; The cdr has to be a list.
3815            (symbolp (car elem))         ; Has to be a symbol in there.
3816            (not (memq (car elem) vars))
3817            (ignore-errors               ; So we set it.
3818              (push (car elem) vars)
3819              (make-local-variable (car elem))
3820              (set (car elem) (eval (nth 1 elem))))))))
3821
3822 (defun gnus-summary-read-group (group &optional show-all no-article
3823                                       kill-buffer no-display backward
3824                                       select-articles)
3825   "Start reading news in newsgroup GROUP.
3826 If SHOW-ALL is non-nil, already read articles are also listed.
3827 If NO-ARTICLE is non-nil, no article is selected initially.
3828 If NO-DISPLAY, don't generate a summary buffer."
3829   (let (result)
3830     (while (and group
3831                 (null (setq result
3832                             (let ((gnus-auto-select-next nil))
3833                               (or (gnus-summary-read-group-1
3834                                    group show-all no-article
3835                                    kill-buffer no-display
3836                                    select-articles)
3837                                   (setq show-all nil
3838                                         select-articles nil)))))
3839                 (eq gnus-auto-select-next 'quietly))
3840       (set-buffer gnus-group-buffer)
3841       ;; The entry function called above goes to the next
3842       ;; group automatically, so we go two groups back
3843       ;; if we are searching for the previous group.
3844       (when backward
3845         (gnus-group-prev-unread-group 2))
3846       (if (not (equal group (gnus-group-group-name)))
3847           (setq group (gnus-group-group-name))
3848         (setq group nil)))
3849     result))
3850
3851 (defun gnus-summary-read-group-1 (group show-all no-article
3852                                         kill-buffer no-display
3853                                         &optional select-articles)
3854   ;; Killed foreign groups can't be entered.
3855   ;;  (when (and (not (gnus-group-native-p group))
3856   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3857   ;;    (error "Dead non-native groups can't be entered"))
3858   (gnus-message 5 "Retrieving newsgroup: %s..."
3859                 (gnus-group-decoded-name group))
3860   (let* ((new-group (gnus-summary-setup-buffer group))
3861          (quit-config (gnus-group-quit-config group))
3862          (did-select (and new-group (gnus-select-newsgroup
3863                                      group show-all select-articles))))
3864     (cond
3865      ;; This summary buffer exists already, so we just select it.
3866      ((not new-group)
3867       (gnus-set-global-variables)
3868       (when kill-buffer
3869         (gnus-kill-or-deaden-summary kill-buffer))
3870       (gnus-configure-windows 'summary 'force)
3871       (gnus-set-mode-line 'summary)
3872       (gnus-summary-position-point)
3873       (message "")
3874       t)
3875      ;; We couldn't select this group.
3876      ((null did-select)
3877       (when (and (eq major-mode 'gnus-summary-mode)
3878                  (not (equal (current-buffer) kill-buffer)))
3879         (kill-buffer (current-buffer))
3880         (if (not quit-config)
3881             (progn
3882               ;; Update the info -- marks might need to be removed,
3883               ;; for instance.
3884               (gnus-summary-update-info)
3885               (set-buffer gnus-group-buffer)
3886               (gnus-group-jump-to-group group)
3887               (gnus-group-next-unread-group 1))
3888           (gnus-handle-ephemeral-exit quit-config)))
3889       (let ((grpinfo (gnus-get-info group)))
3890         (if (null (gnus-info-read grpinfo))
3891             (gnus-message 3 "Group %s contains no messages"
3892                           (gnus-group-decoded-name group))
3893           (gnus-message 3 "Can't select group")))
3894       nil)
3895      ;; The user did a `C-g' while prompting for number of articles,
3896      ;; so we exit this group.
3897      ((eq did-select 'quit)
3898       (and (eq major-mode 'gnus-summary-mode)
3899            (not (equal (current-buffer) kill-buffer))
3900            (kill-buffer (current-buffer)))
3901       (when kill-buffer
3902         (gnus-kill-or-deaden-summary kill-buffer))
3903       (if (not quit-config)
3904           (progn
3905             (set-buffer gnus-group-buffer)
3906             (gnus-group-jump-to-group group)
3907             (gnus-group-next-unread-group 1)
3908             (gnus-configure-windows 'group 'force))
3909         (gnus-handle-ephemeral-exit quit-config))
3910       ;; Finally signal the quit.
3911       (signal 'quit nil))
3912      ;; The group was successfully selected.
3913      (t
3914       (gnus-set-global-variables)
3915       ;; Save the active value in effect when the group was entered.
3916       (setq gnus-newsgroup-active
3917             (gnus-copy-sequence
3918              (gnus-active gnus-newsgroup-name)))
3919       ;; You can change the summary buffer in some way with this hook.
3920       (gnus-run-hooks 'gnus-select-group-hook)
3921       (when (memq 'summary (gnus-update-format-specifications
3922                             nil 'summary 'summary-mode 'summary-dummy))
3923         ;; The format specification for the summary line was updated,
3924         ;; so we need to update the mark positions as well.
3925         (gnus-update-summary-mark-positions))
3926       ;; Do score processing.
3927       (when gnus-use-scoring
3928         (gnus-possibly-score-headers))
3929       ;; Check whether to fill in the gaps in the threads.
3930       (when gnus-build-sparse-threads
3931         (gnus-build-sparse-threads))
3932       ;; Find the initial limit.
3933       (if show-all
3934           (let ((gnus-newsgroup-dormant nil))
3935             (gnus-summary-initial-limit show-all))
3936         (gnus-summary-initial-limit show-all))
3937       ;; Generate the summary buffer.
3938       (unless no-display
3939         (gnus-summary-prepare))
3940       (when gnus-use-trees
3941         (gnus-tree-open group)
3942         (setq gnus-summary-highlight-line-function
3943               'gnus-tree-highlight-article))
3944       ;; If the summary buffer is empty, but there are some low-scored
3945       ;; articles or some excluded dormants, we include these in the
3946       ;; buffer.
3947       (when (and (zerop (buffer-size))
3948                  (not no-display))
3949         (cond (gnus-newsgroup-dormant
3950                (gnus-summary-limit-include-dormant))
3951               ((and gnus-newsgroup-scored show-all)
3952                (gnus-summary-limit-include-expunged t))))
3953       ;; Function `gnus-apply-kill-file' must be called in this hook.
3954       (gnus-run-hooks 'gnus-apply-kill-hook)
3955       (if (and (zerop (buffer-size))
3956                (not no-display))
3957           (progn
3958             ;; This newsgroup is empty.
3959             (gnus-summary-catchup-and-exit nil t)
3960             (gnus-message 6 "No unread news")
3961             (when kill-buffer
3962               (gnus-kill-or-deaden-summary kill-buffer))
3963             ;; Return nil from this function.
3964             nil)
3965         ;; Hide conversation thread subtrees.  We cannot do this in
3966         ;; gnus-summary-prepare-hook since kill processing may not
3967         ;; work with hidden articles.
3968         (gnus-summary-maybe-hide-threads)
3969         (when kill-buffer
3970           (gnus-kill-or-deaden-summary kill-buffer))
3971         (gnus-summary-auto-select-subject)
3972         ;; Show first unread article if requested.
3973         (if (and (not no-article)
3974                  (not no-display)
3975                  gnus-newsgroup-unreads
3976                  gnus-auto-select-first)
3977             (progn
3978               (gnus-configure-windows 'summary)
3979               (let ((art (gnus-summary-article-number)))
3980                 (unless (and (not gnus-plugged)
3981                              (or (memq art gnus-newsgroup-undownloaded)
3982                                  (memq art gnus-newsgroup-downloadable)))
3983                   (gnus-summary-goto-article art))))
3984           ;; Don't select any articles.
3985           (gnus-summary-position-point)
3986           (gnus-configure-windows 'summary 'force)
3987           (gnus-set-mode-line 'summary))
3988         (when (and gnus-auto-center-group
3989                    (get-buffer-window gnus-group-buffer t))
3990           ;; Gotta use windows, because recenter does weird stuff if
3991           ;; the current buffer ain't the displayed window.
3992           (let ((owin (selected-window)))
3993             (select-window (get-buffer-window gnus-group-buffer t))
3994             (when (gnus-group-goto-group group)
3995               (recenter))
3996             (select-window owin)))
3997         ;; Mark this buffer as "prepared".
3998         (setq gnus-newsgroup-prepared t)
3999         (gnus-run-hooks 'gnus-summary-prepared-hook)
4000         (unless (gnus-ephemeral-group-p group)
4001           (gnus-group-update-group group))
4002         t)))))
4003
4004 (defun gnus-summary-auto-select-subject ()
4005   "Select the subject line on initial group entry."
4006   (goto-char (point-min))
4007   (cond
4008    ((eq gnus-auto-select-subject 'best)
4009     (gnus-summary-best-unread-subject))
4010    ((eq gnus-auto-select-subject 'unread)
4011     (gnus-summary-first-unread-subject))
4012    ((eq gnus-auto-select-subject 'unseen)
4013     (gnus-summary-first-unseen-subject))
4014    ((eq gnus-auto-select-subject 'unseen-or-unread)
4015     (gnus-summary-first-unseen-or-unread-subject))
4016    ((eq gnus-auto-select-subject 'first)
4017     ;; Do nothing.
4018     )
4019    ((functionp gnus-auto-select-subject)
4020     (funcall gnus-auto-select-subject))))
4021
4022 (defun gnus-summary-prepare ()
4023   "Generate the summary buffer."
4024   (interactive)
4025   (let ((buffer-read-only nil))
4026     (erase-buffer)
4027     (setq gnus-newsgroup-data nil
4028           gnus-newsgroup-data-reverse nil)
4029     (gnus-run-hooks 'gnus-summary-generate-hook)
4030     ;; Generate the buffer, either with threads or without.
4031     (when gnus-newsgroup-headers
4032       (gnus-summary-prepare-threads
4033        (if gnus-show-threads
4034            (gnus-sort-gathered-threads
4035             (funcall gnus-summary-thread-gathering-function
4036                      (gnus-sort-threads
4037                       (gnus-cut-threads (gnus-make-threads)))))
4038          ;; Unthreaded display.
4039          (gnus-sort-articles gnus-newsgroup-headers))))
4040     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4041     ;; Call hooks for modifying summary buffer.
4042     (goto-char (point-min))
4043     (gnus-run-hooks 'gnus-summary-prepare-hook)))
4044
4045 (defsubst gnus-general-simplify-subject (subject)
4046   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4047   (setq subject
4048         (cond
4049          ;; Truncate the subject.
4050          (gnus-simplify-subject-functions
4051           (gnus-map-function gnus-simplify-subject-functions subject))
4052          ((numberp gnus-summary-gather-subject-limit)
4053           (setq subject (gnus-simplify-subject-re subject))
4054           (if (> (length subject) gnus-summary-gather-subject-limit)
4055               (substring subject 0 gnus-summary-gather-subject-limit)
4056             subject))
4057          ;; Fuzzily simplify it.
4058          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4059           (gnus-simplify-subject-fuzzy subject))
4060          ;; Just remove the leading "Re:".
4061          (t
4062           (gnus-simplify-subject-re subject))))
4063
4064   (if (and gnus-summary-gather-exclude-subject
4065            (string-match gnus-summary-gather-exclude-subject subject))
4066       nil                         ; This article shouldn't be gathered
4067     subject))
4068
4069 (defun gnus-summary-simplify-subject-query ()
4070   "Query where the respool algorithm would put this article."
4071   (interactive)
4072   (gnus-summary-select-article)
4073   (message "%s" (gnus-general-simplify-subject (gnus-summary-article-subject))))
4074
4075 (defun gnus-gather-threads-by-subject (threads)
4076   "Gather threads by looking at Subject headers."
4077   (if (not gnus-summary-make-false-root)
4078       threads
4079     (let ((hashtb (gnus-make-hashtable 1024))
4080           (prev threads)
4081           (result threads)
4082           subject hthread whole-subject)
4083       (while threads
4084         (setq subject (gnus-general-simplify-subject
4085                        (setq whole-subject (mail-header-subject
4086                                             (caar threads)))))
4087         (when subject
4088           (if (setq hthread (gnus-gethash subject hashtb))
4089               (progn
4090                 ;; We enter a dummy root into the thread, if we
4091                 ;; haven't done that already.
4092                 (unless (stringp (caar hthread))
4093                   (setcar hthread (list whole-subject (car hthread))))
4094                 ;; We add this new gathered thread to this gathered
4095                 ;; thread.
4096                 (setcdr (car hthread)
4097                         (nconc (cdar hthread) (list (car threads))))
4098                 ;; Remove it from the list of threads.
4099                 (setcdr prev (cdr threads))
4100                 (setq threads prev))
4101             ;; Enter this thread into the hash table.
4102             (gnus-sethash subject
4103                           (if gnus-summary-make-false-root-always
4104                               (progn
4105                                 ;; If you want a dummy root above all
4106                                 ;; threads...
4107                                 (setcar threads (list whole-subject
4108                                                       (car threads)))
4109                                 threads)
4110                             threads)
4111                           hashtb)))
4112         (setq prev threads)
4113         (setq threads (cdr threads)))
4114       result)))
4115
4116 (defun gnus-gather-threads-by-references (threads)
4117   "Gather threads by looking at References headers."
4118   (let ((idhashtb (gnus-make-hashtable 1024))
4119         (thhashtb (gnus-make-hashtable 1024))
4120         (prev threads)
4121         (result threads)
4122         ids references id gthread gid entered ref)
4123     (while threads
4124       (when (setq references (mail-header-references (caar threads)))
4125         (setq id (mail-header-id (caar threads))
4126               ids (inline (gnus-split-references references))
4127               entered nil)
4128         (while (setq ref (pop ids))
4129           (setq ids (delete ref ids))
4130           (if (not (setq gid (gnus-gethash ref idhashtb)))
4131               (progn
4132                 (gnus-sethash ref id idhashtb)
4133                 (gnus-sethash id threads thhashtb))
4134             (setq gthread (gnus-gethash gid thhashtb))
4135             (unless entered
4136               ;; We enter a dummy root into the thread, if we
4137               ;; haven't done that already.
4138               (unless (stringp (caar gthread))
4139                 (setcar gthread (list (mail-header-subject (caar gthread))
4140                                       (car gthread))))
4141               ;; We add this new gathered thread to this gathered
4142               ;; thread.
4143               (setcdr (car gthread)
4144                       (nconc (cdar gthread) (list (car threads)))))
4145             ;; Add it into the thread hash table.
4146             (gnus-sethash id gthread thhashtb)
4147             (setq entered t)
4148             ;; Remove it from the list of threads.
4149             (setcdr prev (cdr threads))
4150             (setq threads prev))))
4151       (setq prev threads)
4152       (setq threads (cdr threads)))
4153     result))
4154
4155 (defun gnus-sort-gathered-threads (threads)
4156   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4157   (let ((result threads))
4158     (while threads
4159       (when (stringp (caar threads))
4160         (setcdr (car threads)
4161                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4162       (setq threads (cdr threads)))
4163     result))
4164
4165 (defun gnus-thread-loop-p (root thread)
4166   "Say whether ROOT is in THREAD."
4167   (let ((stack (list thread))
4168         (infloop 0)
4169         th)
4170     (while (setq thread (pop stack))
4171       (setq th (cdr thread))
4172       (while (and th
4173                   (not (eq (caar th) root)))
4174         (pop th))
4175       (if th
4176           ;; We have found a loop.
4177           (let (ref-dep)
4178             (setcdr thread (delq (car th) (cdr thread)))
4179             (if (boundp (setq ref-dep (intern "none"
4180                                               gnus-newsgroup-dependencies)))
4181                 (setcdr (symbol-value ref-dep)
4182                         (nconc (cdr (symbol-value ref-dep))
4183                                (list (car th))))
4184               (set ref-dep (list nil (car th))))
4185             (setq infloop 1
4186                   stack nil))
4187         ;; Push all the subthreads onto the stack.
4188         (push (cdr thread) stack)))
4189     infloop))
4190
4191 (defun gnus-make-threads ()
4192   "Go through the dependency hashtb and find the roots.  Return all threads."
4193   (let (threads)
4194     (while (catch 'infloop
4195              (mapatoms
4196               (lambda (refs)
4197                 ;; Deal with self-referencing References loops.
4198                 (when (and (car (symbol-value refs))
4199                            (not (zerop
4200                                  (apply
4201                                   '+
4202                                   (mapcar
4203                                    (lambda (thread)
4204                                      (gnus-thread-loop-p
4205                                       (car (symbol-value refs)) thread))
4206                                    (cdr (symbol-value refs)))))))
4207                   (setq threads nil)
4208                   (throw 'infloop t))
4209                 (unless (car (symbol-value refs))
4210                   ;; These threads do not refer back to any other
4211                   ;; articles, so they're roots.
4212                   (setq threads (append (cdr (symbol-value refs)) threads))))
4213               gnus-newsgroup-dependencies)))
4214     threads))
4215
4216 ;; Build the thread tree.
4217 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4218   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4219
4220 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4221 if it was already present.
4222
4223 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4224 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4225 Message-IDs will be renamed to a unique Message-ID before being
4226 entered.
4227
4228 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4229   (let* ((id (mail-header-id header))
4230          (id-dep (and id (intern id dependencies)))
4231          parent-id ref ref-dep ref-header replaced)
4232     ;; Enter this `header' in the `dependencies' table.
4233     (cond
4234      ((not id-dep)
4235       (setq header nil))
4236      ;; The first two cases do the normal part: enter a new `header'
4237      ;; in the `dependencies' table.
4238      ((not (boundp id-dep))
4239       (set id-dep (list header)))
4240      ((null (car (symbol-value id-dep)))
4241       (setcar (symbol-value id-dep) header))
4242
4243      ;; From here the `header' was already present in the
4244      ;; `dependencies' table.
4245      (force-new
4246       ;; Overrides an existing entry;
4247       ;; just set the header part of the entry.
4248       (setcar (symbol-value id-dep) header)
4249       (setq replaced t))
4250
4251      ;; Renames the existing `header' to a unique Message-ID.
4252      ((not gnus-summary-ignore-duplicates)
4253       ;; An article with this Message-ID has already been seen.
4254       ;; We rename the Message-ID.
4255       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4256            (list header))
4257       (mail-header-set-id header id))
4258
4259      ;; The last case ignores an existing entry, except it adds any
4260      ;; additional Xrefs (in case the two articles came from different
4261      ;; servers.
4262      ;; Also sets `header' to `nil' meaning that the `dependencies'
4263      ;; table was *not* modified.
4264      (t
4265       (mail-header-set-xref
4266        (car (symbol-value id-dep))
4267        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4268                    "")
4269                (or (mail-header-xref header) "")))
4270       (setq header nil)))
4271
4272     (when (and header (not replaced))
4273       ;; First check that we are not creating a References loop.
4274       (setq parent-id (gnus-parent-id (mail-header-references header)))
4275       (setq ref parent-id)
4276       (while (and ref
4277                   (setq ref-dep (intern-soft ref dependencies))
4278                   (boundp ref-dep)
4279                   (setq ref-header (car (symbol-value ref-dep))))
4280         (if (string= id ref)
4281             ;; Yuk!  This is a reference loop.  Make the article be a
4282             ;; root article.
4283             (progn
4284               (mail-header-set-references (car (symbol-value id-dep)) "none")
4285               (setq ref nil)
4286               (setq parent-id nil))
4287           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4288       (setq ref-dep (intern (or parent-id "none") dependencies))
4289       (if (boundp ref-dep)
4290           (setcdr (symbol-value ref-dep)
4291                   (nconc (cdr (symbol-value ref-dep))
4292                          (list (symbol-value id-dep))))
4293         (set ref-dep (list nil (symbol-value id-dep)))))
4294     header))
4295
4296 (defun gnus-extract-message-id-from-in-reply-to (string)
4297   (if (string-match "<[^>]+>" string)
4298       (substring string (match-beginning 0) (match-end 0))
4299     nil))
4300
4301 (defun gnus-build-sparse-threads ()
4302   (let ((headers gnus-newsgroup-headers)
4303         (mail-parse-charset gnus-newsgroup-charset)
4304         (gnus-summary-ignore-duplicates t)
4305         header references generation relations
4306         subject child end new-child date)
4307     ;; First we create an alist of generations/relations, where
4308     ;; generations is how much we trust the relation, and the relation
4309     ;; is parent/child.
4310     (gnus-message 7 "Making sparse threads...")
4311     (save-excursion
4312       (nnheader-set-temp-buffer " *gnus sparse threads*")
4313       (while (setq header (pop headers))
4314         (when (and (setq references (mail-header-references header))
4315                    (not (string= references "")))
4316           (insert references)
4317           (setq child (mail-header-id header)
4318                 subject (mail-header-subject header)
4319                 date (mail-header-date header)
4320                 generation 0)
4321           (while (search-backward ">" nil t)
4322             (setq end (1+ (point)))
4323             (when (search-backward "<" nil t)
4324               (setq new-child (buffer-substring (point) end))
4325               (push (list (incf generation)
4326                           child (setq child new-child)
4327                           subject date)
4328                     relations)))
4329           (when child
4330             (push (list (1+ generation) child nil subject) relations))
4331           (erase-buffer)))
4332       (kill-buffer (current-buffer)))
4333     ;; Sort over trustworthiness.
4334     (dolist (relation (sort relations 'car-less-than-car))
4335       (when (gnus-dependencies-add-header
4336              (make-full-mail-header
4337               gnus-reffed-article-number
4338               (nth 3 relation) "" (or (nth 4 relation) "")
4339               (nth 1 relation)
4340               (or (nth 2 relation) "") 0 0 "")
4341              gnus-newsgroup-dependencies nil)
4342         (push gnus-reffed-article-number gnus-newsgroup-limit)
4343         (push gnus-reffed-article-number gnus-newsgroup-sparse)
4344         (push (cons gnus-reffed-article-number gnus-sparse-mark)
4345               gnus-newsgroup-reads)
4346         (decf gnus-reffed-article-number)))
4347     (gnus-message 7 "Making sparse threads...done")))
4348
4349 (defun gnus-build-old-threads ()
4350   ;; Look at all the articles that refer back to old articles, and
4351   ;; fetch the headers for the articles that aren't there.  This will
4352   ;; build complete threads - if the roots haven't been expired by the
4353   ;; server, that is.
4354   (let ((mail-parse-charset gnus-newsgroup-charset)
4355         id heads)
4356     (mapatoms
4357      (lambda (refs)
4358        (when (not (car (symbol-value refs)))
4359          (setq heads (cdr (symbol-value refs)))
4360          (while heads
4361            (if (memq (mail-header-number (caar heads))
4362                      gnus-newsgroup-dormant)
4363                (setq heads (cdr heads))
4364              (setq id (symbol-name refs))
4365              (while (and (setq id (gnus-build-get-header id))
4366                          (not (car (gnus-id-to-thread id)))))
4367              (setq heads nil)))))
4368      gnus-newsgroup-dependencies)))
4369
4370 (defsubst gnus-remove-odd-characters (string)
4371   "Translate STRING into something that doesn't contain weird characters."
4372   (mm-subst-char-in-string
4373    ?\r ?\-
4374    (mm-subst-char-in-string ?\n ?\- string t) t))
4375
4376 ;; This function has to be called with point after the article number
4377 ;; on the beginning of the line.
4378 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4379   (let ((eol (point-at-eol))
4380         (buffer (current-buffer))
4381         header references in-reply-to)
4382
4383     ;; overview: [num subject from date id refs chars lines misc]
4384     (unwind-protect
4385         (let (x)
4386           (narrow-to-region (point) eol)
4387           (unless (eobp)
4388             (forward-char))
4389
4390           (setq header
4391                 (make-full-mail-header
4392                  number                 ; number
4393                  (condition-case ()     ; subject
4394                      (gnus-remove-odd-characters
4395                       (funcall gnus-decode-encoded-word-function
4396                                (setq x (nnheader-nov-field))))
4397                    (error x))
4398                  (condition-case ()     ; from
4399                      (gnus-remove-odd-characters
4400                       (funcall gnus-decode-encoded-address-function
4401                                (setq x (nnheader-nov-field))))
4402                    (error x))
4403                  (nnheader-nov-field)   ; date
4404                  (nnheader-nov-read-message-id number)  ; id
4405                  (setq references (nnheader-nov-field)) ; refs
4406                  (nnheader-nov-read-integer) ; chars
4407                  (nnheader-nov-read-integer) ; lines
4408                  (unless (eobp)
4409                    (if (looking-at "Xref: ")
4410                        (goto-char (match-end 0)))
4411                    (nnheader-nov-field)) ; Xref
4412                  (nnheader-nov-parse-extra)))) ; extra
4413
4414       (widen))
4415
4416     (when (and (string= references "")
4417                (setq in-reply-to (mail-header-extra header))
4418                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4419       (mail-header-set-references
4420        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4421
4422     (when gnus-alter-header-function
4423       (funcall gnus-alter-header-function header))
4424     (gnus-dependencies-add-header header dependencies force-new)))
4425
4426 (defun gnus-build-get-header (id)
4427   "Look through the buffer of NOV lines and find the header to ID.
4428 Enter this line into the dependencies hash table, and return
4429 the id of the parent article (if any)."
4430   (let ((deps gnus-newsgroup-dependencies)
4431         found header)
4432     (prog1
4433         (save-excursion
4434           (set-buffer nntp-server-buffer)
4435           (let ((case-fold-search nil))
4436             (goto-char (point-min))
4437             (while (and (not found)
4438                         (search-forward id nil t))
4439               (beginning-of-line)
4440               (setq found (looking-at
4441                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4442                                    (regexp-quote id))))
4443               (or found (beginning-of-line 2)))
4444             (when found
4445               (beginning-of-line)
4446               (and
4447                (setq header (gnus-nov-parse-line
4448                              (read (current-buffer)) deps))
4449                (gnus-parent-id (mail-header-references header))))))
4450       (when header
4451         (let ((number (mail-header-number header)))
4452           (push number gnus-newsgroup-limit)
4453           (push header gnus-newsgroup-headers)
4454           (if (memq number gnus-newsgroup-unselected)
4455               (progn
4456                 (setq gnus-newsgroup-unreads
4457                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4458                                                number))
4459                 (setq gnus-newsgroup-unselected
4460                       (delq number gnus-newsgroup-unselected)))
4461             (push number gnus-newsgroup-ancient)))))))
4462
4463 (defun gnus-build-all-threads ()
4464   "Read all the headers."
4465   (let ((gnus-summary-ignore-duplicates t)
4466         (mail-parse-charset gnus-newsgroup-charset)
4467         (dependencies gnus-newsgroup-dependencies)
4468         header article)
4469     (save-excursion
4470       (set-buffer nntp-server-buffer)
4471       (let ((case-fold-search nil))
4472         (goto-char (point-min))
4473         (while (not (eobp))
4474           (ignore-errors
4475             (setq article (read (current-buffer))
4476                   header (gnus-nov-parse-line article dependencies)))
4477           (when header
4478             (with-current-buffer gnus-summary-buffer
4479               (push header gnus-newsgroup-headers)
4480               (if (memq (setq article (mail-header-number header))
4481                         gnus-newsgroup-unselected)
4482                   (progn
4483                     (setq gnus-newsgroup-unreads
4484                           (gnus-add-to-sorted-list
4485                            gnus-newsgroup-unreads article))
4486                     (setq gnus-newsgroup-unselected
4487                           (delq article gnus-newsgroup-unselected)))
4488                 (push article gnus-newsgroup-ancient)))
4489             (forward-line 1)))))))
4490
4491 (defun gnus-summary-update-article-line (article header)
4492   "Update the line for ARTICLE using HEADER."
4493   (let* ((id (mail-header-id header))
4494          (thread (gnus-id-to-thread id)))
4495     (unless thread
4496       (error "Article in no thread"))
4497     ;; Update the thread.
4498     (setcar thread header)
4499     (gnus-summary-goto-subject article)
4500     (let* ((datal (gnus-data-find-list article))
4501            (data (car datal))
4502            (buffer-read-only nil)
4503            (level (gnus-summary-thread-level)))
4504       (gnus-delete-line)
4505       (let ((inserted (- (point)
4506                          (progn
4507                            (gnus-summary-insert-line
4508                             header level nil
4509                             (memq article gnus-newsgroup-undownloaded)
4510                             (gnus-article-mark article)
4511                             (memq article gnus-newsgroup-replied)
4512                             (memq article gnus-newsgroup-expirable)
4513                             ;; Only insert the Subject string when it's different
4514                             ;; from the previous Subject string.
4515                             (if (and
4516                                  gnus-show-threads
4517                                  (gnus-subject-equal
4518                                   (condition-case ()
4519                                       (mail-header-subject
4520                                        (gnus-data-header
4521                                         (cadr
4522                                          (gnus-data-find-list
4523                                           article
4524                                           (gnus-data-list t)))))
4525                                     ;; Error on the side of excessive subjects.
4526                                     (error ""))
4527                                   (mail-header-subject header)))
4528                                 ""
4529                               (mail-header-subject header))
4530                             nil (cdr (assq article gnus-newsgroup-scored))
4531                             (memq article gnus-newsgroup-processable))
4532                            (point)))))
4533         (when (cdr datal)
4534           (gnus-data-update-list
4535            (cdr datal)
4536            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4537
4538 (defun gnus-summary-update-article (article &optional iheader)
4539   "Update ARTICLE in the summary buffer."
4540   (set-buffer gnus-summary-buffer)
4541   (let* ((header (gnus-summary-article-header article))
4542          (id (mail-header-id header))
4543          (data (gnus-data-find article))
4544          (thread (gnus-id-to-thread id))
4545          (references (mail-header-references header))
4546          (parent
4547           (gnus-id-to-thread
4548            (or (gnus-parent-id
4549                 (when (and references
4550                            (not (equal "" references)))
4551                   references))
4552                "none")))
4553          (buffer-read-only nil)
4554          (old (car thread)))
4555     (when thread
4556       (unless iheader
4557         (setcar thread nil)
4558         (when parent
4559           (delq thread parent)))
4560       (if (gnus-summary-insert-subject id header)
4561           ;; Set the (possibly) new article number in the data structure.
4562           (gnus-data-set-number data (gnus-id-to-article id))
4563         (setcar thread old)
4564         nil))))
4565
4566 (defun gnus-rebuild-thread (id &optional line)
4567   "Rebuild the thread containing ID.
4568 If LINE, insert the rebuilt thread starting on line LINE."
4569   (let ((buffer-read-only nil)
4570         old-pos current thread data)
4571     (if (not gnus-show-threads)
4572         (setq thread (list (car (gnus-id-to-thread id))))
4573       ;; Get the thread this article is part of.
4574       (setq thread (gnus-remove-thread id)))
4575     (setq old-pos (point-at-bol))
4576     (setq current (save-excursion
4577                     (and (re-search-backward "[\r\n]" nil t)
4578                          (gnus-summary-article-number))))
4579     ;; If this is a gathered thread, we have to go some re-gathering.
4580     (when (stringp (car thread))
4581       (let ((subject (car thread))
4582             roots thr)
4583         (setq thread (cdr thread))
4584         (while thread
4585           (unless (memq (setq thr (gnus-id-to-thread
4586                                    (gnus-root-id
4587                                     (mail-header-id (caar thread)))))
4588                         roots)
4589             (push thr roots))
4590           (setq thread (cdr thread)))
4591         ;; We now have all (unique) roots.
4592         (if (= (length roots) 1)
4593             ;; All the loose roots are now one solid root.
4594             (setq thread (car roots))
4595           (setq thread (cons subject (gnus-sort-threads roots))))))
4596     (let (threads)
4597       ;; We then insert this thread into the summary buffer.
4598       (when line
4599         (goto-char (point-min))
4600         (forward-line (1- line)))
4601       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4602         (if gnus-show-threads
4603             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4604           (gnus-summary-prepare-unthreaded thread))
4605         (setq data (nreverse gnus-newsgroup-data))
4606         (setq threads gnus-newsgroup-threads))
4607       ;; We splice the new data into the data structure.
4608       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4609       ;;!!! then we want to insert at the beginning of the buffer.
4610       ;;!!! That happens to be true with Gnus now, but that may
4611       ;;!!! change in the future.  Perhaps.
4612       (gnus-data-enter-list
4613        (if line nil current) data (- (point) old-pos))
4614       (setq gnus-newsgroup-threads
4615             (nconc threads gnus-newsgroup-threads))
4616       (gnus-data-compute-positions))))
4617
4618 (defun gnus-number-to-header (number)
4619   "Return the header for article NUMBER."
4620   (let ((headers gnus-newsgroup-headers))
4621     (while (and headers
4622                 (not (= number (mail-header-number (car headers)))))
4623       (pop headers))
4624     (when headers
4625       (car headers))))
4626
4627 (defun gnus-parent-headers (in-headers &optional generation)
4628   "Return the headers of the GENERATIONeth parent of HEADERS."
4629   (unless generation
4630     (setq generation 1))
4631   (let ((parent t)
4632         (headers in-headers)
4633         references)
4634     (while (and parent
4635                 (not (zerop generation))
4636                 (setq references (mail-header-references headers)))
4637       (setq headers (if (and references
4638                              (setq parent (gnus-parent-id references)))
4639                         (car (gnus-id-to-thread parent))
4640                       nil))
4641       (decf generation))
4642     (and (not (eq headers in-headers))
4643          headers)))
4644
4645 (defun gnus-id-to-thread (id)
4646   "Return the (sub-)thread where ID appears."
4647   (gnus-gethash id gnus-newsgroup-dependencies))
4648
4649 (defun gnus-id-to-article (id)
4650   "Return the article number of ID."
4651   (let ((thread (gnus-id-to-thread id)))
4652     (when (and thread
4653                (car thread))
4654       (mail-header-number (car thread)))))
4655
4656 (defun gnus-id-to-header (id)
4657   "Return the article headers of ID."
4658   (car (gnus-id-to-thread id)))
4659
4660 (defun gnus-article-displayed-root-p (article)
4661   "Say whether ARTICLE is a root(ish) article."
4662   (let ((level (gnus-summary-thread-level article))
4663         (refs (mail-header-references  (gnus-summary-article-header article)))
4664         particle)
4665     (cond
4666      ((null level) nil)
4667      ((zerop level) t)
4668      ((null refs) t)
4669      ((null (gnus-parent-id refs)) t)
4670      ((and (= 1 level)
4671            (null (setq particle (gnus-id-to-article
4672                                  (gnus-parent-id refs))))
4673            (null (gnus-summary-thread-level particle)))))))
4674
4675 (defun gnus-root-id (id)
4676   "Return the id of the root of the thread where ID appears."
4677   (let (last-id prev)
4678     (while (and id (setq prev (car (gnus-id-to-thread id))))
4679       (setq last-id id
4680             id (gnus-parent-id (mail-header-references prev))))
4681     last-id))
4682
4683 (defun gnus-articles-in-thread (thread)
4684   "Return the list of articles in THREAD."
4685   (cons (mail-header-number (car thread))
4686         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4687
4688 (defun gnus-remove-thread (id &optional dont-remove)
4689   "Remove the thread that has ID in it."
4690   (let (headers thread last-id)
4691     ;; First go up in this thread until we find the root.
4692     (setq last-id (gnus-root-id id)
4693           headers (message-flatten-list (gnus-id-to-thread last-id)))
4694     ;; We have now found the real root of this thread.  It might have
4695     ;; been gathered into some loose thread, so we have to search
4696     ;; through the threads to find the thread we wanted.
4697     (let ((threads gnus-newsgroup-threads)
4698           sub)
4699       (while threads
4700         (setq sub (car threads))
4701         (if (stringp (car sub))
4702             ;; This is a gathered thread, so we look at the roots
4703             ;; below it to find whether this article is in this
4704             ;; gathered root.
4705             (progn
4706               (setq sub (cdr sub))
4707               (while sub
4708                 (when (member (caar sub) headers)
4709                   (setq thread (car threads)
4710                         threads nil
4711                         sub nil))
4712                 (setq sub (cdr sub))))
4713           ;; It's an ordinary thread, so we check it.
4714           (when (eq (car sub) (car headers))
4715             (setq thread sub
4716                   threads nil)))
4717         (setq threads (cdr threads)))
4718       ;; If this article is in no thread, then it's a root.
4719       (if thread
4720           (unless dont-remove
4721             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4722         (setq thread (gnus-id-to-thread last-id)))
4723       (when thread
4724         (prog1
4725             thread                      ; We return this thread.
4726           (unless dont-remove
4727             (if (stringp (car thread))
4728                 (progn
4729                   ;; If we use dummy roots, then we have to remove the
4730                   ;; dummy root as well.
4731                   (when (eq gnus-summary-make-false-root 'dummy)
4732                     ;; We go to the dummy root by going to
4733                     ;; the first sub-"thread", and then one line up.
4734                     (gnus-summary-goto-article
4735                      (mail-header-number (caadr thread)))
4736                     (forward-line -1)
4737                     (gnus-delete-line)
4738                     (gnus-data-compute-positions))
4739                   (setq thread (cdr thread))
4740                   (while thread
4741                     (gnus-remove-thread-1 (car thread))
4742                     (setq thread (cdr thread))))
4743               (gnus-remove-thread-1 thread))))))))
4744
4745 (defun gnus-remove-thread-1 (thread)
4746   "Remove the thread THREAD recursively."
4747   (let ((number (mail-header-number (pop thread)))
4748         d)
4749     (setq thread (reverse thread))
4750     (while thread
4751       (gnus-remove-thread-1 (pop thread)))
4752     (when (setq d (gnus-data-find number))
4753       (goto-char (gnus-data-pos d))
4754       (gnus-summary-show-thread)
4755       (gnus-data-remove
4756        number
4757        (- (point-at-bol)
4758           (prog1
4759               (1+ (point-at-eol))
4760             (gnus-delete-line)))))))
4761
4762 (defun gnus-sort-threads-recursive (threads func)
4763   (sort (mapcar (lambda (thread)
4764                   (cons (car thread)
4765                         (and (cdr thread)
4766                              (gnus-sort-threads-recursive (cdr thread) func))))
4767                 threads) func))
4768
4769 (defun gnus-sort-threads-loop (threads func)
4770   (let* ((superthread (cons nil threads))
4771          (stack (list (cons superthread threads)))
4772          remaining-threads thread)
4773     (while stack
4774       (setq remaining-threads (cdr (car stack)))
4775       (if remaining-threads
4776           (progn (setq thread (car remaining-threads))
4777                  (setcdr (car stack) (cdr remaining-threads))
4778                  (if (cdr thread)
4779                      (push (cons thread (cdr thread)) stack)))
4780         (setq thread (caar stack))
4781         (setcdr thread (sort (cdr thread) func))
4782         (pop stack)))
4783     (cdr superthread)))
4784
4785 (defun gnus-sort-threads (threads)
4786   "Sort THREADS."
4787   (if (not gnus-thread-sort-functions)
4788       threads
4789     (gnus-message 8 "Sorting threads...")
4790     (prog1
4791         (condition-case nil
4792             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4793               (gnus-sort-threads-recursive
4794                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4795           ;; Even after binding max-lisp-eval-depth, the recursive
4796           ;; sorter might fail for very long threads.  In that case,
4797           ;; try using a (less well-tested) non-recursive sorter.
4798           (error (gnus-sort-threads-loop
4799                   threads (gnus-make-sort-function
4800                            gnus-thread-sort-functions))))
4801       (gnus-message 8 "Sorting threads...done"))))
4802
4803 (defun gnus-sort-articles (articles)
4804   "Sort ARTICLES."
4805   (when gnus-article-sort-functions
4806     (gnus-message 7 "Sorting articles...")
4807     (prog1
4808         (setq gnus-newsgroup-headers
4809               (sort articles (gnus-make-sort-function
4810                               gnus-article-sort-functions)))
4811       (gnus-message 7 "Sorting articles...done"))))
4812
4813 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4814 (defmacro gnus-thread-header (thread)
4815   "Return header of first article in THREAD.
4816 Note that THREAD must never, ever be anything else than a variable -
4817 using some other form will lead to serious barfage."
4818   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4819   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4820   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4821         (vector thread) 2))
4822
4823 (defsubst gnus-article-sort-by-number (h1 h2)
4824   "Sort articles by article number."
4825   (< (mail-header-number h1)
4826      (mail-header-number h2)))
4827
4828 (defun gnus-thread-sort-by-number (h1 h2)
4829   "Sort threads by root article number."
4830   (gnus-article-sort-by-number
4831    (gnus-thread-header h1) (gnus-thread-header h2)))
4832
4833 (defsubst gnus-article-sort-by-random (h1 h2)
4834   "Sort articles randomly."
4835   (zerop (random 2)))
4836
4837 (defun gnus-thread-sort-by-random (h1 h2)
4838   "Sort threads randomly."
4839   (gnus-article-sort-by-random
4840    (gnus-thread-header h1) (gnus-thread-header h2)))
4841
4842 (defsubst gnus-article-sort-by-lines (h1 h2)
4843   "Sort articles by article Lines header."
4844   (< (mail-header-lines h1)
4845      (mail-header-lines h2)))
4846
4847 (defun gnus-thread-sort-by-lines (h1 h2)
4848   "Sort threads by root article Lines header."
4849   (gnus-article-sort-by-lines
4850    (gnus-thread-header h1) (gnus-thread-header h2)))
4851
4852 (defsubst gnus-article-sort-by-chars (h1 h2)
4853   "Sort articles by octet length."
4854   (< (mail-header-chars h1)
4855      (mail-header-chars h2)))
4856
4857 (defun gnus-thread-sort-by-chars (h1 h2)
4858   "Sort threads by root article octet length."
4859   (gnus-article-sort-by-chars
4860    (gnus-thread-header h1) (gnus-thread-header h2)))
4861
4862 (defsubst gnus-article-sort-by-author (h1 h2)
4863   "Sort articles by root author."
4864   (gnus-string<
4865    (let ((extract (funcall
4866                    gnus-extract-address-components
4867                    (mail-header-from h1))))
4868      (or (car extract) (cadr extract) ""))
4869    (let ((extract (funcall
4870                    gnus-extract-address-components
4871                    (mail-header-from h2))))
4872      (or (car extract) (cadr extract) ""))))
4873
4874 (defun gnus-thread-sort-by-author (h1 h2)
4875   "Sort threads by root author."
4876   (gnus-article-sort-by-author
4877    (gnus-thread-header h1)  (gnus-thread-header h2)))
4878
4879 (defsubst gnus-article-sort-by-recipient (h1 h2)
4880   "Sort articles by recipient."
4881   (gnus-string<
4882    (let ((extract (funcall
4883                    gnus-extract-address-components
4884                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4885      (or (car extract) (cadr extract)))
4886    (let ((extract (funcall
4887                    gnus-extract-address-components
4888                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4889      (or (car extract) (cadr extract)))))
4890
4891 (defun gnus-thread-sort-by-recipient (h1 h2)
4892   "Sort threads by root recipient."
4893   (gnus-article-sort-by-recipient
4894    (gnus-thread-header h1) (gnus-thread-header h2)))
4895
4896 (defsubst gnus-article-sort-by-subject (h1 h2)
4897   "Sort articles by root subject."
4898   (gnus-string<
4899    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4900    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4901
4902 (defun gnus-thread-sort-by-subject (h1 h2)
4903   "Sort threads by root subject."
4904   (gnus-article-sort-by-subject
4905    (gnus-thread-header h1) (gnus-thread-header h2)))
4906
4907 (defsubst gnus-article-sort-by-date (h1 h2)
4908   "Sort articles by root article date."
4909   (time-less-p
4910    (gnus-date-get-time (mail-header-date h1))
4911    (gnus-date-get-time (mail-header-date h2))))
4912
4913 (defun gnus-thread-sort-by-date (h1 h2)
4914   "Sort threads by root article date."
4915   (gnus-article-sort-by-date
4916    (gnus-thread-header h1) (gnus-thread-header h2)))
4917
4918 (defsubst gnus-article-sort-by-score (h1 h2)
4919   "Sort articles by root article score.
4920 Unscored articles will be counted as having a score of zero."
4921   (> (or (cdr (assq (mail-header-number h1)
4922                     gnus-newsgroup-scored))
4923          gnus-summary-default-score 0)
4924      (or (cdr (assq (mail-header-number h2)
4925                     gnus-newsgroup-scored))
4926          gnus-summary-default-score 0)))
4927
4928 (defun gnus-thread-sort-by-score (h1 h2)
4929   "Sort threads by root article score."
4930   (gnus-article-sort-by-score
4931    (gnus-thread-header h1) (gnus-thread-header h2)))
4932
4933 (defun gnus-thread-sort-by-total-score (h1 h2)
4934   "Sort threads by the sum of all scores in the thread.
4935 Unscored articles will be counted as having a score of zero."
4936   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4937
4938 (defun gnus-thread-total-score (thread)
4939   ;; This function find the total score of THREAD.
4940   (cond
4941    ((null thread)
4942     0)
4943    ((consp thread)
4944     (if (stringp (car thread))
4945         (apply gnus-thread-score-function 0
4946                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4947       (gnus-thread-total-score-1 thread)))
4948    (t
4949     (gnus-thread-total-score-1 (list thread)))))
4950
4951 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4952   "Sort threads such that the thread with the most recently arrived article comes first."
4953   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4954
4955 (defun gnus-thread-highest-number (thread)
4956   "Return the highest article number in THREAD."
4957   (apply 'max (mapcar (lambda (header)
4958                         (mail-header-number header))
4959                       (message-flatten-list thread))))
4960
4961 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4962   "Sort threads such that the thread with the most recently dated article comes first."
4963   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4964
4965 (defun gnus-thread-latest-date (thread)
4966   "Return the highest article date in THREAD."
4967   (let ((previous-time 0))
4968     (apply 'max
4969            (mapcar
4970             (lambda (header)
4971               (setq previous-time
4972                     (condition-case ()
4973                         (time-to-seconds (mail-header-parse-date
4974                                           (mail-header-date header)))
4975                       (error previous-time))))
4976             (sort
4977              (message-flatten-list thread)
4978              (lambda (h1 h2)
4979                (< (mail-header-number h1)
4980                   (mail-header-number h2))))))))
4981
4982 (defun gnus-thread-total-score-1 (root)
4983   ;; This function find the total score of the thread below ROOT.
4984   (setq root (car root))
4985   (apply gnus-thread-score-function
4986          (or (append
4987               (mapcar 'gnus-thread-total-score
4988                       (cdr (gnus-id-to-thread (mail-header-id root))))
4989               (when (> (mail-header-number root) 0)
4990                 (list (or (cdr (assq (mail-header-number root)
4991                                      gnus-newsgroup-scored))
4992                           gnus-summary-default-score 0))))
4993              (list gnus-summary-default-score)
4994              '(0))))
4995
4996 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4997 (defvar gnus-tmp-prev-subject nil)
4998 (defvar gnus-tmp-false-parent nil)
4999 (defvar gnus-tmp-root-expunged nil)
5000 (defvar gnus-tmp-dummy-line nil)
5001
5002 (defun gnus-extra-header (type &optional header)
5003   "Return the extra header of TYPE."
5004   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
5005       ""))
5006
5007 (defvar gnus-tmp-thread-tree-header-string "")
5008
5009 (defcustom gnus-sum-thread-tree-root "> "
5010   "With %B spec, used for the root of a thread.
5011 If nil, use subject instead."
5012   :version "22.1"
5013   :type '(radio (const :format "%v  " nil) string)
5014   :group 'gnus-thread)
5015
5016 (defcustom gnus-sum-thread-tree-false-root "> "
5017   "With %B spec, used for a false root of a thread.
5018 If nil, use subject instead."
5019   :version "22.1"
5020   :type '(radio (const :format "%v  " nil) string)
5021   :group 'gnus-thread)
5022
5023 (defcustom gnus-sum-thread-tree-single-indent ""
5024   "With %B spec, used for a thread with just one message.
5025 If nil, use subject instead."
5026   :version "22.1"
5027   :type '(radio (const :format "%v  " nil) string)
5028   :group 'gnus-thread)
5029
5030 (defcustom gnus-sum-thread-tree-vertical "| "
5031   "With %B spec, used for drawing a vertical line."
5032   :version "22.1"
5033   :type 'string
5034   :group 'gnus-thread)
5035
5036 (defcustom gnus-sum-thread-tree-indent "  "
5037   "With %B spec, used for indenting."
5038   :version "22.1"
5039   :type 'string
5040   :group 'gnus-thread)
5041
5042 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5043   "With %B spec, used for a leaf with brothers."
5044   :version "22.1"
5045   :type 'string
5046   :group 'gnus-thread)
5047
5048 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5049   "With %B spec, used for a leaf without brothers."
5050   :version "22.1"
5051   :type 'string
5052   :group 'gnus-thread)
5053
5054 (defun gnus-summary-prepare-threads (threads)
5055   "Prepare summary buffer from THREADS and indentation LEVEL.
5056 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5057 or a straight list of headers."
5058   (gnus-message 7 "Generating summary...")
5059
5060   (setq gnus-newsgroup-threads threads)
5061   (beginning-of-line)
5062
5063   (let ((gnus-tmp-level 0)
5064         (default-score (or gnus-summary-default-score 0))
5065         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5066         (building-line-count gnus-summary-display-while-building)
5067         (building-count (integerp gnus-summary-display-while-building))
5068         thread number subject stack state gnus-tmp-gathered beg-match
5069         new-roots gnus-tmp-new-adopts thread-end simp-subject
5070         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5071         gnus-tmp-replied gnus-tmp-subject-or-nil
5072         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5073         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5074         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5075         tree-stack)
5076
5077     (setq gnus-tmp-prev-subject nil
5078           gnus-tmp-thread-tree-header-string "")
5079
5080     (if (vectorp (car threads))
5081         ;; If this is a straight (sic) list of headers, then a
5082         ;; threaded summary display isn't required, so we just create
5083         ;; an unthreaded one.
5084         (gnus-summary-prepare-unthreaded threads)
5085
5086       ;; Do the threaded display.
5087
5088       (if gnus-summary-display-while-building
5089           (switch-to-buffer (buffer-name)))
5090       (while (or threads stack gnus-tmp-new-adopts new-roots)
5091
5092         (if (and (= gnus-tmp-level 0)
5093                  (or (not stack)
5094                      (= (caar stack) 0))
5095                  (not gnus-tmp-false-parent)
5096                  (or gnus-tmp-new-adopts new-roots))
5097             (if gnus-tmp-new-adopts
5098                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5099                       thread (list (car gnus-tmp-new-adopts))
5100                       gnus-tmp-header (caar thread)
5101                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5102               (when new-roots
5103                 (setq thread (list (car new-roots))
5104                       gnus-tmp-header (caar thread)
5105                       new-roots (cdr new-roots))))
5106
5107           (if threads
5108               ;; If there are some threads, we do them before the
5109               ;; threads on the stack.
5110               (setq thread threads
5111                     gnus-tmp-header (caar thread))
5112             ;; There were no current threads, so we pop something off
5113             ;; the stack.
5114             (setq state (car stack)
5115                   gnus-tmp-level (car state)
5116                   tree-stack (cadr state)
5117                   thread (caddr state)
5118                   stack (cdr stack)
5119                   gnus-tmp-header (caar thread))))
5120
5121         (setq gnus-tmp-false-parent nil)
5122         (setq gnus-tmp-root-expunged nil)
5123         (setq thread-end nil)
5124
5125         (if (stringp gnus-tmp-header)
5126             ;; The header is a dummy root.
5127             (cond
5128              ((eq gnus-summary-make-false-root 'adopt)
5129               ;; We let the first article adopt the rest.
5130               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5131                                                (cddar thread)))
5132               (setq gnus-tmp-gathered
5133                     (nconc (mapcar
5134                             (lambda (h) (mail-header-number (car h)))
5135                             (cddar thread))
5136                            gnus-tmp-gathered))
5137               (setq thread (cons (list (caar thread)
5138                                        (cadar thread))
5139                                  (cdr thread)))
5140               (setq gnus-tmp-level -1
5141                     gnus-tmp-false-parent t))
5142              ((eq gnus-summary-make-false-root 'empty)
5143               ;; We print adopted articles with empty subject fields.
5144               (setq gnus-tmp-gathered
5145                     (nconc (mapcar
5146                             (lambda (h) (mail-header-number (car h)))
5147                             (cddar thread))
5148                            gnus-tmp-gathered))
5149               (setq gnus-tmp-level -1))
5150              ((eq gnus-summary-make-false-root 'dummy)
5151               ;; We remember that we probably want to output a dummy
5152               ;; root.
5153               (setq gnus-tmp-dummy-line gnus-tmp-header)
5154               (setq gnus-tmp-prev-subject gnus-tmp-header))
5155              (t
5156               ;; We do not make a root for the gathered
5157               ;; sub-threads at all.
5158               (setq gnus-tmp-level -1)))
5159
5160           (setq number (mail-header-number gnus-tmp-header)
5161                 subject (mail-header-subject gnus-tmp-header)
5162                 simp-subject (gnus-simplify-subject-fully subject))
5163
5164           (cond
5165            ;; If the thread has changed subject, we might want to make
5166            ;; this subthread into a root.
5167            ((and (null gnus-thread-ignore-subject)
5168                  (not (zerop gnus-tmp-level))
5169                  gnus-tmp-prev-subject
5170                  (not (string= gnus-tmp-prev-subject simp-subject)))
5171             (setq new-roots (nconc new-roots (list (car thread)))
5172                   thread-end t
5173                   gnus-tmp-header nil))
5174            ;; If the article lies outside the current limit,
5175            ;; then we do not display it.
5176            ((not (memq number gnus-newsgroup-limit))
5177             (setq gnus-tmp-gathered
5178                   (nconc (mapcar
5179                           (lambda (h) (mail-header-number (car h)))
5180                           (cdar thread))
5181                          gnus-tmp-gathered))
5182             (setq gnus-tmp-new-adopts (if (cdar thread)
5183                                           (append gnus-tmp-new-adopts
5184                                                   (cdar thread))
5185                                         gnus-tmp-new-adopts)
5186                   thread-end t
5187                   gnus-tmp-header nil)
5188             (when (zerop gnus-tmp-level)
5189               (setq gnus-tmp-root-expunged t)))
5190            ;; Perhaps this article is to be marked as read?
5191            ((and gnus-summary-mark-below
5192                  (< (or (cdr (assq number gnus-newsgroup-scored))
5193                         default-score)
5194                     gnus-summary-mark-below)
5195                  ;; Don't touch sparse articles.
5196                  (not (gnus-summary-article-sparse-p number))
5197                  (not (gnus-summary-article-ancient-p number)))
5198             (setq gnus-newsgroup-unreads
5199                   (delq number gnus-newsgroup-unreads))
5200             (if gnus-newsgroup-auto-expire
5201                 (setq gnus-newsgroup-expirable
5202                       (gnus-add-to-sorted-list
5203                        gnus-newsgroup-expirable number))
5204               (push (cons number gnus-low-score-mark)
5205                     gnus-newsgroup-reads))))
5206
5207           (when gnus-tmp-header
5208             ;; We may have an old dummy line to output before this
5209             ;; article.
5210             (when (and gnus-tmp-dummy-line
5211                        (gnus-subject-equal
5212                         gnus-tmp-dummy-line
5213                         (mail-header-subject gnus-tmp-header)))
5214               (gnus-summary-insert-dummy-line
5215                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5216               (setq gnus-tmp-dummy-line nil))
5217
5218             ;; Compute the mark.
5219             (setq gnus-tmp-unread (gnus-article-mark number))
5220
5221             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5222                                   gnus-tmp-header gnus-tmp-level)
5223                   gnus-newsgroup-data)
5224
5225             ;; Actually insert the line.
5226             (setq
5227              gnus-tmp-subject-or-nil
5228              (cond
5229               ((and gnus-thread-ignore-subject
5230                     gnus-tmp-prev-subject
5231                     (not (string= gnus-tmp-prev-subject simp-subject)))
5232                subject)
5233               ((zerop gnus-tmp-level)
5234                (if (and (eq gnus-summary-make-false-root 'empty)
5235                         (memq number gnus-tmp-gathered)
5236                         gnus-tmp-prev-subject
5237                         (string= gnus-tmp-prev-subject simp-subject))
5238                    gnus-summary-same-subject
5239                  subject))
5240               (t gnus-summary-same-subject)))
5241             (if (and (eq gnus-summary-make-false-root 'adopt)
5242                      (= gnus-tmp-level 1)
5243                      (memq number gnus-tmp-gathered))
5244                 (setq gnus-tmp-opening-bracket ?\<
5245                       gnus-tmp-closing-bracket ?\>)
5246               (setq gnus-tmp-opening-bracket ?\[
5247                     gnus-tmp-closing-bracket ?\]))
5248             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5249                 (gnus-make-thread-indent-array
5250                  (max (* 2 (length gnus-thread-indent-array))
5251                       gnus-tmp-level)))
5252             (setq
5253              gnus-tmp-indentation
5254              (aref gnus-thread-indent-array gnus-tmp-level)
5255              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5256              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5257                                 gnus-summary-default-score 0)
5258              gnus-tmp-score-char
5259              (if (or (null gnus-summary-default-score)
5260                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5261                          gnus-summary-zcore-fuzz))
5262                  ?                      ;Whitespace
5263                (if (< gnus-tmp-score gnus-summary-default-score)
5264                    gnus-score-below-mark gnus-score-over-mark))
5265              gnus-tmp-replied
5266              (cond ((memq number gnus-newsgroup-processable)
5267                     gnus-process-mark)
5268                    ((memq number gnus-newsgroup-cached)
5269                     gnus-cached-mark)
5270                    ((memq number gnus-newsgroup-replied)
5271                     gnus-replied-mark)
5272                    ((memq number gnus-newsgroup-forwarded)
5273                     gnus-forwarded-mark)
5274                    ((memq number gnus-newsgroup-saved)
5275                     gnus-saved-mark)
5276                    ((memq number gnus-newsgroup-recent)
5277                     gnus-recent-mark)
5278                    ((memq number gnus-newsgroup-unseen)
5279                     gnus-unseen-mark)
5280                    (t gnus-no-mark))
5281              gnus-tmp-downloaded
5282              (cond ((memq number gnus-newsgroup-undownloaded)
5283                     gnus-undownloaded-mark)
5284                    (gnus-newsgroup-agentized
5285                     gnus-downloaded-mark)
5286                    (t
5287                     gnus-no-mark))
5288              gnus-tmp-from (mail-header-from gnus-tmp-header)
5289              gnus-tmp-name
5290              (cond
5291               ((string-match "<[^>]+> *$" gnus-tmp-from)
5292                (setq beg-match (match-beginning 0))
5293                (or (and (string-match "^\".+\"" gnus-tmp-from)
5294                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5295                    (substring gnus-tmp-from 0 beg-match)))
5296               ((string-match "(.+)" gnus-tmp-from)
5297                (substring gnus-tmp-from
5298                           (1+ (match-beginning 0)) (1- (match-end 0))))
5299               (t gnus-tmp-from))
5300
5301              ;; Do the %B string
5302              gnus-tmp-thread-tree-header-string
5303              (cond
5304               ((not gnus-show-threads) "")
5305               ((zerop gnus-tmp-level)
5306                (cond ((cdar thread)
5307                       (or gnus-sum-thread-tree-root subject))
5308                      (gnus-tmp-new-adopts
5309                       (or gnus-sum-thread-tree-false-root subject))
5310                      (t
5311                       (or gnus-sum-thread-tree-single-indent subject))))
5312               (t
5313                (concat (apply 'concat
5314                               (mapcar (lambda (item)
5315                                         (if (= item 1)
5316                                             gnus-sum-thread-tree-vertical
5317                                           gnus-sum-thread-tree-indent))
5318                                       (cdr (reverse tree-stack))))
5319                        (if (nth 1 thread)
5320                            gnus-sum-thread-tree-leaf-with-other
5321                          gnus-sum-thread-tree-single-leaf)))))
5322             (when (string= gnus-tmp-name "")
5323               (setq gnus-tmp-name gnus-tmp-from))
5324             (unless (numberp gnus-tmp-lines)
5325               (setq gnus-tmp-lines -1))
5326             (if (= gnus-tmp-lines -1)
5327                 (setq gnus-tmp-lines "?")
5328               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5329               (gnus-put-text-property
5330              (point)
5331              (progn (eval gnus-summary-line-format-spec) (point))
5332                'gnus-number number)
5333             (when gnus-visual-p
5334               (forward-line -1)
5335               (gnus-run-hooks 'gnus-summary-update-hook)
5336               (forward-line 1))
5337
5338             (setq gnus-tmp-prev-subject simp-subject)))
5339
5340         (when (nth 1 thread)
5341           (push (list (max 0 gnus-tmp-level)
5342                       (copy-sequence tree-stack)
5343                       (nthcdr 1 thread))
5344                 stack))
5345         (push (if (nth 1 thread) 1 0) tree-stack)
5346         (incf gnus-tmp-level)
5347         (setq threads (if thread-end nil (cdar thread)))
5348         (if gnus-summary-display-while-building
5349             (if building-count
5350                 (progn
5351                   ;; use a set frequency
5352                   (setq building-line-count (1- building-line-count))
5353                   (when (= building-line-count 0)
5354                     (sit-for 0)
5355                     (setq building-line-count
5356                           gnus-summary-display-while-building)))
5357               ;; always
5358               (sit-for 0)))
5359         (unless threads
5360           (setq gnus-tmp-level 0)))))
5361   (gnus-message 7 "Generating summary...done"))
5362
5363 (defun gnus-summary-prepare-unthreaded (headers)
5364   "Generate an unthreaded summary buffer based on HEADERS."
5365   (let (header number mark)
5366
5367     (beginning-of-line)
5368
5369     (while headers
5370       ;; We may have to root out some bad articles...
5371       (when (memq (setq number (mail-header-number
5372                                 (setq header (pop headers))))
5373                   gnus-newsgroup-limit)
5374         ;; Mark article as read when it has a low score.
5375         (when (and gnus-summary-mark-below
5376                    (< (or (cdr (assq number gnus-newsgroup-scored))
5377                           gnus-summary-default-score 0)
5378                       gnus-summary-mark-below)
5379                    (not (gnus-summary-article-ancient-p number)))
5380           (setq gnus-newsgroup-unreads
5381                 (delq number gnus-newsgroup-unreads))
5382           (if gnus-newsgroup-auto-expire
5383               (push number gnus-newsgroup-expirable)
5384             (push (cons number gnus-low-score-mark)
5385                   gnus-newsgroup-reads)))
5386
5387         (setq mark (gnus-article-mark number))
5388         (push (gnus-data-make number mark (1+ (point)) header 0)
5389               gnus-newsgroup-data)
5390         (gnus-summary-insert-line
5391          header 0 number
5392          (memq number gnus-newsgroup-undownloaded)
5393          mark (memq number gnus-newsgroup-replied)
5394          (memq number gnus-newsgroup-expirable)
5395          (mail-header-subject header) nil
5396          (cdr (assq number gnus-newsgroup-scored))
5397          (memq number gnus-newsgroup-processable))))))
5398
5399 (defun gnus-summary-remove-list-identifiers ()
5400   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5401   (let ((regexp (if (consp gnus-list-identifiers)
5402                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5403                   gnus-list-identifiers))
5404         changed subject)
5405     (when regexp
5406       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5407       (dolist (header gnus-newsgroup-headers)
5408         (setq subject (mail-header-subject header)
5409               changed nil)
5410         (while (string-match regexp subject)
5411           (setq subject
5412                 (concat (substring subject 0 (match-beginning 1))
5413                         (substring subject (match-end 0)))
5414                 changed t))
5415         (when changed
5416           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5417             (setq subject
5418                   (concat (substring subject 0 (match-beginning 1))
5419                           (substring subject (match-end 1)))))
5420           (mail-header-set-subject header subject))))))
5421
5422 (defun gnus-fetch-headers (articles)
5423   "Fetch headers of ARTICLES."
5424   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5425     (gnus-message 5 "Fetching headers for %s..." name)
5426     (prog1
5427         (if (eq 'nov
5428                 (setq gnus-headers-retrieved-by
5429                       (gnus-retrieve-headers
5430                        articles gnus-newsgroup-name
5431                        ;; We might want to fetch old headers, but
5432                        ;; not if there is only 1 article.
5433                        (and (or (and
5434                                  (not (eq gnus-fetch-old-headers 'some))
5435                                  (not (numberp gnus-fetch-old-headers)))
5436                                 (> (length articles) 1))
5437                             gnus-fetch-old-headers))))
5438             (gnus-get-newsgroup-headers-xover
5439              articles nil nil gnus-newsgroup-name t)
5440           (gnus-get-newsgroup-headers))
5441       (gnus-message 5 "Fetching headers for %s...done" name))))
5442
5443 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5444   "Select newsgroup GROUP.
5445 If READ-ALL is non-nil, all articles in the group are selected.
5446 If SELECT-ARTICLES, only select those articles from GROUP."
5447   (let* ((entry (gnus-group-entry group))
5448          ;;!!! Dirty hack; should be removed.
5449          (gnus-summary-ignore-duplicates
5450           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5451               t
5452             gnus-summary-ignore-duplicates))
5453          (info (nth 2 entry))
5454          charset articles fetched-articles cached)
5455
5456     (unless (gnus-check-server
5457              (set (make-local-variable 'gnus-current-select-method)
5458                   (gnus-find-method-for-group group)))
5459       (error "Couldn't open server"))
5460     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5461
5462     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5463         (gnus-activate-group group)     ; Or we can activate it...
5464         (progn                          ; Or we bug out.
5465           (when (equal major-mode 'gnus-summary-mode)
5466             (gnus-kill-buffer (current-buffer)))
5467           (error
5468            "Couldn't activate group %s: %s"
5469            (mm-decode-coding-string group charset)
5470            (mm-decode-coding-string (gnus-status-message group) charset))))
5471
5472     (unless (gnus-request-group group t)
5473         (when (equal major-mode 'gnus-summary-mode)
5474           (gnus-kill-buffer (current-buffer)))
5475         (error "Couldn't request group %s: %s"
5476                (mm-decode-coding-string group charset)
5477                (mm-decode-coding-string (gnus-status-message group) charset)))
5478
5479     (when gnus-agent
5480       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5481
5482       (setq gnus-summary-use-undownloaded-faces
5483             (gnus-agent-find-parameter
5484              group
5485              'agent-enable-undownloaded-faces)))
5486
5487     (setq gnus-newsgroup-name group
5488           gnus-newsgroup-unselected nil
5489           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5490
5491     (let ((display (gnus-group-find-parameter group 'display)))
5492       (setq gnus-newsgroup-display
5493             (cond
5494              ((not (zerop (or (car-safe read-all) 0)))
5495               ;; The user entered the group with C-u SPC/RET, let's show
5496               ;; all articles.
5497               'gnus-not-ignore)
5498              ((eq display 'all)
5499               'gnus-not-ignore)
5500              ((arrayp display)
5501               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5502              ((numberp display)
5503               ;; The following is probably the "correct" solution, but
5504               ;; it makes Gnus fetch all headers and then limit the
5505               ;; articles (which is slow), so instead we hack the
5506               ;; select-articles parameter instead. -- Simon Josefsson
5507               ;; <jas@kth.se>
5508               ;;
5509               ;; (gnus-byte-compile
5510               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5511               ;;                         display)))))
5512               (setq select-articles
5513                     (gnus-uncompress-range
5514                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5515                              (if (> tmp 0)
5516                                  tmp
5517                                1))
5518                            (cdr (gnus-active group)))))
5519               nil)
5520              (t
5521               nil))))
5522
5523     (gnus-summary-setup-default-charset)
5524
5525     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5526     (when (gnus-virtual-group-p group)
5527       (setq cached gnus-newsgroup-cached))
5528
5529     (setq gnus-newsgroup-unreads
5530           (gnus-sorted-ndifference
5531            (gnus-sorted-ndifference gnus-newsgroup-unreads
5532                                     gnus-newsgroup-marked)
5533            gnus-newsgroup-dormant))
5534
5535     (setq gnus-newsgroup-processable nil)
5536
5537     (gnus-update-read-articles group gnus-newsgroup-unreads)
5538
5539     ;; Adjust and set lists of article marks.
5540     (when info
5541       (gnus-adjust-marked-articles info))
5542     (if (setq articles select-articles)
5543         (setq gnus-newsgroup-unselected
5544               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5545       (setq articles (gnus-articles-to-read group read-all)))
5546
5547     (cond
5548      ((null articles)
5549       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5550       'quit)
5551      ((eq articles 0) nil)
5552      (t
5553       ;; Init the dependencies hash table.
5554       (setq gnus-newsgroup-dependencies
5555             (gnus-make-hashtable (length articles)))
5556       (gnus-set-global-variables)
5557       ;; Retrieve the headers and read them in.
5558
5559       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5560
5561       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5562       (when cached
5563         (setq gnus-newsgroup-cached cached))
5564
5565       ;; Suppress duplicates?
5566       (when gnus-suppress-duplicates
5567         (gnus-dup-suppress-articles))
5568
5569       ;; Set the initial limit.
5570       (setq gnus-newsgroup-limit (copy-sequence articles))
5571       ;; Remove canceled articles from the list of unread articles.
5572       (setq fetched-articles
5573             (mapcar (lambda (headers) (mail-header-number headers))
5574                     gnus-newsgroup-headers))
5575       (setq gnus-newsgroup-articles fetched-articles)
5576       (setq gnus-newsgroup-unreads
5577             (gnus-sorted-nintersection
5578              gnus-newsgroup-unreads fetched-articles))
5579       (gnus-compute-unseen-list)
5580
5581       ;; Removed marked articles that do not exist.
5582       (gnus-update-missing-marks
5583        (gnus-sorted-difference articles fetched-articles))
5584       ;; We might want to build some more threads first.
5585       (when (and gnus-fetch-old-headers
5586                  (eq gnus-headers-retrieved-by 'nov))
5587         (if (eq gnus-fetch-old-headers 'invisible)
5588             (gnus-build-all-threads)
5589           (gnus-build-old-threads)))
5590       ;; Let the Gnus agent mark articles as read.
5591       (when gnus-agent
5592         (gnus-agent-get-undownloaded-list))
5593       ;; Remove list identifiers from subject
5594       (when gnus-list-identifiers
5595         (gnus-summary-remove-list-identifiers))
5596       ;; Check whether auto-expire is to be done in this group.
5597       (setq gnus-newsgroup-auto-expire
5598             (gnus-group-auto-expirable-p group))
5599       ;; Set up the article buffer now, if necessary.
5600       (unless (and gnus-single-article-buffer
5601                    (equal gnus-article-buffer "*Article*"))
5602         (gnus-article-setup-buffer))
5603       ;; First and last article in this newsgroup.
5604       (when gnus-newsgroup-headers
5605         (setq gnus-newsgroup-begin
5606               (mail-header-number (car gnus-newsgroup-headers))
5607               gnus-newsgroup-end
5608               (mail-header-number
5609                (gnus-last-element gnus-newsgroup-headers))))
5610       ;; GROUP is successfully selected.
5611       (or gnus-newsgroup-headers t)))))
5612
5613 (defun gnus-compute-unseen-list ()
5614   ;; The `seen' marks are treated specially.
5615   (if (not gnus-newsgroup-seen)
5616       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5617     (setq gnus-newsgroup-unseen
5618           (gnus-inverse-list-range-intersection
5619            gnus-newsgroup-articles gnus-newsgroup-seen))))
5620
5621 (declare-function gnus-get-predicate "gnus-agent" (predicate))
5622
5623 (defun gnus-summary-display-make-predicate (display)
5624   (require 'gnus-agent)
5625   (when (= (length display) 1)
5626     (setq display (car display)))
5627   (unless gnus-summary-display-cache
5628     (dolist (elem (append '((unread . unread)
5629                             (read . read)
5630                             (unseen . unseen))
5631                           gnus-article-mark-lists))
5632       (push (cons (cdr elem)
5633                   (gnus-byte-compile
5634                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5635             gnus-summary-display-cache)))
5636   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5637         (gnus-category-predicate-cache gnus-summary-display-cache))
5638     (gnus-get-predicate display)))
5639
5640 ;; Uses the dynamically bound `number' variable.
5641 (defvar number)
5642 (defun gnus-article-marked-p (type &optional article)
5643   (let ((article (or article number)))
5644     (cond
5645      ((eq type 'tick)
5646       (memq article gnus-newsgroup-marked))
5647      ((eq type 'spam)
5648       (memq article gnus-newsgroup-spam-marked))
5649      ((eq type 'unsend)
5650       (memq article gnus-newsgroup-unsendable))
5651      ((eq type 'undownload)
5652       (memq article gnus-newsgroup-undownloaded))
5653      ((eq type 'download)
5654       (memq article gnus-newsgroup-downloadable))
5655      ((eq type 'unread)
5656       (memq article gnus-newsgroup-unreads))
5657      ((eq type 'read)
5658       (memq article gnus-newsgroup-reads))
5659      ((eq type 'dormant)
5660       (memq article gnus-newsgroup-dormant) )
5661      ((eq type 'expire)
5662       (memq article gnus-newsgroup-expirable))
5663      ((eq type 'reply)
5664       (memq article gnus-newsgroup-replied))
5665      ((eq type 'killed)
5666       (memq article gnus-newsgroup-killed))
5667      ((eq type 'bookmark)
5668       (assq article gnus-newsgroup-bookmarks))
5669      ((eq type 'score)
5670       (assq article gnus-newsgroup-scored))
5671      ((eq type 'save)
5672       (memq article gnus-newsgroup-saved))
5673      ((eq type 'cache)
5674       (memq article gnus-newsgroup-cached))
5675      ((eq type 'forward)
5676       (memq article gnus-newsgroup-forwarded))
5677      ((eq type 'seen)
5678       (not (memq article gnus-newsgroup-unseen)))
5679      ((eq type 'recent)
5680       (memq article gnus-newsgroup-recent))
5681      (t t))))
5682
5683 (defun gnus-articles-to-read (group &optional read-all)
5684   "Find out what articles the user wants to read."
5685   (let* ((articles
5686           ;; Select all articles if `read-all' is non-nil, or if there
5687           ;; are no unread articles.
5688           (if (or read-all
5689                   (and (zerop (length gnus-newsgroup-marked))
5690                        (zerop (length gnus-newsgroup-unreads)))
5691                   ;; Fetch all if the predicate is non-nil.
5692                   gnus-newsgroup-display)
5693               ;; We want to select the headers for all the articles in
5694               ;; the group, so we select either all the active
5695               ;; articles in the group, or (if that's nil), the
5696               ;; articles in the cache.
5697               (or
5698                (if gnus-newsgroup-maximum-articles
5699                    (let ((active (gnus-active group)))
5700                      (gnus-uncompress-range
5701                       (cons (max (car active)
5702                                  (- (cdr active)
5703                                     gnus-newsgroup-maximum-articles
5704                                     -1))
5705                             (cdr active))))
5706                  (gnus-uncompress-range (gnus-active group)))
5707                (gnus-cache-articles-in-group group))
5708             ;; Select only the "normal" subset of articles.
5709             (gnus-sorted-nunion
5710              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5711              gnus-newsgroup-unreads)))
5712          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5713          (scored (length scored-list))
5714          (number (length articles))
5715          (marked (+ (length gnus-newsgroup-marked)
5716                     (length gnus-newsgroup-dormant)))
5717          (select
5718           (cond
5719            ((numberp read-all)
5720             read-all)
5721            ((numberp gnus-newsgroup-display)
5722             gnus-newsgroup-display)
5723            (t
5724             (condition-case ()
5725                 (cond
5726                  ((and (or (<= scored marked) (= scored number))
5727                        (numberp gnus-large-newsgroup)
5728                        (> number gnus-large-newsgroup))
5729                   (let* ((cursor-in-echo-area nil)
5730                          (initial (gnus-parameter-large-newsgroup-initial
5731                                    gnus-newsgroup-name))
5732                          (input
5733                           (read-string
5734                            (format
5735                             "How many articles from %s (%s %d): "
5736                             (gnus-group-decoded-name gnus-newsgroup-name)
5737                             (if initial "max" "default")
5738                             number)
5739                            (if initial
5740                                (cons (number-to-string initial)
5741                                      0)))))
5742                     (if (string-match "^[ \t]*$" input) number input)))
5743                  ((and (> scored marked) (< scored number)
5744                        (> (- scored number) 20))
5745                   (let ((input
5746                          (read-string
5747                           (format "%s %s (%d scored, %d total): "
5748                                   "How many articles from"
5749                                   (gnus-group-decoded-name group)
5750                                   scored number))))
5751                     (if (string-match "^[ \t]*$" input)
5752                         number input)))
5753                  (t number))
5754               (quit
5755                (message "Quit getting the articles to read")
5756                nil))))))
5757     (setq select (if (stringp select) (string-to-number select) select))
5758     (if (or (null select) (zerop select))
5759         select
5760       (if (and (not (zerop scored)) (<= (abs select) scored))
5761           (progn
5762             (setq articles (sort scored-list '<))
5763             (setq number (length articles)))
5764         (setq articles (copy-sequence articles)))
5765
5766       (when (< (abs select) number)
5767         (if (< select 0)
5768             ;; Select the N oldest articles.
5769             (setcdr (nthcdr (1- (abs select)) articles) nil)
5770           ;; Select the N most recent articles.
5771           (setq articles (nthcdr (- number select) articles))))
5772       (setq gnus-newsgroup-unselected
5773             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5774       (when gnus-alter-articles-to-read-function
5775         (setq articles
5776               (sort
5777                (funcall gnus-alter-articles-to-read-function
5778                         gnus-newsgroup-name articles)
5779                '<)))
5780       articles)))
5781
5782 (defun gnus-killed-articles (killed articles)
5783   (let (out)
5784     (while articles
5785       (when (inline (gnus-member-of-range (car articles) killed))
5786         (push (car articles) out))
5787       (setq articles (cdr articles)))
5788     out))
5789
5790 (defun gnus-uncompress-marks (marks)
5791   "Uncompress the mark ranges in MARKS."
5792   (let ((uncompressed '(score bookmark))
5793         out)
5794     (while marks
5795       (if (memq (caar marks) uncompressed)
5796           (push (car marks) out)
5797         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5798       (setq marks (cdr marks)))
5799     out))
5800
5801 (defun gnus-article-mark-to-type (mark)
5802   "Return the type of MARK."
5803   (or (cadr (assq mark gnus-article-special-mark-lists))
5804       'list))
5805
5806 (defun gnus-article-unpropagatable-p (mark)
5807   "Return whether MARK should be propagated to back end."
5808   (memq mark gnus-article-unpropagated-mark-lists))
5809
5810 (defun gnus-adjust-marked-articles (info)
5811   "Set all article lists and remove all marks that are no longer valid."
5812   (let* ((marked-lists (gnus-info-marks info))
5813          (active (gnus-active (gnus-info-group info)))
5814          (min (car active))
5815          (max (cdr active))
5816          (types gnus-article-mark-lists)
5817          marks var articles article mark mark-type
5818          bgn end)
5819
5820     (dolist (marks marked-lists)
5821       (setq mark (car marks)
5822             mark-type (gnus-article-mark-to-type mark)
5823             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5824
5825       ;; We set the variable according to the type of the marks list,
5826       ;; and then adjust the marks to a subset of the active articles.
5827       (cond
5828        ;; Adjust "simple" lists - compressed yet unsorted
5829        ((eq mark-type 'list)
5830         ;; Simultaneously uncompress and clip to active range
5831         ;; See gnus-uncompress-range for a description of possible marks
5832         (let (l lh)
5833           (if (not (cadr marks))
5834               (set var nil)
5835             (setq articles (if (numberp (cddr marks))
5836                                (list (cdr marks))
5837                              (cdr marks))
5838                   lh (cons nil nil)
5839                   l lh)
5840
5841             (while (setq article (pop articles))
5842               (cond ((consp article)
5843                      (setq bgn (max (car article) min)
5844                            end (min (cdr article) max))
5845                      (while (<= bgn end)
5846                        (setq l (setcdr l (cons bgn nil))
5847                              bgn (1+ bgn))))
5848                     ((and (<= min article)
5849                           (>= max article))
5850                      (setq l (setcdr l (cons article nil))))))
5851             (set var (cdr lh)))))
5852        ;; Adjust assocs.
5853        ((eq mark-type 'tuple)
5854         (set var (setq articles (cdr marks)))
5855         (when (not (listp (cdr (symbol-value var))))
5856           (set var (list (symbol-value var))))
5857         (when (not (listp (cdr articles)))
5858           (setq articles (list articles)))
5859         (while articles
5860           (when (or (not (consp (setq article (pop articles))))
5861                     (< (car article) min)
5862                     (> (car article) max))
5863             (set var (delq article (symbol-value var))))))
5864        ;; Adjust ranges (sloppily).
5865        ((eq mark-type 'range)
5866         (cond
5867          ((eq mark 'seen)
5868           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5869           ;; It should be (seen (NUM1 . NUM2)).
5870           (when (numberp (cddr marks))
5871             (setcdr marks (list (cdr marks))))
5872           (setq articles (cdr marks))
5873           (while (and articles
5874                       (or (and (consp (car articles))
5875                                (> min (cdar articles)))
5876                           (and (numberp (car articles))
5877                                (> min (car articles)))))
5878             (pop articles))
5879           (set var articles))))))))
5880
5881 (defun gnus-update-missing-marks (missing)
5882   "Go through the list of MISSING articles and remove them from the mark lists."
5883   (when missing
5884     (let (var m)
5885       ;; Go through all types.
5886       (dolist (elem gnus-article-mark-lists)
5887         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5888           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5889           (when (symbol-value var)
5890             ;; This list has articles.  So we delete all missing
5891             ;; articles from it.
5892             (setq m missing)
5893             (while m
5894               (set var (delq (pop m) (symbol-value var))))))))))
5895
5896 (defun gnus-update-marks ()
5897   "Enter the various lists of marked articles into the newsgroup info list."
5898   (let ((types gnus-article-mark-lists)
5899         (info (gnus-get-info gnus-newsgroup-name))
5900         type list newmarked symbol delta-marks)
5901     (when info
5902       ;; Add all marks lists to the list of marks lists.
5903       (while (setq type (pop types))
5904         (setq list (symbol-value
5905                     (setq symbol
5906                           (intern (format "gnus-newsgroup-%s" (car type))))))
5907
5908         (when list
5909           ;; Get rid of the entries of the articles that have the
5910           ;; default score.
5911           (when (and (eq (cdr type) 'score)
5912                      gnus-save-score
5913                      list)
5914             (let* ((arts list)
5915                    (prev (cons nil list))
5916                    (all prev))
5917               (while arts
5918                 (if (or (not (consp (car arts)))
5919                         (= (cdar arts) gnus-summary-default-score))
5920                     (setcdr prev (cdr arts))
5921                   (setq prev arts))
5922                 (setq arts (cdr arts)))
5923               (setq list (cdr all)))))
5924
5925         (when (eq (cdr type) 'seen)
5926           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5927
5928         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5929           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5930
5931         (when (and (gnus-check-backend-function
5932                     'request-set-mark gnus-newsgroup-name)
5933                    (not (gnus-article-unpropagatable-p (cdr type))))
5934           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5935                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5936                  (add (gnus-remove-from-range
5937                        (gnus-copy-sequence list) old)))
5938             (when add
5939               (push (list add 'add (list (cdr type))) delta-marks))
5940             (when del
5941               (push (list del 'del (list (cdr type))) delta-marks))))
5942
5943         (when list
5944           (push (cons (cdr type) list) newmarked)))
5945
5946       (when delta-marks
5947         (unless (gnus-check-group gnus-newsgroup-name)
5948           (error "Can't open server for %s" gnus-newsgroup-name))
5949         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5950
5951       ;; Enter these new marks into the info of the group.
5952       (if (nthcdr 3 info)
5953           (setcar (nthcdr 3 info) newmarked)
5954         ;; Add the marks lists to the end of the info.
5955         (when newmarked
5956           (setcdr (nthcdr 2 info) (list newmarked))))
5957
5958       ;; Cut off the end of the info if there's nothing else there.
5959       (let ((i 5))
5960         (while (and (> i 2)
5961                     (not (nth i info)))
5962           (when (nthcdr (decf i) info)
5963             (setcdr (nthcdr i info) nil)))))))
5964
5965 (defun gnus-set-mode-line (where)
5966   "Set the mode line of the article or summary buffers.
5967 If WHERE is `summary', the summary mode line format will be used."
5968   ;; Is this mode line one we keep updated?
5969   (when (and (memq where gnus-updated-mode-lines)
5970              (symbol-value
5971               (intern (format "gnus-%s-mode-line-format-spec" where))))
5972     (let (mode-string)
5973       (save-excursion
5974         ;; We evaluate this in the summary buffer since these
5975         ;; variables are buffer-local to that buffer.
5976         (set-buffer gnus-summary-buffer)
5977        ;; We bind all these variables that are used in the `eval' form
5978         ;; below.
5979         (let* ((mformat (symbol-value
5980                          (intern
5981                           (format "gnus-%s-mode-line-format-spec" where))))
5982                (gnus-tmp-group-name (gnus-mode-string-quote
5983                                      (gnus-group-decoded-name
5984                                       gnus-newsgroup-name)))
5985                (gnus-tmp-article-number (or gnus-current-article 0))
5986                (gnus-tmp-unread gnus-newsgroup-unreads)
5987                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5988                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5989                (gnus-tmp-unread-and-unselected
5990                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5991                             (zerop gnus-tmp-unselected))
5992                        "")
5993                       ((zerop gnus-tmp-unselected)
5994                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5995                       (t (format "{%d(+%d) more}"
5996                                  gnus-tmp-unread-and-unticked
5997                                  gnus-tmp-unselected))))
5998                (gnus-tmp-subject
5999                 (if (and gnus-current-headers
6000                          (vectorp gnus-current-headers))
6001                     (gnus-mode-string-quote
6002                      (mail-header-subject gnus-current-headers))
6003                   ""))
6004                bufname-length max-len
6005                gnus-tmp-header) ;; passed as argument to any user-format-funcs
6006           (setq mode-string (eval mformat))
6007           (setq bufname-length (if (string-match "%b" mode-string)
6008                                    (- (length
6009                                        (buffer-name
6010                                         (if (eq where 'summary)
6011                                             nil
6012                                           (get-buffer gnus-article-buffer))))
6013                                       2)
6014                                  0))
6015           (setq max-len (max 4 (if gnus-mode-non-string-length
6016                                    (- (window-width)
6017                                       gnus-mode-non-string-length
6018                                       bufname-length)
6019                                  (length mode-string))))
6020           ;; We might have to chop a bit of the string off...
6021           (when (> (length mode-string) max-len)
6022             (setq mode-string
6023                   (concat (truncate-string-to-width mode-string (- max-len 3))
6024                           "...")))
6025           ;; Pad the mode string a bit.
6026           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
6027       ;; Update the mode line.
6028       (setq mode-line-buffer-identification
6029             (gnus-mode-line-buffer-identification (list mode-string)))
6030       (set-buffer-modified-p t))))
6031
6032 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6033   "Go through the HEADERS list and add all Xrefs to a hash table.
6034 The resulting hash table is returned, or nil if no Xrefs were found."
6035   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
6036          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
6037          (xref-hashtb (gnus-make-hashtable))
6038          start group entry number xrefs header)
6039     (while headers
6040       (setq header (pop headers))
6041       (when (and (setq xrefs (mail-header-xref header))
6042                  (not (memq (setq number (mail-header-number header))
6043                             unreads)))
6044         (setq start 0)
6045         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6046           (setq start (match-end 0))
6047           (setq group (if prefix
6048                           (concat prefix (substring xrefs (match-beginning 1)
6049                                                     (match-end 1)))
6050                         (substring xrefs (match-beginning 1) (match-end 1))))
6051           (setq number
6052                 (string-to-number (substring xrefs (match-beginning 2)
6053                                           (match-end 2))))
6054           (if (setq entry (gnus-gethash group xref-hashtb))
6055               (setcdr entry (cons number (cdr entry)))
6056             (gnus-sethash group (cons number nil) xref-hashtb)))))
6057     (and start xref-hashtb)))
6058
6059 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6060   "Look through all the headers and mark the Xrefs as read."
6061   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6062         name info xref-hashtb idlist method nth4)
6063     (save-excursion
6064       (set-buffer gnus-group-buffer)
6065       (when (setq xref-hashtb
6066                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6067         (mapatoms
6068          (lambda (group)
6069            (unless (string= from-newsgroup (setq name (symbol-name group)))
6070              (setq idlist (symbol-value group))
6071              ;; Dead groups are not updated.
6072              (and (prog1
6073                       (setq info (gnus-get-info name))
6074                     (when (stringp (setq nth4 (gnus-info-method info)))
6075                       (setq nth4 (gnus-server-to-method nth4))))
6076                   ;; Only do the xrefs if the group has the same
6077                   ;; select method as the group we have just read.
6078                   (or (gnus-methods-equal-p
6079                        nth4 (gnus-find-method-for-group from-newsgroup))
6080                       virtual
6081                       (equal nth4 (setq method (gnus-find-method-for-group
6082                                                 from-newsgroup)))
6083                       (and (equal (car nth4) (car method))
6084                            (equal (nth 1 nth4) (nth 1 method))))
6085                   gnus-use-cross-reference
6086                   (or (not (eq gnus-use-cross-reference t))
6087                       virtual
6088                       ;; Only do cross-references on subscribed
6089                       ;; groups, if that is what is wanted.
6090                       (<= (gnus-info-level info) gnus-level-subscribed))
6091                   (gnus-group-make-articles-read name idlist))))
6092          xref-hashtb)))))
6093
6094 (defun gnus-compute-read-articles (group articles)
6095   (let* ((entry (gnus-group-entry group))
6096          (info (nth 2 entry))
6097          (active (gnus-active group))
6098          ninfo)
6099     (when entry
6100       ;; First peel off all invalid article numbers.
6101       (when active
6102         (let ((ids articles)
6103               id first)
6104           (while (setq id (pop ids))
6105             (when (and first (> id (cdr active)))
6106               ;; We'll end up in this situation in one particular
6107               ;; obscure situation.  If you re-scan a group and get
6108               ;; a new article that is cross-posted to a different
6109               ;; group that has not been re-scanned, you might get
6110               ;; crossposted article that has a higher number than
6111               ;; Gnus believes possible.  So we re-activate this
6112               ;; group as well.  This might mean doing the
6113               ;; crossposting thingy will *increase* the number
6114               ;; of articles in some groups.  Tsk, tsk.
6115               (setq active (or (gnus-activate-group group) active)))
6116             (when (or (> id (cdr active))
6117                       (< id (car active)))
6118               (setq articles (delq id articles))))))
6119       ;; If the read list is nil, we init it.
6120       (if (and active
6121                (null (gnus-info-read info))
6122                (> (car active) 1))
6123           (setq ninfo (cons 1 (1- (car active))))
6124         (setq ninfo (gnus-info-read info)))
6125       ;; Then we add the read articles to the range.
6126       (gnus-add-to-range
6127        ninfo (setq articles (sort articles '<))))))
6128
6129 (defun gnus-group-make-articles-read (group articles)
6130   "Update the info of GROUP to say that ARTICLES are read."
6131   (let* ((num 0)
6132          (entry (gnus-group-entry group))
6133          (info (nth 2 entry))
6134          (active (gnus-active group))
6135          range)
6136     (when entry
6137       (setq range (gnus-compute-read-articles group articles))
6138       (with-current-buffer gnus-group-buffer
6139         (gnus-undo-register
6140           `(progn
6141              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6142              (gnus-info-set-read ',info ',(gnus-info-read info))
6143              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6144              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6145              (gnus-group-update-group ,group t))))
6146       ;; Add the read articles to the range.
6147       (gnus-info-set-read info range)
6148       (gnus-request-set-mark group (list (list range 'add '(read))))
6149       ;; Then we have to re-compute how many unread
6150       ;; articles there are in this group.
6151       (when active
6152         (cond
6153          ((not range)
6154           (setq num (- (1+ (cdr active)) (car active))))
6155          ((not (listp (cdr range)))
6156           (setq num (- (cdr active) (- (1+ (cdr range))
6157                                        (car range)))))
6158          (t
6159           (while range
6160             (if (numberp (car range))
6161                 (setq num (1+ num))
6162               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6163             (setq range (cdr range)))
6164           (setq num (- (cdr active) num))))
6165         ;; Update the number of unread articles.
6166         (setcar entry num)
6167         ;; Update the group buffer.
6168         (unless (gnus-ephemeral-group-p group)
6169           (gnus-group-update-group group t))))))
6170
6171 (defvar gnus-newsgroup-none-id 0)
6172
6173 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6174   (let ((cur nntp-server-buffer)
6175         (dependencies
6176          (or dependencies
6177              (with-current-buffer gnus-summary-buffer
6178                gnus-newsgroup-dependencies)))
6179         headers id end ref number
6180         (mail-parse-charset gnus-newsgroup-charset)
6181         (mail-parse-ignored-charsets
6182          (save-excursion (condition-case nil
6183                              (set-buffer gnus-summary-buffer)
6184                            (error))
6185                          gnus-newsgroup-ignored-charsets)))
6186     (save-excursion
6187       (set-buffer nntp-server-buffer)
6188       ;; Translate all TAB characters into SPACE characters.
6189       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6190       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6191       (ietf-drums-unfold-fws)
6192       (gnus-run-hooks 'gnus-parse-headers-hook)
6193       (let ((case-fold-search t)
6194             in-reply-to header p lines chars)
6195         (goto-char (point-min))
6196         ;; Search to the beginning of the next header.  Error messages
6197         ;; do not begin with 2 or 3.
6198         (while (re-search-forward "^[23][0-9]+ " nil t)
6199           (setq id nil
6200                 ref nil)
6201           ;; This implementation of this function, with nine
6202           ;; search-forwards instead of the one re-search-forward and
6203           ;; a case (which basically was the old function) is actually
6204           ;; about twice as fast, even though it looks messier.  You
6205           ;; can't have everything, I guess.  Speed and elegance
6206           ;; doesn't always go hand in hand.
6207           (setq
6208            header
6209            (vector
6210             ;; Number.
6211             (prog1
6212                 (setq number (read cur))
6213               (end-of-line)
6214               (setq p (point))
6215               (narrow-to-region (point)
6216                                 (or (and (search-forward "\n.\n" nil t)
6217                                          (- (point) 2))
6218                                     (point))))
6219             ;; Subject.
6220             (progn
6221               (goto-char p)
6222               (if (search-forward "\nsubject:" nil t)
6223                   (funcall gnus-decode-encoded-word-function
6224                            (nnheader-header-value))
6225                 "(none)"))
6226             ;; From.
6227             (progn
6228               (goto-char p)
6229               (if (search-forward "\nfrom:" nil t)
6230                   (funcall gnus-decode-encoded-address-function
6231                            (nnheader-header-value))
6232                 "(nobody)"))
6233             ;; Date.
6234             (progn
6235               (goto-char p)
6236               (if (search-forward "\ndate:" nil t)
6237                   (nnheader-header-value) ""))
6238             ;; Message-ID.
6239             (progn
6240               (goto-char p)
6241               (setq id (if (re-search-forward
6242                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6243                            ;; We do it this way to make sure the Message-ID
6244                            ;; is (somewhat) syntactically valid.
6245                            (buffer-substring (match-beginning 1)
6246                                              (match-end 1))
6247                          ;; If there was no message-id, we just fake one
6248                          ;; to make subsequent routines simpler.
6249                          (nnheader-generate-fake-message-id number))))
6250             ;; References.
6251             (progn
6252               (goto-char p)
6253               (if (search-forward "\nreferences:" nil t)
6254                   (progn
6255                     (setq end (point))
6256                     (prog1
6257                         (nnheader-header-value)
6258                       (setq ref
6259                             (buffer-substring
6260                              (progn
6261                                (end-of-line)
6262                                (search-backward ">" end t)
6263                                (1+ (point)))
6264                              (progn
6265                                (search-backward "<" end t)
6266                                (point))))))
6267                 ;; Get the references from the in-reply-to header if there
6268                 ;; were no references and the in-reply-to header looks
6269                 ;; promising.
6270                 (if (and (search-forward "\nin-reply-to:" nil t)
6271                          (setq in-reply-to (nnheader-header-value))
6272                          (string-match "<[^>]+>" in-reply-to))
6273                     (let (ref2)
6274                       (setq ref (substring in-reply-to (match-beginning 0)
6275                                            (match-end 0)))
6276                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6277                         (setq ref2 (substring in-reply-to (match-beginning 0)
6278                                               (match-end 0)))
6279                         (when (> (length ref2) (length ref))
6280                           (setq ref ref2)))
6281                       ref)
6282                   (setq ref nil))))
6283             ;; Chars.
6284             (progn
6285               (goto-char p)
6286               (if (search-forward "\nchars: " nil t)
6287                   (if (numberp (setq chars (ignore-errors (read cur))))
6288                       chars -1)
6289                 -1))
6290             ;; Lines.
6291             (progn
6292               (goto-char p)
6293               (if (search-forward "\nlines: " nil t)
6294                   (if (numberp (setq lines (ignore-errors (read cur))))
6295                       lines -1)
6296                 -1))
6297             ;; Xref.
6298             (progn
6299               (goto-char p)
6300               (and (search-forward "\nxref:" nil t)
6301                    (nnheader-header-value)))
6302             ;; Extra.
6303             (when gnus-extra-headers
6304               (let ((extra gnus-extra-headers)
6305                     out)
6306                 (while extra
6307                   (goto-char p)
6308                   (when (search-forward
6309                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6310                     (push (cons (car extra) (nnheader-header-value))
6311                           out))
6312                   (pop extra))
6313                 out))))
6314           (when (equal id ref)
6315             (setq ref nil))
6316
6317           (when gnus-alter-header-function
6318             (funcall gnus-alter-header-function header)
6319             (setq id (mail-header-id header)
6320                   ref (gnus-parent-id (mail-header-references header))))
6321
6322           (when (setq header
6323                       (gnus-dependencies-add-header
6324                        header dependencies force-new))
6325             (push header headers))
6326           (goto-char (point-max))
6327           (widen))
6328         (nreverse headers)))))
6329
6330 ;; Goes through the xover lines and returns a list of vectors
6331 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6332                                                   force-new dependencies
6333                                                   group also-fetch-heads)
6334   "Parse the news overview data in the server buffer.
6335 Return a list of headers that match SEQUENCE (see
6336 `nntp-retrieve-headers')."
6337   ;; Get the Xref when the users reads the articles since most/some
6338   ;; NNTP servers do not include Xrefs when using XOVER.
6339   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6340   (let ((mail-parse-charset gnus-newsgroup-charset)
6341         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6342         (cur nntp-server-buffer)
6343         (dependencies (or dependencies gnus-newsgroup-dependencies))
6344         (allp (cond
6345                ((eq gnus-read-all-available-headers t)
6346                 t)
6347                ((and (stringp gnus-read-all-available-headers)
6348                      group)
6349                 (string-match gnus-read-all-available-headers group))
6350                (t
6351                 nil)))
6352         number headers header)
6353     (save-excursion
6354       (set-buffer nntp-server-buffer)
6355       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6356       ;; Allow the user to mangle the headers before parsing them.
6357       (gnus-run-hooks 'gnus-parse-headers-hook)
6358       (goto-char (point-min))
6359       (gnus-parse-without-error
6360         (while (and (or sequence allp)
6361                     (not (eobp)))
6362           (setq number (read cur))
6363           (when (not allp)
6364             (while (and sequence
6365                         (< (car sequence) number))
6366               (setq sequence (cdr sequence))))
6367           (when (and (or allp
6368                          (and sequence
6369                               (eq number (car sequence))))
6370                      (progn
6371                        (setq sequence (cdr sequence))
6372                        (setq header (inline
6373                                       (gnus-nov-parse-line
6374                                        number dependencies force-new)))))
6375             (push header headers))
6376           (forward-line 1)))
6377       ;; A common bug in inn is that if you have posted an article and
6378       ;; then retrieves the active file, it will answer correctly --
6379       ;; the new article is included.  However, a NOV entry for the
6380       ;; article may not have been generated yet, so this may fail.
6381       ;; We work around this problem by retrieving the last few
6382       ;; headers using HEAD.
6383       (if (or (not also-fetch-heads)
6384               (not sequence))
6385           ;; We (probably) got all the headers.
6386           (nreverse headers)
6387         (let ((gnus-nov-is-evil t))
6388           (nconc
6389            (nreverse headers)
6390            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6391              (gnus-get-newsgroup-headers))))))))
6392
6393 (defun gnus-article-get-xrefs ()
6394   "Fill in the Xref value in `gnus-current-headers', if necessary.
6395 This is meant to be called in `gnus-article-internal-prepare-hook'."
6396   (let ((headers (with-current-buffer gnus-summary-buffer
6397                    gnus-current-headers)))
6398     (or (not gnus-use-cross-reference)
6399         (not headers)
6400         (and (mail-header-xref headers)
6401              (not (string= (mail-header-xref headers) "")))
6402         (let ((case-fold-search t)
6403               xref)
6404           (save-restriction
6405             (nnheader-narrow-to-headers)
6406             (goto-char (point-min))
6407             (when (or (and (not (eobp))
6408                            (eq (downcase (char-after)) ?x)
6409                            (looking-at "Xref:"))
6410                       (search-forward "\nXref:" nil t))
6411               (goto-char (1+ (match-end 0)))
6412               (setq xref (buffer-substring (point) (point-at-eol)))
6413               (mail-header-set-xref headers xref)))))))
6414
6415 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6416   "Find article ID and insert the summary line for that article.
6417 OLD-HEADER can either be a header or a line number to insert
6418 the subject line on."
6419   (let* ((line (and (numberp old-header) old-header))
6420          (old-header (and (vectorp old-header) old-header))
6421          (header (cond ((and old-header use-old-header)
6422                         old-header)
6423                        ((and (numberp id)
6424                              (gnus-number-to-header id))
6425                         (gnus-number-to-header id))
6426                        (t
6427                         (gnus-read-header id))))
6428          (number (and (numberp id) id))
6429          d)
6430     (when header
6431       ;; Rebuild the thread that this article is part of and go to the
6432       ;; article we have fetched.
6433       (when (and (not gnus-show-threads)
6434                  old-header)
6435         (when (and number
6436                    (setq d (gnus-data-find (mail-header-number old-header))))
6437           (goto-char (gnus-data-pos d))
6438           (gnus-data-remove
6439            number
6440            (- (point-at-bol)
6441               (prog1
6442                   (1+ (point-at-eol))
6443                 (gnus-delete-line))))))
6444       ;; Remove list identifiers from subject.
6445       (when gnus-list-identifiers
6446         (let ((gnus-newsgroup-headers (list header)))
6447           (gnus-summary-remove-list-identifiers)))
6448       (when old-header
6449         (mail-header-set-number header (mail-header-number old-header)))
6450       (setq gnus-newsgroup-sparse
6451             (delq (setq number (mail-header-number header))
6452                   gnus-newsgroup-sparse))
6453       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6454       (push number gnus-newsgroup-limit)
6455       (gnus-rebuild-thread (mail-header-id header) line)
6456       (gnus-summary-goto-subject number nil t))
6457     (when (and (numberp number)
6458                (> number 0))
6459       ;; We have to update the boundaries even if we can't fetch the
6460       ;; article if ID is a number -- so that the next `P' or `N'
6461       ;; command will fetch the previous (or next) article even
6462       ;; if the one we tried to fetch this time has been canceled.
6463       (when (> number gnus-newsgroup-end)
6464         (setq gnus-newsgroup-end number))
6465       (when (< number gnus-newsgroup-begin)
6466         (setq gnus-newsgroup-begin number))
6467       (setq gnus-newsgroup-unselected
6468             (delq number gnus-newsgroup-unselected)))
6469     ;; Report back a success?
6470     (and header (mail-header-number header))))
6471
6472 ;;; Process/prefix in the summary buffer
6473
6474 (defun gnus-summary-work-articles (n)
6475   "Return a list of articles to be worked upon.
6476 The prefix argument, the list of process marked articles, and the
6477 current article will be taken into consideration."
6478   (save-excursion
6479     (set-buffer gnus-summary-buffer)
6480     (cond
6481      (n
6482       ;; A numerical prefix has been given.
6483       (setq n (prefix-numeric-value n))
6484       (let ((backward (< n 0))
6485             (n (abs (prefix-numeric-value n)))
6486             articles article)
6487         (save-excursion
6488           (while
6489               (and (> n 0)
6490                    (push (setq article (gnus-summary-article-number))
6491                          articles)
6492                    (if backward
6493                        (gnus-summary-find-prev nil article)
6494                      (gnus-summary-find-next nil article)))
6495             (decf n)))
6496         (nreverse articles)))
6497      ((and (gnus-region-active-p) (mark))
6498       (message "region active")
6499       ;; Work on the region between point and mark.
6500       (let ((max (max (point) (mark)))
6501             articles article)
6502         (save-excursion
6503           (goto-char (min (point) (mark)))
6504           (while
6505               (and
6506                (push (setq article (gnus-summary-article-number)) articles)
6507                (gnus-summary-find-next nil article)
6508                (< (point) max)))
6509           (nreverse articles))))
6510      (gnus-newsgroup-processable
6511       ;; There are process-marked articles present.
6512       ;; Save current state.
6513       (gnus-summary-save-process-mark)
6514       ;; Return the list.
6515       (reverse gnus-newsgroup-processable))
6516      (t
6517       ;; Just return the current article.
6518       (list (gnus-summary-article-number))))))
6519
6520 (defmacro gnus-summary-iterate (arg &rest forms)
6521   "Iterate over the process/prefixed articles and do FORMS.
6522 ARG is the interactive prefix given to the command.  FORMS will be
6523 executed with point over the summary line of the articles."
6524   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6525     `(let ((,articles (gnus-summary-work-articles ,arg)))
6526        (while ,articles
6527          (gnus-summary-goto-subject (car ,articles))
6528          ,@forms
6529          (pop ,articles)))))
6530
6531 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6532 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6533
6534 (defun gnus-summary-save-process-mark ()
6535   "Push the current set of process marked articles on the stack."
6536   (interactive)
6537   (push (copy-sequence gnus-newsgroup-processable)
6538         gnus-newsgroup-process-stack))
6539
6540 (defun gnus-summary-kill-process-mark ()
6541   "Push the current set of process marked articles on the stack and unmark."
6542   (interactive)
6543   (gnus-summary-save-process-mark)
6544   (gnus-summary-unmark-all-processable))
6545
6546 (defun gnus-summary-yank-process-mark ()
6547   "Pop the last process mark state off the stack and restore it."
6548   (interactive)
6549   (unless gnus-newsgroup-process-stack
6550     (error "Empty mark stack"))
6551   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6552
6553 (defun gnus-summary-process-mark-set (set)
6554   "Make SET into the current process marked articles."
6555   (gnus-summary-unmark-all-processable)
6556   (mapc 'gnus-summary-set-process-mark set))
6557
6558 ;;; Searching and stuff
6559
6560 (defun gnus-summary-search-group (&optional backward use-level)
6561   "Search for next unread newsgroup.
6562 If optional argument BACKWARD is non-nil, search backward instead."
6563   (save-excursion
6564     (set-buffer gnus-group-buffer)
6565     (when (gnus-group-search-forward
6566            backward nil (if use-level (gnus-group-group-level) nil))
6567       (gnus-group-group-name))))
6568
6569 (defun gnus-summary-best-group (&optional exclude-group)
6570   "Find the name of the best unread group.
6571 If EXCLUDE-GROUP, do not go to this group."
6572   (with-current-buffer gnus-group-buffer
6573     (save-excursion
6574       (gnus-group-best-unread-group exclude-group))))
6575
6576 (defun gnus-summary-find-next (&optional unread article backward)
6577   (if backward
6578       (gnus-summary-find-prev unread article)
6579     (let* ((dummy (gnus-summary-article-intangible-p))
6580            (article (or article (gnus-summary-article-number)))
6581            (data (gnus-data-find-list article))
6582            result)
6583       (when (and (not dummy)
6584                  (or (not gnus-summary-check-current)
6585                      (not unread)
6586                      (not (gnus-data-unread-p (car data)))))
6587         (setq data (cdr data)))
6588       (when (setq result
6589                   (if unread
6590                       (progn
6591                         (while data
6592                           (unless (memq (gnus-data-number (car data))
6593                                         (cond
6594                                          ((eq gnus-auto-goto-ignores
6595                                               'always-undownloaded)
6596                                           gnus-newsgroup-undownloaded)
6597                                          (gnus-plugged
6598                                           nil)
6599                                          ((eq gnus-auto-goto-ignores
6600                                               'unfetched)
6601                                           gnus-newsgroup-unfetched)
6602                                          ((eq gnus-auto-goto-ignores
6603                                               'undownloaded)
6604                                           gnus-newsgroup-undownloaded)))
6605                             (when (gnus-data-unread-p (car data))
6606                               (setq result (car data)
6607                                     data nil)))
6608                           (setq data (cdr data)))
6609                         result)
6610                     (car data)))
6611         (goto-char (gnus-data-pos result))
6612         (gnus-data-number result)))))
6613
6614 (defun gnus-summary-find-prev (&optional unread article)
6615   (let* ((eobp (eobp))
6616          (article (or article (gnus-summary-article-number)))
6617          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6618          result)
6619     (when (and (not eobp)
6620                (or (not gnus-summary-check-current)
6621                    (not unread)
6622                    (not (gnus-data-unread-p (car data)))))
6623       (setq data (cdr data)))
6624     (when (setq result
6625                 (if unread
6626                     (progn
6627                       (while data
6628                         (unless (memq (gnus-data-number (car data))
6629                                       (cond
6630                                        ((eq gnus-auto-goto-ignores
6631                                             'always-undownloaded)
6632                                         gnus-newsgroup-undownloaded)
6633                                        (gnus-plugged
6634                                         nil)
6635                                        ((eq gnus-auto-goto-ignores
6636                                             'unfetched)
6637                                         gnus-newsgroup-unfetched)
6638                                        ((eq gnus-auto-goto-ignores
6639                                             'undownloaded)
6640                                         gnus-newsgroup-undownloaded)))
6641                           (when (gnus-data-unread-p (car data))
6642                             (setq result (car data)
6643                                   data nil)))
6644                         (setq data (cdr data)))
6645                       result)
6646                   (car data)))
6647       (goto-char (gnus-data-pos result))
6648       (gnus-data-number result))))
6649
6650 (defun gnus-summary-find-subject (subject &optional unread backward article)
6651   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6652          (article (or article (gnus-summary-article-number)))
6653          (articles (gnus-data-list backward))
6654          (arts (gnus-data-find-list article articles))
6655          result)
6656     (when (or (not gnus-summary-check-current)
6657               (not unread)
6658               (not (gnus-data-unread-p (car arts))))
6659       (setq arts (cdr arts)))
6660     (while arts
6661       (and (or (not unread)
6662                (gnus-data-unread-p (car arts)))
6663            (vectorp (gnus-data-header (car arts)))
6664            (gnus-subject-equal
6665             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6666            (setq result (car arts)
6667                  arts nil))
6668       (setq arts (cdr arts)))
6669     (and result
6670          (goto-char (gnus-data-pos result))
6671          (gnus-data-number result))))
6672
6673 (defun gnus-summary-search-forward (&optional unread subject backward)
6674   "Search forward for an article.
6675 If UNREAD, look for unread articles.  If SUBJECT, look for
6676 articles with that subject.  If BACKWARD, search backward instead."
6677   (cond (subject (gnus-summary-find-subject subject unread backward))
6678         (backward (gnus-summary-find-prev unread))
6679         (t (gnus-summary-find-next unread))))
6680
6681 (defun gnus-recenter (&optional n)
6682   "Center point in window and redisplay frame.
6683 Also do horizontal recentering."
6684   (interactive "P")
6685   (when (and gnus-auto-center-summary
6686              (not (eq gnus-auto-center-summary 'vertical)))
6687     (gnus-horizontal-recenter))
6688   (recenter n))
6689
6690 (defun gnus-summary-recenter ()
6691   "Center point in the summary window.
6692 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6693 displayed, no centering will be performed."
6694   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6695   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6696   (interactive)
6697   ;; The user has to want it.
6698   (when gnus-auto-center-summary
6699     (let* ((top (cond ((< (window-height) 4) 0)
6700                       ((< (window-height) 7) 1)
6701                       (t (if (numberp gnus-auto-center-summary)
6702                              gnus-auto-center-summary
6703                            (/ (1- (window-height)) 2)))))
6704            (height (1- (window-height)))
6705            (bottom (save-excursion (goto-char (point-max))
6706                                    (forward-line (- height))
6707                                    (point)))
6708            (window (get-buffer-window (current-buffer))))
6709       (when (get-buffer-window gnus-article-buffer)
6710         ;; Only do recentering when the article buffer is displayed,
6711         ;; Set the window start to either `bottom', which is the biggest
6712         ;; possible valid number, or the second line from the top,
6713         ;; whichever is the least.
6714         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6715           (if (> bottom top-pos)
6716               ;; Keep the second line from the top visible
6717               (set-window-start window top-pos)
6718             ;; Try to keep the bottom line visible; if it's partially
6719             ;; obscured, either scroll one more line to make it fully
6720             ;; visible, or revert to using TOP-POS.
6721             (save-excursion
6722               (goto-char (point-max))
6723               (forward-line -1)
6724               (let ((last-line-start (point)))
6725                 (goto-char bottom)
6726                 (set-window-start window (point) t)
6727                 (when (not (pos-visible-in-window-p last-line-start window))
6728                   (forward-line 1)
6729                   (set-window-start window (min (point) top-pos) t)))))))
6730       ;; Do horizontal recentering while we're at it.
6731       (when (and (get-buffer-window (current-buffer) t)
6732                  (not (eq gnus-auto-center-summary 'vertical)))
6733         (let ((selected (selected-window)))
6734           (select-window (get-buffer-window (current-buffer) t))
6735           (gnus-summary-position-point)
6736           (gnus-horizontal-recenter)
6737           (select-window selected))))))
6738
6739 (defun gnus-summary-jump-to-group (newsgroup)
6740   "Move point to NEWSGROUP in group mode buffer."
6741   ;; Keep update point of group mode buffer if visible.
6742   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6743       (save-window-excursion
6744         ;; Take care of tree window mode.
6745         (when (get-buffer-window gnus-group-buffer)
6746           (pop-to-buffer gnus-group-buffer))
6747         (gnus-group-jump-to-group newsgroup))
6748     (save-excursion
6749       ;; Take care of tree window mode.
6750       (if (get-buffer-window gnus-group-buffer)
6751           (pop-to-buffer gnus-group-buffer)
6752         (set-buffer gnus-group-buffer))
6753       (gnus-group-jump-to-group newsgroup))))
6754
6755 ;; This function returns a list of article numbers based on the
6756 ;; difference between the ranges of read articles in this group and
6757 ;; the range of active articles.
6758 (defun gnus-list-of-unread-articles (group)
6759   (let* ((read (gnus-info-read (gnus-get-info group)))
6760          (active (or (gnus-active group) (gnus-activate-group group)))
6761          (last (or (cdr active)
6762                    (error "Group %s couldn't be activated " group)))
6763          (bottom (if gnus-newsgroup-maximum-articles
6764                      (max (car active)
6765                           (- last gnus-newsgroup-maximum-articles -1))
6766                    (car active)))
6767          first nlast unread)
6768     ;; If none are read, then all are unread.
6769     (if (not read)
6770         (setq first bottom)
6771       ;; If the range of read articles is a single range, then the
6772       ;; first unread article is the article after the last read
6773       ;; article.  Sounds logical, doesn't it?
6774       (if (and (not (listp (cdr read)))
6775                (or (< (car read) bottom)
6776                    (progn (setq read (list read))
6777                           nil)))
6778           (setq first (max bottom (1+ (cdr read))))
6779         ;; `read' is a list of ranges.
6780         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6781                                   (caar read)))
6782                   1)
6783           (setq first bottom))
6784         (while read
6785           (when first
6786             (while (< first nlast)
6787               (setq unread (cons first unread)
6788                     first (1+ first))))
6789           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6790           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6791           (setq read (cdr read)))))
6792     ;; And add the last unread articles.
6793     (while (<= first last)
6794       (setq unread (cons first unread)
6795             first (1+ first)))
6796     ;; Return the list of unread articles.
6797     (delq 0 (nreverse unread))))
6798
6799 (defun gnus-list-of-read-articles (group)
6800   "Return a list of unread, unticked and non-dormant articles."
6801   (let* ((info (gnus-get-info group))
6802          (marked (gnus-info-marks info))
6803          (active (gnus-active group)))
6804     (and info active
6805          (gnus-list-range-difference
6806           (gnus-list-range-difference
6807            (gnus-sorted-complement
6808             (gnus-uncompress-range
6809              (if gnus-newsgroup-maximum-articles
6810                  (cons (max (car active)
6811                             (- (cdr active)
6812                                gnus-newsgroup-maximum-articles
6813                                -1))
6814                        (cdr active))
6815                active))
6816             (gnus-list-of-unread-articles group))
6817            (cdr (assq 'dormant marked)))
6818           (cdr (assq 'tick marked))))))
6819
6820 ;; This function returns a sequence of article numbers based on the
6821 ;; difference between the ranges of read articles in this group and
6822 ;; the range of active articles.
6823 (defun gnus-sequence-of-unread-articles (group)
6824   (let* ((read (gnus-info-read (gnus-get-info group)))
6825          (active (or (gnus-active group) (gnus-activate-group group)))
6826          (last (cdr active))
6827          (bottom (if gnus-newsgroup-maximum-articles
6828                      (max (car active)
6829                           (- last gnus-newsgroup-maximum-articles -1))
6830                    (car active)))
6831          first nlast unread)
6832     ;; If none are read, then all are unread.
6833     (if (not read)
6834         (setq first bottom)
6835       ;; If the range of read articles is a single range, then the
6836       ;; first unread article is the article after the last read
6837       ;; article.  Sounds logical, doesn't it?
6838       (if (and (not (listp (cdr read)))
6839                (or (< (car read) bottom)
6840                    (progn (setq read (list read))
6841                           nil)))
6842           (setq first (max bottom (1+ (cdr read))))
6843         ;; `read' is a list of ranges.
6844         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6845                                   (caar read)))
6846                   1)
6847           (setq first bottom))
6848         (while read
6849           (when first
6850             (push (cons first nlast) unread))
6851           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6852           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6853           (setq read (cdr read)))))
6854     ;; And add the last unread articles.
6855     (cond ((not (and first last))
6856            nil)
6857           ((< first last)
6858            (push (cons first last) unread))
6859           ((= first last)
6860            (push first unread)))
6861     ;; Return the sequence of unread articles.
6862     (delq 0 (nreverse unread))))
6863
6864 ;; Various summary commands
6865
6866 (defun gnus-summary-select-article-buffer ()
6867   "Reconfigure windows to show article buffer."
6868   (interactive)
6869   (if (not (gnus-buffer-live-p gnus-article-buffer))
6870       (error "There is no article buffer for this summary buffer")
6871     (gnus-configure-windows 'article)
6872     (select-window (get-buffer-window gnus-article-buffer))))
6873
6874 (defun gnus-summary-universal-argument (arg)
6875   "Perform any operation on all articles that are process/prefixed."
6876   (interactive "P")
6877   (let ((articles (gnus-summary-work-articles arg))
6878         func article)
6879     (if (eq
6880          (setq
6881           func
6882           (key-binding
6883            (read-key-sequence
6884             (substitute-command-keys
6885              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6886          'undefined)
6887         (gnus-error 1 "Undefined key")
6888       (save-excursion
6889         (while articles
6890           (gnus-summary-goto-subject (setq article (pop articles)))
6891           (let (gnus-newsgroup-processable)
6892             (command-execute func))
6893           (gnus-summary-remove-process-mark article)))))
6894   (gnus-summary-position-point))
6895
6896 (defun gnus-summary-toggle-truncation (&optional arg)
6897   "Toggle truncation of summary lines.
6898 With ARG, turn line truncation on if ARG is positive."
6899   (interactive "P")
6900   (setq truncate-lines
6901         (if (null arg) (not truncate-lines)
6902           (> (prefix-numeric-value arg) 0)))
6903   (redraw-display))
6904
6905 (defun gnus-summary-find-for-reselect ()
6906   "Return the number of an article to stay on across a reselect.
6907 The current article is considered, then following articles, then previous
6908 articles.  An article is sought which is not cancelled and isn't a temporary
6909 insertion from another group.  If there's no such then return a dummy 0."
6910   (let (found)
6911     (dolist (rev '(nil t))
6912       (unless found      ; don't demand the reverse list if we don't need it
6913         (let ((data (gnus-data-find-list
6914                      (gnus-summary-article-number) (gnus-data-list rev))))
6915           (while (and data (not found))
6916             (if (and (< 0 (gnus-data-number (car data)))
6917                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6918                 (setq found (gnus-data-number (car data))))
6919             (setq data (cdr data))))))
6920     (or found 0)))
6921
6922 (defun gnus-summary-reselect-current-group (&optional all rescan)
6923   "Exit and then reselect the current newsgroup.
6924 The prefix argument ALL means to select all articles."
6925   (interactive "P")
6926   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6927     (error "Ephemeral groups can't be reselected"))
6928   (let ((current-subject (gnus-summary-find-for-reselect))
6929         (group gnus-newsgroup-name))
6930     (setq gnus-newsgroup-begin nil)
6931     (gnus-summary-exit nil 'leave-hidden)
6932     ;; We have to adjust the point of group mode buffer because
6933     ;; point was moved to the next unread newsgroup by exiting.
6934     (gnus-summary-jump-to-group group)
6935     (when rescan
6936       (save-excursion
6937         (gnus-group-get-new-news-this-group 1)))
6938     (gnus-group-read-group all t)
6939     (gnus-summary-goto-subject current-subject nil t)))
6940
6941 (defun gnus-summary-rescan-group (&optional all)
6942   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6943   (interactive "P")
6944   (gnus-summary-reselect-current-group all t))
6945
6946 (defun gnus-summary-update-info (&optional non-destructive)
6947   (save-excursion
6948     (let ((group gnus-newsgroup-name))
6949       (when group
6950         (when gnus-newsgroup-kill-headers
6951           (setq gnus-newsgroup-killed
6952                 (gnus-compress-sequence
6953                  (gnus-sorted-union
6954                   (gnus-list-range-intersection
6955                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6956                   gnus-newsgroup-unreads)
6957                  t)))
6958         (unless (listp (cdr gnus-newsgroup-killed))
6959           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6960         (let ((headers gnus-newsgroup-headers))
6961           ;; Set the new ranges of read articles.
6962           (with-current-buffer gnus-group-buffer
6963             (gnus-undo-force-boundary))
6964           (gnus-update-read-articles
6965            group (gnus-sorted-union
6966                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6967           ;; Set the current article marks.
6968           (let ((gnus-newsgroup-scored
6969                  (if (and (not gnus-save-score)
6970                           (not non-destructive))
6971                      nil
6972                    gnus-newsgroup-scored)))
6973             (save-excursion
6974               (gnus-update-marks)))
6975           ;; Do the cross-ref thing.
6976           (when gnus-use-cross-reference
6977             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6978           ;; Do not switch windows but change the buffer to work.
6979           (set-buffer gnus-group-buffer)
6980           (unless (gnus-ephemeral-group-p group)
6981             (gnus-group-update-group group)))))))
6982
6983 (defun gnus-summary-save-newsrc (&optional force)
6984   "Save the current number of read/marked articles in the dribble buffer.
6985 The dribble buffer will then be saved.
6986 If FORCE (the prefix), also save the .newsrc file(s)."
6987   (interactive "P")
6988   (gnus-summary-update-info t)
6989   (if force
6990       (gnus-save-newsrc-file)
6991     (gnus-dribble-save)))
6992
6993 (declare-function gnus-cache-write-active "gnus-cache" (&optional force))
6994
6995 (defun gnus-summary-exit (&optional temporary leave-hidden)
6996   "Exit reading current newsgroup, and then return to group selection mode.
6997 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6998   (interactive)
6999   (gnus-set-global-variables)
7000   (when (gnus-buffer-live-p gnus-article-buffer)
7001     (save-excursion
7002       (set-buffer gnus-article-buffer)
7003       (mm-destroy-parts gnus-article-mime-handles)
7004       ;; Set it to nil for safety reason.
7005       (setq gnus-article-mime-handle-alist nil)
7006       (setq gnus-article-mime-handles nil)))
7007   (gnus-kill-save-kill-buffer)
7008   (gnus-async-halt-prefetch)
7009   (let* ((group gnus-newsgroup-name)
7010          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
7011          (gnus-group-is-exiting-p t)
7012          (mode major-mode)
7013          (group-point nil)
7014          (buf (current-buffer)))
7015     (unless quit-config
7016       ;; Do adaptive scoring, and possibly save score files.
7017       (when gnus-newsgroup-adaptive
7018         (gnus-score-adaptive))
7019       (when gnus-use-scoring
7020         (gnus-score-save)))
7021     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
7022     ;; If we have several article buffers, we kill them at exit.
7023     (unless gnus-single-article-buffer
7024       (when (gnus-buffer-live-p gnus-article-buffer)
7025         (with-current-buffer gnus-article-buffer
7026           ;; Don't kill sticky article buffers
7027           (unless (eq major-mode 'gnus-sticky-article-mode)
7028             (gnus-kill-buffer gnus-article-buffer)
7029             (setq gnus-article-current nil))))
7030       (gnus-kill-buffer gnus-original-article-buffer))
7031     (when gnus-use-cache
7032       (gnus-cache-possibly-remove-articles)
7033       (gnus-cache-save-buffers))
7034     (gnus-async-prefetch-remove-group group)
7035     (when gnus-suppress-duplicates
7036       (gnus-dup-enter-articles))
7037     (when gnus-use-trees
7038       (gnus-tree-close group))
7039     (when gnus-use-cache
7040       (gnus-cache-write-active))
7041     ;; Remove entries for this group.
7042     (nnmail-purge-split-history (gnus-group-real-name group))
7043     ;; Make all changes in this group permanent.
7044     (unless quit-config
7045       (gnus-run-hooks 'gnus-exit-group-hook)
7046       (gnus-summary-update-info))
7047     (gnus-close-group group)
7048     ;; Make sure where we were, and go to next newsgroup.
7049     (set-buffer gnus-group-buffer)
7050     (unless quit-config
7051       (gnus-group-jump-to-group group))
7052     (gnus-run-hooks 'gnus-summary-exit-hook)
7053     (unless (or quit-config
7054                 (not gnus-summary-next-group-on-exit)
7055                 ;; If this group has disappeared from the summary
7056                 ;; buffer, don't skip forwards.
7057                 (not (string= group (gnus-group-group-name))))
7058       (gnus-group-next-unread-group 1))
7059     (setq group-point (point))
7060     (if temporary
7061         nil                             ;Nothing to do.
7062       (set-buffer buf)
7063       (if (not gnus-kill-summary-on-exit)
7064           (progn
7065             (gnus-deaden-summary)
7066             (setq mode nil))
7067         ;; We set all buffer-local variables to nil.  It is unclear why
7068         ;; this is needed, but if we don't, buffer-local variables are
7069         ;; not garbage-collected, it seems.  This would the lead to en
7070         ;; ever-growing Emacs.
7071         (gnus-summary-clear-local-variables)
7072         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7073           (gnus-summary-clear-local-variables))
7074         (when (get-buffer gnus-article-buffer)
7075           (bury-buffer gnus-article-buffer))
7076         ;; Return to group mode buffer.
7077         (when (eq mode 'gnus-summary-mode)
7078           (gnus-kill-buffer buf)))
7079       (setq gnus-current-select-method gnus-select-method)
7080       (set-buffer gnus-group-buffer)
7081       (if quit-config
7082           (gnus-handle-ephemeral-exit quit-config)
7083         (goto-char group-point)
7084         ;; If gnus-group-buffer is already displayed, make sure we also move
7085         ;; the cursor in the window that displays it.
7086         (let ((win (get-buffer-window (current-buffer) 0)))
7087           (if win (set-window-point win (point))))
7088         (unless leave-hidden
7089           (gnus-configure-windows 'group 'force)))
7090       ;; Clear the current group name.
7091       (unless quit-config
7092         (setq gnus-newsgroup-name nil)))))
7093
7094 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7095 (defun gnus-summary-exit-no-update (&optional no-questions)
7096   "Quit reading current newsgroup without updating read article info."
7097   (interactive)
7098   (let* ((group gnus-newsgroup-name)
7099          (gnus-group-is-exiting-p t)
7100          (gnus-group-is-exiting-without-update-p t)
7101          (quit-config (gnus-group-quit-config group)))
7102     (when (or no-questions
7103               gnus-expert-user
7104               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7105       (gnus-async-halt-prefetch)
7106       (run-hooks 'gnus-summary-prepare-exit-hook)
7107       (when (gnus-buffer-live-p gnus-article-buffer)
7108         (save-excursion
7109           (set-buffer gnus-article-buffer)
7110           (mm-destroy-parts gnus-article-mime-handles)
7111           ;; Set it to nil for safety reason.
7112           (setq gnus-article-mime-handle-alist nil)
7113           (setq gnus-article-mime-handles nil)))
7114       ;; If we have several article buffers, we kill them at exit.
7115       (unless gnus-single-article-buffer
7116         (gnus-kill-buffer gnus-article-buffer)
7117         (gnus-kill-buffer gnus-original-article-buffer)
7118         (setq gnus-article-current nil))
7119       (if (not gnus-kill-summary-on-exit)
7120           (gnus-deaden-summary)
7121         (gnus-close-group group)
7122         (gnus-summary-clear-local-variables)
7123         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7124           (gnus-summary-clear-local-variables))
7125         (gnus-kill-buffer gnus-summary-buffer))
7126       (unless gnus-single-article-buffer
7127         (setq gnus-article-current nil))
7128       (when gnus-use-trees
7129         (gnus-tree-close group))
7130       (gnus-async-prefetch-remove-group group)
7131       (when (get-buffer gnus-article-buffer)
7132         (bury-buffer gnus-article-buffer))
7133       ;; Return to the group buffer.
7134       (gnus-configure-windows 'group 'force)
7135       ;; Clear the current group name.
7136       (setq gnus-newsgroup-name nil)
7137       (unless (gnus-ephemeral-group-p group)
7138         (gnus-group-update-group group))
7139       (when (equal (gnus-group-group-name) group)
7140         (gnus-group-next-unread-group 1))
7141       (when quit-config
7142         (gnus-handle-ephemeral-exit quit-config)))))
7143
7144 (defun gnus-handle-ephemeral-exit (quit-config)
7145   "Handle movement when leaving an ephemeral group.
7146 The state which existed when entering the ephemeral is reset."
7147   (if (not (buffer-name (car quit-config)))
7148       (gnus-configure-windows 'group 'force)
7149     (set-buffer (car quit-config))
7150     (cond ((eq major-mode 'gnus-summary-mode)
7151            (gnus-set-global-variables))
7152           ((eq major-mode 'gnus-article-mode)
7153            (save-excursion
7154              ;; The `gnus-summary-buffer' variable may point
7155              ;; to the old summary buffer when using a single
7156              ;; article buffer.
7157              (unless (gnus-buffer-live-p gnus-summary-buffer)
7158                (set-buffer gnus-group-buffer))
7159              (set-buffer gnus-summary-buffer)
7160              (gnus-set-global-variables))))
7161     (if (or (eq (cdr quit-config) 'article)
7162             (eq (cdr quit-config) 'pick))
7163         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7164             (gnus-configure-windows 'pick 'force)
7165           (gnus-configure-windows (cdr quit-config) 'force))
7166       (gnus-configure-windows (cdr quit-config) 'force))
7167     (when (eq major-mode 'gnus-summary-mode)
7168       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7169                                                      next-unread-noselect))
7170           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7171                                   'next-noselect)
7172                               (gnus-summary-next-subject 1 nil t))
7173                              ((eq gnus-auto-select-on-ephemeral-exit
7174                                   'next-unread-noselect)
7175                               (gnus-summary-next-subject 1 t t))))
7176             ;; Hide the article buffer which displays the article different
7177             ;; from the one that the cursor points to in the summary buffer.
7178             (gnus-configure-windows 'summary 'force))
7179         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7180                (gnus-summary-next-subject 1))
7181               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7182                (gnus-summary-next-subject 1 t))))
7183       (gnus-summary-recenter)
7184       (gnus-summary-position-point))))
7185
7186 ;;; Dead summaries.
7187
7188 (defvar gnus-dead-summary-mode-map nil)
7189
7190 (unless gnus-dead-summary-mode-map
7191   (setq gnus-dead-summary-mode-map (make-keymap))
7192   (suppress-keymap gnus-dead-summary-mode-map)
7193   (substitute-key-definition
7194    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7195   (dolist (key '("\C-d" "\r" "\177" [delete]))
7196     (define-key gnus-dead-summary-mode-map
7197       key 'gnus-summary-wake-up-the-dead))
7198   (dolist (key '("q" "Q"))
7199     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7200
7201 (defvar gnus-dead-summary-mode nil
7202   "Minor mode for Gnus summary buffers.")
7203
7204 (defun gnus-dead-summary-mode (&optional arg)
7205   "Minor mode for Gnus summary buffers."
7206   (interactive "P")
7207   (when (eq major-mode 'gnus-summary-mode)
7208     (make-local-variable 'gnus-dead-summary-mode)
7209     (setq gnus-dead-summary-mode
7210           (if (null arg) (not gnus-dead-summary-mode)
7211             (> (prefix-numeric-value arg) 0)))
7212     (when gnus-dead-summary-mode
7213       (add-minor-mode
7214        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7215
7216 (defun gnus-deaden-summary ()
7217   "Make the current summary buffer into a dead summary buffer."
7218   ;; Kill any previous dead summary buffer.
7219   (when (and gnus-dead-summary
7220              (buffer-name gnus-dead-summary))
7221     (with-current-buffer gnus-dead-summary
7222       (when gnus-dead-summary-mode
7223         (kill-buffer (current-buffer)))))
7224   ;; Make this the current dead summary.
7225   (setq gnus-dead-summary (current-buffer))
7226   (gnus-dead-summary-mode 1)
7227   (let ((name (buffer-name)))
7228     (when (string-match "Summary" name)
7229       (rename-buffer
7230        (concat (substring name 0 (match-beginning 0)) "Dead "
7231                (substring name (match-beginning 0)))
7232        t)
7233       (bury-buffer))))
7234
7235 (defun gnus-kill-or-deaden-summary (buffer)
7236   "Kill or deaden the summary BUFFER."
7237   (save-excursion
7238     (when (and (buffer-name buffer)
7239                (not gnus-single-article-buffer))
7240       (with-current-buffer buffer
7241         (gnus-kill-buffer gnus-article-buffer)
7242         (gnus-kill-buffer gnus-original-article-buffer)))
7243     (cond
7244      ;; Kill the buffer.
7245      (gnus-kill-summary-on-exit
7246       (when (and gnus-use-trees
7247                  (gnus-buffer-exists-p buffer))
7248         (save-excursion
7249           (set-buffer buffer)
7250           (gnus-tree-close gnus-newsgroup-name)))
7251       (gnus-kill-buffer buffer))
7252      ;; Deaden the buffer.
7253      ((gnus-buffer-exists-p buffer)
7254       (save-excursion
7255         (set-buffer buffer)
7256         (gnus-deaden-summary))))))
7257
7258 (defun gnus-summary-wake-up-the-dead (&rest args)
7259   "Wake up the dead summary buffer."
7260   (interactive)
7261   (gnus-dead-summary-mode -1)
7262   (let ((name (buffer-name)))
7263     (when (string-match "Dead " name)
7264       (rename-buffer
7265        (concat (substring name 0 (match-beginning 0))
7266                (substring name (match-end 0)))
7267        t)))
7268   (gnus-message 3 "This dead summary is now alive again"))
7269
7270 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7271 (defun gnus-summary-fetch-faq (&optional faq-dir)
7272   "Fetch the FAQ for the current group.
7273 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7274 in."
7275   (interactive
7276    (list
7277     (when current-prefix-arg
7278       (completing-read
7279        "FAQ dir: " (and (listp gnus-group-faq-directory)
7280                         (mapcar 'list
7281                                 gnus-group-faq-directory))))))
7282   (let (gnus-faq-buffer)
7283     (when (setq gnus-faq-buffer
7284                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7285       (gnus-configure-windows 'summary-faq))))
7286
7287 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7288 (defun gnus-summary-describe-group (&optional force)
7289   "Describe the current newsgroup."
7290   (interactive "P")
7291   (gnus-group-describe-group force gnus-newsgroup-name))
7292
7293 (defun gnus-summary-describe-briefly ()
7294   "Describe summary mode commands briefly."
7295   (interactive)
7296   (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")))
7297
7298 ;; Walking around group mode buffer from summary mode.
7299
7300 (defun gnus-summary-next-group (&optional no-article target-group backward)
7301   "Exit current newsgroup and then select next unread newsgroup.
7302 If prefix argument NO-ARTICLE is non-nil, no article is selected
7303 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7304 previous group instead."
7305   (interactive "P")
7306   ;; Stop pre-fetching.
7307   (gnus-async-halt-prefetch)
7308   (let ((current-group gnus-newsgroup-name)
7309         (current-buffer (current-buffer))
7310         entered)
7311     ;; First we semi-exit this group to update Xrefs and all variables.
7312     ;; We can't do a real exit, because the window conf must remain
7313     ;; the same in case the user is prompted for info, and we don't
7314     ;; want the window conf to change before that...
7315     (gnus-summary-exit t)
7316     (while (not entered)
7317       ;; Then we find what group we are supposed to enter.
7318       (set-buffer gnus-group-buffer)
7319       (gnus-group-jump-to-group current-group)
7320       (setq target-group
7321             (or target-group
7322                 (if (eq gnus-keep-same-level 'best)
7323                     (gnus-summary-best-group gnus-newsgroup-name)
7324                   (gnus-summary-search-group backward gnus-keep-same-level))))
7325       (if (not target-group)
7326           ;; There are no further groups, so we return to the group
7327           ;; buffer.
7328           (progn
7329             (gnus-message 5 "Returning to the group buffer")
7330             (setq entered t)
7331             (when (gnus-buffer-live-p current-buffer)
7332               (set-buffer current-buffer)
7333               (gnus-summary-exit))
7334             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7335         ;; We try to enter the target group.
7336         (gnus-group-jump-to-group target-group)
7337         (let ((unreads (gnus-group-group-unread)))
7338           (if (and (or (eq t unreads)
7339                        (and unreads (not (zerop unreads))))
7340                    (gnus-summary-read-group
7341                     target-group nil no-article
7342                     (and (buffer-name current-buffer) current-buffer)
7343                     nil backward))
7344               (setq entered t)
7345             (setq current-group target-group
7346                   target-group nil)))))))
7347
7348 (defun gnus-summary-prev-group (&optional no-article)
7349   "Exit current newsgroup and then select previous unread newsgroup.
7350 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7351   (interactive "P")
7352   (gnus-summary-next-group no-article nil t))
7353
7354 ;; Walking around summary lines.
7355
7356 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7357   "Go to the first subject satisfying any non-nil constraint.
7358 If UNREAD is non-nil, the article should be unread.
7359 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7360 If UNSEEN is non-nil, the article should be unseen.
7361 Returns the article selected or nil if there are no matching articles."
7362   (interactive "P")
7363   (cond
7364    ;; Empty summary.
7365    ((null gnus-newsgroup-data)
7366     (gnus-message 3 "No articles in the group")
7367     nil)
7368    ;; Pick the first article.
7369    ((not (or unread undownloaded unseen))
7370     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7371     (gnus-data-number (car gnus-newsgroup-data)))
7372    ;; Find the first unread article.
7373    (t
7374     (let ((data gnus-newsgroup-data))
7375       (while (and data
7376                   (let ((num (gnus-data-number (car data))))
7377                     (or (memq num gnus-newsgroup-unfetched)
7378                         (not (or (and unread
7379                                       (memq num gnus-newsgroup-unreads))
7380                                  (and undownloaded
7381                                       (memq num gnus-newsgroup-undownloaded))
7382                                  (and unseen
7383                                       (memq num gnus-newsgroup-unseen)))))))
7384         (setq data (cdr data)))
7385       (prog1
7386           (if data
7387               (progn
7388                 (goto-char (gnus-data-pos (car data)))
7389                 (gnus-data-number (car data)))
7390             (gnus-message 3 "No more%s articles"
7391                           (let* ((r (when unread " unread"))
7392                                  (d (when undownloaded " undownloaded"))
7393                                  (s (when unseen " unseen"))
7394                                  (l (delq nil (list r d s))))
7395                             (cond ((= 3 (length l))
7396                                    (concat r "," d ", or" s))
7397                                   ((= 2 (length l))
7398                                    (concat (car l) ", or" (cadr l)))
7399                                   ((= 1 (length l))
7400                                    (car l))
7401                                   (t
7402                                    ""))))
7403             nil
7404             )
7405         (gnus-summary-position-point))))))
7406
7407 (defun gnus-summary-next-subject (n &optional unread dont-display)
7408   "Go to next N'th summary line.
7409 If N is negative, go to the previous N'th subject line.
7410 If UNREAD is non-nil, only unread articles are selected.
7411 The difference between N and the actual number of steps taken is
7412 returned."
7413   (interactive "p")
7414   (let ((backward (< n 0))
7415         (n (abs n)))
7416     (while (and (> n 0)
7417                 (if backward
7418                     (gnus-summary-find-prev unread)
7419                   (gnus-summary-find-next unread)))
7420       (unless (zerop (setq n (1- n)))
7421         (gnus-summary-show-thread)))
7422     (when (/= 0 n)
7423       (gnus-message 7 "No more%s articles"
7424                     (if unread " unread" "")))
7425     (unless dont-display
7426       (gnus-summary-recenter)
7427       (gnus-summary-position-point))
7428     n))
7429
7430 (defun gnus-summary-next-unread-subject (n)
7431   "Go to next N'th unread summary line."
7432   (interactive "p")
7433   (gnus-summary-next-subject n t))
7434
7435 (defun gnus-summary-prev-subject (n &optional unread)
7436   "Go to previous N'th summary line.
7437 If optional argument UNREAD is non-nil, only unread article is selected."
7438   (interactive "p")
7439   (gnus-summary-next-subject (- n) unread))
7440
7441 (defun gnus-summary-prev-unread-subject (n)
7442   "Go to previous N'th unread summary line."
7443   (interactive "p")
7444   (gnus-summary-next-subject (- n) t))
7445
7446 (defun gnus-summary-goto-subjects (articles)
7447   "Insert the subject header for ARTICLES in the current buffer."
7448   (save-excursion
7449     (dolist (article articles)
7450       (gnus-summary-goto-subject article t)))
7451   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7452   (gnus-summary-position-point))
7453
7454 (defun gnus-summary-goto-subject (article &optional force silent)
7455   "Go to the subject line of ARTICLE.
7456 If FORCE, also allow jumping to articles not currently shown."
7457   (interactive "nArticle number: ")
7458   (unless (numberp article)
7459     (error "Article %s is not a number" article))
7460   (let ((b (point))
7461         (data (gnus-data-find article)))
7462     ;; We read in the article if we have to.
7463     (and (not data)
7464          force
7465          (gnus-summary-insert-subject
7466           article
7467           (if (or (numberp force) (vectorp force)) force)
7468           t)
7469          (setq data (gnus-data-find article)))
7470     (goto-char b)
7471     (if (not data)
7472         (progn
7473           (unless silent
7474             (gnus-message 3 "Can't find article %d" article))
7475           nil)
7476       (let ((pt (gnus-data-pos data)))
7477         (goto-char pt)
7478         (gnus-summary-set-article-display-arrow pt))
7479       (gnus-summary-position-point)
7480       article)))
7481
7482 ;; Walking around summary lines with displaying articles.
7483
7484 (defun gnus-summary-expand-window (&optional arg)
7485   "Make the summary buffer take up the entire Emacs frame.
7486 Given a prefix, will force an `article' buffer configuration."
7487   (interactive "P")
7488   (if arg
7489       (gnus-configure-windows 'article 'force)
7490     (gnus-configure-windows 'summary 'force)))
7491
7492 (defun gnus-summary-display-article (article &optional all-header)
7493   "Display ARTICLE in article buffer."
7494   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7495                (with-current-buffer gnus-article-buffer
7496                  (eq major-mode 'gnus-article-mode)))
7497     (gnus-article-setup-buffer))
7498   (gnus-set-global-variables)
7499   (with-current-buffer gnus-article-buffer
7500     (setq gnus-article-charset gnus-newsgroup-charset)
7501     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7502     (mm-enable-multibyte))
7503   (if (null article)
7504       nil
7505     (prog1
7506         (if gnus-summary-display-article-function
7507             (funcall gnus-summary-display-article-function article all-header)
7508           (gnus-article-prepare article all-header))
7509       (gnus-run-hooks 'gnus-select-article-hook)
7510       (when (and gnus-current-article
7511                  (not (zerop gnus-current-article)))
7512         (gnus-summary-goto-subject gnus-current-article))
7513       (gnus-summary-recenter)
7514       (when (and gnus-use-trees gnus-show-threads)
7515         (gnus-possibly-generate-tree article)
7516         (gnus-highlight-selected-tree article))
7517       ;; Successfully display article.
7518       (gnus-article-set-window-start
7519        (cdr (assq article gnus-newsgroup-bookmarks))))))
7520
7521 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7522   "Select the current article.
7523 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7524 non-nil, the article will be re-fetched even if it already present in
7525 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7526 be displayed."
7527   ;; Make sure we are in the summary buffer to work around bbdb bug.
7528   (unless (eq major-mode 'gnus-summary-mode)
7529     (set-buffer gnus-summary-buffer))
7530   (let ((article (or article (gnus-summary-article-number)))
7531         (all-headers (not (not all-headers))) ;Must be t or nil.
7532         gnus-summary-display-article-function)
7533     (and (not pseudo)
7534          (gnus-summary-article-pseudo-p article)
7535          (error "This is a pseudo-article"))
7536     (save-excursion
7537       (set-buffer gnus-summary-buffer)
7538       (if (or (and gnus-single-article-buffer
7539                    (or (null gnus-current-article)
7540                        (null gnus-article-current)
7541                        (null (get-buffer gnus-article-buffer))
7542                        (not (eq article (cdr gnus-article-current)))
7543                        (not (equal (car gnus-article-current)
7544                                    gnus-newsgroup-name))))
7545               (and (not gnus-single-article-buffer)
7546                    (or (null gnus-current-article)
7547                        (not (eq gnus-current-article article))))
7548               force)
7549           ;; The requested article is different from the current article.
7550           (progn
7551             (gnus-summary-display-article article all-headers)
7552             (when (gnus-buffer-live-p gnus-article-buffer)
7553               (with-current-buffer gnus-article-buffer
7554                 (if (not gnus-article-decoded-p) ;; a local variable
7555                     (mm-disable-multibyte))))
7556             (gnus-article-set-window-start
7557              (cdr (assq article gnus-newsgroup-bookmarks)))
7558             article)
7559         'old))))
7560
7561 (defun gnus-summary-force-verify-and-decrypt ()
7562   "Display buttons for signed/encrypted parts and verify/decrypt them."
7563   (interactive)
7564   (let ((mm-verify-option 'known)
7565         (mm-decrypt-option 'known)
7566         (gnus-article-emulate-mime t)
7567         (gnus-buttonized-mime-types (append (list "multipart/signed"
7568                                                   "multipart/encrypted")
7569                                             gnus-buttonized-mime-types)))
7570     (gnus-summary-select-article nil 'force)))
7571
7572 (defun gnus-summary-set-current-mark (&optional current-mark)
7573   "Obsolete function."
7574   nil)
7575
7576 (defun gnus-summary-next-article (&optional unread subject backward push)
7577   "Select the next article.
7578 If UNREAD, only unread articles are selected.
7579 If SUBJECT, only articles with SUBJECT are selected.
7580 If BACKWARD, the previous article is selected instead of the next."
7581   (interactive "P")
7582   ;; Make sure we are in the summary buffer.
7583   (unless (eq major-mode 'gnus-summary-mode)
7584     (set-buffer gnus-summary-buffer))
7585   (cond
7586    ;; Is there such an article?
7587    ((and (gnus-summary-search-forward unread subject backward)
7588          (or (gnus-summary-display-article (gnus-summary-article-number))
7589              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7590     (gnus-summary-position-point))
7591    ;; If not, we try the first unread, if that is wanted.
7592    ((and subject
7593          gnus-auto-select-same
7594          (gnus-summary-first-unread-article))
7595     (gnus-summary-position-point)
7596     (gnus-message 6 "Wrapped"))
7597    ;; Try to get next/previous article not displayed in this group.
7598    ((and gnus-auto-extend-newsgroup
7599          (not unread) (not subject))
7600     (gnus-summary-goto-article
7601      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7602      nil (count-lines (point-min) (point))))
7603    ;; Go to next/previous group.
7604    (t
7605     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7606       (gnus-summary-jump-to-group gnus-newsgroup-name))
7607     (let ((cmd last-command-char)
7608           (point
7609            (with-current-buffer gnus-group-buffer
7610              (point)))
7611           (group
7612            (if (eq gnus-keep-same-level 'best)
7613                (gnus-summary-best-group gnus-newsgroup-name)
7614              (gnus-summary-search-group backward gnus-keep-same-level))))
7615       ;; For some reason, the group window gets selected.  We change
7616       ;; it back.
7617       (select-window (get-buffer-window (current-buffer)))
7618       ;; Select next unread newsgroup automagically.
7619       (cond
7620        ((or (not gnus-auto-select-next)
7621             (not cmd))
7622         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7623        ((or (eq gnus-auto-select-next 'quietly)
7624             (and (eq gnus-auto-select-next 'slightly-quietly)
7625                  push)
7626             (and (eq gnus-auto-select-next 'almost-quietly)
7627                  (gnus-summary-last-article-p)))
7628         ;; Select quietly.
7629         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7630             (gnus-summary-exit)
7631           (gnus-message 7 "No more%s articles (%s)..."
7632                         (if unread " unread" "")
7633                         (if group (concat "selecting " group)
7634                           "exiting"))
7635           (gnus-summary-next-group nil group backward)))
7636        (t
7637         (when (gnus-key-press-event-p last-input-event)
7638           (gnus-summary-walk-group-buffer
7639            gnus-newsgroup-name cmd unread backward point))))))))
7640
7641 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7642   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7643                       (?\C-p (gnus-group-prev-unread-group 1))))
7644         (cursor-in-echo-area t)
7645         keve key group ended prompt)
7646     (save-excursion
7647       (set-buffer gnus-group-buffer)
7648       (goto-char start)
7649       (setq group
7650             (if (eq gnus-keep-same-level 'best)
7651                 (gnus-summary-best-group gnus-newsgroup-name)
7652               (gnus-summary-search-group backward gnus-keep-same-level))))
7653     (while (not ended)
7654       (setq prompt
7655             (format
7656              "No more%s articles%s " (if unread " unread" "")
7657              (if (and group
7658                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7659                  (format " (Type %s for %s [%s])"
7660                          (single-key-description cmd)
7661                          (gnus-group-decoded-name group)
7662                          (gnus-group-unread group))
7663                (format " (Type %s to exit %s)"
7664                        (single-key-description cmd)
7665                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7666       ;; Confirm auto selection.
7667       (setq key (car (setq keve (gnus-read-event-char prompt)))
7668             ended t)
7669       (cond
7670        ((assq key keystrokes)
7671         (let ((obuf (current-buffer)))
7672           (switch-to-buffer gnus-group-buffer)
7673           (when group
7674             (gnus-group-jump-to-group group))
7675           (eval (cadr (assq key keystrokes)))
7676           (setq group (gnus-group-group-name))
7677           (switch-to-buffer obuf))
7678         (setq ended nil))
7679        ((equal key cmd)
7680         (if (or (not group)
7681                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7682             (gnus-summary-exit)
7683           (gnus-summary-next-group nil group backward)))
7684        (t
7685         (push (cdr keve) unread-command-events))))))
7686
7687 (defun gnus-summary-next-unread-article ()
7688   "Select unread article after current one."
7689   (interactive)
7690   (gnus-summary-next-article
7691    (or (not (eq gnus-summary-goto-unread 'never))
7692        (gnus-summary-last-article-p (gnus-summary-article-number)))
7693    (and gnus-auto-select-same
7694         (gnus-summary-article-subject))))
7695
7696 (defun gnus-summary-prev-article (&optional unread subject)
7697   "Select the article before the current one.
7698 If UNREAD is non-nil, only unread articles are selected."
7699   (interactive "P")
7700   (gnus-summary-next-article unread subject t))
7701
7702 (defun gnus-summary-prev-unread-article ()
7703   "Select unread article before current one."
7704   (interactive)
7705   (gnus-summary-prev-article
7706    (or (not (eq gnus-summary-goto-unread 'never))
7707        (gnus-summary-first-article-p (gnus-summary-article-number)))
7708    (and gnus-auto-select-same
7709         (gnus-summary-article-subject))))
7710
7711 (defun gnus-summary-next-page (&optional lines circular stop)
7712   "Show next page of the selected article.
7713 If at the end of the current article, select the next article.
7714 LINES says how many lines should be scrolled up.
7715
7716 If CIRCULAR is non-nil, go to the start of the article instead of
7717 selecting the next article when reaching the end of the current
7718 article.
7719
7720 If STOP is non-nil, just stop when reaching the end of the message.
7721
7722 Also see the variable `gnus-article-skip-boring'."
7723   (interactive "P")
7724   (setq gnus-summary-buffer (current-buffer))
7725   (gnus-set-global-variables)
7726   (let ((article (gnus-summary-article-number))
7727         (article-window (get-buffer-window gnus-article-buffer t))
7728         endp)
7729     ;; If the buffer is empty, we have no article.
7730     (unless article
7731       (error "No article to select"))
7732     (gnus-configure-windows 'article)
7733     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7734         (if (and (eq gnus-summary-goto-unread 'never)
7735                  (not (gnus-summary-last-article-p article)))
7736             (gnus-summary-next-article)
7737           (gnus-summary-next-unread-article))
7738       (if (or (null gnus-current-article)
7739               (null gnus-article-current)
7740               (/= article (cdr gnus-article-current))
7741               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7742           ;; Selected subject is different from current article's.
7743           (gnus-summary-display-article article)
7744         (when article-window
7745           (gnus-eval-in-buffer-window gnus-article-buffer
7746             (setq endp (or (gnus-article-next-page lines)
7747                            (gnus-article-only-boring-p))))
7748           (when endp
7749             (cond (stop
7750                    (gnus-message 3 "End of message"))
7751                   (circular
7752                    (gnus-summary-beginning-of-article))
7753                   (lines
7754                    (gnus-message 3 "End of message"))
7755                   ((null lines)
7756                    (if (and (eq gnus-summary-goto-unread 'never)
7757                             (not (gnus-summary-last-article-p article)))
7758                        (gnus-summary-next-article)
7759                      (gnus-summary-next-unread-article))))))))
7760     (gnus-summary-recenter)
7761     (gnus-summary-position-point)))
7762
7763 (defun gnus-summary-prev-page (&optional lines move)
7764   "Show previous page of selected article.
7765 Argument LINES specifies lines to be scrolled down.
7766 If MOVE, move to the previous unread article if point is at
7767 the beginning of the buffer."
7768   (interactive "P")
7769   (let ((article (gnus-summary-article-number))
7770         (article-window (get-buffer-window gnus-article-buffer t))
7771         endp)
7772     (gnus-configure-windows 'article)
7773     (if (or (null gnus-current-article)
7774             (null gnus-article-current)
7775             (/= article (cdr gnus-article-current))
7776             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7777         ;; Selected subject is different from current article's.
7778         (gnus-summary-display-article article)
7779       (gnus-summary-recenter)
7780       (when article-window
7781         (gnus-eval-in-buffer-window gnus-article-buffer
7782           (setq endp (gnus-article-prev-page lines)))
7783         (when (and move endp)
7784           (cond (lines
7785                  (gnus-message 3 "Beginning of message"))
7786                 ((null lines)
7787                  (if (and (eq gnus-summary-goto-unread 'never)
7788                           (not (gnus-summary-first-article-p article)))
7789                      (gnus-summary-prev-article)
7790                    (gnus-summary-prev-unread-article))))))))
7791   (gnus-summary-position-point))
7792
7793 (defun gnus-summary-prev-page-or-article (&optional lines)
7794   "Show previous page of selected article.
7795 Argument LINES specifies lines to be scrolled down.
7796 If at the beginning of the article, go to the next article."
7797   (interactive "P")
7798   (gnus-summary-prev-page lines t))
7799
7800 (defun gnus-summary-scroll-up (lines)
7801   "Scroll up (or down) one line current article.
7802 Argument LINES specifies lines to be scrolled up (or down if negative)."
7803   (interactive "p")
7804   (gnus-configure-windows 'article)
7805   (gnus-summary-show-thread)
7806   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7807     (gnus-eval-in-buffer-window gnus-article-buffer
7808       (cond ((> lines 0)
7809              (when (gnus-article-next-page lines)
7810                (gnus-message 3 "End of message")))
7811             ((< lines 0)
7812              (gnus-article-prev-page (- lines))))))
7813   (gnus-summary-recenter)
7814   (gnus-summary-position-point))
7815
7816 (defun gnus-summary-scroll-down (lines)
7817   "Scroll down (or up) one line current article.
7818 Argument LINES specifies lines to be scrolled down (or up if negative)."
7819   (interactive "p")
7820   (gnus-summary-scroll-up (- lines)))
7821
7822 (defun gnus-summary-next-same-subject ()
7823   "Select next article which has the same subject as current one."
7824   (interactive)
7825   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7826
7827 (defun gnus-summary-prev-same-subject ()
7828   "Select previous article which has the same subject as current one."
7829   (interactive)
7830   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7831
7832 (defun gnus-summary-next-unread-same-subject ()
7833   "Select next unread article which has the same subject as current one."
7834   (interactive)
7835   (gnus-summary-next-article t (gnus-summary-article-subject)))
7836
7837 (defun gnus-summary-prev-unread-same-subject ()
7838   "Select previous unread article which has the same subject as current one."
7839   (interactive)
7840   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7841
7842 (defun gnus-summary-first-unread-article ()
7843   "Select the first unread article.
7844 Return nil if there are no unread articles."
7845   (interactive)
7846   (prog1
7847       (when (gnus-summary-first-subject t)
7848         (gnus-summary-show-thread)
7849         (gnus-summary-first-subject t)
7850         (gnus-summary-display-article (gnus-summary-article-number)))
7851     (gnus-summary-position-point)))
7852
7853 (defun gnus-summary-first-unread-subject ()
7854   "Place the point on the subject line of the first unread article.
7855 Return nil if there are no unread articles."
7856   (interactive)
7857   (prog1
7858       (when (gnus-summary-first-subject t)
7859         (gnus-summary-show-thread)
7860         (gnus-summary-first-subject t))
7861     (gnus-summary-position-point)))
7862
7863 (defun gnus-summary-first-unseen-subject ()
7864   "Place the point on the subject line of the first unseen article.
7865 Return nil if there are no unseen articles."
7866   (interactive)
7867   (prog1
7868       (when (gnus-summary-first-subject nil nil t)
7869         (gnus-summary-show-thread)
7870         (gnus-summary-first-subject nil nil t))
7871     (gnus-summary-position-point)))
7872
7873 (defun gnus-summary-first-unseen-or-unread-subject ()
7874   "Place the point on the subject line of the first unseen article or,
7875 if all article have been seen, on the subject line of the first unread
7876 article."
7877   (interactive)
7878   (prog1
7879       (unless (when (gnus-summary-first-subject nil nil t)
7880                 (gnus-summary-show-thread)
7881                 (gnus-summary-first-subject nil nil t))
7882         (when (gnus-summary-first-subject t)
7883           (gnus-summary-show-thread)
7884           (gnus-summary-first-subject t)))
7885     (gnus-summary-position-point)))
7886
7887 (defun gnus-summary-first-article ()
7888   "Select the first article.
7889 Return nil if there are no articles."
7890   (interactive)
7891   (prog1
7892       (when (gnus-summary-first-subject)
7893         (gnus-summary-show-thread)
7894         (gnus-summary-first-subject)
7895         (gnus-summary-display-article (gnus-summary-article-number)))
7896     (gnus-summary-position-point)))
7897
7898 (defun gnus-summary-best-unread-article (&optional arg)
7899   "Select the unread article with the highest score.
7900 If given a prefix argument, select the next unread article that has a
7901 score higher than the default score."
7902   (interactive "P")
7903   (let ((article (if arg
7904                      (gnus-summary-better-unread-subject)
7905                    (gnus-summary-best-unread-subject))))
7906     (if article
7907         (gnus-summary-goto-article article)
7908       (error "No unread articles"))))
7909
7910 (defun gnus-summary-best-unread-subject ()
7911   "Select the unread subject with the highest score."
7912   (interactive)
7913   (let ((best -1000000)
7914         (data gnus-newsgroup-data)
7915         article score)
7916     (while data
7917       (and (gnus-data-unread-p (car data))
7918            (> (setq score
7919                     (gnus-summary-article-score (gnus-data-number (car data))))
7920               best)
7921            (setq best score
7922                  article (gnus-data-number (car data))))
7923       (setq data (cdr data)))
7924     (when article
7925       (gnus-summary-goto-subject article))
7926     (gnus-summary-position-point)
7927     article))
7928
7929 (defun gnus-summary-better-unread-subject ()
7930   "Select the first unread subject that has a score over the default score."
7931   (interactive)
7932   (let ((data gnus-newsgroup-data)
7933         article score)
7934     (while (and (setq article (gnus-data-number (car data)))
7935                 (or (gnus-data-read-p (car data))
7936                     (not (> (gnus-summary-article-score article)
7937                             gnus-summary-default-score))))
7938       (setq data (cdr data)))
7939     (when article
7940       (gnus-summary-goto-subject article))
7941     (gnus-summary-position-point)
7942     article))
7943
7944 (defun gnus-summary-last-subject ()
7945   "Go to the last displayed subject line in the group."
7946   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7947     (when article
7948       (gnus-summary-goto-subject article))))
7949
7950 (defun gnus-summary-goto-article (article &optional all-headers force)
7951   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7952 If ALL-HEADERS is non-nil, no header lines are hidden.
7953 If FORCE, go to the article even if it isn't displayed.  If FORCE
7954 is a number, it is the line the article is to be displayed on."
7955   (interactive
7956    (list
7957     (completing-read
7958      "Article number or Message-ID: "
7959      (mapcar (lambda (number) (list (int-to-string number)))
7960              gnus-newsgroup-limit))
7961     current-prefix-arg
7962     t))
7963   (prog1
7964       (if (and (stringp article)
7965                (string-match "@\\|%40" article))
7966           (gnus-summary-refer-article article)
7967         (when (stringp article)
7968           (setq article (string-to-number article)))
7969         (if (gnus-summary-goto-subject article force)
7970             (gnus-summary-display-article article all-headers)
7971           (gnus-message 4 "Couldn't go to article %s" article) nil))
7972     (gnus-summary-position-point)))
7973
7974 (defun gnus-summary-goto-last-article ()
7975   "Go to the previously read article."
7976   (interactive)
7977   (prog1
7978       (when gnus-last-article
7979         (gnus-summary-goto-article gnus-last-article nil t))
7980     (gnus-summary-position-point)))
7981
7982 (defun gnus-summary-pop-article (number)
7983   "Pop one article off the history and go to the previous.
7984 NUMBER articles will be popped off."
7985   (interactive "p")
7986   (let (to)
7987     (setq gnus-newsgroup-history
7988           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7989     (if to
7990         (gnus-summary-goto-article (car to) nil t)
7991       (error "Article history empty")))
7992   (gnus-summary-position-point))
7993
7994 ;; Summary commands and functions for limiting the summary buffer.
7995
7996 (defun gnus-summary-limit-to-articles (n)
7997   "Limit the summary buffer to the next N articles.
7998 If not given a prefix, use the process marked articles instead."
7999   (interactive "P")
8000   (prog1
8001       (let ((articles (gnus-summary-work-articles n)))
8002         (setq gnus-newsgroup-processable nil)
8003         (gnus-summary-limit articles))
8004     (gnus-summary-position-point)))
8005
8006 (defun gnus-summary-pop-limit (&optional total)
8007   "Restore the previous limit.
8008 If given a prefix, remove all limits."
8009   (interactive "P")
8010   (when total
8011     (setq gnus-newsgroup-limits
8012           (list (mapcar (lambda (h) (mail-header-number h))
8013                         gnus-newsgroup-headers))))
8014   (unless gnus-newsgroup-limits
8015     (error "No limit to pop"))
8016   (prog1
8017       (gnus-summary-limit nil 'pop)
8018     (gnus-summary-position-point)))
8019
8020 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
8021   "Limit the summary buffer to articles that have subjects that match a regexp.
8022 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
8023   (interactive
8024    (list (read-string (if current-prefix-arg
8025                           "Exclude subject (regexp): "
8026                         "Limit to subject (regexp): "))
8027          nil current-prefix-arg))
8028   (unless header
8029     (setq header "subject"))
8030   (when (not (equal "" subject))
8031     (prog1
8032         (let ((articles (gnus-summary-find-matching
8033                          (or header "subject") subject 'all nil nil
8034                          not-matching)))
8035           (unless articles
8036             (error "Found no matches for \"%s\"" subject))
8037           (gnus-summary-limit articles))
8038       (gnus-summary-position-point))))
8039
8040 (defun gnus-summary-limit-to-author (from &optional not-matching)
8041   "Limit the summary buffer to articles that have authors that match a regexp.
8042 If NOT-MATCHING, excluding articles that have authors that match a regexp."
8043   (interactive
8044    (list (read-string (if current-prefix-arg
8045                           "Exclude author (regexp): "
8046                         "Limit to author (regexp): "))
8047          current-prefix-arg))
8048   (gnus-summary-limit-to-subject from "from" not-matching))
8049
8050 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8051   "Limit the summary buffer to articles with the given RECIPIENT.
8052
8053 If NOT-MATCHING, exclude RECIPIENT.
8054
8055 To and Cc headers are checked.  You need to include them in
8056 `nnmail-extra-headers'."
8057   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8058   (interactive
8059    (list (read-string (format "%s recipient (regexp): "
8060                               (if current-prefix-arg "Exclude" "Limit to")))
8061          current-prefix-arg))
8062   (when (not (equal "" recipient))
8063     (prog1 (let* ((to
8064                    (if (memq 'To nnmail-extra-headers)
8065                        (gnus-summary-find-matching
8066                         (cons 'extra 'To) recipient 'all nil nil
8067                         not-matching)
8068                      (gnus-message
8069                       1 "`To' isn't present in `nnmail-extra-headers'")
8070                      (sit-for 1)
8071                      nil))
8072                   (cc
8073                    (if (memq 'Cc nnmail-extra-headers)
8074                        (gnus-summary-find-matching
8075                         (cons 'extra 'Cc) recipient 'all nil nil
8076                         not-matching)
8077                      (gnus-message
8078                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8079                      (sit-for 1)
8080                      nil))
8081                   (articles
8082                    (if not-matching
8083                        ;; We need the numbers that are in both lists:
8084                        (mapcar (lambda (a)
8085                                  (and (memq a to) a))
8086                                cc)
8087                      (nconc to cc))))
8088              (unless articles
8089                (error "Found no matches for \"%s\"" recipient))
8090              (gnus-summary-limit articles))
8091       (gnus-summary-position-point))))
8092
8093 (defun gnus-summary-limit-to-address (address &optional not-matching)
8094   "Limit the summary buffer to articles with the given ADDRESS.
8095
8096 If NOT-MATCHING, exclude ADDRESS.
8097
8098 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8099 in `nnmail-extra-headers'."
8100   (interactive
8101    (list (read-string (format "%s address (regexp): "
8102                               (if current-prefix-arg "Exclude" "Limit to")))
8103          current-prefix-arg))
8104   (when (not (equal "" address))
8105     (prog1 (let* ((to
8106                    (if (memq 'To nnmail-extra-headers)
8107                        (gnus-summary-find-matching
8108                         (cons 'extra 'To) address 'all nil nil
8109                         not-matching)
8110                      (gnus-message
8111                       1 "`To' isn't present in `nnmail-extra-headers'")
8112                      (sit-for 1)
8113                      t))
8114                   (cc
8115                    (if (memq 'Cc nnmail-extra-headers)
8116                        (gnus-summary-find-matching
8117                         (cons 'extra 'Cc) address 'all nil nil
8118                         not-matching)
8119                      (gnus-message
8120                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8121                      (sit-for 1)
8122                      t))
8123                   (from
8124                    (gnus-summary-find-matching "from" address
8125                                                'all nil nil not-matching))
8126                   (articles
8127                    (if not-matching
8128                        ;; We need the numbers that are in all lists:
8129                        (if (eq cc t)
8130                            (if (eq to t)
8131                                from
8132                              (mapcar (lambda (a) (car (memq a from))) to))
8133                          (if (eq to t)
8134                              (mapcar (lambda (a) (car (memq a from))) cc)
8135                            (mapcar (lambda (a) (car (memq a from)))
8136                                    (mapcar (lambda (a) (car (memq a to)))
8137                                            cc))))
8138                      (nconc (if (eq to t) nil to)
8139                             (if (eq cc t) nil cc)
8140                             from))))
8141              (unless articles
8142                (error "Found no matches for \"%s\"" address))
8143              (gnus-summary-limit articles))
8144       (gnus-summary-position-point))))
8145
8146 (defun gnus-summary-limit-strange-charsets-predicate (header)
8147   (let ((string (concat (mail-header-subject header)
8148                         (mail-header-from header)))
8149         charset found)
8150     (dotimes (i (1- (length string)))
8151       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8152       (when (string-match "unicode\\|big\\|japanese" charset)
8153         (setq found t)))
8154     found))
8155
8156 (defun gnus-summary-limit-to-predicate (predicate)
8157   "Limit to articles where PREDICATE returns non-nil.
8158 PREDICATE will be called with the header structures of the
8159 articles."
8160   (let ((articles nil)
8161         (case-fold-search t))
8162     (dolist (header gnus-newsgroup-headers)
8163       (when (funcall predicate header)
8164         (push (mail-header-number header) articles)))
8165     (gnus-summary-limit (nreverse articles))))
8166
8167 (defun gnus-summary-limit-to-age (age &optional younger-p)
8168   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8169 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8170 articles that are younger than AGE days."
8171   (interactive
8172    (let ((younger current-prefix-arg)
8173          (days-got nil)
8174          days)
8175      (while (not days-got)
8176        (setq days (if younger
8177                       (read-string "Limit to articles younger than (in days, older when negative): ")
8178                     (read-string
8179                      "Limit to articles older than (in days, younger when negative): ")))
8180        (when (> (length days) 0)
8181          (setq days (read days)))
8182        (if (numberp days)
8183            (progn
8184              (setq days-got t)
8185              (when (< days 0)
8186                (setq younger (not younger))
8187                (setq days (* days -1))))
8188          (message "Please enter a number.")
8189          (sleep-for 1)))
8190      (list days younger)))
8191   (prog1
8192       (let ((data gnus-newsgroup-data)
8193             (cutoff (days-to-time age))
8194             articles d date is-younger)
8195         (while (setq d (pop data))
8196           (when (and (vectorp (gnus-data-header d))
8197                      (setq date (mail-header-date (gnus-data-header d))))
8198             (setq is-younger (time-less-p
8199                               (time-since (condition-case ()
8200                                               (date-to-time date)
8201                                             (error '(0 0))))
8202                               cutoff))
8203             (when (if younger-p
8204                       is-younger
8205                     (not is-younger))
8206               (push (gnus-data-number d) articles))))
8207         (gnus-summary-limit (nreverse articles)))
8208     (gnus-summary-position-point)))
8209
8210 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8211   "Limit the summary buffer to articles that match an 'extra' header."
8212   (interactive
8213    (let ((header
8214           (intern
8215            (gnus-completing-read-with-default
8216             (symbol-name (car gnus-extra-headers))
8217             (if current-prefix-arg
8218                 "Exclude extra header"
8219               "Limit extra header")
8220             (mapcar (lambda (x)
8221                       (cons (symbol-name x) x))
8222                     gnus-extra-headers)
8223             nil
8224             t))))
8225      (list header
8226            (read-string (format "%s header %s (regexp): "
8227                                 (if current-prefix-arg "Exclude" "Limit to")
8228                                 header))
8229            current-prefix-arg)))
8230   (when (not (equal "" regexp))
8231     (prog1
8232         (let ((articles (gnus-summary-find-matching
8233                          (cons 'extra header) regexp 'all nil nil
8234                          not-matching)))
8235           (unless articles
8236             (error "Found no matches for \"%s\"" regexp))
8237           (gnus-summary-limit articles))
8238       (gnus-summary-position-point))))
8239
8240 (defun gnus-summary-limit-to-display-predicate ()
8241   "Limit the summary buffer to the predicated in the `display' group parameter."
8242   (interactive)
8243   (unless gnus-newsgroup-display
8244     (error "There is no `display' group parameter"))
8245   (let (articles)
8246     (dolist (number gnus-newsgroup-articles)
8247       (when (funcall gnus-newsgroup-display)
8248         (push number articles)))
8249     (gnus-summary-limit articles))
8250   (gnus-summary-position-point))
8251
8252 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8253 (make-obsolete
8254  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8255
8256 (defun gnus-summary-limit-to-unread (&optional all)
8257   "Limit the summary buffer to articles that are not marked as read.
8258 If ALL is non-nil, limit strictly to unread articles."
8259   (interactive "P")
8260   (if all
8261       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8262     (gnus-summary-limit-to-marks
8263      ;; Concat all the marks that say that an article is read and have
8264      ;; those removed.
8265      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8266            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8267            gnus-low-score-mark gnus-expirable-mark
8268            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8269            gnus-duplicate-mark gnus-souped-mark)
8270      'reverse)))
8271
8272 (defun gnus-summary-limit-to-headers (match &optional reverse)
8273   "Limit the summary buffer to articles that have headers that match MATCH.
8274 If REVERSE (the prefix), limit to articles that don't match."
8275   (interactive "sMatch headers (regexp): \nP")
8276   (gnus-summary-limit-to-bodies match reverse t))
8277
8278 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8279   "Limit the summary buffer to articles that have bodies that match MATCH.
8280 If REVERSE (the prefix), limit to articles that don't match."
8281   (interactive "sMatch body (regexp): \nP")
8282   (let ((articles nil)
8283         (gnus-select-article-hook nil)  ;Disable hook.
8284         (gnus-article-prepare-hook nil)
8285         (gnus-use-article-prefetch nil)
8286         (gnus-keep-backlog nil)
8287         (gnus-break-pages nil)
8288         (gnus-summary-display-arrow nil)
8289         (gnus-updated-mode-lines nil)
8290         (gnus-auto-center-summary nil)
8291         (gnus-display-mime-function nil))
8292     (dolist (data gnus-newsgroup-data)
8293       (let (gnus-mark-article-hook)
8294         (gnus-summary-select-article t t nil (gnus-data-number data)))
8295       (save-excursion
8296         (set-buffer gnus-article-buffer)
8297         (article-goto-body)
8298         (let* ((case-fold-search t)
8299                (found (if headersp
8300                           (re-search-backward match nil t)
8301                         (re-search-forward match nil t))))
8302           (when (or (and found
8303                          (not reverse))
8304                     (and (not found)
8305                          reverse))
8306             (push (gnus-data-number data) articles)))))
8307     (if (not articles)
8308         (message "No messages matched")
8309       (gnus-summary-limit articles)))
8310   (gnus-summary-position-point))
8311
8312 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8313   "Limit the summary buffer to articles that aren't part on any thread.
8314 If THREADSP (the prefix), limit to articles that are in threads."
8315   (interactive "P")
8316   (let ((articles nil)
8317         thread-articles
8318         threads)
8319     (dolist (thread gnus-newsgroup-threads)
8320       (if (stringp (car thread))
8321           (dolist (thread (cdr thread))
8322             (push thread threads))
8323         (push thread threads)))
8324     (dolist (thread threads)
8325       (setq thread-articles (gnus-articles-in-thread thread))
8326       (when (or (and threadsp
8327                      (> (length thread-articles) 1))
8328                 (and (not threadsp)
8329                      (= (length thread-articles) 1)))
8330         (setq articles (nconc thread-articles articles))))
8331     (if (not articles)
8332         (message "No messages matched")
8333       (gnus-summary-limit articles))
8334     (gnus-summary-position-point)))
8335
8336 (defun gnus-summary-limit-to-replied (&optional unreplied)
8337   "Limit the summary buffer to replied articles.
8338 If UNREPLIED (the prefix), limit to unreplied articles."
8339   (interactive "P")
8340   (if unreplied
8341       (gnus-summary-limit
8342        (gnus-set-difference gnus-newsgroup-articles
8343         gnus-newsgroup-replied))
8344     (gnus-summary-limit gnus-newsgroup-replied))
8345   (gnus-summary-position-point))
8346
8347 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8348 (make-obsolete 'gnus-summary-delete-marked-with
8349                'gnus-summary-limit-exclude-marks)
8350
8351 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8352   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8353 If REVERSE, limit the summary buffer to articles that are marked
8354 with MARKS.  MARKS can either be a string of marks or a list of marks.
8355 Returns how many articles were removed."
8356   (interactive "sMarks: ")
8357   (gnus-summary-limit-to-marks marks t))
8358
8359 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8360   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8361 If REVERSE (the prefix), limit the summary buffer to articles that are
8362 not marked with MARKS.  MARKS can either be a string of marks or a
8363 list of marks.
8364 Returns how many articles were removed."
8365   (interactive "sMarks: \nP")
8366   (prog1
8367       (let ((data gnus-newsgroup-data)
8368             (marks (if (listp marks) marks
8369                      (append marks nil))) ; Transform to list.
8370             articles)
8371         (while data
8372           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8373                   (memq (gnus-data-mark (car data)) marks))
8374             (push (gnus-data-number (car data)) articles))
8375           (setq data (cdr data)))
8376         (gnus-summary-limit articles))
8377     (gnus-summary-position-point)))
8378
8379 (defun gnus-summary-limit-to-score (score)
8380   "Limit to articles with score at or above SCORE."
8381   (interactive "NLimit to articles with score of at least: ")
8382   (let ((data gnus-newsgroup-data)
8383         articles)
8384     (while data
8385       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8386                 score)
8387         (push (gnus-data-number (car data)) articles))
8388       (setq data (cdr data)))
8389     (prog1
8390         (gnus-summary-limit articles)
8391       (gnus-summary-position-point))))
8392
8393 (defun gnus-summary-limit-to-unseen ()
8394   "Limit to unseen articles."
8395   (interactive)
8396   (prog1
8397       (gnus-summary-limit gnus-newsgroup-unseen)
8398     (gnus-summary-position-point)))
8399
8400 (defun gnus-summary-limit-include-thread (id)
8401   "Display all the hidden articles that is in the thread with ID in it.
8402 When called interactively, ID is the Message-ID of the current
8403 article."
8404   (interactive (list (mail-header-id (gnus-summary-article-header))))
8405   (let ((articles (gnus-articles-in-thread
8406                    (gnus-id-to-thread (gnus-root-id id)))))
8407     (prog1
8408         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8409       (gnus-summary-limit-include-matching-articles
8410        "subject"
8411        (regexp-quote (gnus-simplify-subject-re
8412                       (mail-header-subject (gnus-id-to-header id)))))
8413       (gnus-summary-position-point))))
8414
8415 (defun gnus-summary-limit-include-matching-articles (header regexp)
8416   "Display all the hidden articles that have HEADERs that match REGEXP."
8417   (interactive (list (read-string "Match on header: ")
8418                      (read-string "Regexp: ")))
8419   (let ((articles (gnus-find-matching-articles header regexp)))
8420     (prog1
8421         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8422       (gnus-summary-position-point))))
8423
8424 (defun gnus-summary-insert-dormant-articles ()
8425   "Insert all the dormant articles for this group into the current buffer."
8426   (interactive)
8427   (let ((gnus-verbose (max 6 gnus-verbose)))
8428     (if (not gnus-newsgroup-dormant)
8429         (gnus-message 3 "No dormant articles for this group")
8430       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8431
8432 (defun gnus-summary-insert-ticked-articles ()
8433   "Insert ticked articles for this group into the current buffer."
8434   (interactive)
8435   (let ((gnus-verbose (max 6 gnus-verbose)))
8436     (if (not gnus-newsgroup-marked)
8437         (gnus-message 3 "No ticked articles for this group")
8438       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8439
8440 (defun gnus-summary-limit-include-dormant ()
8441   "Display all the hidden articles that are marked as dormant.
8442 Note that this command only works on a subset of the articles currently
8443 fetched for this group."
8444   (interactive)
8445   (unless gnus-newsgroup-dormant
8446     (error "There are no dormant articles in this group"))
8447   (prog1
8448       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8449     (gnus-summary-position-point)))
8450
8451 (defun gnus-summary-limit-exclude-dormant ()
8452   "Hide all dormant articles."
8453   (interactive)
8454   (prog1
8455       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8456     (gnus-summary-position-point)))
8457
8458 (defun gnus-summary-limit-exclude-childless-dormant ()
8459   "Hide all dormant articles that have no children."
8460   (interactive)
8461   (let ((data (gnus-data-list t))
8462         articles d children)
8463     ;; Find all articles that are either not dormant or have
8464     ;; children.
8465     (while (setq d (pop data))
8466       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8467                 (and (setq children
8468                            (gnus-article-children (gnus-data-number d)))
8469                      (let (found)
8470                        (while children
8471                          (when (memq (car children) articles)
8472                            (setq children nil
8473                                  found t))
8474                          (pop children))
8475                        found)))
8476         (push (gnus-data-number d) articles)))
8477     ;; Do the limiting.
8478     (prog1
8479         (gnus-summary-limit articles)
8480       (gnus-summary-position-point))))
8481
8482 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8483   "Mark all unread excluded articles as read.
8484 If ALL, mark even excluded ticked and dormants as read."
8485   (interactive "P")
8486   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8487   (let ((articles (gnus-sorted-ndifference
8488                    (sort
8489                     (mapcar (lambda (h) (mail-header-number h))
8490                             gnus-newsgroup-headers)
8491                     '<)
8492                    gnus-newsgroup-limit))
8493         article)
8494     (setq gnus-newsgroup-unreads
8495           (gnus-sorted-intersection gnus-newsgroup-unreads
8496                                     gnus-newsgroup-limit))
8497     (if all
8498         (setq gnus-newsgroup-dormant nil
8499               gnus-newsgroup-marked nil
8500               gnus-newsgroup-reads
8501               (nconc
8502                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8503                gnus-newsgroup-reads))
8504       (while (setq article (pop articles))
8505         (unless (or (memq article gnus-newsgroup-dormant)
8506                     (memq article gnus-newsgroup-marked))
8507           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8508
8509 (defun gnus-summary-limit (articles &optional pop)
8510   (if pop
8511       ;; We pop the previous limit off the stack and use that.
8512       (setq articles (car gnus-newsgroup-limits)
8513             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8514     ;; We use the new limit, so we push the old limit on the stack.
8515     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8516   ;; Set the limit.
8517   (setq gnus-newsgroup-limit articles)
8518   (let ((total (length gnus-newsgroup-data))
8519         (data (gnus-data-find-list (gnus-summary-article-number)))
8520         (gnus-summary-mark-below nil)   ; Inhibit this.
8521         found)
8522     ;; This will do all the work of generating the new summary buffer
8523     ;; according to the new limit.
8524     (gnus-summary-prepare)
8525     ;; Hide any threads, possibly.
8526     (gnus-summary-maybe-hide-threads)
8527     ;; Try to return to the article you were at, or one in the
8528     ;; neighborhood.
8529     (when data
8530       ;; We try to find some article after the current one.
8531       (while data
8532         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8533           (setq data nil
8534                 found t))
8535         (setq data (cdr data))))
8536     (unless found
8537       ;; If there is no data, that means that we were after the last
8538       ;; article.  The same goes when we can't find any articles
8539       ;; after the current one.
8540       (goto-char (point-max))
8541       (gnus-summary-find-prev))
8542     (gnus-set-mode-line 'summary)
8543     ;; We return how many articles were removed from the summary
8544     ;; buffer as a result of the new limit.
8545     (- total (length gnus-newsgroup-data))))
8546
8547 (defsubst gnus-invisible-cut-children (threads)
8548   (let ((num 0))
8549     (while threads
8550       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8551         (incf num))
8552       (pop threads))
8553     (< num 2)))
8554
8555 (defsubst gnus-cut-thread (thread)
8556   "Go forwards in the thread until we find an article that we want to display."
8557   (when (or (eq gnus-fetch-old-headers 'some)
8558             (eq gnus-fetch-old-headers 'invisible)
8559             (numberp gnus-fetch-old-headers)
8560             (eq gnus-build-sparse-threads 'some)
8561             (eq gnus-build-sparse-threads 'more))
8562     ;; Deal with old-fetched headers and sparse threads.
8563     (while (and
8564             thread
8565             (or
8566              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8567              (gnus-summary-article-ancient-p
8568               (mail-header-number (car thread))))
8569             (if (or (<= (length (cdr thread)) 1)
8570                     (eq gnus-fetch-old-headers 'invisible))
8571                 (setq gnus-newsgroup-limit
8572                       (delq (mail-header-number (car thread))
8573                             gnus-newsgroup-limit)
8574                       thread (cadr thread))
8575               (when (gnus-invisible-cut-children (cdr thread))
8576                 (let ((th (cdr thread)))
8577                   (while th
8578                     (if (memq (mail-header-number (caar th))
8579                               gnus-newsgroup-limit)
8580                         (setq thread (car th)
8581                               th nil)
8582                       (setq th (cdr th))))))))))
8583   thread)
8584
8585 (defun gnus-cut-threads (threads)
8586   "Cut off all uninteresting articles from the beginning of THREADS."
8587   (when (or (eq gnus-fetch-old-headers 'some)
8588             (eq gnus-fetch-old-headers 'invisible)
8589             (numberp gnus-fetch-old-headers)
8590             (eq gnus-build-sparse-threads 'some)
8591             (eq gnus-build-sparse-threads 'more))
8592     (let ((th threads))
8593       (while th
8594         (setcar th (gnus-cut-thread (car th)))
8595         (setq th (cdr th)))))
8596   ;; Remove nixed out threads.
8597   (delq nil threads))
8598
8599 (defun gnus-summary-initial-limit (&optional show-if-empty)
8600   "Figure out what the initial limit is supposed to be on group entry.
8601 This entails weeding out unwanted dormants, low-scored articles,
8602 fetch-old-headers verbiage, and so on."
8603   ;; Most groups have nothing to remove.
8604   (if (or gnus-inhibit-limiting
8605           (and (null gnus-newsgroup-dormant)
8606                (eq gnus-newsgroup-display 'gnus-not-ignore)
8607                (not (eq gnus-fetch-old-headers 'some))
8608                (not (numberp gnus-fetch-old-headers))
8609                (not (eq gnus-fetch-old-headers 'invisible))
8610                (null gnus-summary-expunge-below)
8611                (not (eq gnus-build-sparse-threads 'some))
8612                (not (eq gnus-build-sparse-threads 'more))
8613                (null gnus-thread-expunge-below)
8614                (not gnus-use-nocem)))
8615       ()                                ; Do nothing.
8616     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8617     (setq gnus-newsgroup-limit nil)
8618     (mapatoms
8619      (lambda (node)
8620        (unless (car (symbol-value node))
8621          ;; These threads have no parents -- they are roots.
8622          (let ((nodes (cdr (symbol-value node)))
8623                thread)
8624            (while nodes
8625              (if (and gnus-thread-expunge-below
8626                       (< (gnus-thread-total-score (car nodes))
8627                          gnus-thread-expunge-below))
8628                  (gnus-expunge-thread (pop nodes))
8629                (setq thread (pop nodes))
8630                (gnus-summary-limit-children thread))))))
8631      gnus-newsgroup-dependencies)
8632     ;; If this limitation resulted in an empty group, we might
8633     ;; pop the previous limit and use it instead.
8634     (when (and (not gnus-newsgroup-limit)
8635                show-if-empty)
8636       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8637     gnus-newsgroup-limit))
8638
8639 (defun gnus-summary-limit-children (thread)
8640   "Return 1 if this subthread is visible and 0 if it is not."
8641   ;; First we get the number of visible children to this thread.  This
8642   ;; is done by recursing down the thread using this function, so this
8643   ;; will really go down to a leaf article first, before slowly
8644   ;; working its way up towards the root.
8645   (when thread
8646     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8647            (children
8648            (if (cdr thread)
8649                (apply '+ (mapcar 'gnus-summary-limit-children
8650                                  (cdr thread)))
8651              0))
8652           (number (mail-header-number (car thread)))
8653           score)
8654       (if (and
8655            (not (memq number gnus-newsgroup-marked))
8656            (or
8657             ;; If this article is dormant and has absolutely no visible
8658             ;; children, then this article isn't visible.
8659             (and (memq number gnus-newsgroup-dormant)
8660                  (zerop children))
8661             ;; If this is "fetch-old-headered" and there is no
8662             ;; visible children, then we don't want this article.
8663             (and (or (eq gnus-fetch-old-headers 'some)
8664                      (numberp gnus-fetch-old-headers))
8665                  (gnus-summary-article-ancient-p number)
8666                  (zerop children))
8667             ;; If this is "fetch-old-headered" and `invisible', then
8668             ;; we don't want this article.
8669             (and (eq gnus-fetch-old-headers 'invisible)
8670                  (gnus-summary-article-ancient-p number))
8671             ;; If this is a sparsely inserted article with no children,
8672             ;; we don't want it.
8673             (and (eq gnus-build-sparse-threads 'some)
8674                  (gnus-summary-article-sparse-p number)
8675                  (zerop children))
8676             ;; If we use expunging, and this article is really
8677             ;; low-scored, then we don't want this article.
8678             (when (and gnus-summary-expunge-below
8679                        (< (setq score
8680                                 (or (cdr (assq number gnus-newsgroup-scored))
8681                                     gnus-summary-default-score))
8682                           gnus-summary-expunge-below))
8683               ;; We increase the expunge-tally here, but that has
8684               ;; nothing to do with the limits, really.
8685               (incf gnus-newsgroup-expunged-tally)
8686               ;; We also mark as read here, if that's wanted.
8687               (when (and gnus-summary-mark-below
8688                          (< score gnus-summary-mark-below))
8689                 (setq gnus-newsgroup-unreads
8690                       (delq number gnus-newsgroup-unreads))
8691                 (if gnus-newsgroup-auto-expire
8692                     (push number gnus-newsgroup-expirable)
8693                   (push (cons number gnus-low-score-mark)
8694                         gnus-newsgroup-reads)))
8695               t)
8696             ;; Do the `display' group parameter.
8697             (and gnus-newsgroup-display
8698                  (not (funcall gnus-newsgroup-display)))
8699             ;; Check NoCeM things.
8700             (when (and gnus-use-nocem
8701                        (gnus-nocem-unwanted-article-p
8702                         (mail-header-id (car thread))))
8703               (setq gnus-newsgroup-unreads
8704                     (delq number gnus-newsgroup-unreads))
8705               t)))
8706           ;; Nope, invisible article.
8707           0
8708         ;; Ok, this article is to be visible, so we add it to the limit
8709         ;; and return 1.
8710         (push number gnus-newsgroup-limit)
8711         1))))
8712
8713 (defun gnus-expunge-thread (thread)
8714   "Mark all articles in THREAD as read."
8715   (let* ((number (mail-header-number (car thread))))
8716     (incf gnus-newsgroup-expunged-tally)
8717     ;; We also mark as read here, if that's wanted.
8718     (setq gnus-newsgroup-unreads
8719           (delq number gnus-newsgroup-unreads))
8720     (if gnus-newsgroup-auto-expire
8721         (push number gnus-newsgroup-expirable)
8722       (push (cons number gnus-low-score-mark)
8723             gnus-newsgroup-reads)))
8724   ;; Go recursively through all subthreads.
8725   (mapcar 'gnus-expunge-thread (cdr thread)))
8726
8727 ;; Summary article oriented commands
8728
8729 (defun gnus-summary-refer-parent-article (n)
8730   "Refer parent article N times.
8731 If N is negative, go to ancestor -N instead.
8732 The difference between N and the number of articles fetched is returned."
8733   (interactive "p")
8734   (let ((skip 1)
8735         error header ref)
8736     (when (not (natnump n))
8737       (setq skip (abs n)
8738             n 1))
8739     (while (and (> n 0)
8740                 (not error))
8741       (setq header (gnus-summary-article-header))
8742       (if (and (eq (mail-header-number header)
8743                    (cdr gnus-article-current))
8744                (equal gnus-newsgroup-name
8745                       (car gnus-article-current)))
8746           ;; If we try to find the parent of the currently
8747           ;; displayed article, then we take a look at the actual
8748           ;; References header, since this is slightly more
8749           ;; reliable than the References field we got from the
8750           ;; server.
8751           (save-excursion
8752             (set-buffer gnus-original-article-buffer)
8753             (nnheader-narrow-to-headers)
8754             (unless (setq ref (message-fetch-field "references"))
8755               (when (setq ref (message-fetch-field "in-reply-to"))
8756                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8757             (widen))
8758         (setq ref
8759               ;; It's not the current article, so we take a bet on
8760               ;; the value we got from the server.
8761               (mail-header-references header)))
8762       (if (and ref
8763                (not (equal ref "")))
8764           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8765             (gnus-message 1 "Couldn't find parent"))
8766         (gnus-message 1 "No references in article %d"
8767                       (gnus-summary-article-number))
8768         (setq error t))
8769       (decf n))
8770     (gnus-summary-position-point)
8771     n))
8772
8773 (defun gnus-summary-refer-references ()
8774   "Fetch all articles mentioned in the References header.
8775 Return the number of articles fetched."
8776   (interactive)
8777   (let ((ref (mail-header-references (gnus-summary-article-header)))
8778         (current (gnus-summary-article-number))
8779         (n 0))
8780     (if (or (not ref)
8781             (equal ref ""))
8782         (error "No References in the current article")
8783       ;; For each Message-ID in the References header...
8784       (while (string-match "<[^>]*>" ref)
8785         (incf n)
8786         ;; ... fetch that article.
8787         (gnus-summary-refer-article
8788          (prog1 (match-string 0 ref)
8789            (setq ref (substring ref (match-end 0))))))
8790       (gnus-summary-goto-subject current)
8791       (gnus-summary-position-point)
8792       n)))
8793
8794 (defun gnus-summary-refer-thread (&optional limit)
8795   "Fetch all articles in the current thread.
8796 If LIMIT (the numerical prefix), fetch that many old headers instead
8797 of what's specified by the `gnus-refer-thread-limit' variable."
8798   (interactive "P")
8799   (let ((id (mail-header-id (gnus-summary-article-header)))
8800         (limit (if limit (prefix-numeric-value limit)
8801                  gnus-refer-thread-limit)))
8802     (unless (eq gnus-fetch-old-headers 'invisible)
8803       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8804       ;; Retrieve the headers and read them in.
8805       (if (eq (if (numberp limit)
8806                   (gnus-retrieve-headers
8807                    (list (min
8808                           (+ (mail-header-number
8809                               (gnus-summary-article-header))
8810                              limit)
8811                           gnus-newsgroup-end))
8812                    gnus-newsgroup-name (* limit 2))
8813                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8814                 ;; headers.
8815                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8816                                        gnus-newsgroup-name limit))
8817               'nov)
8818           (gnus-build-all-threads)
8819         (error "Can't fetch thread from back ends that don't support NOV"))
8820       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8821     (gnus-summary-limit-include-thread id)))
8822
8823 (defun gnus-summary-refer-article (message-id)
8824   "Fetch an article specified by MESSAGE-ID."
8825   (interactive "sMessage-ID: ")
8826   (when (and (stringp message-id)
8827              (not (zerop (length message-id))))
8828     (setq message-id (gnus-replace-in-string message-id " " ""))
8829     ;; Construct the correct Message-ID if necessary.
8830     ;; Suggested by tale@pawl.rpi.edu.
8831     (unless (string-match "^<" message-id)
8832       (setq message-id (concat "<" message-id)))
8833     (unless (string-match ">$" message-id)
8834       (setq message-id (concat message-id ">")))
8835     ;; People often post MIDs from URLs, so unhex it:
8836     (unless (string-match "@" message-id)
8837       (setq message-id (gnus-url-unhex-string message-id)))
8838     (let* ((header (gnus-id-to-header message-id))
8839            (sparse (and header
8840                         (gnus-summary-article-sparse-p
8841                          (mail-header-number header))
8842                         (memq (mail-header-number header)
8843                               gnus-newsgroup-limit)))
8844            number)
8845       (cond
8846        ;; If the article is present in the buffer we just go to it.
8847        ((and header
8848              (or (not (gnus-summary-article-sparse-p
8849                        (mail-header-number header)))
8850                  sparse))
8851         (prog1
8852             (gnus-summary-goto-article
8853              (mail-header-number header) nil t)
8854           (when sparse
8855             (gnus-summary-update-article (mail-header-number header)))))
8856        (t
8857         ;; We fetch the article.
8858         (catch 'found
8859           (dolist (gnus-override-method (gnus-refer-article-methods))
8860             (when (and (gnus-check-server gnus-override-method)
8861                        ;; Fetch the header,
8862                        (setq number (gnus-summary-insert-subject message-id)))
8863               ;; and display the article.
8864               (gnus-summary-select-article nil nil nil number)
8865               (throw 'found t)))
8866           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8867
8868 (defun gnus-refer-article-methods ()
8869   "Return a list of referable methods."
8870   (cond
8871    ;; No method, so we default to current and native.
8872    ((null gnus-refer-article-method)
8873     (list gnus-current-select-method gnus-select-method))
8874    ;; Current.
8875    ((eq 'current gnus-refer-article-method)
8876     (list gnus-current-select-method))
8877    ;; List of select methods.
8878    ((not (and (symbolp (car gnus-refer-article-method))
8879               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8880     (let (out)
8881       (dolist (method gnus-refer-article-method)
8882         (push (if (eq 'current method)
8883                   gnus-current-select-method
8884                 method)
8885               out))
8886       (nreverse out)))
8887    ;; One single select method.
8888    (t
8889     (list gnus-refer-article-method))))
8890
8891 (defun gnus-summary-edit-parameters ()
8892   "Edit the group parameters of the current group."
8893   (interactive)
8894   (gnus-group-edit-group gnus-newsgroup-name 'params))
8895
8896 (defun gnus-summary-customize-parameters ()
8897   "Customize the group parameters of the current group."
8898   (interactive)
8899   (gnus-group-customize gnus-newsgroup-name))
8900
8901 (defun gnus-summary-enter-digest-group (&optional force)
8902   "Enter an nndoc group based on the current article.
8903 If FORCE, force a digest interpretation.  If not, try
8904 to guess what the document format is."
8905   (interactive "P")
8906   (let ((conf gnus-current-window-configuration))
8907     (save-window-excursion
8908       (save-excursion
8909         (let (gnus-article-prepare-hook
8910               gnus-display-mime-function
8911               gnus-break-pages)
8912           (gnus-summary-select-article))))
8913     (setq gnus-current-window-configuration conf)
8914     (let* ((name (format "%s-%d"
8915                          (gnus-group-prefixed-name
8916                           gnus-newsgroup-name (list 'nndoc ""))
8917                          (with-current-buffer gnus-summary-buffer
8918                            gnus-current-article)))
8919            (ogroup gnus-newsgroup-name)
8920            (params (append (gnus-info-params (gnus-get-info ogroup))
8921                            (list (cons 'to-group ogroup))
8922                            (list (cons 'parent-group ogroup))
8923                            (list (cons 'save-article-group ogroup))))
8924            (case-fold-search t)
8925            (buf (current-buffer))
8926            dig to-address)
8927       (save-excursion
8928         (set-buffer gnus-original-article-buffer)
8929         ;; Have the digest group inherit the main mail address of
8930         ;; the parent article.
8931         (when (setq to-address (or (gnus-fetch-field "reply-to")
8932                                    (gnus-fetch-field "from")))
8933           (setq params
8934                 (append
8935                  (list (cons 'to-address
8936                              (funcall gnus-decode-encoded-address-function
8937                                       to-address))))))
8938         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8939         (insert-buffer-substring gnus-original-article-buffer)
8940         ;; Remove lines that may lead nndoc to misinterpret the
8941         ;; document type.
8942         (narrow-to-region
8943          (goto-char (point-min))
8944          (or (search-forward "\n\n" nil t) (point)))
8945         (goto-char (point-min))
8946         (delete-matching-lines "^Path:\\|^From ")
8947         (widen))
8948       (unwind-protect
8949           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8950                     (gnus-newsgroup-ephemeral-ignored-charsets
8951                      gnus-newsgroup-ignored-charsets))
8952                 (gnus-group-read-ephemeral-group
8953                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8954                               (nndoc-article-type
8955                                ,(if force 'mbox 'guess)))
8956                  t nil nil nil
8957                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8958                                                         "ADAPT")))))
8959               ;; Make all postings to this group go to the parent group.
8960               (nconc (gnus-info-params (gnus-get-info name))
8961                      params)
8962             ;; Couldn't select this doc group.
8963             (switch-to-buffer buf)
8964             (gnus-set-global-variables)
8965             (gnus-configure-windows 'summary)
8966             (gnus-message 3 "Article couldn't be entered?"))
8967         (kill-buffer dig)))))
8968
8969 (defun gnus-summary-read-document (n)
8970   "Open a new group based on the current article(s).
8971 This will allow you to read digests and other similar
8972 documents as newsgroups.
8973 Obeys the standard process/prefix convention."
8974   (interactive "P")
8975   (let* ((ogroup gnus-newsgroup-name)
8976          (params (append (gnus-info-params (gnus-get-info ogroup))
8977                          (list (cons 'to-group ogroup))))
8978          group egroup groups vgroup)
8979     (dolist (article (gnus-summary-work-articles n))
8980       (setq group (format "%s-%d" gnus-newsgroup-name article))
8981       (gnus-summary-remove-process-mark article)
8982       (when (gnus-summary-display-article article)
8983         (save-excursion
8984           (with-temp-buffer
8985             (insert-buffer-substring gnus-original-article-buffer)
8986             ;; Remove some headers that may lead nndoc to make
8987             ;; the wrong guess.
8988             (message-narrow-to-head)
8989             (goto-char (point-min))
8990             (delete-matching-lines "^Path:\\|^From ")
8991             (widen)
8992             (if (setq egroup
8993                       (gnus-group-read-ephemeral-group
8994                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8995                                      (nndoc-article-type guess))
8996                        t nil t))
8997                 (progn
8998             ;; Make all postings to this group go to the parent group.
8999                   (nconc (gnus-info-params (gnus-get-info egroup))
9000                          params)
9001                   (push egroup groups))
9002               ;; Couldn't select this doc group.
9003               (gnus-error 3 "Article couldn't be entered"))))))
9004     ;; Now we have selected all the documents.
9005     (cond
9006      ((not groups)
9007       (error "None of the articles could be interpreted as documents"))
9008      ((gnus-group-read-ephemeral-group
9009        (setq vgroup (format
9010                      "nnvirtual:%s-%s" gnus-newsgroup-name
9011                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
9012        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
9013        t
9014        (cons (current-buffer) 'summary)))
9015      (t
9016       (error "Couldn't select virtual nndoc group")))))
9017
9018 (defun gnus-summary-isearch-article (&optional regexp-p)
9019   "Do incremental search forward on the current article.
9020 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
9021   (interactive "P")
9022   (gnus-summary-select-article)
9023   (gnus-configure-windows 'article)
9024   (gnus-eval-in-buffer-window gnus-article-buffer
9025     (save-restriction
9026       (widen)
9027       (isearch-forward regexp-p))))
9028
9029 (defun gnus-summary-repeat-search-article-forward ()
9030   "Repeat the previous search forwards."
9031   (interactive)
9032   (unless gnus-last-search-regexp
9033     (error "No previous search"))
9034   (gnus-summary-search-article-forward gnus-last-search-regexp))
9035
9036 (defun gnus-summary-repeat-search-article-backward ()
9037   "Repeat the previous search backwards."
9038   (interactive)
9039   (unless gnus-last-search-regexp
9040     (error "No previous search"))
9041   (gnus-summary-search-article-forward gnus-last-search-regexp t))
9042
9043 (defun gnus-summary-search-article-forward (regexp &optional backward)
9044   "Search for an article containing REGEXP forward.
9045 If BACKWARD, search backward instead."
9046   (interactive
9047    (list (read-string
9048           (format "Search article %s (regexp%s): "
9049                   (if current-prefix-arg "backward" "forward")
9050                   (if gnus-last-search-regexp
9051                       (concat ", default " gnus-last-search-regexp)
9052                     "")))
9053          current-prefix-arg))
9054   (if (string-equal regexp "")
9055       (setq regexp (or gnus-last-search-regexp ""))
9056     (setq gnus-last-search-regexp regexp)
9057     (setq gnus-article-before-search gnus-current-article))
9058   ;; Intentionally set gnus-last-article.
9059   (setq gnus-last-article gnus-article-before-search)
9060   (let ((gnus-last-article gnus-last-article))
9061     (if (gnus-summary-search-article regexp backward)
9062         (gnus-summary-show-thread)
9063       (signal 'search-failed (list regexp)))))
9064
9065 (defun gnus-summary-search-article-backward (regexp)
9066   "Search for an article containing REGEXP backward."
9067   (interactive
9068    (list (read-string
9069           (format "Search article backward (regexp%s): "
9070                   (if gnus-last-search-regexp
9071                       (concat ", default " gnus-last-search-regexp)
9072                     "")))))
9073   (gnus-summary-search-article-forward regexp 'backward))
9074
9075 (defun gnus-summary-search-article (regexp &optional backward)
9076   "Search for an article containing REGEXP.
9077 Optional argument BACKWARD means do search for backward.
9078 `gnus-select-article-hook' is not called during the search."
9079   ;; We have to require this here to make sure that the following
9080   ;; dynamic binding isn't shadowed by autoloading.
9081   (require 'gnus-async)
9082   (require 'gnus-art)
9083   (let ((gnus-select-article-hook nil)  ;Disable hook.
9084         (gnus-article-prepare-hook nil)
9085         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9086         (gnus-use-article-prefetch nil)
9087         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9088         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9089         (gnus-visual nil)
9090         (gnus-keep-backlog nil)
9091         (gnus-break-pages nil)
9092         (gnus-summary-display-arrow nil)
9093         (gnus-updated-mode-lines nil)
9094         (gnus-auto-center-summary nil)
9095         (sum (current-buffer))
9096         (gnus-display-mime-function nil)
9097         (found nil)
9098         point)
9099     (gnus-save-hidden-threads
9100       (gnus-summary-select-article)
9101       (set-buffer gnus-article-buffer)
9102       (goto-char (window-point (get-buffer-window (current-buffer))))
9103       (when backward
9104         (forward-line -1))
9105       (while (not found)
9106         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9107         (if (if backward
9108                 (re-search-backward regexp nil t)
9109               (re-search-forward regexp nil t))
9110             ;; We found the regexp.
9111             (progn
9112               (setq found 'found)
9113               (beginning-of-line)
9114               (set-window-start
9115                (get-buffer-window (current-buffer))
9116                (point))
9117               (forward-line 1)
9118               (set-window-point
9119                (get-buffer-window (current-buffer))
9120                (point))
9121               (set-buffer sum)
9122               (setq point (point)))
9123           ;; We didn't find it, so we go to the next article.
9124           (set-buffer sum)
9125           (setq found 'not)
9126           (while (eq found 'not)
9127             (if (not (if backward (gnus-summary-find-prev)
9128                        (gnus-summary-find-next)))
9129                 ;; No more articles.
9130                 (setq found t)
9131               ;; Select the next article and adjust point.
9132               (unless (gnus-summary-article-sparse-p
9133                        (gnus-summary-article-number))
9134                 (setq found nil)
9135                 (gnus-summary-select-article)
9136                 (set-buffer gnus-article-buffer)
9137                 (widen)
9138                 (goto-char (if backward (point-max) (point-min))))))))
9139       (gnus-message 7 ""))
9140     ;; Return whether we found the regexp.
9141     (when (eq found 'found)
9142       (goto-char point)
9143       (gnus-summary-show-thread)
9144       (gnus-summary-goto-subject gnus-current-article)
9145       (gnus-summary-position-point)
9146       t)))
9147
9148 (defun gnus-find-matching-articles (header regexp)
9149   "Return a list of all articles that match REGEXP on HEADER.
9150 This search includes all articles in the current group that Gnus has
9151 fetched headers for, whether they are displayed or not."
9152   (let ((articles nil)
9153         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9154         (case-fold-search t))
9155     (dolist (header gnus-newsgroup-headers)
9156       (when (string-match regexp (funcall func header))
9157         (push (mail-header-number header) articles)))
9158     (nreverse articles)))
9159
9160 (defun gnus-summary-find-matching (header regexp &optional backward unread
9161                                           not-case-fold not-matching)
9162   "Return a list of all articles that match REGEXP on HEADER.
9163 The search stars on the current article and goes forwards unless
9164 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9165 If UNREAD is non-nil, only unread articles will
9166 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9167 in the comparisons. If NOT-MATCHING, return a list of all articles that
9168 not match REGEXP on HEADER."
9169   (let ((case-fold-search (not not-case-fold))
9170         articles d func)
9171     (if (consp header)
9172         (if (eq (car header) 'extra)
9173             (setq func
9174                   `(lambda (h)
9175                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9176                          "")))
9177           (error "%s is an invalid header" header))
9178       (unless (fboundp (intern (concat "mail-header-" header)))
9179         (error "%s is not a valid header" header))
9180       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9181     (dolist (d (if (eq backward 'all)
9182                    gnus-newsgroup-data
9183                  (gnus-data-find-list
9184                   (gnus-summary-article-number)
9185                   (gnus-data-list backward))))
9186       (when (and (or (not unread)       ; We want all articles...
9187                      (gnus-data-unread-p d)) ; Or just unreads.
9188                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9189                  (if not-matching
9190                      (not (string-match
9191                            regexp
9192                            (funcall func (gnus-data-header d))))
9193                    (string-match regexp
9194                                  (funcall func (gnus-data-header d)))))
9195         (push (gnus-data-number d) articles))) ; Success!
9196     (nreverse articles)))
9197
9198 (defun gnus-summary-execute-command (header regexp command &optional backward)
9199   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9200 If HEADER is an empty string (or nil), the match is done on the entire
9201 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9202   (interactive
9203    (list (let ((completion-ignore-case t))
9204            (completing-read
9205             "Header name: "
9206             (mapcar (lambda (header) (list (format "%s" header)))
9207                     (append
9208                      '("Number" "Subject" "From" "Lines" "Date"
9209                        "Message-ID" "Xref" "References" "Body")
9210                      gnus-extra-headers))
9211             nil 'require-match))
9212          (read-string "Regexp: ")
9213          (read-key-sequence "Command: ")
9214          current-prefix-arg))
9215   (when (equal header "Body")
9216     (setq header ""))
9217   ;; Hidden thread subtrees must be searched as well.
9218   (gnus-summary-show-all-threads)
9219   ;; We don't want to change current point nor window configuration.
9220   (save-excursion
9221     (save-window-excursion
9222       (let (gnus-visual
9223             gnus-treat-strip-trailing-blank-lines
9224             gnus-treat-strip-leading-blank-lines
9225             gnus-treat-strip-multiple-blank-lines
9226             gnus-treat-hide-boring-headers
9227             gnus-treat-fold-newsgroups
9228             gnus-article-prepare-hook)
9229         (gnus-message 6 "Executing %s..." (key-description command))
9230         ;; We'd like to execute COMMAND interactively so as to give arguments.
9231         (gnus-execute header regexp
9232                       `(call-interactively ',(key-binding command))
9233                       backward)
9234         (gnus-message 6 "Executing %s...done" (key-description command))))))
9235
9236 (defun gnus-summary-beginning-of-article ()
9237   "Scroll the article back to the beginning."
9238   (interactive)
9239   (gnus-summary-select-article)
9240   (gnus-configure-windows 'article)
9241   (gnus-eval-in-buffer-window gnus-article-buffer
9242     (widen)
9243     (goto-char (point-min))
9244     (when gnus-break-pages
9245       (gnus-narrow-to-page))))
9246
9247 (defun gnus-summary-end-of-article ()
9248   "Scroll to the end of the article."
9249   (interactive)
9250   (gnus-summary-select-article)
9251   (gnus-configure-windows 'article)
9252   (gnus-eval-in-buffer-window gnus-article-buffer
9253     (widen)
9254     (goto-char (point-max))
9255     (recenter -3)
9256     (when gnus-break-pages
9257       (gnus-narrow-to-page))))
9258
9259 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9260   "Truncate to LEN and quote all \"(\"'s in STRING."
9261   (gnus-replace-in-string (if (and len (> (length string) len))
9262                               (substring string 0 len)
9263                             string)
9264                           "[()]" "\\\\\\&"))
9265
9266 (defun gnus-summary-print-article (&optional filename n)
9267   "Generate and print a PostScript image of the process-marked (mail) articles.
9268
9269 If used interactively, print the current article if none are
9270 process-marked.  With prefix arg, prompt the user for the name of the
9271 file to save in.
9272
9273 When used from Lisp, accept two optional args FILENAME and N.  N means
9274 to print the next N articles.  If N is negative, print the N previous
9275 articles.  If N is nil and articles have been marked with the process
9276 mark, print these instead.
9277
9278 If the optional first argument FILENAME is nil, send the image to the
9279 printer.  If FILENAME is a string, save the PostScript image in a file with
9280 that name.  If FILENAME is a number, prompt the user for the name of the file
9281 to save in."
9282   (interactive (list (ps-print-preprint current-prefix-arg)))
9283   (dolist (article (gnus-summary-work-articles n))
9284     (gnus-summary-select-article nil nil 'pseudo article)
9285     (gnus-eval-in-buffer-window gnus-article-buffer
9286       (gnus-print-buffer))
9287     (gnus-summary-remove-process-mark article))
9288   (ps-despool filename))
9289
9290 (defun gnus-print-buffer ()
9291   (let ((buffer (generate-new-buffer " *print*")))
9292     (unwind-protect
9293         (progn
9294           (copy-to-buffer buffer (point-min) (point-max))
9295           (set-buffer buffer)
9296           (gnus-remove-text-with-property 'gnus-decoration)
9297           (when (gnus-visual-p 'article-highlight 'highlight)
9298             ;; Copy-to-buffer doesn't copy overlay.  So redo
9299             ;; highlight.
9300             (let ((gnus-article-buffer buffer))
9301               (gnus-article-highlight-citation t)
9302               (gnus-article-highlight-signature)
9303               (gnus-article-emphasize)
9304               (gnus-article-delete-invisible-text)))
9305           (let ((ps-left-header
9306                  (list
9307                   (concat "("
9308                           (gnus-summary-print-truncate-and-quote
9309                            (mail-header-subject gnus-current-headers)
9310                            66) ")")
9311                   (concat "("
9312                           (gnus-summary-print-truncate-and-quote
9313                            (mail-header-from gnus-current-headers)
9314                            45) ")")))
9315                 (ps-right-header
9316                  (list
9317                   "/pagenumberstring load"
9318                   (concat "("
9319                           (mail-header-date gnus-current-headers) ")"))))
9320             (gnus-run-hooks 'gnus-ps-print-hook)
9321             (save-excursion
9322               (if ps-print-color-p
9323                   (ps-spool-buffer-with-faces)
9324                 (ps-spool-buffer)))))
9325       (kill-buffer buffer))))
9326
9327 (defun gnus-summary-show-article (&optional arg)
9328   "Force redisplaying of the current article.
9329 If ARG (the prefix) is a number, show the article with the charset
9330 defined in `gnus-summary-show-article-charset-alist', or the charset
9331 input.
9332 If ARG (the prefix) is non-nil and not a number, show the raw article
9333 without any article massaging functions being run.  Normally, the key
9334 strokes are `C-u g'."
9335   (interactive "P")
9336   (cond
9337    ((numberp arg)
9338     (gnus-summary-show-article t)
9339     (let ((gnus-newsgroup-charset
9340            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9341                (mm-read-coding-system
9342                 "View as charset: " ;; actually it is coding system.
9343                 (with-current-buffer gnus-article-buffer
9344                   (mm-detect-coding-region (point) (point-max))))))
9345           (gnus-newsgroup-ignored-charsets 'gnus-all))
9346       (gnus-summary-select-article nil 'force)
9347       (let ((deps gnus-newsgroup-dependencies)
9348             head header lines)
9349         (save-excursion
9350           (set-buffer gnus-original-article-buffer)
9351           (save-restriction
9352             (message-narrow-to-head)
9353             (setq head (buffer-string))
9354             (goto-char (point-min))
9355             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9356               (goto-char (point-max))
9357               (widen)
9358               (setq lines (1- (count-lines (point) (point-max))))))
9359           (with-temp-buffer
9360             (insert (format "211 %d Article retrieved.\n"
9361                             (cdr gnus-article-current)))
9362             (insert head)
9363             (if lines (insert (format "Lines: %d\n" lines)))
9364             (insert ".\n")
9365             (let ((nntp-server-buffer (current-buffer)))
9366               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9367         (gnus-data-set-header
9368          (gnus-data-find (cdr gnus-article-current))
9369          header)
9370         (gnus-summary-update-article-line
9371          (cdr gnus-article-current) header)
9372         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9373           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9374    ((not arg)
9375     ;; Select the article the normal way.
9376     (gnus-summary-select-article nil 'force))
9377    (t
9378     ;; We have to require this here to make sure that the following
9379     ;; dynamic binding isn't shadowed by autoloading.
9380     (require 'gnus-async)
9381     (require 'gnus-art)
9382     ;; Bind the article treatment functions to nil.
9383     (let ((gnus-have-all-headers t)
9384           gnus-article-prepare-hook
9385           gnus-article-decode-hook
9386           gnus-display-mime-function
9387           gnus-break-pages)
9388       ;; Destroy any MIME parts.
9389       (when (gnus-buffer-live-p gnus-article-buffer)
9390         (save-excursion
9391           (set-buffer gnus-article-buffer)
9392           (mm-destroy-parts gnus-article-mime-handles)
9393           ;; Set it to nil for safety reason.
9394           (setq gnus-article-mime-handle-alist nil)
9395           (setq gnus-article-mime-handles nil)))
9396       (gnus-summary-select-article nil 'force))))
9397   (gnus-summary-goto-subject gnus-current-article)
9398   (gnus-summary-position-point))
9399
9400 (defun gnus-summary-show-raw-article ()
9401   "Show the raw article without any article massaging functions being run."
9402   (interactive)
9403   (gnus-summary-show-article t))
9404
9405 (defun gnus-summary-verbose-headers (&optional arg)
9406   "Toggle permanent full header display.
9407 If ARG is a positive number, turn header display on.
9408 If ARG is a negative number, turn header display off."
9409   (interactive "P")
9410   (setq gnus-show-all-headers
9411         (cond ((or (not (numberp arg))
9412                    (zerop arg))
9413                (not gnus-show-all-headers))
9414               ((natnump arg)
9415                t)))
9416   (gnus-summary-show-article))
9417
9418 (defun gnus-summary-toggle-header (&optional arg)
9419   "Show the headers if they are hidden, or hide them if they are shown.
9420 If ARG is a positive number, show the entire header.
9421 If ARG is a negative number, hide the unwanted header lines."
9422   (interactive "P")
9423   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9424                      (get-buffer-window gnus-article-buffer t))))
9425     (with-current-buffer gnus-article-buffer
9426       (widen)
9427       (article-narrow-to-head)
9428       (let* ((buffer-read-only nil)
9429              (inhibit-point-motion-hooks t)
9430              (hidden (if (numberp arg)
9431                          (>= arg 0)
9432                        (or (not (looking-at "[^ \t\n]+:"))
9433                            (gnus-article-hidden-text-p 'headers))))
9434              s e)
9435         (delete-region (point-min) (point-max))
9436         (with-current-buffer gnus-original-article-buffer
9437           (goto-char (setq s (point-min)))
9438           (setq e (if (search-forward "\n\n" nil t)
9439                       (1- (point))
9440                     (point-max))))
9441         (insert-buffer-substring gnus-original-article-buffer s e)
9442         (run-hooks 'gnus-article-decode-hook)
9443         (if hidden
9444             (let ((gnus-treat-hide-headers nil)
9445                   (gnus-treat-hide-boring-headers nil))
9446               (gnus-delete-wash-type 'headers)
9447               (gnus-treat-article 'head))
9448           (gnus-treat-article 'head))
9449         (widen)
9450         (if window
9451             (set-window-start window (goto-char (point-min))))
9452         (if gnus-break-pages
9453             (gnus-narrow-to-page)
9454           (when (gnus-visual-p 'page-marker)
9455             (let ((buffer-read-only nil))
9456               (gnus-remove-text-with-property 'gnus-prev)
9457               (gnus-remove-text-with-property 'gnus-next))))
9458         (gnus-set-mode-line 'article)))))
9459
9460 (defun gnus-summary-show-all-headers ()
9461   "Make all header lines visible."
9462   (interactive)
9463   (gnus-summary-toggle-header 1))
9464
9465 (defun gnus-summary-caesar-message (&optional arg)
9466   "Caesar rotate the current article by 13.
9467 With a non-numerical prefix, also rotate headers.  A numerical
9468 prefix specifies how many places to rotate each letter forward."
9469   (interactive "P")
9470   (gnus-summary-select-article)
9471   (let ((mail-header-separator ""))
9472     (gnus-eval-in-buffer-window gnus-article-buffer
9473       (save-restriction
9474         (widen)
9475         (let ((start (window-start))
9476               buffer-read-only)
9477           (if (equal arg '(4))
9478               (message-caesar-buffer-body nil t)
9479             (message-caesar-buffer-body arg))
9480           (set-window-start (get-buffer-window (current-buffer)) start)))))
9481   ;; Create buttons and stuff...
9482   (gnus-treat-article nil))
9483
9484 (declare-function idna-to-unicode "ext:idna" (str))
9485
9486 (defun gnus-summary-idna-message (&optional arg)
9487   "Decode IDNA encoded domain names in the current articles.
9488 IDNA encoded domain names looks like `xn--bar'.  If a string
9489 remain unencoded after running this function, it is likely an
9490 invalid IDNA string (`xn--bar' is invalid).
9491
9492 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9493 installed for this command to work."
9494   (interactive "P")
9495   (if (not (and (condition-case nil (require 'idna)
9496                   (file-error))
9497                 (mm-coding-system-p 'utf-8)
9498                 (executable-find (symbol-value 'idna-program))))
9499       (gnus-message
9500        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9501     (gnus-summary-select-article)
9502     (let ((mail-header-separator ""))
9503       (gnus-eval-in-buffer-window gnus-article-buffer
9504         (save-restriction
9505           (widen)
9506           (let ((start (window-start))
9507                 buffer-read-only)
9508             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9509               (replace-match (idna-to-unicode (match-string 1))))
9510             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9511
9512 (defun gnus-summary-morse-message (&optional arg)
9513   "Morse decode the current article."
9514   (interactive "P")
9515   (gnus-summary-select-article)
9516   (let ((mail-header-separator ""))
9517     (gnus-eval-in-buffer-window gnus-article-buffer
9518       (save-excursion
9519         (save-restriction
9520           (widen)
9521           (let ((pos (window-start))
9522                 buffer-read-only)
9523             (goto-char (point-min))
9524             (when (message-goto-body)
9525               (gnus-narrow-to-body))
9526             (goto-char (point-min))
9527             (while (search-forward "·" (point-max) t)
9528               (replace-match "."))
9529             (unmorse-region (point-min) (point-max))
9530             (widen)
9531             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9532
9533 (defun gnus-summary-stop-page-breaking ()
9534   "Stop page breaking in the current article."
9535   (interactive)
9536   (gnus-summary-select-article)
9537   (gnus-eval-in-buffer-window gnus-article-buffer
9538     (widen)
9539     (when (gnus-visual-p 'page-marker)
9540       (let ((buffer-read-only nil))
9541         (gnus-remove-text-with-property 'gnus-prev)
9542         (gnus-remove-text-with-property 'gnus-next))
9543       (setq gnus-page-broken nil))))
9544
9545 (defun gnus-summary-move-article (&optional n to-newsgroup
9546                                             select-method action)
9547   "Move the current article to a different newsgroup.
9548 If N is a positive number, move the N next articles.
9549 If N is a negative number, move the N previous articles.
9550 If N is nil and any articles have been marked with the process mark,
9551 move those articles instead.
9552 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9553 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9554 re-spool using this method.
9555
9556 When called interactively with TO-NEWSGROUP being nil, the value of
9557 the variable `gnus-move-split-methods' is used for finding a default
9558 for the target newsgroup.
9559
9560 For this function to work, both the current newsgroup and the
9561 newsgroup that you want to move to have to support the `request-move'
9562 and `request-accept' functions.
9563
9564 ACTION can be either `move' (the default), `crosspost' or `copy'."
9565   (interactive "P")
9566   (unless action
9567     (setq action 'move))
9568   ;; Check whether the source group supports the required functions.
9569   (cond ((and (eq action 'move)
9570               (not (gnus-check-backend-function
9571                     'request-move-article gnus-newsgroup-name)))
9572          (error "The current group does not support article moving"))
9573         ((and (eq action 'crosspost)
9574               (not (gnus-check-backend-function
9575                     'request-replace-article gnus-newsgroup-name)))
9576          (error "The current group does not support article editing")))
9577   (let ((articles (gnus-summary-work-articles n))
9578         (prefix (if (gnus-check-backend-function
9579                      'request-move-article gnus-newsgroup-name)
9580                     (funcall gnus-move-group-prefix-function
9581                              gnus-newsgroup-name)
9582                   ""))
9583         (names '((move "Move" "Moving")
9584                  (copy "Copy" "Copying")
9585                  (crosspost "Crosspost" "Crossposting")))
9586         (copy-buf (save-excursion
9587                     (nnheader-set-temp-buffer " *copy article*")))
9588         art-group to-method new-xref article to-groups
9589         articles-to-update-marks encoded)
9590     (unless (assq action names)
9591       (error "Unknown action %s" action))
9592     ;; Read the newsgroup name.
9593     (when (and (not to-newsgroup)
9594                (not select-method))
9595       (if (and gnus-move-split-methods
9596                (not
9597                 (and (memq gnus-current-article articles)
9598                      (gnus-buffer-live-p gnus-original-article-buffer))))
9599           ;; When `gnus-move-split-methods' is non-nil, we have to
9600           ;; select an article to give `gnus-read-move-group-name' an
9601           ;; opportunity to suggest an appropriate default.  However,
9602           ;; we needn't render or mark the article.
9603           (let ((gnus-display-mime-function nil)
9604                 (gnus-article-prepare-hook nil)
9605                 (gnus-mark-article-hook nil))
9606             (gnus-summary-select-article nil nil nil (car articles))))
9607       (setq to-newsgroup (gnus-read-move-group-name
9608                           (cadr (assq action names))
9609                           (symbol-value
9610                            (intern (format "gnus-current-%s-group" action)))
9611                           articles prefix)
9612             encoded to-newsgroup
9613             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9614       (set (intern (format "gnus-current-%s-group" action))
9615            (mm-decode-coding-string
9616             to-newsgroup
9617             (gnus-group-name-charset to-method to-newsgroup))))
9618     (unless to-method
9619       (setq to-method (or select-method
9620                           (gnus-server-to-method
9621                            (gnus-group-method to-newsgroup)))))
9622     (setq to-newsgroup
9623           (or encoded
9624               (and to-newsgroup
9625                    (mm-encode-coding-string
9626                     to-newsgroup
9627                     (gnus-group-name-charset to-method to-newsgroup)))))
9628     ;; Check the method we are to move this article to...
9629     (unless (gnus-check-backend-function
9630              'request-accept-article (car to-method))
9631       (error "%s does not support article copying" (car to-method)))
9632     (unless (gnus-check-server to-method)
9633       (error "Can't open server %s" (car to-method)))
9634     (gnus-message 6 "%s to %s: %s..."
9635                   (caddr (assq action names))
9636                   (or (car select-method)
9637                       (gnus-group-decoded-name to-newsgroup))
9638                   articles)
9639     (while articles
9640       (setq article (pop articles))
9641       (setq
9642        art-group
9643        (cond
9644         ;; Move the article.
9645         ((eq action 'move)
9646          ;; Remove this article from future suppression.
9647          (gnus-dup-unsuppress-article article)
9648          (let* ((from-method (gnus-find-method-for-group
9649                               gnus-newsgroup-name))
9650                 (to-method (or select-method
9651                                (gnus-find-method-for-group to-newsgroup)))
9652                 (move-is-internal (gnus-method-equal from-method to-method)))
9653            (gnus-request-move-article
9654             article                     ; Article to move
9655             gnus-newsgroup-name         ; From newsgroup
9656             (nth 1 (gnus-find-method-for-group
9657                     gnus-newsgroup-name)) ; Server
9658             (list 'gnus-request-accept-article
9659                   to-newsgroup (list 'quote select-method)
9660                   (not articles) t)     ; Accept form
9661             (not articles)              ; Only save nov last time
9662             move-is-internal)))         ; is this move internal?
9663         ;; Copy the article.
9664         ((eq action 'copy)
9665          (save-excursion
9666            (set-buffer copy-buf)
9667            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9668              (save-restriction
9669                (nnheader-narrow-to-headers)
9670                (dolist (hdr gnus-copy-article-ignored-headers)
9671                  (message-remove-header hdr t)))
9672              (gnus-request-accept-article
9673               to-newsgroup select-method (not articles) t))))
9674         ;; Crosspost the article.
9675         ((eq action 'crosspost)
9676          (let ((xref (message-tokenize-header
9677                       (mail-header-xref (gnus-summary-article-header article))
9678                       " ")))
9679            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9680                                   ":" (number-to-string article)))
9681            (unless xref
9682              (setq xref (list (system-name))))
9683            (setq new-xref
9684                  (concat
9685                   (mapconcat 'identity
9686                              (delete "Xref:" (delete new-xref xref))
9687                              " ")
9688                   " " new-xref))
9689            (save-excursion
9690              (set-buffer copy-buf)
9691              ;; First put the article in the destination group.
9692              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9693              (when (consp (setq art-group
9694                                 (gnus-request-accept-article
9695                                  to-newsgroup select-method (not articles) t)))
9696                (setq new-xref (concat new-xref " " (car art-group)
9697                                       ":"
9698                                       (number-to-string (cdr art-group))))
9699                ;; Now we have the new Xrefs header, so we insert
9700                ;; it and replace the new article.
9701                (nnheader-replace-header "Xref" new-xref)
9702                (gnus-request-replace-article
9703                 (cdr art-group) to-newsgroup (current-buffer) t)
9704                art-group))))))
9705       (cond
9706        ((not art-group)
9707         (gnus-message 1 "Couldn't %s article %s: %s"
9708                       (cadr (assq action names)) article
9709                       (nnheader-get-report (car to-method))))
9710        ((eq art-group 'junk)
9711         (when (eq action 'move)
9712           (gnus-summary-mark-article article gnus-canceled-mark)
9713           (gnus-message 4 "Deleted article %s" article)
9714           ;; run the delete hook
9715           (run-hook-with-args 'gnus-summary-article-delete-hook
9716                               action
9717                               (gnus-data-header
9718                                (assoc article (gnus-data-list nil)))
9719                               gnus-newsgroup-name nil
9720                               select-method)))
9721        (t
9722         (let* ((pto-group (gnus-group-prefixed-name
9723                            (car art-group) to-method))
9724                (info (gnus-get-info pto-group))
9725                (to-group (gnus-info-group info))
9726                to-marks)
9727           ;; Update the group that has been moved to.
9728           (when (and info
9729                      (memq action '(move copy)))
9730             (unless (member to-group to-groups)
9731               (push to-group to-groups))
9732
9733             (unless (memq article gnus-newsgroup-unreads)
9734               (push 'read to-marks)
9735               (gnus-info-set-read
9736                info (gnus-add-to-range (gnus-info-read info)
9737                                        (list (cdr art-group)))))
9738
9739             ;; See whether the article is to be put in the cache.
9740             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9741                              gnus-article-mark-lists
9742                            (delete '(expirable . expire)
9743                                    (copy-sequence gnus-article-mark-lists))))
9744                   (to-article (cdr art-group)))
9745
9746               ;; Enter the article into the cache in the new group,
9747               ;; if that is required.
9748               (when gnus-use-cache
9749                 (gnus-cache-possibly-enter-article
9750                  to-group to-article
9751                  (memq article gnus-newsgroup-marked)
9752                  (memq article gnus-newsgroup-dormant)
9753                  (memq article gnus-newsgroup-unreads)))
9754
9755               (when gnus-preserve-marks
9756                 ;; Copy any marks over to the new group.
9757                 (when (and (equal to-group gnus-newsgroup-name)
9758                            (not (memq article gnus-newsgroup-unreads)))
9759                   ;; Mark this article as read in this group.
9760                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9761                   (setcdr (gnus-active to-group) to-article)
9762                   (setcdr gnus-newsgroup-active to-article))
9763
9764                 (while marks
9765                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9766                     (when (memq article (symbol-value
9767                                          (intern (format "gnus-newsgroup-%s"
9768                                                          (caar marks)))))
9769                       (push (cdar marks) to-marks)
9770                       ;; If the other group is the same as this group,
9771                       ;; then we have to add the mark to the list.
9772                       (when (equal to-group gnus-newsgroup-name)
9773                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9774                              (cons to-article
9775                                    (symbol-value
9776                                     (intern (format "gnus-newsgroup-%s"
9777                                                     (caar marks)))))))
9778                       ;; Copy the marks to other group.
9779                       (gnus-add-marked-articles
9780                        to-group (cdar marks) (list to-article) info)))
9781                   (setq marks (cdr marks)))
9782
9783                 (gnus-request-set-mark
9784                  to-group (list (list (list to-article) 'add to-marks))))
9785
9786               (gnus-dribble-enter
9787                (concat "(gnus-group-set-info '"
9788                        (gnus-prin1-to-string (gnus-get-info to-group))
9789                        ")"))))
9790
9791           ;; Update the Xref header in this article to point to
9792           ;; the new crossposted article we have just created.
9793           (when (eq action 'crosspost)
9794             (save-excursion
9795               (set-buffer copy-buf)
9796               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9797               (nnheader-replace-header "Xref" new-xref)
9798               (gnus-request-replace-article
9799                article gnus-newsgroup-name (current-buffer) t)))
9800
9801           ;; run the move/copy/crosspost/respool hook
9802           (run-hook-with-args 'gnus-summary-article-move-hook
9803                               action
9804                               (gnus-data-header
9805                                (assoc article (gnus-data-list nil)))
9806                               gnus-newsgroup-name
9807                               to-newsgroup
9808                               select-method))
9809
9810         ;;;!!!Why is this necessary?
9811         (set-buffer gnus-summary-buffer)
9812
9813         (gnus-summary-goto-subject article)
9814         (when (eq action 'move)
9815           (gnus-summary-mark-article article gnus-canceled-mark))))
9816       (push article articles-to-update-marks))
9817
9818     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9819     ;; Re-activate all groups that have been moved to.
9820     (save-excursion
9821       (set-buffer gnus-group-buffer)
9822       (let ((gnus-group-marked to-groups))
9823         (gnus-group-get-new-news-this-group nil t)))
9824
9825     (gnus-kill-buffer copy-buf)
9826     (gnus-summary-position-point)
9827     (gnus-set-mode-line 'summary)))
9828
9829 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9830   "Copy the current article to some other group.
9831 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9832 When called interactively, if TO-NEWSGROUP is nil, use the value of
9833 the variable `gnus-move-split-methods' for finding a default target
9834 newsgroup.
9835 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9836 re-spool using this method."
9837   (interactive "P")
9838   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9839
9840 (defun gnus-summary-crosspost-article (&optional n)
9841   "Crosspost the current article to some other group."
9842   (interactive "P")
9843   (gnus-summary-move-article n nil nil 'crosspost))
9844
9845 (defcustom gnus-summary-respool-default-method nil
9846   "Default method type for respooling an article.
9847 If nil, use to the current newsgroup method."
9848   :type 'symbol
9849   :group 'gnus-summary-mail)
9850
9851 (defcustom gnus-summary-display-while-building nil
9852   "If non-nil, show and update the summary buffer as it's being built.
9853 If the value is t, update the buffer after every line is inserted.  If
9854 the value is an integer (N), update the display every N lines."
9855   :version "22.1"
9856   :group 'gnus-thread
9857   :type '(choice (const :tag "off" nil)
9858                  number
9859                  (const :tag "frequently" t)))
9860
9861 (defun gnus-summary-respool-article (&optional n method)
9862   "Respool the current article.
9863 The article will be squeezed through the mail spooling process again,
9864 which means that it will be put in some mail newsgroup or other
9865 depending on `nnmail-split-methods'.
9866 If N is a positive number, respool the N next articles.
9867 If N is a negative number, respool the N previous articles.
9868 If N is nil and any articles have been marked with the process mark,
9869 respool those articles instead.
9870
9871 Respooling can be done both from mail groups and \"real\" newsgroups.
9872 In the former case, the articles in question will be moved from the
9873 current group into whatever groups they are destined to.  In the
9874 latter case, they will be copied into the relevant groups."
9875   (interactive
9876    (list current-prefix-arg
9877          (let* ((methods (gnus-methods-using 'respool))
9878                 (methname
9879                  (symbol-name (or gnus-summary-respool-default-method
9880                                   (car (gnus-find-method-for-group
9881                                         gnus-newsgroup-name)))))
9882                 (method
9883                  (gnus-completing-read-with-default
9884                   methname "Backend to use when respooling"
9885                   methods nil t nil 'gnus-mail-method-history))
9886                 ms)
9887            (cond
9888             ((zerop (length (setq ms (gnus-servers-using-backend
9889                                       (intern method)))))
9890              (list (intern method) ""))
9891             ((= 1 (length ms))
9892              (car ms))
9893             (t
9894              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9895                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9896                            ms-alist))))))))
9897   (unless method
9898     (error "No method given for respooling"))
9899   (if (assoc (symbol-name
9900               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9901              (gnus-methods-using 'respool))
9902       (gnus-summary-move-article n nil method)
9903     (gnus-summary-copy-article n nil method)))
9904
9905 (defun gnus-summary-import-article (file &optional edit)
9906   "Import an arbitrary file into a mail newsgroup."
9907   (interactive "fImport file: \nP")
9908   (let ((group gnus-newsgroup-name)
9909         (now (current-time))
9910         atts lines group-art)
9911     (unless (gnus-check-backend-function 'request-accept-article group)
9912       (error "%s does not support article importing" group))
9913     (or (file-readable-p file)
9914         (not (file-regular-p file))
9915         (error "Can't read %s" file))
9916     (save-excursion
9917       (set-buffer (gnus-get-buffer-create " *import file*"))
9918       (erase-buffer)
9919       (nnheader-insert-file-contents file)
9920       (goto-char (point-min))
9921       (if (nnheader-article-p)
9922           (save-restriction
9923             (goto-char (point-min))
9924             (search-forward "\n\n" nil t)
9925             (narrow-to-region (point-min) (1- (point)))
9926             (goto-char (point-min))
9927             (unless (re-search-forward "^date:" nil t)
9928               (goto-char (point-max))
9929               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9930        ;; This doesn't look like an article, so we fudge some headers.
9931         (setq atts (file-attributes file)
9932               lines (count-lines (point-min) (point-max)))
9933         (insert "From: " (read-string "From: ") "\n"
9934                 "Subject: " (read-string "Subject: ") "\n"
9935                 "Date: " (message-make-date (nth 5 atts)) "\n"
9936                 "Message-ID: " (message-make-message-id) "\n"
9937                 "Lines: " (int-to-string lines) "\n"
9938                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9939       (setq group-art (gnus-request-accept-article group nil t))
9940       (kill-buffer (current-buffer)))
9941     (setq gnus-newsgroup-active (gnus-activate-group group))
9942     (forward-line 1)
9943     (gnus-summary-goto-article (cdr group-art) nil t)
9944     (when edit
9945       (gnus-summary-edit-article))))
9946
9947 (defun gnus-summary-create-article ()
9948   "Create an article in a mail newsgroup."
9949   (interactive)
9950   (let ((group gnus-newsgroup-name)
9951         (now (current-time))
9952         group-art)
9953     (unless (gnus-check-backend-function 'request-accept-article group)
9954       (error "%s does not support article importing" group))
9955     (save-excursion
9956       (set-buffer (gnus-get-buffer-create " *import file*"))
9957       (erase-buffer)
9958       (goto-char (point-min))
9959       ;; This doesn't look like an article, so we fudge some headers.
9960       (insert "From: " (read-string "From: ") "\n"
9961               "Subject: " (read-string "Subject: ") "\n"
9962               "Date: " (message-make-date now) "\n"
9963               "Message-ID: " (message-make-message-id) "\n")
9964       (setq group-art (gnus-request-accept-article group nil t))
9965       (kill-buffer (current-buffer)))
9966     (setq gnus-newsgroup-active (gnus-activate-group group))
9967     (forward-line 1)
9968     (gnus-summary-goto-article (cdr group-art) nil t)
9969     (gnus-summary-edit-article)))
9970
9971 (defun gnus-summary-article-posted-p ()
9972   "Say whether the current (mail) article is available from news as well.
9973 This will be the case if the article has both been mailed and posted."
9974   (interactive)
9975   (let ((id (mail-header-references (gnus-summary-article-header)))
9976         (gnus-override-method (car (gnus-refer-article-methods))))
9977     (if (gnus-request-head id "")
9978         (gnus-message 2 "The current message was found on %s"
9979                       gnus-override-method)
9980       (gnus-message 2 "The current message couldn't be found on %s"
9981                     gnus-override-method)
9982       nil)))
9983
9984 (defun gnus-summary-expire-articles (&optional now)
9985   "Expire all articles that are marked as expirable in the current group."
9986   (interactive)
9987   (when (and (not gnus-group-is-exiting-without-update-p)
9988              (gnus-check-backend-function
9989               'request-expire-articles gnus-newsgroup-name))
9990     ;; This backend supports expiry.
9991     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9992            (expirable (if total
9993                           (progn
9994                             ;; We need to update the info for
9995                             ;; this group for `gnus-list-of-read-articles'
9996                             ;; to give us the right answer.
9997                             (gnus-run-hooks 'gnus-exit-group-hook)
9998                             (gnus-summary-update-info)
9999                             (gnus-list-of-read-articles gnus-newsgroup-name))
10000                         (setq gnus-newsgroup-expirable
10001                               (sort gnus-newsgroup-expirable '<))))
10002            (expiry-wait (if now 'immediate
10003                           (gnus-group-find-parameter
10004                            gnus-newsgroup-name 'expiry-wait)))
10005            (nnmail-expiry-target
10006             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
10007                 nnmail-expiry-target))
10008            es)
10009       (when expirable
10010         ;; There are expirable articles in this group, so we run them
10011         ;; through the expiry process.
10012         (gnus-message 6 "Expiring articles...")
10013         (unless (gnus-check-group gnus-newsgroup-name)
10014           (error "Can't open server for %s" gnus-newsgroup-name))
10015         ;; The list of articles that weren't expired is returned.
10016         (save-excursion
10017           (if expiry-wait
10018               (let ((nnmail-expiry-wait-function nil)
10019                     (nnmail-expiry-wait expiry-wait))
10020                 (setq es (gnus-request-expire-articles
10021                           expirable gnus-newsgroup-name)))
10022             (setq es (gnus-request-expire-articles
10023                       expirable gnus-newsgroup-name)))
10024           (unless total
10025             (setq gnus-newsgroup-expirable es))
10026           ;; We go through the old list of expirable, and mark all
10027           ;; really expired articles as nonexistent.
10028           (unless (eq es expirable) ;If nothing was expired, we don't mark.
10029             (let ((gnus-use-cache nil))
10030               (dolist (article expirable)
10031                 (when (and (not (memq article es))
10032                            (gnus-data-find article))
10033                   (gnus-summary-mark-article article gnus-canceled-mark)
10034                   (run-hook-with-args 'gnus-summary-article-expire-hook
10035                                       'delete
10036                                       (gnus-data-header
10037                                        (assoc article (gnus-data-list nil)))
10038                                       gnus-newsgroup-name
10039                                       nil
10040                                       nil))))))
10041         (gnus-message 6 "Expiring articles...done")))))
10042
10043 (defun gnus-summary-expire-articles-now ()
10044   "Expunge all expirable articles in the current group.
10045 This means that *all* articles that are marked as expirable will be
10046 deleted forever, right now."
10047   (interactive)
10048   (or gnus-expert-user
10049       (gnus-yes-or-no-p
10050        "Are you really, really sure you want to delete all expirable messages? ")
10051       (error "Phew!"))
10052   (gnus-summary-expire-articles t))
10053
10054 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10055 (defun gnus-summary-delete-article (&optional n)
10056   "Delete the N next (mail) articles.
10057 This command actually deletes articles.  This is not a marking
10058 command.  The article will disappear forever from your life, never to
10059 return.
10060
10061 If N is negative, delete backwards.
10062 If N is nil and articles have been marked with the process mark,
10063 delete these instead.
10064
10065 If `gnus-novice-user' is non-nil you will be asked for
10066 confirmation before the articles are deleted."
10067   (interactive "P")
10068   (unless (gnus-check-backend-function 'request-expire-articles
10069                                        gnus-newsgroup-name)
10070     (error "The current newsgroup does not support article deletion"))
10071   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10072     (error "Couldn't open server"))
10073   ;; Compute the list of articles to delete.
10074   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10075         (nnmail-expiry-target 'delete)
10076         not-deleted)
10077     (if (and gnus-novice-user
10078              (not (gnus-yes-or-no-p
10079                    (format "Do you really want to delete %s forever? "
10080                            (if (> (length articles) 1)
10081                                (format "these %s articles" (length articles))
10082                              "this article")))))
10083         ()
10084       ;; Delete the articles.
10085       (setq not-deleted (gnus-request-expire-articles
10086                          articles gnus-newsgroup-name 'force))
10087       (while articles
10088         (gnus-summary-remove-process-mark (car articles))
10089         ;; The backend might not have been able to delete the article
10090         ;; after all.
10091         (unless (memq (car articles) not-deleted)
10092           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10093         (let* ((article (car articles))
10094                (ghead  (gnus-data-header
10095                                     (assoc article (gnus-data-list nil)))))
10096           (run-hook-with-args 'gnus-summary-article-delete-hook
10097                               'delete ghead gnus-newsgroup-name nil
10098                               nil))
10099         (setq articles (cdr articles)))
10100       (when not-deleted
10101         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10102     (gnus-summary-position-point)
10103     (gnus-set-mode-line 'summary)
10104     not-deleted))
10105
10106 (defun gnus-summary-edit-article (&optional arg)
10107   "Edit the current article.
10108 This will have permanent effect only in mail groups.
10109 If ARG is nil, edit the decoded articles.
10110 If ARG is 1, edit the raw articles.
10111 If ARG is 2, edit the raw articles even in read-only groups.
10112 If ARG is 3, edit the articles with the current handles.
10113 Otherwise, allow editing of articles even in read-only
10114 groups."
10115   (interactive "P")
10116   (let (force raw current-handles)
10117     (cond
10118      ((null arg))
10119      ((eq arg 1)
10120       (setq raw t))
10121      ((eq arg 2)
10122       (setq raw t
10123             force t))
10124      ((eq arg 3)
10125       (setq current-handles
10126             (and (gnus-buffer-live-p gnus-article-buffer)
10127                  (with-current-buffer gnus-article-buffer
10128                    (prog1
10129                        gnus-article-mime-handles
10130                      (setq gnus-article-mime-handles nil))))))
10131      (t
10132       (setq force t)))
10133     (when (and raw (not force)
10134                (member gnus-newsgroup-name '("nndraft:delayed"
10135                                              "nndraft:drafts"
10136                                              "nndraft:queue")))
10137       (error "Can't edit the raw article in group %s"
10138              gnus-newsgroup-name))
10139     (save-excursion
10140       (set-buffer gnus-summary-buffer)
10141       (let ((mail-parse-charset gnus-newsgroup-charset)
10142             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10143         (gnus-set-global-variables)
10144         (when (and (not force)
10145                    (gnus-group-read-only-p))
10146           (error "The current newsgroup does not support article editing"))
10147         (gnus-summary-show-article t)
10148         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10149           (with-current-buffer gnus-article-buffer
10150             (mm-enable-multibyte)))
10151         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10152             (setq raw t))
10153         (gnus-article-edit-article
10154          (if raw 'ignore
10155            `(lambda ()
10156               (let ((mbl mml-buffer-list))
10157                 (setq mml-buffer-list nil)
10158                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10159                   (mime-to-mml ,'current-handles))
10160                 (let ((mbl1 mml-buffer-list))
10161                   (setq mml-buffer-list mbl)
10162                   (set (make-local-variable 'mml-buffer-list) mbl1))
10163                 (gnus-make-local-hook 'kill-buffer-hook)
10164                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10165          `(lambda (no-highlight)
10166             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10167                   (message-options message-options)
10168                   (message-options-set-recipient)
10169                   (mail-parse-ignored-charsets
10170                    ',gnus-newsgroup-ignored-charsets)
10171                   (rfc2047-header-encoding-alist
10172                    ',(let ((charset (gnus-group-name-charset
10173                                      (gnus-find-method-for-group
10174                                       gnus-newsgroup-name)
10175                                      gnus-newsgroup-name)))
10176                        (append (list (cons "Newsgroups" charset)
10177                                      (cons "Followup-To" charset)
10178                                      (cons "Xref" charset))
10179                                rfc2047-header-encoding-alist))))
10180               ,(if (not raw) '(progn
10181                                 (mml-to-mime)
10182                                 (mml-destroy-buffers)
10183                                 (remove-hook 'kill-buffer-hook
10184                                              'mml-destroy-buffers t)
10185                                 (kill-local-variable 'mml-buffer-list)))
10186               (gnus-summary-edit-article-done
10187                ,(or (mail-header-references gnus-current-headers) "")
10188                ,(gnus-group-read-only-p)
10189                ,gnus-summary-buffer no-highlight))))))))
10190
10191 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10192
10193 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10194                                                  no-highlight)
10195   "Make edits to the current article permanent."
10196   (interactive)
10197   (save-excursion
10198    ;; The buffer restriction contains the entire article if it exists.
10199     (when (article-goto-body)
10200       (let ((lines (count-lines (point) (point-max)))
10201             (length (- (point-max) (point)))
10202             (case-fold-search t)
10203             (body (copy-marker (point))))
10204         (goto-char (point-min))
10205         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10206           (delete-region (match-beginning 1) (match-end 1))
10207           (insert (number-to-string length)))
10208         (goto-char (point-min))
10209         (when (re-search-forward
10210                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10211           (delete-region (match-beginning 1) (match-end 1))
10212           (insert (number-to-string length)))
10213         (goto-char (point-min))
10214         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10215           (delete-region (match-beginning 1) (match-end 1))
10216           (insert (number-to-string lines))))))
10217   ;; Replace the article.
10218   (let ((buf (current-buffer)))
10219     (with-temp-buffer
10220       (insert-buffer-substring buf)
10221
10222       (if (and (not read-only)
10223                (not (gnus-request-replace-article
10224                      (cdr gnus-article-current) (car gnus-article-current)
10225                      (current-buffer) t)))
10226           (error "Couldn't replace article")
10227         ;; Update the summary buffer.
10228         (if (and references
10229                  (equal (message-tokenize-header references " ")
10230                         (message-tokenize-header
10231                          (or (message-fetch-field "references") "") " ")))
10232             ;; We only have to update this line.
10233             (save-excursion
10234               (save-restriction
10235                 (message-narrow-to-head)
10236                 (let ((head (buffer-substring-no-properties
10237                              (point-min) (point-max)))
10238                       header)
10239                   (with-temp-buffer
10240                     (insert (format "211 %d Article retrieved.\n"
10241                                     (cdr gnus-article-current)))
10242                     (insert head)
10243                     (insert ".\n")
10244                     (let ((nntp-server-buffer (current-buffer)))
10245                       (setq header (car (gnus-get-newsgroup-headers
10246                                          nil t))))
10247                     (save-excursion
10248                       (set-buffer gnus-summary-buffer)
10249                       (gnus-data-set-header
10250                        (gnus-data-find (cdr gnus-article-current))
10251                        header)
10252                       (gnus-summary-update-article-line
10253                        (cdr gnus-article-current) header)
10254                       (if (gnus-summary-goto-subject
10255                            (cdr gnus-article-current) nil t)
10256                           (gnus-summary-update-secondary-mark
10257                            (cdr gnus-article-current))))))))
10258           ;; Update threads.
10259           (set-buffer (or buffer gnus-summary-buffer))
10260           (gnus-summary-update-article (cdr gnus-article-current))
10261           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10262               (gnus-summary-update-secondary-mark
10263                (cdr gnus-article-current))))
10264         ;; Prettify the article buffer again.
10265         (unless no-highlight
10266           (save-excursion
10267             (set-buffer gnus-article-buffer)
10268             ;;;!!! Fix this -- article should be rehighlighted.
10269             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10270             (set-buffer gnus-original-article-buffer)
10271             (gnus-request-article
10272              (cdr gnus-article-current)
10273              (car gnus-article-current) (current-buffer))))
10274         ;; Prettify the summary buffer line.
10275         (when (gnus-visual-p 'summary-highlight 'highlight)
10276           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10277
10278 (defun gnus-summary-edit-wash (key)
10279   "Perform editing command KEY in the article buffer."
10280   (interactive
10281    (list
10282     (progn
10283       (message "%s" (concat (this-command-keys) "- "))
10284       (read-char))))
10285   (message "")
10286   (gnus-summary-edit-article)
10287   (execute-kbd-macro (concat (this-command-keys) key))
10288   (gnus-article-edit-done))
10289
10290 ;;; Respooling
10291
10292 (defun gnus-summary-respool-query (&optional silent trace)
10293   "Query where the respool algorithm would put this article."
10294   (interactive)
10295   (let (gnus-mark-article-hook)
10296     (gnus-summary-select-article)
10297     (save-excursion
10298       (set-buffer gnus-original-article-buffer)
10299       (let ((groups (nnmail-article-group 'identity trace)))
10300         (unless silent
10301           (if groups
10302               (message "This message would go to %s"
10303                        (mapconcat 'car groups ", "))
10304             (message "This message would go to no groups"))
10305           groups)))))
10306
10307 (defun gnus-summary-respool-trace ()
10308   "Trace where the respool algorithm would put this article.
10309 Display a buffer showing all fancy splitting patterns which matched."
10310   (interactive)
10311   (gnus-summary-respool-query nil t))
10312
10313 ;; Summary marking commands.
10314
10315 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10316   "Mark articles which has the same subject as read, and then select the next.
10317 If UNMARK is positive, remove any kind of mark.
10318 If UNMARK is negative, tick articles."
10319   (interactive "P")
10320   (when unmark
10321     (setq unmark (prefix-numeric-value unmark)))
10322   (let ((count
10323          (gnus-summary-mark-same-subject
10324           (gnus-summary-article-subject) unmark)))
10325     ;; Select next unread article.  If auto-select-same mode, should
10326     ;; select the first unread article.
10327     (gnus-summary-next-article t (and gnus-auto-select-same
10328                                       (gnus-summary-article-subject)))
10329     (gnus-message 7 "%d article%s marked as %s"
10330                   count (if (= count 1) " is" "s are")
10331                   (if unmark "unread" "read"))))
10332
10333 (defun gnus-summary-kill-same-subject (&optional unmark)
10334   "Mark articles which has the same subject as read.
10335 If UNMARK is positive, remove any kind of mark.
10336 If UNMARK is negative, tick articles."
10337   (interactive "P")
10338   (when unmark
10339     (setq unmark (prefix-numeric-value unmark)))
10340   (let ((count
10341          (gnus-summary-mark-same-subject
10342           (gnus-summary-article-subject) unmark)))
10343     ;; If marked as read, go to next unread subject.
10344     (when (null unmark)
10345       ;; Go to next unread subject.
10346       (gnus-summary-next-subject 1 t))
10347     (gnus-message 7 "%d articles are marked as %s"
10348                   count (if unmark "unread" "read"))))
10349
10350 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10351   "Mark articles with same SUBJECT as read, and return marked number.
10352 If optional argument UNMARK is positive, remove any kinds of marks.
10353 If optional argument UNMARK is negative, mark articles as unread instead."
10354   (let ((count 1))
10355     (save-excursion
10356       (cond
10357        ((null unmark)                   ; Mark as read.
10358         (while (and
10359                 (progn
10360                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10361                   (gnus-summary-show-thread) t)
10362                 (gnus-summary-find-subject subject))
10363           (setq count (1+ count))))
10364        ((> unmark 0)                    ; Tick.
10365         (while (and
10366                 (progn
10367                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10368                   (gnus-summary-show-thread) t)
10369                 (gnus-summary-find-subject subject))
10370           (setq count (1+ count))))
10371        (t                               ; Mark as unread.
10372         (while (and
10373                 (progn
10374                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10375                   (gnus-summary-show-thread) t)
10376                 (gnus-summary-find-subject subject))
10377           (setq count (1+ count)))))
10378       (gnus-set-mode-line 'summary)
10379       ;; Return the number of marked articles.
10380       count)))
10381
10382 (defun gnus-summary-mark-as-processable (n &optional unmark)
10383   "Set the process mark on the next N articles.
10384 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10385 the process mark instead.  The difference between N and the actual
10386 number of articles marked is returned."
10387   (interactive "P")
10388   (if (and (null n) (gnus-region-active-p))
10389       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10390     (setq n (prefix-numeric-value n))
10391     (let ((backward (< n 0))
10392           (n (abs n)))
10393       (while (and
10394               (> n 0)
10395               (if unmark
10396                   (gnus-summary-remove-process-mark
10397                    (gnus-summary-article-number))
10398                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10399               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10400         (setq n (1- n)))
10401       (when (/= 0 n)
10402         (gnus-message 7 "No more articles"))
10403       (gnus-summary-recenter)
10404       (gnus-summary-position-point)
10405       n)))
10406
10407 (defun gnus-summary-unmark-as-processable (n)
10408   "Remove the process mark from the next N articles.
10409 If N is negative, unmark backward instead.  The difference between N and
10410 the actual number of articles unmarked is returned."
10411   (interactive "P")
10412   (gnus-summary-mark-as-processable n t))
10413
10414 (defun gnus-summary-unmark-all-processable ()
10415   "Remove the process mark from all articles."
10416   (interactive)
10417   (save-excursion
10418     (while gnus-newsgroup-processable
10419       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10420   (gnus-summary-position-point))
10421
10422 (defun gnus-summary-add-mark (article type)
10423   "Mark ARTICLE with a mark of TYPE."
10424   (let ((vtype (car (assq type gnus-article-mark-lists)))
10425         var)
10426     (if (not vtype)
10427         (error "No such mark type: %s" type)
10428       (setq var (intern (format "gnus-newsgroup-%s" type)))
10429       (set var (cons article (symbol-value var)))
10430       (if (memq type '(processable cached replied forwarded recent saved))
10431           (gnus-summary-update-secondary-mark article)
10432         ;;; !!! This is bogus.  We should find out what primary
10433         ;;; !!! mark we want to set.
10434         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10435
10436 (defun gnus-summary-mark-as-expirable (n)
10437   "Mark N articles forward as expirable.
10438 If N is negative, mark backward instead.  The difference between N and
10439 the actual number of articles marked is returned."
10440   (interactive "p")
10441   (gnus-summary-mark-forward n gnus-expirable-mark))
10442
10443 (defun gnus-summary-mark-as-spam (n)
10444   "Mark N articles forward as spam.
10445 If N is negative, mark backward instead.  The difference between N and
10446 the actual number of articles marked is returned."
10447   (interactive "p")
10448   (gnus-summary-mark-forward n gnus-spam-mark))
10449
10450 (defun gnus-summary-mark-article-as-replied (article)
10451   "Mark ARTICLE as replied to and update the summary line.
10452 ARTICLE can also be a list of articles."
10453   (interactive (list (gnus-summary-article-number)))
10454   (let ((articles (if (listp article) article (list article))))
10455     (dolist (article articles)
10456       (unless (numberp article)
10457         (error "%s is not a number" article))
10458       (push article gnus-newsgroup-replied)
10459       (let ((buffer-read-only nil))
10460         (when (gnus-summary-goto-subject article nil t)
10461           (gnus-summary-update-secondary-mark article))))))
10462
10463 (defun gnus-summary-mark-article-as-forwarded (article)
10464   "Mark ARTICLE as forwarded and update the summary line.
10465 ARTICLE can also be a list of articles."
10466   (let ((articles (if (listp article) article (list article))))
10467     (dolist (article articles)
10468       (push article gnus-newsgroup-forwarded)
10469       (let ((buffer-read-only nil))
10470         (when (gnus-summary-goto-subject article nil t)
10471           (gnus-summary-update-secondary-mark article))))))
10472
10473 (defun gnus-summary-set-bookmark (article)
10474   "Set a bookmark in current article."
10475   (interactive (list (gnus-summary-article-number)))
10476   (when (or (not (get-buffer gnus-article-buffer))
10477             (not gnus-current-article)
10478             (not gnus-article-current)
10479             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10480     (error "No current article selected"))
10481   ;; Remove old bookmark, if one exists.
10482   (gnus-pull article gnus-newsgroup-bookmarks)
10483   ;; Set the new bookmark, which is on the form
10484   ;; (article-number . line-number-in-body).
10485   (push
10486    (cons article
10487          (with-current-buffer gnus-article-buffer
10488            (count-lines
10489             (min (point)
10490                  (save-excursion
10491                    (article-goto-body)
10492                    (point)))
10493             (point))))
10494    gnus-newsgroup-bookmarks)
10495   (gnus-message 6 "A bookmark has been added to the current article."))
10496
10497 (defun gnus-summary-remove-bookmark (article)
10498   "Remove the bookmark from the current article."
10499   (interactive (list (gnus-summary-article-number)))
10500   ;; Remove old bookmark, if one exists.
10501   (if (not (assq article gnus-newsgroup-bookmarks))
10502       (gnus-message 6 "No bookmark in current article.")
10503     (gnus-pull article gnus-newsgroup-bookmarks)
10504     (gnus-message 6 "Removed bookmark.")))
10505
10506 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10507 (defun gnus-summary-mark-as-dormant (n)
10508   "Mark N articles forward as dormant.
10509 If N is negative, mark backward instead.  The difference between N and
10510 the actual number of articles marked is returned."
10511   (interactive "p")
10512   (gnus-summary-mark-forward n gnus-dormant-mark))
10513
10514 (defun gnus-summary-set-process-mark (article)
10515   "Set the process mark on ARTICLE and update the summary line."
10516   (setq gnus-newsgroup-processable
10517         (cons article
10518               (delq article gnus-newsgroup-processable)))
10519   (when (gnus-summary-goto-subject article)
10520     (gnus-summary-show-thread)
10521     (gnus-summary-goto-subject article)
10522     (gnus-summary-update-secondary-mark article)))
10523
10524 (defun gnus-summary-remove-process-mark (&rest articles)
10525   "Remove the process mark from ARTICLES and update the summary line."
10526   (dolist (article articles)
10527     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10528     (when (gnus-summary-goto-subject article)
10529       (gnus-summary-show-thread)
10530       (gnus-summary-goto-subject article)
10531       (gnus-summary-update-secondary-mark article)))
10532   t)
10533
10534 (defun gnus-summary-set-saved-mark (article)
10535   "Set the process mark on ARTICLE and update the summary line."
10536   (push article gnus-newsgroup-saved)
10537   (when (gnus-summary-goto-subject article)
10538     (gnus-summary-update-secondary-mark article)))
10539
10540 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10541   "Mark N articles as read forwards.
10542 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10543 The difference between N and the actual number of articles marked is
10544 returned.
10545 If NO-EXPIRE, auto-expiry will be inhibited."
10546   (interactive "p")
10547   (gnus-summary-show-thread)
10548   (let ((backward (< n 0))
10549         (gnus-summary-goto-unread
10550          (and gnus-summary-goto-unread
10551               (not (eq gnus-summary-goto-unread 'never))
10552               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10553                                     gnus-ticked-mark gnus-dormant-mark)))))
10554         (n (abs n))
10555         (mark (or mark gnus-del-mark)))
10556     (while (and (> n 0)
10557                 (gnus-summary-mark-article nil mark no-expire)
10558                 (zerop (gnus-summary-next-subject
10559                         (if backward -1 1)
10560                         (and gnus-summary-goto-unread
10561                              (not (eq gnus-summary-goto-unread 'never)))
10562                         t)))
10563       (setq n (1- n)))
10564     (when (/= 0 n)
10565       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10566     (gnus-summary-recenter)
10567     (gnus-summary-position-point)
10568     (gnus-set-mode-line 'summary)
10569     n))
10570
10571 (defun gnus-summary-mark-article-as-read (mark)
10572   "Mark the current article quickly as read with MARK."
10573   (let ((article (gnus-summary-article-number)))
10574     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10575     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10576     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10577     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10578     (push (cons article mark) gnus-newsgroup-reads)
10579     ;; Possibly remove from cache, if that is used.
10580     (when gnus-use-cache
10581       (gnus-cache-enter-remove-article article))
10582     ;; Allow the backend to change the mark.
10583     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10584     ;; Check for auto-expiry.
10585     (when (and gnus-newsgroup-auto-expire
10586                (memq mark gnus-auto-expirable-marks))
10587       (setq mark gnus-expirable-mark)
10588       ;; Let the backend know about the mark change.
10589       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10590       (push article gnus-newsgroup-expirable))
10591     ;; Set the mark in the buffer.
10592     (gnus-summary-update-mark mark 'unread)
10593     t))
10594
10595 (defun gnus-summary-mark-article-as-unread (mark)
10596   "Mark the current article quickly as unread with MARK."
10597   (let* ((article (gnus-summary-article-number))
10598          (old-mark (gnus-summary-article-mark article)))
10599     ;; Allow the backend to change the mark.
10600     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10601     (if (eq mark old-mark)
10602         t
10603       (if (<= article 0)
10604           (progn
10605             (gnus-error 1 "Can't mark negative article numbers")
10606             nil)
10607         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10608         (setq gnus-newsgroup-spam-marked
10609               (delq article gnus-newsgroup-spam-marked))
10610         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10611         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10612         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10613         (cond ((= mark gnus-ticked-mark)
10614                (setq gnus-newsgroup-marked
10615                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10616                                               article)))
10617               ((= mark gnus-spam-mark)
10618                (setq gnus-newsgroup-spam-marked
10619                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10620                                               article)))
10621               ((= mark gnus-dormant-mark)
10622                (setq gnus-newsgroup-dormant
10623                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10624                                               article)))
10625               (t
10626                (setq gnus-newsgroup-unreads
10627                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10628                                               article))))
10629         (gnus-pull article gnus-newsgroup-reads)
10630
10631         ;; See whether the article is to be put in the cache.
10632         (and gnus-use-cache
10633              (vectorp (gnus-summary-article-header article))
10634              (save-excursion
10635                (gnus-cache-possibly-enter-article
10636                 gnus-newsgroup-name article
10637                 (= mark gnus-ticked-mark)
10638                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10639
10640         ;; Fix the mark.
10641         (gnus-summary-update-mark mark 'unread)
10642         t))))
10643
10644 (defun gnus-summary-mark-article (&optional article mark no-expire)
10645   "Mark ARTICLE with MARK.  MARK can be any character.
10646 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10647 `??' (dormant) and `?E' (expirable).
10648 If MARK is nil, then the default character `?r' is used.
10649 If ARTICLE is nil, then the article on the current line will be
10650 marked.
10651 If NO-EXPIRE, auto-expiry will be inhibited."
10652   ;; The mark might be a string.
10653   (when (stringp mark)
10654     (setq mark (aref mark 0)))
10655   ;; If no mark is given, then we check auto-expiring.
10656   (when (null mark)
10657     (setq mark gnus-del-mark))
10658   (when (and (not no-expire)
10659              gnus-newsgroup-auto-expire
10660              (memq mark gnus-auto-expirable-marks))
10661     (setq mark gnus-expirable-mark))
10662   (let ((article (or article (gnus-summary-article-number)))
10663         (old-mark (gnus-summary-article-mark article)))
10664     ;; Allow the backend to change the mark.
10665     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10666     (if (eq mark old-mark)
10667         t
10668       (unless article
10669         (error "No article on current line"))
10670       (if (not (if (or (= mark gnus-unread-mark)
10671                        (= mark gnus-ticked-mark)
10672                        (= mark gnus-spam-mark)
10673                        (= mark gnus-dormant-mark))
10674                    (gnus-mark-article-as-unread article mark)
10675                  (gnus-mark-article-as-read article mark)))
10676           t
10677         ;; See whether the article is to be put in the cache.
10678         (and gnus-use-cache
10679              (not (= mark gnus-canceled-mark))
10680              (vectorp (gnus-summary-article-header article))
10681              (save-excursion
10682                (gnus-cache-possibly-enter-article
10683                 gnus-newsgroup-name article
10684                 (= mark gnus-ticked-mark)
10685                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10686
10687         (when (gnus-summary-goto-subject article nil t)
10688           (let ((buffer-read-only nil))
10689             (gnus-summary-show-thread)
10690             ;; Fix the mark.
10691             (gnus-summary-update-mark mark 'unread)
10692             t))))))
10693
10694 (defun gnus-summary-update-secondary-mark (article)
10695   "Update the secondary (read, process, cache) mark."
10696   (gnus-summary-update-mark
10697    (cond ((memq article gnus-newsgroup-processable)
10698           gnus-process-mark)
10699          ((memq article gnus-newsgroup-cached)
10700           gnus-cached-mark)
10701          ((memq article gnus-newsgroup-replied)
10702           gnus-replied-mark)
10703          ((memq article gnus-newsgroup-forwarded)
10704           gnus-forwarded-mark)
10705          ((memq article gnus-newsgroup-saved)
10706           gnus-saved-mark)
10707          ((memq article gnus-newsgroup-recent)
10708           gnus-recent-mark)
10709          ((memq article gnus-newsgroup-unseen)
10710           gnus-unseen-mark)
10711          (t gnus-no-mark))
10712    'replied)
10713   (when (gnus-visual-p 'summary-highlight 'highlight)
10714     (gnus-run-hooks 'gnus-summary-update-hook))
10715   t)
10716
10717 (defun gnus-summary-update-download-mark (article)
10718   "Update the download mark."
10719   (gnus-summary-update-mark
10720    (cond ((memq article gnus-newsgroup-undownloaded)
10721           gnus-undownloaded-mark)
10722          (gnus-newsgroup-agentized
10723           gnus-downloaded-mark)
10724          (t
10725           gnus-no-mark))
10726    'download)
10727   (gnus-summary-update-line t)
10728   t)
10729
10730 (defun gnus-summary-update-mark (mark type)
10731   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10732         (buffer-read-only nil))
10733     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10734     (when forward
10735       (when (looking-at "\r")
10736         (incf forward))
10737       (when (<= (+ forward (point)) (point-max))
10738         ;; Go to the right position on the line.
10739         (goto-char (+ forward (point)))
10740         ;; Replace the old mark with the new mark.
10741         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10742         ;; Optionally update the marks by some user rule.
10743         (when (eq type 'unread)
10744           (gnus-data-set-mark
10745            (gnus-data-find (gnus-summary-article-number)) mark)
10746           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10747
10748 (defun gnus-mark-article-as-read (article &optional mark)
10749   "Enter ARTICLE in the pertinent lists and remove it from others."
10750   ;; Make the article expirable.
10751   (let ((mark (or mark gnus-del-mark)))
10752     (setq gnus-newsgroup-expirable
10753           (if (= mark gnus-expirable-mark)
10754               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10755             (delq article gnus-newsgroup-expirable)))
10756     ;; Remove from unread and marked lists.
10757     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10758     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10759     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10760     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10761     (push (cons article mark) gnus-newsgroup-reads)
10762     ;; Possibly remove from cache, if that is used.
10763     (when gnus-use-cache
10764       (gnus-cache-enter-remove-article article))
10765     t))
10766
10767 (defun gnus-mark-article-as-unread (article &optional mark)
10768   "Enter ARTICLE in the pertinent lists and remove it from others."
10769   (let ((mark (or mark gnus-ticked-mark)))
10770     (if (<= article 0)
10771         (progn
10772           (gnus-error 1 "Can't mark negative article numbers")
10773           nil)
10774       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10775             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10776             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10777             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10778             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10779
10780       ;; Unsuppress duplicates?
10781       (when gnus-suppress-duplicates
10782         (gnus-dup-unsuppress-article article))
10783
10784       (cond ((= mark gnus-ticked-mark)
10785              (setq gnus-newsgroup-marked
10786                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10787             ((= mark gnus-spam-mark)
10788              (setq gnus-newsgroup-spam-marked
10789                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10790                                             article)))
10791             ((= mark gnus-dormant-mark)
10792              (setq gnus-newsgroup-dormant
10793                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10794             (t
10795              (setq gnus-newsgroup-unreads
10796                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10797       (gnus-pull article gnus-newsgroup-reads)
10798       t)))
10799
10800 (defalias 'gnus-summary-mark-as-unread-forward
10801   'gnus-summary-tick-article-forward)
10802 (make-obsolete 'gnus-summary-mark-as-unread-forward
10803                'gnus-summary-tick-article-forward)
10804 (defun gnus-summary-tick-article-forward (n)
10805   "Tick N articles forwards.
10806 If N is negative, tick backwards instead.
10807 The difference between N and the number of articles ticked is returned."
10808   (interactive "p")
10809   (gnus-summary-mark-forward n gnus-ticked-mark))
10810
10811 (defalias 'gnus-summary-mark-as-unread-backward
10812   'gnus-summary-tick-article-backward)
10813 (make-obsolete 'gnus-summary-mark-as-unread-backward
10814                'gnus-summary-tick-article-backward)
10815 (defun gnus-summary-tick-article-backward (n)
10816   "Tick N articles backwards.
10817 The difference between N and the number of articles ticked is returned."
10818   (interactive "p")
10819   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10820
10821 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10822 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10823 (defun gnus-summary-tick-article (&optional article clear-mark)
10824   "Mark current article as unread.
10825 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10826 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10827   (interactive)
10828   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10829                                        gnus-ticked-mark)))
10830
10831 (defun gnus-summary-mark-as-read-forward (n)
10832   "Mark N articles as read forwards.
10833 If N is negative, mark backwards instead.
10834 The difference between N and the actual number of articles marked is
10835 returned."
10836   (interactive "p")
10837   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10838
10839 (defun gnus-summary-mark-as-read-backward (n)
10840   "Mark the N articles as read backwards.
10841 The difference between N and the actual number of articles marked is
10842 returned."
10843   (interactive "p")
10844   (gnus-summary-mark-forward
10845    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10846
10847 (defun gnus-summary-mark-as-read (&optional article mark)
10848   "Mark current article as read.
10849 ARTICLE specifies the article to be marked as read.
10850 MARK specifies a string to be inserted at the beginning of the line."
10851   (gnus-summary-mark-article article mark))
10852
10853 (defun gnus-summary-clear-mark-forward (n)
10854   "Clear marks from N articles forward.
10855 If N is negative, clear backward instead.
10856 The difference between N and the number of marks cleared is returned."
10857   (interactive "p")
10858   (gnus-summary-mark-forward n gnus-unread-mark))
10859
10860 (defun gnus-summary-clear-mark-backward (n)
10861   "Clear marks from N articles backward.
10862 The difference between N and the number of marks cleared is returned."
10863   (interactive "p")
10864   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10865
10866 (defun gnus-summary-mark-unread-as-read ()
10867   "Intended to be used by `gnus-mark-article-hook'."
10868   (when (memq gnus-current-article gnus-newsgroup-unreads)
10869     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10870
10871 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10872   "Intended to be used by `gnus-mark-article-hook'."
10873   (let ((mark (gnus-summary-article-mark)))
10874     (when (or (gnus-unread-mark-p mark)
10875               (gnus-read-mark-p mark))
10876       (gnus-summary-mark-article gnus-current-article
10877                                  (or new-mark gnus-read-mark)))))
10878
10879 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10880   "Intended to be used by `gnus-mark-article-hook'."
10881   (let ((mark (gnus-summary-article-mark)))
10882     (when (or (gnus-unread-mark-p mark)
10883               (gnus-read-mark-p mark))
10884       (gnus-summary-mark-article (gnus-summary-article-number)
10885                                  (or new-mark gnus-read-mark)))))
10886
10887 (defun gnus-summary-mark-unread-as-ticked ()
10888   "Intended to be used by `gnus-mark-article-hook'."
10889   (when (memq gnus-current-article gnus-newsgroup-unreads)
10890     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10891
10892 (defun gnus-summary-mark-region-as-read (point mark all)
10893   "Mark all unread articles between point and mark as read.
10894 If given a prefix, mark all articles between point and mark as read,
10895 even ticked and dormant ones."
10896   (interactive "r\nP")
10897   (save-excursion
10898     (let (article)
10899       (goto-char point)
10900       (beginning-of-line)
10901       (while (and
10902               (< (point) mark)
10903               (progn
10904                 (when (or all
10905                           (memq (setq article (gnus-summary-article-number))
10906                                 gnus-newsgroup-unreads))
10907                   (gnus-summary-mark-article article gnus-del-mark))
10908                 t)
10909               (gnus-summary-find-next))))))
10910
10911 (defun gnus-summary-mark-below (score mark)
10912   "Mark articles with score less than SCORE with MARK."
10913   (interactive "P\ncMark: ")
10914   (setq score (if score
10915                   (prefix-numeric-value score)
10916                 (or gnus-summary-default-score 0)))
10917   (save-excursion
10918     (set-buffer gnus-summary-buffer)
10919     (goto-char (point-min))
10920     (while
10921         (progn
10922           (and (< (gnus-summary-article-score) score)
10923                (gnus-summary-mark-article nil mark))
10924           (gnus-summary-find-next)))))
10925
10926 (defun gnus-summary-kill-below (&optional score)
10927   "Mark articles with score below SCORE as read."
10928   (interactive "P")
10929   (gnus-summary-mark-below score gnus-killed-mark))
10930
10931 (defun gnus-summary-clear-above (&optional score)
10932   "Clear all marks from articles with score above SCORE."
10933   (interactive "P")
10934   (gnus-summary-mark-above score gnus-unread-mark))
10935
10936 (defun gnus-summary-tick-above (&optional score)
10937   "Tick all articles with score above SCORE."
10938   (interactive "P")
10939   (gnus-summary-mark-above score gnus-ticked-mark))
10940
10941 (defun gnus-summary-mark-above (score mark)
10942   "Mark articles with score over SCORE with MARK."
10943   (interactive "P\ncMark: ")
10944   (setq score (if score
10945                   (prefix-numeric-value score)
10946                 (or gnus-summary-default-score 0)))
10947   (save-excursion
10948     (set-buffer gnus-summary-buffer)
10949     (goto-char (point-min))
10950     (while (and (progn
10951                   (when (> (gnus-summary-article-score) score)
10952                     (gnus-summary-mark-article nil mark))
10953                   t)
10954                 (gnus-summary-find-next)))))
10955
10956 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10957 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10958 (defun gnus-summary-limit-include-expunged (&optional no-error)
10959   "Display all the hidden articles that were expunged for low scores."
10960   (interactive)
10961   (let ((buffer-read-only nil))
10962     (let ((scored gnus-newsgroup-scored)
10963           headers h)
10964       (while scored
10965         (unless (gnus-summary-article-header (caar scored))
10966           (and (setq h (gnus-number-to-header (caar scored)))
10967                (< (cdar scored) gnus-summary-expunge-below)
10968                (push h headers)))
10969         (setq scored (cdr scored)))
10970       (if (not headers)
10971           (when (not no-error)
10972             (error "No expunged articles hidden"))
10973         (goto-char (point-min))
10974         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10975         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10976         (dolist (x headers)
10977           (push (mail-header-number x) gnus-newsgroup-limit))
10978         (gnus-summary-prepare-unthreaded (nreverse headers))
10979         (goto-char (point-min))
10980         (gnus-summary-position-point)
10981         t))))
10982
10983 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10984   "Mark all unread articles in this newsgroup as read.
10985 If prefix argument ALL is non-nil, ticked and dormant articles will
10986 also be marked as read.
10987 If QUIETLY is non-nil, no questions will be asked.
10988
10989 If TO-HERE is non-nil, it should be a point in the buffer.  All
10990 articles before (after, if REVERSE is set) this point will be marked
10991 as read.
10992
10993 Note that this function will only catch up the unread article
10994 in the current summary buffer limitation.
10995
10996 The number of articles marked as read is returned."
10997   (interactive "P")
10998   (prog1
10999       (save-excursion
11000         (when (or quietly
11001                   (not gnus-interactive-catchup) ;Without confirmation?
11002                   gnus-expert-user
11003                   (gnus-y-or-n-p
11004                    (if all
11005                        "Mark absolutely all articles as read? "
11006                      "Mark all unread articles as read? ")))
11007           (if (and not-mark
11008                    (not gnus-newsgroup-adaptive)
11009                    (not gnus-newsgroup-auto-expire)
11010                    (not gnus-suppress-duplicates)
11011                    (or (not gnus-use-cache)
11012                        (eq gnus-use-cache 'passive)))
11013               (progn
11014                 (when all
11015                   (setq gnus-newsgroup-marked nil
11016                         gnus-newsgroup-spam-marked nil
11017                         gnus-newsgroup-dormant nil))
11018                 (setq gnus-newsgroup-unreads
11019                       (gnus-sorted-nunion
11020                        (gnus-sorted-intersection gnus-newsgroup-unreads
11021                                                  gnus-newsgroup-downloadable)
11022                        (gnus-sorted-difference gnus-newsgroup-unfetched
11023                                                gnus-newsgroup-cached))))
11024             ;; We actually mark all articles as canceled, which we
11025             ;; have to do when using auto-expiry or adaptive scoring.
11026             (gnus-summary-show-all-threads)
11027             (if (and to-here reverse)
11028                 (progn
11029                   (goto-char to-here)
11030                   (gnus-summary-mark-current-read-and-unread-as-read
11031                    gnus-catchup-mark)
11032                   (while (gnus-summary-find-next (not all))
11033                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
11034               (when (gnus-summary-first-subject (not all))
11035                 (while (and
11036                         (if to-here (< (point) to-here) t)
11037                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
11038                         (gnus-summary-find-next (not all))))))
11039             (gnus-set-mode-line 'summary))
11040           t))
11041     (gnus-summary-position-point)))
11042
11043 (defun gnus-summary-catchup-to-here (&optional all)
11044   "Mark all unticked articles before the current one as read.
11045 If ALL is non-nil, also mark ticked and dormant articles as read."
11046   (interactive "P")
11047   (save-excursion
11048     (gnus-save-hidden-threads
11049       (let ((beg (point)))
11050         ;; We check that there are unread articles.
11051         (when (or all (gnus-summary-find-prev))
11052           (gnus-summary-catchup all t beg)))))
11053   (gnus-summary-position-point))
11054
11055 (defun gnus-summary-catchup-from-here (&optional all)
11056   "Mark all unticked articles after (and including) the current one as read.
11057 If ALL is non-nil, also mark ticked and dormant articles as read."
11058   (interactive "P")
11059   (save-excursion
11060     (gnus-save-hidden-threads
11061       (let ((beg (point)))
11062         ;; We check that there are unread articles.
11063         (when (or all (gnus-summary-find-next))
11064           (gnus-summary-catchup all t beg nil t)))))
11065   (gnus-summary-position-point))
11066
11067 (defun gnus-summary-catchup-all (&optional quietly)
11068   "Mark all articles in this newsgroup as read.
11069 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11070 instead, which marks only unread articles as read."
11071   (interactive "P")
11072   (gnus-summary-catchup t quietly))
11073
11074 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11075   "Mark all unread articles in this group as read, then exit.
11076 If prefix argument ALL is non-nil, all articles are marked as read.
11077 If QUIETLY is non-nil, no questions will be asked."
11078   (interactive "P")
11079   (when (gnus-summary-catchup all quietly nil 'fast)
11080     ;; Select next newsgroup or exit.
11081     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11082              (eq gnus-auto-select-next 'quietly))
11083         (gnus-summary-next-group nil)
11084       (gnus-summary-exit))))
11085
11086 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11087   "Mark all articles in this newsgroup as read, and then exit.
11088 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11089 instead, which marks only unread articles as read."
11090   (interactive "P")
11091   (gnus-summary-catchup-and-exit t quietly))
11092
11093 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11094   "Mark all articles in this group as read and select the next group.
11095 If given a prefix, mark all articles, unread as well as ticked, as
11096 read."
11097   (interactive "P")
11098   (save-excursion
11099     (gnus-summary-catchup all))
11100   (gnus-summary-next-group))
11101
11102 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11103   "Mark all articles in this group as read and select the previous group.
11104 If given a prefix, mark all articles, unread as well as ticked, as
11105 read."
11106   (interactive "P")
11107   (save-excursion
11108     (gnus-summary-catchup all))
11109   (gnus-summary-next-group nil nil t))
11110
11111 ;;;
11112 ;;; with article
11113 ;;;
11114
11115 (defmacro gnus-with-article (article &rest forms)
11116   "Select ARTICLE and perform FORMS in the original article buffer.
11117 Then replace the article with the result."
11118   `(progn
11119      ;; We don't want the article to be marked as read.
11120      (let (gnus-mark-article-hook)
11121        (gnus-summary-select-article t t nil ,article))
11122      (set-buffer gnus-original-article-buffer)
11123      ,@forms
11124      (if (not (gnus-check-backend-function
11125                'request-replace-article (car gnus-article-current)))
11126          (gnus-message 5 "Read-only group; not replacing")
11127        (unless (gnus-request-replace-article
11128                 ,article (car gnus-article-current)
11129                 (current-buffer) t)
11130          (error "Couldn't replace article")))
11131      ;; The cache and backlog have to be flushed somewhat.
11132      (when gnus-keep-backlog
11133        (gnus-backlog-remove-article
11134         (car gnus-article-current) (cdr gnus-article-current)))
11135      (when gnus-use-cache
11136        (gnus-cache-update-article
11137         (car gnus-article-current) (cdr gnus-article-current)))))
11138
11139 (put 'gnus-with-article 'lisp-indent-function 1)
11140 (put 'gnus-with-article 'edebug-form-spec '(form body))
11141
11142 ;; Thread-based commands.
11143
11144 (defun gnus-summary-articles-in-thread (&optional article)
11145   "Return a list of all articles in the current thread.
11146 If ARTICLE is non-nil, return all articles in the thread that starts
11147 with that article."
11148   (let* ((article (or article (gnus-summary-article-number)))
11149          (data (gnus-data-find-list article))
11150          (top-level (gnus-data-level (car data)))
11151          (top-subject
11152           (cond ((null gnus-thread-operation-ignore-subject)
11153                  (gnus-simplify-subject-re
11154                   (mail-header-subject (gnus-data-header (car data)))))
11155                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11156                  (gnus-simplify-subject-fuzzy
11157                   (mail-header-subject (gnus-data-header (car data)))))
11158                 (t nil)))
11159          (end-point (save-excursion
11160                       (if (gnus-summary-go-to-next-thread)
11161                           (point) (point-max))))
11162          articles)
11163     (while (and data
11164                 (< (gnus-data-pos (car data)) end-point))
11165       (when (or (not top-subject)
11166                 (string= top-subject
11167                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11168                              (gnus-simplify-subject-fuzzy
11169                               (mail-header-subject
11170                                (gnus-data-header (car data))))
11171                            (gnus-simplify-subject-re
11172                             (mail-header-subject
11173                              (gnus-data-header (car data)))))))
11174         (push (gnus-data-number (car data)) articles))
11175       (unless (and (setq data (cdr data))
11176                    (> (gnus-data-level (car data)) top-level))
11177         (setq data nil)))
11178     ;; Return the list of articles.
11179     (nreverse articles)))
11180
11181 (defun gnus-summary-rethread-current ()
11182   "Rethread the thread the current article is part of."
11183   (interactive)
11184   (let* ((gnus-show-threads t)
11185          (article (gnus-summary-article-number))
11186          (id (mail-header-id (gnus-summary-article-header)))
11187          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11188     (unless id
11189       (error "No article on the current line"))
11190     (gnus-rebuild-thread id)
11191     (gnus-summary-goto-subject article)))
11192
11193 (defun gnus-summary-reparent-thread ()
11194   "Make the current article child of the marked (or previous) article.
11195
11196 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11197 is non-nil or the Subject: of both articles are the same."
11198   (interactive)
11199   (unless (not (gnus-group-read-only-p))
11200     (error "The current newsgroup does not support article editing"))
11201   (unless (<= (length gnus-newsgroup-processable) 1)
11202     (error "No more than one article may be marked"))
11203   (let ((child (gnus-summary-article-number))
11204         ;; First grab the marked article, otherwise one line up.
11205         (parent (if (not (null gnus-newsgroup-processable))
11206                     (car gnus-newsgroup-processable)
11207                   (save-excursion
11208                     (if (eq (forward-line -1) 0)
11209                         (gnus-summary-article-number)
11210                       (error "Beginning of summary buffer"))))))
11211     (gnus-summary-reparent-children parent (list child))))
11212
11213 (defun gnus-summary-reparent-children (parent children)
11214   "Make PARENT the parent of CHILDREN.
11215 When called interactively, PARENT is the current article and CHILDREN
11216 are the process-marked articles."
11217   (interactive
11218    (list (gnus-summary-article-number)
11219          (gnus-summary-work-articles nil)))
11220   (dolist (child children)
11221     (save-window-excursion
11222       (let ((gnus-article-buffer " *reparent*"))
11223         (unless (not (eq parent child))
11224           (error "An article may not be self-referential"))
11225         (let ((message-id (mail-header-id
11226                            (gnus-summary-article-header parent))))
11227           (unless (and message-id (not (equal message-id "")))
11228             (error "No message-id in desired parent"))
11229           (gnus-with-article child
11230             (save-restriction
11231               (goto-char (point-min))
11232               (message-narrow-to-head)
11233               (if (re-search-forward "^References: " nil t)
11234                   (progn
11235                     (re-search-forward "^[^ \t]" nil t)
11236                     (forward-line -1)
11237                     (end-of-line)
11238                     (insert " " message-id))
11239                 (insert "References: " message-id "\n"))))
11240           (set-buffer gnus-summary-buffer)
11241           (gnus-summary-unmark-all-processable)
11242           (gnus-summary-update-article child)
11243           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11244             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11245           (gnus-summary-rethread-current)
11246           (gnus-message 3 "Article %d is now the child of article %d"
11247                         child parent))))))
11248
11249 (defun gnus-summary-toggle-threads (&optional arg)
11250   "Toggle showing conversation threads.
11251 If ARG is positive number, turn showing conversation threads on."
11252   (interactive "P")
11253   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11254     (setq gnus-show-threads
11255           (if (null arg) (not gnus-show-threads)
11256             (> (prefix-numeric-value arg) 0)))
11257     (gnus-summary-prepare)
11258     (gnus-summary-goto-subject current)
11259     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11260     (gnus-summary-position-point)))
11261
11262 (defun gnus-summary-show-all-threads ()
11263   "Show all threads."
11264   (interactive)
11265   (save-excursion
11266     (let ((buffer-read-only nil))
11267       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11268   (gnus-summary-position-point))
11269
11270 (defun gnus-summary-show-thread ()
11271   "Show thread subtrees.
11272 Returns nil if no thread was there to be shown."
11273   (interactive)
11274   (let ((buffer-read-only nil)
11275         (orig (point))
11276         (end (point-at-eol))
11277         ;; Leave point at bol
11278         (beg (progn (beginning-of-line) (point))))
11279     (prog1
11280         ;; Any hidden lines here?
11281         (search-forward "\r" end t)
11282       (subst-char-in-region beg end ?\^M ?\n t)
11283       (goto-char orig)
11284       (gnus-summary-position-point))))
11285
11286 (defun gnus-summary-maybe-hide-threads ()
11287   "If requested, hide the threads that should be hidden."
11288   (when (and gnus-show-threads
11289              gnus-thread-hide-subtree)
11290     (gnus-summary-hide-all-threads
11291      (if (or (consp gnus-thread-hide-subtree)
11292              (functionp gnus-thread-hide-subtree))
11293          (gnus-make-predicate gnus-thread-hide-subtree)
11294        nil))))
11295
11296 ;;; Hiding predicates.
11297
11298 (defun gnus-article-unread-p (header)
11299   (memq (mail-header-number header) gnus-newsgroup-unreads))
11300
11301 (defun gnus-article-unseen-p (header)
11302   (memq (mail-header-number header) gnus-newsgroup-unseen))
11303
11304 (defun gnus-map-articles (predicate articles)
11305   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11306   (apply 'gnus-or (mapcar predicate
11307                           (mapcar (lambda (number)
11308                                     (gnus-summary-article-header number))
11309                                   articles))))
11310
11311 (defun gnus-summary-hide-all-threads (&optional predicate)
11312   "Hide all thread subtrees.
11313 If PREDICATE is supplied, threads that satisfy this predicate
11314 will not be hidden."
11315   (interactive)
11316   (save-excursion
11317     (goto-char (point-min))
11318     (let ((end nil))
11319       (while (not end)
11320         (when (or (not predicate)
11321                   (gnus-map-articles
11322                    predicate (gnus-summary-article-children)))
11323             (gnus-summary-hide-thread))
11324         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11325   (gnus-summary-position-point))
11326
11327 (defun gnus-summary-hide-thread ()
11328   "Hide thread subtrees.
11329 If PREDICATE is supplied, threads that satisfy this predicate
11330 will not be hidden.
11331 Returns nil if no threads were there to be hidden."
11332   (interactive)
11333   (let ((buffer-read-only nil)
11334         (start (point))
11335         (article (gnus-summary-article-number)))
11336     (goto-char start)
11337     ;; Go forward until either the buffer ends or the subthread
11338     ;; ends.
11339     (when (and (not (eobp))
11340                (or (zerop (gnus-summary-next-thread 1 t))
11341                    (goto-char (point-max))))
11342       (prog1
11343           (if (and (> (point) start)
11344                    (search-backward "\n" start t))
11345               (progn
11346                 (subst-char-in-region start (point) ?\n ?\^M)
11347                 (gnus-summary-goto-subject article))
11348             (goto-char start)
11349             nil)))))
11350
11351 (defun gnus-summary-go-to-next-thread (&optional previous)
11352   "Go to the same level (or less) next thread.
11353 If PREVIOUS is non-nil, go to previous thread instead.
11354 Return the article number moved to, or nil if moving was impossible."
11355   (let ((level (gnus-summary-thread-level))
11356         (way (if previous -1 1))
11357         (beg (point)))
11358     (forward-line way)
11359     (while (and (not (eobp))
11360                 (< level (gnus-summary-thread-level)))
11361       (forward-line way))
11362     (if (eobp)
11363         (progn
11364           (goto-char beg)
11365           nil)
11366       (setq beg (point))
11367       (prog1
11368           (gnus-summary-article-number)
11369         (goto-char beg)))))
11370
11371 (defun gnus-summary-next-thread (n &optional silent)
11372   "Go to the same level next N'th thread.
11373 If N is negative, search backward instead.
11374 Returns the difference between N and the number of skips actually
11375 done.
11376
11377 If SILENT, don't output messages."
11378   (interactive "p")
11379   (let ((backward (< n 0))
11380         (n (abs n)))
11381     (while (and (> n 0)
11382                 (gnus-summary-go-to-next-thread backward))
11383       (decf n))
11384     (unless silent
11385       (gnus-summary-position-point))
11386     (when (and (not silent) (/= 0 n))
11387       (gnus-message 7 "No more threads"))
11388     n))
11389
11390 (defun gnus-summary-prev-thread (n)
11391   "Go to the same level previous N'th thread.
11392 Returns the difference between N and the number of skips actually
11393 done."
11394   (interactive "p")
11395   (gnus-summary-next-thread (- n)))
11396
11397 (defun gnus-summary-go-down-thread ()
11398   "Go down one level in the current thread."
11399   (let ((children (gnus-summary-article-children)))
11400     (when children
11401       (gnus-summary-goto-subject (car children)))))
11402
11403 (defun gnus-summary-go-up-thread ()
11404   "Go up one level in the current thread."
11405   (let ((parent (gnus-summary-article-parent)))
11406     (when parent
11407       (gnus-summary-goto-subject parent))))
11408
11409 (defun gnus-summary-down-thread (n)
11410   "Go down thread N steps.
11411 If N is negative, go up instead.
11412 Returns the difference between N and how many steps down that were
11413 taken."
11414   (interactive "p")
11415   (let ((up (< n 0))
11416         (n (abs n)))
11417     (while (and (> n 0)
11418                 (if up (gnus-summary-go-up-thread)
11419                   (gnus-summary-go-down-thread)))
11420       (setq n (1- n)))
11421     (gnus-summary-position-point)
11422     (when (/= 0 n)
11423       (gnus-message 7 "Can't go further"))
11424     n))
11425
11426 (defun gnus-summary-up-thread (n)
11427   "Go up thread N steps.
11428 If N is negative, go down instead.
11429 Returns the difference between N and how many steps down that were
11430 taken."
11431   (interactive "p")
11432   (gnus-summary-down-thread (- n)))
11433
11434 (defun gnus-summary-top-thread ()
11435   "Go to the top of the thread."
11436   (interactive)
11437   (while (gnus-summary-go-up-thread))
11438   (gnus-summary-article-number))
11439
11440 (defun gnus-summary-expire-thread ()
11441   "Mark articles under current thread as expired."
11442   (interactive)
11443   (gnus-summary-kill-thread 0))
11444
11445 (defun gnus-summary-kill-thread (&optional unmark)
11446   "Mark articles under current thread as read.
11447 If the prefix argument is positive, remove any kinds of marks.
11448 If the prefix argument is zero, mark thread as expired.
11449 If the prefix argument is negative, tick articles instead."
11450   (interactive "P")
11451   (when unmark
11452     (setq unmark (prefix-numeric-value unmark)))
11453   (let ((articles (gnus-summary-articles-in-thread))
11454         (hide (or (null unmark) (= unmark 0))))
11455     (save-excursion
11456       ;; Expand the thread.
11457       (gnus-summary-show-thread)
11458       ;; Mark all the articles.
11459       (while articles
11460         (gnus-summary-goto-subject (car articles))
11461         (cond ((null unmark)
11462                (gnus-summary-mark-article-as-read gnus-killed-mark))
11463               ((> unmark 0)
11464                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11465               ((= unmark 0)
11466                (gnus-summary-mark-article-as-unread gnus-expirable-mark))
11467               (t
11468                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11469         (setq articles (cdr articles))))
11470     ;; Hide killed subtrees when hide is true.
11471     (and hide
11472          gnus-thread-hide-killed
11473          (gnus-summary-hide-thread))
11474     ;; If hide is t, go to next unread subject.
11475     (when hide
11476       ;; Go to next unread subject.
11477       (gnus-summary-next-subject 1 t)))
11478   (gnus-set-mode-line 'summary))
11479
11480 ;; Summary sorting commands
11481
11482 (defun gnus-summary-sort-by-number (&optional reverse)
11483   "Sort the summary buffer by article number.
11484 Argument REVERSE means reverse order."
11485   (interactive "P")
11486   (gnus-summary-sort 'number reverse))
11487
11488 (defun gnus-summary-sort-by-random (&optional reverse)
11489   "Randomize the order in the summary buffer.
11490 Argument REVERSE means to randomize in reverse order."
11491   (interactive "P")
11492   (gnus-summary-sort 'random reverse))
11493
11494 (defun gnus-summary-sort-by-author (&optional reverse)
11495   "Sort the summary buffer by author name alphabetically.
11496 If `case-fold-search' is non-nil, case of letters is ignored.
11497 Argument REVERSE means reverse order."
11498   (interactive "P")
11499   (gnus-summary-sort 'author reverse))
11500
11501 (defun gnus-summary-sort-by-recipient (&optional reverse)
11502   "Sort the summary buffer by recipient name alphabetically.
11503 If `case-fold-search' is non-nil, case of letters is ignored.
11504 Argument REVERSE means reverse order."
11505   (interactive "P")
11506   (gnus-summary-sort 'recipient reverse))
11507
11508 (defun gnus-summary-sort-by-subject (&optional reverse)
11509   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11510 If `case-fold-search' is non-nil, case of letters is ignored.
11511 Argument REVERSE means reverse order."
11512   (interactive "P")
11513   (gnus-summary-sort 'subject reverse))
11514
11515 (defun gnus-summary-sort-by-date (&optional reverse)
11516   "Sort the summary buffer by date.
11517 Argument REVERSE means reverse order."
11518   (interactive "P")
11519   (gnus-summary-sort 'date reverse))
11520
11521 (defun gnus-summary-sort-by-score (&optional reverse)
11522   "Sort the summary buffer by score.
11523 Argument REVERSE means reverse order."
11524   (interactive "P")
11525   (gnus-summary-sort 'score reverse))
11526
11527 (defun gnus-summary-sort-by-lines (&optional reverse)
11528   "Sort the summary buffer by the number of lines.
11529 Argument REVERSE means reverse order."
11530   (interactive "P")
11531   (gnus-summary-sort 'lines reverse))
11532
11533 (defun gnus-summary-sort-by-chars (&optional reverse)
11534   "Sort the summary buffer by article length.
11535 Argument REVERSE means reverse order."
11536   (interactive "P")
11537   (gnus-summary-sort 'chars reverse))
11538
11539 (defun gnus-summary-sort-by-original (&optional reverse)
11540   "Sort the summary buffer using the default sorting method.
11541 Argument REVERSE means reverse order."
11542   (interactive "P")
11543   (let* ((buffer-read-only)
11544          (gnus-summary-prepare-hook nil))
11545     ;; We do the sorting by regenerating the threads.
11546     (gnus-summary-prepare)
11547     ;; Hide subthreads if needed.
11548     (gnus-summary-maybe-hide-threads)))
11549
11550 (defun gnus-summary-sort (predicate reverse)
11551   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11552   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11553          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11554          (gnus-thread-sort-functions
11555           (if (not reverse)
11556               thread
11557             `(lambda (t1 t2)
11558                (,thread t2 t1))))
11559          (gnus-sort-gathered-threads-function
11560           gnus-thread-sort-functions)
11561          (gnus-article-sort-functions
11562           (if (not reverse)
11563               article
11564             `(lambda (t1 t2)
11565                (,article t2 t1))))
11566          (buffer-read-only)
11567          (gnus-summary-prepare-hook nil))
11568     ;; We do the sorting by regenerating the threads.
11569     (gnus-summary-prepare)
11570     ;; Hide subthreads if needed.
11571     (gnus-summary-maybe-hide-threads)))
11572
11573 ;; Summary saving commands.
11574
11575 (defun gnus-summary-save-article (&optional n not-saved)
11576   "Save the current article using the default saver function.
11577 If N is a positive number, save the N next articles.
11578 If N is a negative number, save the N previous articles.
11579 If N is nil and any articles have been marked with the process mark,
11580 save those articles instead.
11581 The variable `gnus-default-article-saver' specifies the saver function.
11582
11583 If the optional second argument NOT-SAVED is non-nil, articles saved
11584 will not be marked as saved."
11585   (interactive "P")
11586   (require 'gnus-art)
11587   (let* ((articles (gnus-summary-work-articles n))
11588          (save-buffer (save-excursion
11589                         (nnheader-set-temp-buffer " *Gnus Save*")))
11590          (num (length articles))
11591          ;; Whether to save decoded articles or raw articles.
11592          (decode (when gnus-article-save-coding-system
11593                    (get gnus-default-article-saver :decode)))
11594          ;; When saving many articles in a single file, use the other
11595          ;; function to save articles other than the first one.
11596          (saver2 (get gnus-default-article-saver :function))
11597          (gnus-prompt-before-saving (if saver2
11598                                         t
11599                                       gnus-prompt-before-saving))
11600          (gnus-default-article-saver gnus-default-article-saver)
11601          header file)
11602     (dolist (article articles)
11603       (setq header (gnus-summary-article-header article))
11604       (if (not (vectorp header))
11605           ;; This is a pseudo-article.
11606           (if (assq 'name header)
11607               (gnus-copy-file (cdr (assq 'name header)))
11608             (gnus-message 1 "Article %d is unsaveable" article))
11609         ;; This is a real article.
11610         (save-window-excursion
11611           (let ((gnus-display-mime-function (when decode
11612                                               gnus-display-mime-function))
11613                 (gnus-article-prepare-hook (when decode
11614                                              gnus-article-prepare-hook)))
11615             (gnus-summary-select-article t nil nil article)
11616             (gnus-summary-goto-subject article)))
11617         (save-excursion
11618           (set-buffer save-buffer)
11619           (erase-buffer)
11620           (insert-buffer-substring (if decode
11621                                        gnus-article-buffer
11622                                      gnus-original-article-buffer)))
11623         (setq file (gnus-article-save save-buffer file num))
11624         (gnus-summary-remove-process-mark article)
11625         (unless not-saved
11626           (gnus-summary-set-saved-mark article)))
11627       (when saver2
11628         (setq gnus-default-article-saver saver2
11629               saver2 nil)))
11630     (gnus-kill-buffer save-buffer)
11631     (gnus-summary-position-point)
11632     (gnus-set-mode-line 'summary)
11633     n))
11634
11635 (defun gnus-summary-pipe-output (&optional arg headers)
11636   "Pipe the current article to a subprocess.
11637 If N is a positive number, pipe the N next articles.
11638 If N is a negative number, pipe the N previous articles.
11639 If N is nil and any articles have been marked with the process mark,
11640 pipe those articles instead.
11641 If HEADERS (the symbolic prefix), include the headers, too."
11642   (interactive (gnus-interactive "P\ny"))
11643   (require 'gnus-art)
11644   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11645         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11646     (gnus-summary-save-article arg t))
11647   (let ((buffer (get-buffer "*Shell Command Output*")))
11648     (when (and buffer
11649                (not (zerop (buffer-size buffer))))
11650       (gnus-configure-windows 'pipe))))
11651
11652 (defun gnus-summary-save-article-mail (&optional arg)
11653   "Append the current article to a Unix mail box file.
11654 If N is a positive number, save the N next articles.
11655 If N is a negative number, save the N previous articles.
11656 If N is nil and any articles have been marked with the process mark,
11657 save those articles instead."
11658   (interactive "P")
11659   (require 'gnus-art)
11660   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11661     (gnus-summary-save-article arg)))
11662
11663 (defun gnus-summary-save-article-rmail (&optional arg)
11664   "Append the current article to an rmail file.
11665 If N is a positive number, save the N next articles.
11666 If N is a negative number, save the N previous articles.
11667 If N is nil and any articles have been marked with the process mark,
11668 save those articles instead."
11669   (interactive "P")
11670   (require 'gnus-art)
11671   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11672     (gnus-summary-save-article arg)))
11673
11674 (defun gnus-summary-save-article-file (&optional arg)
11675   "Append the current article to a file.
11676 If N is a positive number, save the N next articles.
11677 If N is a negative number, save the N previous articles.
11678 If N is nil and any articles have been marked with the process mark,
11679 save those articles instead."
11680   (interactive "P")
11681   (require 'gnus-art)
11682   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11683     (gnus-summary-save-article arg)))
11684
11685 (defun gnus-summary-write-article-file (&optional arg)
11686   "Write the current article to a file, deleting the previous file.
11687 If N is a positive number, save the N next articles.
11688 If N is a negative number, save the N previous articles.
11689 If N is nil and any articles have been marked with the process mark,
11690 save those articles instead."
11691   (interactive "P")
11692   (require 'gnus-art)
11693   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11694     (gnus-summary-save-article arg)))
11695
11696 (defun gnus-summary-save-article-body-file (&optional arg)
11697   "Append the current article body to a file.
11698 If N is a positive number, save the N next articles.
11699 If N is a negative number, save the N previous articles.
11700 If N is nil and any articles have been marked with the process mark,
11701 save those articles instead."
11702   (interactive "P")
11703   (require 'gnus-art)
11704   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11705     (gnus-summary-save-article arg)))
11706
11707 (defun gnus-summary-write-article-body-file (&optional arg)
11708   "Write the current article body to a file, deleting the previous file.
11709 If N is a positive number, save the N next articles.
11710 If N is a negative number, save the N previous articles.
11711 If N is nil and any articles have been marked with the process mark,
11712 save those articles instead."
11713   (interactive "P")
11714   (require 'gnus-art)
11715   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11716     (gnus-summary-save-article arg)))
11717
11718 (defun gnus-summary-muttprint (&optional arg)
11719   "Print the current article using Muttprint.
11720 If N is a positive number, save the N next articles.
11721 If N is a negative number, save the N previous articles.
11722 If N is nil and any articles have been marked with the process mark,
11723 save those articles instead."
11724   (interactive "P")
11725   (require 'gnus-art)
11726   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11727     (gnus-summary-save-article arg t)))
11728
11729 (defun gnus-summary-pipe-message (program)
11730   "Pipe the current article through PROGRAM."
11731   (interactive "sProgram: ")
11732   (gnus-summary-select-article)
11733   (let ((mail-header-separator ""))
11734     (gnus-eval-in-buffer-window gnus-article-buffer
11735       (save-restriction
11736         (widen)
11737         (let ((start (window-start))
11738               buffer-read-only)
11739           (message-pipe-buffer-body program)
11740           (set-window-start (get-buffer-window (current-buffer)) start))))))
11741
11742 (defun gnus-get-split-value (methods)
11743   "Return a value based on the split METHODS."
11744   (let (split-name method result match)
11745     (when methods
11746       (save-excursion
11747         (set-buffer gnus-original-article-buffer)
11748         (save-restriction
11749           (nnheader-narrow-to-headers)
11750           (while (and methods (not split-name))
11751             (goto-char (point-min))
11752             (setq method (pop methods))
11753             (setq match (car method))
11754             (when (cond
11755                    ((stringp match)
11756                     ;; Regular expression.
11757                     (ignore-errors
11758                       (re-search-forward match nil t)))
11759                    ((functionp match)
11760                     ;; Function.
11761                     (save-restriction
11762                       (widen)
11763                       (setq result (funcall match gnus-newsgroup-name))))
11764                    ((consp match)
11765                     ;; Form.
11766                     (save-restriction
11767                       (widen)
11768                       (setq result (eval match)))))
11769               (setq split-name (cdr method))
11770               (cond ((stringp result)
11771                      (push (expand-file-name
11772                             result gnus-article-save-directory)
11773                            split-name))
11774                     ((consp result)
11775                      (setq split-name (append result split-name)))))))))
11776     (nreverse split-name)))
11777
11778 (defun gnus-valid-move-group-p (group)
11779   (and (boundp group)
11780        (symbol-name group)
11781        (symbol-value group)
11782        (gnus-get-function (gnus-find-method-for-group
11783                            (symbol-name group)) 'request-accept-article t)))
11784
11785 (defun gnus-read-move-group-name (prompt default articles prefix)
11786   "Read a group name."
11787   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11788          (minibuffer-confirm-incomplete nil) ; XEmacs
11789          (prom
11790           (format "%s %s to"
11791                   prompt
11792                   (if (> (length articles) 1)
11793                       (format "these %d articles" (length articles))
11794                     "this article")))
11795          (to-newsgroup
11796           (let (active group)
11797             (when (or (null split-name) (= 1 (length split-name)))
11798               (setq active (gnus-make-hashtable (length gnus-active-hashtb)))
11799               (mapatoms (lambda (symbol)
11800                           (setq group (symbol-name symbol))
11801                           (when (string-match "[^\000-\177]" group)
11802                             (setq group (gnus-group-decoded-name group)))
11803                           (set (intern group active) group))
11804                         gnus-active-hashtb))
11805             (cond
11806              ((null split-name)
11807               (gnus-completing-read-with-default
11808                default prom active 'gnus-valid-move-group-p nil prefix
11809                'gnus-group-history))
11810              ((= 1 (length split-name))
11811               (gnus-completing-read-with-default
11812                (car split-name) prom active 'gnus-valid-move-group-p nil nil
11813                'gnus-group-history))
11814              (t
11815               (gnus-completing-read-with-default
11816                nil prom (mapcar 'list (nreverse split-name)) nil nil nil
11817                'gnus-group-history)))))
11818          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
11819          encoded)
11820     (when to-newsgroup
11821       (if (or (string= to-newsgroup "")
11822               (string= to-newsgroup prefix))
11823           (setq to-newsgroup default))
11824       (unless to-newsgroup
11825         (error "No group name entered"))
11826       (setq encoded (mm-encode-coding-string
11827                      to-newsgroup
11828                      (gnus-group-name-charset to-method to-newsgroup)))
11829       (or (gnus-active encoded)
11830           (gnus-activate-group encoded nil nil to-method)
11831           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11832                                      to-newsgroup))
11833               (or (and (gnus-request-create-group encoded to-method)
11834                        (gnus-activate-group encoded nil nil to-method)
11835                        (gnus-subscribe-group encoded))
11836                   (error "Couldn't create group %s" to-newsgroup)))
11837           (error "No such group: %s" to-newsgroup))
11838       encoded)))
11839
11840 (defvar gnus-summary-save-parts-counter)
11841 (declare-function mm-uu-dissect "mm-uu" (&optional noheader mime-type))
11842
11843 (defun gnus-summary-save-parts (type dir n &optional reverse)
11844   "Save parts matching TYPE to DIR.
11845 If REVERSE, save parts that do not match TYPE."
11846   (interactive
11847    (list (read-string "Save parts of type: "
11848                       (or (car gnus-summary-save-parts-type-history)
11849                           gnus-summary-save-parts-default-mime)
11850                       'gnus-summary-save-parts-type-history)
11851          (setq gnus-summary-save-parts-last-directory
11852                (read-file-name "Save to directory: "
11853                                gnus-summary-save-parts-last-directory
11854                                nil t))
11855          current-prefix-arg))
11856   (gnus-summary-iterate n
11857     (let ((gnus-display-mime-function nil)
11858           (gnus-inhibit-treatment t))
11859       (gnus-summary-select-article))
11860     (save-excursion
11861       (set-buffer gnus-article-buffer)
11862       (let ((handles (or gnus-article-mime-handles
11863                          (mm-dissect-buffer nil gnus-article-loose-mime)
11864                          (and gnus-article-emulate-mime
11865                               (mm-uu-dissect))))
11866             (gnus-summary-save-parts-counter 1))
11867         (when handles
11868           (gnus-summary-save-parts-1 type dir handles reverse)
11869           (unless gnus-article-mime-handles ;; Don't destroy this case.
11870             (mm-destroy-parts handles)))))))
11871
11872 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11873   (if (stringp (car handle))
11874       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11875               (cdr handle))
11876     (when (if reverse
11877               (not (string-match type (mm-handle-media-type handle)))
11878             (string-match type (mm-handle-media-type handle)))
11879       (let ((file (expand-file-name
11880                    (gnus-map-function
11881                     mm-file-name-rewrite-functions
11882                     (file-name-nondirectory
11883                      (or
11884                       (mail-content-type-get
11885                        (mm-handle-disposition handle) 'filename)
11886                       (mail-content-type-get
11887                        (mm-handle-type handle) 'name)
11888                       (format "%s.%d.%d" gnus-newsgroup-name
11889                               (cdr gnus-article-current)
11890                               gnus-summary-save-parts-counter))))
11891                    dir)))
11892         (incf gnus-summary-save-parts-counter)
11893         (unless (file-exists-p file)
11894           (mm-save-part-to-file handle file))))))
11895
11896 ;; Summary extract commands
11897
11898 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11899   (let ((buffer-read-only nil)
11900         (article (gnus-summary-article-number))
11901         after-article b e)
11902     (unless (gnus-summary-goto-subject article)
11903       (error "No such article: %d" article))
11904     (gnus-summary-position-point)
11905     ;; If all commands are to be bunched up on one line, we collect
11906     ;; them here.
11907     (unless gnus-view-pseudos-separately
11908       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11909             files action)
11910         (while ps
11911           (setq action (cdr (assq 'action (car ps))))
11912           (setq files (list (cdr (assq 'name (car ps)))))
11913           (while (and ps (cdr ps)
11914                       (string= (or action "1")
11915                                (or (cdr (assq 'action (cadr ps))) "2")))
11916             (push (cdr (assq 'name (cadr ps))) files)
11917             (setcdr ps (cddr ps)))
11918           (when files
11919             (when (not (string-match "%s" action))
11920               (push " " files))
11921             (push " " files)
11922             (when (assq 'execute (car ps))
11923               (setcdr (assq 'execute (car ps))
11924                       (funcall (if (string-match "%s" action)
11925                                    'format 'concat)
11926                                action
11927                                (mapconcat
11928                                 (lambda (f)
11929                                   (if (equal f " ")
11930                                       f
11931                                     (shell-quote-argument f)))
11932                                 files " ")))))
11933           (setq ps (cdr ps)))))
11934     (if (and gnus-view-pseudos (not not-view))
11935         (while pslist
11936           (when (assq 'execute (car pslist))
11937             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11938                                   (eq gnus-view-pseudos 'not-confirm)))
11939           (setq pslist (cdr pslist)))
11940       (save-excursion
11941         (while pslist
11942           (setq after-article (or (cdr (assq 'article (car pslist)))
11943                                   (gnus-summary-article-number)))
11944           (gnus-summary-goto-subject after-article)
11945           (forward-line 1)
11946           (setq b (point))
11947           (insert "    " (file-name-nondirectory
11948                           (cdr (assq 'name (car pslist))))
11949                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11950           (setq e (point))
11951           (forward-line -1)             ; back to `b'
11952           (gnus-add-text-properties
11953            b (1- e) (list 'gnus-number gnus-reffed-article-number
11954                           gnus-mouse-face-prop gnus-mouse-face))
11955           (gnus-data-enter
11956            after-article gnus-reffed-article-number
11957            gnus-unread-mark b (car pslist) 0 (- e b))
11958           (setq gnus-newsgroup-unreads
11959                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11960                                          gnus-reffed-article-number))
11961           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11962           (setq pslist (cdr pslist)))))))
11963
11964 (defun gnus-pseudos< (p1 p2)
11965   (let ((c1 (cdr (assq 'action p1)))
11966         (c2 (cdr (assq 'action p2))))
11967     (and c1 c2 (string< c1 c2))))
11968
11969 (defun gnus-request-pseudo-article (props)
11970   (cond ((assq 'execute props)
11971          (gnus-execute-command (cdr (assq 'execute props)))))
11972   (let ((gnus-current-article (gnus-summary-article-number)))
11973     (gnus-run-hooks 'gnus-mark-article-hook)))
11974
11975 (defun gnus-execute-command (command &optional automatic)
11976   (save-excursion
11977     (gnus-article-setup-buffer)
11978     (set-buffer gnus-article-buffer)
11979     (setq buffer-read-only nil)
11980     (let ((command (if automatic command
11981                      (read-string "Command: " (cons command 0)))))
11982       (erase-buffer)
11983       (insert "$ " command "\n\n")
11984       (if gnus-view-pseudo-asynchronously
11985           (start-process "gnus-execute" (current-buffer) shell-file-name
11986                          shell-command-switch command)
11987         (call-process shell-file-name nil t nil
11988                       shell-command-switch command)))))
11989
11990 ;; Summary kill commands.
11991
11992 (defun gnus-summary-edit-global-kill (article)
11993   "Edit the \"global\" kill file."
11994   (interactive (list (gnus-summary-article-number)))
11995   (gnus-group-edit-global-kill article))
11996
11997 (defun gnus-summary-edit-local-kill ()
11998   "Edit a local kill file applied to the current newsgroup."
11999   (interactive)
12000   (setq gnus-current-headers (gnus-summary-article-header))
12001   (gnus-group-edit-local-kill
12002    (gnus-summary-article-number) gnus-newsgroup-name))
12003
12004 ;;; Header reading.
12005
12006 (defun gnus-read-header (id &optional header)
12007   "Read the headers of article ID and enter them into the Gnus system."
12008   (let ((group gnus-newsgroup-name)
12009         (gnus-override-method
12010          (or
12011           gnus-override-method
12012           (and (gnus-news-group-p gnus-newsgroup-name)
12013                (car (gnus-refer-article-methods)))))
12014         where)
12015     ;; First we check to see whether the header in question is already
12016     ;; fetched.
12017     (if (stringp id)
12018         ;; This is a Message-ID.
12019         (setq header (or header (gnus-id-to-header id)))
12020       ;; This is an article number.
12021       (setq header (or header (gnus-summary-article-header id))))
12022     (if (and header
12023              (not (gnus-summary-article-sparse-p (mail-header-number header))))
12024         ;; We have found the header.
12025         header
12026       ;; We have to really fetch the header to this article.
12027       (save-excursion
12028         (set-buffer nntp-server-buffer)
12029         (when (setq where (gnus-request-head id group))
12030           (nnheader-fold-continuation-lines)
12031           (goto-char (point-max))
12032           (insert ".\n")
12033           (goto-char (point-min))
12034           (insert "211 ")
12035           (princ (cond
12036                   ((numberp id) id)
12037                   ((cdr where) (cdr where))
12038                   (header (mail-header-number header))
12039                   (t gnus-reffed-article-number))
12040                  (current-buffer))
12041           (insert " Article retrieved.\n"))
12042         (if (or (not where)
12043                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
12044             ()                          ; Malformed head.
12045           (unless (gnus-summary-article-sparse-p (mail-header-number header))
12046             (when (and (stringp id)
12047                        (or
12048                         (not (string= (gnus-group-real-name group)
12049                                       (car where)))
12050                         (not (gnus-server-equal gnus-override-method
12051                                                 (gnus-group-method group)))))
12052               ;; If we fetched by Message-ID and the article came from
12053               ;; a different group (or server), we fudge some bogus
12054               ;; article numbers for this article.
12055               (mail-header-set-number header gnus-reffed-article-number))
12056             (save-excursion
12057               (set-buffer gnus-summary-buffer)
12058               (decf gnus-reffed-article-number)
12059               (gnus-remove-header (mail-header-number header))
12060               (push header gnus-newsgroup-headers)
12061               (setq gnus-current-headers header)
12062               (push (mail-header-number header) gnus-newsgroup-limit)))
12063           header)))))
12064
12065 (defun gnus-remove-header (number)
12066   "Remove header NUMBER from `gnus-newsgroup-headers'."
12067   (if (and gnus-newsgroup-headers
12068            (= number (mail-header-number (car gnus-newsgroup-headers))))
12069       (pop gnus-newsgroup-headers)
12070     (let ((headers gnus-newsgroup-headers))
12071       (while (and (cdr headers)
12072                   (not (= number (mail-header-number (cadr headers)))))
12073         (pop headers))
12074       (when (cdr headers)
12075         (setcdr headers (cddr headers))))))
12076
12077 ;;;
12078 ;;; summary highlights
12079 ;;;
12080
12081 (defun gnus-highlight-selected-summary ()
12082   "Highlight selected article in summary buffer."
12083   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12084   (when gnus-summary-selected-face
12085     (save-excursion
12086       (let* ((beg (point-at-bol))
12087              (end (point-at-eol))
12088              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12089              (from (if (get-text-property beg gnus-mouse-face-prop)
12090                        beg
12091                      (or (next-single-property-change
12092                           beg gnus-mouse-face-prop nil end)
12093                          beg)))
12094              (to
12095               (if (= from end)
12096                   (- from 2)
12097                 (or (next-single-property-change
12098                      from gnus-mouse-face-prop nil end)
12099                     end))))
12100         ;; If no mouse-face prop on line we will have to = from = end,
12101         ;; so we highlight the entire line instead.
12102         (when (= (+ to 2) from)
12103           (setq from beg)
12104           (setq to end))
12105         (if gnus-newsgroup-selected-overlay
12106             ;; Move old overlay.
12107             (gnus-move-overlay
12108              gnus-newsgroup-selected-overlay from to (current-buffer))
12109           ;; Create new overlay.
12110           (gnus-overlay-put
12111            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12112            'face gnus-summary-selected-face))))))
12113
12114 (defvar gnus-summary-highlight-line-cached nil)
12115 (defvar gnus-summary-highlight-line-trigger nil)
12116
12117 (defun gnus-summary-highlight-line-0 ()
12118   (if (and (eq gnus-summary-highlight-line-trigger
12119                gnus-summary-highlight)
12120            gnus-summary-highlight-line-cached)
12121       gnus-summary-highlight-line-cached
12122     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12123           gnus-summary-highlight-line-cached
12124           (let* ((cond (list 'cond))
12125                  (c cond)
12126                  (list gnus-summary-highlight))
12127             (while list
12128               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12129                               nil))
12130               (setq c (cdr c)
12131                     list (cdr list)))
12132             (gnus-byte-compile (list 'lambda nil cond))))))
12133
12134 (defun gnus-summary-highlight-line ()
12135   "Highlight current line according to `gnus-summary-highlight'."
12136   (let* ((beg (point-at-bol))
12137          (article (or (gnus-summary-article-number) gnus-current-article))
12138          (score (or (cdr (assq article
12139                                gnus-newsgroup-scored))
12140                     gnus-summary-default-score 0))
12141          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12142          (inhibit-read-only t)
12143          (default gnus-summary-default-score)
12144          (default-high gnus-summary-default-high-score)
12145          (default-low gnus-summary-default-low-score)
12146          (uncached (and gnus-summary-use-undownloaded-faces
12147                         (memq article gnus-newsgroup-undownloaded)
12148                         (not (memq article gnus-newsgroup-cached)))))
12149     (let ((face (funcall (gnus-summary-highlight-line-0))))
12150       (unless (eq face (get-text-property beg 'face))
12151         (gnus-put-text-property-excluding-characters-with-faces
12152          beg (point-at-eol) 'face
12153          (setq face (if (boundp face) (symbol-value face) face)))
12154         (when gnus-summary-highlight-line-function
12155           (funcall gnus-summary-highlight-line-function article face))))))
12156
12157 (defun gnus-update-read-articles (group unread &optional compute)
12158   "Update the list of read articles in GROUP.
12159 UNREAD is a sorted list."
12160   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12161         (info (gnus-get-info group))
12162         (prev 1)
12163         read)
12164     (if (or (not info) (not active))
12165         ;; There is no info on this group if it was, in fact,
12166         ;; killed.  Gnus stores no information on killed groups, so
12167         ;; there's nothing to be done.
12168         ;; One could store the information somewhere temporarily,
12169         ;; perhaps...  Hmmm...
12170         ()
12171       ;; Remove any negative articles numbers.
12172       (while (and unread (< (car unread) 0))
12173         (setq unread (cdr unread)))
12174       ;; Remove any expired article numbers
12175       (while (and unread (< (car unread) (car active)))
12176         (setq unread (cdr unread)))
12177       ;; Compute the ranges of read articles by looking at the list of
12178       ;; unread articles.
12179       (while unread
12180         (when (/= (car unread) prev)
12181           (push (if (= prev (1- (car unread))) prev
12182                   (cons prev (1- (car unread))))
12183                 read))
12184         (setq prev (1+ (car unread)))
12185         (setq unread (cdr unread)))
12186       (when (<= prev (cdr active))
12187         (push (cons prev (cdr active)) read))
12188       (setq read (if (> (length read) 1) (nreverse read) read))
12189       (if compute
12190           read
12191         (save-excursion
12192           (let (setmarkundo)
12193             ;; Propagate the read marks to the backend.
12194             (when (gnus-check-backend-function 'request-set-mark group)
12195               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12196                     (add (gnus-remove-from-range read (gnus-info-read info))))
12197                 (when (or add del)
12198                   (unless (gnus-check-group group)
12199                     (error "Can't open server for %s" group))
12200                   (gnus-request-set-mark
12201                    group (delq nil (list (if add (list add 'add '(read)))
12202                                          (if del (list del 'del '(read))))))
12203                   (setq setmarkundo
12204                         `(gnus-request-set-mark
12205                           ,group
12206                           ',(delq nil (list
12207                                        (if del (list del 'add '(read)))
12208                                        (if add (list add 'del '(read))))))))))
12209             (set-buffer gnus-group-buffer)
12210             (gnus-undo-register
12211               `(progn
12212                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12213                  (gnus-info-set-read ',info ',(gnus-info-read info))
12214                  (gnus-get-unread-articles-in-group ',info
12215                                                     (gnus-active ,group))
12216                  (gnus-group-update-group ,group t)
12217                  ,setmarkundo))))
12218         ;; Enter this list into the group info.
12219         (gnus-info-set-read info read)
12220         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12221         (gnus-get-unread-articles-in-group info (gnus-active group))
12222         t))))
12223
12224 (defun gnus-offer-save-summaries ()
12225   "Offer to save all active summary buffers."
12226   (let (buffers)
12227     ;; Go through all buffers and find all summaries.
12228     (dolist (buffer (buffer-list))
12229       (when (and (setq buffer (buffer-name buffer))
12230                  (string-match "Summary" buffer)
12231                  (with-current-buffer buffer
12232                    ;; We check that this is, indeed, a summary buffer.
12233                    (and (eq major-mode 'gnus-summary-mode)
12234                         ;; Also make sure this isn't bogus.
12235                         gnus-newsgroup-prepared
12236                         ;; Also make sure that this isn't a
12237                         ;; dead summary buffer.
12238                         (not gnus-dead-summary-mode))))
12239         (push buffer buffers)))
12240     ;; Go through all these summary buffers and offer to save them.
12241     (when buffers
12242       (save-excursion
12243         (map-y-or-n-p
12244          "Update summary buffer %s? "
12245          (lambda (buf)
12246            (switch-to-buffer buf)
12247            (gnus-summary-exit))
12248          buffers)))))
12249
12250 (defun gnus-summary-setup-default-charset ()
12251   "Setup newsgroup default charset."
12252   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12253       (setq gnus-newsgroup-charset nil)
12254     (let* ((ignored-charsets
12255             (or gnus-newsgroup-ephemeral-ignored-charsets
12256                 (append
12257                  (and gnus-newsgroup-name
12258                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12259                  gnus-newsgroup-ignored-charsets))))
12260       (setq gnus-newsgroup-charset
12261             (or gnus-newsgroup-ephemeral-charset
12262                 (and gnus-newsgroup-name
12263                      (gnus-parameter-charset gnus-newsgroup-name))
12264                 gnus-default-charset))
12265       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12266            ignored-charsets))))
12267
12268 ;;;
12269 ;;; Mime Commands
12270 ;;;
12271
12272 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12273   "Display the current article buffer fully MIME-buttonized.
12274 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12275 treated as multipart/mixed."
12276   (interactive "P")
12277   (require 'gnus-art)
12278   (let ((gnus-unbuttonized-mime-types nil)
12279         (gnus-mime-display-multipart-as-mixed show-all-parts))
12280     (gnus-summary-show-article)))
12281
12282 (defun gnus-summary-repair-multipart (article)
12283   "Add a Content-Type header to a multipart article without one."
12284   (interactive (list (gnus-summary-article-number)))
12285   (gnus-with-article article
12286     (message-narrow-to-head)
12287     (message-remove-header "Mime-Version")
12288     (goto-char (point-max))
12289     (insert "Mime-Version: 1.0\n")
12290     (widen)
12291     (when (search-forward "\n--" nil t)
12292       (let ((separator (buffer-substring (point) (point-at-eol))))
12293         (message-narrow-to-head)
12294         (message-remove-header "Content-Type")
12295         (goto-char (point-max))
12296         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12297                         separator))
12298         (widen))))
12299   (let (gnus-mark-article-hook)
12300     (gnus-summary-select-article t t nil article)))
12301
12302 (defun gnus-summary-toggle-display-buttonized ()
12303   "Toggle the buttonizing of the article buffer."
12304   (interactive)
12305   (require 'gnus-art)
12306   (if (setq gnus-inhibit-mime-unbuttonizing
12307             (not gnus-inhibit-mime-unbuttonizing))
12308       (let ((gnus-unbuttonized-mime-types nil))
12309         (gnus-summary-show-article))
12310     (gnus-summary-show-article)))
12311
12312 ;;;
12313 ;;; Generic summary marking commands
12314 ;;;
12315
12316 (defvar gnus-summary-marking-alist
12317   '((read gnus-del-mark "d")
12318     (unread gnus-unread-mark "u")
12319     (ticked gnus-ticked-mark "!")
12320     (dormant gnus-dormant-mark "?")
12321     (expirable gnus-expirable-mark "e"))
12322   "An alist of names/marks/keystrokes.")
12323
12324 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12325 (defvar gnus-summary-mark-map)
12326
12327 (defun gnus-summary-make-all-marking-commands ()
12328   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12329   (dolist (elem gnus-summary-marking-alist)
12330     (apply 'gnus-summary-make-marking-command elem)))
12331
12332 (defun gnus-summary-make-marking-command (name mark keystroke)
12333   (let ((map (make-sparse-keymap)))
12334     (define-key gnus-summary-generic-mark-map keystroke map)
12335     (dolist (lway `((next "next" next nil "n")
12336                     (next-unread "next unread" next t "N")
12337                     (prev "previous" prev nil "p")
12338                     (prev-unread "previous unread" prev t "P")
12339                     (nomove "" nil nil ,keystroke)))
12340       (let ((func (gnus-summary-make-marking-command-1
12341                    mark (car lway) lway name)))
12342         (setq func (eval func))
12343         (define-key map (nth 4 lway) func)))))
12344
12345 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12346   `(defun ,(intern
12347             (format "gnus-summary-put-mark-as-%s%s"
12348                     name (if (eq way 'nomove)
12349                              ""
12350                            (concat "-" (symbol-name way)))))
12351      (n)
12352      ,(format
12353        "Mark the current article as %s%s.
12354 If N, the prefix, then repeat N times.
12355 If N is negative, move in reverse order.
12356 The difference between N and the actual number of articles marked is
12357 returned."
12358        name (cadr lway))
12359      (interactive "p")
12360      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12361
12362 (defun gnus-summary-generic-mark (n mark move unread)
12363   "Mark N articles with MARK."
12364   (unless (eq major-mode 'gnus-summary-mode)
12365     (error "This command can only be used in the summary buffer"))
12366   (gnus-summary-show-thread)
12367   (let ((nummove
12368          (cond
12369           ((eq move 'next) 1)
12370           ((eq move 'prev) -1)
12371           (t 0))))
12372     (if (zerop nummove)
12373         (setq n 1)
12374       (when (< n 0)
12375         (setq n (abs n)
12376               nummove (* -1 nummove))))
12377     (while (and (> n 0)
12378                 (gnus-summary-mark-article nil mark)
12379                 (zerop (gnus-summary-next-subject nummove unread t)))
12380       (setq n (1- n)))
12381     (when (/= 0 n)
12382       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12383     (gnus-summary-recenter)
12384     (gnus-summary-position-point)
12385     (gnus-set-mode-line 'summary)
12386     n))
12387
12388 (defun gnus-summary-insert-articles (articles)
12389   (when (setq articles
12390               (gnus-sorted-difference articles
12391                                       (mapcar (lambda (h)
12392                                                 (mail-header-number h))
12393                                               gnus-newsgroup-headers)))
12394     (setq gnus-newsgroup-headers
12395           (gnus-merge 'list
12396                       gnus-newsgroup-headers
12397                       (gnus-fetch-headers articles)
12398                       'gnus-article-sort-by-number))
12399     ;; Suppress duplicates?
12400     (when gnus-suppress-duplicates
12401       (gnus-dup-suppress-articles))
12402
12403     (if (and gnus-fetch-old-headers
12404              (eq gnus-headers-retrieved-by 'nov))
12405         ;; We might want to build some more threads first.
12406         (if (eq gnus-fetch-old-headers 'invisible)
12407             (gnus-build-all-threads)
12408           (gnus-build-old-threads))
12409       ;; Mark the inserted articles that are unread as unread.
12410       (setq gnus-newsgroup-unreads
12411             (gnus-sorted-nunion
12412              gnus-newsgroup-unreads
12413              (gnus-sorted-nintersection
12414               (gnus-list-of-unread-articles gnus-newsgroup-name)
12415               articles)))
12416       ;; Mark the inserted articles as selected so that the information
12417       ;; of the marks having been changed by a user may be updated when
12418       ;; exiting this group.  See `gnus-summary-update-info'.
12419       (dolist (art articles)
12420         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12421     ;; Let the Gnus agent mark articles as read.
12422     (when gnus-agent
12423       (gnus-agent-get-undownloaded-list))
12424     ;; Remove list identifiers from subject
12425     (when gnus-list-identifiers
12426       (gnus-summary-remove-list-identifiers))
12427     ;; First and last article in this newsgroup.
12428     (when gnus-newsgroup-headers
12429       (setq gnus-newsgroup-begin
12430             (mail-header-number (car gnus-newsgroup-headers))
12431             gnus-newsgroup-end
12432             (mail-header-number
12433              (gnus-last-element gnus-newsgroup-headers))))
12434     (when gnus-use-scoring
12435       (gnus-possibly-score-headers))))
12436
12437 (defun gnus-summary-insert-old-articles (&optional all)
12438   "Insert all old articles in this group.
12439 If ALL is non-nil, already read articles become readable.
12440 If ALL is a number, fetch this number of articles."
12441   (interactive "P")
12442   (prog1
12443       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12444             older len)
12445         (setq older
12446               ;; Some nntp servers lie about their active range.  When
12447               ;; this happens, the active range can be in the millions.
12448               ;; Use a compressed range to avoid creating a huge list.
12449               (gnus-range-difference (list gnus-newsgroup-active) old))
12450         (setq len (gnus-range-length older))
12451         (cond
12452          ((null older) nil)
12453          ((numberp all)
12454           (if (< all len)
12455               (let ((older-range (nreverse older)))
12456                 (setq older nil)
12457
12458                 (while (> all 0)
12459                   (let* ((r (pop older-range))
12460                          (min (if (numberp r) r (car r)))
12461                          (max (if (numberp r) r (cdr r))))
12462                     (while (and (<= min max)
12463                                 (> all 0))
12464                       (push max older)
12465                       (setq all (1- all)
12466                             max (1- max))))))
12467             (setq older (gnus-uncompress-range older))))
12468          (all
12469           (setq older (gnus-uncompress-range older)))
12470          (t
12471           (when (and (numberp gnus-large-newsgroup)
12472                    (> len gnus-large-newsgroup))
12473               (let* ((cursor-in-echo-area nil)
12474                      (initial (gnus-parameter-large-newsgroup-initial
12475                                gnus-newsgroup-name))
12476                      (input
12477                       (read-string
12478                        (format
12479                         "How many articles from %s (%s %d): "
12480                         (gnus-group-decoded-name gnus-newsgroup-name)
12481                         (if initial "max" "default")
12482                         len)
12483                        (if initial
12484                            (cons (number-to-string initial)
12485                                  0)))))
12486                 (unless (string-match "^[ \t]*$" input)
12487                   (setq all (string-to-number input))
12488                   (if (< all len)
12489                       (let ((older-range (nreverse older)))
12490                         (setq older nil)
12491
12492                         (while (> all 0)
12493                           (let* ((r (pop older-range))
12494                                  (min (if (numberp r) r (car r)))
12495                                  (max (if (numberp r) r (cdr r))))
12496                             (while (and (<= min max)
12497                                         (> all 0))
12498                               (push max older)
12499                               (setq all (1- all)
12500                                     max (1- max))))))))))
12501           (setq older (gnus-uncompress-range older))))
12502         (if (not older)
12503             (message "No old news.")
12504           (gnus-summary-insert-articles older)
12505           (gnus-summary-limit (gnus-sorted-nunion old older))))
12506     (gnus-summary-position-point)))
12507
12508 (defun gnus-summary-insert-new-articles ()
12509   "Insert all new articles in this group."
12510   (interactive)
12511   (prog1
12512       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12513             (old-active gnus-newsgroup-active)
12514             (nnmail-fetched-sources (list t))
12515             i new)
12516         (setq gnus-newsgroup-active
12517               (gnus-activate-group gnus-newsgroup-name 'scan))
12518         (setq i (cdr gnus-newsgroup-active))
12519         (while (> i (cdr old-active))
12520           (push i new)
12521           (decf i))
12522         (if (not new)
12523             (message "No gnus is bad news")
12524           (gnus-summary-insert-articles new)
12525           (setq gnus-newsgroup-unreads
12526                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12527           (gnus-summary-limit (gnus-sorted-nunion old new))))
12528     (gnus-summary-position-point)))
12529
12530 (gnus-summary-make-all-marking-commands)
12531
12532 (gnus-ems-redefine)
12533
12534 (provide 'gnus-sum)
12535
12536 (run-hooks 'gnus-sum-load-hook)
12537
12538 ;; Local Variables:
12539 ;; coding: iso-8859-1
12540 ;; End:
12541
12542 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12543 ;;; gnus-sum.el ends here