* gnus-agent.el (gnus-agent-group-pathname): Take notice of the method.
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-mode))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'gmm-utils)
42 (require 'mm-decode)
43 (require 'nnoo)
44
45 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
46 (autoload 'gnus-cache-write-active "gnus-cache")
47 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
48 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
49 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
50 (autoload 'mm-uu-dissect "mm-uu")
51 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
52   "Deuglify broken Outlook (Express) articles and redisplay."
53   t)
54 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
55 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
56 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
57
58 (defcustom gnus-kill-summary-on-exit t
59   "*If non-nil, kill the summary buffer when you exit from it.
60 If nil, the summary will become a \"*Dead Summary*\" buffer, and
61 it will be killed sometime later."
62   :group 'gnus-summary-exit
63   :type 'boolean)
64
65 (defcustom gnus-summary-next-group-on-exit t
66   "If non-nil, go to the next unread newsgroup on summary exit.
67 See `gnus-group-goto-unread'."
68   :link '(custom-manual "(gnus)Group Maneuvering")
69   :group 'gnus-summary-exit
70   :version "23.0" ;; No Gnus
71   :type 'boolean)
72
73 (defcustom gnus-fetch-old-headers nil
74   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
75 If an unread article in the group refers to an older, already
76 read (or just marked as read) article, the old article will not
77 normally be displayed in the Summary buffer.  If this variable is
78 t, Gnus will attempt to grab the headers to the old articles, and
79 thereby build complete threads.  If it has the value `some', all
80 old headers will be fetched but only enough headers to connect
81 otherwise loose threads will be displayed.  This variable can
82 also be a number.  In that case, no more than that number of old
83 headers will be fetched.  If it has the value `invisible', all
84 old headers will be fetched, but none will be displayed.
85
86 The server has to support NOV for any of this to work.
87
88 This feature can seriously impact performance it ignores all
89 locally cached header entries."
90   :group 'gnus-thread
91   :type '(choice (const :tag "off" nil)
92                  (const :tag "on" t)
93                  (const some)
94                  (const invisible)
95                  number
96                  (sexp :menu-tag "other" t)))
97
98 (defcustom gnus-refer-thread-limit 500
99   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
100 If t, fetch all the available old headers."
101   :group 'gnus-thread
102   :type '(choice number
103                  (sexp :menu-tag "other" t)))
104
105 (defcustom gnus-summary-make-false-root 'adopt
106   "*nil means that Gnus won't gather loose threads.
107 If the root of a thread has expired or been read in a previous
108 session, the information necessary to build a complete thread has been
109 lost.  Instead of having many small sub-threads from this original thread
110 scattered all over the summary buffer, Gnus can gather them.
111
112 If non-nil, Gnus will try to gather all loose sub-threads from an
113 original thread into one large thread.
114
115 If this variable is non-nil, it should be one of `none', `adopt',
116 `dummy' or `empty'.
117
118 If this variable is `none', Gnus will not make a false root, but just
119 present the sub-threads after another.
120 If this variable is `dummy', Gnus will create a dummy root that will
121 have all the sub-threads as children.
122 If this variable is `adopt', Gnus will make one of the \"children\"
123 the parent and mark all the step-children as such.
124 If this variable is `empty', the \"children\" are printed with empty
125 subject fields.  (Or rather, they will be printed with a string
126 given by the `gnus-summary-same-subject' variable.)"
127   :group 'gnus-thread
128   :type '(choice (const :tag "off" nil)
129                  (const none)
130                  (const dummy)
131                  (const adopt)
132                  (const empty)))
133
134 (defcustom gnus-summary-make-false-root-always nil
135   "Always make a false dummy root."
136   :version "22.1"
137   :group 'gnus-thread
138   :type 'boolean)
139
140 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
141   "*A regexp to match subjects to be excluded from loose thread gathering.
142 As loose thread gathering is done on subjects only, that means that
143 there can be many false gatherings performed.  By rooting out certain
144 common subjects, gathering might become saner."
145   :group 'gnus-thread
146   :type 'regexp)
147
148 (defcustom gnus-summary-gather-subject-limit nil
149   "*Maximum length of subject comparisons when gathering loose threads.
150 Use nil to compare full subjects.  Setting this variable to a low
151 number will help gather threads that have been corrupted by
152 newsreaders chopping off subject lines, but it might also mean that
153 unrelated articles that have subject that happen to begin with the
154 same few characters will be incorrectly gathered.
155
156 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
157 comparing subjects."
158   :group 'gnus-thread
159   :type '(choice (const :tag "off" nil)
160                  (const fuzzy)
161                  (sexp :menu-tag "on" t)))
162
163 (defcustom gnus-simplify-subject-functions nil
164   "List of functions taking a string argument that simplify subjects.
165 The functions are applied recursively.
166
167 Useful functions to put in this list include:
168 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
169 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
170   :group 'gnus-thread
171   :type '(repeat function))
172
173 (defcustom gnus-simplify-ignored-prefixes nil
174   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
175   :group 'gnus-thread
176   :type '(choice (const :tag "off" nil)
177                  regexp))
178
179 (defcustom gnus-build-sparse-threads nil
180   "*If non-nil, fill in the gaps in threads.
181 If `some', only fill in the gaps that are needed to tie loose threads
182 together.  If `more', fill in all leaf nodes that Gnus can find.  If
183 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
184   :group 'gnus-thread
185   :type '(choice (const :tag "off" nil)
186                  (const some)
187                  (const more)
188                  (sexp :menu-tag "all" t)))
189
190 (defcustom gnus-summary-thread-gathering-function
191   'gnus-gather-threads-by-subject
192   "*Function used for gathering loose threads.
193 There are two pre-defined functions: `gnus-gather-threads-by-subject',
194 which only takes Subjects into consideration; and
195 `gnus-gather-threads-by-references', which compared the References
196 headers of the articles to find matches."
197   :group 'gnus-thread
198   :type '(radio (function-item gnus-gather-threads-by-subject)
199                 (function-item gnus-gather-threads-by-references)
200                 (function :tag "other")))
201
202 (defcustom gnus-summary-same-subject ""
203   "*String indicating that the current article has the same subject as the previous.
204 This variable will only be used if the value of
205 `gnus-summary-make-false-root' is `empty'."
206   :group 'gnus-summary-format
207   :type 'string)
208
209 (defcustom gnus-summary-goto-unread t
210   "*If t, many commands will go to the next unread article.
211 This applies to marking commands as well as other commands that
212 \"naturally\" select the next article, like, for instance, `SPC' at
213 the end of an article.
214
215 If nil, the marking commands do NOT go to the next unread article
216 \(they go to the next article instead).  If `never', commands that
217 usually go to the next unread article, will go to the next article,
218 whether it is read or not."
219   :group 'gnus-summary-marks
220   :link '(custom-manual "(gnus)Setting Marks")
221   :type '(choice (const :tag "off" nil)
222                  (const never)
223                  (sexp :menu-tag "on" t)))
224
225 (defcustom gnus-summary-default-score 0
226   "*Default article score level.
227 All scores generated by the score files will be added to this score.
228 If this variable is nil, scoring will be disabled."
229   :group 'gnus-score-default
230   :type '(choice (const :tag "disable")
231                  integer))
232
233 (defcustom gnus-summary-default-high-score 0
234   "*Default threshold for a high scored article.
235 An article will be highlighted as high scored if its score is greater
236 than this score."
237   :version "22.1"
238   :group 'gnus-score-default
239   :type 'integer)
240
241 (defcustom gnus-summary-default-low-score 0
242   "*Default threshold for a low scored article.
243 An article will be highlighted as low scored if its score is smaller
244 than this score."
245   :version "22.1"
246   :group 'gnus-score-default
247   :type 'integer)
248
249 (defcustom gnus-summary-zcore-fuzz 0
250   "*Fuzziness factor for the zcore in the summary buffer.
251 Articles with scores closer than this to `gnus-summary-default-score'
252 will not be marked."
253   :group 'gnus-summary-format
254   :type 'integer)
255
256 (defcustom gnus-simplify-subject-fuzzy-regexp nil
257   "*Strings to be removed when doing fuzzy matches.
258 This can either be a regular expression or list of regular expressions
259 that will be removed from subject strings if fuzzy subject
260 simplification is selected."
261   :group 'gnus-thread
262   :type '(repeat regexp))
263
264 (defcustom gnus-show-threads t
265   "*If non-nil, display threads in summary mode."
266   :group 'gnus-thread
267   :type 'boolean)
268
269 (defcustom gnus-thread-hide-subtree nil
270   "*If non-nil, hide all threads initially.
271 This can be a predicate specifier which says which threads to hide.
272 If threads are hidden, you have to run the command
273 `gnus-summary-show-thread' by hand or select an article."
274   :group 'gnus-thread
275   :type '(radio (sexp :format "Non-nil\n"
276                       :match (lambda (widget value)
277                                (not (or (consp value) (functionp value))))
278                       :value t)
279                 (const nil)
280                 (sexp :tag "Predicate specifier")))
281
282 (defcustom gnus-thread-hide-killed t
283   "*If non-nil, hide killed threads automatically."
284   :group 'gnus-thread
285   :type 'boolean)
286
287 (defcustom gnus-thread-ignore-subject t
288   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
289 If nil, articles that have different subjects from their parents will
290 start separate threads."
291   :group 'gnus-thread
292   :type 'boolean)
293
294 (defcustom gnus-thread-operation-ignore-subject t
295   "*If non-nil, subjects will be ignored when doing thread commands.
296 This affects commands like `gnus-summary-kill-thread' and
297 `gnus-summary-lower-thread'.
298
299 If this variable is nil, articles in the same thread with different
300 subjects will not be included in the operation in question.  If this
301 variable is `fuzzy', only articles that have subjects that are fuzzily
302 equal will be included."
303   :group 'gnus-thread
304   :type '(choice (const :tag "off" nil)
305                  (const fuzzy)
306                  (sexp :tag "on" t)))
307
308 (defcustom gnus-thread-indent-level 4
309   "*Number that says how much each sub-thread should be indented."
310   :group 'gnus-thread
311   :type 'integer)
312
313 (defcustom gnus-auto-extend-newsgroup t
314   "*If non-nil, extend newsgroup forward and backward when requested."
315   :group 'gnus-summary-choose
316   :type 'boolean)
317
318 (defcustom gnus-auto-select-first t
319   "If non-nil, select an article on group entry.
320 An article is selected automatically when entering a group
321 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
322 `gnus-summary-catchup-and-goto-next-group'.
323
324 Which article is selected is controlled by the variable
325 `gnus-auto-select-subject'.
326
327 If you want to prevent automatic selection of articles in some
328 newsgroups, set the variable to nil in `gnus-select-group-hook'."
329   ;; Commands include...
330   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
331   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
332   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
333   :group 'gnus-group-select
334   :type '(choice (const :tag "none" nil)
335                  (sexp :menu-tag "first" t)))
336
337 (defcustom gnus-auto-select-subject 'unread
338   "*Says what subject to place under point when entering a group.
339
340 This variable can either be the symbols `first' (place point on the
341 first subject), `unread' (place point on the subject line of the first
342 unread article), `best' (place point on the subject line of the
343 higest-scored article), `unseen' (place point on the subject line of
344 the first unseen article), `unseen-or-unread' (place point on the subject
345 line of the first unseen article or, if all article have been seen, on the
346 subject line of the first unread article), or a function to be called to
347 place point on some subject line."
348   :version "22.1"
349   :group 'gnus-group-select
350   :type '(choice (const best)
351                  (const unread)
352                  (const first)
353                  (const unseen)
354                  (const unseen-or-unread)))
355
356 (defcustom gnus-auto-select-next t
357   "*If non-nil, offer to go to the next group from the end of the previous.
358 If the value is t and the next newsgroup is empty, Gnus will exit
359 summary mode and go back to group mode.  If the value is neither nil
360 nor t, Gnus will select the following unread newsgroup.  In
361 particular, if the value is the symbol `quietly', the next unread
362 newsgroup will be selected without any confirmation, and if it is
363 `almost-quietly', the next group will be selected without any
364 confirmation if you are located on the last article in the group.
365 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
366 will go to the next group without confirmation."
367   :group 'gnus-summary-maneuvering
368   :type '(choice (const :tag "off" nil)
369                  (const quietly)
370                  (const almost-quietly)
371                  (const slightly-quietly)
372                  (sexp :menu-tag "on" t)))
373
374 (defcustom gnus-auto-select-same nil
375   "*If non-nil, select the next article with the same subject.
376 If there are no more articles with the same subject, go to
377 the first unread article."
378   :group 'gnus-summary-maneuvering
379   :type 'boolean)
380
381 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
382   "What article should be selected after exiting an ephemeral group.
383 Valid values include:
384
385 `next'
386   Select the next article.
387 `next-unread'
388   Select the next unread article.
389 `next-noselect'
390   Move the cursor to the next article.  This is the default.
391 `next-unread-noselect'
392   Move the cursor to the next unread article.
393
394 If it has any other value or there is no next (unread) article, the
395 article selected before entering to the ephemeral group will appear."
396   :version "23.0" ;; No Gnus
397   :group 'gnus-summary-maneuvering
398   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
399                  (const next) (const next-unread)
400                  (const next-noselect) (const next-unread-noselect)
401                  (sexp :tag "other" :value nil)))
402
403 (defcustom gnus-auto-goto-ignores 'unfetched
404   "*Says how to handle unfetched articles when maneuvering.
405
406 This variable can either be the symbols nil (maneuver to any
407 article), `undownloaded' (maneuvering while unplugged ignores articles
408 that have not been fetched), `always-undownloaded' (maneuvering always
409 ignores articles that have not been fetched), `unfetched' (maneuvering
410 ignores articles whose headers have not been fetched).
411
412 NOTE: The list of unfetched articles will always be nil when plugged
413 and, when unplugged, a subset of the undownloaded article list."
414   :version "22.1"
415   :group 'gnus-summary-maneuvering
416   :type '(choice (const :tag "None" nil)
417                  (const :tag "Undownloaded when unplugged" undownloaded)
418                  (const :tag "Undownloaded" always-undownloaded)
419                  (const :tag "Unfetched" unfetched)))
420
421 (defcustom gnus-summary-check-current nil
422   "*If non-nil, consider the current article when moving.
423 The \"unread\" movement commands will stay on the same line if the
424 current article is unread."
425   :group 'gnus-summary-maneuvering
426   :type 'boolean)
427
428 (defcustom gnus-auto-center-summary 2
429   "*If non-nil, always center the current summary buffer.
430 In particular, if `vertical' do only vertical recentering.  If non-nil
431 and non-`vertical', do both horizontal and vertical recentering."
432   :group 'gnus-summary-maneuvering
433   :type '(choice (const :tag "none" nil)
434                  (const vertical)
435                  (integer :tag "height")
436                  (sexp :menu-tag "both" t)))
437
438 (defvar gnus-auto-center-group t
439   "*If non-nil, always center the group buffer.")
440
441 (defcustom gnus-show-all-headers nil
442   "*If non-nil, don't hide any headers."
443   :group 'gnus-article-hiding
444   :group 'gnus-article-headers
445   :type 'boolean)
446
447 (defcustom gnus-summary-ignore-duplicates nil
448   "*If non-nil, ignore articles with identical Message-ID headers."
449   :group 'gnus-summary
450   :type 'boolean)
451
452 (defcustom gnus-single-article-buffer t
453   "*If non-nil, display all articles in the same buffer.
454 If nil, each group will get its own article buffer."
455   :group 'gnus-article-various
456   :type 'boolean)
457
458 (defcustom gnus-break-pages t
459   "*If non-nil, do page breaking on articles.
460 The page delimiter is specified by the `gnus-page-delimiter'
461 variable."
462   :group 'gnus-article-various
463   :type 'boolean)
464
465 (defcustom gnus-move-split-methods nil
466   "*Variable used to suggest where articles are to be moved to.
467 It uses the same syntax as the `gnus-split-methods' variable.
468 However, whereas `gnus-split-methods' specifies file names as targets,
469 this variable specifies group names."
470   :group 'gnus-summary-mail
471   :type '(repeat (choice (list :value (fun) function)
472                          (cons :value ("" "") regexp (repeat string))
473                          (sexp :value nil))))
474
475 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
476   "Function used to compute default prefix for article move/copy/etc prompts.
477 The function should take one argument, a group name, and return a
478 string with the suggested prefix."
479   :group 'gnus-summary-mail
480   :type 'function)
481
482 ;; FIXME: Although the custom type is `character' for the following variables,
483 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
484
485 (defcustom gnus-unread-mark ?           ;Whitespace
486   "*Mark used for unread articles."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-ticked-mark ?!
491   "*Mark used for ticked articles."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-dormant-mark ??
496   "*Mark used for dormant articles."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-del-mark ?r
501   "*Mark used for del'd articles."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-read-mark ?R
506   "*Mark used for read articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-expirable-mark ?E
511   "*Mark used for expirable articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-killed-mark ?K
516   "*Mark used for killed articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-spam-mark ?$
521   "*Mark used for spam articles."
522   :version "22.1"
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-souped-mark ?F
527   "*Mark used for souped articles."
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-kill-file-mark ?X
532   "*Mark used for articles killed by kill files."
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-low-score-mark ?Y
537   "*Mark used for articles with a low score."
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-catchup-mark ?C
542   "*Mark used for articles that are caught up."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-replied-mark ?A
547   "*Mark used for articles that have been replied to."
548   :group 'gnus-summary-marks
549   :type 'character)
550
551 (defcustom gnus-forwarded-mark ?F
552   "*Mark used for articles that have been forwarded."
553   :version "22.1"
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-recent-mark ?N
558   "*Mark used for articles that are recent."
559   :version "22.1"
560   :group 'gnus-summary-marks
561   :type 'character)
562
563 (defcustom gnus-cached-mark ?*
564   "*Mark used for articles that are in the cache."
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-saved-mark ?S
569   "*Mark used for articles that have been saved."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-unseen-mark ?.
574   "*Mark used for articles that haven't been seen."
575   :version "22.1"
576   :group 'gnus-summary-marks
577   :type 'character)
578
579 (defcustom gnus-no-mark ?               ;Whitespace
580   "*Mark used for articles that have no other secondary mark."
581   :version "22.1"
582   :group 'gnus-summary-marks
583   :type 'character)
584
585 (defcustom gnus-ancient-mark ?O
586   "*Mark used for ancient articles."
587   :group 'gnus-summary-marks
588   :type 'character)
589
590 (defcustom gnus-sparse-mark ?Q
591   "*Mark used for sparsely reffed articles."
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-canceled-mark ?G
596   "*Mark used for canceled articles."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-duplicate-mark ?M
601   "*Mark used for duplicate articles."
602   :group 'gnus-summary-marks
603   :type 'character)
604
605 (defcustom gnus-undownloaded-mark ?-
606   "*Mark used for articles that weren't downloaded."
607   :version "22.1"
608   :group 'gnus-summary-marks
609   :type 'character)
610
611 (defcustom gnus-downloaded-mark ?+
612   "*Mark used for articles that were downloaded."
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-downloadable-mark ?%
617   "*Mark used for articles that are to be downloaded."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-unsendable-mark ?=
622   "*Mark used for articles that won't be sent."
623   :group 'gnus-summary-marks
624   :type 'character)
625
626 (defcustom gnus-score-over-mark ?+
627   "*Score mark used for articles with high scores."
628   :group 'gnus-summary-marks
629   :type 'character)
630
631 (defcustom gnus-score-below-mark ?-
632   "*Score mark used for articles with low scores."
633   :group 'gnus-summary-marks
634   :type 'character)
635
636 (defcustom gnus-empty-thread-mark ?     ;Whitespace
637   "*There is no thread under the article."
638   :group 'gnus-summary-marks
639   :type 'character)
640
641 (defcustom gnus-not-empty-thread-mark ?=
642   "*There is a thread under the article."
643   :group 'gnus-summary-marks
644   :type 'character)
645
646 (defcustom gnus-view-pseudo-asynchronously nil
647   "*If non-nil, Gnus will view pseudo-articles asynchronously."
648   :group 'gnus-extract-view
649   :type 'boolean)
650
651 (defcustom gnus-auto-expirable-marks
652   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
653         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
654         gnus-souped-mark gnus-duplicate-mark)
655   "*The list of marks converted into expiration if a group is auto-expirable."
656   :version "21.1"
657   :group 'gnus-summary
658   :type '(repeat character))
659
660 (defcustom gnus-inhibit-user-auto-expire t
661   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
662   :version "21.1"
663   :group 'gnus-summary
664   :type 'boolean)
665
666 (defcustom gnus-view-pseudos nil
667   "*If `automatic', pseudo-articles will be viewed automatically.
668 If `not-confirm', pseudos will be viewed automatically, and the user
669 will not be asked to confirm the command."
670   :group 'gnus-extract-view
671   :type '(choice (const :tag "off" nil)
672                  (const automatic)
673                  (const not-confirm)))
674
675 (defcustom gnus-view-pseudos-separately t
676   "*If non-nil, one pseudo-article will be created for each file to be viewed.
677 If nil, all files that use the same viewing command will be given as a
678 list of parameters to that command."
679   :group 'gnus-extract-view
680   :type 'boolean)
681
682 (defcustom gnus-insert-pseudo-articles t
683   "*If non-nil, insert pseudo-articles when decoding articles."
684   :group 'gnus-extract-view
685   :type 'boolean)
686
687 (defcustom gnus-summary-dummy-line-format
688   "   %(:                             :%) %S\n"
689   "*The format specification for the dummy roots in the summary buffer.
690 It works along the same lines as a normal formatting string,
691 with some simple extensions.
692
693 %S  The subject
694
695 General format specifiers can also be used.
696 See `(gnus)Formatting Variables'."
697   :link '(custom-manual "(gnus)Formatting Variables")
698   :group 'gnus-threading
699   :type 'string)
700
701 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
702   "*The format specification for the summary mode line.
703 It works along the same lines as a normal formatting string,
704 with some simple extensions:
705
706 %G  Group name
707 %p  Unprefixed group name
708 %A  Current article number
709 %z  Current article score
710 %V  Gnus version
711 %U  Number of unread articles in the group
712 %e  Number of unselected articles in the group
713 %Z  A string with unread/unselected article counts
714 %g  Shortish group name
715 %S  Subject of the current article
716 %u  User-defined spec
717 %s  Current score file name
718 %d  Number of dormant articles
719 %r  Number of articles that have been marked as read in this session
720 %E  Number of articles expunged by the score files"
721   :group 'gnus-summary-format
722   :type 'string)
723
724 (defcustom gnus-list-identifiers nil
725   "Regexp that matches list identifiers to be removed from subject.
726 This can also be a list of regexps."
727   :version "21.1"
728   :group 'gnus-summary-format
729   :group 'gnus-article-hiding
730   :type '(choice (const :tag "none" nil)
731                  (regexp :value ".*")
732                  (repeat :value (".*") regexp)))
733
734 (defcustom gnus-summary-mark-below 0
735   "*Mark all articles with a score below this variable as read.
736 This variable is local to each summary buffer and usually set by the
737 score file."
738   :group 'gnus-score-default
739   :type 'integer)
740
741 (defun gnus-widget-reversible-match (widget value)
742   "Ignoring WIDGET, convert VALUE to internal form.
743 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
744   ;; (debug value)
745   (or (symbolp value)
746       (and (listp value)
747            (eq (length value) 2)
748            (eq (nth 0 value) 'not)
749            (symbolp (nth 1 value)))))
750
751 (defun gnus-widget-reversible-to-internal (widget value)
752   "Ignoring WIDGET, convert VALUE to internal form.
753 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
754 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
755   ;; (debug value)
756   (if (atom value)
757       (list value nil)
758     (list (nth 1 value) t)))
759
760 (defun gnus-widget-reversible-to-external (widget value)
761   "Ignoring WIDGET, convert VALUE to external form.
762 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
763 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
764   ;; (debug value)
765   (if (nth 1 value)
766       (list 'not (nth 0 value))
767     (nth 0 value)))
768
769 (define-widget 'gnus-widget-reversible 'group
770   "A `group' that convert values."
771   :match 'gnus-widget-reversible-match
772   :value-to-internal 'gnus-widget-reversible-to-internal
773   :value-to-external 'gnus-widget-reversible-to-external)
774
775 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
776   "*List of functions used for sorting articles in the summary buffer.
777
778 Each function takes two articles and returns non-nil if the first
779 article should be sorted before the other.  If you use more than one
780 function, the primary sort function should be the last.  You should
781 probably always include `gnus-article-sort-by-number' in the list of
782 sorting functions -- preferably first.  Also note that sorting by date
783 is often much slower than sorting by number, and the sorting order is
784 very similar.  (Sorting by date means sorting by the time the message
785 was sent, sorting by number means sorting by arrival time.)
786
787 Each item can also be a list `(not F)' where F is a function;
788 this reverses the sort order.
789
790 Ready-made functions include `gnus-article-sort-by-number',
791 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
792 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
793 and `gnus-article-sort-by-score'.
794
795 When threading is turned on, the variable `gnus-thread-sort-functions'
796 controls how articles are sorted."
797   :group 'gnus-summary-sort
798   :type '(repeat (gnus-widget-reversible
799                   (choice (function-item gnus-article-sort-by-number)
800                           (function-item gnus-article-sort-by-author)
801                           (function-item gnus-article-sort-by-subject)
802                           (function-item gnus-article-sort-by-date)
803                           (function-item gnus-article-sort-by-score)
804                           (function-item gnus-article-sort-by-random)
805                           (function :tag "other"))
806                   (boolean :tag "Reverse order"))))
807
808
809 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
810   "*List of functions used for sorting threads in the summary buffer.
811 By default, threads are sorted by article number.
812
813 Each function takes two threads and returns non-nil if the first
814 thread should be sorted before the other.  If you use more than one
815 function, the primary sort function should be the last.  You should
816 probably always include `gnus-thread-sort-by-number' in the list of
817 sorting functions -- preferably first.  Also note that sorting by date
818 is often much slower than sorting by number, and the sorting order is
819 very similar.  (Sorting by date means sorting by the time the message
820 was sent, sorting by number means sorting by arrival time.)
821
822 Each list item can also be a list `(not F)' where F is a
823 function; this specifies reversed sort order.
824
825 Ready-made functions include `gnus-thread-sort-by-number',
826 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
827 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
828 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
829 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
830 and `gnus-thread-sort-by-total-score' (see
831 `gnus-thread-score-function').
832
833 When threading is turned off, the variable
834 `gnus-article-sort-functions' controls how articles are sorted."
835   :group 'gnus-summary-sort
836   :type '(repeat
837           (gnus-widget-reversible
838            (choice (function-item gnus-thread-sort-by-number)
839                    (function-item gnus-thread-sort-by-author)
840                    (function-item gnus-thread-sort-by-recipient)
841                    (function-item gnus-thread-sort-by-subject)
842                    (function-item gnus-thread-sort-by-date)
843                    (function-item gnus-thread-sort-by-score)
844                    (function-item gnus-thread-sort-by-most-recent-number)
845                    (function-item gnus-thread-sort-by-most-recent-date)
846                    (function-item gnus-thread-sort-by-random)
847                    (function-item gnus-thread-sort-by-total-score)
848                    (function :tag "other"))
849            (boolean :tag "Reverse order"))))
850
851 (defcustom gnus-thread-score-function '+
852   "*Function used for calculating the total score of a thread.
853
854 The function is called with the scores of the article and each
855 subthread and should then return the score of the thread.
856
857 Some functions you can use are `+', `max', or `min'."
858   :group 'gnus-summary-sort
859   :type 'function)
860
861 (defcustom gnus-summary-expunge-below nil
862   "All articles that have a score less than this variable will be expunged.
863 This variable is local to the summary buffers."
864   :group 'gnus-score-default
865   :type '(choice (const :tag "off" nil)
866                  integer))
867
868 (defcustom gnus-thread-expunge-below nil
869   "All threads that have a total score less than this variable will be expunged.
870 See `gnus-thread-score-function' for en explanation of what a
871 \"thread score\" is.
872
873 This variable is local to the summary buffers."
874   :group 'gnus-threading
875   :group 'gnus-score-default
876   :type '(choice (const :tag "off" nil)
877                  integer))
878
879 (defcustom gnus-summary-mode-hook nil
880   "*A hook for Gnus summary mode.
881 This hook is run before any variables are set in the summary buffer."
882   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
883   :group 'gnus-summary-various
884   :type 'hook)
885
886 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
887 (when (featurep 'xemacs)
888   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
889   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
890   (add-hook 'gnus-summary-mode-hook
891             'gnus-xmas-switch-horizontal-scrollbar-off))
892
893 (defcustom gnus-summary-menu-hook nil
894   "*Hook run after the creation of the summary mode menu."
895   :group 'gnus-summary-visual
896   :type 'hook)
897
898 (defcustom gnus-summary-exit-hook nil
899   "*A hook called on exit from the summary buffer.
900 It will be called with point in the group buffer."
901   :group 'gnus-summary-exit
902   :type 'hook)
903
904 (defcustom gnus-summary-prepare-hook nil
905   "*A hook called after the summary buffer has been generated.
906 If you want to modify the summary buffer, you can use this hook."
907   :group 'gnus-summary-various
908   :type 'hook)
909
910 (defcustom gnus-summary-prepared-hook nil
911   "*A hook called as the last thing after the summary buffer has been generated."
912   :group 'gnus-summary-various
913   :type 'hook)
914
915 (defcustom gnus-summary-generate-hook nil
916   "*A hook run just before generating the summary buffer.
917 This hook is commonly used to customize threading variables and the
918 like."
919   :group 'gnus-summary-various
920   :type 'hook)
921
922 (defcustom gnus-select-group-hook nil
923   "*A hook called when a newsgroup is selected.
924
925 If you'd like to simplify subjects like the
926 `gnus-summary-next-same-subject' command does, you can use the
927 following hook:
928
929  (add-hook gnus-select-group-hook
930            (lambda ()
931              (mapcar (lambda (header)
932                        (mail-header-set-subject
933                         header
934                         (gnus-simplify-subject
935                          (mail-header-subject header) 're-only)))
936                      gnus-newsgroup-headers)))"
937   :group 'gnus-group-select
938   :type 'hook)
939
940 (defcustom gnus-select-article-hook nil
941   "*A hook called when an article is selected."
942   :group 'gnus-summary-choose
943   :options '(gnus-agent-fetch-selected-article)
944   :type 'hook)
945
946 (defcustom gnus-visual-mark-article-hook
947   (list 'gnus-highlight-selected-summary)
948   "*Hook run after selecting an article in the summary buffer.
949 It is meant to be used for highlighting the article in some way.  It
950 is not run if `gnus-visual' is nil."
951   :group 'gnus-summary-visual
952   :type 'hook)
953
954 (defcustom gnus-parse-headers-hook nil
955   "*A hook called before parsing the headers."
956   :group 'gnus-various
957   :type 'hook)
958
959 (defcustom gnus-exit-group-hook nil
960   "*A hook called when exiting summary mode.
961 This hook is not called from the non-updating exit commands like `Q'."
962   :group 'gnus-various
963   :type 'hook)
964
965 (defcustom gnus-summary-update-hook
966   (list 'gnus-summary-highlight-line)
967   "*A hook called when a summary line is changed.
968 The hook will not be called if `gnus-visual' is nil.
969
970 The default function `gnus-summary-highlight-line' will
971 highlight the line according to the `gnus-summary-highlight'
972 variable."
973   :group 'gnus-summary-visual
974   :type 'hook)
975
976 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
977   "*A hook called when an article is selected for the first time.
978 The hook is intended to mark an article as read (or unread)
979 automatically when it is selected."
980   :group 'gnus-summary-choose
981   :type 'hook)
982
983 (defcustom gnus-group-no-more-groups-hook nil
984   "*A hook run when returning to group mode having no more (unread) groups."
985   :group 'gnus-group-select
986   :type 'hook)
987
988 (defcustom gnus-ps-print-hook nil
989   "*A hook run before ps-printing something from Gnus."
990   :group 'gnus-summary
991   :type 'hook)
992
993 (defcustom gnus-summary-article-move-hook nil
994   "*A hook called after an article is moved, copied, respooled, or crossposted."
995   :version "22.1"
996   :group 'gnus-summary
997   :type 'hook)
998
999 (defcustom gnus-summary-article-delete-hook nil
1000   "*A hook called after an article is deleted."
1001   :version "22.1"
1002   :group 'gnus-summary
1003   :type 'hook)
1004
1005 (defcustom gnus-summary-article-expire-hook nil
1006   "*A hook called after an article is expired."
1007   :version "22.1"
1008   :group 'gnus-summary
1009   :type 'hook)
1010
1011 (defcustom gnus-summary-display-arrow
1012   (and (fboundp 'display-graphic-p)
1013        (display-graphic-p))
1014   "*If non-nil, display an arrow highlighting the current article."
1015   :version "22.1"
1016   :group 'gnus-summary
1017   :type 'boolean)
1018
1019 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1020   "Face used for highlighting the current article in the summary buffer."
1021   :group 'gnus-summary-visual
1022   :type 'face)
1023
1024 (defvar gnus-tmp-downloaded nil)
1025
1026 (defcustom gnus-summary-highlight
1027   '(((eq mark gnus-canceled-mark)
1028      . gnus-summary-cancelled)
1029     ((and uncached (> score default-high))
1030      . gnus-summary-high-undownloaded)
1031     ((and uncached (< score default-low))
1032      . gnus-summary-low-undownloaded)
1033     (uncached
1034      . gnus-summary-normal-undownloaded)
1035     ((and (> score default-high)
1036           (or (eq mark gnus-dormant-mark)
1037               (eq mark gnus-ticked-mark)))
1038      . gnus-summary-high-ticked)
1039     ((and (< score default-low)
1040           (or (eq mark gnus-dormant-mark)
1041               (eq mark gnus-ticked-mark)))
1042      . gnus-summary-low-ticked)
1043     ((or (eq mark gnus-dormant-mark)
1044          (eq mark gnus-ticked-mark))
1045      . gnus-summary-normal-ticked)
1046     ((and (> score default-high) (eq mark gnus-ancient-mark))
1047      . gnus-summary-high-ancient)
1048     ((and (< score default-low) (eq mark gnus-ancient-mark))
1049      . gnus-summary-low-ancient)
1050     ((eq mark gnus-ancient-mark)
1051      . gnus-summary-normal-ancient)
1052     ((and (> score default-high) (eq mark gnus-unread-mark))
1053      . gnus-summary-high-unread)
1054     ((and (< score default-low) (eq mark gnus-unread-mark))
1055      . gnus-summary-low-unread)
1056     ((eq mark gnus-unread-mark)
1057      . gnus-summary-normal-unread)
1058     ((> score default-high)
1059      . gnus-summary-high-read)
1060     ((< score default-low)
1061      . gnus-summary-low-read)
1062     (t
1063      . gnus-summary-normal-read))
1064   "*Controls the highlighting of summary buffer lines.
1065
1066 A list of (FORM . FACE) pairs.  When deciding how a particular
1067 summary line should be displayed, each form is evaluated.  The content
1068 of the face field after the first true form is used.  You can change
1069 how those summary lines are displayed, by editing the face field.
1070
1071 You can use the following variables in the FORM field.
1072
1073 score:        The article's score.
1074 default:      The default article score.
1075 default-high: The default score for high scored articles.
1076 default-low:  The default score for low scored articles.
1077 below:        The score below which articles are automatically marked as read.
1078 mark:         The article's mark.
1079 uncached:     Non-nil if the article is uncached."
1080   :group 'gnus-summary-visual
1081   :type '(repeat (cons (sexp :tag "Form" nil)
1082                        face)))
1083
1084 (defcustom gnus-alter-header-function nil
1085   "Function called to allow alteration of article header structures.
1086 The function is called with one parameter, the article header vector,
1087 which it may alter in any way."
1088   :type '(choice (const :tag "None" nil)
1089                  function)
1090   :group 'gnus-summary)
1091
1092 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1093   "Function used to decode a string with encoded words.")
1094
1095 (defvar gnus-decode-encoded-address-function
1096   'mail-decode-encoded-address-string
1097   "Function used to decode addresses with encoded words.")
1098
1099 (defcustom gnus-extra-headers '(To Newsgroups)
1100   "*Extra headers to parse."
1101   :version "21.1"
1102   :group 'gnus-summary
1103   :type '(repeat symbol))
1104
1105 (defcustom gnus-ignored-from-addresses
1106   (and user-mail-address
1107        (not (string= user-mail-address ""))
1108        (regexp-quote user-mail-address))
1109   "*From headers that may be suppressed in favor of To headers.
1110 This can be a regexp or a list of regexps."
1111   :version "21.1"
1112   :group 'gnus-summary
1113   :type '(choice regexp
1114                  (repeat :tag "Regexp List" regexp)))
1115
1116 (defsubst gnus-ignored-from-addresses ()
1117   (gmm-regexp-concat gnus-ignored-from-addresses))
1118
1119 (defcustom gnus-summary-to-prefix "-> "
1120   "*String prefixed to the To field in the summary line when
1121 using `gnus-ignored-from-addresses'."
1122   :version "22.1"
1123   :group 'gnus-summary
1124   :type 'string)
1125
1126 (defcustom gnus-summary-newsgroup-prefix "=> "
1127   "*String prefixed to the Newsgroup field in the summary
1128 line when using `gnus-ignored-from-addresses'."
1129   :version "22.1"
1130   :group 'gnus-summary
1131   :type 'string)
1132
1133 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1134   "List of charsets that should be ignored.
1135 When these charsets are used in the \"charset\" parameter, the
1136 default charset will be used instead."
1137   :version "21.1"
1138   :type '(repeat symbol)
1139   :group 'gnus-charset)
1140
1141 (gnus-define-group-parameter
1142  ignored-charsets
1143  :type list
1144  :function-document
1145  "Return the ignored charsets of GROUP."
1146  :variable gnus-group-ignored-charsets-alist
1147  :variable-default
1148  '(("alt\\.chinese\\.text" iso-8859-1))
1149  :variable-document
1150  "Alist of regexps (to match group names) and charsets that should be ignored.
1151 When these charsets are used in the \"charset\" parameter, the
1152 default charset will be used instead."
1153  :variable-group gnus-charset
1154  :variable-type '(repeat (cons (regexp :tag "Group")
1155                                (repeat symbol)))
1156  :parameter-type '(choice :tag "Ignored charsets"
1157                           :value nil
1158                           (repeat (symbol)))
1159  :parameter-document       "\
1160 List of charsets that should be ignored.
1161
1162 When these charsets are used in the \"charset\" parameter, the
1163 default charset will be used instead.")
1164
1165 (defcustom gnus-group-highlight-words-alist nil
1166   "Alist of group regexps and highlight regexps.
1167 This variable uses the same syntax as `gnus-emphasis-alist'."
1168   :version "21.1"
1169   :type '(repeat (cons (regexp :tag "Group")
1170                        (repeat (list (regexp :tag "Highlight regexp")
1171                                      (number :tag "Group for entire word" 0)
1172                                      (number :tag "Group for displayed part" 0)
1173                                      (symbol :tag "Face"
1174                                              gnus-emphasis-highlight-words)))))
1175   :group 'gnus-summary-visual)
1176
1177 (defcustom gnus-summary-show-article-charset-alist
1178   nil
1179   "Alist of number and charset.
1180 The article will be shown with the charset corresponding to the
1181 numbered argument.
1182 For example: ((1 . cn-gb-2312) (2 . big5))."
1183   :version "21.1"
1184   :type '(repeat (cons (number :tag "Argument" 1)
1185                        (symbol :tag "Charset")))
1186   :group 'gnus-charset)
1187
1188 (defcustom gnus-preserve-marks t
1189   "Whether marks are preserved when moving, copying and respooling messages."
1190   :version "21.1"
1191   :type 'boolean
1192   :group 'gnus-summary-marks)
1193
1194 (defcustom gnus-alter-articles-to-read-function nil
1195   "Function to be called to alter the list of articles to be selected."
1196   :type '(choice (const nil) function)
1197   :group 'gnus-summary)
1198
1199 (defcustom gnus-orphan-score nil
1200   "*All orphans get this score added.  Set in the score file."
1201   :group 'gnus-score-default
1202   :type '(choice (const nil)
1203                  integer))
1204
1205 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1206   "*A regexp to match MIME parts when saving multiple parts of a
1207 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1208 This regexp will be used by default when prompting the user for which
1209 type of files to save."
1210   :group 'gnus-summary
1211   :type 'regexp)
1212
1213 (defcustom gnus-read-all-available-headers nil
1214   "Whether Gnus should parse all headers made available to it.
1215 This is mostly relevant for slow back ends where the user may
1216 wish to widen the summary buffer to include all headers
1217 that were fetched.  Say, for nnultimate groups."
1218   :version "22.1"
1219   :group 'gnus-summary
1220   :type '(choice boolean regexp))
1221
1222 (defcustom gnus-summary-muttprint-program "muttprint"
1223   "Command (and optional arguments) used to run Muttprint."
1224   :version "22.1"
1225   :group 'gnus-summary
1226   :type 'string)
1227
1228 (defcustom gnus-article-loose-mime t
1229   "If non-nil, don't require MIME-Version header.
1230 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1231 supply the MIME-Version header or deliberately strip it from the mail.
1232 If non-nil (the default), Gnus will treat some articles as MIME
1233 even if the MIME-Version header is missing."
1234   :version "22.1"
1235   :type 'boolean
1236   :group 'gnus-article-mime)
1237
1238 (defcustom gnus-article-emulate-mime t
1239   "If non-nil, use MIME emulation for uuencode and the like.
1240 This means that Gnus will search message bodies for text that look
1241 like uuencoded bits, yEncoded bits, and so on, and present that using
1242 the normal Gnus MIME machinery."
1243   :version "22.1"
1244   :type 'boolean
1245   :group 'gnus-article-mime)
1246
1247 ;;; Internal variables
1248
1249 (defvar gnus-summary-display-cache nil)
1250 (defvar gnus-article-mime-handles nil)
1251 (defvar gnus-article-decoded-p nil)
1252 (defvar gnus-article-charset nil)
1253 (defvar gnus-article-ignored-charsets nil)
1254 (defvar gnus-scores-exclude-files nil)
1255 (defvar gnus-page-broken nil)
1256
1257 (defvar gnus-original-article nil)
1258 (defvar gnus-article-internal-prepare-hook nil)
1259 (defvar gnus-newsgroup-process-stack nil)
1260
1261 (defvar gnus-thread-indent-array nil)
1262 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1263 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1264   "Function called to sort the articles within a thread after it has been gathered together.")
1265
1266 (defvar gnus-summary-save-parts-type-history nil)
1267 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1268
1269 ;; Avoid highlighting in kill files.
1270 (defvar gnus-summary-inhibit-highlight nil)
1271 (defvar gnus-newsgroup-selected-overlay nil)
1272 (defvar gnus-inhibit-limiting nil)
1273 (defvar gnus-newsgroup-adaptive-score-file nil)
1274 (defvar gnus-current-score-file nil)
1275 (defvar gnus-current-move-group nil)
1276 (defvar gnus-current-copy-group nil)
1277 (defvar gnus-current-crosspost-group nil)
1278 (defvar gnus-newsgroup-display nil)
1279
1280 (defvar gnus-newsgroup-dependencies nil)
1281 (defvar gnus-newsgroup-adaptive nil)
1282 (defvar gnus-summary-display-article-function nil)
1283 (defvar gnus-summary-highlight-line-function nil
1284   "Function called after highlighting a summary line.")
1285
1286 (defvar gnus-summary-line-format-alist
1287   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1288     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1289     (?s gnus-tmp-subject-or-nil ?s)
1290     (?n gnus-tmp-name ?s)
1291     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1292         ?s)
1293     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1294             gnus-tmp-from) ?s)
1295     (?F gnus-tmp-from ?s)
1296     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1297     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1298     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1299     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1300     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1301     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1302     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1303     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1304     (?L gnus-tmp-lines ?s)
1305     (?O gnus-tmp-downloaded ?c)
1306     (?I gnus-tmp-indentation ?s)
1307     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1308     (?R gnus-tmp-replied ?c)
1309     (?\[ gnus-tmp-opening-bracket ?c)
1310     (?\] gnus-tmp-closing-bracket ?c)
1311     (?\> (make-string gnus-tmp-level ? ) ?s)
1312     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1313     (?i gnus-tmp-score ?d)
1314     (?z gnus-tmp-score-char ?c)
1315     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1316     (?U gnus-tmp-unread ?c)
1317     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1318         ?s)
1319     (?t (gnus-summary-number-of-articles-in-thread
1320          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1321         ?d)
1322     (?e (gnus-summary-number-of-articles-in-thread
1323          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1324         ?c)
1325     (?u gnus-tmp-user-defined ?s)
1326     (?P (gnus-pick-line-number) ?d)
1327     (?B gnus-tmp-thread-tree-header-string ?s)
1328     (user-date (gnus-user-date
1329                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1330   "An alist of format specifications that can appear in summary lines.
1331 These are paired with what variables they correspond with, along with
1332 the type of the variable (string, integer, character, etc).")
1333
1334 (defvar gnus-summary-dummy-line-format-alist
1335   `((?S gnus-tmp-subject ?s)
1336     (?N gnus-tmp-number ?d)
1337     (?u gnus-tmp-user-defined ?s)))
1338
1339 (defvar gnus-summary-mode-line-format-alist
1340   `((?G gnus-tmp-group-name ?s)
1341     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1342     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1343     (?A gnus-tmp-article-number ?d)
1344     (?Z gnus-tmp-unread-and-unselected ?s)
1345     (?V gnus-version ?s)
1346     (?U gnus-tmp-unread-and-unticked ?d)
1347     (?S gnus-tmp-subject ?s)
1348     (?e gnus-tmp-unselected ?d)
1349     (?u gnus-tmp-user-defined ?s)
1350     (?d (length gnus-newsgroup-dormant) ?d)
1351     (?t (length gnus-newsgroup-marked) ?d)
1352     (?h (length gnus-newsgroup-spam-marked) ?d)
1353     (?r (length gnus-newsgroup-reads) ?d)
1354     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1355     (?E gnus-newsgroup-expunged-tally ?d)
1356     (?s (gnus-current-score-file-nondirectory) ?s)))
1357
1358 (defvar gnus-last-search-regexp nil
1359   "Default regexp for article search command.")
1360
1361 (defvar gnus-last-shell-command nil
1362   "Default shell command on article.")
1363
1364 (defvar gnus-newsgroup-agentized nil
1365   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1366 (defvar gnus-newsgroup-begin nil)
1367 (defvar gnus-newsgroup-end nil)
1368 (defvar gnus-newsgroup-last-rmail nil)
1369 (defvar gnus-newsgroup-last-mail nil)
1370 (defvar gnus-newsgroup-last-folder nil)
1371 (defvar gnus-newsgroup-last-file nil)
1372 (defvar gnus-newsgroup-last-directory nil)
1373 (defvar gnus-newsgroup-auto-expire nil)
1374 (defvar gnus-newsgroup-active nil)
1375
1376 (defvar gnus-newsgroup-data nil)
1377 (defvar gnus-newsgroup-data-reverse nil)
1378 (defvar gnus-newsgroup-limit nil)
1379 (defvar gnus-newsgroup-limits nil)
1380 (defvar gnus-summary-use-undownloaded-faces nil)
1381
1382 (defvar gnus-newsgroup-unreads nil
1383   "Sorted list of unread articles in the current newsgroup.")
1384
1385 (defvar gnus-newsgroup-unselected nil
1386   "Sorted list of unselected unread articles in the current newsgroup.")
1387
1388 (defvar gnus-newsgroup-reads nil
1389   "Alist of read articles and article marks in the current newsgroup.")
1390
1391 (defvar gnus-newsgroup-expunged-tally nil)
1392
1393 (defvar gnus-newsgroup-marked nil
1394   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1395
1396 (defvar gnus-newsgroup-spam-marked nil
1397   "List of ranges of articles that have been marked as spam.")
1398
1399 (defvar gnus-newsgroup-killed nil
1400   "List of ranges of articles that have been through the scoring process.")
1401
1402 (defvar gnus-newsgroup-cached nil
1403   "Sorted list of articles that come from the article cache.")
1404
1405 (defvar gnus-newsgroup-saved nil
1406   "List of articles that have been saved.")
1407
1408 (defvar gnus-newsgroup-kill-headers nil)
1409
1410 (defvar gnus-newsgroup-replied nil
1411   "List of articles that have been replied to in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-forwarded nil
1414   "List of articles that have been forwarded in the current newsgroup.")
1415
1416 (defvar gnus-newsgroup-recent nil
1417   "List of articles that have are recent in the current newsgroup.")
1418
1419 (defvar gnus-newsgroup-expirable nil
1420   "Sorted list of articles in the current newsgroup that can be expired.")
1421
1422 (defvar gnus-newsgroup-processable nil
1423   "List of articles in the current newsgroup that can be processed.")
1424
1425 (defvar gnus-newsgroup-downloadable nil
1426   "Sorted list of articles in the current newsgroup that can be processed.")
1427
1428 (defvar gnus-newsgroup-unfetched nil
1429   "Sorted list of articles in the current newsgroup whose headers have
1430 not been fetched into the agent.
1431
1432 This list will always be a subset of gnus-newsgroup-undownloaded.")
1433
1434 (defvar gnus-newsgroup-undownloaded nil
1435   "List of articles in the current newsgroup that haven't been downloaded.")
1436
1437 (defvar gnus-newsgroup-unsendable nil
1438   "List of articles in the current newsgroup that won't be sent.")
1439
1440 (defvar gnus-newsgroup-bookmarks nil
1441   "List of articles in the current newsgroup that have bookmarks.")
1442
1443 (defvar gnus-newsgroup-dormant nil
1444   "Sorted list of dormant articles in the current newsgroup.")
1445
1446 (defvar gnus-newsgroup-unseen nil
1447   "List of unseen articles in the current newsgroup.")
1448
1449 (defvar gnus-newsgroup-seen nil
1450   "Range of seen articles in the current newsgroup.")
1451
1452 (defvar gnus-newsgroup-articles nil
1453   "List of articles in the current newsgroup.")
1454
1455 (defvar gnus-newsgroup-scored nil
1456   "List of scored articles in the current newsgroup.")
1457
1458 (defvar gnus-newsgroup-headers nil
1459   "List of article headers in the current newsgroup.")
1460
1461 (defvar gnus-newsgroup-threads nil)
1462
1463 (defvar gnus-newsgroup-prepared nil
1464   "Whether the current group has been prepared properly.")
1465
1466 (defvar gnus-newsgroup-ancient nil
1467   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-sparse nil)
1470
1471 (defvar gnus-current-article nil)
1472 (defvar gnus-article-current nil)
1473 (defvar gnus-current-headers nil)
1474 (defvar gnus-have-all-headers nil)
1475 (defvar gnus-last-article nil)
1476 (defvar gnus-newsgroup-history nil)
1477 (defvar gnus-newsgroup-charset nil)
1478 (defvar gnus-newsgroup-ephemeral-charset nil)
1479 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1480
1481 (defvar gnus-article-before-search nil)
1482
1483 (defvar gnus-summary-local-variables
1484   '(gnus-newsgroup-name
1485     gnus-newsgroup-begin gnus-newsgroup-end
1486     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1487     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1488     gnus-newsgroup-last-directory
1489     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1490     gnus-newsgroup-unselected gnus-newsgroup-marked
1491     gnus-newsgroup-spam-marked
1492     gnus-newsgroup-reads gnus-newsgroup-saved
1493     gnus-newsgroup-replied gnus-newsgroup-forwarded
1494     gnus-newsgroup-recent
1495     gnus-newsgroup-expirable
1496     gnus-newsgroup-processable gnus-newsgroup-killed
1497     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1498     gnus-newsgroup-unfetched
1499     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1500     gnus-newsgroup-seen gnus-newsgroup-articles
1501     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1502     gnus-newsgroup-headers gnus-newsgroup-threads
1503     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1504     gnus-current-article gnus-current-headers gnus-have-all-headers
1505     gnus-last-article gnus-article-internal-prepare-hook
1506     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1507     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1508     gnus-thread-expunge-below
1509     gnus-score-alist gnus-current-score-file
1510     (gnus-summary-expunge-below . global)
1511     (gnus-summary-mark-below . global)
1512     (gnus-orphan-score . global)
1513     gnus-newsgroup-active gnus-scores-exclude-files
1514     gnus-newsgroup-history gnus-newsgroup-ancient
1515     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1516     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1517     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1518     (gnus-newsgroup-expunged-tally . 0)
1519     gnus-cache-removable-articles gnus-newsgroup-cached
1520     gnus-newsgroup-data gnus-newsgroup-data-reverse
1521     gnus-newsgroup-limit gnus-newsgroup-limits
1522     gnus-newsgroup-charset gnus-newsgroup-display
1523     gnus-summary-use-undownloaded-faces)
1524   "Variables that are buffer-local to the summary buffers.")
1525
1526 (defvar gnus-newsgroup-variables nil
1527   "A list of variables that have separate values in different newsgroups.
1528 A list of newsgroup (summary buffer) local variables, or cons of
1529 variables and their default expressions to be evalled (when the default
1530 values are not nil), that should be made global while the summary buffer
1531 is active.
1532
1533 Note: The default expressions will be evaluated (using function `eval')
1534 before assignment to the local variable rather than just assigned to it.
1535 If the default expression is the symbol `global', that symbol will not
1536 be evaluated but the global value of the local variable will be used
1537 instead.
1538
1539 These variables can be used to set variables in the group parameters
1540 while still allowing them to affect operations done in other buffers.
1541 For example:
1542
1543 \(setq gnus-newsgroup-variables
1544      '(message-use-followup-to
1545        (gnus-visible-headers .
1546          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1547 ")
1548
1549 ;; Byte-compiler warning.
1550 (eval-when-compile
1551   ;; Bind features so that require will believe that gnus-sum has
1552   ;; already been loaded (avoids infinite recursion)
1553   (let ((features (cons 'gnus-sum features)))
1554     ;; Several of the declarations in gnus-sum are needed to load the
1555     ;; following files. Right now, these definitions have been
1556     ;; compiled but not defined (evaluated).  We could either do a
1557     ;; eval-and-compile about all of the declarations or evaluate the
1558     ;; source file.
1559     (if (boundp 'gnus-newsgroup-variables)
1560         nil
1561       (load "gnus-sum.el" t t t))
1562     (require 'gnus)
1563     (require 'gnus-art)))
1564
1565 ;; MIME stuff.
1566
1567 (defvar gnus-decode-encoded-word-methods
1568   '(mail-decode-encoded-word-string)
1569   "List of methods used to decode encoded words.
1570
1571 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1572 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1573 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1574 whose names match REGEXP.
1575
1576 For example:
1577 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1578  mail-decode-encoded-word-string
1579  (\"chinese\" . rfc1843-decode-string))")
1580
1581 (defvar gnus-decode-encoded-word-methods-cache nil)
1582
1583 (defun gnus-multi-decode-encoded-word-string (string)
1584   "Apply the functions from `gnus-encoded-word-methods' that match."
1585   (unless (and gnus-decode-encoded-word-methods-cache
1586                (eq gnus-newsgroup-name
1587                    (car gnus-decode-encoded-word-methods-cache)))
1588     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1589     (mapcar (lambda (x)
1590               (if (symbolp x)
1591                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1592                 (if (and gnus-newsgroup-name
1593                          (string-match (car x) gnus-newsgroup-name))
1594                     (nconc gnus-decode-encoded-word-methods-cache
1595                            (list (cdr x))))))
1596             gnus-decode-encoded-word-methods))
1597   (let ((xlist gnus-decode-encoded-word-methods-cache))
1598     (pop xlist)
1599     (while xlist
1600       (setq string (funcall (pop xlist) string))))
1601   string)
1602
1603 ;; Subject simplification.
1604
1605 (defun gnus-simplify-whitespace (str)
1606   "Remove excessive whitespace from STR."
1607   ;; Multiple spaces.
1608   (while (string-match "[ \t][ \t]+" str)
1609     (setq str (concat (substring str 0 (match-beginning 0))
1610                         " "
1611                         (substring str (match-end 0)))))
1612   ;; Leading spaces.
1613   (when (string-match "^[ \t]+" str)
1614     (setq str (substring str (match-end 0))))
1615   ;; Trailing spaces.
1616   (when (string-match "[ \t]+$" str)
1617     (setq str (substring str 0 (match-beginning 0))))
1618   str)
1619
1620 (defun gnus-simplify-all-whitespace (str)
1621   "Remove all whitespace from STR."
1622   (while (string-match "[ \t\n]+" str)
1623     (setq str (replace-match "" nil nil str)))
1624   str)
1625
1626 (defsubst gnus-simplify-subject-re (subject)
1627   "Remove \"Re:\" from subject lines."
1628   (if (string-match message-subject-re-regexp subject)
1629       (substring subject (match-end 0))
1630     subject))
1631
1632 (defun gnus-simplify-subject (subject &optional re-only)
1633   "Remove `Re:' and words in parentheses.
1634 If RE-ONLY is non-nil, strip leading `Re:'s only."
1635   (let ((case-fold-search t))           ;Ignore case.
1636     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1637     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1638       (setq subject (substring subject (match-end 0))))
1639     ;; Remove uninteresting prefixes.
1640     (when (and (not re-only)
1641                gnus-simplify-ignored-prefixes
1642                (string-match gnus-simplify-ignored-prefixes subject))
1643       (setq subject (substring subject (match-end 0))))
1644     ;; Remove words in parentheses from end.
1645     (unless re-only
1646       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1647         (setq subject (substring subject 0 (match-beginning 0)))))
1648     ;; Return subject string.
1649     subject))
1650
1651 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1652 ;; all whitespace.
1653 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1654   (goto-char (point-min))
1655   (while (re-search-forward regexp nil t)
1656     (replace-match (or newtext ""))))
1657
1658 (defun gnus-simplify-buffer-fuzzy ()
1659   "Simplify string in the buffer fuzzily.
1660 The string in the accessible portion of the current buffer is simplified.
1661 It is assumed to be a single-line subject.
1662 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1663 matter is removed.  Additional things can be deleted by setting
1664 `gnus-simplify-subject-fuzzy-regexp'."
1665   (let ((case-fold-search t)
1666         (modified-tick))
1667     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1668
1669     (while (not (eq modified-tick (buffer-modified-tick)))
1670       (setq modified-tick (buffer-modified-tick))
1671       (cond
1672        ((listp gnus-simplify-subject-fuzzy-regexp)
1673         (mapcar 'gnus-simplify-buffer-fuzzy-step
1674                 gnus-simplify-subject-fuzzy-regexp))
1675        (gnus-simplify-subject-fuzzy-regexp
1676         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1677       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1678       (gnus-simplify-buffer-fuzzy-step
1679        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1680       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1681
1682     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1683     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1684     (gnus-simplify-buffer-fuzzy-step " $")
1685     (gnus-simplify-buffer-fuzzy-step "^ +")))
1686
1687 (defun gnus-simplify-subject-fuzzy (subject)
1688   "Simplify a subject string fuzzily.
1689 See `gnus-simplify-buffer-fuzzy' for details."
1690   (save-excursion
1691     (gnus-set-work-buffer)
1692     (let ((case-fold-search t))
1693       ;; Remove uninteresting prefixes.
1694       (when (and gnus-simplify-ignored-prefixes
1695                  (string-match gnus-simplify-ignored-prefixes subject))
1696         (setq subject (substring subject (match-end 0))))
1697       (insert subject)
1698       (inline (gnus-simplify-buffer-fuzzy))
1699       (buffer-string))))
1700
1701 (defsubst gnus-simplify-subject-fully (subject)
1702   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1703   (cond
1704    (gnus-simplify-subject-functions
1705     (gnus-map-function gnus-simplify-subject-functions subject))
1706    ((null gnus-summary-gather-subject-limit)
1707     (gnus-simplify-subject-re subject))
1708    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1709     (gnus-simplify-subject-fuzzy subject))
1710    ((numberp gnus-summary-gather-subject-limit)
1711     (truncate-string-to-width (gnus-simplify-subject-re subject)
1712                               gnus-summary-gather-subject-limit))
1713    (t
1714     subject)))
1715
1716 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1717   "Check whether two subjects are equal.
1718 If optional argument SIMPLE-FIRST is t, first argument is already
1719 simplified."
1720   (cond
1721    ((null simple-first)
1722     (equal (gnus-simplify-subject-fully s1)
1723            (gnus-simplify-subject-fully s2)))
1724    (t
1725     (equal s1
1726            (gnus-simplify-subject-fully s2)))))
1727
1728 (defun gnus-summary-bubble-group ()
1729   "Increase the score of the current group.
1730 This is a handy function to add to `gnus-summary-exit-hook' to
1731 increase the score of each group you read."
1732   (gnus-group-add-score gnus-newsgroup-name))
1733
1734 \f
1735 ;;;
1736 ;;; Gnus summary mode
1737 ;;;
1738
1739 (put 'gnus-summary-mode 'mode-class 'special)
1740
1741 (defvar gnus-article-commands-menu)
1742
1743 ;; Non-orthogonal keys
1744
1745 (gnus-define-keys gnus-summary-mode-map
1746   " " gnus-summary-next-page
1747   "\177" gnus-summary-prev-page
1748   [delete] gnus-summary-prev-page
1749   [backspace] gnus-summary-prev-page
1750   "\r" gnus-summary-scroll-up
1751   "\M-\r" gnus-summary-scroll-down
1752   "n" gnus-summary-next-unread-article
1753   "p" gnus-summary-prev-unread-article
1754   "N" gnus-summary-next-article
1755   "P" gnus-summary-prev-article
1756   "\M-\C-n" gnus-summary-next-same-subject
1757   "\M-\C-p" gnus-summary-prev-same-subject
1758   "\M-n" gnus-summary-next-unread-subject
1759   "\M-p" gnus-summary-prev-unread-subject
1760   "." gnus-summary-first-unread-article
1761   "," gnus-summary-best-unread-article
1762   "\M-s" gnus-summary-search-article-forward
1763   "\M-r" gnus-summary-search-article-backward
1764   "\M-S" gnus-summary-repeat-search-article-forward
1765   "\M-R" gnus-summary-repeat-search-article-backward
1766   "<" gnus-summary-beginning-of-article
1767   ">" gnus-summary-end-of-article
1768   "j" gnus-summary-goto-article
1769   "^" gnus-summary-refer-parent-article
1770   "\M-^" gnus-summary-refer-article
1771   "u" gnus-summary-tick-article-forward
1772   "!" gnus-summary-tick-article-forward
1773   "U" gnus-summary-tick-article-backward
1774   "d" gnus-summary-mark-as-read-forward
1775   "D" gnus-summary-mark-as-read-backward
1776   "E" gnus-summary-mark-as-expirable
1777   "\M-u" gnus-summary-clear-mark-forward
1778   "\M-U" gnus-summary-clear-mark-backward
1779   "k" gnus-summary-kill-same-subject-and-select
1780   "\C-k" gnus-summary-kill-same-subject
1781   "\M-\C-k" gnus-summary-kill-thread
1782   "\M-\C-l" gnus-summary-lower-thread
1783   "e" gnus-summary-edit-article
1784   "#" gnus-summary-mark-as-processable
1785   "\M-#" gnus-summary-unmark-as-processable
1786   "\M-\C-t" gnus-summary-toggle-threads
1787   "\M-\C-s" gnus-summary-show-thread
1788   "\M-\C-h" gnus-summary-hide-thread
1789   "\M-\C-f" gnus-summary-next-thread
1790   "\M-\C-b" gnus-summary-prev-thread
1791   [(meta down)] gnus-summary-next-thread
1792   [(meta up)] gnus-summary-prev-thread
1793   "\M-\C-u" gnus-summary-up-thread
1794   "\M-\C-d" gnus-summary-down-thread
1795   "&" gnus-summary-execute-command
1796   "c" gnus-summary-catchup-and-exit
1797   "\C-w" gnus-summary-mark-region-as-read
1798   "\C-t" gnus-summary-toggle-truncation
1799   "?" gnus-summary-mark-as-dormant
1800   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1801   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1802   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1803   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1804   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1805   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1806   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1807   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1808   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1809   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1810   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1811   "=" gnus-summary-expand-window
1812   "\C-x\C-s" gnus-summary-reselect-current-group
1813   "\M-g" gnus-summary-rescan-group
1814   "w" gnus-summary-stop-page-breaking
1815   "\C-c\C-r" gnus-summary-caesar-message
1816   "f" gnus-summary-followup
1817   "F" gnus-summary-followup-with-original
1818   "C" gnus-summary-cancel-article
1819   "r" gnus-summary-reply
1820   "R" gnus-summary-reply-with-original
1821   "\C-c\C-f" gnus-summary-mail-forward
1822   "o" gnus-summary-save-article
1823   "\C-o" gnus-summary-save-article-mail
1824   "|" gnus-summary-pipe-output
1825   "\M-k" gnus-summary-edit-local-kill
1826   "\M-K" gnus-summary-edit-global-kill
1827   ;; "V" gnus-version
1828   "\C-c\C-d" gnus-summary-describe-group
1829   "q" gnus-summary-exit
1830   "Q" gnus-summary-exit-no-update
1831   "\C-c\C-i" gnus-info-find-node
1832   gnus-mouse-2 gnus-mouse-pick-article
1833   [follow-link] mouse-face
1834   "m" gnus-summary-mail-other-window
1835   "a" gnus-summary-post-news
1836   "i" gnus-summary-news-other-window
1837   "x" gnus-summary-limit-to-unread
1838   "s" gnus-summary-isearch-article
1839   "t" gnus-summary-toggle-header
1840   "g" gnus-summary-show-article
1841   "l" gnus-summary-goto-last-article
1842   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1843   "\C-d" gnus-summary-enter-digest-group
1844   "\M-\C-d" gnus-summary-read-document
1845   "\M-\C-e" gnus-summary-edit-parameters
1846   "\M-\C-a" gnus-summary-customize-parameters
1847   "\C-c\C-b" gnus-bug
1848   "*" gnus-cache-enter-article
1849   "\M-*" gnus-cache-remove-article
1850   "\M-&" gnus-summary-universal-argument
1851   "\C-l" gnus-recenter
1852   "I" gnus-summary-increase-score
1853   "L" gnus-summary-lower-score
1854   "\M-i" gnus-symbolic-argument
1855   "h" gnus-summary-select-article-buffer
1856
1857   "b" gnus-article-view-part
1858   "\M-t" gnus-summary-toggle-display-buttonized
1859
1860   "V" gnus-summary-score-map
1861   "X" gnus-uu-extract-map
1862   "S" gnus-summary-send-map)
1863
1864 ;; Sort of orthogonal keymap
1865 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1866   "t" gnus-summary-tick-article-forward
1867   "!" gnus-summary-tick-article-forward
1868   "d" gnus-summary-mark-as-read-forward
1869   "r" gnus-summary-mark-as-read-forward
1870   "c" gnus-summary-clear-mark-forward
1871   " " gnus-summary-clear-mark-forward
1872   "e" gnus-summary-mark-as-expirable
1873   "x" gnus-summary-mark-as-expirable
1874   "?" gnus-summary-mark-as-dormant
1875   "b" gnus-summary-set-bookmark
1876   "B" gnus-summary-remove-bookmark
1877   "#" gnus-summary-mark-as-processable
1878   "\M-#" gnus-summary-unmark-as-processable
1879   "S" gnus-summary-limit-include-expunged
1880   "C" gnus-summary-catchup
1881   "H" gnus-summary-catchup-to-here
1882   "h" gnus-summary-catchup-from-here
1883   "\C-c" gnus-summary-catchup-all
1884   "k" gnus-summary-kill-same-subject-and-select
1885   "K" gnus-summary-kill-same-subject
1886   "P" gnus-uu-mark-map)
1887
1888 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1889   "c" gnus-summary-clear-above
1890   "u" gnus-summary-tick-above
1891   "m" gnus-summary-mark-above
1892   "k" gnus-summary-kill-below)
1893
1894 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1895   "/" gnus-summary-limit-to-subject
1896   "n" gnus-summary-limit-to-articles
1897   "b" gnus-summary-limit-to-bodies
1898   "h" gnus-summary-limit-to-headers
1899   "w" gnus-summary-pop-limit
1900   "s" gnus-summary-limit-to-subject
1901   "a" gnus-summary-limit-to-author
1902   "u" gnus-summary-limit-to-unread
1903   "m" gnus-summary-limit-to-marks
1904   "M" gnus-summary-limit-exclude-marks
1905   "v" gnus-summary-limit-to-score
1906   "*" gnus-summary-limit-include-cached
1907   "D" gnus-summary-limit-include-dormant
1908   "T" gnus-summary-limit-include-thread
1909   "d" gnus-summary-limit-exclude-dormant
1910   "t" gnus-summary-limit-to-age
1911   "." gnus-summary-limit-to-unseen
1912   "x" gnus-summary-limit-to-extra
1913   "p" gnus-summary-limit-to-display-predicate
1914   "E" gnus-summary-limit-include-expunged
1915   "c" gnus-summary-limit-exclude-childless-dormant
1916   "C" gnus-summary-limit-mark-excluded-as-read
1917   "o" gnus-summary-insert-old-articles
1918   "N" gnus-summary-insert-new-articles
1919   "S" gnus-summary-limit-to-singletons
1920   "r" gnus-summary-limit-to-replied
1921   "R" gnus-summary-limit-to-recipient
1922   "A" gnus-summary-limit-to-address)
1923
1924 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1925   "n" gnus-summary-next-unread-article
1926   "p" gnus-summary-prev-unread-article
1927   "N" gnus-summary-next-article
1928   "P" gnus-summary-prev-article
1929   "\C-n" gnus-summary-next-same-subject
1930   "\C-p" gnus-summary-prev-same-subject
1931   "\M-n" gnus-summary-next-unread-subject
1932   "\M-p" gnus-summary-prev-unread-subject
1933   "f" gnus-summary-first-unread-article
1934   "b" gnus-summary-best-unread-article
1935   "j" gnus-summary-goto-article
1936   "g" gnus-summary-goto-subject
1937   "l" gnus-summary-goto-last-article
1938   "o" gnus-summary-pop-article)
1939
1940 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1941   "k" gnus-summary-kill-thread
1942   "l" gnus-summary-lower-thread
1943   "i" gnus-summary-raise-thread
1944   "T" gnus-summary-toggle-threads
1945   "t" gnus-summary-rethread-current
1946   "^" gnus-summary-reparent-thread
1947   "\M-^" gnus-summary-reparent-children
1948   "s" gnus-summary-show-thread
1949   "S" gnus-summary-show-all-threads
1950   "h" gnus-summary-hide-thread
1951   "H" gnus-summary-hide-all-threads
1952   "n" gnus-summary-next-thread
1953   "p" gnus-summary-prev-thread
1954   "u" gnus-summary-up-thread
1955   "o" gnus-summary-top-thread
1956   "d" gnus-summary-down-thread
1957   "#" gnus-uu-mark-thread
1958   "\M-#" gnus-uu-unmark-thread)
1959
1960 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1961   "g" gnus-summary-prepare
1962   "c" gnus-summary-insert-cached-articles
1963   "d" gnus-summary-insert-dormant-articles
1964   "t" gnus-summary-insert-ticked-articles)
1965
1966 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1967   "c" gnus-summary-catchup-and-exit
1968   "C" gnus-summary-catchup-all-and-exit
1969   "E" gnus-summary-exit-no-update
1970   "Q" gnus-summary-exit
1971   "Z" gnus-summary-exit
1972   "n" gnus-summary-catchup-and-goto-next-group
1973   "p" gnus-summary-catchup-and-goto-prev-group
1974   "R" gnus-summary-reselect-current-group
1975   "G" gnus-summary-rescan-group
1976   "N" gnus-summary-next-group
1977   "s" gnus-summary-save-newsrc
1978   "P" gnus-summary-prev-group)
1979
1980 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1981   " " gnus-summary-next-page
1982   "n" gnus-summary-next-page
1983   "\177" gnus-summary-prev-page
1984   [delete] gnus-summary-prev-page
1985   "p" gnus-summary-prev-page
1986   "\r" gnus-summary-scroll-up
1987   "\M-\r" gnus-summary-scroll-down
1988   "<" gnus-summary-beginning-of-article
1989   ">" gnus-summary-end-of-article
1990   "b" gnus-summary-beginning-of-article
1991   "e" gnus-summary-end-of-article
1992   "^" gnus-summary-refer-parent-article
1993   "r" gnus-summary-refer-parent-article
1994   "D" gnus-summary-enter-digest-group
1995   "R" gnus-summary-refer-references
1996   "T" gnus-summary-refer-thread
1997   "g" gnus-summary-show-article
1998   "s" gnus-summary-isearch-article
1999   "P" gnus-summary-print-article
2000   "M" gnus-mailing-list-insinuate
2001   "t" gnus-article-babel)
2002
2003 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2004   "b" gnus-article-add-buttons
2005   "B" gnus-article-add-buttons-to-head
2006   "o" gnus-article-treat-overstrike
2007   "e" gnus-article-emphasize
2008   "w" gnus-article-fill-cited-article
2009   "Q" gnus-article-fill-long-lines
2010   "L" gnus-article-toggle-truncate-lines
2011   "C" gnus-article-capitalize-sentences
2012   "c" gnus-article-remove-cr
2013   "q" gnus-article-de-quoted-unreadable
2014   "6" gnus-article-de-base64-unreadable
2015   "Z" gnus-article-decode-HZ
2016   "A" gnus-article-treat-ansi-sequences
2017   "h" gnus-article-wash-html
2018   "u" gnus-article-unsplit-urls
2019   "s" gnus-summary-force-verify-and-decrypt
2020   "f" gnus-article-display-x-face
2021   "l" gnus-summary-stop-page-breaking
2022   "r" gnus-summary-caesar-message
2023   "m" gnus-summary-morse-message
2024   "t" gnus-summary-toggle-header
2025   "g" gnus-treat-smiley
2026   "v" gnus-summary-verbose-headers
2027   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2028   "p" gnus-article-verify-x-pgp-sig
2029   "d" gnus-article-treat-dumbquotes
2030   "i" gnus-summary-idna-message)
2031
2032 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2033   ;; mnemonic: deuglif*Y*
2034   "u" gnus-article-outlook-unwrap-lines
2035   "a" gnus-article-outlook-repair-attribution
2036   "c" gnus-article-outlook-rearrange-citation
2037   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2038
2039 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2040   "a" gnus-article-hide
2041   "h" gnus-article-hide-headers
2042   "b" gnus-article-hide-boring-headers
2043   "s" gnus-article-hide-signature
2044   "c" gnus-article-hide-citation
2045   "C" gnus-article-hide-citation-in-followups
2046   "l" gnus-article-hide-list-identifiers
2047   "B" gnus-article-strip-banner
2048   "P" gnus-article-hide-pem
2049   "\C-c" gnus-article-hide-citation-maybe)
2050
2051 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2052   "a" gnus-article-highlight
2053   "h" gnus-article-highlight-headers
2054   "c" gnus-article-highlight-citation
2055   "s" gnus-article-highlight-signature)
2056
2057 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2058   "f" gnus-article-treat-fold-headers
2059   "u" gnus-article-treat-unfold-headers
2060   "n" gnus-article-treat-fold-newsgroups)
2061
2062 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2063   "x" gnus-article-display-x-face
2064   "d" gnus-article-display-face
2065   "s" gnus-treat-smiley
2066   "D" gnus-article-remove-images
2067   "f" gnus-treat-from-picon
2068   "m" gnus-treat-mail-picon
2069   "n" gnus-treat-newsgroups-picon)
2070
2071 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2072   "w" gnus-article-decode-mime-words
2073   "c" gnus-article-decode-charset
2074   "v" gnus-mime-view-all-parts
2075   "b" gnus-article-view-part)
2076
2077 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2078   "z" gnus-article-date-ut
2079   "u" gnus-article-date-ut
2080   "l" gnus-article-date-local
2081   "p" gnus-article-date-english
2082   "e" gnus-article-date-lapsed
2083   "o" gnus-article-date-original
2084   "i" gnus-article-date-iso8601
2085   "s" gnus-article-date-user)
2086
2087 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2088   "t" gnus-article-remove-trailing-blank-lines
2089   "l" gnus-article-strip-leading-blank-lines
2090   "m" gnus-article-strip-multiple-blank-lines
2091   "a" gnus-article-strip-blank-lines
2092   "A" gnus-article-strip-all-blank-lines
2093   "s" gnus-article-strip-leading-space
2094   "e" gnus-article-strip-trailing-space
2095   "w" gnus-article-remove-leading-whitespace)
2096
2097 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2098   "v" gnus-version
2099   "f" gnus-summary-fetch-faq
2100   "d" gnus-summary-describe-group
2101   "h" gnus-summary-describe-briefly
2102   "i" gnus-info-find-node
2103   "c" gnus-group-fetch-charter
2104   "C" gnus-group-fetch-control)
2105
2106 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2107   "e" gnus-summary-expire-articles
2108   "\M-\C-e" gnus-summary-expire-articles-now
2109   "\177" gnus-summary-delete-article
2110   [delete] gnus-summary-delete-article
2111   [backspace] gnus-summary-delete-article
2112   "m" gnus-summary-move-article
2113   "r" gnus-summary-respool-article
2114   "w" gnus-summary-edit-article
2115   "c" gnus-summary-copy-article
2116   "B" gnus-summary-crosspost-article
2117   "q" gnus-summary-respool-query
2118   "t" gnus-summary-respool-trace
2119   "i" gnus-summary-import-article
2120   "I" gnus-summary-create-article
2121   "p" gnus-summary-article-posted-p)
2122
2123 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2124   "o" gnus-summary-save-article
2125   "m" gnus-summary-save-article-mail
2126   "F" gnus-summary-write-article-file
2127   "r" gnus-summary-save-article-rmail
2128   "f" gnus-summary-save-article-file
2129   "b" gnus-summary-save-article-body-file
2130   "B" gnus-summary-write-article-body-file
2131   "h" gnus-summary-save-article-folder
2132   "v" gnus-summary-save-article-vm
2133   "p" gnus-summary-pipe-output
2134   "P" gnus-summary-muttprint
2135   "s" gnus-soup-add-article)
2136
2137 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2138   "b" gnus-summary-display-buttonized
2139   "m" gnus-summary-repair-multipart
2140   "v" gnus-article-view-part
2141   "o" gnus-article-save-part
2142   "O" gnus-article-save-part-and-strip
2143   "r" gnus-article-replace-part
2144   "d" gnus-article-delete-part
2145   "t" gnus-article-view-part-as-type
2146   "j" gnus-article-jump-to-part
2147   "c" gnus-article-copy-part
2148   "C" gnus-article-view-part-as-charset
2149   "e" gnus-article-view-part-externally
2150   "H" gnus-article-browse-html-article
2151   "E" gnus-article-encrypt-body
2152   "i" gnus-article-inline-part
2153   "|" gnus-article-pipe-part)
2154
2155 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2156   "p" gnus-summary-mark-as-processable
2157   "u" gnus-summary-unmark-as-processable
2158   "U" gnus-summary-unmark-all-processable
2159   "v" gnus-uu-mark-over
2160   "s" gnus-uu-mark-series
2161   "r" gnus-uu-mark-region
2162   "g" gnus-uu-unmark-region
2163   "R" gnus-uu-mark-by-regexp
2164   "G" gnus-uu-unmark-by-regexp
2165   "t" gnus-uu-mark-thread
2166   "T" gnus-uu-unmark-thread
2167   "a" gnus-uu-mark-all
2168   "b" gnus-uu-mark-buffer
2169   "S" gnus-uu-mark-sparse
2170   "k" gnus-summary-kill-process-mark
2171   "y" gnus-summary-yank-process-mark
2172   "w" gnus-summary-save-process-mark
2173   "i" gnus-uu-invert-processable)
2174
2175 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2176   ;;"x" gnus-uu-extract-any
2177   "m" gnus-summary-save-parts
2178   "u" gnus-uu-decode-uu
2179   "U" gnus-uu-decode-uu-and-save
2180   "s" gnus-uu-decode-unshar
2181   "S" gnus-uu-decode-unshar-and-save
2182   "o" gnus-uu-decode-save
2183   "O" gnus-uu-decode-save
2184   "b" gnus-uu-decode-binhex
2185   "B" gnus-uu-decode-binhex
2186   "p" gnus-uu-decode-postscript
2187   "P" gnus-uu-decode-postscript-and-save)
2188
2189 (gnus-define-keys
2190     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2191   "u" gnus-uu-decode-uu-view
2192   "U" gnus-uu-decode-uu-and-save-view
2193   "s" gnus-uu-decode-unshar-view
2194   "S" gnus-uu-decode-unshar-and-save-view
2195   "o" gnus-uu-decode-save-view
2196   "O" gnus-uu-decode-save-view
2197   "b" gnus-uu-decode-binhex-view
2198   "B" gnus-uu-decode-binhex-view
2199   "p" gnus-uu-decode-postscript-view
2200   "P" gnus-uu-decode-postscript-and-save-view)
2201
2202 (defvar gnus-article-post-menu nil)
2203
2204 (defconst gnus-summary-menu-maxlen 20)
2205
2206 (defun gnus-summary-menu-split (menu)
2207   ;; If we have lots of elements, divide them into groups of 20
2208   ;; and make a pane (or submenu) for each one.
2209   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2210       (let ((menu menu) sublists next
2211             (i 1))
2212         (while menu
2213           ;; Pull off the next gnus-summary-menu-maxlen elements
2214           ;; and make them the next element of sublist.
2215           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2216           (if next
2217               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2218                       nil))
2219           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2220                                              (aref (car (last menu)) 0)) menu)
2221                                sublists))
2222           (setq i (1+ i))
2223           (setq menu next))
2224         (nreverse sublists))
2225     ;; Few elements--put them all in one pane.
2226     menu))
2227
2228 (defun gnus-summary-make-menu-bar ()
2229   (gnus-turn-off-edit-menu 'summary)
2230
2231   (unless (boundp 'gnus-summary-misc-menu)
2232
2233     (easy-menu-define
2234       gnus-summary-kill-menu gnus-summary-mode-map ""
2235       (cons
2236        "Score"
2237        (nconc
2238         (list
2239          ["Customize" gnus-score-customize t])
2240         (gnus-make-score-map 'increase)
2241         (gnus-make-score-map 'lower)
2242         '(("Mark"
2243            ["Kill below" gnus-summary-kill-below t]
2244            ["Mark above" gnus-summary-mark-above t]
2245            ["Tick above" gnus-summary-tick-above t]
2246            ["Clear above" gnus-summary-clear-above t])
2247           ["Current score" gnus-summary-current-score t]
2248           ["Set score" gnus-summary-set-score t]
2249           ["Switch current score file..." gnus-score-change-score-file t]
2250           ["Set mark below..." gnus-score-set-mark-below t]
2251           ["Set expunge below..." gnus-score-set-expunge-below t]
2252           ["Edit current score file" gnus-score-edit-current-scores t]
2253           ["Edit score file" gnus-score-edit-file t]
2254           ["Trace score" gnus-score-find-trace t]
2255           ["Find words" gnus-score-find-favourite-words t]
2256           ["Rescore buffer" gnus-summary-rescore t]
2257           ["Increase score..." gnus-summary-increase-score t]
2258           ["Lower score..." gnus-summary-lower-score t]))))
2259
2260     ;; Define both the Article menu in the summary buffer and the
2261     ;; equivalent Commands menu in the article buffer here for
2262     ;; consistency.
2263     (let ((innards
2264            `(("Hide"
2265               ["All" gnus-article-hide t]
2266               ["Headers" gnus-article-hide-headers t]
2267               ["Signature" gnus-article-hide-signature t]
2268               ["Citation" gnus-article-hide-citation t]
2269               ["List identifiers" gnus-article-hide-list-identifiers t]
2270               ["Banner" gnus-article-strip-banner t]
2271               ["Boring headers" gnus-article-hide-boring-headers t])
2272              ("Highlight"
2273               ["All" gnus-article-highlight t]
2274               ["Headers" gnus-article-highlight-headers t]
2275               ["Signature" gnus-article-highlight-signature t]
2276               ["Citation" gnus-article-highlight-citation t])
2277              ("MIME"
2278               ["Words" gnus-article-decode-mime-words t]
2279               ["Charset" gnus-article-decode-charset t]
2280               ["QP" gnus-article-de-quoted-unreadable t]
2281               ["Base64" gnus-article-de-base64-unreadable t]
2282               ["View MIME buttons" gnus-summary-display-buttonized t]
2283               ["View all" gnus-mime-view-all-parts t]
2284               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2285               ["Encrypt body" gnus-article-encrypt-body
2286                :active (not (gnus-group-read-only-p))
2287                ,@(if (featurep 'xemacs) nil
2288                    '(:help "Encrypt the message body on disk"))]
2289               ["Extract all parts..." gnus-summary-save-parts t]
2290               ("Multipart"
2291                ["Repair multipart" gnus-summary-repair-multipart t]
2292                ["Pipe part..." gnus-article-pipe-part t]
2293                ["Inline part" gnus-article-inline-part t]
2294                ["View part as type..." gnus-article-view-part-as-type t]
2295                ["Encrypt body" gnus-article-encrypt-body
2296                 :active (not (gnus-group-read-only-p))
2297                ,@(if (featurep 'xemacs) nil
2298                    '(:help "Encrypt the message body on disk"))]
2299                ["View part externally" gnus-article-view-part-externally t]
2300                ["View HTML parts in browser" gnus-article-browse-html-article t]
2301                ["View part with charset..." gnus-article-view-part-as-charset t]
2302                ["Copy part" gnus-article-copy-part t]
2303                ["Save part..." gnus-article-save-part t]
2304                ["View part" gnus-article-view-part t]))
2305              ("Date"
2306               ["Local" gnus-article-date-local t]
2307               ["ISO8601" gnus-article-date-iso8601 t]
2308               ["UT" gnus-article-date-ut t]
2309               ["Original" gnus-article-date-original t]
2310               ["Lapsed" gnus-article-date-lapsed t]
2311               ["User-defined" gnus-article-date-user t])
2312              ("Display"
2313               ["Remove images" gnus-article-remove-images t]
2314               ["Toggle smiley" gnus-treat-smiley t]
2315               ["Show X-Face" gnus-article-display-x-face t]
2316               ["Show picons in From" gnus-treat-from-picon t]
2317               ["Show picons in mail headers" gnus-treat-mail-picon t]
2318               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2319               ("View as different encoding"
2320                ,@(gnus-summary-menu-split
2321                   (mapcar
2322                    (lambda (cs)
2323                      ;; Since easymenu under Emacs doesn't allow
2324                      ;; lambda forms for menu commands, we should
2325                      ;; provide intern'ed function symbols.
2326                      (let ((command (intern (format "\
2327 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2328                        (fset command
2329                              `(lambda ()
2330                                 (interactive)
2331                                 (let ((gnus-summary-show-article-charset-alist
2332                                        '((1 . ,cs))))
2333                                   (gnus-summary-show-article 1))))
2334                        `[,(symbol-name cs) ,command t]))
2335                    (sort (if (fboundp 'coding-system-list)
2336                              (coding-system-list)
2337                            (mapcar 'car mm-mime-mule-charset-alist))
2338                          'string<)))))
2339              ("Washing"
2340               ("Remove Blanks"
2341                ["Leading" gnus-article-strip-leading-blank-lines t]
2342                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2343                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2344                ["All of the above" gnus-article-strip-blank-lines t]
2345                ["All" gnus-article-strip-all-blank-lines t]
2346                ["Leading space" gnus-article-strip-leading-space t]
2347                ["Trailing space" gnus-article-strip-trailing-space t]
2348                ["Leading space in headers"
2349                 gnus-article-remove-leading-whitespace t])
2350               ["Overstrike" gnus-article-treat-overstrike t]
2351               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2352               ["Emphasis" gnus-article-emphasize t]
2353               ["Word wrap" gnus-article-fill-cited-article t]
2354               ["Fill long lines" gnus-article-fill-long-lines t]
2355               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2356               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2357               ["Remove CR" gnus-article-remove-cr t]
2358               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2359               ["Base64" gnus-article-de-base64-unreadable t]
2360               ["Rot 13" gnus-summary-caesar-message
2361                ,@(if (featurep 'xemacs) '(t)
2362                    '(:help "\"Caesar rotate\" article by 13"))]
2363               ["De-IDNA" gnus-summary-idna-message t]
2364               ["Morse decode" gnus-summary-morse-message t]
2365               ["Unix pipe..." gnus-summary-pipe-message t]
2366               ["Add buttons" gnus-article-add-buttons t]
2367               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2368               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2369               ["Verbose header" gnus-summary-verbose-headers t]
2370               ["Toggle header" gnus-summary-toggle-header t]
2371               ["Unfold headers" gnus-article-treat-unfold-headers t]
2372               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2373               ["Html" gnus-article-wash-html t]
2374               ["Unsplit URLs" gnus-article-unsplit-urls t]
2375               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2376               ["Decode HZ" gnus-article-decode-HZ t]
2377               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2378               ("(Outlook) Deuglify"
2379                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2380                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2381                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2382                ["Full (Outlook) deuglify"
2383                 gnus-article-outlook-deuglify-article t])
2384               )
2385              ("Output"
2386               ["Save in default format..." gnus-summary-save-article
2387                ,@(if (featurep 'xemacs) '(t)
2388                    '(:help "Save article using default method"))]
2389               ["Save in file..." gnus-summary-save-article-file
2390                ,@(if (featurep 'xemacs) '(t)
2391                    '(:help "Save article in file"))]
2392               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2393               ["Save in MH folder..." gnus-summary-save-article-folder t]
2394               ["Save in VM folder..." gnus-summary-save-article-vm t]
2395               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2396               ["Save body in file..." gnus-summary-save-article-body-file t]
2397               ["Pipe through a filter..." gnus-summary-pipe-output t]
2398               ["Add to SOUP packet" gnus-soup-add-article t]
2399               ["Print with Muttprint..." gnus-summary-muttprint t]
2400               ["Print" gnus-summary-print-article
2401                ,@(if (featurep 'xemacs) '(t)
2402                    '(:help "Generate and print a PostScript image"))])
2403              ("Copy, move,... (Backend)"
2404               ,@(if (featurep 'xemacs) nil
2405                   '(:help "Copying, moving, expiring articles..."))
2406               ["Respool article..." gnus-summary-respool-article t]
2407               ["Move article..." gnus-summary-move-article
2408                (gnus-check-backend-function
2409                 'request-move-article gnus-newsgroup-name)]
2410               ["Copy article..." gnus-summary-copy-article t]
2411               ["Crosspost article..." gnus-summary-crosspost-article
2412                (gnus-check-backend-function
2413                 'request-replace-article gnus-newsgroup-name)]
2414               ["Import file..." gnus-summary-import-article
2415                (gnus-check-backend-function
2416                 'request-accept-article gnus-newsgroup-name)]
2417               ["Create article..." gnus-summary-create-article
2418                (gnus-check-backend-function
2419                 'request-accept-article gnus-newsgroup-name)]
2420               ["Check if posted" gnus-summary-article-posted-p t]
2421               ["Edit article" gnus-summary-edit-article
2422                (not (gnus-group-read-only-p))]
2423               ["Delete article" gnus-summary-delete-article
2424                (gnus-check-backend-function
2425                 'request-expire-articles gnus-newsgroup-name)]
2426               ["Query respool" gnus-summary-respool-query t]
2427               ["Trace respool" gnus-summary-respool-trace t]
2428               ["Delete expirable articles" gnus-summary-expire-articles-now
2429                (gnus-check-backend-function
2430                 'request-expire-articles gnus-newsgroup-name)])
2431              ("Extract"
2432               ["Uudecode" gnus-uu-decode-uu
2433                ,@(if (featurep 'xemacs) '(t)
2434                    '(:help "Decode uuencoded article(s)"))]
2435               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2436               ["Unshar" gnus-uu-decode-unshar t]
2437               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2438               ["Save" gnus-uu-decode-save t]
2439               ["Binhex" gnus-uu-decode-binhex t]
2440               ["Postscript" gnus-uu-decode-postscript t]
2441               ["All MIME parts" gnus-summary-save-parts t])
2442              ("Cache"
2443               ["Enter article" gnus-cache-enter-article t]
2444               ["Remove article" gnus-cache-remove-article t])
2445              ["Translate" gnus-article-babel t]
2446              ["Select article buffer" gnus-summary-select-article-buffer t]
2447              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2448              ["Isearch article..." gnus-summary-isearch-article t]
2449              ["Beginning of the article" gnus-summary-beginning-of-article t]
2450              ["End of the article" gnus-summary-end-of-article t]
2451              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2452              ["Fetch referenced articles" gnus-summary-refer-references t]
2453              ["Fetch current thread" gnus-summary-refer-thread t]
2454              ["Fetch article with id..." gnus-summary-refer-article t]
2455              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2456              ["Redisplay" gnus-summary-show-article t]
2457              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2458       (easy-menu-define
2459         gnus-summary-article-menu gnus-summary-mode-map ""
2460         (cons "Article" innards))
2461
2462       (if (not (keymapp gnus-summary-article-menu))
2463           (easy-menu-define
2464             gnus-article-commands-menu gnus-article-mode-map ""
2465             (cons "Commands" innards))
2466         ;; in Emacs, don't share menu.
2467         (setq gnus-article-commands-menu
2468               (copy-keymap gnus-summary-article-menu))
2469         (define-key gnus-article-mode-map [menu-bar commands]
2470           (cons "Commands" gnus-article-commands-menu))))
2471
2472     (easy-menu-define
2473       gnus-summary-thread-menu gnus-summary-mode-map ""
2474       '("Threads"
2475         ["Find all messages in thread" gnus-summary-refer-thread t]
2476         ["Toggle threading" gnus-summary-toggle-threads t]
2477         ["Hide threads" gnus-summary-hide-all-threads t]
2478         ["Show threads" gnus-summary-show-all-threads t]
2479         ["Hide thread" gnus-summary-hide-thread t]
2480         ["Show thread" gnus-summary-show-thread t]
2481         ["Go to next thread" gnus-summary-next-thread t]
2482         ["Go to previous thread" gnus-summary-prev-thread t]
2483         ["Go down thread" gnus-summary-down-thread t]
2484         ["Go up thread" gnus-summary-up-thread t]
2485         ["Top of thread" gnus-summary-top-thread t]
2486         ["Mark thread as read" gnus-summary-kill-thread t]
2487         ["Lower thread score" gnus-summary-lower-thread t]
2488         ["Raise thread score" gnus-summary-raise-thread t]
2489         ["Rethread current" gnus-summary-rethread-current t]))
2490
2491     (easy-menu-define
2492       gnus-summary-post-menu gnus-summary-mode-map ""
2493       `("Post"
2494         ["Send a message (mail or news)" gnus-summary-post-news
2495          ,@(if (featurep 'xemacs) '(t)
2496              '(:help "Compose a new message (mail or news)"))]
2497         ["Followup" gnus-summary-followup
2498          ,@(if (featurep 'xemacs) '(t)
2499              '(:help "Post followup to this article"))]
2500         ["Followup and yank" gnus-summary-followup-with-original
2501          ,@(if (featurep 'xemacs) '(t)
2502              '(:help "Post followup to this article, quoting its contents"))]
2503         ["Supersede article" gnus-summary-supersede-article t]
2504         ["Cancel article" gnus-summary-cancel-article
2505          ,@(if (featurep 'xemacs) '(t)
2506              '(:help "Cancel an article you posted"))]
2507         ["Reply" gnus-summary-reply t]
2508         ["Reply and yank" gnus-summary-reply-with-original t]
2509         ["Wide reply" gnus-summary-wide-reply t]
2510         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2511          ,@(if (featurep 'xemacs) '(t)
2512              '(:help "Mail a reply, quoting this article"))]
2513         ["Very wide reply" gnus-summary-very-wide-reply t]
2514         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2515          ,@(if (featurep 'xemacs) '(t)
2516              '(:help "Mail a very wide reply, quoting this article"))]
2517         ["Mail forward" gnus-summary-mail-forward t]
2518         ["Post forward" gnus-summary-post-forward t]
2519         ["Digest and mail" gnus-uu-digest-mail-forward t]
2520         ["Digest and post" gnus-uu-digest-post-forward t]
2521         ["Resend message" gnus-summary-resend-message t]
2522         ["Resend message edit" gnus-summary-resend-message-edit t]
2523         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2524         ["Send a mail" gnus-summary-mail-other-window t]
2525         ["Create a local message" gnus-summary-news-other-window t]
2526         ["Uuencode and post" gnus-uu-post-news
2527          ,@(if (featurep 'xemacs) '(t)
2528              '(:help "Post a uuencoded article"))]
2529         ["Followup via news" gnus-summary-followup-to-mail t]
2530         ["Followup via news and yank"
2531          gnus-summary-followup-to-mail-with-original t]
2532         ;;("Draft"
2533         ;;["Send" gnus-summary-send-draft t]
2534         ;;["Send bounced" gnus-resend-bounced-mail t])
2535         ))
2536
2537     (cond
2538      ((not (keymapp gnus-summary-post-menu))
2539       (setq gnus-article-post-menu gnus-summary-post-menu))
2540      ((not gnus-article-post-menu)
2541       ;; Don't share post menu.
2542       (setq gnus-article-post-menu
2543             (copy-keymap gnus-summary-post-menu))))
2544     (define-key gnus-article-mode-map [menu-bar post]
2545       (cons "Post" gnus-article-post-menu))
2546
2547     (easy-menu-define
2548       gnus-summary-misc-menu gnus-summary-mode-map ""
2549       `("Gnus"
2550         ("Mark Read"
2551          ["Mark as read" gnus-summary-mark-as-read-forward t]
2552          ["Mark same subject and select"
2553           gnus-summary-kill-same-subject-and-select t]
2554          ["Mark same subject" gnus-summary-kill-same-subject t]
2555          ["Catchup" gnus-summary-catchup
2556           ,@(if (featurep 'xemacs) '(t)
2557               '(:help "Mark unread articles in this group as read"))]
2558          ["Catchup all" gnus-summary-catchup-all t]
2559          ["Catchup to here" gnus-summary-catchup-to-here t]
2560          ["Catchup from here" gnus-summary-catchup-from-here t]
2561          ["Catchup region" gnus-summary-mark-region-as-read
2562           (gnus-mark-active-p)]
2563          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2564         ("Mark Various"
2565          ["Tick" gnus-summary-tick-article-forward t]
2566          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2567          ["Remove marks" gnus-summary-clear-mark-forward t]
2568          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2569          ["Set bookmark" gnus-summary-set-bookmark t]
2570          ["Remove bookmark" gnus-summary-remove-bookmark t])
2571         ("Limit to"
2572          ["Marks..." gnus-summary-limit-to-marks t]
2573          ["Subject..." gnus-summary-limit-to-subject t]
2574          ["Author..." gnus-summary-limit-to-author t]
2575          ["Recipient..." gnus-summary-limit-to-recipient t]
2576          ["Address..." gnus-summary-limit-to-address t]
2577          ["Age..." gnus-summary-limit-to-age t]
2578          ["Extra..." gnus-summary-limit-to-extra t]
2579          ["Score..." gnus-summary-limit-to-score t]
2580          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2581          ["Unread" gnus-summary-limit-to-unread t]
2582          ["Unseen" gnus-summary-limit-to-unseen t]
2583          ["Singletons" gnus-summary-limit-to-singletons t]
2584          ["Replied" gnus-summary-limit-to-replied t]
2585          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2586          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2587          ["Pop limit" gnus-summary-pop-limit t]
2588          ["Show dormant" gnus-summary-limit-include-dormant t]
2589          ["Hide childless dormant"
2590           gnus-summary-limit-exclude-childless-dormant t]
2591          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2592          ["Hide marked" gnus-summary-limit-exclude-marks t]
2593          ["Show expunged" gnus-summary-limit-include-expunged t])
2594         ("Process Mark"
2595          ["Set mark" gnus-summary-mark-as-processable t]
2596          ["Remove mark" gnus-summary-unmark-as-processable t]
2597          ["Remove all marks" gnus-summary-unmark-all-processable t]
2598          ["Invert marks" gnus-uu-invert-processable t]
2599          ["Mark above" gnus-uu-mark-over t]
2600          ["Mark series" gnus-uu-mark-series t]
2601          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2602          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2603          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2604          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2605          ["Mark all" gnus-uu-mark-all t]
2606          ["Mark buffer" gnus-uu-mark-buffer t]
2607          ["Mark sparse" gnus-uu-mark-sparse t]
2608          ["Mark thread" gnus-uu-mark-thread t]
2609          ["Unmark thread" gnus-uu-unmark-thread t]
2610          ("Process Mark Sets"
2611           ["Kill" gnus-summary-kill-process-mark t]
2612           ["Yank" gnus-summary-yank-process-mark
2613            gnus-newsgroup-process-stack]
2614           ["Save" gnus-summary-save-process-mark t]
2615           ["Run command on marked..." gnus-summary-universal-argument t]))
2616         ("Scroll article"
2617          ["Page forward" gnus-summary-next-page
2618           ,@(if (featurep 'xemacs) '(t)
2619               '(:help "Show next page of article"))]
2620          ["Page backward" gnus-summary-prev-page
2621           ,@(if (featurep 'xemacs) '(t)
2622               '(:help "Show previous page of article"))]
2623          ["Line forward" gnus-summary-scroll-up t])
2624         ("Move"
2625          ["Next unread article" gnus-summary-next-unread-article t]
2626          ["Previous unread article" gnus-summary-prev-unread-article t]
2627          ["Next article" gnus-summary-next-article t]
2628          ["Previous article" gnus-summary-prev-article t]
2629          ["Next unread subject" gnus-summary-next-unread-subject t]
2630          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2631          ["Next article same subject" gnus-summary-next-same-subject t]
2632          ["Previous article same subject" gnus-summary-prev-same-subject t]
2633          ["First unread article" gnus-summary-first-unread-article t]
2634          ["Best unread article" gnus-summary-best-unread-article t]
2635          ["Go to subject number..." gnus-summary-goto-subject t]
2636          ["Go to article number..." gnus-summary-goto-article t]
2637          ["Go to the last article" gnus-summary-goto-last-article t]
2638          ["Pop article off history" gnus-summary-pop-article t])
2639         ("Sort"
2640          ["Sort by number" gnus-summary-sort-by-number t]
2641          ["Sort by author" gnus-summary-sort-by-author t]
2642          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2643          ["Sort by subject" gnus-summary-sort-by-subject t]
2644          ["Sort by date" gnus-summary-sort-by-date t]
2645          ["Sort by score" gnus-summary-sort-by-score t]
2646          ["Sort by lines" gnus-summary-sort-by-lines t]
2647          ["Sort by characters" gnus-summary-sort-by-chars t]
2648          ["Randomize" gnus-summary-sort-by-random t]
2649          ["Original sort" gnus-summary-sort-by-original t])
2650         ("Help"
2651          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2652          ["Describe group" gnus-summary-describe-group t]
2653          ["Fetch charter" gnus-group-fetch-charter
2654           ,@(if (featurep 'xemacs) nil
2655               '(:help "Display the charter of the current group"))]
2656          ["Fetch control message" gnus-group-fetch-control
2657           ,@(if (featurep 'xemacs) nil
2658               '(:help "Display the archived control message for the current group"))]
2659          ["Read manual" gnus-info-find-node t])
2660         ("Modes"
2661          ["Pick and read" gnus-pick-mode t]
2662          ["Binary" gnus-binary-mode t])
2663         ("Regeneration"
2664          ["Regenerate" gnus-summary-prepare t]
2665          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2666          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2667          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2668          ["Toggle threading" gnus-summary-toggle-threads t])
2669         ["See old articles" gnus-summary-insert-old-articles t]
2670         ["See new articles" gnus-summary-insert-new-articles t]
2671         ["Filter articles..." gnus-summary-execute-command t]
2672         ["Run command on articles..." gnus-summary-universal-argument t]
2673         ["Search articles forward..." gnus-summary-search-article-forward t]
2674         ["Search articles backward..." gnus-summary-search-article-backward t]
2675         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2676         ["Expand window" gnus-summary-expand-window t]
2677         ["Expire expirable articles" gnus-summary-expire-articles
2678          (gnus-check-backend-function
2679           'request-expire-articles gnus-newsgroup-name)]
2680         ["Edit local kill file" gnus-summary-edit-local-kill t]
2681         ["Edit main kill file" gnus-summary-edit-global-kill t]
2682         ["Edit group parameters" gnus-summary-edit-parameters t]
2683         ["Customize group parameters" gnus-summary-customize-parameters t]
2684         ["Send a bug report" gnus-bug t]
2685         ("Exit"
2686          ["Catchup and exit" gnus-summary-catchup-and-exit
2687           ,@(if (featurep 'xemacs) '(t)
2688               '(:help "Mark unread articles in this group as read, then exit"))]
2689          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2690          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2691          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2692          ["Exit group" gnus-summary-exit
2693           ,@(if (featurep 'xemacs) '(t)
2694               '(:help "Exit current group, return to group selection mode"))]
2695          ["Exit group without updating" gnus-summary-exit-no-update t]
2696          ["Exit and goto next group" gnus-summary-next-group t]
2697          ["Exit and goto prev group" gnus-summary-prev-group t]
2698          ["Reselect group" gnus-summary-reselect-current-group t]
2699          ["Rescan group" gnus-summary-rescan-group t]
2700          ["Update dribble" gnus-summary-save-newsrc t])))
2701
2702     (gnus-run-hooks 'gnus-summary-menu-hook)))
2703
2704 (defvar gnus-summary-tool-bar-map nil)
2705
2706 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2707 ;; affect _new_ message buffers.  We might add a function that walks thru all
2708 ;; summary-mode buffers and force the update.
2709 (defun gnus-summary-tool-bar-update (&optional symbol value)
2710   "Update summary mode toolbar.
2711 Setter function for custom variables."
2712   (setq-default gnus-summary-tool-bar-map nil)
2713   (when symbol
2714     ;; When used as ":set" function:
2715     (set-default symbol value))
2716   (when (gnus-buffer-live-p gnus-summary-buffer)
2717     (with-current-buffer gnus-summary-buffer
2718       (gnus-summary-make-tool-bar))))
2719
2720 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2721                                      'gnus-summary-tool-bar-gnome
2722                                    'gnus-summary-tool-bar-retro)
2723   "Specifies the Gnus summary tool bar.
2724
2725 It can be either a list or a symbol refering to a list.  See
2726 `gmm-tool-bar-from-list' for the format of the list.  The
2727 default key map is `gnus-summary-mode-map'.
2728
2729 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2730 `gnus-summary-tool-bar-retro'."
2731   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2732                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2733                  (repeat :tag "User defined list" gmm-tool-bar-item)
2734                  (symbol))
2735   :version "23.0" ;; No Gnus
2736   :initialize 'custom-initialize-default
2737   :set 'gnus-summary-tool-bar-update
2738   :group 'gnus-summary)
2739
2740 (defcustom gnus-summary-tool-bar-gnome
2741   '((gnus-summary-post-news "mail/compose" nil)
2742     (gnus-summary-insert-new-articles "mail/inbox" nil
2743                                       :visible (or (not gnus-agent)
2744                                                    gnus-plugged))
2745     (gnus-summary-reply-with-original "mail/reply")
2746     (gnus-summary-reply "mail/reply" nil :visible nil)
2747     (gnus-summary-followup-with-original "mail/reply-all")
2748     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2749     (gnus-summary-mail-forward "mail/forward")
2750     (gnus-summary-save-article "mail/save")
2751     (gnus-summary-search-article-forward "search" nil :visible nil)
2752     (gnus-summary-print-article "print")
2753     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2754     ;; Some new commands that may need more suitable icons:
2755     (gnus-summary-save-newsrc "save" nil :visible nil)
2756     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2757     (gnus-summary-prev-article "left-arrow")
2758     (gnus-summary-next-article "right-arrow")
2759     (gnus-summary-next-page "next-page")
2760     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2761     ;;
2762     ;; Maybe some sort-by-... could be added:
2763     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2764     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2765     (gnus-summary-mark-as-expirable
2766      "delete" nil
2767      :visible (gnus-check-backend-function 'request-expire-articles
2768                                            gnus-newsgroup-name))
2769     (gnus-summary-mark-as-spam
2770      "mail/spam" t
2771      :visible (and (fboundp 'spam-group-ham-contents-p)
2772                    (spam-group-ham-contents-p gnus-newsgroup-name))
2773      :help "Mark as spam")
2774     (gnus-summary-mark-as-read-forward
2775      "mail/not-spam" nil
2776      :visible (and (fboundp 'spam-group-spam-contents-p)
2777                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2778     ;;
2779     (gnus-summary-exit "exit")
2780     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2781     (gnus-info-find-node "help"))
2782   "List of functions for the summary tool bar (GNOME style).
2783
2784 See `gmm-tool-bar-from-list' for the format of the list."
2785   :type '(repeat gmm-tool-bar-item)
2786   :version "23.0" ;; No Gnus
2787   :initialize 'custom-initialize-default
2788   :set 'gnus-summary-tool-bar-update
2789   :group 'gnus-summary)
2790
2791 (defcustom gnus-summary-tool-bar-retro
2792   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2793     (gnus-summary-next-unread-article "gnus/next-ur")
2794     (gnus-summary-post-news "gnus/post")
2795     (gnus-summary-followup-with-original "gnus/fuwo")
2796     (gnus-summary-followup "gnus/followup")
2797     (gnus-summary-reply-with-original "gnus/reply-wo")
2798     (gnus-summary-reply "gnus/reply")
2799     (gnus-summary-caesar-message "gnus/rot13")
2800     (gnus-uu-decode-uu "gnus/uu-decode")
2801     (gnus-summary-save-article-file "gnus/save-aif")
2802     (gnus-summary-save-article "gnus/save-art")
2803     (gnus-uu-post-news "gnus/uu-post")
2804     (gnus-summary-catchup "gnus/catchup")
2805     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2806     (gnus-summary-exit "gnus/exit-summ")
2807     ;; Some new command that may need more suitable icons:
2808     (gnus-summary-print-article "gnus/print" nil :visible nil)
2809     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2810     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2811     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2812     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2813     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2814     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2815     ;;
2816     (gnus-info-find-node "gnus/help" nil :visible nil))
2817   "List of functions for the summary tool bar (retro look).
2818
2819 See `gmm-tool-bar-from-list' for the format of the list."
2820   :type '(repeat gmm-tool-bar-item)
2821   :version "23.0" ;; No Gnus
2822   :initialize 'custom-initialize-default
2823   :set 'gnus-summary-tool-bar-update
2824   :group 'gnus-summary)
2825
2826 (defcustom gnus-summary-tool-bar-zap-list t
2827   "List of icon items from the global tool bar.
2828 These items are not displayed in the Gnus summary mode tool bar.
2829
2830 See `gmm-tool-bar-from-list' for the format of the list."
2831   :type 'gmm-tool-bar-zap-list
2832   :version "23.0" ;; No Gnus
2833   :initialize 'custom-initialize-default
2834   :set 'gnus-summary-tool-bar-update
2835   :group 'gnus-summary)
2836
2837 (defvar image-load-path)
2838
2839 (defun gnus-summary-make-tool-bar (&optional force)
2840   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2841 When FORCE, rebuild the tool bar."
2842   (when (and (not (featurep 'xemacs))
2843              (boundp 'tool-bar-mode)
2844              tool-bar-mode
2845              (or (not gnus-summary-tool-bar-map) force))
2846     (let* ((load-path
2847             (gmm-image-load-path-for-library "gnus"
2848                                              "mail/save.xpm"
2849                                              nil t))
2850            (image-load-path (cons (car load-path)
2851                                   (when (boundp 'image-load-path)
2852                                     image-load-path)))
2853            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2854                                         gnus-summary-tool-bar-zap-list
2855                                         'gnus-summary-mode-map)))
2856       (when map
2857         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2858         ;; uses it's value.
2859         (setq gnus-summary-tool-bar-map map))))
2860   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2861
2862 (defun gnus-score-set-default (var value)
2863   "A version of set that updates the GNU Emacs menu-bar."
2864   (set var value)
2865   ;; It is the message that forces the active status to be updated.
2866   (message ""))
2867
2868 (defun gnus-make-score-map (type)
2869   "Make a summary score map of type TYPE."
2870   (if t
2871       nil
2872     (let ((headers '(("author" "from" string)
2873                      ("subject" "subject" string)
2874                      ("article body" "body" string)
2875                      ("article head" "head" string)
2876                      ("xref" "xref" string)
2877                      ("extra header" "extra" string)
2878                      ("lines" "lines" number)
2879                      ("followups to author" "followup" string)))
2880           (types '((number ("less than" <)
2881                            ("greater than" >)
2882                            ("equal" =))
2883                    (string ("substring" s)
2884                            ("exact string" e)
2885                            ("fuzzy string" f)
2886                            ("regexp" r))))
2887           (perms '(("temporary" (current-time-string))
2888                    ("permanent" nil)
2889                    ("immediate" now)))
2890           header)
2891       (list
2892        (apply
2893         'nconc
2894         (list
2895          (if (eq type 'lower)
2896              "Lower score"
2897            "Increase score"))
2898         (let (outh)
2899           (while headers
2900             (setq header (car headers))
2901             (setq outh
2902                   (cons
2903                    (apply
2904                     'nconc
2905                     (list (car header))
2906                     (let ((ts (cdr (assoc (nth 2 header) types)))
2907                           outt)
2908                       (while ts
2909                         (setq outt
2910                               (cons
2911                                (apply
2912                                 'nconc
2913                                 (list (caar ts))
2914                                 (let ((ps perms)
2915                                       outp)
2916                                   (while ps
2917                                     (setq outp
2918                                           (cons
2919                                            (vector
2920                                             (caar ps)
2921                                             (list
2922                                              'gnus-summary-score-entry
2923                                              (nth 1 header)
2924                                              (if (or (string= (nth 1 header)
2925                                                               "head")
2926                                                      (string= (nth 1 header)
2927                                                               "body"))
2928                                                  ""
2929                                                (list 'gnus-summary-header
2930                                                      (nth 1 header)))
2931                                              (list 'quote (nth 1 (car ts)))
2932                                              (list 'gnus-score-delta-default
2933                                                    nil)
2934                                              (nth 1 (car ps))
2935                                              t)
2936                                             t)
2937                                            outp))
2938                                     (setq ps (cdr ps)))
2939                                   (list (nreverse outp))))
2940                                outt))
2941                         (setq ts (cdr ts)))
2942                       (list (nreverse outt))))
2943                    outh))
2944             (setq headers (cdr headers)))
2945           (list (nreverse outh))))))))
2946
2947 \f
2948
2949 (defun gnus-summary-mode (&optional group)
2950   "Major mode for reading articles.
2951
2952 All normal editing commands are switched off.
2953 \\<gnus-summary-mode-map>
2954 Each line in this buffer represents one article.  To read an
2955 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2956 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2957 respectively.
2958
2959 You can also post articles and send mail from this buffer.  To
2960 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2961 of an article, type `\\[gnus-summary-reply]'.
2962
2963 There are approx. one gazillion commands you can execute in this
2964 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2965
2966 The following commands are available:
2967
2968 \\{gnus-summary-mode-map}"
2969   (interactive)
2970   (kill-all-local-variables)
2971   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2972     (gnus-summary-make-local-variables))
2973   (gnus-summary-make-local-variables)
2974   (setq gnus-newsgroup-name group)
2975   (when (gnus-visual-p 'summary-menu 'menu)
2976     (gnus-summary-make-menu-bar)
2977     (gnus-summary-make-tool-bar))
2978   (gnus-make-thread-indent-array)
2979   (gnus-simplify-mode-line)
2980   (setq major-mode 'gnus-summary-mode)
2981   (setq mode-name "Summary")
2982   (make-local-variable 'minor-mode-alist)
2983   (use-local-map gnus-summary-mode-map)
2984   (buffer-disable-undo)
2985   (setq buffer-read-only t              ;Disable modification
2986         show-trailing-whitespace nil)
2987   (setq truncate-lines t)
2988   (setq selective-display t)
2989   (setq selective-display-ellipses t)   ;Display `...'
2990   (gnus-summary-set-display-table)
2991   (gnus-set-default-directory)
2992   (make-local-variable 'gnus-summary-line-format)
2993   (make-local-variable 'gnus-summary-line-format-spec)
2994   (make-local-variable 'gnus-summary-dummy-line-format)
2995   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2996   (make-local-variable 'gnus-summary-mark-positions)
2997   (gnus-make-local-hook 'pre-command-hook)
2998   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2999   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3000   (turn-on-gnus-mailing-list-mode)
3001   (mm-enable-multibyte)
3002   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3003   (gnus-update-summary-mark-positions))
3004
3005 (defun gnus-summary-make-local-variables ()
3006   "Make all the local summary buffer variables."
3007   (let (global)
3008     (dolist (local gnus-summary-local-variables)
3009       (if (consp local)
3010           (progn
3011             (if (eq (cdr local) 'global)
3012                 ;; Copy the global value of the variable.
3013                 (setq global (symbol-value (car local)))
3014               ;; Use the value from the list.
3015               (setq global (eval (cdr local))))
3016             (set (make-local-variable (car local)) global))
3017         ;; Simple nil-valued local variable.
3018         (set (make-local-variable local) nil)))))
3019
3020 (defun gnus-summary-clear-local-variables ()
3021   (let ((locals gnus-summary-local-variables))
3022     (while locals
3023       (if (consp (car locals))
3024           (and (symbolp (caar locals))
3025                (set (caar locals) nil))
3026         (and (symbolp (car locals))
3027              (set (car locals) nil)))
3028       (setq locals (cdr locals)))))
3029
3030 ;; Summary data functions.
3031
3032 (defmacro gnus-data-number (data)
3033   `(car ,data))
3034
3035 (defmacro gnus-data-set-number (data number)
3036   `(setcar ,data ,number))
3037
3038 (defmacro gnus-data-mark (data)
3039   `(nth 1 ,data))
3040
3041 (defmacro gnus-data-set-mark (data mark)
3042   `(setcar (nthcdr 1 ,data) ,mark))
3043
3044 (defmacro gnus-data-pos (data)
3045   `(nth 2 ,data))
3046
3047 (defmacro gnus-data-set-pos (data pos)
3048   `(setcar (nthcdr 2 ,data) ,pos))
3049
3050 (defmacro gnus-data-header (data)
3051   `(nth 3 ,data))
3052
3053 (defmacro gnus-data-set-header (data header)
3054   `(setf (nth 3 ,data) ,header))
3055
3056 (defmacro gnus-data-level (data)
3057   `(nth 4 ,data))
3058
3059 (defmacro gnus-data-unread-p (data)
3060   `(= (nth 1 ,data) gnus-unread-mark))
3061
3062 (defmacro gnus-data-read-p (data)
3063   `(/= (nth 1 ,data) gnus-unread-mark))
3064
3065 (defmacro gnus-data-pseudo-p (data)
3066   `(consp (nth 3 ,data)))
3067
3068 (defmacro gnus-data-find (number)
3069   `(assq ,number gnus-newsgroup-data))
3070
3071 (defmacro gnus-data-find-list (number &optional data)
3072   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3073      (memq (assq ,number bdata)
3074            bdata)))
3075
3076 (defmacro gnus-data-make (number mark pos header level)
3077   `(list ,number ,mark ,pos ,header ,level))
3078
3079 (defun gnus-data-enter (after-article number mark pos header level offset)
3080   (let ((data (gnus-data-find-list after-article)))
3081     (unless data
3082       (error "No such article: %d" after-article))
3083     (setcdr data (cons (gnus-data-make number mark pos header level)
3084                        (cdr data)))
3085     (setq gnus-newsgroup-data-reverse nil)
3086     (gnus-data-update-list (cddr data) offset)))
3087
3088 (defun gnus-data-enter-list (after-article list &optional offset)
3089   (when list
3090     (let ((data (and after-article (gnus-data-find-list after-article)))
3091           (ilist list))
3092       (if (not (or data
3093                    after-article))
3094           (let ((odata gnus-newsgroup-data))
3095             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3096             (when offset
3097               (gnus-data-update-list odata offset)))
3098         ;; Find the last element in the list to be spliced into the main
3099         ;; list.
3100         (setq list (last list))
3101         (if (not data)
3102             (progn
3103               (setcdr list gnus-newsgroup-data)
3104               (setq gnus-newsgroup-data ilist)
3105               (when offset
3106                 (gnus-data-update-list (cdr list) offset)))
3107           (setcdr list (cdr data))
3108           (setcdr data ilist)
3109           (when offset
3110             (gnus-data-update-list (cdr list) offset))))
3111       (setq gnus-newsgroup-data-reverse nil))))
3112
3113 (defun gnus-data-remove (article &optional offset)
3114   (let ((data gnus-newsgroup-data))
3115     (if (= (gnus-data-number (car data)) article)
3116         (progn
3117           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3118                 gnus-newsgroup-data-reverse nil)
3119           (when offset
3120             (gnus-data-update-list gnus-newsgroup-data offset)))
3121       (while (cdr data)
3122         (when (= (gnus-data-number (cadr data)) article)
3123           (setcdr data (cddr data))
3124           (when offset
3125             (gnus-data-update-list (cdr data) offset))
3126           (setq data nil
3127                 gnus-newsgroup-data-reverse nil))
3128         (setq data (cdr data))))))
3129
3130 (defmacro gnus-data-list (backward)
3131   `(if ,backward
3132        (or gnus-newsgroup-data-reverse
3133            (setq gnus-newsgroup-data-reverse
3134                  (reverse gnus-newsgroup-data)))
3135      gnus-newsgroup-data))
3136
3137 (defun gnus-data-update-list (data offset)
3138   "Add OFFSET to the POS of all data entries in DATA."
3139   (setq gnus-newsgroup-data-reverse nil)
3140   (while data
3141     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3142     (setq data (cdr data))))
3143
3144 (defun gnus-summary-article-pseudo-p (article)
3145   "Say whether this article is a pseudo article or not."
3146   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3147
3148 (defmacro gnus-summary-article-sparse-p (article)
3149   "Say whether this article is a sparse article or not."
3150   `(memq ,article gnus-newsgroup-sparse))
3151
3152 (defmacro gnus-summary-article-ancient-p (article)
3153   "Say whether this article is a sparse article or not."
3154   `(memq ,article gnus-newsgroup-ancient))
3155
3156 (defun gnus-article-parent-p (number)
3157   "Say whether this article is a parent or not."
3158   (let ((data (gnus-data-find-list number)))
3159     (and (cdr data)              ; There has to be an article after...
3160          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3161             (gnus-data-level (nth 1 data))))))
3162
3163 (defun gnus-article-children (number)
3164   "Return a list of all children to NUMBER."
3165   (let* ((data (gnus-data-find-list number))
3166          (level (gnus-data-level (car data)))
3167          children)
3168     (setq data (cdr data))
3169     (while (and data
3170                 (= (gnus-data-level (car data)) (1+ level)))
3171       (push (gnus-data-number (car data)) children)
3172       (setq data (cdr data)))
3173     children))
3174
3175 (defmacro gnus-summary-skip-intangible ()
3176   "If the current article is intangible, then jump to a different article."
3177   '(let ((to (get-text-property (point) 'gnus-intangible)))
3178      (and to (gnus-summary-goto-subject to))))
3179
3180 (defmacro gnus-summary-article-intangible-p ()
3181   "Say whether this article is intangible or not."
3182   '(get-text-property (point) 'gnus-intangible))
3183
3184 (defun gnus-article-read-p (article)
3185   "Say whether ARTICLE is read or not."
3186   (not (or (memq article gnus-newsgroup-marked)
3187            (memq article gnus-newsgroup-spam-marked)
3188            (memq article gnus-newsgroup-unreads)
3189            (memq article gnus-newsgroup-unselected)
3190            (memq article gnus-newsgroup-dormant))))
3191
3192 ;; Some summary mode macros.
3193
3194 (defmacro gnus-summary-article-number ()
3195   "The article number of the article on the current line.
3196 If there isn't an article number here, then we return the current
3197 article number."
3198   '(progn
3199      (gnus-summary-skip-intangible)
3200      (or (get-text-property (point) 'gnus-number)
3201          (gnus-summary-last-subject))))
3202
3203 (defmacro gnus-summary-article-header (&optional number)
3204   "Return the header of article NUMBER."
3205   `(gnus-data-header (gnus-data-find
3206                       ,(or number '(gnus-summary-article-number)))))
3207
3208 (defmacro gnus-summary-thread-level (&optional number)
3209   "Return the level of thread that starts with article NUMBER."
3210   `(if (and (eq gnus-summary-make-false-root 'dummy)
3211             (get-text-property (point) 'gnus-intangible))
3212        0
3213      (gnus-data-level (gnus-data-find
3214                        ,(or number '(gnus-summary-article-number))))))
3215
3216 (defmacro gnus-summary-article-mark (&optional number)
3217   "Return the mark of article NUMBER."
3218   `(gnus-data-mark (gnus-data-find
3219                     ,(or number '(gnus-summary-article-number)))))
3220
3221 (defmacro gnus-summary-article-pos (&optional number)
3222   "Return the position of the line of article NUMBER."
3223   `(gnus-data-pos (gnus-data-find
3224                    ,(or number '(gnus-summary-article-number)))))
3225
3226 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3227 (defmacro gnus-summary-article-subject (&optional number)
3228   "Return current subject string or nil if nothing."
3229   `(let ((headers
3230           ,(if number
3231                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3232              '(gnus-data-header (assq (gnus-summary-article-number)
3233                                       gnus-newsgroup-data)))))
3234      (and headers
3235           (vectorp headers)
3236           (mail-header-subject headers))))
3237
3238 (defmacro gnus-summary-article-score (&optional number)
3239   "Return current article score."
3240   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3241                   gnus-newsgroup-scored))
3242        gnus-summary-default-score 0))
3243
3244 (defun gnus-summary-article-children (&optional number)
3245   "Return a list of article numbers that are children of article NUMBER."
3246   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3247          (level (gnus-data-level (car data)))
3248          l children)
3249     (while (and (setq data (cdr data))
3250                 (> (setq l (gnus-data-level (car data))) level))
3251       (and (= (1+ level) l)
3252            (push (gnus-data-number (car data))
3253                  children)))
3254     (nreverse children)))
3255
3256 (defun gnus-summary-article-parent (&optional number)
3257   "Return the article number of the parent of article NUMBER."
3258   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3259                                     (gnus-data-list t)))
3260          (level (gnus-data-level (car data))))
3261     (if (zerop level)
3262         ()                              ; This is a root.
3263       ;; We search until we find an article with a level less than
3264       ;; this one.  That function has to be the parent.
3265       (while (and (setq data (cdr data))
3266                   (not (< (gnus-data-level (car data)) level))))
3267       (and data (gnus-data-number (car data))))))
3268
3269 (defun gnus-unread-mark-p (mark)
3270   "Say whether MARK is the unread mark."
3271   (= mark gnus-unread-mark))
3272
3273 (defun gnus-read-mark-p (mark)
3274   "Say whether MARK is one of the marks that mark as read.
3275 This is all marks except unread, ticked, dormant, and expirable."
3276   (not (or (= mark gnus-unread-mark)
3277            (= mark gnus-ticked-mark)
3278            (= mark gnus-spam-mark)
3279            (= mark gnus-dormant-mark)
3280            (= mark gnus-expirable-mark))))
3281
3282 (defmacro gnus-article-mark (number)
3283   "Return the MARK of article NUMBER.
3284 This macro should only be used when computing the mark the \"first\"
3285 time; i.e., when generating the summary lines.  After that,
3286 `gnus-summary-article-mark' should be used to examine the
3287 marks of articles."
3288   `(cond
3289     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3290     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3291     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3292     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3293     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3294     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3295     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3296     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3297            gnus-ancient-mark))))
3298
3299 ;; Saving hidden threads.
3300
3301 (defmacro gnus-save-hidden-threads (&rest forms)
3302   "Save hidden threads, eval FORMS, and restore the hidden threads."
3303   (let ((config (make-symbol "config")))
3304     `(let ((,config (gnus-hidden-threads-configuration)))
3305        (unwind-protect
3306            (save-excursion
3307              ,@forms)
3308          (gnus-restore-hidden-threads-configuration ,config)))))
3309 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3310 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3311
3312 (defun gnus-data-compute-positions ()
3313   "Compute the positions of all articles."
3314   (setq gnus-newsgroup-data-reverse nil)
3315   (let ((data gnus-newsgroup-data))
3316     (save-excursion
3317       (gnus-save-hidden-threads
3318         (gnus-summary-show-all-threads)
3319         (goto-char (point-min))
3320         (while data
3321           (while (get-text-property (point) 'gnus-intangible)
3322             (forward-line 1))
3323           (gnus-data-set-pos (car data) (+ (point) 3))
3324           (setq data (cdr data))
3325           (forward-line 1))))))
3326
3327 (defun gnus-hidden-threads-configuration ()
3328   "Return the current hidden threads configuration."
3329   (save-excursion
3330     (let (config)
3331       (goto-char (point-min))
3332       (while (search-forward "\r" nil t)
3333         (push (1- (point)) config))
3334       config)))
3335
3336 (defun gnus-restore-hidden-threads-configuration (config)
3337   "Restore hidden threads configuration from CONFIG."
3338   (save-excursion
3339     (let (point buffer-read-only)
3340       (while (setq point (pop config))
3341         (when (and (< point (point-max))
3342                    (goto-char point)
3343                    (eq (char-after) ?\n))
3344           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3345
3346 ;; Various summary mode internalish functions.
3347
3348 (defun gnus-mouse-pick-article (e)
3349   (interactive "e")
3350   (mouse-set-point e)
3351   (gnus-summary-next-page nil t))
3352
3353 (defun gnus-summary-set-display-table ()
3354   "Change the display table.
3355 Odd characters have a tendency to mess
3356 up nicely formatted displays - we make all possible glyphs
3357 display only a single character."
3358
3359   ;; We start from the standard display table, if any.
3360   (let ((table (or (copy-sequence standard-display-table)
3361                    (make-display-table)))
3362         (i 32))
3363     ;; Nix out all the control chars...
3364     (while (>= (setq i (1- i)) 0)
3365       (aset table i [??]))
3366    ;; ... but not newline and cr, of course.  (cr is necessary for the
3367     ;; selective display).
3368     (aset table ?\n nil)
3369     (aset table ?\r nil)
3370     ;; We keep TAB as well.
3371     (aset table ?\t nil)
3372     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3373     ;; Emacs 23 (unicode), that are not set already.
3374     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3375                  160
3376                256)))
3377       (while (>= (setq i (1- i)) 127)
3378         ;; Only modify if the entry is nil.
3379         (unless (aref table i)
3380           (aset table i [??]))))
3381     (setq buffer-display-table table)))
3382
3383 (defun gnus-summary-set-article-display-arrow (pos)
3384   "Update the overlay arrow to point to line at position POS."
3385   (when (and gnus-summary-display-arrow
3386              (boundp 'overlay-arrow-position)
3387              (boundp 'overlay-arrow-string))
3388     (save-excursion
3389       (goto-char pos)
3390       (beginning-of-line)
3391       (unless overlay-arrow-position
3392         (setq overlay-arrow-position (make-marker)))
3393       (setq overlay-arrow-string "=>"
3394             overlay-arrow-position (set-marker overlay-arrow-position
3395                                                (point)
3396                                                (current-buffer))))))
3397
3398 (defun gnus-summary-setup-buffer (group)
3399   "Initialize summary buffer."
3400   (let ((buffer (gnus-summary-buffer-name group))
3401         (dead-name (concat "*Dead Summary "
3402                            (gnus-group-decoded-name group) "*")))
3403     ;; If a dead summary buffer exists, we kill it.
3404     (when (gnus-buffer-live-p dead-name)
3405       (gnus-kill-buffer dead-name))
3406     (if (get-buffer buffer)
3407         (progn
3408           (set-buffer buffer)
3409           (setq gnus-summary-buffer (current-buffer))
3410           (not gnus-newsgroup-prepared))
3411       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3412       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3413       (gnus-summary-mode group)
3414       (when gnus-carpal
3415         (gnus-carpal-setup-buffer 'summary))
3416       (when (gnus-group-quit-config group)
3417         (set (make-local-variable 'gnus-single-article-buffer) nil))
3418       (make-local-variable 'gnus-article-buffer)
3419       (make-local-variable 'gnus-article-current)
3420       (make-local-variable 'gnus-original-article-buffer)
3421       (setq gnus-newsgroup-name group)
3422       ;; Set any local variables in the group parameters.
3423       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3424       t)))
3425
3426 (defun gnus-set-global-variables ()
3427   "Set the global equivalents of the buffer-local variables.
3428 They are set to the latest values they had.  These reflect the summary
3429 buffer that was in action when the last article was fetched."
3430   (when (eq major-mode 'gnus-summary-mode)
3431     (setq gnus-summary-buffer (current-buffer))
3432     (let ((name gnus-newsgroup-name)
3433           (marked gnus-newsgroup-marked)
3434           (spam gnus-newsgroup-spam-marked)
3435           (unread gnus-newsgroup-unreads)
3436           (headers gnus-current-headers)
3437           (data gnus-newsgroup-data)
3438           (summary gnus-summary-buffer)
3439           (article-buffer gnus-article-buffer)
3440           (original gnus-original-article-buffer)
3441           (gac gnus-article-current)
3442           (reffed gnus-reffed-article-number)
3443           (score-file gnus-current-score-file)
3444           (default-charset gnus-newsgroup-charset)
3445           vlist)
3446       (let ((locals gnus-newsgroup-variables))
3447         (while locals
3448           (if (consp (car locals))
3449               (push (eval (caar locals)) vlist)
3450             (push (eval (car locals)) vlist))
3451           (setq locals (cdr locals)))
3452         (setq vlist (nreverse vlist)))
3453       (with-current-buffer gnus-group-buffer
3454         (setq gnus-newsgroup-name name
3455               gnus-newsgroup-marked marked
3456               gnus-newsgroup-spam-marked spam
3457               gnus-newsgroup-unreads unread
3458               gnus-current-headers headers
3459               gnus-newsgroup-data data
3460               gnus-article-current gac
3461               gnus-summary-buffer summary
3462               gnus-article-buffer article-buffer
3463               gnus-original-article-buffer original
3464               gnus-reffed-article-number reffed
3465               gnus-current-score-file score-file
3466               gnus-newsgroup-charset default-charset)
3467         (let ((locals gnus-newsgroup-variables))
3468           (while locals
3469             (if (consp (car locals))
3470                 (set (caar locals) (pop vlist))
3471               (set (car locals) (pop vlist)))
3472             (setq locals (cdr locals))))
3473         ;; The article buffer also has local variables.
3474         (when (gnus-buffer-live-p gnus-article-buffer)
3475           (set-buffer gnus-article-buffer)
3476           (setq gnus-summary-buffer summary))))))
3477
3478 (defun gnus-summary-article-unread-p (article)
3479   "Say whether ARTICLE is unread or not."
3480   (memq article gnus-newsgroup-unreads))
3481
3482 (defun gnus-summary-first-article-p (&optional article)
3483   "Return whether ARTICLE is the first article in the buffer."
3484   (if (not (setq article (or article (gnus-summary-article-number))))
3485       nil
3486     (eq article (caar gnus-newsgroup-data))))
3487
3488 (defun gnus-summary-last-article-p (&optional article)
3489   "Return whether ARTICLE is the last article in the buffer."
3490   (if (not (setq article (or article (gnus-summary-article-number))))
3491       ;; All non-existent numbers are the last article.  :-)
3492       t
3493     (not (cdr (gnus-data-find-list article)))))
3494
3495 (defun gnus-make-thread-indent-array (&optional n)
3496   (when (or n
3497             (progn (setq n 200) nil)
3498             (null gnus-thread-indent-array)
3499             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3500     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3501           gnus-thread-indent-array-level gnus-thread-indent-level)
3502     (while (>= n 0)
3503       (aset gnus-thread-indent-array n
3504             (make-string (* n gnus-thread-indent-level) ? ))
3505       (setq n (1- n)))))
3506
3507 (defun gnus-update-summary-mark-positions ()
3508   "Compute where the summary marks are to go."
3509   (save-excursion
3510     (when (gnus-buffer-exists-p gnus-summary-buffer)
3511       (set-buffer gnus-summary-buffer))
3512     (let ((spec gnus-summary-line-format-spec)
3513           pos)
3514       (save-excursion
3515         (gnus-set-work-buffer)
3516         (let ((gnus-tmp-unread ?Z)
3517               (gnus-replied-mark ?Z)
3518               (gnus-score-below-mark ?Z)
3519               (gnus-score-over-mark ?Z)
3520               (gnus-undownloaded-mark ?Z)
3521               (gnus-summary-line-format-spec spec)
3522               (gnus-newsgroup-downloadable '(0))
3523               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3524               case-fold-search ignores)
3525           ;; Here, all marks are bound to Z.
3526           (gnus-summary-insert-line header
3527                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3528           (goto-char (point-min))
3529           ;; Memorize the positions of the same characters as dummy marks.
3530           (while (re-search-forward "[A-D]" nil t)
3531             (push (point) ignores))
3532           (erase-buffer)
3533           ;; We use A-D as dummy marks in order to know column positions
3534           ;; where marks should be inserted.
3535           (setq gnus-tmp-unread ?A
3536                 gnus-replied-mark ?B
3537                 gnus-score-below-mark ?C
3538                 gnus-score-over-mark ?C
3539                 gnus-undownloaded-mark ?D)
3540           (gnus-summary-insert-line header
3541                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3542           ;; Ignore characters which aren't dummy marks.
3543           (dolist (p ignores)
3544             (delete-region (goto-char (1- p)) p)
3545             (insert ?Z))
3546           (goto-char (point-min))
3547           (setq pos (list (cons 'unread
3548                                 (and (search-forward "A" nil t)
3549                                      (- (point) (point-min) 1)))))
3550           (goto-char (point-min))
3551           (push (cons 'replied (and (search-forward "B" nil t)
3552                                     (- (point) (point-min) 1)))
3553                 pos)
3554           (goto-char (point-min))
3555           (push (cons 'score (and (search-forward "C" nil t)
3556                                   (- (point) (point-min) 1)))
3557                 pos)
3558           (goto-char (point-min))
3559           (push (cons 'download (and (search-forward "D" nil t)
3560                                      (- (point) (point-min) 1)))
3561                 pos)))
3562       (setq gnus-summary-mark-positions pos))))
3563
3564 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3565   "Insert a dummy root in the summary buffer."
3566   (beginning-of-line)
3567   (gnus-add-text-properties
3568    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3569    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3570
3571 (defun gnus-summary-extract-address-component (from)
3572   (or (car (funcall gnus-extract-address-components from))
3573       from))
3574
3575 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3576   (let ((mail-parse-charset gnus-newsgroup-charset)
3577         (ignored-from-addresses (gnus-ignored-from-addresses))
3578         ; Is it really necessary to do this next part for each summary line?
3579         ; Luckily, doesn't seem to slow things down much.
3580         (mail-parse-ignored-charsets
3581          (with-current-buffer gnus-summary-buffer
3582            gnus-newsgroup-ignored-charsets)))
3583     (or
3584      (and ignored-from-addresses
3585           (string-match ignored-from-addresses gnus-tmp-from)
3586           (let ((extra-headers (mail-header-extra header))
3587                 to
3588                 newsgroups)
3589             (cond
3590              ((setq to (cdr (assq 'To extra-headers)))
3591               (concat gnus-summary-to-prefix
3592                       (inline
3593                         (gnus-summary-extract-address-component
3594                          (funcall gnus-decode-encoded-address-function to)))))
3595              ((setq newsgroups
3596                     (or
3597                      (cdr (assq 'Newsgroups extra-headers))
3598                      (and
3599                       (memq 'Newsgroups gnus-extra-headers)
3600                       (eq (car (gnus-find-method-for-group
3601                                 gnus-newsgroup-name)) 'nntp)
3602                       (gnus-group-real-name gnus-newsgroup-name))))
3603               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3604      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3605
3606 (defun gnus-summary-insert-line (gnus-tmp-header
3607                                  gnus-tmp-level gnus-tmp-current
3608                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3609                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3610                                  &optional gnus-tmp-dummy gnus-tmp-score
3611                                  gnus-tmp-process)
3612   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3613       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3614                                           gnus-tmp-level)))
3615   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3616          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3617          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3618          (gnus-tmp-score-char
3619           (if (or (null gnus-summary-default-score)
3620                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3621                       gnus-summary-zcore-fuzz))
3622               ?                         ;Whitespace
3623             (if (< gnus-tmp-score gnus-summary-default-score)
3624                 gnus-score-below-mark gnus-score-over-mark)))
3625          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3626          (gnus-tmp-replied
3627           (cond (gnus-tmp-process gnus-process-mark)
3628                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3629                  gnus-cached-mark)
3630                 (gnus-tmp-replied gnus-replied-mark)
3631                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3632                  gnus-forwarded-mark)
3633                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3634                  gnus-saved-mark)
3635                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3636                  gnus-recent-mark)
3637                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3638                  gnus-unseen-mark)
3639                 (t gnus-no-mark)))
3640          (gnus-tmp-downloaded
3641           (cond (undownloaded
3642                  gnus-undownloaded-mark)
3643                 (gnus-newsgroup-agentized
3644                  gnus-downloaded-mark)
3645                 (t
3646                  gnus-no-mark)))
3647          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3648          (gnus-tmp-name
3649           (cond
3650            ((string-match "<[^>]+> *$" gnus-tmp-from)
3651             (let ((beg (match-beginning 0)))
3652               (or (and (string-match "^\".+\"" gnus-tmp-from)
3653                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3654                   (substring gnus-tmp-from 0 beg))))
3655            ((string-match "(.+)" gnus-tmp-from)
3656             (substring gnus-tmp-from
3657                        (1+ (match-beginning 0)) (1- (match-end 0))))
3658            (t gnus-tmp-from)))
3659          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3660          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3661          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3662          (buffer-read-only nil))
3663     (when (string= gnus-tmp-name "")
3664       (setq gnus-tmp-name gnus-tmp-from))
3665     (unless (numberp gnus-tmp-lines)
3666       (setq gnus-tmp-lines -1))
3667     (if (= gnus-tmp-lines -1)
3668         (setq gnus-tmp-lines "?")
3669       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3670       (gnus-put-text-property
3671      (point)
3672      (progn (eval gnus-summary-line-format-spec) (point))
3673        'gnus-number gnus-tmp-number)
3674     (when (gnus-visual-p 'summary-highlight 'highlight)
3675       (forward-line -1)
3676       (gnus-run-hooks 'gnus-summary-update-hook)
3677       (forward-line 1))))
3678
3679 (defun gnus-summary-update-line (&optional dont-update)
3680   "Update summary line after change."
3681   (when (and gnus-summary-default-score
3682              (not gnus-summary-inhibit-highlight))
3683     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3684            (article (gnus-summary-article-number))
3685            (score (gnus-summary-article-score article)))
3686       (unless dont-update
3687         (if (and gnus-summary-mark-below
3688                  (< (gnus-summary-article-score)
3689                     gnus-summary-mark-below))
3690             ;; This article has a low score, so we mark it as read.
3691             (when (memq article gnus-newsgroup-unreads)
3692               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3693           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3694             ;; This article was previously marked as read on account
3695             ;; of a low score, but now it has risen, so we mark it as
3696             ;; unread.
3697             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3698         (gnus-summary-update-mark
3699          (if (or (null gnus-summary-default-score)
3700                  (<= (abs (- score gnus-summary-default-score))
3701                      gnus-summary-zcore-fuzz))
3702              ?                          ;Whitespace
3703            (if (< score gnus-summary-default-score)
3704                gnus-score-below-mark gnus-score-over-mark))
3705          'score))
3706       ;; Do visual highlighting.
3707       (when (gnus-visual-p 'summary-highlight 'highlight)
3708         (gnus-run-hooks 'gnus-summary-update-hook)))))
3709
3710 (defvar gnus-tmp-new-adopts nil)
3711
3712 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3713   "Return the number of articles in THREAD.
3714 This may be 0 in some cases -- if none of the articles in
3715 the thread are to be displayed."
3716   (let* ((number
3717          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3718           (cond
3719            ((not (listp thread))
3720             1)
3721            ((and (consp thread) (cdr thread))
3722             (apply
3723              '+ 1 (mapcar
3724                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3725            ((null thread)
3726             1)
3727            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3728             1)
3729            (t 0))))
3730     (when (and level (zerop level) gnus-tmp-new-adopts)
3731       (incf number
3732             (apply '+ (mapcar
3733                        'gnus-summary-number-of-articles-in-thread
3734                        gnus-tmp-new-adopts))))
3735     (if char
3736         (if (> number 1) gnus-not-empty-thread-mark
3737           gnus-empty-thread-mark)
3738       number)))
3739
3740 (defsubst gnus-summary-line-message-size (head)
3741   "Return pretty-printed version of message size.
3742 This function is intended to be used in
3743 `gnus-summary-line-format-alist'."
3744   (let ((c (or (mail-header-chars head) -1)))
3745     (cond ((< c 0) "n/a")               ; chars not available
3746           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3747           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3748           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3749           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3750
3751
3752 (defun gnus-summary-set-local-parameters (group)
3753   "Go through the local params of GROUP and set all variable specs in that list."
3754   (let ((vars '(quit-config)))          ; Ignore quit-config.
3755     (dolist (elem (gnus-group-find-parameter group))
3756       (and (consp elem)                 ; Has to be a cons.
3757            (consp (cdr elem))           ; The cdr has to be a list.
3758            (symbolp (car elem))         ; Has to be a symbol in there.
3759            (not (memq (car elem) vars))
3760            (ignore-errors               ; So we set it.
3761              (push (car elem) vars)
3762              (make-local-variable (car elem))
3763              (set (car elem) (eval (nth 1 elem))))))))
3764
3765 (defun gnus-summary-read-group (group &optional show-all no-article
3766                                       kill-buffer no-display backward
3767                                       select-articles)
3768   "Start reading news in newsgroup GROUP.
3769 If SHOW-ALL is non-nil, already read articles are also listed.
3770 If NO-ARTICLE is non-nil, no article is selected initially.
3771 If NO-DISPLAY, don't generate a summary buffer."
3772   (let (result)
3773     (while (and group
3774                 (null (setq result
3775                             (let ((gnus-auto-select-next nil))
3776                               (or (gnus-summary-read-group-1
3777                                    group show-all no-article
3778                                    kill-buffer no-display
3779                                    select-articles)
3780                                   (setq show-all nil
3781                                         select-articles nil)))))
3782                 (eq gnus-auto-select-next 'quietly))
3783       (set-buffer gnus-group-buffer)
3784       ;; The entry function called above goes to the next
3785       ;; group automatically, so we go two groups back
3786       ;; if we are searching for the previous group.
3787       (when backward
3788         (gnus-group-prev-unread-group 2))
3789       (if (not (equal group (gnus-group-group-name)))
3790           (setq group (gnus-group-group-name))
3791         (setq group nil)))
3792     result))
3793
3794 (defun gnus-summary-read-group-1 (group show-all no-article
3795                                         kill-buffer no-display
3796                                         &optional select-articles)
3797   ;; Killed foreign groups can't be entered.
3798   ;;  (when (and (not (gnus-group-native-p group))
3799   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3800   ;;    (error "Dead non-native groups can't be entered"))
3801   (gnus-message 5 "Retrieving newsgroup: %s..."
3802                 (gnus-group-decoded-name group))
3803   (let* ((new-group (gnus-summary-setup-buffer group))
3804          (quit-config (gnus-group-quit-config group))
3805          (did-select (and new-group (gnus-select-newsgroup
3806                                      group show-all select-articles))))
3807     (cond
3808      ;; This summary buffer exists already, so we just select it.
3809      ((not new-group)
3810       (gnus-set-global-variables)
3811       (when kill-buffer
3812         (gnus-kill-or-deaden-summary kill-buffer))
3813       (gnus-configure-windows 'summary 'force)
3814       (gnus-set-mode-line 'summary)
3815       (gnus-summary-position-point)
3816       (message "")
3817       t)
3818      ;; We couldn't select this group.
3819      ((null did-select)
3820       (when (and (eq major-mode 'gnus-summary-mode)
3821                  (not (equal (current-buffer) kill-buffer)))
3822         (kill-buffer (current-buffer))
3823         (if (not quit-config)
3824             (progn
3825               ;; Update the info -- marks might need to be removed,
3826               ;; for instance.
3827               (gnus-summary-update-info)
3828               (set-buffer gnus-group-buffer)
3829               (gnus-group-jump-to-group group)
3830               (gnus-group-next-unread-group 1))
3831           (gnus-handle-ephemeral-exit quit-config)))
3832       (let ((grpinfo (gnus-get-info group)))
3833         (if (null (gnus-info-read grpinfo))
3834             (gnus-message 3 "Group %s contains no messages"
3835                           (gnus-group-decoded-name group))
3836           (gnus-message 3 "Can't select group")))
3837       nil)
3838      ;; The user did a `C-g' while prompting for number of articles,
3839      ;; so we exit this group.
3840      ((eq did-select 'quit)
3841       (and (eq major-mode 'gnus-summary-mode)
3842            (not (equal (current-buffer) kill-buffer))
3843            (kill-buffer (current-buffer)))
3844       (when kill-buffer
3845         (gnus-kill-or-deaden-summary kill-buffer))
3846       (if (not quit-config)
3847           (progn
3848             (set-buffer gnus-group-buffer)
3849             (gnus-group-jump-to-group group)
3850             (gnus-group-next-unread-group 1)
3851             (gnus-configure-windows 'group 'force))
3852         (gnus-handle-ephemeral-exit quit-config))
3853       ;; Finally signal the quit.
3854       (signal 'quit nil))
3855      ;; The group was successfully selected.
3856      (t
3857       (gnus-set-global-variables)
3858       ;; Save the active value in effect when the group was entered.
3859       (setq gnus-newsgroup-active
3860             (gnus-copy-sequence
3861              (gnus-active gnus-newsgroup-name)))
3862       ;; You can change the summary buffer in some way with this hook.
3863       (gnus-run-hooks 'gnus-select-group-hook)
3864       (when (memq 'summary (gnus-update-format-specifications
3865                             nil 'summary 'summary-mode 'summary-dummy))
3866         ;; The format specification for the summary line was updated,
3867         ;; so we need to update the mark positions as well.
3868         (gnus-update-summary-mark-positions))
3869       ;; Do score processing.
3870       (when gnus-use-scoring
3871         (gnus-possibly-score-headers))
3872       ;; Check whether to fill in the gaps in the threads.
3873       (when gnus-build-sparse-threads
3874         (gnus-build-sparse-threads))
3875       ;; Find the initial limit.
3876       (if show-all
3877           (let ((gnus-newsgroup-dormant nil))
3878             (gnus-summary-initial-limit show-all))
3879         (gnus-summary-initial-limit show-all))
3880       ;; Generate the summary buffer.
3881       (unless no-display
3882         (gnus-summary-prepare))
3883       (when gnus-use-trees
3884         (gnus-tree-open group)
3885         (setq gnus-summary-highlight-line-function
3886               'gnus-tree-highlight-article))
3887       ;; If the summary buffer is empty, but there are some low-scored
3888       ;; articles or some excluded dormants, we include these in the
3889       ;; buffer.
3890       (when (and (zerop (buffer-size))
3891                  (not no-display))
3892         (cond (gnus-newsgroup-dormant
3893                (gnus-summary-limit-include-dormant))
3894               ((and gnus-newsgroup-scored show-all)
3895                (gnus-summary-limit-include-expunged t))))
3896       ;; Function `gnus-apply-kill-file' must be called in this hook.
3897       (gnus-run-hooks 'gnus-apply-kill-hook)
3898       (if (and (zerop (buffer-size))
3899                (not no-display))
3900           (progn
3901             ;; This newsgroup is empty.
3902             (gnus-summary-catchup-and-exit nil t)
3903             (gnus-message 6 "No unread news")
3904             (when kill-buffer
3905               (gnus-kill-or-deaden-summary kill-buffer))
3906             ;; Return nil from this function.
3907             nil)
3908         ;; Hide conversation thread subtrees.  We cannot do this in
3909         ;; gnus-summary-prepare-hook since kill processing may not
3910         ;; work with hidden articles.
3911         (gnus-summary-maybe-hide-threads)
3912         (when kill-buffer
3913           (gnus-kill-or-deaden-summary kill-buffer))
3914         (gnus-summary-auto-select-subject)
3915         ;; Show first unread article if requested.
3916         (if (and (not no-article)
3917                  (not no-display)
3918                  gnus-newsgroup-unreads
3919                  gnus-auto-select-first)
3920             (progn
3921               (gnus-configure-windows 'summary)
3922               (let ((art (gnus-summary-article-number)))
3923                 (unless (and (not gnus-plugged)
3924                              (or (memq art gnus-newsgroup-undownloaded)
3925                                  (memq art gnus-newsgroup-downloadable)))
3926                   (gnus-summary-goto-article art))))
3927           ;; Don't select any articles.
3928           (gnus-summary-position-point)
3929           (gnus-configure-windows 'summary 'force)
3930           (gnus-set-mode-line 'summary))
3931         (when (and gnus-auto-center-group
3932                    (get-buffer-window gnus-group-buffer t))
3933           ;; Gotta use windows, because recenter does weird stuff if
3934           ;; the current buffer ain't the displayed window.
3935           (let ((owin (selected-window)))
3936             (select-window (get-buffer-window gnus-group-buffer t))
3937             (when (gnus-group-goto-group group)
3938               (recenter))
3939             (select-window owin)))
3940         ;; Mark this buffer as "prepared".
3941         (setq gnus-newsgroup-prepared t)
3942         (gnus-run-hooks 'gnus-summary-prepared-hook)
3943         (unless (gnus-ephemeral-group-p group)
3944           (gnus-group-update-group group))
3945         t)))))
3946
3947 (defun gnus-summary-auto-select-subject ()
3948   "Select the subject line on initial group entry."
3949   (goto-char (point-min))
3950   (cond
3951    ((eq gnus-auto-select-subject 'best)
3952     (gnus-summary-best-unread-subject))
3953    ((eq gnus-auto-select-subject 'unread)
3954     (gnus-summary-first-unread-subject))
3955    ((eq gnus-auto-select-subject 'unseen)
3956     (gnus-summary-first-unseen-subject))
3957    ((eq gnus-auto-select-subject 'unseen-or-unread)
3958     (gnus-summary-first-unseen-or-unread-subject))
3959    ((eq gnus-auto-select-subject 'first)
3960     ;; Do nothing.
3961     )
3962    ((functionp gnus-auto-select-subject)
3963     (funcall gnus-auto-select-subject))))
3964
3965 (defun gnus-summary-prepare ()
3966   "Generate the summary buffer."
3967   (interactive)
3968   (let ((buffer-read-only nil))
3969     (erase-buffer)
3970     (setq gnus-newsgroup-data nil
3971           gnus-newsgroup-data-reverse nil)
3972     (gnus-run-hooks 'gnus-summary-generate-hook)
3973     ;; Generate the buffer, either with threads or without.
3974     (when gnus-newsgroup-headers
3975       (gnus-summary-prepare-threads
3976        (if gnus-show-threads
3977            (gnus-sort-gathered-threads
3978             (funcall gnus-summary-thread-gathering-function
3979                      (gnus-sort-threads
3980                       (gnus-cut-threads (gnus-make-threads)))))
3981          ;; Unthreaded display.
3982          (gnus-sort-articles gnus-newsgroup-headers))))
3983     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3984     ;; Call hooks for modifying summary buffer.
3985     (goto-char (point-min))
3986     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3987
3988 (defsubst gnus-general-simplify-subject (subject)
3989   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3990   (setq subject
3991         (cond
3992          ;; Truncate the subject.
3993          (gnus-simplify-subject-functions
3994           (gnus-map-function gnus-simplify-subject-functions subject))
3995          ((numberp gnus-summary-gather-subject-limit)
3996           (setq subject (gnus-simplify-subject-re subject))
3997           (if (> (length subject) gnus-summary-gather-subject-limit)
3998               (substring subject 0 gnus-summary-gather-subject-limit)
3999             subject))
4000          ;; Fuzzily simplify it.
4001          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4002           (gnus-simplify-subject-fuzzy subject))
4003          ;; Just remove the leading "Re:".
4004          (t
4005           (gnus-simplify-subject-re subject))))
4006
4007   (if (and gnus-summary-gather-exclude-subject
4008            (string-match gnus-summary-gather-exclude-subject subject))
4009       nil                         ; This article shouldn't be gathered
4010     subject))
4011
4012 (defun gnus-summary-simplify-subject-query ()
4013   "Query where the respool algorithm would put this article."
4014   (interactive)
4015   (gnus-summary-select-article)
4016   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
4017
4018 (defun gnus-gather-threads-by-subject (threads)
4019   "Gather threads by looking at Subject headers."
4020   (if (not gnus-summary-make-false-root)
4021       threads
4022     (let ((hashtb (gnus-make-hashtable 1024))
4023           (prev threads)
4024           (result threads)
4025           subject hthread whole-subject)
4026       (while threads
4027         (setq subject (gnus-general-simplify-subject
4028                        (setq whole-subject (mail-header-subject
4029                                             (caar threads)))))
4030         (when subject
4031           (if (setq hthread (gnus-gethash subject hashtb))
4032               (progn
4033                 ;; We enter a dummy root into the thread, if we
4034                 ;; haven't done that already.
4035                 (unless (stringp (caar hthread))
4036                   (setcar hthread (list whole-subject (car hthread))))
4037                 ;; We add this new gathered thread to this gathered
4038                 ;; thread.
4039                 (setcdr (car hthread)
4040                         (nconc (cdar hthread) (list (car threads))))
4041                 ;; Remove it from the list of threads.
4042                 (setcdr prev (cdr threads))
4043                 (setq threads prev))
4044             ;; Enter this thread into the hash table.
4045             (gnus-sethash subject
4046                           (if gnus-summary-make-false-root-always
4047                               (progn
4048                                 ;; If you want a dummy root above all
4049                                 ;; threads...
4050                                 (setcar threads (list whole-subject
4051                                                       (car threads)))
4052                                 threads)
4053                             threads)
4054                           hashtb)))
4055         (setq prev threads)
4056         (setq threads (cdr threads)))
4057       result)))
4058
4059 (defun gnus-gather-threads-by-references (threads)
4060   "Gather threads by looking at References headers."
4061   (let ((idhashtb (gnus-make-hashtable 1024))
4062         (thhashtb (gnus-make-hashtable 1024))
4063         (prev threads)
4064         (result threads)
4065         ids references id gthread gid entered ref)
4066     (while threads
4067       (when (setq references (mail-header-references (caar threads)))
4068         (setq id (mail-header-id (caar threads))
4069               ids (inline (gnus-split-references references))
4070               entered nil)
4071         (while (setq ref (pop ids))
4072           (setq ids (delete ref ids))
4073           (if (not (setq gid (gnus-gethash ref idhashtb)))
4074               (progn
4075                 (gnus-sethash ref id idhashtb)
4076                 (gnus-sethash id threads thhashtb))
4077             (setq gthread (gnus-gethash gid thhashtb))
4078             (unless entered
4079               ;; We enter a dummy root into the thread, if we
4080               ;; haven't done that already.
4081               (unless (stringp (caar gthread))
4082                 (setcar gthread (list (mail-header-subject (caar gthread))
4083                                       (car gthread))))
4084               ;; We add this new gathered thread to this gathered
4085               ;; thread.
4086               (setcdr (car gthread)
4087                       (nconc (cdar gthread) (list (car threads)))))
4088             ;; Add it into the thread hash table.
4089             (gnus-sethash id gthread thhashtb)
4090             (setq entered t)
4091             ;; Remove it from the list of threads.
4092             (setcdr prev (cdr threads))
4093             (setq threads prev))))
4094       (setq prev threads)
4095       (setq threads (cdr threads)))
4096     result))
4097
4098 (defun gnus-sort-gathered-threads (threads)
4099   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4100   (let ((result threads))
4101     (while threads
4102       (when (stringp (caar threads))
4103         (setcdr (car threads)
4104                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4105       (setq threads (cdr threads)))
4106     result))
4107
4108 (defun gnus-thread-loop-p (root thread)
4109   "Say whether ROOT is in THREAD."
4110   (let ((stack (list thread))
4111         (infloop 0)
4112         th)
4113     (while (setq thread (pop stack))
4114       (setq th (cdr thread))
4115       (while (and th
4116                   (not (eq (caar th) root)))
4117         (pop th))
4118       (if th
4119           ;; We have found a loop.
4120           (let (ref-dep)
4121             (setcdr thread (delq (car th) (cdr thread)))
4122             (if (boundp (setq ref-dep (intern "none"
4123                                               gnus-newsgroup-dependencies)))
4124                 (setcdr (symbol-value ref-dep)
4125                         (nconc (cdr (symbol-value ref-dep))
4126                                (list (car th))))
4127               (set ref-dep (list nil (car th))))
4128             (setq infloop 1
4129                   stack nil))
4130         ;; Push all the subthreads onto the stack.
4131         (push (cdr thread) stack)))
4132     infloop))
4133
4134 (defun gnus-make-threads ()
4135   "Go through the dependency hashtb and find the roots.  Return all threads."
4136   (let (threads)
4137     (while (catch 'infloop
4138              (mapatoms
4139               (lambda (refs)
4140                 ;; Deal with self-referencing References loops.
4141                 (when (and (car (symbol-value refs))
4142                            (not (zerop
4143                                  (apply
4144                                   '+
4145                                   (mapcar
4146                                    (lambda (thread)
4147                                      (gnus-thread-loop-p
4148                                       (car (symbol-value refs)) thread))
4149                                    (cdr (symbol-value refs)))))))
4150                   (setq threads nil)
4151                   (throw 'infloop t))
4152                 (unless (car (symbol-value refs))
4153                   ;; These threads do not refer back to any other
4154                   ;; articles, so they're roots.
4155                   (setq threads (append (cdr (symbol-value refs)) threads))))
4156               gnus-newsgroup-dependencies)))
4157     threads))
4158
4159 ;; Build the thread tree.
4160 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4161   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4162
4163 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4164 if it was already present.
4165
4166 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4167 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4168 Message-IDs will be renamed to a unique Message-ID before being
4169 entered.
4170
4171 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4172   (let* ((id (mail-header-id header))
4173          (id-dep (and id (intern id dependencies)))
4174          parent-id ref ref-dep ref-header replaced)
4175     ;; Enter this `header' in the `dependencies' table.
4176     (cond
4177      ((not id-dep)
4178       (setq header nil))
4179      ;; The first two cases do the normal part: enter a new `header'
4180      ;; in the `dependencies' table.
4181      ((not (boundp id-dep))
4182       (set id-dep (list header)))
4183      ((null (car (symbol-value id-dep)))
4184       (setcar (symbol-value id-dep) header))
4185
4186      ;; From here the `header' was already present in the
4187      ;; `dependencies' table.
4188      (force-new
4189       ;; Overrides an existing entry;
4190       ;; just set the header part of the entry.
4191       (setcar (symbol-value id-dep) header)
4192       (setq replaced t))
4193
4194      ;; Renames the existing `header' to a unique Message-ID.
4195      ((not gnus-summary-ignore-duplicates)
4196       ;; An article with this Message-ID has already been seen.
4197       ;; We rename the Message-ID.
4198       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4199            (list header))
4200       (mail-header-set-id header id))
4201
4202      ;; The last case ignores an existing entry, except it adds any
4203      ;; additional Xrefs (in case the two articles came from different
4204      ;; servers.
4205      ;; Also sets `header' to `nil' meaning that the `dependencies'
4206      ;; table was *not* modified.
4207      (t
4208       (mail-header-set-xref
4209        (car (symbol-value id-dep))
4210        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4211                    "")
4212                (or (mail-header-xref header) "")))
4213       (setq header nil)))
4214
4215     (when (and header (not replaced))
4216       ;; First check that we are not creating a References loop.
4217       (setq parent-id (gnus-parent-id (mail-header-references header)))
4218       (setq ref parent-id)
4219       (while (and ref
4220                   (setq ref-dep (intern-soft ref dependencies))
4221                   (boundp ref-dep)
4222                   (setq ref-header (car (symbol-value ref-dep))))
4223         (if (string= id ref)
4224             ;; Yuk!  This is a reference loop.  Make the article be a
4225             ;; root article.
4226             (progn
4227               (mail-header-set-references (car (symbol-value id-dep)) "none")
4228               (setq ref nil)
4229               (setq parent-id nil))
4230           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4231       (setq ref-dep (intern (or parent-id "none") dependencies))
4232       (if (boundp ref-dep)
4233           (setcdr (symbol-value ref-dep)
4234                   (nconc (cdr (symbol-value ref-dep))
4235                          (list (symbol-value id-dep))))
4236         (set ref-dep (list nil (symbol-value id-dep)))))
4237     header))
4238
4239 (defun gnus-extract-message-id-from-in-reply-to (string)
4240   (if (string-match "<[^>]+>" string)
4241       (substring string (match-beginning 0) (match-end 0))
4242     nil))
4243
4244 (defun gnus-build-sparse-threads ()
4245   (let ((headers gnus-newsgroup-headers)
4246         (mail-parse-charset gnus-newsgroup-charset)
4247         (gnus-summary-ignore-duplicates t)
4248         header references generation relations
4249         subject child end new-child date)
4250     ;; First we create an alist of generations/relations, where
4251     ;; generations is how much we trust the relation, and the relation
4252     ;; is parent/child.
4253     (gnus-message 7 "Making sparse threads...")
4254     (save-excursion
4255       (nnheader-set-temp-buffer " *gnus sparse threads*")
4256       (while (setq header (pop headers))
4257         (when (and (setq references (mail-header-references header))
4258                    (not (string= references "")))
4259           (insert references)
4260           (setq child (mail-header-id header)
4261                 subject (mail-header-subject header)
4262                 date (mail-header-date header)
4263                 generation 0)
4264           (while (search-backward ">" nil t)
4265             (setq end (1+ (point)))
4266             (when (search-backward "<" nil t)
4267               (setq new-child (buffer-substring (point) end))
4268               (push (list (incf generation)
4269                           child (setq child new-child)
4270                           subject date)
4271                     relations)))
4272           (when child
4273             (push (list (1+ generation) child nil subject) relations))
4274           (erase-buffer)))
4275       (kill-buffer (current-buffer)))
4276     ;; Sort over trustworthiness.
4277     (mapcar
4278      (lambda (relation)
4279        (when (gnus-dependencies-add-header
4280               (make-full-mail-header
4281                gnus-reffed-article-number
4282                (nth 3 relation) "" (or (nth 4 relation) "")
4283                (nth 1 relation)
4284                (or (nth 2 relation) "") 0 0 "")
4285               gnus-newsgroup-dependencies nil)
4286          (push gnus-reffed-article-number gnus-newsgroup-limit)
4287          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4288          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4289                gnus-newsgroup-reads)
4290          (decf gnus-reffed-article-number)))
4291      (sort relations 'car-less-than-car))
4292     (gnus-message 7 "Making sparse threads...done")))
4293
4294 (defun gnus-build-old-threads ()
4295   ;; Look at all the articles that refer back to old articles, and
4296   ;; fetch the headers for the articles that aren't there.  This will
4297   ;; build complete threads - if the roots haven't been expired by the
4298   ;; server, that is.
4299   (let ((mail-parse-charset gnus-newsgroup-charset)
4300         id heads)
4301     (mapatoms
4302      (lambda (refs)
4303        (when (not (car (symbol-value refs)))
4304          (setq heads (cdr (symbol-value refs)))
4305          (while heads
4306            (if (memq (mail-header-number (caar heads))
4307                      gnus-newsgroup-dormant)
4308                (setq heads (cdr heads))
4309              (setq id (symbol-name refs))
4310              (while (and (setq id (gnus-build-get-header id))
4311                          (not (car (gnus-id-to-thread id)))))
4312              (setq heads nil)))))
4313      gnus-newsgroup-dependencies)))
4314
4315 (defsubst gnus-remove-odd-characters (string)
4316   "Translate STRING into something that doesn't contain weird characters."
4317   (mm-subst-char-in-string
4318    ?\r ?\-
4319    (mm-subst-char-in-string ?\n ?\- string t) t))
4320
4321 ;; This function has to be called with point after the article number
4322 ;; on the beginning of the line.
4323 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4324   (let ((eol (point-at-eol))
4325         (buffer (current-buffer))
4326         header references in-reply-to)
4327
4328     ;; overview: [num subject from date id refs chars lines misc]
4329     (unwind-protect
4330         (let (x)
4331           (narrow-to-region (point) eol)
4332           (unless (eobp)
4333             (forward-char))
4334
4335           (setq header
4336                 (make-full-mail-header
4337                  number                 ; number
4338                  (condition-case ()     ; subject
4339                      (gnus-remove-odd-characters
4340                       (funcall gnus-decode-encoded-word-function
4341                                (setq x (nnheader-nov-field))))
4342                    (error x))
4343                  (condition-case ()     ; from
4344                      (gnus-remove-odd-characters
4345                       (funcall gnus-decode-encoded-address-function
4346                                (setq x (nnheader-nov-field))))
4347                    (error x))
4348                  (nnheader-nov-field)   ; date
4349                  (nnheader-nov-read-message-id number)  ; id
4350                  (setq references (nnheader-nov-field)) ; refs
4351                  (nnheader-nov-read-integer) ; chars
4352                  (nnheader-nov-read-integer) ; lines
4353                  (unless (eobp)
4354                    (if (looking-at "Xref: ")
4355                        (goto-char (match-end 0)))
4356                    (nnheader-nov-field)) ; Xref
4357                  (nnheader-nov-parse-extra)))) ; extra
4358
4359       (widen))
4360
4361     (when (and (string= references "")
4362                (setq in-reply-to (mail-header-extra header))
4363                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4364       (mail-header-set-references
4365        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4366
4367     (when gnus-alter-header-function
4368       (funcall gnus-alter-header-function header))
4369     (gnus-dependencies-add-header header dependencies force-new)))
4370
4371 (defun gnus-build-get-header (id)
4372   "Look through the buffer of NOV lines and find the header to ID.
4373 Enter this line into the dependencies hash table, and return
4374 the id of the parent article (if any)."
4375   (let ((deps gnus-newsgroup-dependencies)
4376         found header)
4377     (prog1
4378         (save-excursion
4379           (set-buffer nntp-server-buffer)
4380           (let ((case-fold-search nil))
4381             (goto-char (point-min))
4382             (while (and (not found)
4383                         (search-forward id nil t))
4384               (beginning-of-line)
4385               (setq found (looking-at
4386                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4387                                    (regexp-quote id))))
4388               (or found (beginning-of-line 2)))
4389             (when found
4390               (beginning-of-line)
4391               (and
4392                (setq header (gnus-nov-parse-line
4393                              (read (current-buffer)) deps))
4394                (gnus-parent-id (mail-header-references header))))))
4395       (when header
4396         (let ((number (mail-header-number header)))
4397           (push number gnus-newsgroup-limit)
4398           (push header gnus-newsgroup-headers)
4399           (if (memq number gnus-newsgroup-unselected)
4400               (progn
4401                 (setq gnus-newsgroup-unreads
4402                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4403                                                number))
4404                 (setq gnus-newsgroup-unselected
4405                       (delq number gnus-newsgroup-unselected)))
4406             (push number gnus-newsgroup-ancient)))))))
4407
4408 (defun gnus-build-all-threads ()
4409   "Read all the headers."
4410   (let ((gnus-summary-ignore-duplicates t)
4411         (mail-parse-charset gnus-newsgroup-charset)
4412         (dependencies gnus-newsgroup-dependencies)
4413         header article)
4414     (save-excursion
4415       (set-buffer nntp-server-buffer)
4416       (let ((case-fold-search nil))
4417         (goto-char (point-min))
4418         (while (not (eobp))
4419           (ignore-errors
4420             (setq article (read (current-buffer))
4421                   header (gnus-nov-parse-line article dependencies)))
4422           (when header
4423             (with-current-buffer gnus-summary-buffer
4424               (push header gnus-newsgroup-headers)
4425               (if (memq (setq article (mail-header-number header))
4426                         gnus-newsgroup-unselected)
4427                   (progn
4428                     (setq gnus-newsgroup-unreads
4429                           (gnus-add-to-sorted-list
4430                            gnus-newsgroup-unreads article))
4431                     (setq gnus-newsgroup-unselected
4432                           (delq article gnus-newsgroup-unselected)))
4433                 (push article gnus-newsgroup-ancient)))
4434             (forward-line 1)))))))
4435
4436 (defun gnus-summary-update-article-line (article header)
4437   "Update the line for ARTICLE using HEADER."
4438   (let* ((id (mail-header-id header))
4439          (thread (gnus-id-to-thread id)))
4440     (unless thread
4441       (error "Article in no thread"))
4442     ;; Update the thread.
4443     (setcar thread header)
4444     (gnus-summary-goto-subject article)
4445     (let* ((datal (gnus-data-find-list article))
4446            (data (car datal))
4447            (buffer-read-only nil)
4448            (level (gnus-summary-thread-level)))
4449       (gnus-delete-line)
4450       (let ((inserted (- (point)
4451                          (progn
4452                            (gnus-summary-insert-line
4453                             header level nil
4454                             (memq article gnus-newsgroup-undownloaded)
4455                             (gnus-article-mark article)
4456                             (memq article gnus-newsgroup-replied)
4457                             (memq article gnus-newsgroup-expirable)
4458                             ;; Only insert the Subject string when it's different
4459                             ;; from the previous Subject string.
4460                             (if (and
4461                                  gnus-show-threads
4462                                  (gnus-subject-equal
4463                                   (condition-case ()
4464                                       (mail-header-subject
4465                                        (gnus-data-header
4466                                         (cadr
4467                                          (gnus-data-find-list
4468                                           article
4469                                           (gnus-data-list t)))))
4470                                     ;; Error on the side of excessive subjects.
4471                                     (error ""))
4472                                   (mail-header-subject header)))
4473                                 ""
4474                               (mail-header-subject header))
4475                             nil (cdr (assq article gnus-newsgroup-scored))
4476                             (memq article gnus-newsgroup-processable))
4477                            (point)))))
4478         (when (cdr datal)
4479           (gnus-data-update-list
4480            (cdr datal)
4481            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4482
4483 (defun gnus-summary-update-article (article &optional iheader)
4484   "Update ARTICLE in the summary buffer."
4485   (set-buffer gnus-summary-buffer)
4486   (let* ((header (gnus-summary-article-header article))
4487          (id (mail-header-id header))
4488          (data (gnus-data-find article))
4489          (thread (gnus-id-to-thread id))
4490          (references (mail-header-references header))
4491          (parent
4492           (gnus-id-to-thread
4493            (or (gnus-parent-id
4494                 (when (and references
4495                            (not (equal "" references)))
4496                   references))
4497                "none")))
4498          (buffer-read-only nil)
4499          (old (car thread)))
4500     (when thread
4501       (unless iheader
4502         (setcar thread nil)
4503         (when parent
4504           (delq thread parent)))
4505       (if (gnus-summary-insert-subject id header)
4506           ;; Set the (possibly) new article number in the data structure.
4507           (gnus-data-set-number data (gnus-id-to-article id))
4508         (setcar thread old)
4509         nil))))
4510
4511 (defun gnus-rebuild-thread (id &optional line)
4512   "Rebuild the thread containing ID.
4513 If LINE, insert the rebuilt thread starting on line LINE."
4514   (let ((buffer-read-only nil)
4515         old-pos current thread data)
4516     (if (not gnus-show-threads)
4517         (setq thread (list (car (gnus-id-to-thread id))))
4518       ;; Get the thread this article is part of.
4519       (setq thread (gnus-remove-thread id)))
4520     (setq old-pos (point-at-bol))
4521     (setq current (save-excursion
4522                     (and (re-search-backward "[\r\n]" nil t)
4523                          (gnus-summary-article-number))))
4524     ;; If this is a gathered thread, we have to go some re-gathering.
4525     (when (stringp (car thread))
4526       (let ((subject (car thread))
4527             roots thr)
4528         (setq thread (cdr thread))
4529         (while thread
4530           (unless (memq (setq thr (gnus-id-to-thread
4531                                    (gnus-root-id
4532                                     (mail-header-id (caar thread)))))
4533                         roots)
4534             (push thr roots))
4535           (setq thread (cdr thread)))
4536         ;; We now have all (unique) roots.
4537         (if (= (length roots) 1)
4538             ;; All the loose roots are now one solid root.
4539             (setq thread (car roots))
4540           (setq thread (cons subject (gnus-sort-threads roots))))))
4541     (let (threads)
4542       ;; We then insert this thread into the summary buffer.
4543       (when line
4544         (goto-char (point-min))
4545         (forward-line (1- line)))
4546       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4547         (if gnus-show-threads
4548             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4549           (gnus-summary-prepare-unthreaded thread))
4550         (setq data (nreverse gnus-newsgroup-data))
4551         (setq threads gnus-newsgroup-threads))
4552       ;; We splice the new data into the data structure.
4553       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4554       ;;!!! then we want to insert at the beginning of the buffer.
4555       ;;!!! That happens to be true with Gnus now, but that may
4556       ;;!!! change in the future.  Perhaps.
4557       (gnus-data-enter-list
4558        (if line nil current) data (- (point) old-pos))
4559       (setq gnus-newsgroup-threads
4560             (nconc threads gnus-newsgroup-threads))
4561       (gnus-data-compute-positions))))
4562
4563 (defun gnus-number-to-header (number)
4564   "Return the header for article NUMBER."
4565   (let ((headers gnus-newsgroup-headers))
4566     (while (and headers
4567                 (not (= number (mail-header-number (car headers)))))
4568       (pop headers))
4569     (when headers
4570       (car headers))))
4571
4572 (defun gnus-parent-headers (in-headers &optional generation)
4573   "Return the headers of the GENERATIONeth parent of HEADERS."
4574   (unless generation
4575     (setq generation 1))
4576   (let ((parent t)
4577         (headers in-headers)
4578         references)
4579     (while (and parent
4580                 (not (zerop generation))
4581                 (setq references (mail-header-references headers)))
4582       (setq headers (if (and references
4583                              (setq parent (gnus-parent-id references)))
4584                         (car (gnus-id-to-thread parent))
4585                       nil))
4586       (decf generation))
4587     (and (not (eq headers in-headers))
4588          headers)))
4589
4590 (defun gnus-id-to-thread (id)
4591   "Return the (sub-)thread where ID appears."
4592   (gnus-gethash id gnus-newsgroup-dependencies))
4593
4594 (defun gnus-id-to-article (id)
4595   "Return the article number of ID."
4596   (let ((thread (gnus-id-to-thread id)))
4597     (when (and thread
4598                (car thread))
4599       (mail-header-number (car thread)))))
4600
4601 (defun gnus-id-to-header (id)
4602   "Return the article headers of ID."
4603   (car (gnus-id-to-thread id)))
4604
4605 (defun gnus-article-displayed-root-p (article)
4606   "Say whether ARTICLE is a root(ish) article."
4607   (let ((level (gnus-summary-thread-level article))
4608         (refs (mail-header-references  (gnus-summary-article-header article)))
4609         particle)
4610     (cond
4611      ((null level) nil)
4612      ((zerop level) t)
4613      ((null refs) t)
4614      ((null (gnus-parent-id refs)) t)
4615      ((and (= 1 level)
4616            (null (setq particle (gnus-id-to-article
4617                                  (gnus-parent-id refs))))
4618            (null (gnus-summary-thread-level particle)))))))
4619
4620 (defun gnus-root-id (id)
4621   "Return the id of the root of the thread where ID appears."
4622   (let (last-id prev)
4623     (while (and id (setq prev (car (gnus-id-to-thread id))))
4624       (setq last-id id
4625             id (gnus-parent-id (mail-header-references prev))))
4626     last-id))
4627
4628 (defun gnus-articles-in-thread (thread)
4629   "Return the list of articles in THREAD."
4630   (cons (mail-header-number (car thread))
4631         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4632
4633 (defun gnus-remove-thread (id &optional dont-remove)
4634   "Remove the thread that has ID in it."
4635   (let (headers thread last-id)
4636     ;; First go up in this thread until we find the root.
4637     (setq last-id (gnus-root-id id)
4638           headers (message-flatten-list (gnus-id-to-thread last-id)))
4639     ;; We have now found the real root of this thread.  It might have
4640     ;; been gathered into some loose thread, so we have to search
4641     ;; through the threads to find the thread we wanted.
4642     (let ((threads gnus-newsgroup-threads)
4643           sub)
4644       (while threads
4645         (setq sub (car threads))
4646         (if (stringp (car sub))
4647             ;; This is a gathered thread, so we look at the roots
4648             ;; below it to find whether this article is in this
4649             ;; gathered root.
4650             (progn
4651               (setq sub (cdr sub))
4652               (while sub
4653                 (when (member (caar sub) headers)
4654                   (setq thread (car threads)
4655                         threads nil
4656                         sub nil))
4657                 (setq sub (cdr sub))))
4658           ;; It's an ordinary thread, so we check it.
4659           (when (eq (car sub) (car headers))
4660             (setq thread sub
4661                   threads nil)))
4662         (setq threads (cdr threads)))
4663       ;; If this article is in no thread, then it's a root.
4664       (if thread
4665           (unless dont-remove
4666             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4667         (setq thread (gnus-id-to-thread last-id)))
4668       (when thread
4669         (prog1
4670             thread                      ; We return this thread.
4671           (unless dont-remove
4672             (if (stringp (car thread))
4673                 (progn
4674                   ;; If we use dummy roots, then we have to remove the
4675                   ;; dummy root as well.
4676                   (when (eq gnus-summary-make-false-root 'dummy)
4677                     ;; We go to the dummy root by going to
4678                     ;; the first sub-"thread", and then one line up.
4679                     (gnus-summary-goto-article
4680                      (mail-header-number (caadr thread)))
4681                     (forward-line -1)
4682                     (gnus-delete-line)
4683                     (gnus-data-compute-positions))
4684                   (setq thread (cdr thread))
4685                   (while thread
4686                     (gnus-remove-thread-1 (car thread))
4687                     (setq thread (cdr thread))))
4688               (gnus-remove-thread-1 thread))))))))
4689
4690 (defun gnus-remove-thread-1 (thread)
4691   "Remove the thread THREAD recursively."
4692   (let ((number (mail-header-number (pop thread)))
4693         d)
4694     (setq thread (reverse thread))
4695     (while thread
4696       (gnus-remove-thread-1 (pop thread)))
4697     (when (setq d (gnus-data-find number))
4698       (goto-char (gnus-data-pos d))
4699       (gnus-summary-show-thread)
4700       (gnus-data-remove
4701        number
4702        (- (point-at-bol)
4703           (prog1
4704               (1+ (point-at-eol))
4705             (gnus-delete-line)))))))
4706
4707 (defun gnus-sort-threads-recursive (threads func)
4708   (sort (mapcar (lambda (thread)
4709                   (cons (car thread)
4710                         (and (cdr thread)
4711                              (gnus-sort-threads-recursive (cdr thread) func))))
4712                 threads) func))
4713
4714 (defun gnus-sort-threads-loop (threads func)
4715   (let* ((superthread (cons nil threads))
4716          (stack (list (cons superthread threads)))
4717          remaining-threads thread)
4718     (while stack
4719       (setq remaining-threads (cdr (car stack)))
4720       (if remaining-threads
4721           (progn (setq thread (car remaining-threads))
4722                  (setcdr (car stack) (cdr remaining-threads))
4723                  (if (cdr thread)
4724                      (push (cons thread (cdr thread)) stack)))
4725         (setq thread (caar stack))
4726         (setcdr thread (sort (cdr thread) func))
4727         (pop stack)))
4728     (cdr superthread)))
4729
4730 (defun gnus-sort-threads (threads)
4731   "Sort THREADS."
4732   (if (not gnus-thread-sort-functions)
4733       threads
4734     (gnus-message 8 "Sorting threads...")
4735     (prog1
4736         (condition-case nil
4737             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4738               (gnus-sort-threads-recursive
4739                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4740           ;; Even after binding max-lisp-eval-depth, the recursive
4741           ;; sorter might fail for very long threads.  In that case,
4742           ;; try using a (less well-tested) non-recursive sorter.
4743           (error (gnus-sort-threads-loop
4744                   threads (gnus-make-sort-function
4745                            gnus-thread-sort-functions))))
4746       (gnus-message 8 "Sorting threads...done"))))
4747
4748 (defun gnus-sort-articles (articles)
4749   "Sort ARTICLES."
4750   (when gnus-article-sort-functions
4751     (gnus-message 7 "Sorting articles...")
4752     (prog1
4753         (setq gnus-newsgroup-headers
4754               (sort articles (gnus-make-sort-function
4755                               gnus-article-sort-functions)))
4756       (gnus-message 7 "Sorting articles...done"))))
4757
4758 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4759 (defmacro gnus-thread-header (thread)
4760   "Return header of first article in THREAD.
4761 Note that THREAD must never, ever be anything else than a variable -
4762 using some other form will lead to serious barfage."
4763   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4764   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4765   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4766         (vector thread) 2))
4767
4768 (defsubst gnus-article-sort-by-number (h1 h2)
4769   "Sort articles by article number."
4770   (< (mail-header-number h1)
4771      (mail-header-number h2)))
4772
4773 (defun gnus-thread-sort-by-number (h1 h2)
4774   "Sort threads by root article number."
4775   (gnus-article-sort-by-number
4776    (gnus-thread-header h1) (gnus-thread-header h2)))
4777
4778 (defsubst gnus-article-sort-by-random (h1 h2)
4779   "Sort articles by article number."
4780   (zerop (random 2)))
4781
4782 (defun gnus-thread-sort-by-random (h1 h2)
4783   "Sort threads by root article number."
4784   (gnus-article-sort-by-random
4785    (gnus-thread-header h1) (gnus-thread-header h2)))
4786
4787 (defsubst gnus-article-sort-by-lines (h1 h2)
4788   "Sort articles by article Lines header."
4789   (< (mail-header-lines h1)
4790      (mail-header-lines h2)))
4791
4792 (defun gnus-thread-sort-by-lines (h1 h2)
4793   "Sort threads by root article Lines header."
4794   (gnus-article-sort-by-lines
4795    (gnus-thread-header h1) (gnus-thread-header h2)))
4796
4797 (defsubst gnus-article-sort-by-chars (h1 h2)
4798   "Sort articles by octet length."
4799   (< (mail-header-chars h1)
4800      (mail-header-chars h2)))
4801
4802 (defun gnus-thread-sort-by-chars (h1 h2)
4803   "Sort threads by root article octet length."
4804   (gnus-article-sort-by-chars
4805    (gnus-thread-header h1) (gnus-thread-header h2)))
4806
4807 (defsubst gnus-article-sort-by-author (h1 h2)
4808   "Sort articles by root author."
4809   (string-lessp
4810    (let ((extract (funcall
4811                    gnus-extract-address-components
4812                    (mail-header-from h1))))
4813      (or (car extract) (cadr extract) ""))
4814    (let ((extract (funcall
4815                    gnus-extract-address-components
4816                    (mail-header-from h2))))
4817      (or (car extract) (cadr extract) ""))))
4818
4819 (defun gnus-thread-sort-by-author (h1 h2)
4820   "Sort threads by root author."
4821   (gnus-article-sort-by-author
4822    (gnus-thread-header h1)  (gnus-thread-header h2)))
4823
4824 (defsubst gnus-article-sort-by-recipient (h1 h2)
4825   "Sort articles by recipient."
4826   (string-lessp
4827    (let ((extract (funcall
4828                    gnus-extract-address-components
4829                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4830      (or (car extract) (cadr extract)))
4831    (let ((extract (funcall
4832                    gnus-extract-address-components
4833                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4834      (or (car extract) (cadr extract)))))
4835
4836 (defun gnus-thread-sort-by-recipient (h1 h2)
4837   "Sort threads by root recipient."
4838   (gnus-article-sort-by-recipient
4839    (gnus-thread-header h1) (gnus-thread-header h2)))
4840
4841 (defsubst gnus-article-sort-by-subject (h1 h2)
4842   "Sort articles by root subject."
4843   (string-lessp
4844    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4845    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4846
4847 (defun gnus-thread-sort-by-subject (h1 h2)
4848   "Sort threads by root subject."
4849   (gnus-article-sort-by-subject
4850    (gnus-thread-header h1) (gnus-thread-header h2)))
4851
4852 (defsubst gnus-article-sort-by-date (h1 h2)
4853   "Sort articles by root article date."
4854   (time-less-p
4855    (gnus-date-get-time (mail-header-date h1))
4856    (gnus-date-get-time (mail-header-date h2))))
4857
4858 (defun gnus-thread-sort-by-date (h1 h2)
4859   "Sort threads by root article date."
4860   (gnus-article-sort-by-date
4861    (gnus-thread-header h1) (gnus-thread-header h2)))
4862
4863 (defsubst gnus-article-sort-by-score (h1 h2)
4864   "Sort articles by root article score.
4865 Unscored articles will be counted as having a score of zero."
4866   (> (or (cdr (assq (mail-header-number h1)
4867                     gnus-newsgroup-scored))
4868          gnus-summary-default-score 0)
4869      (or (cdr (assq (mail-header-number h2)
4870                     gnus-newsgroup-scored))
4871          gnus-summary-default-score 0)))
4872
4873 (defun gnus-thread-sort-by-score (h1 h2)
4874   "Sort threads by root article score."
4875   (gnus-article-sort-by-score
4876    (gnus-thread-header h1) (gnus-thread-header h2)))
4877
4878 (defun gnus-thread-sort-by-total-score (h1 h2)
4879   "Sort threads by the sum of all scores in the thread.
4880 Unscored articles will be counted as having a score of zero."
4881   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4882
4883 (defun gnus-thread-total-score (thread)
4884   ;; This function find the total score of THREAD.
4885   (cond
4886    ((null thread)
4887     0)
4888    ((consp thread)
4889     (if (stringp (car thread))
4890         (apply gnus-thread-score-function 0
4891                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4892       (gnus-thread-total-score-1 thread)))
4893    (t
4894     (gnus-thread-total-score-1 (list thread)))))
4895
4896 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4897   "Sort threads such that the thread with the most recently arrived article comes first."
4898   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4899
4900 (defun gnus-thread-highest-number (thread)
4901   "Return the highest article number in THREAD."
4902   (apply 'max (mapcar (lambda (header)
4903                         (mail-header-number header))
4904                       (message-flatten-list thread))))
4905
4906 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4907   "Sort threads such that the thread with the most recently dated article comes first."
4908   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4909
4910 (defun gnus-thread-latest-date (thread)
4911   "Return the highest article date in THREAD."
4912   (let ((previous-time 0))
4913     (apply 'max
4914            (mapcar
4915             (lambda (header)
4916               (setq previous-time
4917                     (condition-case ()
4918                         (time-to-seconds (mail-header-parse-date
4919                                           (mail-header-date header)))
4920                       (error previous-time))))
4921             (sort
4922              (message-flatten-list thread)
4923              (lambda (h1 h2)
4924                (< (mail-header-number h1)
4925                   (mail-header-number h2))))))))
4926
4927 (defun gnus-thread-total-score-1 (root)
4928   ;; This function find the total score of the thread below ROOT.
4929   (setq root (car root))
4930   (apply gnus-thread-score-function
4931          (or (append
4932               (mapcar 'gnus-thread-total-score
4933                       (cdr (gnus-id-to-thread (mail-header-id root))))
4934               (when (> (mail-header-number root) 0)
4935                 (list (or (cdr (assq (mail-header-number root)
4936                                      gnus-newsgroup-scored))
4937                           gnus-summary-default-score 0))))
4938              (list gnus-summary-default-score)
4939              '(0))))
4940
4941 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4942 (defvar gnus-tmp-prev-subject nil)
4943 (defvar gnus-tmp-false-parent nil)
4944 (defvar gnus-tmp-root-expunged nil)
4945 (defvar gnus-tmp-dummy-line nil)
4946
4947 (eval-when-compile (defvar gnus-tmp-header))
4948 (defun gnus-extra-header (type &optional header)
4949   "Return the extra header of TYPE."
4950   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4951       ""))
4952
4953 (defvar gnus-tmp-thread-tree-header-string "")
4954
4955 (defcustom gnus-sum-thread-tree-root "> "
4956   "With %B spec, used for the root of a thread.
4957 If nil, use subject instead."
4958   :version "22.1"
4959   :type '(radio (const :format "%v  " nil) string)
4960   :group 'gnus-thread)
4961
4962 (defcustom gnus-sum-thread-tree-false-root "> "
4963   "With %B spec, used for a false root of a thread.
4964 If nil, use subject instead."
4965   :version "22.1"
4966   :type '(radio (const :format "%v  " nil) string)
4967   :group 'gnus-thread)
4968
4969 (defcustom gnus-sum-thread-tree-single-indent ""
4970   "With %B spec, used for a thread with just one message.
4971 If nil, use subject instead."
4972   :version "22.1"
4973   :type '(radio (const :format "%v  " nil) string)
4974   :group 'gnus-thread)
4975
4976 (defcustom gnus-sum-thread-tree-vertical "| "
4977   "With %B spec, used for drawing a vertical line."
4978   :version "22.1"
4979   :type 'string
4980   :group 'gnus-thread)
4981
4982 (defcustom gnus-sum-thread-tree-indent "  "
4983   "With %B spec, used for indenting."
4984   :version "22.1"
4985   :type 'string
4986   :group 'gnus-thread)
4987
4988 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4989   "With %B spec, used for a leaf with brothers."
4990   :version "22.1"
4991   :type 'string
4992   :group 'gnus-thread)
4993
4994 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4995   "With %B spec, used for a leaf without brothers."
4996   :version "22.1"
4997   :type 'string
4998   :group 'gnus-thread)
4999
5000 (defun gnus-summary-prepare-threads (threads)
5001   "Prepare summary buffer from THREADS and indentation LEVEL.
5002 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5003 or a straight list of headers."
5004   (gnus-message 7 "Generating summary...")
5005
5006   (setq gnus-newsgroup-threads threads)
5007   (beginning-of-line)
5008
5009   (let ((gnus-tmp-level 0)
5010         (default-score (or gnus-summary-default-score 0))
5011         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5012         (building-line-count gnus-summary-display-while-building)
5013         (building-count (integerp gnus-summary-display-while-building))
5014         thread number subject stack state gnus-tmp-gathered beg-match
5015         new-roots gnus-tmp-new-adopts thread-end simp-subject
5016         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5017         gnus-tmp-replied gnus-tmp-subject-or-nil
5018         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5019         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5020         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5021         tree-stack)
5022
5023     (setq gnus-tmp-prev-subject nil
5024           gnus-tmp-thread-tree-header-string "")
5025
5026     (if (vectorp (car threads))
5027         ;; If this is a straight (sic) list of headers, then a
5028         ;; threaded summary display isn't required, so we just create
5029         ;; an unthreaded one.
5030         (gnus-summary-prepare-unthreaded threads)
5031
5032       ;; Do the threaded display.
5033
5034       (if gnus-summary-display-while-building
5035           (switch-to-buffer (buffer-name)))
5036       (while (or threads stack gnus-tmp-new-adopts new-roots)
5037
5038         (if (and (= gnus-tmp-level 0)
5039                  (or (not stack)
5040                      (= (caar stack) 0))
5041                  (not gnus-tmp-false-parent)
5042                  (or gnus-tmp-new-adopts new-roots))
5043             (if gnus-tmp-new-adopts
5044                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5045                       thread (list (car gnus-tmp-new-adopts))
5046                       gnus-tmp-header (caar thread)
5047                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5048               (when new-roots
5049                 (setq thread (list (car new-roots))
5050                       gnus-tmp-header (caar thread)
5051                       new-roots (cdr new-roots))))
5052
5053           (if threads
5054               ;; If there are some threads, we do them before the
5055               ;; threads on the stack.
5056               (setq thread threads
5057                     gnus-tmp-header (caar thread))
5058             ;; There were no current threads, so we pop something off
5059             ;; the stack.
5060             (setq state (car stack)
5061                   gnus-tmp-level (car state)
5062                   tree-stack (cadr state)
5063                   thread (caddr state)
5064                   stack (cdr stack)
5065                   gnus-tmp-header (caar thread))))
5066
5067         (setq gnus-tmp-false-parent nil)
5068         (setq gnus-tmp-root-expunged nil)
5069         (setq thread-end nil)
5070
5071         (if (stringp gnus-tmp-header)
5072             ;; The header is a dummy root.
5073             (cond
5074              ((eq gnus-summary-make-false-root 'adopt)
5075               ;; We let the first article adopt the rest.
5076               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5077                                                (cddar thread)))
5078               (setq gnus-tmp-gathered
5079                     (nconc (mapcar
5080                             (lambda (h) (mail-header-number (car h)))
5081                             (cddar thread))
5082                            gnus-tmp-gathered))
5083               (setq thread (cons (list (caar thread)
5084                                        (cadar thread))
5085                                  (cdr thread)))
5086               (setq gnus-tmp-level -1
5087                     gnus-tmp-false-parent t))
5088              ((eq gnus-summary-make-false-root 'empty)
5089               ;; We print adopted articles with empty subject fields.
5090               (setq gnus-tmp-gathered
5091                     (nconc (mapcar
5092                             (lambda (h) (mail-header-number (car h)))
5093                             (cddar thread))
5094                            gnus-tmp-gathered))
5095               (setq gnus-tmp-level -1))
5096              ((eq gnus-summary-make-false-root 'dummy)
5097               ;; We remember that we probably want to output a dummy
5098               ;; root.
5099               (setq gnus-tmp-dummy-line gnus-tmp-header)
5100               (setq gnus-tmp-prev-subject gnus-tmp-header))
5101              (t
5102               ;; We do not make a root for the gathered
5103               ;; sub-threads at all.
5104               (setq gnus-tmp-level -1)))
5105
5106           (setq number (mail-header-number gnus-tmp-header)
5107                 subject (mail-header-subject gnus-tmp-header)
5108                 simp-subject (gnus-simplify-subject-fully subject))
5109
5110           (cond
5111            ;; If the thread has changed subject, we might want to make
5112            ;; this subthread into a root.
5113            ((and (null gnus-thread-ignore-subject)
5114                  (not (zerop gnus-tmp-level))
5115                  gnus-tmp-prev-subject
5116                  (not (string= gnus-tmp-prev-subject simp-subject)))
5117             (setq new-roots (nconc new-roots (list (car thread)))
5118                   thread-end t
5119                   gnus-tmp-header nil))
5120            ;; If the article lies outside the current limit,
5121            ;; then we do not display it.
5122            ((not (memq number gnus-newsgroup-limit))
5123             (setq gnus-tmp-gathered
5124                   (nconc (mapcar
5125                           (lambda (h) (mail-header-number (car h)))
5126                           (cdar thread))
5127                          gnus-tmp-gathered))
5128             (setq gnus-tmp-new-adopts (if (cdar thread)
5129                                           (append gnus-tmp-new-adopts
5130                                                   (cdar thread))
5131                                         gnus-tmp-new-adopts)
5132                   thread-end t
5133                   gnus-tmp-header nil)
5134             (when (zerop gnus-tmp-level)
5135               (setq gnus-tmp-root-expunged t)))
5136            ;; Perhaps this article is to be marked as read?
5137            ((and gnus-summary-mark-below
5138                  (< (or (cdr (assq number gnus-newsgroup-scored))
5139                         default-score)
5140                     gnus-summary-mark-below)
5141                  ;; Don't touch sparse articles.
5142                  (not (gnus-summary-article-sparse-p number))
5143                  (not (gnus-summary-article-ancient-p number)))
5144             (setq gnus-newsgroup-unreads
5145                   (delq number gnus-newsgroup-unreads))
5146             (if gnus-newsgroup-auto-expire
5147                 (setq gnus-newsgroup-expirable
5148                       (gnus-add-to-sorted-list
5149                        gnus-newsgroup-expirable number))
5150               (push (cons number gnus-low-score-mark)
5151                     gnus-newsgroup-reads))))
5152
5153           (when gnus-tmp-header
5154             ;; We may have an old dummy line to output before this
5155             ;; article.
5156             (when (and gnus-tmp-dummy-line
5157                        (gnus-subject-equal
5158                         gnus-tmp-dummy-line
5159                         (mail-header-subject gnus-tmp-header)))
5160               (gnus-summary-insert-dummy-line
5161                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5162               (setq gnus-tmp-dummy-line nil))
5163
5164             ;; Compute the mark.
5165             (setq gnus-tmp-unread (gnus-article-mark number))
5166
5167             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5168                                   gnus-tmp-header gnus-tmp-level)
5169                   gnus-newsgroup-data)
5170
5171             ;; Actually insert the line.
5172             (setq
5173              gnus-tmp-subject-or-nil
5174              (cond
5175               ((and gnus-thread-ignore-subject
5176                     gnus-tmp-prev-subject
5177                     (not (string= gnus-tmp-prev-subject simp-subject)))
5178                subject)
5179               ((zerop gnus-tmp-level)
5180                (if (and (eq gnus-summary-make-false-root 'empty)
5181                         (memq number gnus-tmp-gathered)
5182                         gnus-tmp-prev-subject
5183                         (string= gnus-tmp-prev-subject simp-subject))
5184                    gnus-summary-same-subject
5185                  subject))
5186               (t gnus-summary-same-subject)))
5187             (if (and (eq gnus-summary-make-false-root 'adopt)
5188                      (= gnus-tmp-level 1)
5189                      (memq number gnus-tmp-gathered))
5190                 (setq gnus-tmp-opening-bracket ?\<
5191                       gnus-tmp-closing-bracket ?\>)
5192               (setq gnus-tmp-opening-bracket ?\[
5193                     gnus-tmp-closing-bracket ?\]))
5194             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5195                 (gnus-make-thread-indent-array
5196                  (max (* 2 (length gnus-thread-indent-array))
5197                       gnus-tmp-level)))
5198             (setq
5199              gnus-tmp-indentation
5200              (aref gnus-thread-indent-array gnus-tmp-level)
5201              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5202              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5203                                 gnus-summary-default-score 0)
5204              gnus-tmp-score-char
5205              (if (or (null gnus-summary-default-score)
5206                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5207                          gnus-summary-zcore-fuzz))
5208                  ?                      ;Whitespace
5209                (if (< gnus-tmp-score gnus-summary-default-score)
5210                    gnus-score-below-mark gnus-score-over-mark))
5211              gnus-tmp-replied
5212              (cond ((memq number gnus-newsgroup-processable)
5213                     gnus-process-mark)
5214                    ((memq number gnus-newsgroup-cached)
5215                     gnus-cached-mark)
5216                    ((memq number gnus-newsgroup-replied)
5217                     gnus-replied-mark)
5218                    ((memq number gnus-newsgroup-forwarded)
5219                     gnus-forwarded-mark)
5220                    ((memq number gnus-newsgroup-saved)
5221                     gnus-saved-mark)
5222                    ((memq number gnus-newsgroup-recent)
5223                     gnus-recent-mark)
5224                    ((memq number gnus-newsgroup-unseen)
5225                     gnus-unseen-mark)
5226                    (t gnus-no-mark))
5227              gnus-tmp-downloaded
5228              (cond ((memq number gnus-newsgroup-undownloaded)
5229                     gnus-undownloaded-mark)
5230                    (gnus-newsgroup-agentized
5231                     gnus-downloaded-mark)
5232                    (t
5233                     gnus-no-mark))
5234              gnus-tmp-from (mail-header-from gnus-tmp-header)
5235              gnus-tmp-name
5236              (cond
5237               ((string-match "<[^>]+> *$" gnus-tmp-from)
5238                (setq beg-match (match-beginning 0))
5239                (or (and (string-match "^\".+\"" gnus-tmp-from)
5240                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5241                    (substring gnus-tmp-from 0 beg-match)))
5242               ((string-match "(.+)" gnus-tmp-from)
5243                (substring gnus-tmp-from
5244                           (1+ (match-beginning 0)) (1- (match-end 0))))
5245               (t gnus-tmp-from))
5246
5247              ;; Do the %B string
5248              gnus-tmp-thread-tree-header-string
5249              (cond
5250               ((not gnus-show-threads) "")
5251               ((zerop gnus-tmp-level)
5252                (cond ((cdar thread)
5253                       (or gnus-sum-thread-tree-root subject))
5254                      (gnus-tmp-new-adopts
5255                       (or gnus-sum-thread-tree-false-root subject))
5256                      (t
5257                       (or gnus-sum-thread-tree-single-indent subject))))
5258               (t
5259                (concat (apply 'concat
5260                               (mapcar (lambda (item)
5261                                         (if (= item 1)
5262                                             gnus-sum-thread-tree-vertical
5263                                           gnus-sum-thread-tree-indent))
5264                                       (cdr (reverse tree-stack))))
5265                        (if (nth 1 thread)
5266                            gnus-sum-thread-tree-leaf-with-other
5267                          gnus-sum-thread-tree-single-leaf)))))
5268             (when (string= gnus-tmp-name "")
5269               (setq gnus-tmp-name gnus-tmp-from))
5270             (unless (numberp gnus-tmp-lines)
5271               (setq gnus-tmp-lines -1))
5272             (if (= gnus-tmp-lines -1)
5273                 (setq gnus-tmp-lines "?")
5274               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5275               (gnus-put-text-property
5276              (point)
5277              (progn (eval gnus-summary-line-format-spec) (point))
5278                'gnus-number number)
5279             (when gnus-visual-p
5280               (forward-line -1)
5281               (gnus-run-hooks 'gnus-summary-update-hook)
5282               (forward-line 1))
5283
5284             (setq gnus-tmp-prev-subject simp-subject)))
5285
5286         (when (nth 1 thread)
5287           (push (list (max 0 gnus-tmp-level)
5288                       (copy-sequence tree-stack)
5289                       (nthcdr 1 thread))
5290                 stack))
5291         (push (if (nth 1 thread) 1 0) tree-stack)
5292         (incf gnus-tmp-level)
5293         (setq threads (if thread-end nil (cdar thread)))
5294         (if gnus-summary-display-while-building
5295             (if building-count
5296                 (progn
5297                   ;; use a set frequency
5298                   (setq building-line-count (1- building-line-count))
5299                   (when (= building-line-count 0)
5300                     (sit-for 0)
5301                     (setq building-line-count
5302                           gnus-summary-display-while-building)))
5303               ;; always
5304               (sit-for 0)))
5305         (unless threads
5306           (setq gnus-tmp-level 0)))))
5307   (gnus-message 7 "Generating summary...done"))
5308
5309 (defun gnus-summary-prepare-unthreaded (headers)
5310   "Generate an unthreaded summary buffer based on HEADERS."
5311   (let (header number mark)
5312
5313     (beginning-of-line)
5314
5315     (while headers
5316       ;; We may have to root out some bad articles...
5317       (when (memq (setq number (mail-header-number
5318                                 (setq header (pop headers))))
5319                   gnus-newsgroup-limit)
5320         ;; Mark article as read when it has a low score.
5321         (when (and gnus-summary-mark-below
5322                    (< (or (cdr (assq number gnus-newsgroup-scored))
5323                           gnus-summary-default-score 0)
5324                       gnus-summary-mark-below)
5325                    (not (gnus-summary-article-ancient-p number)))
5326           (setq gnus-newsgroup-unreads
5327                 (delq number gnus-newsgroup-unreads))
5328           (if gnus-newsgroup-auto-expire
5329               (push number gnus-newsgroup-expirable)
5330             (push (cons number gnus-low-score-mark)
5331                   gnus-newsgroup-reads)))
5332
5333         (setq mark (gnus-article-mark number))
5334         (push (gnus-data-make number mark (1+ (point)) header 0)
5335               gnus-newsgroup-data)
5336         (gnus-summary-insert-line
5337          header 0 number
5338          (memq number gnus-newsgroup-undownloaded)
5339          mark (memq number gnus-newsgroup-replied)
5340          (memq number gnus-newsgroup-expirable)
5341          (mail-header-subject header) nil
5342          (cdr (assq number gnus-newsgroup-scored))
5343          (memq number gnus-newsgroup-processable))))))
5344
5345 (defun gnus-summary-remove-list-identifiers ()
5346   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5347   (let ((regexp (if (consp gnus-list-identifiers)
5348                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5349                   gnus-list-identifiers))
5350         changed subject)
5351     (when regexp
5352       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5353       (dolist (header gnus-newsgroup-headers)
5354         (setq subject (mail-header-subject header)
5355               changed nil)
5356         (while (string-match regexp subject)
5357           (setq subject
5358                 (concat (substring subject 0 (match-beginning 1))
5359                         (substring subject (match-end 0)))
5360                 changed t))
5361         (when changed
5362           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5363             (setq subject
5364                   (concat (substring subject 0 (match-beginning 1))
5365                           (substring subject (match-end 1)))))
5366           (mail-header-set-subject header subject))))))
5367
5368 (defun gnus-fetch-headers (articles)
5369   "Fetch headers of ARTICLES."
5370   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5371     (gnus-message 5 "Fetching headers for %s..." name)
5372     (prog1
5373         (if (eq 'nov
5374                 (setq gnus-headers-retrieved-by
5375                       (gnus-retrieve-headers
5376                        articles gnus-newsgroup-name
5377                        ;; We might want to fetch old headers, but
5378                        ;; not if there is only 1 article.
5379                        (and (or (and
5380                                  (not (eq gnus-fetch-old-headers 'some))
5381                                  (not (numberp gnus-fetch-old-headers)))
5382                                 (> (length articles) 1))
5383                             gnus-fetch-old-headers))))
5384             (gnus-get-newsgroup-headers-xover
5385              articles nil nil gnus-newsgroup-name t)
5386           (gnus-get-newsgroup-headers))
5387       (gnus-message 5 "Fetching headers for %s...done" name))))
5388
5389 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5390   "Select newsgroup GROUP.
5391 If READ-ALL is non-nil, all articles in the group are selected.
5392 If SELECT-ARTICLES, only select those articles from GROUP."
5393   (let* ((entry (gnus-group-entry group))
5394          ;;!!! Dirty hack; should be removed.
5395          (gnus-summary-ignore-duplicates
5396           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5397               t
5398             gnus-summary-ignore-duplicates))
5399          (info (nth 2 entry))
5400          articles fetched-articles cached)
5401
5402     (unless (gnus-check-server
5403              (set (make-local-variable 'gnus-current-select-method)
5404                   (gnus-find-method-for-group group)))
5405       (error "Couldn't open server"))
5406
5407     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5408         (gnus-activate-group group)     ; Or we can activate it...
5409         (progn                          ; Or we bug out.
5410           (when (equal major-mode 'gnus-summary-mode)
5411             (gnus-kill-buffer (current-buffer)))
5412           (error "Couldn't activate group %s: %s"
5413                  (gnus-group-decoded-name group) (gnus-status-message group))))
5414
5415     (unless (gnus-request-group group t)
5416       (when (equal major-mode 'gnus-summary-mode)
5417         (gnus-kill-buffer (current-buffer)))
5418       (error "Couldn't request group %s: %s"
5419              (gnus-group-decoded-name group) (gnus-status-message group)))
5420
5421     (when gnus-agent
5422       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5423
5424       (setq gnus-summary-use-undownloaded-faces
5425             (gnus-agent-find-parameter
5426              group
5427              'agent-enable-undownloaded-faces)))
5428
5429     (setq gnus-newsgroup-name group
5430           gnus-newsgroup-unselected nil
5431           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5432
5433     (let ((display (gnus-group-find-parameter group 'display)))
5434       (setq gnus-newsgroup-display
5435             (cond
5436              ((not (zerop (or (car-safe read-all) 0)))
5437               ;; The user entered the group with C-u SPC/RET, let's show
5438               ;; all articles.
5439               'gnus-not-ignore)
5440              ((eq display 'all)
5441               'gnus-not-ignore)
5442              ((arrayp display)
5443               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5444              ((numberp display)
5445               ;; The following is probably the "correct" solution, but
5446               ;; it makes Gnus fetch all headers and then limit the
5447               ;; articles (which is slow), so instead we hack the
5448               ;; select-articles parameter instead. -- Simon Josefsson
5449               ;; <jas@kth.se>
5450               ;;
5451               ;; (gnus-byte-compile
5452               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5453               ;;                         display)))))
5454               (setq select-articles
5455                     (gnus-uncompress-range
5456                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5457                              (if (> tmp 0)
5458                                  tmp
5459                                1))
5460                            (cdr (gnus-active group)))))
5461               nil)
5462              (t
5463               nil))))
5464
5465     (gnus-summary-setup-default-charset)
5466
5467     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5468     (when (gnus-virtual-group-p group)
5469       (setq cached gnus-newsgroup-cached))
5470
5471     (setq gnus-newsgroup-unreads
5472           (gnus-sorted-ndifference
5473            (gnus-sorted-ndifference gnus-newsgroup-unreads
5474                                     gnus-newsgroup-marked)
5475            gnus-newsgroup-dormant))
5476
5477     (setq gnus-newsgroup-processable nil)
5478
5479     (gnus-update-read-articles group gnus-newsgroup-unreads)
5480
5481     ;; Adjust and set lists of article marks.
5482     (when info
5483       (gnus-adjust-marked-articles info))
5484     (if (setq articles select-articles)
5485         (setq gnus-newsgroup-unselected
5486               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5487       (setq articles (gnus-articles-to-read group read-all)))
5488
5489     (cond
5490      ((null articles)
5491       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5492       'quit)
5493      ((eq articles 0) nil)
5494      (t
5495       ;; Init the dependencies hash table.
5496       (setq gnus-newsgroup-dependencies
5497             (gnus-make-hashtable (length articles)))
5498       (gnus-set-global-variables)
5499       ;; Retrieve the headers and read them in.
5500
5501       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5502
5503       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5504       (when cached
5505         (setq gnus-newsgroup-cached cached))
5506
5507       ;; Suppress duplicates?
5508       (when gnus-suppress-duplicates
5509         (gnus-dup-suppress-articles))
5510
5511       ;; Set the initial limit.
5512       (setq gnus-newsgroup-limit (copy-sequence articles))
5513       ;; Remove canceled articles from the list of unread articles.
5514       (setq fetched-articles
5515             (mapcar (lambda (headers) (mail-header-number headers))
5516                     gnus-newsgroup-headers))
5517       (setq gnus-newsgroup-articles fetched-articles)
5518       (setq gnus-newsgroup-unreads
5519             (gnus-sorted-nintersection
5520              gnus-newsgroup-unreads fetched-articles))
5521       (gnus-compute-unseen-list)
5522
5523       ;; Removed marked articles that do not exist.
5524       (gnus-update-missing-marks
5525        (gnus-sorted-difference articles fetched-articles))
5526       ;; We might want to build some more threads first.
5527       (when (and gnus-fetch-old-headers
5528                  (eq gnus-headers-retrieved-by 'nov))
5529         (if (eq gnus-fetch-old-headers 'invisible)
5530             (gnus-build-all-threads)
5531           (gnus-build-old-threads)))
5532       ;; Let the Gnus agent mark articles as read.
5533       (when gnus-agent
5534         (gnus-agent-get-undownloaded-list))
5535       ;; Remove list identifiers from subject
5536       (when gnus-list-identifiers
5537         (gnus-summary-remove-list-identifiers))
5538       ;; Check whether auto-expire is to be done in this group.
5539       (setq gnus-newsgroup-auto-expire
5540             (gnus-group-auto-expirable-p group))
5541       ;; Set up the article buffer now, if necessary.
5542       (unless (and gnus-single-article-buffer
5543                    (equal gnus-article-buffer "*Article*"))
5544         (gnus-article-setup-buffer))
5545       ;; First and last article in this newsgroup.
5546       (when gnus-newsgroup-headers
5547         (setq gnus-newsgroup-begin
5548               (mail-header-number (car gnus-newsgroup-headers))
5549               gnus-newsgroup-end
5550               (mail-header-number
5551                (gnus-last-element gnus-newsgroup-headers))))
5552       ;; GROUP is successfully selected.
5553       (or gnus-newsgroup-headers t)))))
5554
5555 (defun gnus-compute-unseen-list ()
5556   ;; The `seen' marks are treated specially.
5557   (if (not gnus-newsgroup-seen)
5558       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5559     (setq gnus-newsgroup-unseen
5560           (gnus-inverse-list-range-intersection
5561            gnus-newsgroup-articles gnus-newsgroup-seen))))
5562
5563 (defun gnus-summary-display-make-predicate (display)
5564   (require 'gnus-agent)
5565   (when (= (length display) 1)
5566     (setq display (car display)))
5567   (unless gnus-summary-display-cache
5568     (dolist (elem (append '((unread . unread)
5569                             (read . read)
5570                             (unseen . unseen))
5571                           gnus-article-mark-lists))
5572       (push (cons (cdr elem)
5573                   (gnus-byte-compile
5574                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5575             gnus-summary-display-cache)))
5576   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5577         (gnus-category-predicate-cache gnus-summary-display-cache))
5578     (gnus-get-predicate display)))
5579
5580 ;; Uses the dynamically bound `number' variable.
5581 (eval-when-compile
5582   (defvar number))
5583 (defun gnus-article-marked-p (type &optional article)
5584   (let ((article (or article number)))
5585     (cond
5586      ((eq type 'tick)
5587       (memq article gnus-newsgroup-marked))
5588      ((eq type 'spam)
5589       (memq article gnus-newsgroup-spam-marked))
5590      ((eq type 'unsend)
5591       (memq article gnus-newsgroup-unsendable))
5592      ((eq type 'undownload)
5593       (memq article gnus-newsgroup-undownloaded))
5594      ((eq type 'download)
5595       (memq article gnus-newsgroup-downloadable))
5596      ((eq type 'unread)
5597       (memq article gnus-newsgroup-unreads))
5598      ((eq type 'read)
5599       (memq article gnus-newsgroup-reads))
5600      ((eq type 'dormant)
5601       (memq article gnus-newsgroup-dormant) )
5602      ((eq type 'expire)
5603       (memq article gnus-newsgroup-expirable))
5604      ((eq type 'reply)
5605       (memq article gnus-newsgroup-replied))
5606      ((eq type 'killed)
5607       (memq article gnus-newsgroup-killed))
5608      ((eq type 'bookmark)
5609       (assq article gnus-newsgroup-bookmarks))
5610      ((eq type 'score)
5611       (assq article gnus-newsgroup-scored))
5612      ((eq type 'save)
5613       (memq article gnus-newsgroup-saved))
5614      ((eq type 'cache)
5615       (memq article gnus-newsgroup-cached))
5616      ((eq type 'forward)
5617       (memq article gnus-newsgroup-forwarded))
5618      ((eq type 'seen)
5619       (not (memq article gnus-newsgroup-unseen)))
5620      ((eq type 'recent)
5621       (memq article gnus-newsgroup-recent))
5622      (t t))))
5623
5624 (defun gnus-articles-to-read (group &optional read-all)
5625   "Find out what articles the user wants to read."
5626   (let* ((articles
5627           ;; Select all articles if `read-all' is non-nil, or if there
5628           ;; are no unread articles.
5629           (if (or read-all
5630                   (and (zerop (length gnus-newsgroup-marked))
5631                        (zerop (length gnus-newsgroup-unreads)))
5632                   ;; Fetch all if the predicate is non-nil.
5633                   gnus-newsgroup-display)
5634               ;; We want to select the headers for all the articles in
5635               ;; the group, so we select either all the active
5636               ;; articles in the group, or (if that's nil), the
5637               ;; articles in the cache.
5638               (or
5639                (gnus-uncompress-range (gnus-active group))
5640                (gnus-cache-articles-in-group group))
5641             ;; Select only the "normal" subset of articles.
5642             (gnus-sorted-nunion
5643              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5644              gnus-newsgroup-unreads)))
5645          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5646          (scored (length scored-list))
5647          (number (length articles))
5648          (marked (+ (length gnus-newsgroup-marked)
5649                     (length gnus-newsgroup-dormant)))
5650          (select
5651           (cond
5652            ((numberp read-all)
5653             read-all)
5654            ((numberp gnus-newsgroup-display)
5655             gnus-newsgroup-display)
5656            (t
5657             (condition-case ()
5658                 (cond
5659                  ((and (or (<= scored marked) (= scored number))
5660                        (numberp gnus-large-newsgroup)
5661                        (> number gnus-large-newsgroup))
5662                   (let* ((cursor-in-echo-area nil)
5663                          (initial (gnus-parameter-large-newsgroup-initial
5664                                    gnus-newsgroup-name))
5665                          (input
5666                           (read-string
5667                            (format
5668                             "How many articles from %s (%s %d): "
5669                             (gnus-group-decoded-name gnus-newsgroup-name)
5670                             (if initial "max" "default")
5671                             number)
5672                            (if initial
5673                                (cons (number-to-string initial)
5674                                      0)))))
5675                     (if (string-match "^[ \t]*$" input) number input)))
5676                  ((and (> scored marked) (< scored number)
5677                        (> (- scored number) 20))
5678                   (let ((input
5679                          (read-string
5680                           (format "%s %s (%d scored, %d total): "
5681                                   "How many articles from"
5682                                   (gnus-group-decoded-name group)
5683                                   scored number))))
5684                     (if (string-match "^[ \t]*$" input)
5685                         number input)))
5686                  (t number))
5687               (quit
5688                (message "Quit getting the articles to read")
5689                nil))))))
5690     (setq select (if (stringp select) (string-to-number select) select))
5691     (if (or (null select) (zerop select))
5692         select
5693       (if (and (not (zerop scored)) (<= (abs select) scored))
5694           (progn
5695             (setq articles (sort scored-list '<))
5696             (setq number (length articles)))
5697         (setq articles (copy-sequence articles)))
5698
5699       (when (< (abs select) number)
5700         (if (< select 0)
5701             ;; Select the N oldest articles.
5702             (setcdr (nthcdr (1- (abs select)) articles) nil)
5703           ;; Select the N most recent articles.
5704           (setq articles (nthcdr (- number select) articles))))
5705       (setq gnus-newsgroup-unselected
5706             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5707       (when gnus-alter-articles-to-read-function
5708         (setq articles
5709               (sort
5710                (funcall gnus-alter-articles-to-read-function
5711                         gnus-newsgroup-name articles)
5712                '<)))
5713       articles)))
5714
5715 (defun gnus-killed-articles (killed articles)
5716   (let (out)
5717     (while articles
5718       (when (inline (gnus-member-of-range (car articles) killed))
5719         (push (car articles) out))
5720       (setq articles (cdr articles)))
5721     out))
5722
5723 (defun gnus-uncompress-marks (marks)
5724   "Uncompress the mark ranges in MARKS."
5725   (let ((uncompressed '(score bookmark))
5726         out)
5727     (while marks
5728       (if (memq (caar marks) uncompressed)
5729           (push (car marks) out)
5730         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5731       (setq marks (cdr marks)))
5732     out))
5733
5734 (defun gnus-article-mark-to-type (mark)
5735   "Return the type of MARK."
5736   (or (cadr (assq mark gnus-article-special-mark-lists))
5737       'list))
5738
5739 (defun gnus-article-unpropagatable-p (mark)
5740   "Return whether MARK should be propagated to back end."
5741   (memq mark gnus-article-unpropagated-mark-lists))
5742
5743 (defun gnus-adjust-marked-articles (info)
5744   "Set all article lists and remove all marks that are no longer valid."
5745   (let* ((marked-lists (gnus-info-marks info))
5746          (active (gnus-active (gnus-info-group info)))
5747          (min (car active))
5748          (max (cdr active))
5749          (types gnus-article-mark-lists)
5750          marks var articles article mark mark-type
5751          bgn end)
5752
5753     (dolist (marks marked-lists)
5754       (setq mark (car marks)
5755             mark-type (gnus-article-mark-to-type mark)
5756             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5757
5758       ;; We set the variable according to the type of the marks list,
5759       ;; and then adjust the marks to a subset of the active articles.
5760       (cond
5761        ;; Adjust "simple" lists - compressed yet unsorted
5762        ((eq mark-type 'list)
5763         ;; Simultaneously uncompress and clip to active range
5764         ;; See gnus-uncompress-range for a description of possible marks
5765         (let (l lh)
5766           (if (not (cadr marks))
5767               (set var nil)
5768             (setq articles (if (numberp (cddr marks))
5769                                (list (cdr marks))
5770                              (cdr marks))
5771                   lh (cons nil nil)
5772                   l lh)
5773
5774             (while (setq article (pop articles))
5775               (cond ((consp article)
5776                      (setq bgn (max (car article) min)
5777                            end (min (cdr article) max))
5778                      (while (<= bgn end)
5779                        (setq l (setcdr l (cons bgn nil))
5780                              bgn (1+ bgn))))
5781                     ((and (<= min article)
5782                           (>= max article))
5783                      (setq l (setcdr l (cons article nil))))))
5784             (set var (cdr lh)))))
5785        ;; Adjust assocs.
5786        ((eq mark-type 'tuple)
5787         (set var (setq articles (cdr marks)))
5788         (when (not (listp (cdr (symbol-value var))))
5789           (set var (list (symbol-value var))))
5790         (when (not (listp (cdr articles)))
5791           (setq articles (list articles)))
5792         (while articles
5793           (when (or (not (consp (setq article (pop articles))))
5794                     (< (car article) min)
5795                     (> (car article) max))
5796             (set var (delq article (symbol-value var))))))
5797        ;; Adjust ranges (sloppily).
5798        ((eq mark-type 'range)
5799         (cond
5800          ((eq mark 'seen)
5801           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5802           ;; It should be (seen (NUM1 . NUM2)).
5803           (when (numberp (cddr marks))
5804             (setcdr marks (list (cdr marks))))
5805           (setq articles (cdr marks))
5806           (while (and articles
5807                       (or (and (consp (car articles))
5808                                (> min (cdar articles)))
5809                           (and (numberp (car articles))
5810                                (> min (car articles)))))
5811             (pop articles))
5812           (set var articles))))))))
5813
5814 (defun gnus-update-missing-marks (missing)
5815   "Go through the list of MISSING articles and remove them from the mark lists."
5816   (when missing
5817     (let (var m)
5818       ;; Go through all types.
5819       (dolist (elem gnus-article-mark-lists)
5820         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5821           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5822           (when (symbol-value var)
5823             ;; This list has articles.  So we delete all missing
5824             ;; articles from it.
5825             (setq m missing)
5826             (while m
5827               (set var (delq (pop m) (symbol-value var))))))))))
5828
5829 (defun gnus-update-marks ()
5830   "Enter the various lists of marked articles into the newsgroup info list."
5831   (let ((types gnus-article-mark-lists)
5832         (info (gnus-get-info gnus-newsgroup-name))
5833         type list newmarked symbol delta-marks)
5834     (when info
5835       ;; Add all marks lists to the list of marks lists.
5836       (while (setq type (pop types))
5837         (setq list (symbol-value
5838                     (setq symbol
5839                           (intern (format "gnus-newsgroup-%s" (car type))))))
5840
5841         (when list
5842           ;; Get rid of the entries of the articles that have the
5843           ;; default score.
5844           (when (and (eq (cdr type) 'score)
5845                      gnus-save-score
5846                      list)
5847             (let* ((arts list)
5848                    (prev (cons nil list))
5849                    (all prev))
5850               (while arts
5851                 (if (or (not (consp (car arts)))
5852                         (= (cdar arts) gnus-summary-default-score))
5853                     (setcdr prev (cdr arts))
5854                   (setq prev arts))
5855                 (setq arts (cdr arts)))
5856               (setq list (cdr all)))))
5857
5858         (when (eq (cdr type) 'seen)
5859           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5860
5861         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5862           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5863
5864         (when (and (gnus-check-backend-function
5865                     'request-set-mark gnus-newsgroup-name)
5866                    (not (gnus-article-unpropagatable-p (cdr type))))
5867           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5868                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5869                  (add (gnus-remove-from-range
5870                        (gnus-copy-sequence list) old)))
5871             (when add
5872               (push (list add 'add (list (cdr type))) delta-marks))
5873             (when del
5874               (push (list del 'del (list (cdr type))) delta-marks))))
5875
5876         (when list
5877           (push (cons (cdr type) list) newmarked)))
5878
5879       (when delta-marks
5880         (unless (gnus-check-group gnus-newsgroup-name)
5881           (error "Can't open server for %s" gnus-newsgroup-name))
5882         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5883
5884       ;; Enter these new marks into the info of the group.
5885       (if (nthcdr 3 info)
5886           (setcar (nthcdr 3 info) newmarked)
5887         ;; Add the marks lists to the end of the info.
5888         (when newmarked
5889           (setcdr (nthcdr 2 info) (list newmarked))))
5890
5891       ;; Cut off the end of the info if there's nothing else there.
5892       (let ((i 5))
5893         (while (and (> i 2)
5894                     (not (nth i info)))
5895           (when (nthcdr (decf i) info)
5896             (setcdr (nthcdr i info) nil)))))))
5897
5898 (defun gnus-set-mode-line (where)
5899   "Set the mode line of the article or summary buffers.
5900 If WHERE is `summary', the summary mode line format will be used."
5901   ;; Is this mode line one we keep updated?
5902   (when (and (memq where gnus-updated-mode-lines)
5903              (symbol-value
5904               (intern (format "gnus-%s-mode-line-format-spec" where))))
5905     (let (mode-string)
5906       (save-excursion
5907         ;; We evaluate this in the summary buffer since these
5908         ;; variables are buffer-local to that buffer.
5909         (set-buffer gnus-summary-buffer)
5910        ;; We bind all these variables that are used in the `eval' form
5911         ;; below.
5912         (let* ((mformat (symbol-value
5913                          (intern
5914                           (format "gnus-%s-mode-line-format-spec" where))))
5915                (gnus-tmp-group-name (gnus-mode-string-quote
5916                                      (gnus-group-decoded-name
5917                                       gnus-newsgroup-name)))
5918                (gnus-tmp-article-number (or gnus-current-article 0))
5919                (gnus-tmp-unread gnus-newsgroup-unreads)
5920                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5921                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5922                (gnus-tmp-unread-and-unselected
5923                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5924                             (zerop gnus-tmp-unselected))
5925                        "")
5926                       ((zerop gnus-tmp-unselected)
5927                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5928                       (t (format "{%d(+%d) more}"
5929                                  gnus-tmp-unread-and-unticked
5930                                  gnus-tmp-unselected))))
5931                (gnus-tmp-subject
5932                 (if (and gnus-current-headers
5933                          (vectorp gnus-current-headers))
5934                     (gnus-mode-string-quote
5935                      (mail-header-subject gnus-current-headers))
5936                   ""))
5937                bufname-length max-len
5938                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5939           (setq mode-string (eval mformat))
5940           (setq bufname-length (if (string-match "%b" mode-string)
5941                                    (- (length
5942                                        (buffer-name
5943                                         (if (eq where 'summary)
5944                                             nil
5945                                           (get-buffer gnus-article-buffer))))
5946                                       2)
5947                                  0))
5948           (setq max-len (max 4 (if gnus-mode-non-string-length
5949                                    (- (window-width)
5950                                       gnus-mode-non-string-length
5951                                       bufname-length)
5952                                  (length mode-string))))
5953           ;; We might have to chop a bit of the string off...
5954           (when (> (length mode-string) max-len)
5955             (setq mode-string
5956                   (concat (truncate-string-to-width mode-string (- max-len 3))
5957                           "...")))
5958           ;; Pad the mode string a bit.
5959           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5960       ;; Update the mode line.
5961       (setq mode-line-buffer-identification
5962             (gnus-mode-line-buffer-identification (list mode-string)))
5963       (set-buffer-modified-p t))))
5964
5965 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5966   "Go through the HEADERS list and add all Xrefs to a hash table.
5967 The resulting hash table is returned, or nil if no Xrefs were found."
5968   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5969          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5970          (xref-hashtb (gnus-make-hashtable))
5971          start group entry number xrefs header)
5972     (while headers
5973       (setq header (pop headers))
5974       (when (and (setq xrefs (mail-header-xref header))
5975                  (not (memq (setq number (mail-header-number header))
5976                             unreads)))
5977         (setq start 0)
5978         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5979           (setq start (match-end 0))
5980           (setq group (if prefix
5981                           (concat prefix (substring xrefs (match-beginning 1)
5982                                                     (match-end 1)))
5983                         (substring xrefs (match-beginning 1) (match-end 1))))
5984           (setq number
5985                 (string-to-number (substring xrefs (match-beginning 2)
5986                                           (match-end 2))))
5987           (if (setq entry (gnus-gethash group xref-hashtb))
5988               (setcdr entry (cons number (cdr entry)))
5989             (gnus-sethash group (cons number nil) xref-hashtb)))))
5990     (and start xref-hashtb)))
5991
5992 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5993   "Look through all the headers and mark the Xrefs as read."
5994   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5995         name info xref-hashtb idlist method nth4)
5996     (save-excursion
5997       (set-buffer gnus-group-buffer)
5998       (when (setq xref-hashtb
5999                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6000         (mapatoms
6001          (lambda (group)
6002            (unless (string= from-newsgroup (setq name (symbol-name group)))
6003              (setq idlist (symbol-value group))
6004              ;; Dead groups are not updated.
6005              (and (prog1
6006                       (setq info (gnus-get-info name))
6007                     (when (stringp (setq nth4 (gnus-info-method info)))
6008                       (setq nth4 (gnus-server-to-method nth4))))
6009                   ;; Only do the xrefs if the group has the same
6010                   ;; select method as the group we have just read.
6011                   (or (gnus-methods-equal-p
6012                        nth4 (gnus-find-method-for-group from-newsgroup))
6013                       virtual
6014                       (equal nth4 (setq method (gnus-find-method-for-group
6015                                                 from-newsgroup)))
6016                       (and (equal (car nth4) (car method))
6017                            (equal (nth 1 nth4) (nth 1 method))))
6018                   gnus-use-cross-reference
6019                   (or (not (eq gnus-use-cross-reference t))
6020                       virtual
6021                       ;; Only do cross-references on subscribed
6022                       ;; groups, if that is what is wanted.
6023                       (<= (gnus-info-level info) gnus-level-subscribed))
6024                   (gnus-group-make-articles-read name idlist))))
6025          xref-hashtb)))))
6026
6027 (defun gnus-compute-read-articles (group articles)
6028   (let* ((entry (gnus-group-entry group))
6029          (info (nth 2 entry))
6030          (active (gnus-active group))
6031          ninfo)
6032     (when entry
6033       ;; First peel off all invalid article numbers.
6034       (when active
6035         (let ((ids articles)
6036               id first)
6037           (while (setq id (pop ids))
6038             (when (and first (> id (cdr active)))
6039               ;; We'll end up in this situation in one particular
6040               ;; obscure situation.  If you re-scan a group and get
6041               ;; a new article that is cross-posted to a different
6042               ;; group that has not been re-scanned, you might get
6043               ;; crossposted article that has a higher number than
6044               ;; Gnus believes possible.  So we re-activate this
6045               ;; group as well.  This might mean doing the
6046               ;; crossposting thingy will *increase* the number
6047               ;; of articles in some groups.  Tsk, tsk.
6048               (setq active (or (gnus-activate-group group) active)))
6049             (when (or (> id (cdr active))
6050                       (< id (car active)))
6051               (setq articles (delq id articles))))))
6052       ;; If the read list is nil, we init it.
6053       (if (and active
6054                (null (gnus-info-read info))
6055                (> (car active) 1))
6056           (setq ninfo (cons 1 (1- (car active))))
6057         (setq ninfo (gnus-info-read info)))
6058       ;; Then we add the read articles to the range.
6059       (gnus-add-to-range
6060        ninfo (setq articles (sort articles '<))))))
6061
6062 (defun gnus-group-make-articles-read (group articles)
6063   "Update the info of GROUP to say that ARTICLES are read."
6064   (let* ((num 0)
6065          (entry (gnus-group-entry group))
6066          (info (nth 2 entry))
6067          (active (gnus-active group))
6068          range)
6069     (when entry
6070       (setq range (gnus-compute-read-articles group articles))
6071       (with-current-buffer gnus-group-buffer
6072         (gnus-undo-register
6073           `(progn
6074              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6075              (gnus-info-set-read ',info ',(gnus-info-read info))
6076              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6077              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6078              (gnus-group-update-group ,group t))))
6079       ;; Add the read articles to the range.
6080       (gnus-info-set-read info range)
6081       (gnus-request-set-mark group (list (list range 'add '(read))))
6082       ;; Then we have to re-compute how many unread
6083       ;; articles there are in this group.
6084       (when active
6085         (cond
6086          ((not range)
6087           (setq num (- (1+ (cdr active)) (car active))))
6088          ((not (listp (cdr range)))
6089           (setq num (- (cdr active) (- (1+ (cdr range))
6090                                        (car range)))))
6091          (t
6092           (while range
6093             (if (numberp (car range))
6094                 (setq num (1+ num))
6095               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6096             (setq range (cdr range)))
6097           (setq num (- (cdr active) num))))
6098         ;; Update the number of unread articles.
6099         (setcar entry num)
6100         ;; Update the group buffer.
6101         (unless (gnus-ephemeral-group-p group)
6102           (gnus-group-update-group group t))))))
6103
6104 (defvar gnus-newsgroup-none-id 0)
6105
6106 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6107   (let ((cur nntp-server-buffer)
6108         (dependencies
6109          (or dependencies
6110              (with-current-buffer gnus-summary-buffer
6111                gnus-newsgroup-dependencies)))
6112         headers id end ref number
6113         (mail-parse-charset gnus-newsgroup-charset)
6114         (mail-parse-ignored-charsets
6115          (save-excursion (condition-case nil
6116                              (set-buffer gnus-summary-buffer)
6117                            (error))
6118                          gnus-newsgroup-ignored-charsets)))
6119     (save-excursion
6120       (set-buffer nntp-server-buffer)
6121       ;; Translate all TAB characters into SPACE characters.
6122       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6123       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6124       (ietf-drums-unfold-fws)
6125       (gnus-run-hooks 'gnus-parse-headers-hook)
6126       (let ((case-fold-search t)
6127             in-reply-to header p lines chars)
6128         (goto-char (point-min))
6129         ;; Search to the beginning of the next header.  Error messages
6130         ;; do not begin with 2 or 3.
6131         (while (re-search-forward "^[23][0-9]+ " nil t)
6132           (setq id nil
6133                 ref nil)
6134           ;; This implementation of this function, with nine
6135           ;; search-forwards instead of the one re-search-forward and
6136           ;; a case (which basically was the old function) is actually
6137           ;; about twice as fast, even though it looks messier.  You
6138           ;; can't have everything, I guess.  Speed and elegance
6139           ;; doesn't always go hand in hand.
6140           (setq
6141            header
6142            (vector
6143             ;; Number.
6144             (prog1
6145                 (setq number (read cur))
6146               (end-of-line)
6147               (setq p (point))
6148               (narrow-to-region (point)
6149                                 (or (and (search-forward "\n.\n" nil t)
6150                                          (- (point) 2))
6151                                     (point))))
6152             ;; Subject.
6153             (progn
6154               (goto-char p)
6155               (if (search-forward "\nsubject:" nil t)
6156                   (funcall gnus-decode-encoded-word-function
6157                            (nnheader-header-value))
6158                 "(none)"))
6159             ;; From.
6160             (progn
6161               (goto-char p)
6162               (if (search-forward "\nfrom:" nil t)
6163                   (funcall gnus-decode-encoded-address-function
6164                            (nnheader-header-value))
6165                 "(nobody)"))
6166             ;; Date.
6167             (progn
6168               (goto-char p)
6169               (if (search-forward "\ndate:" nil t)
6170                   (nnheader-header-value) ""))
6171             ;; Message-ID.
6172             (progn
6173               (goto-char p)
6174               (setq id (if (re-search-forward
6175                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6176                            ;; We do it this way to make sure the Message-ID
6177                            ;; is (somewhat) syntactically valid.
6178                            (buffer-substring (match-beginning 1)
6179                                              (match-end 1))
6180                          ;; If there was no message-id, we just fake one
6181                          ;; to make subsequent routines simpler.
6182                          (nnheader-generate-fake-message-id number))))
6183             ;; References.
6184             (progn
6185               (goto-char p)
6186               (if (search-forward "\nreferences:" nil t)
6187                   (progn
6188                     (setq end (point))
6189                     (prog1
6190                         (nnheader-header-value)
6191                       (setq ref
6192                             (buffer-substring
6193                              (progn
6194                                (end-of-line)
6195                                (search-backward ">" end t)
6196                                (1+ (point)))
6197                              (progn
6198                                (search-backward "<" end t)
6199                                (point))))))
6200                 ;; Get the references from the in-reply-to header if there
6201                 ;; were no references and the in-reply-to header looks
6202                 ;; promising.
6203                 (if (and (search-forward "\nin-reply-to:" nil t)
6204                          (setq in-reply-to (nnheader-header-value))
6205                          (string-match "<[^>]+>" in-reply-to))
6206                     (let (ref2)
6207                       (setq ref (substring in-reply-to (match-beginning 0)
6208                                            (match-end 0)))
6209                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6210                         (setq ref2 (substring in-reply-to (match-beginning 0)
6211                                               (match-end 0)))
6212                         (when (> (length ref2) (length ref))
6213                           (setq ref ref2)))
6214                       ref)
6215                   (setq ref nil))))
6216             ;; Chars.
6217             (progn
6218               (goto-char p)
6219               (if (search-forward "\nchars: " nil t)
6220                   (if (numberp (setq chars (ignore-errors (read cur))))
6221                       chars -1)
6222                 -1))
6223             ;; Lines.
6224             (progn
6225               (goto-char p)
6226               (if (search-forward "\nlines: " nil t)
6227                   (if (numberp (setq lines (ignore-errors (read cur))))
6228                       lines -1)
6229                 -1))
6230             ;; Xref.
6231             (progn
6232               (goto-char p)
6233               (and (search-forward "\nxref:" nil t)
6234                    (nnheader-header-value)))
6235             ;; Extra.
6236             (when gnus-extra-headers
6237               (let ((extra gnus-extra-headers)
6238                     out)
6239                 (while extra
6240                   (goto-char p)
6241                   (when (search-forward
6242                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6243                     (push (cons (car extra) (nnheader-header-value))
6244                           out))
6245                   (pop extra))
6246                 out))))
6247           (when (equal id ref)
6248             (setq ref nil))
6249
6250           (when gnus-alter-header-function
6251             (funcall gnus-alter-header-function header)
6252             (setq id (mail-header-id header)
6253                   ref (gnus-parent-id (mail-header-references header))))
6254
6255           (when (setq header
6256                       (gnus-dependencies-add-header
6257                        header dependencies force-new))
6258             (push header headers))
6259           (goto-char (point-max))
6260           (widen))
6261         (nreverse headers)))))
6262
6263 ;; Goes through the xover lines and returns a list of vectors
6264 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6265                                                   force-new dependencies
6266                                                   group also-fetch-heads)
6267   "Parse the news overview data in the server buffer.
6268 Return a list of headers that match SEQUENCE (see
6269 `nntp-retrieve-headers')."
6270   ;; Get the Xref when the users reads the articles since most/some
6271   ;; NNTP servers do not include Xrefs when using XOVER.
6272   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6273   (let ((mail-parse-charset gnus-newsgroup-charset)
6274         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6275         (cur nntp-server-buffer)
6276         (dependencies (or dependencies gnus-newsgroup-dependencies))
6277         (allp (cond
6278                ((eq gnus-read-all-available-headers t)
6279                 t)
6280                ((and (stringp gnus-read-all-available-headers)
6281                      group)
6282                 (string-match gnus-read-all-available-headers group))
6283                (t
6284                 nil)))
6285         number headers header)
6286     (save-excursion
6287       (set-buffer nntp-server-buffer)
6288       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6289       ;; Allow the user to mangle the headers before parsing them.
6290       (gnus-run-hooks 'gnus-parse-headers-hook)
6291       (goto-char (point-min))
6292       (gnus-parse-without-error
6293         (while (and (or sequence allp)
6294                     (not (eobp)))
6295           (setq number (read cur))
6296           (when (not allp)
6297             (while (and sequence
6298                         (< (car sequence) number))
6299               (setq sequence (cdr sequence))))
6300           (when (and (or allp
6301                          (and sequence
6302                               (eq number (car sequence))))
6303                      (progn
6304                        (setq sequence (cdr sequence))
6305                        (setq header (inline
6306                                       (gnus-nov-parse-line
6307                                        number dependencies force-new)))))
6308             (push header headers))
6309           (forward-line 1)))
6310       ;; A common bug in inn is that if you have posted an article and
6311       ;; then retrieves the active file, it will answer correctly --
6312       ;; the new article is included.  However, a NOV entry for the
6313       ;; article may not have been generated yet, so this may fail.
6314       ;; We work around this problem by retrieving the last few
6315       ;; headers using HEAD.
6316       (if (or (not also-fetch-heads)
6317               (not sequence))
6318           ;; We (probably) got all the headers.
6319           (nreverse headers)
6320         (let ((gnus-nov-is-evil t))
6321           (nconc
6322            (nreverse headers)
6323            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6324              (gnus-get-newsgroup-headers))))))))
6325
6326 (defun gnus-article-get-xrefs ()
6327   "Fill in the Xref value in `gnus-current-headers', if necessary.
6328 This is meant to be called in `gnus-article-internal-prepare-hook'."
6329   (let ((headers (with-current-buffer gnus-summary-buffer
6330                    gnus-current-headers)))
6331     (or (not gnus-use-cross-reference)
6332         (not headers)
6333         (and (mail-header-xref headers)
6334              (not (string= (mail-header-xref headers) "")))
6335         (let ((case-fold-search t)
6336               xref)
6337           (save-restriction
6338             (nnheader-narrow-to-headers)
6339             (goto-char (point-min))
6340             (when (or (and (not (eobp))
6341                            (eq (downcase (char-after)) ?x)
6342                            (looking-at "Xref:"))
6343                       (search-forward "\nXref:" nil t))
6344               (goto-char (1+ (match-end 0)))
6345               (setq xref (buffer-substring (point) (point-at-eol)))
6346               (mail-header-set-xref headers xref)))))))
6347
6348 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6349   "Find article ID and insert the summary line for that article.
6350 OLD-HEADER can either be a header or a line number to insert
6351 the subject line on."
6352   (let* ((line (and (numberp old-header) old-header))
6353          (old-header (and (vectorp old-header) old-header))
6354          (header (cond ((and old-header use-old-header)
6355                         old-header)
6356                        ((and (numberp id)
6357                              (gnus-number-to-header id))
6358                         (gnus-number-to-header id))
6359                        (t
6360                         (gnus-read-header id))))
6361          (number (and (numberp id) id))
6362          d)
6363     (when header
6364       ;; Rebuild the thread that this article is part of and go to the
6365       ;; article we have fetched.
6366       (when (and (not gnus-show-threads)
6367                  old-header)
6368         (when (and number
6369                    (setq d (gnus-data-find (mail-header-number old-header))))
6370           (goto-char (gnus-data-pos d))
6371           (gnus-data-remove
6372            number
6373            (- (point-at-bol)
6374               (prog1
6375                   (1+ (point-at-eol))
6376                 (gnus-delete-line))))))
6377       ;; Remove list identifiers from subject.
6378       (when gnus-list-identifiers
6379         (let ((gnus-newsgroup-headers (list header)))
6380           (gnus-summary-remove-list-identifiers)))
6381       (when old-header
6382         (mail-header-set-number header (mail-header-number old-header)))
6383       (setq gnus-newsgroup-sparse
6384             (delq (setq number (mail-header-number header))
6385                   gnus-newsgroup-sparse))
6386       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6387       (push number gnus-newsgroup-limit)
6388       (gnus-rebuild-thread (mail-header-id header) line)
6389       (gnus-summary-goto-subject number nil t))
6390     (when (and (numberp number)
6391                (> number 0))
6392       ;; We have to update the boundaries even if we can't fetch the
6393       ;; article if ID is a number -- so that the next `P' or `N'
6394       ;; command will fetch the previous (or next) article even
6395       ;; if the one we tried to fetch this time has been canceled.
6396       (when (> number gnus-newsgroup-end)
6397         (setq gnus-newsgroup-end number))
6398       (when (< number gnus-newsgroup-begin)
6399         (setq gnus-newsgroup-begin number))
6400       (setq gnus-newsgroup-unselected
6401             (delq number gnus-newsgroup-unselected)))
6402     ;; Report back a success?
6403     (and header (mail-header-number header))))
6404
6405 ;;; Process/prefix in the summary buffer
6406
6407 (defun gnus-summary-work-articles (n)
6408   "Return a list of articles to be worked upon.
6409 The prefix argument, the list of process marked articles, and the
6410 current article will be taken into consideration."
6411   (save-excursion
6412     (set-buffer gnus-summary-buffer)
6413     (cond
6414      (n
6415       ;; A numerical prefix has been given.
6416       (setq n (prefix-numeric-value n))
6417       (let ((backward (< n 0))
6418             (n (abs (prefix-numeric-value n)))
6419             articles article)
6420         (save-excursion
6421           (while
6422               (and (> n 0)
6423                    (push (setq article (gnus-summary-article-number))
6424                          articles)
6425                    (if backward
6426                        (gnus-summary-find-prev nil article)
6427                      (gnus-summary-find-next nil article)))
6428             (decf n)))
6429         (nreverse articles)))
6430      ((and (gnus-region-active-p) (mark))
6431       (message "region active")
6432       ;; Work on the region between point and mark.
6433       (let ((max (max (point) (mark)))
6434             articles article)
6435         (save-excursion
6436           (goto-char (min (point) (mark)))
6437           (while
6438               (and
6439                (push (setq article (gnus-summary-article-number)) articles)
6440                (gnus-summary-find-next nil article)
6441                (< (point) max)))
6442           (nreverse articles))))
6443      (gnus-newsgroup-processable
6444       ;; There are process-marked articles present.
6445       ;; Save current state.
6446       (gnus-summary-save-process-mark)
6447       ;; Return the list.
6448       (reverse gnus-newsgroup-processable))
6449      (t
6450       ;; Just return the current article.
6451       (list (gnus-summary-article-number))))))
6452
6453 (defmacro gnus-summary-iterate (arg &rest forms)
6454   "Iterate over the process/prefixed articles and do FORMS.
6455 ARG is the interactive prefix given to the command.  FORMS will be
6456 executed with point over the summary line of the articles."
6457   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6458     `(let ((,articles (gnus-summary-work-articles ,arg)))
6459        (while ,articles
6460          (gnus-summary-goto-subject (car ,articles))
6461          ,@forms
6462          (pop ,articles)))))
6463
6464 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6465 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6466
6467 (defun gnus-summary-save-process-mark ()
6468   "Push the current set of process marked articles on the stack."
6469   (interactive)
6470   (push (copy-sequence gnus-newsgroup-processable)
6471         gnus-newsgroup-process-stack))
6472
6473 (defun gnus-summary-kill-process-mark ()
6474   "Push the current set of process marked articles on the stack and unmark."
6475   (interactive)
6476   (gnus-summary-save-process-mark)
6477   (gnus-summary-unmark-all-processable))
6478
6479 (defun gnus-summary-yank-process-mark ()
6480   "Pop the last process mark state off the stack and restore it."
6481   (interactive)
6482   (unless gnus-newsgroup-process-stack
6483     (error "Empty mark stack"))
6484   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6485
6486 (defun gnus-summary-process-mark-set (set)
6487   "Make SET into the current process marked articles."
6488   (gnus-summary-unmark-all-processable)
6489   (mapc 'gnus-summary-set-process-mark set))
6490
6491 ;;; Searching and stuff
6492
6493 (defun gnus-summary-search-group (&optional backward use-level)
6494   "Search for next unread newsgroup.
6495 If optional argument BACKWARD is non-nil, search backward instead."
6496   (save-excursion
6497     (set-buffer gnus-group-buffer)
6498     (when (gnus-group-search-forward
6499            backward nil (if use-level (gnus-group-group-level) nil))
6500       (gnus-group-group-name))))
6501
6502 (defun gnus-summary-best-group (&optional exclude-group)
6503   "Find the name of the best unread group.
6504 If EXCLUDE-GROUP, do not go to this group."
6505   (with-current-buffer gnus-group-buffer
6506     (save-excursion
6507       (gnus-group-best-unread-group exclude-group))))
6508
6509 (defun gnus-summary-find-next (&optional unread article backward)
6510   (if backward
6511       (gnus-summary-find-prev unread article)
6512     (let* ((dummy (gnus-summary-article-intangible-p))
6513            (article (or article (gnus-summary-article-number)))
6514            (data (gnus-data-find-list article))
6515            result)
6516       (when (and (not dummy)
6517                  (or (not gnus-summary-check-current)
6518                      (not unread)
6519                      (not (gnus-data-unread-p (car data)))))
6520         (setq data (cdr data)))
6521       (when (setq result
6522                   (if unread
6523                       (progn
6524                         (while data
6525                           (unless (memq (gnus-data-number (car data))
6526                                         (cond
6527                                          ((eq gnus-auto-goto-ignores
6528                                               'always-undownloaded)
6529                                           gnus-newsgroup-undownloaded)
6530                                          (gnus-plugged
6531                                           nil)
6532                                          ((eq gnus-auto-goto-ignores
6533                                               'unfetched)
6534                                           gnus-newsgroup-unfetched)
6535                                          ((eq gnus-auto-goto-ignores
6536                                               'undownloaded)
6537                                           gnus-newsgroup-undownloaded)))
6538                             (when (gnus-data-unread-p (car data))
6539                               (setq result (car data)
6540                                     data nil)))
6541                           (setq data (cdr data)))
6542                         result)
6543                     (car data)))
6544         (goto-char (gnus-data-pos result))
6545         (gnus-data-number result)))))
6546
6547 (defun gnus-summary-find-prev (&optional unread article)
6548   (let* ((eobp (eobp))
6549          (article (or article (gnus-summary-article-number)))
6550          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6551          result)
6552     (when (and (not eobp)
6553                (or (not gnus-summary-check-current)
6554                    (not unread)
6555                    (not (gnus-data-unread-p (car data)))))
6556       (setq data (cdr data)))
6557     (when (setq result
6558                 (if unread
6559                     (progn
6560                       (while data
6561                         (unless (memq (gnus-data-number (car data))
6562                                       (cond
6563                                        ((eq gnus-auto-goto-ignores
6564                                             'always-undownloaded)
6565                                         gnus-newsgroup-undownloaded)
6566                                        (gnus-plugged
6567                                         nil)
6568                                        ((eq gnus-auto-goto-ignores
6569                                             'unfetched)
6570                                         gnus-newsgroup-unfetched)
6571                                        ((eq gnus-auto-goto-ignores
6572                                             'undownloaded)
6573                                         gnus-newsgroup-undownloaded)))
6574                           (when (gnus-data-unread-p (car data))
6575                             (setq result (car data)
6576                                   data nil)))
6577                         (setq data (cdr data)))
6578                       result)
6579                   (car data)))
6580       (goto-char (gnus-data-pos result))
6581       (gnus-data-number result))))
6582
6583 (defun gnus-summary-find-subject (subject &optional unread backward article)
6584   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6585          (article (or article (gnus-summary-article-number)))
6586          (articles (gnus-data-list backward))
6587          (arts (gnus-data-find-list article articles))
6588          result)
6589     (when (or (not gnus-summary-check-current)
6590               (not unread)
6591               (not (gnus-data-unread-p (car arts))))
6592       (setq arts (cdr arts)))
6593     (while arts
6594       (and (or (not unread)
6595                (gnus-data-unread-p (car arts)))
6596            (vectorp (gnus-data-header (car arts)))
6597            (gnus-subject-equal
6598             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6599            (setq result (car arts)
6600                  arts nil))
6601       (setq arts (cdr arts)))
6602     (and result
6603          (goto-char (gnus-data-pos result))
6604          (gnus-data-number result))))
6605
6606 (defun gnus-summary-search-forward (&optional unread subject backward)
6607   "Search forward for an article.
6608 If UNREAD, look for unread articles.  If SUBJECT, look for
6609 articles with that subject.  If BACKWARD, search backward instead."
6610   (cond (subject (gnus-summary-find-subject subject unread backward))
6611         (backward (gnus-summary-find-prev unread))
6612         (t (gnus-summary-find-next unread))))
6613
6614 (defun gnus-recenter (&optional n)
6615   "Center point in window and redisplay frame.
6616 Also do horizontal recentering."
6617   (interactive "P")
6618   (when (and gnus-auto-center-summary
6619              (not (eq gnus-auto-center-summary 'vertical)))
6620     (gnus-horizontal-recenter))
6621   (recenter n))
6622
6623 (defun gnus-summary-recenter ()
6624   "Center point in the summary window.
6625 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6626 displayed, no centering will be performed."
6627   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6628   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6629   (interactive)
6630   ;; The user has to want it.
6631   (when gnus-auto-center-summary
6632     (let* ((top (cond ((< (window-height) 4) 0)
6633                       ((< (window-height) 7) 1)
6634                       (t (if (numberp gnus-auto-center-summary)
6635                              gnus-auto-center-summary
6636                            (/ (1- (window-height)) 2)))))
6637            (height (1- (window-height)))
6638            (bottom (save-excursion (goto-char (point-max))
6639                                    (forward-line (- height))
6640                                    (point)))
6641            (window (get-buffer-window (current-buffer))))
6642       (when (get-buffer-window gnus-article-buffer)
6643         ;; Only do recentering when the article buffer is displayed,
6644         ;; Set the window start to either `bottom', which is the biggest
6645         ;; possible valid number, or the second line from the top,
6646         ;; whichever is the least.
6647         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6648           (if (> bottom top-pos)
6649               ;; Keep the second line from the top visible
6650               (set-window-start window top-pos)
6651             ;; Try to keep the bottom line visible; if it's partially
6652             ;; obscured, either scroll one more line to make it fully
6653             ;; visible, or revert to using TOP-POS.
6654             (save-excursion
6655               (goto-char (point-max))
6656               (forward-line -1)
6657               (let ((last-line-start (point)))
6658                 (goto-char bottom)
6659                 (set-window-start window (point) t)
6660                 (when (not (pos-visible-in-window-p last-line-start window))
6661                   (forward-line 1)
6662                   (set-window-start window (min (point) top-pos) t)))))))
6663       ;; Do horizontal recentering while we're at it.
6664       (when (and (get-buffer-window (current-buffer) t)
6665                  (not (eq gnus-auto-center-summary 'vertical)))
6666         (let ((selected (selected-window)))
6667           (select-window (get-buffer-window (current-buffer) t))
6668           (gnus-summary-position-point)
6669           (gnus-horizontal-recenter)
6670           (select-window selected))))))
6671
6672 (defun gnus-summary-jump-to-group (newsgroup)
6673   "Move point to NEWSGROUP in group mode buffer."
6674   ;; Keep update point of group mode buffer if visible.
6675   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6676       (save-window-excursion
6677         ;; Take care of tree window mode.
6678         (when (get-buffer-window gnus-group-buffer)
6679           (pop-to-buffer gnus-group-buffer))
6680         (gnus-group-jump-to-group newsgroup))
6681     (save-excursion
6682       ;; Take care of tree window mode.
6683       (if (get-buffer-window gnus-group-buffer)
6684           (pop-to-buffer gnus-group-buffer)
6685         (set-buffer gnus-group-buffer))
6686       (gnus-group-jump-to-group newsgroup))))
6687
6688 ;; This function returns a list of article numbers based on the
6689 ;; difference between the ranges of read articles in this group and
6690 ;; the range of active articles.
6691 (defun gnus-list-of-unread-articles (group)
6692   (let* ((read (gnus-info-read (gnus-get-info group)))
6693          (active (or (gnus-active group) (gnus-activate-group group)))
6694          (last (or (cdr active)
6695                    (error "Group %s couldn't be activated " group)))
6696          first nlast unread)
6697     ;; If none are read, then all are unread.
6698     (if (not read)
6699         (setq first (car active))
6700       ;; If the range of read articles is a single range, then the
6701       ;; first unread article is the article after the last read
6702       ;; article.  Sounds logical, doesn't it?
6703       (if (and (not (listp (cdr read)))
6704                (or (< (car read) (car active))
6705                    (progn (setq read (list read))
6706                           nil)))
6707           (setq first (max (car active) (1+ (cdr read))))
6708         ;; `read' is a list of ranges.
6709         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6710                                   (caar read)))
6711                   1)
6712           (setq first (car active)))
6713         (while read
6714           (when first
6715             (while (< first nlast)
6716               (setq unread (cons first unread)
6717                     first (1+ first))))
6718           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6719           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6720           (setq read (cdr read)))))
6721     ;; And add the last unread articles.
6722     (while (<= first last)
6723       (setq unread (cons first unread)
6724             first (1+ first)))
6725     ;; Return the list of unread articles.
6726     (delq 0 (nreverse unread))))
6727
6728 (defun gnus-list-of-read-articles (group)
6729   "Return a list of unread, unticked and non-dormant articles."
6730   (let* ((info (gnus-get-info group))
6731          (marked (gnus-info-marks info))
6732          (active (gnus-active group)))
6733     (and info active
6734          (gnus-list-range-difference
6735           (gnus-list-range-difference
6736            (gnus-sorted-complement
6737             (gnus-uncompress-range active)
6738             (gnus-list-of-unread-articles group))
6739            (cdr (assq 'dormant marked)))
6740           (cdr (assq 'tick marked))))))
6741
6742 ;; This function returns a sequence of article numbers based on the
6743 ;; difference between the ranges of read articles in this group and
6744 ;; the range of active articles.
6745 (defun gnus-sequence-of-unread-articles (group)
6746   (let* ((read (gnus-info-read (gnus-get-info group)))
6747          (active (or (gnus-active group) (gnus-activate-group group)))
6748          (last (cdr active))
6749          first nlast unread)
6750     ;; If none are read, then all are unread.
6751     (if (not read)
6752         (setq first (car active))
6753       ;; If the range of read articles is a single range, then the
6754       ;; first unread article is the article after the last read
6755       ;; article.  Sounds logical, doesn't it?
6756       (if (and (not (listp (cdr read)))
6757                (or (< (car read) (car active))
6758                    (progn (setq read (list read))
6759                           nil)))
6760           (setq first (max (car active) (1+ (cdr read))))
6761         ;; `read' is a list of ranges.
6762         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6763                                   (caar read)))
6764                   1)
6765           (setq first (car active)))
6766         (while read
6767           (when first
6768             (push (cons first nlast) unread))
6769           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6770           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6771           (setq read (cdr read)))))
6772     ;; And add the last unread articles.
6773     (cond ((not (and first last))
6774            nil)
6775           ((< first last)
6776            (push (cons first last) unread))
6777           ((= first last)
6778            (push first unread)))
6779     ;; Return the sequence of unread articles.
6780     (delq 0 (nreverse unread))))
6781
6782 ;; Various summary commands
6783
6784 (defun gnus-summary-select-article-buffer ()
6785   "Reconfigure windows to show article buffer."
6786   (interactive)
6787   (if (not (gnus-buffer-live-p gnus-article-buffer))
6788       (error "There is no article buffer for this summary buffer")
6789     (gnus-configure-windows 'article)
6790     (select-window (get-buffer-window gnus-article-buffer))))
6791
6792 (defun gnus-summary-universal-argument (arg)
6793   "Perform any operation on all articles that are process/prefixed."
6794   (interactive "P")
6795   (let ((articles (gnus-summary-work-articles arg))
6796         func article)
6797     (if (eq
6798          (setq
6799           func
6800           (key-binding
6801            (read-key-sequence
6802             (substitute-command-keys
6803              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6804          'undefined)
6805         (gnus-error 1 "Undefined key")
6806       (save-excursion
6807         (while articles
6808           (gnus-summary-goto-subject (setq article (pop articles)))
6809           (let (gnus-newsgroup-processable)
6810             (command-execute func))
6811           (gnus-summary-remove-process-mark article)))))
6812   (gnus-summary-position-point))
6813
6814 (defun gnus-summary-toggle-truncation (&optional arg)
6815   "Toggle truncation of summary lines.
6816 With ARG, turn line truncation on if ARG is positive."
6817   (interactive "P")
6818   (setq truncate-lines
6819         (if (null arg) (not truncate-lines)
6820           (> (prefix-numeric-value arg) 0)))
6821   (redraw-display))
6822
6823 (defun gnus-summary-find-for-reselect ()
6824   "Return the number of an article to stay on across a reselect.
6825 The current article is considered, then following articles, then previous
6826 articles.  An article is sought which is not cancelled and isn't a temporary
6827 insertion from another group.  If there's no such then return a dummy 0."
6828   (let (found)
6829     (dolist (rev '(nil t))
6830       (unless found      ; don't demand the reverse list if we don't need it
6831         (let ((data (gnus-data-find-list
6832                      (gnus-summary-article-number) (gnus-data-list rev))))
6833           (while (and data (not found))
6834             (if (and (< 0 (gnus-data-number (car data)))
6835                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6836                 (setq found (gnus-data-number (car data))))
6837             (setq data (cdr data))))))
6838     (or found 0)))
6839
6840 (defun gnus-summary-reselect-current-group (&optional all rescan)
6841   "Exit and then reselect the current newsgroup.
6842 The prefix argument ALL means to select all articles."
6843   (interactive "P")
6844   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6845     (error "Ephemeral groups can't be reselected"))
6846   (let ((current-subject (gnus-summary-find-for-reselect))
6847         (group gnus-newsgroup-name))
6848     (setq gnus-newsgroup-begin nil)
6849     (gnus-summary-exit nil 'leave-hidden)
6850     ;; We have to adjust the point of group mode buffer because
6851     ;; point was moved to the next unread newsgroup by exiting.
6852     (gnus-summary-jump-to-group group)
6853     (when rescan
6854       (save-excursion
6855         (gnus-group-get-new-news-this-group 1)))
6856     (gnus-group-read-group all t)
6857     (gnus-summary-goto-subject current-subject nil t)))
6858
6859 (defun gnus-summary-rescan-group (&optional all)
6860   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6861   (interactive "P")
6862   (gnus-summary-reselect-current-group all t))
6863
6864 (defun gnus-summary-update-info (&optional non-destructive)
6865   (save-excursion
6866     (let ((group gnus-newsgroup-name))
6867       (when group
6868         (when gnus-newsgroup-kill-headers
6869           (setq gnus-newsgroup-killed
6870                 (gnus-compress-sequence
6871                  (gnus-sorted-union
6872                   (gnus-list-range-intersection
6873                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6874                   gnus-newsgroup-unreads)
6875                  t)))
6876         (unless (listp (cdr gnus-newsgroup-killed))
6877           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6878         (let ((headers gnus-newsgroup-headers))
6879           ;; Set the new ranges of read articles.
6880           (with-current-buffer gnus-group-buffer
6881             (gnus-undo-force-boundary))
6882           (gnus-update-read-articles
6883            group (gnus-sorted-union
6884                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6885           ;; Set the current article marks.
6886           (let ((gnus-newsgroup-scored
6887                  (if (and (not gnus-save-score)
6888                           (not non-destructive))
6889                      nil
6890                    gnus-newsgroup-scored)))
6891             (save-excursion
6892               (gnus-update-marks)))
6893           ;; Do the cross-ref thing.
6894           (when gnus-use-cross-reference
6895             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6896           ;; Do not switch windows but change the buffer to work.
6897           (set-buffer gnus-group-buffer)
6898           (unless (gnus-ephemeral-group-p group)
6899             (gnus-group-update-group group)))))))
6900
6901 (defun gnus-summary-save-newsrc (&optional force)
6902   "Save the current number of read/marked articles in the dribble buffer.
6903 The dribble buffer will then be saved.
6904 If FORCE (the prefix), also save the .newsrc file(s)."
6905   (interactive "P")
6906   (gnus-summary-update-info t)
6907   (if force
6908       (gnus-save-newsrc-file)
6909     (gnus-dribble-save)))
6910
6911 (defun gnus-summary-exit (&optional temporary leave-hidden)
6912   "Exit reading current newsgroup, and then return to group selection mode.
6913 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6914   (interactive)
6915   (gnus-set-global-variables)
6916   (when (gnus-buffer-live-p gnus-article-buffer)
6917     (save-excursion
6918       (set-buffer gnus-article-buffer)
6919       (mm-destroy-parts gnus-article-mime-handles)
6920       ;; Set it to nil for safety reason.
6921       (setq gnus-article-mime-handle-alist nil)
6922       (setq gnus-article-mime-handles nil)))
6923   (gnus-kill-save-kill-buffer)
6924   (gnus-async-halt-prefetch)
6925   (let* ((group gnus-newsgroup-name)
6926          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6927          (gnus-group-is-exiting-p t)
6928          (mode major-mode)
6929          (group-point nil)
6930          (buf (current-buffer)))
6931     (unless quit-config
6932       ;; Do adaptive scoring, and possibly save score files.
6933       (when gnus-newsgroup-adaptive
6934         (gnus-score-adaptive))
6935       (when gnus-use-scoring
6936         (gnus-score-save)))
6937     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6938     ;; If we have several article buffers, we kill them at exit.
6939     (unless gnus-single-article-buffer
6940       (gnus-kill-buffer gnus-article-buffer)
6941       (gnus-kill-buffer gnus-original-article-buffer)
6942       (setq gnus-article-current nil))
6943     (when gnus-use-cache
6944       (gnus-cache-possibly-remove-articles)
6945       (gnus-cache-save-buffers))
6946     (gnus-async-prefetch-remove-group group)
6947     (when gnus-suppress-duplicates
6948       (gnus-dup-enter-articles))
6949     (when gnus-use-trees
6950       (gnus-tree-close group))
6951     (when gnus-use-cache
6952       (gnus-cache-write-active))
6953     ;; Remove entries for this group.
6954     (nnmail-purge-split-history (gnus-group-real-name group))
6955     ;; Make all changes in this group permanent.
6956     (unless quit-config
6957       (gnus-run-hooks 'gnus-exit-group-hook)
6958       (gnus-summary-update-info))
6959     (gnus-close-group group)
6960     ;; Make sure where we were, and go to next newsgroup.
6961     (set-buffer gnus-group-buffer)
6962     (unless quit-config
6963       (gnus-group-jump-to-group group))
6964     (gnus-run-hooks 'gnus-summary-exit-hook)
6965     (unless (or quit-config
6966                 (not gnus-summary-next-group-on-exit)
6967                 ;; If this group has disappeared from the summary
6968                 ;; buffer, don't skip forwards.
6969                 (not (string= group (gnus-group-group-name))))
6970       (gnus-group-next-unread-group 1))
6971     (setq group-point (point))
6972     (if temporary
6973         nil                             ;Nothing to do.
6974       ;; If we have several article buffers, we kill them at exit.
6975       (unless gnus-single-article-buffer
6976         (gnus-kill-buffer gnus-article-buffer)
6977         (gnus-kill-buffer gnus-original-article-buffer)
6978         (setq gnus-article-current nil))
6979       (set-buffer buf)
6980       (if (not gnus-kill-summary-on-exit)
6981           (progn
6982             (gnus-deaden-summary)
6983             (setq mode nil))
6984         ;; We set all buffer-local variables to nil.  It is unclear why
6985         ;; this is needed, but if we don't, buffer-local variables are
6986         ;; not garbage-collected, it seems.  This would the lead to en
6987         ;; ever-growing Emacs.
6988         (gnus-summary-clear-local-variables)
6989         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6990           (gnus-summary-clear-local-variables))
6991         (when (get-buffer gnus-article-buffer)
6992           (bury-buffer gnus-article-buffer))
6993         ;; Return to group mode buffer.
6994         (when (eq mode 'gnus-summary-mode)
6995           (gnus-kill-buffer buf)))
6996       (setq gnus-current-select-method gnus-select-method)
6997       (set-buffer gnus-group-buffer)
6998       (if quit-config
6999           (gnus-handle-ephemeral-exit quit-config)
7000         (goto-char group-point)
7001         ;; If gnus-group-buffer is already displayed, make sure we also move
7002         ;; the cursor in the window that displays it.
7003         (let ((win (get-buffer-window (current-buffer) 0)))
7004           (if win (set-window-point win (point))))
7005         (unless leave-hidden
7006           (gnus-configure-windows 'group 'force)))
7007       ;; Clear the current group name.
7008       (unless quit-config
7009         (setq gnus-newsgroup-name nil)))))
7010
7011 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7012 (defun gnus-summary-exit-no-update (&optional no-questions)
7013   "Quit reading current newsgroup without updating read article info."
7014   (interactive)
7015   (let* ((group gnus-newsgroup-name)
7016          (gnus-group-is-exiting-p t)
7017          (gnus-group-is-exiting-without-update-p t)
7018          (quit-config (gnus-group-quit-config group)))
7019     (when (or no-questions
7020               gnus-expert-user
7021               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7022       (gnus-async-halt-prefetch)
7023       (run-hooks 'gnus-summary-prepare-exit-hook)
7024       (when (gnus-buffer-live-p gnus-article-buffer)
7025         (save-excursion
7026           (set-buffer gnus-article-buffer)
7027           (mm-destroy-parts gnus-article-mime-handles)
7028           ;; Set it to nil for safety reason.
7029           (setq gnus-article-mime-handle-alist nil)
7030           (setq gnus-article-mime-handles nil)))
7031       ;; If we have several article buffers, we kill them at exit.
7032       (unless gnus-single-article-buffer
7033         (gnus-kill-buffer gnus-article-buffer)
7034         (gnus-kill-buffer gnus-original-article-buffer)
7035         (setq gnus-article-current nil))
7036       (if (not gnus-kill-summary-on-exit)
7037           (gnus-deaden-summary)
7038         (gnus-close-group group)
7039         (gnus-summary-clear-local-variables)
7040         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7041           (gnus-summary-clear-local-variables))
7042         (gnus-kill-buffer gnus-summary-buffer))
7043       (unless gnus-single-article-buffer
7044         (setq gnus-article-current nil))
7045       (when gnus-use-trees
7046         (gnus-tree-close group))
7047       (gnus-async-prefetch-remove-group group)
7048       (when (get-buffer gnus-article-buffer)
7049         (bury-buffer gnus-article-buffer))
7050       ;; Return to the group buffer.
7051       (gnus-configure-windows 'group 'force)
7052       ;; Clear the current group name.
7053       (setq gnus-newsgroup-name nil)
7054       (unless (gnus-ephemeral-group-p group)
7055         (gnus-group-update-group group))
7056       (when (equal (gnus-group-group-name) group)
7057         (gnus-group-next-unread-group 1))
7058       (when quit-config
7059         (gnus-handle-ephemeral-exit quit-config)))))
7060
7061 (defun gnus-handle-ephemeral-exit (quit-config)
7062   "Handle movement when leaving an ephemeral group.
7063 The state which existed when entering the ephemeral is reset."
7064   (if (not (buffer-name (car quit-config)))
7065       (gnus-configure-windows 'group 'force)
7066     (set-buffer (car quit-config))
7067     (cond ((eq major-mode 'gnus-summary-mode)
7068            (gnus-set-global-variables))
7069           ((eq major-mode 'gnus-article-mode)
7070            (save-excursion
7071              ;; The `gnus-summary-buffer' variable may point
7072              ;; to the old summary buffer when using a single
7073              ;; article buffer.
7074              (unless (gnus-buffer-live-p gnus-summary-buffer)
7075                (set-buffer gnus-group-buffer))
7076              (set-buffer gnus-summary-buffer)
7077              (gnus-set-global-variables))))
7078     (if (or (eq (cdr quit-config) 'article)
7079             (eq (cdr quit-config) 'pick))
7080         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7081             (gnus-configure-windows 'pick 'force)
7082           (gnus-configure-windows (cdr quit-config) 'force))
7083       (gnus-configure-windows (cdr quit-config) 'force))
7084     (when (eq major-mode 'gnus-summary-mode)
7085       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7086                                                      next-unread-noselect))
7087           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7088                                   'next-noselect)
7089                               (gnus-summary-next-subject 1 nil t))
7090                              ((eq gnus-auto-select-on-ephemeral-exit
7091                                   'next-unread-noselect)
7092                               (gnus-summary-next-subject 1 t t))))
7093             ;; Hide the article buffer which displays the article different
7094             ;; from the one that the cursor points to in the summary buffer.
7095             (gnus-configure-windows 'summary 'force))
7096         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7097                (gnus-summary-next-subject 1))
7098               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7099                (gnus-summary-next-subject 1 t))))
7100       (gnus-summary-recenter)
7101       (gnus-summary-position-point))))
7102
7103 ;;; Dead summaries.
7104
7105 (defvar gnus-dead-summary-mode-map nil)
7106
7107 (unless gnus-dead-summary-mode-map
7108   (setq gnus-dead-summary-mode-map (make-keymap))
7109   (suppress-keymap gnus-dead-summary-mode-map)
7110   (substitute-key-definition
7111    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7112   (dolist (key '("\C-d" "\r" "\177" [delete]))
7113     (define-key gnus-dead-summary-mode-map
7114       key 'gnus-summary-wake-up-the-dead))
7115   (dolist (key '("q" "Q"))
7116     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7117
7118 (defvar gnus-dead-summary-mode nil
7119   "Minor mode for Gnus summary buffers.")
7120
7121 (defun gnus-dead-summary-mode (&optional arg)
7122   "Minor mode for Gnus summary buffers."
7123   (interactive "P")
7124   (when (eq major-mode 'gnus-summary-mode)
7125     (make-local-variable 'gnus-dead-summary-mode)
7126     (setq gnus-dead-summary-mode
7127           (if (null arg) (not gnus-dead-summary-mode)
7128             (> (prefix-numeric-value arg) 0)))
7129     (when gnus-dead-summary-mode
7130       (add-minor-mode
7131        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7132
7133 (defun gnus-deaden-summary ()
7134   "Make the current summary buffer into a dead summary buffer."
7135   ;; Kill any previous dead summary buffer.
7136   (when (and gnus-dead-summary
7137              (buffer-name gnus-dead-summary))
7138     (with-current-buffer gnus-dead-summary
7139       (when gnus-dead-summary-mode
7140         (kill-buffer (current-buffer)))))
7141   ;; Make this the current dead summary.
7142   (setq gnus-dead-summary (current-buffer))
7143   (gnus-dead-summary-mode 1)
7144   (let ((name (buffer-name)))
7145     (when (string-match "Summary" name)
7146       (rename-buffer
7147        (concat (substring name 0 (match-beginning 0)) "Dead "
7148                (substring name (match-beginning 0)))
7149        t)
7150       (bury-buffer))))
7151
7152 (defun gnus-kill-or-deaden-summary (buffer)
7153   "Kill or deaden the summary BUFFER."
7154   (save-excursion
7155     (when (and (buffer-name buffer)
7156                (not gnus-single-article-buffer))
7157       (with-current-buffer buffer
7158         (gnus-kill-buffer gnus-article-buffer)
7159         (gnus-kill-buffer gnus-original-article-buffer)))
7160     (cond
7161      ;; Kill the buffer.
7162      (gnus-kill-summary-on-exit
7163       (when (and gnus-use-trees
7164                  (gnus-buffer-exists-p buffer))
7165         (save-excursion
7166           (set-buffer buffer)
7167           (gnus-tree-close gnus-newsgroup-name)))
7168       (gnus-kill-buffer buffer))
7169      ;; Deaden the buffer.
7170      ((gnus-buffer-exists-p buffer)
7171       (save-excursion
7172         (set-buffer buffer)
7173         (gnus-deaden-summary))))))
7174
7175 (defun gnus-summary-wake-up-the-dead (&rest args)
7176   "Wake up the dead summary buffer."
7177   (interactive)
7178   (gnus-dead-summary-mode -1)
7179   (let ((name (buffer-name)))
7180     (when (string-match "Dead " name)
7181       (rename-buffer
7182        (concat (substring name 0 (match-beginning 0))
7183                (substring name (match-end 0)))
7184        t)))
7185   (gnus-message 3 "This dead summary is now alive again"))
7186
7187 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7188 (defun gnus-summary-fetch-faq (&optional faq-dir)
7189   "Fetch the FAQ for the current group.
7190 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7191 in."
7192   (interactive
7193    (list
7194     (when current-prefix-arg
7195       (completing-read
7196        "FAQ dir: " (and (listp gnus-group-faq-directory)
7197                         (mapcar 'list
7198                                 gnus-group-faq-directory))))))
7199   (let (gnus-faq-buffer)
7200     (when (setq gnus-faq-buffer
7201                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7202       (gnus-configure-windows 'summary-faq))))
7203
7204 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7205 (defun gnus-summary-describe-group (&optional force)
7206   "Describe the current newsgroup."
7207   (interactive "P")
7208   (gnus-group-describe-group force gnus-newsgroup-name))
7209
7210 (defun gnus-summary-describe-briefly ()
7211   "Describe summary mode commands briefly."
7212   (interactive)
7213   (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")))
7214
7215 ;; Walking around group mode buffer from summary mode.
7216
7217 (defun gnus-summary-next-group (&optional no-article target-group backward)
7218   "Exit current newsgroup and then select next unread newsgroup.
7219 If prefix argument NO-ARTICLE is non-nil, no article is selected
7220 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7221 previous group instead."
7222   (interactive "P")
7223   ;; Stop pre-fetching.
7224   (gnus-async-halt-prefetch)
7225   (let ((current-group gnus-newsgroup-name)
7226         (current-buffer (current-buffer))
7227         entered)
7228     ;; First we semi-exit this group to update Xrefs and all variables.
7229     ;; We can't do a real exit, because the window conf must remain
7230     ;; the same in case the user is prompted for info, and we don't
7231     ;; want the window conf to change before that...
7232     (gnus-summary-exit t)
7233     (while (not entered)
7234       ;; Then we find what group we are supposed to enter.
7235       (set-buffer gnus-group-buffer)
7236       (gnus-group-jump-to-group current-group)
7237       (setq target-group
7238             (or target-group
7239                 (if (eq gnus-keep-same-level 'best)
7240                     (gnus-summary-best-group gnus-newsgroup-name)
7241                   (gnus-summary-search-group backward gnus-keep-same-level))))
7242       (if (not target-group)
7243           ;; There are no further groups, so we return to the group
7244           ;; buffer.
7245           (progn
7246             (gnus-message 5 "Returning to the group buffer")
7247             (setq entered t)
7248             (when (gnus-buffer-live-p current-buffer)
7249               (set-buffer current-buffer)
7250               (gnus-summary-exit))
7251             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7252         ;; We try to enter the target group.
7253         (gnus-group-jump-to-group target-group)
7254         (let ((unreads (gnus-group-group-unread)))
7255           (if (and (or (eq t unreads)
7256                        (and unreads (not (zerop unreads))))
7257                    (gnus-summary-read-group
7258                     target-group nil no-article
7259                     (and (buffer-name current-buffer) current-buffer)
7260                     nil backward))
7261               (setq entered t)
7262             (setq current-group target-group
7263                   target-group nil)))))))
7264
7265 (defun gnus-summary-prev-group (&optional no-article)
7266   "Exit current newsgroup and then select previous unread newsgroup.
7267 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7268   (interactive "P")
7269   (gnus-summary-next-group no-article nil t))
7270
7271 ;; Walking around summary lines.
7272
7273 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7274   "Go to the first subject satisfying any non-nil constraint.
7275 If UNREAD is non-nil, the article should be unread.
7276 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7277 If UNSEEN is non-nil, the article should be unseen.
7278 Returns the article selected or nil if there are no matching articles."
7279   (interactive "P")
7280   (cond
7281    ;; Empty summary.
7282    ((null gnus-newsgroup-data)
7283     (gnus-message 3 "No articles in the group")
7284     nil)
7285    ;; Pick the first article.
7286    ((not (or unread undownloaded unseen))
7287     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7288     (gnus-data-number (car gnus-newsgroup-data)))
7289    ;; Find the first unread article.
7290    (t
7291     (let ((data gnus-newsgroup-data))
7292       (while (and data
7293                   (let ((num (gnus-data-number (car data))))
7294                     (or (memq num gnus-newsgroup-unfetched)
7295                         (not (or (and unread
7296                                       (memq num gnus-newsgroup-unreads))
7297                                  (and undownloaded
7298                                       (memq num gnus-newsgroup-undownloaded))
7299                                  (and unseen
7300                                       (memq num gnus-newsgroup-unseen)))))))
7301         (setq data (cdr data)))
7302       (prog1
7303           (if data
7304               (progn
7305                 (goto-char (gnus-data-pos (car data)))
7306                 (gnus-data-number (car data)))
7307             (gnus-message 3 "No more%s articles"
7308                           (let* ((r (when unread " unread"))
7309                                  (d (when undownloaded " undownloaded"))
7310                                  (s (when unseen " unseen"))
7311                                  (l (delq nil (list r d s))))
7312                             (cond ((= 3 (length l))
7313                                    (concat r "," d ", or" s))
7314                                   ((= 2 (length l))
7315                                    (concat (car l) ", or" (cadr l)))
7316                                   ((= 1 (length l))
7317                                    (car l))
7318                                   (t
7319                                    ""))))
7320             nil
7321             )
7322         (gnus-summary-position-point))))))
7323
7324 (defun gnus-summary-next-subject (n &optional unread dont-display)
7325   "Go to next N'th summary line.
7326 If N is negative, go to the previous N'th subject line.
7327 If UNREAD is non-nil, only unread articles are selected.
7328 The difference between N and the actual number of steps taken is
7329 returned."
7330   (interactive "p")
7331   (let ((backward (< n 0))
7332         (n (abs n)))
7333     (while (and (> n 0)
7334                 (if backward
7335                     (gnus-summary-find-prev unread)
7336                   (gnus-summary-find-next unread)))
7337       (unless (zerop (setq n (1- n)))
7338         (gnus-summary-show-thread)))
7339     (when (/= 0 n)
7340       (gnus-message 7 "No more%s articles"
7341                     (if unread " unread" "")))
7342     (unless dont-display
7343       (gnus-summary-recenter)
7344       (gnus-summary-position-point))
7345     n))
7346
7347 (defun gnus-summary-next-unread-subject (n)
7348   "Go to next N'th unread summary line."
7349   (interactive "p")
7350   (gnus-summary-next-subject n t))
7351
7352 (defun gnus-summary-prev-subject (n &optional unread)
7353   "Go to previous N'th summary line.
7354 If optional argument UNREAD is non-nil, only unread article is selected."
7355   (interactive "p")
7356   (gnus-summary-next-subject (- n) unread))
7357
7358 (defun gnus-summary-prev-unread-subject (n)
7359   "Go to previous N'th unread summary line."
7360   (interactive "p")
7361   (gnus-summary-next-subject (- n) t))
7362
7363 (defun gnus-summary-goto-subjects (articles)
7364   "Insert the subject header for ARTICLES in the current buffer."
7365   (save-excursion
7366     (dolist (article articles)
7367       (gnus-summary-goto-subject article t)))
7368   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7369   (gnus-summary-position-point))
7370
7371 (defun gnus-summary-goto-subject (article &optional force silent)
7372   "Go the subject line of ARTICLE.
7373 If FORCE, also allow jumping to articles not currently shown."
7374   (interactive "nArticle number: ")
7375   (unless (numberp article)
7376     (error "Article %s is not a number" article))
7377   (let ((b (point))
7378         (data (gnus-data-find article)))
7379     ;; We read in the article if we have to.
7380     (and (not data)
7381          force
7382          (gnus-summary-insert-subject
7383           article
7384           (if (or (numberp force) (vectorp force)) force)
7385           t)
7386          (setq data (gnus-data-find article)))
7387     (goto-char b)
7388     (if (not data)
7389         (progn
7390           (unless silent
7391             (gnus-message 3 "Can't find article %d" article))
7392           nil)
7393       (let ((pt (gnus-data-pos data)))
7394         (goto-char pt)
7395         (gnus-summary-set-article-display-arrow pt))
7396       (gnus-summary-position-point)
7397       article)))
7398
7399 ;; Walking around summary lines with displaying articles.
7400
7401 (defun gnus-summary-expand-window (&optional arg)
7402   "Make the summary buffer take up the entire Emacs frame.
7403 Given a prefix, will force an `article' buffer configuration."
7404   (interactive "P")
7405   (if arg
7406       (gnus-configure-windows 'article 'force)
7407     (gnus-configure-windows 'summary 'force)))
7408
7409 (defun gnus-summary-display-article (article &optional all-header)
7410   "Display ARTICLE in article buffer."
7411   (when (gnus-buffer-live-p gnus-article-buffer)
7412     (with-current-buffer gnus-article-buffer
7413       (mm-enable-multibyte)))
7414   (gnus-set-global-variables)
7415   (when (gnus-buffer-live-p gnus-article-buffer)
7416     (with-current-buffer gnus-article-buffer
7417       (setq gnus-article-charset gnus-newsgroup-charset)
7418       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7419       (mm-enable-multibyte)))
7420   (if (null article)
7421       nil
7422     (prog1
7423         (if gnus-summary-display-article-function
7424             (funcall gnus-summary-display-article-function article all-header)
7425           (gnus-article-prepare article all-header))
7426       (gnus-run-hooks 'gnus-select-article-hook)
7427       (when (and gnus-current-article
7428                  (not (zerop gnus-current-article)))
7429         (gnus-summary-goto-subject gnus-current-article))
7430       (gnus-summary-recenter)
7431       (when (and gnus-use-trees gnus-show-threads)
7432         (gnus-possibly-generate-tree article)
7433         (gnus-highlight-selected-tree article))
7434       ;; Successfully display article.
7435       (gnus-article-set-window-start
7436        (cdr (assq article gnus-newsgroup-bookmarks))))))
7437
7438 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7439   "Select the current article.
7440 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7441 non-nil, the article will be re-fetched even if it already present in
7442 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7443 be displayed."
7444   ;; Make sure we are in the summary buffer to work around bbdb bug.
7445   (unless (eq major-mode 'gnus-summary-mode)
7446     (set-buffer gnus-summary-buffer))
7447   (let ((article (or article (gnus-summary-article-number)))
7448         (all-headers (not (not all-headers))) ;Must be t or nil.
7449         gnus-summary-display-article-function)
7450     (and (not pseudo)
7451          (gnus-summary-article-pseudo-p article)
7452          (error "This is a pseudo-article"))
7453     (save-excursion
7454       (set-buffer gnus-summary-buffer)
7455       (if (or (and gnus-single-article-buffer
7456                    (or (null gnus-current-article)
7457                        (null gnus-article-current)
7458                        (null (get-buffer gnus-article-buffer))
7459                        (not (eq article (cdr gnus-article-current)))
7460                        (not (equal (car gnus-article-current)
7461                                    gnus-newsgroup-name))))
7462               (and (not gnus-single-article-buffer)
7463                    (or (null gnus-current-article)
7464                        (not (eq gnus-current-article article))))
7465               force)
7466           ;; The requested article is different from the current article.
7467           (progn
7468             (gnus-summary-display-article article all-headers)
7469             (when (gnus-buffer-live-p gnus-article-buffer)
7470               (with-current-buffer gnus-article-buffer
7471                 (if (not gnus-article-decoded-p) ;; a local variable
7472                     (mm-disable-multibyte))))
7473             (gnus-article-set-window-start
7474              (cdr (assq article gnus-newsgroup-bookmarks)))
7475             article)
7476         'old))))
7477
7478 (defun gnus-summary-force-verify-and-decrypt ()
7479   "Display buttons for signed/encrypted parts and verify/decrypt them."
7480   (interactive)
7481   (let ((mm-verify-option 'known)
7482         (mm-decrypt-option 'known)
7483         (gnus-article-emulate-mime t)
7484         (gnus-buttonized-mime-types (append (list "multipart/signed"
7485                                                   "multipart/encrypted")
7486                                             gnus-buttonized-mime-types)))
7487     (gnus-summary-select-article nil 'force)))
7488
7489 (defun gnus-summary-set-current-mark (&optional current-mark)
7490   "Obsolete function."
7491   nil)
7492
7493 (defun gnus-summary-next-article (&optional unread subject backward push)
7494   "Select the next article.
7495 If UNREAD, only unread articles are selected.
7496 If SUBJECT, only articles with SUBJECT are selected.
7497 If BACKWARD, the previous article is selected instead of the next."
7498   (interactive "P")
7499   ;; Make sure we are in the summary buffer.
7500   (unless (eq major-mode 'gnus-summary-mode)
7501     (set-buffer gnus-summary-buffer))
7502   (cond
7503    ;; Is there such an article?
7504    ((and (gnus-summary-search-forward unread subject backward)
7505          (or (gnus-summary-display-article (gnus-summary-article-number))
7506              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7507     (gnus-summary-position-point))
7508    ;; If not, we try the first unread, if that is wanted.
7509    ((and subject
7510          gnus-auto-select-same
7511          (gnus-summary-first-unread-article))
7512     (gnus-summary-position-point)
7513     (gnus-message 6 "Wrapped"))
7514    ;; Try to get next/previous article not displayed in this group.
7515    ((and gnus-auto-extend-newsgroup
7516          (not unread) (not subject))
7517     (gnus-summary-goto-article
7518      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7519      nil (count-lines (point-min) (point))))
7520    ;; Go to next/previous group.
7521    (t
7522     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7523       (gnus-summary-jump-to-group gnus-newsgroup-name))
7524     (let ((cmd last-command-char)
7525           (point
7526            (with-current-buffer gnus-group-buffer
7527              (point)))
7528           (group
7529            (if (eq gnus-keep-same-level 'best)
7530                (gnus-summary-best-group gnus-newsgroup-name)
7531              (gnus-summary-search-group backward gnus-keep-same-level))))
7532       ;; For some reason, the group window gets selected.  We change
7533       ;; it back.
7534       (select-window (get-buffer-window (current-buffer)))
7535       ;; Select next unread newsgroup automagically.
7536       (cond
7537        ((or (not gnus-auto-select-next)
7538             (not cmd))
7539         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7540        ((or (eq gnus-auto-select-next 'quietly)
7541             (and (eq gnus-auto-select-next 'slightly-quietly)
7542                  push)
7543             (and (eq gnus-auto-select-next 'almost-quietly)
7544                  (gnus-summary-last-article-p)))
7545         ;; Select quietly.
7546         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7547             (gnus-summary-exit)
7548           (gnus-message 7 "No more%s articles (%s)..."
7549                         (if unread " unread" "")
7550                         (if group (concat "selecting " group)
7551                           "exiting"))
7552           (gnus-summary-next-group nil group backward)))
7553        (t
7554         (when (gnus-key-press-event-p last-input-event)
7555           (gnus-summary-walk-group-buffer
7556            gnus-newsgroup-name cmd unread backward point))))))))
7557
7558 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7559   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7560                       (?\C-p (gnus-group-prev-unread-group 1))))
7561         (cursor-in-echo-area t)
7562         keve key group ended prompt)
7563     (save-excursion
7564       (set-buffer gnus-group-buffer)
7565       (goto-char start)
7566       (setq group
7567             (if (eq gnus-keep-same-level 'best)
7568                 (gnus-summary-best-group gnus-newsgroup-name)
7569               (gnus-summary-search-group backward gnus-keep-same-level))))
7570     (while (not ended)
7571       (setq prompt
7572             (format
7573              "No more%s articles%s " (if unread " unread" "")
7574              (if (and group
7575                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7576                  (format " (Type %s for %s [%s])"
7577                          (single-key-description cmd)
7578                          (gnus-group-decoded-name group)
7579                          (gnus-group-unread group))
7580                (format " (Type %s to exit %s)"
7581                        (single-key-description cmd)
7582                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7583       ;; Confirm auto selection.
7584       (setq key (car (setq keve (gnus-read-event-char prompt)))
7585             ended t)
7586       (cond
7587        ((assq key keystrokes)
7588         (let ((obuf (current-buffer)))
7589           (switch-to-buffer gnus-group-buffer)
7590           (when group
7591             (gnus-group-jump-to-group group))
7592           (eval (cadr (assq key keystrokes)))
7593           (setq group (gnus-group-group-name))
7594           (switch-to-buffer obuf))
7595         (setq ended nil))
7596        ((equal key cmd)
7597         (if (or (not group)
7598                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7599             (gnus-summary-exit)
7600           (gnus-summary-next-group nil group backward)))
7601        (t
7602         (push (cdr keve) unread-command-events))))))
7603
7604 (defun gnus-summary-next-unread-article ()
7605   "Select unread article after current one."
7606   (interactive)
7607   (gnus-summary-next-article
7608    (or (not (eq gnus-summary-goto-unread 'never))
7609        (gnus-summary-last-article-p (gnus-summary-article-number)))
7610    (and gnus-auto-select-same
7611         (gnus-summary-article-subject))))
7612
7613 (defun gnus-summary-prev-article (&optional unread subject)
7614   "Select the article after the current one.
7615 If UNREAD is non-nil, only unread articles are selected."
7616   (interactive "P")
7617   (gnus-summary-next-article unread subject t))
7618
7619 (defun gnus-summary-prev-unread-article ()
7620   "Select unread article before current one."
7621   (interactive)
7622   (gnus-summary-prev-article
7623    (or (not (eq gnus-summary-goto-unread 'never))
7624        (gnus-summary-first-article-p (gnus-summary-article-number)))
7625    (and gnus-auto-select-same
7626         (gnus-summary-article-subject))))
7627
7628 (defun gnus-summary-next-page (&optional lines circular stop)
7629   "Show next page of the selected article.
7630 If at the end of the current article, select the next article.
7631 LINES says how many lines should be scrolled up.
7632
7633 If CIRCULAR is non-nil, go to the start of the article instead of
7634 selecting the next article when reaching the end of the current
7635 article.
7636
7637 If STOP is non-nil, just stop when reaching the end of the message.
7638
7639 Also see the variable `gnus-article-skip-boring'."
7640   (interactive "P")
7641   (setq gnus-summary-buffer (current-buffer))
7642   (gnus-set-global-variables)
7643   (let ((article (gnus-summary-article-number))
7644         (article-window (get-buffer-window gnus-article-buffer t))
7645         endp)
7646     ;; If the buffer is empty, we have no article.
7647     (unless article
7648       (error "No article to select"))
7649     (gnus-configure-windows 'article)
7650     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7651         (if (and (eq gnus-summary-goto-unread 'never)
7652                  (not (gnus-summary-last-article-p article)))
7653             (gnus-summary-next-article)
7654           (gnus-summary-next-unread-article))
7655       (if (or (null gnus-current-article)
7656               (null gnus-article-current)
7657               (/= article (cdr gnus-article-current))
7658               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7659           ;; Selected subject is different from current article's.
7660           (gnus-summary-display-article article)
7661         (when article-window
7662           (gnus-eval-in-buffer-window gnus-article-buffer
7663             (setq endp (or (gnus-article-next-page lines)
7664                            (gnus-article-only-boring-p))))
7665           (when endp
7666             (cond (stop
7667                    (gnus-message 3 "End of message"))
7668                   (circular
7669                    (gnus-summary-beginning-of-article))
7670                   (lines
7671                    (gnus-message 3 "End of message"))
7672                   ((null lines)
7673                    (if (and (eq gnus-summary-goto-unread 'never)
7674                             (not (gnus-summary-last-article-p article)))
7675                        (gnus-summary-next-article)
7676                      (gnus-summary-next-unread-article))))))))
7677     (gnus-summary-recenter)
7678     (gnus-summary-position-point)))
7679
7680 (defun gnus-summary-prev-page (&optional lines move)
7681   "Show previous page of selected article.
7682 Argument LINES specifies lines to be scrolled down.
7683 If MOVE, move to the previous unread article if point is at
7684 the beginning of the buffer."
7685   (interactive "P")
7686   (let ((article (gnus-summary-article-number))
7687         (article-window (get-buffer-window gnus-article-buffer t))
7688         endp)
7689     (gnus-configure-windows 'article)
7690     (if (or (null gnus-current-article)
7691             (null gnus-article-current)
7692             (/= article (cdr gnus-article-current))
7693             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7694         ;; Selected subject is different from current article's.
7695         (gnus-summary-display-article article)
7696       (gnus-summary-recenter)
7697       (when article-window
7698         (gnus-eval-in-buffer-window gnus-article-buffer
7699           (setq endp (gnus-article-prev-page lines)))
7700         (when (and move endp)
7701           (cond (lines
7702                  (gnus-message 3 "Beginning of message"))
7703                 ((null lines)
7704                  (if (and (eq gnus-summary-goto-unread 'never)
7705                           (not (gnus-summary-first-article-p article)))
7706                      (gnus-summary-prev-article)
7707                    (gnus-summary-prev-unread-article))))))))
7708   (gnus-summary-position-point))
7709
7710 (defun gnus-summary-prev-page-or-article (&optional lines)
7711   "Show previous page of selected article.
7712 Argument LINES specifies lines to be scrolled down.
7713 If at the beginning of the article, go to the next article."
7714   (interactive "P")
7715   (gnus-summary-prev-page lines t))
7716
7717 (defun gnus-summary-scroll-up (lines)
7718   "Scroll up (or down) one line current article.
7719 Argument LINES specifies lines to be scrolled up (or down if negative)."
7720   (interactive "p")
7721   (gnus-configure-windows 'article)
7722   (gnus-summary-show-thread)
7723   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7724     (gnus-eval-in-buffer-window gnus-article-buffer
7725       (cond ((> lines 0)
7726              (when (gnus-article-next-page lines)
7727                (gnus-message 3 "End of message")))
7728             ((< lines 0)
7729              (gnus-article-prev-page (- lines))))))
7730   (gnus-summary-recenter)
7731   (gnus-summary-position-point))
7732
7733 (defun gnus-summary-scroll-down (lines)
7734   "Scroll down (or up) one line current article.
7735 Argument LINES specifies lines to be scrolled down (or up if negative)."
7736   (interactive "p")
7737   (gnus-summary-scroll-up (- lines)))
7738
7739 (defun gnus-summary-next-same-subject ()
7740   "Select next article which has the same subject as current one."
7741   (interactive)
7742   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7743
7744 (defun gnus-summary-prev-same-subject ()
7745   "Select previous article which has the same subject as current one."
7746   (interactive)
7747   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7748
7749 (defun gnus-summary-next-unread-same-subject ()
7750   "Select next unread article which has the same subject as current one."
7751   (interactive)
7752   (gnus-summary-next-article t (gnus-summary-article-subject)))
7753
7754 (defun gnus-summary-prev-unread-same-subject ()
7755   "Select previous unread article which has the same subject as current one."
7756   (interactive)
7757   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7758
7759 (defun gnus-summary-first-unread-article ()
7760   "Select the first unread article.
7761 Return nil if there are no unread articles."
7762   (interactive)
7763   (prog1
7764       (when (gnus-summary-first-subject t)
7765         (gnus-summary-show-thread)
7766         (gnus-summary-first-subject t)
7767         (gnus-summary-display-article (gnus-summary-article-number)))
7768     (gnus-summary-position-point)))
7769
7770 (defun gnus-summary-first-unread-subject ()
7771   "Place the point on the subject line of the first unread article.
7772 Return nil if there are no unread articles."
7773   (interactive)
7774   (prog1
7775       (when (gnus-summary-first-subject t)
7776         (gnus-summary-show-thread)
7777         (gnus-summary-first-subject t))
7778     (gnus-summary-position-point)))
7779
7780 (defun gnus-summary-first-unseen-subject ()
7781   "Place the point on the subject line of the first unseen article.
7782 Return nil if there are no unseen articles."
7783   (interactive)
7784   (prog1
7785       (when (gnus-summary-first-subject nil nil t)
7786         (gnus-summary-show-thread)
7787         (gnus-summary-first-subject nil nil t))
7788     (gnus-summary-position-point)))
7789
7790 (defun gnus-summary-first-unseen-or-unread-subject ()
7791   "Place the point on the subject line of the first unseen article or,
7792 if all article have been seen, on the subject line of the first unread
7793 article."
7794   (interactive)
7795   (prog1
7796       (unless (when (gnus-summary-first-subject nil nil t)
7797                 (gnus-summary-show-thread)
7798                 (gnus-summary-first-subject nil nil t))
7799         (when (gnus-summary-first-subject t)
7800           (gnus-summary-show-thread)
7801           (gnus-summary-first-subject t)))
7802     (gnus-summary-position-point)))
7803
7804 (defun gnus-summary-first-article ()
7805   "Select the first article.
7806 Return nil if there are no articles."
7807   (interactive)
7808   (prog1
7809       (when (gnus-summary-first-subject)
7810         (gnus-summary-show-thread)
7811         (gnus-summary-first-subject)
7812         (gnus-summary-display-article (gnus-summary-article-number)))
7813     (gnus-summary-position-point)))
7814
7815 (defun gnus-summary-best-unread-article (&optional arg)
7816   "Select the unread article with the highest score.
7817 If given a prefix argument, select the next unread article that has a
7818 score higher than the default score."
7819   (interactive "P")
7820   (let ((article (if arg
7821                      (gnus-summary-better-unread-subject)
7822                    (gnus-summary-best-unread-subject))))
7823     (if article
7824         (gnus-summary-goto-article article)
7825       (error "No unread articles"))))
7826
7827 (defun gnus-summary-best-unread-subject ()
7828   "Select the unread subject with the highest score."
7829   (interactive)
7830   (let ((best -1000000)
7831         (data gnus-newsgroup-data)
7832         article score)
7833     (while data
7834       (and (gnus-data-unread-p (car data))
7835            (> (setq score
7836                     (gnus-summary-article-score (gnus-data-number (car data))))
7837               best)
7838            (setq best score
7839                  article (gnus-data-number (car data))))
7840       (setq data (cdr data)))
7841     (when article
7842       (gnus-summary-goto-subject article))
7843     (gnus-summary-position-point)
7844     article))
7845
7846 (defun gnus-summary-better-unread-subject ()
7847   "Select the first unread subject that has a score over the default score."
7848   (interactive)
7849   (let ((data gnus-newsgroup-data)
7850         article score)
7851     (while (and (setq article (gnus-data-number (car data)))
7852                 (or (gnus-data-read-p (car data))
7853                     (not (> (gnus-summary-article-score article)
7854                             gnus-summary-default-score))))
7855       (setq data (cdr data)))
7856     (when article
7857       (gnus-summary-goto-subject article))
7858     (gnus-summary-position-point)
7859     article))
7860
7861 (defun gnus-summary-last-subject ()
7862   "Go to the last displayed subject line in the group."
7863   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7864     (when article
7865       (gnus-summary-goto-subject article))))
7866
7867 (defun gnus-summary-goto-article (article &optional all-headers force)
7868   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7869 If ALL-HEADERS is non-nil, no header lines are hidden.
7870 If FORCE, go to the article even if it isn't displayed.  If FORCE
7871 is a number, it is the line the article is to be displayed on."
7872   (interactive
7873    (list
7874     (completing-read
7875      "Article number or Message-ID: "
7876      (mapcar (lambda (number) (list (int-to-string number)))
7877              gnus-newsgroup-limit))
7878     current-prefix-arg
7879     t))
7880   (prog1
7881       (if (and (stringp article)
7882                (string-match "@\\|%40" article))
7883           (gnus-summary-refer-article article)
7884         (when (stringp article)
7885           (setq article (string-to-number article)))
7886         (if (gnus-summary-goto-subject article force)
7887             (gnus-summary-display-article article all-headers)
7888           (gnus-message 4 "Couldn't go to article %s" article) nil))
7889     (gnus-summary-position-point)))
7890
7891 (defun gnus-summary-goto-last-article ()
7892   "Go to the previously read article."
7893   (interactive)
7894   (prog1
7895       (when gnus-last-article
7896         (gnus-summary-goto-article gnus-last-article nil t))
7897     (gnus-summary-position-point)))
7898
7899 (defun gnus-summary-pop-article (number)
7900   "Pop one article off the history and go to the previous.
7901 NUMBER articles will be popped off."
7902   (interactive "p")
7903   (let (to)
7904     (setq gnus-newsgroup-history
7905           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7906     (if to
7907         (gnus-summary-goto-article (car to) nil t)
7908       (error "Article history empty")))
7909   (gnus-summary-position-point))
7910
7911 ;; Summary commands and functions for limiting the summary buffer.
7912
7913 (defun gnus-summary-limit-to-articles (n)
7914   "Limit the summary buffer to the next N articles.
7915 If not given a prefix, use the process marked articles instead."
7916   (interactive "P")
7917   (prog1
7918       (let ((articles (gnus-summary-work-articles n)))
7919         (setq gnus-newsgroup-processable nil)
7920         (gnus-summary-limit articles))
7921     (gnus-summary-position-point)))
7922
7923 (defun gnus-summary-pop-limit (&optional total)
7924   "Restore the previous limit.
7925 If given a prefix, remove all limits."
7926   (interactive "P")
7927   (when total
7928     (setq gnus-newsgroup-limits
7929           (list (mapcar (lambda (h) (mail-header-number h))
7930                         gnus-newsgroup-headers))))
7931   (unless gnus-newsgroup-limits
7932     (error "No limit to pop"))
7933   (prog1
7934       (gnus-summary-limit nil 'pop)
7935     (gnus-summary-position-point)))
7936
7937 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7938   "Limit the summary buffer to articles that have subjects that match a regexp.
7939 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7940   (interactive
7941    (list (read-string (if current-prefix-arg
7942                           "Exclude subject (regexp): "
7943                         "Limit to subject (regexp): "))
7944          nil current-prefix-arg))
7945   (unless header
7946     (setq header "subject"))
7947   (when (not (equal "" subject))
7948     (prog1
7949         (let ((articles (gnus-summary-find-matching
7950                          (or header "subject") subject 'all nil nil
7951                          not-matching)))
7952           (unless articles
7953             (error "Found no matches for \"%s\"" subject))
7954           (gnus-summary-limit articles))
7955       (gnus-summary-position-point))))
7956
7957 (defun gnus-summary-limit-to-author (from &optional not-matching)
7958   "Limit the summary buffer to articles that have authors that match a regexp.
7959 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7960   (interactive
7961    (list (read-string (if current-prefix-arg
7962                           "Exclude author (regexp): "
7963                         "Limit to author (regexp): "))
7964          current-prefix-arg))
7965   (gnus-summary-limit-to-subject from "from" not-matching))
7966
7967 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7968   "Limit the summary buffer to articles with the given RECIPIENT.
7969
7970 If NOT-MATCHING, exclude RECIPIENT.
7971
7972 To and Cc headers are checked.  You need to include them in
7973 `nnmail-extra-headers'."
7974   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7975   (interactive
7976    (list (read-string (format "%s recipient (regexp): "
7977                               (if current-prefix-arg "Exclude" "Limit to")))
7978          current-prefix-arg))
7979   (when (not (equal "" recipient))
7980     (prog1 (let* ((to
7981                    (if (memq 'To nnmail-extra-headers)
7982                        (gnus-summary-find-matching
7983                         (cons 'extra 'To) recipient 'all nil nil
7984                         not-matching)
7985                      (gnus-message
7986                       1 "`To' isn't present in `nnmail-extra-headers'")
7987                      (sit-for 1)
7988                      nil))
7989                   (cc
7990                    (if (memq 'Cc nnmail-extra-headers)
7991                        (gnus-summary-find-matching
7992                         (cons 'extra 'Cc) recipient 'all nil nil
7993                         not-matching)
7994                      (gnus-message
7995                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7996                      (sit-for 1)
7997                      nil))
7998                   (articles
7999                    (if not-matching
8000                        ;; We need the numbers that are in both lists:
8001                        (mapcar (lambda (a)
8002                                  (and (memq a to) a))
8003                                cc)
8004                      (nconc to cc))))
8005              (unless articles
8006                (error "Found no matches for \"%s\"" recipient))
8007              (gnus-summary-limit articles))
8008       (gnus-summary-position-point))))
8009
8010 (defun gnus-summary-limit-to-address (address &optional not-matching)
8011   "Limit the summary buffer to articles with the given ADDRESS.
8012
8013 If NOT-MATCHING, exclude ADDRESS.
8014
8015 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8016 in `nnmail-extra-headers'."
8017   (interactive
8018    (list (read-string (format "%s address (regexp): "
8019                               (if current-prefix-arg "Exclude" "Limit to")))
8020          current-prefix-arg))
8021   (when (not (equal "" address))
8022     (prog1 (let* ((to
8023                    (if (memq 'To nnmail-extra-headers)
8024                        (gnus-summary-find-matching
8025                         (cons 'extra 'To) address 'all nil nil
8026                         not-matching)
8027                      (gnus-message
8028                       1 "`To' isn't present in `nnmail-extra-headers'")
8029                      (sit-for 1)
8030                      t))
8031                   (cc
8032                    (if (memq 'Cc nnmail-extra-headers)
8033                        (gnus-summary-find-matching
8034                         (cons 'extra 'Cc) address 'all nil nil
8035                         not-matching)
8036                      (gnus-message
8037                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8038                      (sit-for 1)
8039                      t))
8040                   (from
8041                    (gnus-summary-find-matching "from" address
8042                                                'all nil nil not-matching))
8043                   (articles
8044                    (if not-matching
8045                        ;; We need the numbers that are in all lists:
8046                        (if (eq cc t)
8047                            (if (eq to t)
8048                                from
8049                              (mapcar (lambda (a) (car (memq a from))) to))
8050                          (if (eq to t)
8051                              (mapcar (lambda (a) (car (memq a from))) cc)
8052                            (mapcar (lambda (a) (car (memq a from)))
8053                                    (mapcar (lambda (a) (car (memq a to)))
8054                                            cc))))
8055                      (nconc (if (eq to t) nil to)
8056                             (if (eq cc t) nil cc)
8057                             from))))
8058              (unless articles
8059                (error "Found no matches for \"%s\"" address))
8060              (gnus-summary-limit articles))
8061       (gnus-summary-position-point))))
8062
8063 (defun gnus-summary-limit-strange-charsets-predicate (header)
8064   (let ((string (concat (mail-header-subject header)
8065                         (mail-header-from header)))
8066         charset found)
8067     (dotimes (i (1- (length string)))
8068       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8069       (when (string-match "unicode\\|big\\|japanese" charset)
8070         (setq found t)))
8071     found))
8072
8073 (defun gnus-summary-limit-to-predicate (predicate)
8074   "Limit to articles where PREDICATE returns non-nil.
8075 PREDICATE will be called with the header structures of the
8076 articles."
8077   (let ((articles nil)
8078         (case-fold-search t))
8079     (dolist (header gnus-newsgroup-headers)
8080       (when (funcall predicate header)
8081         (push (mail-header-number header) articles)))
8082     (gnus-summary-limit (nreverse articles))))
8083
8084 (defun gnus-summary-limit-to-age (age &optional younger-p)
8085   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8086 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8087 articles that are younger than AGE days."
8088   (interactive
8089    (let ((younger current-prefix-arg)
8090          (days-got nil)
8091          days)
8092      (while (not days-got)
8093        (setq days (if younger
8094                       (read-string "Limit to articles younger than (in days, older when negative): ")
8095                     (read-string
8096                      "Limit to articles older than (in days, younger when negative): ")))
8097        (when (> (length days) 0)
8098          (setq days (read days)))
8099        (if (numberp days)
8100            (progn
8101              (setq days-got t)
8102              (when (< days 0)
8103                (setq younger (not younger))
8104                (setq days (* days -1))))
8105          (message "Please enter a number.")
8106          (sleep-for 1)))
8107      (list days younger)))
8108   (prog1
8109       (let ((data gnus-newsgroup-data)
8110             (cutoff (days-to-time age))
8111             articles d date is-younger)
8112         (while (setq d (pop data))
8113           (when (and (vectorp (gnus-data-header d))
8114                      (setq date (mail-header-date (gnus-data-header d))))
8115             (setq is-younger (time-less-p
8116                               (time-since (condition-case ()
8117                                               (date-to-time date)
8118                                             (error '(0 0))))
8119                               cutoff))
8120             (when (if younger-p
8121                       is-younger
8122                     (not is-younger))
8123               (push (gnus-data-number d) articles))))
8124         (gnus-summary-limit (nreverse articles)))
8125     (gnus-summary-position-point)))
8126
8127 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8128   "Limit the summary buffer to articles that match an 'extra' header."
8129   (interactive
8130    (let ((header
8131           (intern
8132            (gnus-completing-read-with-default
8133             (symbol-name (car gnus-extra-headers))
8134             (if current-prefix-arg
8135                 "Exclude extra header"
8136               "Limit extra header")
8137             (mapcar (lambda (x)
8138                       (cons (symbol-name x) x))
8139                     gnus-extra-headers)
8140             nil
8141             t))))
8142      (list header
8143            (read-string (format "%s header %s (regexp): "
8144                                 (if current-prefix-arg "Exclude" "Limit to")
8145                                 header))
8146            current-prefix-arg)))
8147   (when (not (equal "" regexp))
8148     (prog1
8149         (let ((articles (gnus-summary-find-matching
8150                          (cons 'extra header) regexp 'all nil nil
8151                          not-matching)))
8152           (unless articles
8153             (error "Found no matches for \"%s\"" regexp))
8154           (gnus-summary-limit articles))
8155       (gnus-summary-position-point))))
8156
8157 (defun gnus-summary-limit-to-display-predicate ()
8158   "Limit the summary buffer to the predicated in the `display' group parameter."
8159   (interactive)
8160   (unless gnus-newsgroup-display
8161     (error "There is no `display' group parameter"))
8162   (let (articles)
8163     (dolist (number gnus-newsgroup-articles)
8164       (when (funcall gnus-newsgroup-display)
8165         (push number articles)))
8166     (gnus-summary-limit articles))
8167   (gnus-summary-position-point))
8168
8169 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8170 (make-obsolete
8171  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8172
8173 (defun gnus-summary-limit-to-unread (&optional all)
8174   "Limit the summary buffer to articles that are not marked as read.
8175 If ALL is non-nil, limit strictly to unread articles."
8176   (interactive "P")
8177   (if all
8178       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8179     (gnus-summary-limit-to-marks
8180      ;; Concat all the marks that say that an article is read and have
8181      ;; those removed.
8182      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8183            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8184            gnus-low-score-mark gnus-expirable-mark
8185            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8186            gnus-duplicate-mark gnus-souped-mark)
8187      'reverse)))
8188
8189 (defun gnus-summary-limit-to-headers (match &optional reverse)
8190   "Limit the summary buffer to articles that have headers that match MATCH.
8191 If REVERSE (the prefix), limit to articles that don't match."
8192   (interactive "sMatch headers (regexp): \nP")
8193   (gnus-summary-limit-to-bodies match reverse t))
8194
8195 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8196   "Limit the summary buffer to articles that have bodies that match MATCH.
8197 If REVERSE (the prefix), limit to articles that don't match."
8198   (interactive "sMatch body (regexp): \nP")
8199   (let ((articles nil)
8200         (gnus-select-article-hook nil)  ;Disable hook.
8201         (gnus-article-prepare-hook nil)
8202         (gnus-use-article-prefetch nil)
8203         (gnus-keep-backlog nil)
8204         (gnus-break-pages nil)
8205         (gnus-summary-display-arrow nil)
8206         (gnus-updated-mode-lines nil)
8207         (gnus-auto-center-summary nil)
8208         (gnus-display-mime-function nil))
8209     (dolist (data gnus-newsgroup-data)
8210       (let (gnus-mark-article-hook)
8211         (gnus-summary-select-article t t nil (gnus-data-number data)))
8212       (save-excursion
8213         (set-buffer gnus-article-buffer)
8214         (article-goto-body)
8215         (let* ((case-fold-search t)
8216                (found (if headersp
8217                           (re-search-backward match nil t)
8218                         (re-search-forward match nil t))))
8219           (when (or (and found
8220                          (not reverse))
8221                     (and (not found)
8222                          reverse))
8223             (push (gnus-data-number data) articles)))))
8224     (if (not articles)
8225         (message "No messages matched")
8226       (gnus-summary-limit articles)))
8227   (gnus-summary-position-point))
8228
8229 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8230   "Limit the summary buffer to articles that aren't part on any thread.
8231 If THREADSP (the prefix), limit to articles that are in threads."
8232   (interactive "P")
8233   (let ((articles nil)
8234         thread-articles
8235         threads)
8236     (dolist (thread gnus-newsgroup-threads)
8237       (if (stringp (car thread))
8238           (dolist (thread (cdr thread))
8239             (push thread threads))
8240         (push thread threads)))
8241     (dolist (thread threads)
8242       (setq thread-articles (gnus-articles-in-thread thread))
8243       (when (or (and threadsp
8244                      (> (length thread-articles) 1))
8245                 (and (not threadsp)
8246                      (= (length thread-articles) 1)))
8247         (setq articles (nconc thread-articles articles))))
8248     (if (not articles)
8249         (message "No messages matched")
8250       (gnus-summary-limit articles))
8251     (gnus-summary-position-point)))
8252
8253 (defun gnus-summary-limit-to-replied (&optional unreplied)
8254   "Limit the summary buffer to replied articles.
8255 If UNREPLIED (the prefix), limit to unreplied articles."
8256   (interactive "P")
8257   (if unreplied
8258       (gnus-summary-limit
8259        (gnus-set-difference gnus-newsgroup-articles
8260         gnus-newsgroup-replied))
8261     (gnus-summary-limit gnus-newsgroup-replied))
8262   (gnus-summary-position-point))
8263
8264 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8265 (make-obsolete 'gnus-summary-delete-marked-with
8266                'gnus-summary-limit-exclude-marks)
8267
8268 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8269   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8270 If REVERSE, limit the summary buffer to articles that are marked
8271 with MARKS.  MARKS can either be a string of marks or a list of marks.
8272 Returns how many articles were removed."
8273   (interactive "sMarks: ")
8274   (gnus-summary-limit-to-marks marks t))
8275
8276 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8277   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8278 If REVERSE (the prefix), limit the summary buffer to articles that are
8279 not marked with MARKS.  MARKS can either be a string of marks or a
8280 list of marks.
8281 Returns how many articles were removed."
8282   (interactive "sMarks: \nP")
8283   (prog1
8284       (let ((data gnus-newsgroup-data)
8285             (marks (if (listp marks) marks
8286                      (append marks nil))) ; Transform to list.
8287             articles)
8288         (while data
8289           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8290                   (memq (gnus-data-mark (car data)) marks))
8291             (push (gnus-data-number (car data)) articles))
8292           (setq data (cdr data)))
8293         (gnus-summary-limit articles))
8294     (gnus-summary-position-point)))
8295
8296 (defun gnus-summary-limit-to-score (score)
8297   "Limit to articles with score at or above SCORE."
8298   (interactive "NLimit to articles with score of at least: ")
8299   (let ((data gnus-newsgroup-data)
8300         articles)
8301     (while data
8302       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8303                 score)
8304         (push (gnus-data-number (car data)) articles))
8305       (setq data (cdr data)))
8306     (prog1
8307         (gnus-summary-limit articles)
8308       (gnus-summary-position-point))))
8309
8310 (defun gnus-summary-limit-to-unseen ()
8311   "Limit to unseen articles."
8312   (interactive)
8313   (prog1
8314       (gnus-summary-limit gnus-newsgroup-unseen)
8315     (gnus-summary-position-point)))
8316
8317 (defun gnus-summary-limit-include-thread (id)
8318   "Display all the hidden articles that is in the thread with ID in it.
8319 When called interactively, ID is the Message-ID of the current
8320 article."
8321   (interactive (list (mail-header-id (gnus-summary-article-header))))
8322   (let ((articles (gnus-articles-in-thread
8323                    (gnus-id-to-thread (gnus-root-id id)))))
8324     (prog1
8325         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8326       (gnus-summary-limit-include-matching-articles
8327        "subject"
8328        (regexp-quote (gnus-simplify-subject-re
8329                       (mail-header-subject (gnus-id-to-header id)))))
8330       (gnus-summary-position-point))))
8331
8332 (defun gnus-summary-limit-include-matching-articles (header regexp)
8333   "Display all the hidden articles that have HEADERs that match REGEXP."
8334   (interactive (list (read-string "Match on header: ")
8335                      (read-string "Regexp: ")))
8336   (let ((articles (gnus-find-matching-articles header regexp)))
8337     (prog1
8338         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8339       (gnus-summary-position-point))))
8340
8341 (defun gnus-summary-insert-dormant-articles ()
8342   "Insert all the dormant articles for this group into the current buffer."
8343   (interactive)
8344   (let ((gnus-verbose (max 6 gnus-verbose)))
8345     (if (not gnus-newsgroup-dormant)
8346         (gnus-message 3 "No dormant articles for this group")
8347       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8348
8349 (defun gnus-summary-insert-ticked-articles ()
8350   "Insert ticked articles for this group into the current buffer."
8351   (interactive)
8352   (let ((gnus-verbose (max 6 gnus-verbose)))
8353     (if (not gnus-newsgroup-marked)
8354         (gnus-message 3 "No ticked articles for this group")
8355       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8356
8357 (defun gnus-summary-limit-include-dormant ()
8358   "Display all the hidden articles that are marked as dormant.
8359 Note that this command only works on a subset of the articles currently
8360 fetched for this group."
8361   (interactive)
8362   (unless gnus-newsgroup-dormant
8363     (error "There are no dormant articles in this group"))
8364   (prog1
8365       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8366     (gnus-summary-position-point)))
8367
8368 (defun gnus-summary-limit-exclude-dormant ()
8369   "Hide all dormant articles."
8370   (interactive)
8371   (prog1
8372       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8373     (gnus-summary-position-point)))
8374
8375 (defun gnus-summary-limit-exclude-childless-dormant ()
8376   "Hide all dormant articles that have no children."
8377   (interactive)
8378   (let ((data (gnus-data-list t))
8379         articles d children)
8380     ;; Find all articles that are either not dormant or have
8381     ;; children.
8382     (while (setq d (pop data))
8383       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8384                 (and (setq children
8385                            (gnus-article-children (gnus-data-number d)))
8386                      (let (found)
8387                        (while children
8388                          (when (memq (car children) articles)
8389                            (setq children nil
8390                                  found t))
8391                          (pop children))
8392                        found)))
8393         (push (gnus-data-number d) articles)))
8394     ;; Do the limiting.
8395     (prog1
8396         (gnus-summary-limit articles)
8397       (gnus-summary-position-point))))
8398
8399 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8400   "Mark all unread excluded articles as read.
8401 If ALL, mark even excluded ticked and dormants as read."
8402   (interactive "P")
8403   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8404   (let ((articles (gnus-sorted-ndifference
8405                    (sort
8406                     (mapcar (lambda (h) (mail-header-number h))
8407                             gnus-newsgroup-headers)
8408                     '<)
8409                    gnus-newsgroup-limit))
8410         article)
8411     (setq gnus-newsgroup-unreads
8412           (gnus-sorted-intersection gnus-newsgroup-unreads
8413                                     gnus-newsgroup-limit))
8414     (if all
8415         (setq gnus-newsgroup-dormant nil
8416               gnus-newsgroup-marked nil
8417               gnus-newsgroup-reads
8418               (nconc
8419                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8420                gnus-newsgroup-reads))
8421       (while (setq article (pop articles))
8422         (unless (or (memq article gnus-newsgroup-dormant)
8423                     (memq article gnus-newsgroup-marked))
8424           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8425
8426 (defun gnus-summary-limit (articles &optional pop)
8427   (if pop
8428       ;; We pop the previous limit off the stack and use that.
8429       (setq articles (car gnus-newsgroup-limits)
8430             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8431     ;; We use the new limit, so we push the old limit on the stack.
8432     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8433   ;; Set the limit.
8434   (setq gnus-newsgroup-limit articles)
8435   (let ((total (length gnus-newsgroup-data))
8436         (data (gnus-data-find-list (gnus-summary-article-number)))
8437         (gnus-summary-mark-below nil)   ; Inhibit this.
8438         found)
8439     ;; This will do all the work of generating the new summary buffer
8440     ;; according to the new limit.
8441     (gnus-summary-prepare)
8442     ;; Hide any threads, possibly.
8443     (gnus-summary-maybe-hide-threads)
8444     ;; Try to return to the article you were at, or one in the
8445     ;; neighborhood.
8446     (when data
8447       ;; We try to find some article after the current one.
8448       (while data
8449         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8450           (setq data nil
8451                 found t))
8452         (setq data (cdr data))))
8453     (unless found
8454       ;; If there is no data, that means that we were after the last
8455       ;; article.  The same goes when we can't find any articles
8456       ;; after the current one.
8457       (goto-char (point-max))
8458       (gnus-summary-find-prev))
8459     (gnus-set-mode-line 'summary)
8460     ;; We return how many articles were removed from the summary
8461     ;; buffer as a result of the new limit.
8462     (- total (length gnus-newsgroup-data))))
8463
8464 (defsubst gnus-invisible-cut-children (threads)
8465   (let ((num 0))
8466     (while threads
8467       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8468         (incf num))
8469       (pop threads))
8470     (< num 2)))
8471
8472 (defsubst gnus-cut-thread (thread)
8473   "Go forwards in the thread until we find an article that we want to display."
8474   (when (or (eq gnus-fetch-old-headers 'some)
8475             (eq gnus-fetch-old-headers 'invisible)
8476             (numberp gnus-fetch-old-headers)
8477             (eq gnus-build-sparse-threads 'some)
8478             (eq gnus-build-sparse-threads 'more))
8479     ;; Deal with old-fetched headers and sparse threads.
8480     (while (and
8481             thread
8482             (or
8483              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8484              (gnus-summary-article-ancient-p
8485               (mail-header-number (car thread))))
8486             (if (or (<= (length (cdr thread)) 1)
8487                     (eq gnus-fetch-old-headers 'invisible))
8488                 (setq gnus-newsgroup-limit
8489                       (delq (mail-header-number (car thread))
8490                             gnus-newsgroup-limit)
8491                       thread (cadr thread))
8492               (when (gnus-invisible-cut-children (cdr thread))
8493                 (let ((th (cdr thread)))
8494                   (while th
8495                     (if (memq (mail-header-number (caar th))
8496                               gnus-newsgroup-limit)
8497                         (setq thread (car th)
8498                               th nil)
8499                       (setq th (cdr th))))))))))
8500   thread)
8501
8502 (defun gnus-cut-threads (threads)
8503   "Cut off all uninteresting articles from the beginning of THREADS."
8504   (when (or (eq gnus-fetch-old-headers 'some)
8505             (eq gnus-fetch-old-headers 'invisible)
8506             (numberp gnus-fetch-old-headers)
8507             (eq gnus-build-sparse-threads 'some)
8508             (eq gnus-build-sparse-threads 'more))
8509     (let ((th threads))
8510       (while th
8511         (setcar th (gnus-cut-thread (car th)))
8512         (setq th (cdr th)))))
8513   ;; Remove nixed out threads.
8514   (delq nil threads))
8515
8516 (defun gnus-summary-initial-limit (&optional show-if-empty)
8517   "Figure out what the initial limit is supposed to be on group entry.
8518 This entails weeding out unwanted dormants, low-scored articles,
8519 fetch-old-headers verbiage, and so on."
8520   ;; Most groups have nothing to remove.
8521   (if (or gnus-inhibit-limiting
8522           (and (null gnus-newsgroup-dormant)
8523                (eq gnus-newsgroup-display 'gnus-not-ignore)
8524                (not (eq gnus-fetch-old-headers 'some))
8525                (not (numberp gnus-fetch-old-headers))
8526                (not (eq gnus-fetch-old-headers 'invisible))
8527                (null gnus-summary-expunge-below)
8528                (not (eq gnus-build-sparse-threads 'some))
8529                (not (eq gnus-build-sparse-threads 'more))
8530                (null gnus-thread-expunge-below)
8531                (not gnus-use-nocem)))
8532       ()                                ; Do nothing.
8533     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8534     (setq gnus-newsgroup-limit nil)
8535     (mapatoms
8536      (lambda (node)
8537        (unless (car (symbol-value node))
8538          ;; These threads have no parents -- they are roots.
8539          (let ((nodes (cdr (symbol-value node)))
8540                thread)
8541            (while nodes
8542              (if (and gnus-thread-expunge-below
8543                       (< (gnus-thread-total-score (car nodes))
8544                          gnus-thread-expunge-below))
8545                  (gnus-expunge-thread (pop nodes))
8546                (setq thread (pop nodes))
8547                (gnus-summary-limit-children thread))))))
8548      gnus-newsgroup-dependencies)
8549     ;; If this limitation resulted in an empty group, we might
8550     ;; pop the previous limit and use it instead.
8551     (when (and (not gnus-newsgroup-limit)
8552                show-if-empty)
8553       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8554     gnus-newsgroup-limit))
8555
8556 (defun gnus-summary-limit-children (thread)
8557   "Return 1 if this subthread is visible and 0 if it is not."
8558   ;; First we get the number of visible children to this thread.  This
8559   ;; is done by recursing down the thread using this function, so this
8560   ;; will really go down to a leaf article first, before slowly
8561   ;; working its way up towards the root.
8562   (when thread
8563     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8564            (children
8565            (if (cdr thread)
8566                (apply '+ (mapcar 'gnus-summary-limit-children
8567                                  (cdr thread)))
8568              0))
8569           (number (mail-header-number (car thread)))
8570           score)
8571       (if (and
8572            (not (memq number gnus-newsgroup-marked))
8573            (or
8574             ;; If this article is dormant and has absolutely no visible
8575             ;; children, then this article isn't visible.
8576             (and (memq number gnus-newsgroup-dormant)
8577                  (zerop children))
8578             ;; If this is "fetch-old-headered" and there is no
8579             ;; visible children, then we don't want this article.
8580             (and (or (eq gnus-fetch-old-headers 'some)
8581                      (numberp gnus-fetch-old-headers))
8582                  (gnus-summary-article-ancient-p number)
8583                  (zerop children))
8584             ;; If this is "fetch-old-headered" and `invisible', then
8585             ;; we don't want this article.
8586             (and (eq gnus-fetch-old-headers 'invisible)
8587                  (gnus-summary-article-ancient-p number))
8588             ;; If this is a sparsely inserted article with no children,
8589             ;; we don't want it.
8590             (and (eq gnus-build-sparse-threads 'some)
8591                  (gnus-summary-article-sparse-p number)
8592                  (zerop children))
8593             ;; If we use expunging, and this article is really
8594             ;; low-scored, then we don't want this article.
8595             (when (and gnus-summary-expunge-below
8596                        (< (setq score
8597                                 (or (cdr (assq number gnus-newsgroup-scored))
8598                                     gnus-summary-default-score))
8599                           gnus-summary-expunge-below))
8600               ;; We increase the expunge-tally here, but that has
8601               ;; nothing to do with the limits, really.
8602               (incf gnus-newsgroup-expunged-tally)
8603               ;; We also mark as read here, if that's wanted.
8604               (when (and gnus-summary-mark-below
8605                          (< score gnus-summary-mark-below))
8606                 (setq gnus-newsgroup-unreads
8607                       (delq number gnus-newsgroup-unreads))
8608                 (if gnus-newsgroup-auto-expire
8609                     (push number gnus-newsgroup-expirable)
8610                   (push (cons number gnus-low-score-mark)
8611                         gnus-newsgroup-reads)))
8612               t)
8613             ;; Do the `display' group parameter.
8614             (and gnus-newsgroup-display
8615                  (not (funcall gnus-newsgroup-display)))
8616             ;; Check NoCeM things.
8617             (when (and gnus-use-nocem
8618                        (gnus-nocem-unwanted-article-p
8619                         (mail-header-id (car thread))))
8620               (setq gnus-newsgroup-unreads
8621                     (delq number gnus-newsgroup-unreads))
8622               t)))
8623           ;; Nope, invisible article.
8624           0
8625         ;; Ok, this article is to be visible, so we add it to the limit
8626         ;; and return 1.
8627         (push number gnus-newsgroup-limit)
8628         1))))
8629
8630 (defun gnus-expunge-thread (thread)
8631   "Mark all articles in THREAD as read."
8632   (let* ((number (mail-header-number (car thread))))
8633     (incf gnus-newsgroup-expunged-tally)
8634     ;; We also mark as read here, if that's wanted.
8635     (setq gnus-newsgroup-unreads
8636           (delq number gnus-newsgroup-unreads))
8637     (if gnus-newsgroup-auto-expire
8638         (push number gnus-newsgroup-expirable)
8639       (push (cons number gnus-low-score-mark)
8640             gnus-newsgroup-reads)))
8641   ;; Go recursively through all subthreads.
8642   (mapcar 'gnus-expunge-thread (cdr thread)))
8643
8644 ;; Summary article oriented commands
8645
8646 (defun gnus-summary-refer-parent-article (n)
8647   "Refer parent article N times.
8648 If N is negative, go to ancestor -N instead.
8649 The difference between N and the number of articles fetched is returned."
8650   (interactive "p")
8651   (let ((skip 1)
8652         error header ref)
8653     (when (not (natnump n))
8654       (setq skip (abs n)
8655             n 1))
8656     (while (and (> n 0)
8657                 (not error))
8658       (setq header (gnus-summary-article-header))
8659       (if (and (eq (mail-header-number header)
8660                    (cdr gnus-article-current))
8661                (equal gnus-newsgroup-name
8662                       (car gnus-article-current)))
8663           ;; If we try to find the parent of the currently
8664           ;; displayed article, then we take a look at the actual
8665           ;; References header, since this is slightly more
8666           ;; reliable than the References field we got from the
8667           ;; server.
8668           (save-excursion
8669             (set-buffer gnus-original-article-buffer)
8670             (nnheader-narrow-to-headers)
8671             (unless (setq ref (message-fetch-field "references"))
8672               (when (setq ref (message-fetch-field "in-reply-to"))
8673                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8674             (widen))
8675         (setq ref
8676               ;; It's not the current article, so we take a bet on
8677               ;; the value we got from the server.
8678               (mail-header-references header)))
8679       (if (and ref
8680                (not (equal ref "")))
8681           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8682             (gnus-message 1 "Couldn't find parent"))
8683         (gnus-message 1 "No references in article %d"
8684                       (gnus-summary-article-number))
8685         (setq error t))
8686       (decf n))
8687     (gnus-summary-position-point)
8688     n))
8689
8690 (defun gnus-summary-refer-references ()
8691   "Fetch all articles mentioned in the References header.
8692 Return the number of articles fetched."
8693   (interactive)
8694   (let ((ref (mail-header-references (gnus-summary-article-header)))
8695         (current (gnus-summary-article-number))
8696         (n 0))
8697     (if (or (not ref)
8698             (equal ref ""))
8699         (error "No References in the current article")
8700       ;; For each Message-ID in the References header...
8701       (while (string-match "<[^>]*>" ref)
8702         (incf n)
8703         ;; ... fetch that article.
8704         (gnus-summary-refer-article
8705          (prog1 (match-string 0 ref)
8706            (setq ref (substring ref (match-end 0))))))
8707       (gnus-summary-goto-subject current)
8708       (gnus-summary-position-point)
8709       n)))
8710
8711 (defun gnus-summary-refer-thread (&optional limit)
8712   "Fetch all articles in the current thread.
8713 If LIMIT (the numerical prefix), fetch that many old headers instead
8714 of what's specified by the `gnus-refer-thread-limit' variable."
8715   (interactive "P")
8716   (let ((id (mail-header-id (gnus-summary-article-header)))
8717         (limit (if limit (prefix-numeric-value limit)
8718                  gnus-refer-thread-limit)))
8719     (unless (eq gnus-fetch-old-headers 'invisible)
8720       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8721       ;; Retrieve the headers and read them in.
8722       (if (eq (if (numberp limit)
8723                   (gnus-retrieve-headers
8724                    (list (min
8725                           (+ (mail-header-number
8726                               (gnus-summary-article-header))
8727                              limit)
8728                           gnus-newsgroup-end))
8729                    gnus-newsgroup-name (* limit 2))
8730                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8731                 ;; headers.
8732                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8733                                        gnus-newsgroup-name limit))
8734               'nov)
8735           (gnus-build-all-threads)
8736         (error "Can't fetch thread from back ends that don't support NOV"))
8737       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8738     (gnus-summary-limit-include-thread id)))
8739
8740 (defun gnus-summary-refer-article (message-id)
8741   "Fetch an article specified by MESSAGE-ID."
8742   (interactive "sMessage-ID: ")
8743   (when (and (stringp message-id)
8744              (not (zerop (length message-id))))
8745     (setq message-id (gnus-replace-in-string message-id " " ""))
8746     ;; Construct the correct Message-ID if necessary.
8747     ;; Suggested by tale@pawl.rpi.edu.
8748     (unless (string-match "^<" message-id)
8749       (setq message-id (concat "<" message-id)))
8750     (unless (string-match ">$" message-id)
8751       (setq message-id (concat message-id ">")))
8752     ;; People often post MIDs from URLs, so unhex it:
8753     (unless (string-match "@" message-id)
8754       (setq message-id (gnus-url-unhex-string message-id)))
8755     (let* ((header (gnus-id-to-header message-id))
8756            (sparse (and header
8757                         (gnus-summary-article-sparse-p
8758                          (mail-header-number header))
8759                         (memq (mail-header-number header)
8760                               gnus-newsgroup-limit)))
8761            number)
8762       (cond
8763        ;; If the article is present in the buffer we just go to it.
8764        ((and header
8765              (or (not (gnus-summary-article-sparse-p
8766                        (mail-header-number header)))
8767                  sparse))
8768         (prog1
8769             (gnus-summary-goto-article
8770              (mail-header-number header) nil t)
8771           (when sparse
8772             (gnus-summary-update-article (mail-header-number header)))))
8773        (t
8774         ;; We fetch the article.
8775         (catch 'found
8776           (dolist (gnus-override-method (gnus-refer-article-methods))
8777             (when (and (gnus-check-server gnus-override-method)
8778                        ;; Fetch the header,
8779                        (setq number (gnus-summary-insert-subject message-id)))
8780               ;; and display the article.
8781               (gnus-summary-select-article nil nil nil number)
8782               (throw 'found t)))
8783           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8784
8785 (defun gnus-refer-article-methods ()
8786   "Return a list of referable methods."
8787   (cond
8788    ;; No method, so we default to current and native.
8789    ((null gnus-refer-article-method)
8790     (list gnus-current-select-method gnus-select-method))
8791    ;; Current.
8792    ((eq 'current gnus-refer-article-method)
8793     (list gnus-current-select-method))
8794    ;; List of select methods.
8795    ((not (and (symbolp (car gnus-refer-article-method))
8796               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8797     (let (out)
8798       (dolist (method gnus-refer-article-method)
8799         (push (if (eq 'current method)
8800                   gnus-current-select-method
8801                 method)
8802               out))
8803       (nreverse out)))
8804    ;; One single select method.
8805    (t
8806     (list gnus-refer-article-method))))
8807
8808 (defun gnus-summary-edit-parameters ()
8809   "Edit the group parameters of the current group."
8810   (interactive)
8811   (gnus-group-edit-group gnus-newsgroup-name 'params))
8812
8813 (defun gnus-summary-customize-parameters ()
8814   "Customize the group parameters of the current group."
8815   (interactive)
8816   (gnus-group-customize gnus-newsgroup-name))
8817
8818 (defun gnus-summary-enter-digest-group (&optional force)
8819   "Enter an nndoc group based on the current article.
8820 If FORCE, force a digest interpretation.  If not, try
8821 to guess what the document format is."
8822   (interactive "P")
8823   (let ((conf gnus-current-window-configuration))
8824     (save-window-excursion
8825       (save-excursion
8826         (let (gnus-article-prepare-hook
8827               gnus-display-mime-function
8828               gnus-break-pages)
8829           (gnus-summary-select-article))))
8830     (setq gnus-current-window-configuration conf)
8831     (let* ((name (format "%s-%d"
8832                          (gnus-group-prefixed-name
8833                           gnus-newsgroup-name (list 'nndoc ""))
8834                          (with-current-buffer gnus-summary-buffer
8835                            gnus-current-article)))
8836            (ogroup gnus-newsgroup-name)
8837            (params (append (gnus-info-params (gnus-get-info ogroup))
8838                            (list (cons 'to-group ogroup))
8839                            (list (cons 'parent-group ogroup))
8840                            (list (cons 'save-article-group ogroup))))
8841            (case-fold-search t)
8842            (buf (current-buffer))
8843            dig to-address)
8844       (save-excursion
8845         (set-buffer gnus-original-article-buffer)
8846         ;; Have the digest group inherit the main mail address of
8847         ;; the parent article.
8848         (when (setq to-address (or (gnus-fetch-field "reply-to")
8849                                    (gnus-fetch-field "from")))
8850           (setq params
8851                 (append
8852                  (list (cons 'to-address
8853                              (funcall gnus-decode-encoded-address-function
8854                                       to-address))))))
8855         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8856         (insert-buffer-substring gnus-original-article-buffer)
8857         ;; Remove lines that may lead nndoc to misinterpret the
8858         ;; document type.
8859         (narrow-to-region
8860          (goto-char (point-min))
8861          (or (search-forward "\n\n" nil t) (point)))
8862         (goto-char (point-min))
8863         (delete-matching-lines "^Path:\\|^From ")
8864         (widen))
8865       (unwind-protect
8866           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8867                     (gnus-newsgroup-ephemeral-ignored-charsets
8868                      gnus-newsgroup-ignored-charsets))
8869                 (gnus-group-read-ephemeral-group
8870                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8871                               (nndoc-article-type
8872                                ,(if force 'mbox 'guess)))
8873                  t nil nil nil
8874                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8875                                                         "ADAPT")))))
8876               ;; Make all postings to this group go to the parent group.
8877               (nconc (gnus-info-params (gnus-get-info name))
8878                      params)
8879             ;; Couldn't select this doc group.
8880             (switch-to-buffer buf)
8881             (gnus-set-global-variables)
8882             (gnus-configure-windows 'summary)
8883             (gnus-message 3 "Article couldn't be entered?"))
8884         (kill-buffer dig)))))
8885
8886 (defun gnus-summary-read-document (n)
8887   "Open a new group based on the current article(s).
8888 This will allow you to read digests and other similar
8889 documents as newsgroups.
8890 Obeys the standard process/prefix convention."
8891   (interactive "P")
8892   (let* ((ogroup gnus-newsgroup-name)
8893          (params (append (gnus-info-params (gnus-get-info ogroup))
8894                          (list (cons 'to-group ogroup))))
8895          group egroup groups vgroup)
8896     (dolist (article (gnus-summary-work-articles n))
8897       (setq group (format "%s-%d" gnus-newsgroup-name article))
8898       (gnus-summary-remove-process-mark article)
8899       (when (gnus-summary-display-article article)
8900         (save-excursion
8901           (with-temp-buffer
8902             (insert-buffer-substring gnus-original-article-buffer)
8903             ;; Remove some headers that may lead nndoc to make
8904             ;; the wrong guess.
8905             (message-narrow-to-head)
8906             (goto-char (point-min))
8907             (delete-matching-lines "^Path:\\|^From ")
8908             (widen)
8909             (if (setq egroup
8910                       (gnus-group-read-ephemeral-group
8911                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8912                                      (nndoc-article-type guess))
8913                        t nil t))
8914                 (progn
8915             ;; Make all postings to this group go to the parent group.
8916                   (nconc (gnus-info-params (gnus-get-info egroup))
8917                          params)
8918                   (push egroup groups))
8919               ;; Couldn't select this doc group.
8920               (gnus-error 3 "Article couldn't be entered"))))))
8921     ;; Now we have selected all the documents.
8922     (cond
8923      ((not groups)
8924       (error "None of the articles could be interpreted as documents"))
8925      ((gnus-group-read-ephemeral-group
8926        (setq vgroup (format
8927                      "nnvirtual:%s-%s" gnus-newsgroup-name
8928                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8929        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8930        t
8931        (cons (current-buffer) 'summary)))
8932      (t
8933       (error "Couldn't select virtual nndoc group")))))
8934
8935 (defun gnus-summary-isearch-article (&optional regexp-p)
8936   "Do incremental search forward on the current article.
8937 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8938   (interactive "P")
8939   (gnus-summary-select-article)
8940   (gnus-configure-windows 'article)
8941   (gnus-eval-in-buffer-window gnus-article-buffer
8942     (save-restriction
8943       (widen)
8944       (isearch-forward regexp-p))))
8945
8946 (defun gnus-summary-repeat-search-article-forward ()
8947   "Repeat the previous search forwards."
8948   (interactive)
8949   (unless gnus-last-search-regexp
8950     (error "No previous search"))
8951   (gnus-summary-search-article-forward gnus-last-search-regexp))
8952
8953 (defun gnus-summary-repeat-search-article-backward ()
8954   "Repeat the previous search backwards."
8955   (interactive)
8956   (unless gnus-last-search-regexp
8957     (error "No previous search"))
8958   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8959
8960 (defun gnus-summary-search-article-forward (regexp &optional backward)
8961   "Search for an article containing REGEXP forward.
8962 If BACKWARD, search backward instead."
8963   (interactive
8964    (list (read-string
8965           (format "Search article %s (regexp%s): "
8966                   (if current-prefix-arg "backward" "forward")
8967                   (if gnus-last-search-regexp
8968                       (concat ", default " gnus-last-search-regexp)
8969                     "")))
8970          current-prefix-arg))
8971   (if (string-equal regexp "")
8972       (setq regexp (or gnus-last-search-regexp ""))
8973     (setq gnus-last-search-regexp regexp)
8974     (setq gnus-article-before-search gnus-current-article))
8975   ;; Intentionally set gnus-last-article.
8976   (setq gnus-last-article gnus-article-before-search)
8977   (let ((gnus-last-article gnus-last-article))
8978     (if (gnus-summary-search-article regexp backward)
8979         (gnus-summary-show-thread)
8980       (signal 'search-failed (list regexp)))))
8981
8982 (defun gnus-summary-search-article-backward (regexp)
8983   "Search for an article containing REGEXP backward."
8984   (interactive
8985    (list (read-string
8986           (format "Search article backward (regexp%s): "
8987                   (if gnus-last-search-regexp
8988                       (concat ", default " gnus-last-search-regexp)
8989                     "")))))
8990   (gnus-summary-search-article-forward regexp 'backward))
8991
8992 (defun gnus-summary-search-article (regexp &optional backward)
8993   "Search for an article containing REGEXP.
8994 Optional argument BACKWARD means do search for backward.
8995 `gnus-select-article-hook' is not called during the search."
8996   ;; We have to require this here to make sure that the following
8997   ;; dynamic binding isn't shadowed by autoloading.
8998   (require 'gnus-async)
8999   (require 'gnus-art)
9000   (let ((gnus-select-article-hook nil)  ;Disable hook.
9001         (gnus-article-prepare-hook nil)
9002         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9003         (gnus-use-article-prefetch nil)
9004         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9005         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9006         (gnus-visual nil)
9007         (gnus-keep-backlog nil)
9008         (gnus-break-pages nil)
9009         (gnus-summary-display-arrow nil)
9010         (gnus-updated-mode-lines nil)
9011         (gnus-auto-center-summary nil)
9012         (sum (current-buffer))
9013         (gnus-display-mime-function nil)
9014         (found nil)
9015         point)
9016     (gnus-save-hidden-threads
9017       (gnus-summary-select-article)
9018       (set-buffer gnus-article-buffer)
9019       (goto-char (window-point (get-buffer-window (current-buffer))))
9020       (when backward
9021         (forward-line -1))
9022       (while (not found)
9023         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9024         (if (if backward
9025                 (re-search-backward regexp nil t)
9026               (re-search-forward regexp nil t))
9027             ;; We found the regexp.
9028             (progn
9029               (setq found 'found)
9030               (beginning-of-line)
9031               (set-window-start
9032                (get-buffer-window (current-buffer))
9033                (point))
9034               (forward-line 1)
9035               (set-window-point
9036                (get-buffer-window (current-buffer))
9037                (point))
9038               (set-buffer sum)
9039               (setq point (point)))
9040           ;; We didn't find it, so we go to the next article.
9041           (set-buffer sum)
9042           (setq found 'not)
9043           (while (eq found 'not)
9044             (if (not (if backward (gnus-summary-find-prev)
9045                        (gnus-summary-find-next)))
9046                 ;; No more articles.
9047                 (setq found t)
9048               ;; Select the next article and adjust point.
9049               (unless (gnus-summary-article-sparse-p
9050                        (gnus-summary-article-number))
9051                 (setq found nil)
9052                 (gnus-summary-select-article)
9053                 (set-buffer gnus-article-buffer)
9054                 (widen)
9055                 (goto-char (if backward (point-max) (point-min))))))))
9056       (gnus-message 7 ""))
9057     ;; Return whether we found the regexp.
9058     (when (eq found 'found)
9059       (goto-char point)
9060       (gnus-summary-show-thread)
9061       (gnus-summary-goto-subject gnus-current-article)
9062       (gnus-summary-position-point)
9063       t)))
9064
9065 (defun gnus-find-matching-articles (header regexp)
9066   "Return a list of all articles that match REGEXP on HEADER.
9067 This search includes all articles in the current group that Gnus has
9068 fetched headers for, whether they are displayed or not."
9069   (let ((articles nil)
9070         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9071         (case-fold-search t))
9072     (dolist (header gnus-newsgroup-headers)
9073       (when (string-match regexp (funcall func header))
9074         (push (mail-header-number header) articles)))
9075     (nreverse articles)))
9076
9077 (defun gnus-summary-find-matching (header regexp &optional backward unread
9078                                           not-case-fold not-matching)
9079   "Return a list of all articles that match REGEXP on HEADER.
9080 The search stars on the current article and goes forwards unless
9081 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9082 If UNREAD is non-nil, only unread articles will
9083 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9084 in the comparisons. If NOT-MATCHING, return a list of all articles that
9085 not match REGEXP on HEADER."
9086   (let ((case-fold-search (not not-case-fold))
9087         articles d func)
9088     (if (consp header)
9089         (if (eq (car header) 'extra)
9090             (setq func
9091                   `(lambda (h)
9092                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9093                          "")))
9094           (error "%s is an invalid header" header))
9095       (unless (fboundp (intern (concat "mail-header-" header)))
9096         (error "%s is not a valid header" header))
9097       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9098     (dolist (d (if (eq backward 'all)
9099                    gnus-newsgroup-data
9100                  (gnus-data-find-list
9101                   (gnus-summary-article-number)
9102                   (gnus-data-list backward))))
9103       (when (and (or (not unread)       ; We want all articles...
9104                      (gnus-data-unread-p d)) ; Or just unreads.
9105                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9106                  (if not-matching
9107                      (not (string-match
9108                            regexp
9109                            (funcall func (gnus-data-header d))))
9110                    (string-match regexp
9111                                  (funcall func (gnus-data-header d)))))
9112         (push (gnus-data-number d) articles))) ; Success!
9113     (nreverse articles)))
9114
9115 (defun gnus-summary-execute-command (header regexp command &optional backward)
9116   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9117 If HEADER is an empty string (or nil), the match is done on the entire
9118 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9119   (interactive
9120    (list (let ((completion-ignore-case t))
9121            (completing-read
9122             "Header name: "
9123             (mapcar (lambda (header) (list (format "%s" header)))
9124                     (append
9125                      '("Number" "Subject" "From" "Lines" "Date"
9126                        "Message-ID" "Xref" "References" "Body")
9127                      gnus-extra-headers))
9128             nil 'require-match))
9129          (read-string "Regexp: ")
9130          (read-key-sequence "Command: ")
9131          current-prefix-arg))
9132   (when (equal header "Body")
9133     (setq header ""))
9134   ;; Hidden thread subtrees must be searched as well.
9135   (gnus-summary-show-all-threads)
9136   ;; We don't want to change current point nor window configuration.
9137   (save-excursion
9138     (save-window-excursion
9139       (let (gnus-visual
9140             gnus-treat-strip-trailing-blank-lines
9141             gnus-treat-strip-leading-blank-lines
9142             gnus-treat-strip-multiple-blank-lines
9143             gnus-treat-hide-boring-headers
9144             gnus-treat-fold-newsgroups
9145             gnus-article-prepare-hook)
9146         (gnus-message 6 "Executing %s..." (key-description command))
9147         ;; We'd like to execute COMMAND interactively so as to give arguments.
9148         (gnus-execute header regexp
9149                       `(call-interactively ',(key-binding command))
9150                       backward)
9151         (gnus-message 6 "Executing %s...done" (key-description command))))))
9152
9153 (defun gnus-summary-beginning-of-article ()
9154   "Scroll the article back to the beginning."
9155   (interactive)
9156   (gnus-summary-select-article)
9157   (gnus-configure-windows 'article)
9158   (gnus-eval-in-buffer-window gnus-article-buffer
9159     (widen)
9160     (goto-char (point-min))
9161     (when gnus-break-pages
9162       (gnus-narrow-to-page))))
9163
9164 (defun gnus-summary-end-of-article ()
9165   "Scroll to the end of the article."
9166   (interactive)
9167   (gnus-summary-select-article)
9168   (gnus-configure-windows 'article)
9169   (gnus-eval-in-buffer-window gnus-article-buffer
9170     (widen)
9171     (goto-char (point-max))
9172     (recenter -3)
9173     (when gnus-break-pages
9174       (when (re-search-backward page-delimiter nil t)
9175         (narrow-to-region (match-end 0) (point-max)))
9176       (gnus-narrow-to-page))))
9177
9178 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9179   "Truncate to LEN and quote all \"(\"'s in STRING."
9180   (gnus-replace-in-string (if (and len (> (length string) len))
9181                               (substring string 0 len)
9182                             string)
9183                           "[()]" "\\\\\\&"))
9184
9185 (defun gnus-summary-print-article (&optional filename n)
9186   "Generate and print a PostScript image of the process-marked (mail) articles.
9187
9188 If used interactively, print the current article if none are
9189 process-marked.  With prefix arg, prompt the user for the name of the
9190 file to save in.
9191
9192 When used from Lisp, accept two optional args FILENAME and N.  N means
9193 to print the next N articles.  If N is negative, print the N previous
9194 articles.  If N is nil and articles have been marked with the process
9195 mark, print these instead.
9196
9197 If the optional first argument FILENAME is nil, send the image to the
9198 printer.  If FILENAME is a string, save the PostScript image in a file with
9199 that name.  If FILENAME is a number, prompt the user for the name of the file
9200 to save in."
9201   (interactive (list (ps-print-preprint current-prefix-arg)))
9202   (dolist (article (gnus-summary-work-articles n))
9203     (gnus-summary-select-article nil nil 'pseudo article)
9204     (gnus-eval-in-buffer-window gnus-article-buffer
9205       (gnus-print-buffer))
9206     (gnus-summary-remove-process-mark article))
9207   (ps-despool filename))
9208
9209 (defun gnus-print-buffer ()
9210   (let ((buffer (generate-new-buffer " *print*")))
9211     (unwind-protect
9212         (progn
9213           (copy-to-buffer buffer (point-min) (point-max))
9214           (set-buffer buffer)
9215           (gnus-remove-text-with-property 'gnus-decoration)
9216           (when (gnus-visual-p 'article-highlight 'highlight)
9217             ;; Copy-to-buffer doesn't copy overlay.  So redo
9218             ;; highlight.
9219             (let ((gnus-article-buffer buffer))
9220               (gnus-article-highlight-citation t)
9221               (gnus-article-highlight-signature)
9222               (gnus-article-emphasize)
9223               (gnus-article-delete-invisible-text)))
9224           (let ((ps-left-header
9225                  (list
9226                   (concat "("
9227                           (gnus-summary-print-truncate-and-quote
9228                            (mail-header-subject gnus-current-headers)
9229                            66) ")")
9230                   (concat "("
9231                           (gnus-summary-print-truncate-and-quote
9232                            (mail-header-from gnus-current-headers)
9233                            45) ")")))
9234                 (ps-right-header
9235                  (list
9236                   "/pagenumberstring load"
9237                   (concat "("
9238                           (mail-header-date gnus-current-headers) ")"))))
9239             (gnus-run-hooks 'gnus-ps-print-hook)
9240             (save-excursion
9241               (if window-system
9242                   (ps-spool-buffer-with-faces)
9243                 (ps-spool-buffer)))))
9244       (kill-buffer buffer))))
9245
9246 (defun gnus-summary-show-article (&optional arg)
9247   "Force redisplaying of the current article.
9248 If ARG (the prefix) is a number, show the article with the charset
9249 defined in `gnus-summary-show-article-charset-alist', or the charset
9250 input.
9251 If ARG (the prefix) is non-nil and not a number, show the raw article
9252 without any article massaging functions being run.  Normally, the key
9253 strokes are `C-u g'."
9254   (interactive "P")
9255   (cond
9256    ((numberp arg)
9257     (gnus-summary-show-article t)
9258     (let ((gnus-newsgroup-charset
9259            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9260                (mm-read-coding-system
9261                 "View as charset: " ;; actually it is coding system.
9262                 (with-current-buffer gnus-article-buffer
9263                   (mm-detect-coding-region (point) (point-max))))))
9264           (gnus-newsgroup-ignored-charsets 'gnus-all))
9265       (gnus-summary-select-article nil 'force)
9266       (let ((deps gnus-newsgroup-dependencies)
9267             head header lines)
9268         (save-excursion
9269           (set-buffer gnus-original-article-buffer)
9270           (save-restriction
9271             (message-narrow-to-head)
9272             (setq head (buffer-string))
9273             (goto-char (point-min))
9274             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9275               (goto-char (point-max))
9276               (widen)
9277               (setq lines (1- (count-lines (point) (point-max))))))
9278           (with-temp-buffer
9279             (insert (format "211 %d Article retrieved.\n"
9280                             (cdr gnus-article-current)))
9281             (insert head)
9282             (if lines (insert (format "Lines: %d\n" lines)))
9283             (insert ".\n")
9284             (let ((nntp-server-buffer (current-buffer)))
9285               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9286         (gnus-data-set-header
9287          (gnus-data-find (cdr gnus-article-current))
9288          header)
9289         (gnus-summary-update-article-line
9290          (cdr gnus-article-current) header)
9291         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9292           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9293    ((not arg)
9294     ;; Select the article the normal way.
9295     (gnus-summary-select-article nil 'force))
9296    (t
9297     ;; We have to require this here to make sure that the following
9298     ;; dynamic binding isn't shadowed by autoloading.
9299     (require 'gnus-async)
9300     (require 'gnus-art)
9301     ;; Bind the article treatment functions to nil.
9302     (let ((gnus-have-all-headers t)
9303           gnus-article-prepare-hook
9304           gnus-article-decode-hook
9305           gnus-display-mime-function
9306           gnus-break-pages)
9307       ;; Destroy any MIME parts.
9308       (when (gnus-buffer-live-p gnus-article-buffer)
9309         (save-excursion
9310           (set-buffer gnus-article-buffer)
9311           (mm-destroy-parts gnus-article-mime-handles)
9312           ;; Set it to nil for safety reason.
9313           (setq gnus-article-mime-handle-alist nil)
9314           (setq gnus-article-mime-handles nil)))
9315       (gnus-summary-select-article nil 'force))))
9316   (gnus-summary-goto-subject gnus-current-article)
9317   (gnus-summary-position-point))
9318
9319 (defun gnus-summary-show-raw-article ()
9320   "Show the raw article without any article massaging functions being run."
9321   (interactive)
9322   (gnus-summary-show-article t))
9323
9324 (defun gnus-summary-verbose-headers (&optional arg)
9325   "Toggle permanent full header display.
9326 If ARG is a positive number, turn header display on.
9327 If ARG is a negative number, turn header display off."
9328   (interactive "P")
9329   (setq gnus-show-all-headers
9330         (cond ((or (not (numberp arg))
9331                    (zerop arg))
9332                (not gnus-show-all-headers))
9333               ((natnump arg)
9334                t)))
9335   (gnus-summary-show-article))
9336
9337 (defun gnus-summary-toggle-header (&optional arg)
9338   "Show the headers if they are hidden, or hide them if they are shown.
9339 If ARG is a positive number, show the entire header.
9340 If ARG is a negative number, hide the unwanted header lines."
9341   (interactive "P")
9342   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9343                      (get-buffer-window gnus-article-buffer t))))
9344     (with-current-buffer gnus-article-buffer
9345       (widen)
9346       (article-narrow-to-head)
9347       (let* ((buffer-read-only nil)
9348              (inhibit-point-motion-hooks t)
9349              (hidden (if (numberp arg)
9350                          (>= arg 0)
9351                        (or (not (looking-at "[^ \t\n]+:"))
9352                            (gnus-article-hidden-text-p 'headers))))
9353              s e)
9354         (delete-region (point-min) (point-max))
9355         (with-current-buffer gnus-original-article-buffer
9356           (goto-char (setq s (point-min)))
9357           (setq e (if (search-forward "\n\n" nil t)
9358                       (1- (point))
9359                     (point-max))))
9360         (insert-buffer-substring gnus-original-article-buffer s e)
9361         (run-hooks 'gnus-article-decode-hook)
9362         (if hidden
9363             (let ((gnus-treat-hide-headers nil)
9364                   (gnus-treat-hide-boring-headers nil))
9365               (gnus-delete-wash-type 'headers)
9366               (gnus-treat-article 'head))
9367           (gnus-treat-article 'head))
9368         (widen)
9369         (if window
9370             (set-window-start window (goto-char (point-min))))
9371         (if gnus-break-pages
9372             (gnus-narrow-to-page)
9373           (when (gnus-visual-p 'page-marker)
9374             (let ((buffer-read-only nil))
9375               (gnus-remove-text-with-property 'gnus-prev)
9376               (gnus-remove-text-with-property 'gnus-next))))
9377         (gnus-set-mode-line 'article)))))
9378
9379 (defun gnus-summary-show-all-headers ()
9380   "Make all header lines visible."
9381   (interactive)
9382   (gnus-summary-toggle-header 1))
9383
9384 (defun gnus-summary-caesar-message (&optional arg)
9385   "Caesar rotate the current article by 13.
9386 With a non-numerical prefix, also rotate headers.  A numerical
9387 prefix specifies how many places to rotate each letter forward."
9388   (interactive "P")
9389   (gnus-summary-select-article)
9390   (let ((mail-header-separator ""))
9391     (gnus-eval-in-buffer-window gnus-article-buffer
9392       (save-restriction
9393         (widen)
9394         (let ((start (window-start))
9395               buffer-read-only)
9396           (if (equal arg '(4))
9397               (message-caesar-buffer-body nil t)
9398             (message-caesar-buffer-body arg))
9399           (set-window-start (get-buffer-window (current-buffer)) start)))))
9400   ;; Create buttons and stuff...
9401   (gnus-treat-article nil))
9402
9403 (defun gnus-summary-idna-message (&optional arg)
9404   "Decode IDNA encoded domain names in the current articles.
9405 IDNA encoded domain names looks like `xn--bar'.  If a string
9406 remain unencoded after running this function, it is likely an
9407 invalid IDNA string (`xn--bar' is invalid).
9408
9409 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9410 installed for this command to work."
9411   (interactive "P")
9412   (if (not (and (condition-case nil (require 'idna)
9413                   (file-error))
9414                 (mm-coding-system-p 'utf-8)
9415                 (executable-find (symbol-value 'idna-program))))
9416       (gnus-message
9417        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9418     (gnus-summary-select-article)
9419     (let ((mail-header-separator ""))
9420       (gnus-eval-in-buffer-window gnus-article-buffer
9421         (save-restriction
9422           (widen)
9423           (let ((start (window-start))
9424                 buffer-read-only)
9425             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9426               (replace-match (idna-to-unicode (match-string 1))))
9427             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9428
9429 (defun gnus-summary-morse-message (&optional arg)
9430   "Morse decode the current article."
9431   (interactive "P")
9432   (gnus-summary-select-article)
9433   (let ((mail-header-separator ""))
9434     (gnus-eval-in-buffer-window gnus-article-buffer
9435       (save-excursion
9436         (save-restriction
9437           (widen)
9438           (let ((pos (window-start))
9439                 buffer-read-only)
9440             (goto-char (point-min))
9441             (when (message-goto-body)
9442               (gnus-narrow-to-body))
9443             (goto-char (point-min))
9444             (while (search-forward "·" (point-max) t)
9445               (replace-match "."))
9446             (unmorse-region (point-min) (point-max))
9447             (widen)
9448             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9449
9450 (defun gnus-summary-stop-page-breaking ()
9451   "Stop page breaking in the current article."
9452   (interactive)
9453   (gnus-summary-select-article)
9454   (gnus-eval-in-buffer-window gnus-article-buffer
9455     (widen)
9456     (when (gnus-visual-p 'page-marker)
9457       (let ((buffer-read-only nil))
9458         (gnus-remove-text-with-property 'gnus-prev)
9459         (gnus-remove-text-with-property 'gnus-next))
9460       (setq gnus-page-broken nil))))
9461
9462 (defun gnus-summary-move-article (&optional n to-newsgroup
9463                                             select-method action)
9464   "Move the current article to a different newsgroup.
9465 If N is a positive number, move the N next articles.
9466 If N is a negative number, move the N previous articles.
9467 If N is nil and any articles have been marked with the process mark,
9468 move those articles instead.
9469 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9470 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9471 re-spool using this method.
9472
9473 When called interactively with TO-NEWSGROUP being nil, the value of
9474 the variable `gnus-move-split-methods' is used for finding a default
9475 for the target newsgroup.
9476
9477 For this function to work, both the current newsgroup and the
9478 newsgroup that you want to move to have to support the `request-move'
9479 and `request-accept' functions.
9480
9481 ACTION can be either `move' (the default), `crosspost' or `copy'."
9482   (interactive "P")
9483   (unless action
9484     (setq action 'move))
9485   ;; Check whether the source group supports the required functions.
9486   (cond ((and (eq action 'move)
9487               (not (gnus-check-backend-function
9488                     'request-move-article gnus-newsgroup-name)))
9489          (error "The current group does not support article moving"))
9490         ((and (eq action 'crosspost)
9491               (not (gnus-check-backend-function
9492                     'request-replace-article gnus-newsgroup-name)))
9493          (error "The current group does not support article editing")))
9494   (let ((articles (gnus-summary-work-articles n))
9495         (prefix (if (gnus-check-backend-function
9496                      'request-move-article gnus-newsgroup-name)
9497                     (funcall gnus-move-group-prefix-function
9498                              gnus-newsgroup-name)
9499                   ""))
9500         (names '((move "Move" "Moving")
9501                  (copy "Copy" "Copying")
9502                  (crosspost "Crosspost" "Crossposting")))
9503         (copy-buf (save-excursion
9504                     (nnheader-set-temp-buffer " *copy article*")))
9505         art-group to-method new-xref article to-groups
9506         articles-to-update-marks encoded)
9507     (unless (assq action names)
9508       (error "Unknown action %s" action))
9509     ;; Read the newsgroup name.
9510     (when (and (not to-newsgroup)
9511                (not select-method))
9512       (if (and gnus-move-split-methods
9513                (not
9514                 (and (memq gnus-current-article articles)
9515                      (gnus-buffer-live-p gnus-original-article-buffer))))
9516           ;; When `gnus-move-split-methods' is non-nil, we have to
9517           ;; select an article to give `gnus-read-move-group-name' an
9518           ;; opportunity to suggest an appropriate default.  However,
9519           ;; we needn't render or mark the article.
9520           (let ((gnus-display-mime-function nil)
9521                 (gnus-article-prepare-hook nil)
9522                 (gnus-mark-article-hook nil))
9523             (gnus-summary-select-article nil nil nil (car articles))))
9524       (setq to-newsgroup (gnus-read-move-group-name
9525                           (cadr (assq action names))
9526                           (symbol-value
9527                            (intern (format "gnus-current-%s-group" action)))
9528                           articles prefix)
9529             encoded to-newsgroup
9530             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9531       (set (intern (format "gnus-current-%s-group" action))
9532            (mm-decode-coding-string
9533             to-newsgroup
9534             (gnus-group-name-charset to-method to-newsgroup))))
9535     (unless to-method
9536       (setq to-method (or select-method
9537                           (gnus-server-to-method
9538                            (gnus-group-method to-newsgroup)))))
9539     (setq to-newsgroup (or encoded
9540                            (mm-encode-coding-string
9541                             to-newsgroup
9542                             (gnus-group-name-charset to-method to-newsgroup))))
9543     ;; Check the method we are to move this article to...
9544     (unless (gnus-check-backend-function
9545              'request-accept-article (car to-method))
9546       (error "%s does not support article copying" (car to-method)))
9547     (unless (gnus-check-server to-method)
9548       (error "Can't open server %s" (car to-method)))
9549     (gnus-message 6 "%s to %s: %s..."
9550                   (caddr (assq action names))
9551                   (or (car select-method)
9552                       (gnus-group-decoded-name to-newsgroup))
9553                   articles)
9554     (while articles
9555       (setq article (pop articles))
9556       (setq
9557        art-group
9558        (cond
9559         ;; Move the article.
9560         ((eq action 'move)
9561          ;; Remove this article from future suppression.
9562          (gnus-dup-unsuppress-article article)
9563          (let* ((from-method (gnus-find-method-for-group
9564                               gnus-newsgroup-name))
9565                 (to-method (gnus-find-method-for-group
9566                             to-newsgroup))
9567                 (move-is-internal (gnus-method-equal from-method to-method)))
9568            (gnus-request-move-article
9569             article                     ; Article to move
9570             gnus-newsgroup-name         ; From newsgroup
9571             (nth 1 (gnus-find-method-for-group
9572                     gnus-newsgroup-name)) ; Server
9573             (list 'gnus-request-accept-article
9574                   to-newsgroup (list 'quote select-method)
9575                   (not articles) t)     ; Accept form
9576             (not articles)              ; Only save nov last time
9577             move-is-internal)))         ; is this move internal?
9578         ;; Copy the article.
9579         ((eq action 'copy)
9580          (save-excursion
9581            (set-buffer copy-buf)
9582            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9583              (save-restriction
9584                (nnheader-narrow-to-headers)
9585                (dolist (hdr gnus-copy-article-ignored-headers)
9586                  (message-remove-header hdr t)))
9587              (gnus-request-accept-article
9588               to-newsgroup select-method (not articles) t))))
9589         ;; Crosspost the article.
9590         ((eq action 'crosspost)
9591          (let ((xref (message-tokenize-header
9592                       (mail-header-xref (gnus-summary-article-header article))
9593                       " ")))
9594            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9595                                   ":" (number-to-string article)))
9596            (unless xref
9597              (setq xref (list (system-name))))
9598            (setq new-xref
9599                  (concat
9600                   (mapconcat 'identity
9601                              (delete "Xref:" (delete new-xref xref))
9602                              " ")
9603                   " " new-xref))
9604            (save-excursion
9605              (set-buffer copy-buf)
9606              ;; First put the article in the destination group.
9607              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9608              (when (consp (setq art-group
9609                                 (gnus-request-accept-article
9610                                  to-newsgroup select-method (not articles) t)))
9611                (setq new-xref (concat new-xref " " (car art-group)
9612                                       ":"
9613                                       (number-to-string (cdr art-group))))
9614                ;; Now we have the new Xrefs header, so we insert
9615                ;; it and replace the new article.
9616                (nnheader-replace-header "Xref" new-xref)
9617                (gnus-request-replace-article
9618                 (cdr art-group) to-newsgroup (current-buffer) t)
9619                art-group))))))
9620       (cond
9621        ((not art-group)
9622         (gnus-message 1 "Couldn't %s article %s: %s"
9623                       (cadr (assq action names)) article
9624                       (nnheader-get-report (car to-method))))
9625        ((eq art-group 'junk)
9626         (when (eq action 'move)
9627           (gnus-summary-mark-article article gnus-canceled-mark)
9628           (gnus-message 4 "Deleted article %s" article)
9629           ;; run the delete hook
9630           (run-hook-with-args 'gnus-summary-article-delete-hook
9631                               action
9632                               (gnus-data-header
9633                                (assoc article (gnus-data-list nil)))
9634                               gnus-newsgroup-name nil
9635                               select-method)))
9636        (t
9637         (let* ((pto-group (gnus-group-prefixed-name
9638                            (car art-group) to-method))
9639                (info (gnus-get-info pto-group))
9640                (to-group (gnus-info-group info))
9641                to-marks)
9642           ;; Update the group that has been moved to.
9643           (when (and info
9644                      (memq action '(move copy)))
9645             (unless (member to-group to-groups)
9646               (push to-group to-groups))
9647
9648             (unless (memq article gnus-newsgroup-unreads)
9649               (push 'read to-marks)
9650               (gnus-info-set-read
9651                info (gnus-add-to-range (gnus-info-read info)
9652                                        (list (cdr art-group)))))
9653
9654             ;; See whether the article is to be put in the cache.
9655             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9656                              gnus-article-mark-lists
9657                            (delete '(expirable . expire)
9658                                    (copy-sequence gnus-article-mark-lists))))
9659                   (to-article (cdr art-group)))
9660
9661               ;; Enter the article into the cache in the new group,
9662               ;; if that is required.
9663               (when gnus-use-cache
9664                 (gnus-cache-possibly-enter-article
9665                  to-group to-article
9666                  (memq article gnus-newsgroup-marked)
9667                  (memq article gnus-newsgroup-dormant)
9668                  (memq article gnus-newsgroup-unreads)))
9669
9670               (when gnus-preserve-marks
9671                 ;; Copy any marks over to the new group.
9672                 (when (and (equal to-group gnus-newsgroup-name)
9673                            (not (memq article gnus-newsgroup-unreads)))
9674                   ;; Mark this article as read in this group.
9675                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9676                   (setcdr (gnus-active to-group) to-article)
9677                   (setcdr gnus-newsgroup-active to-article))
9678
9679                 (while marks
9680                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9681                     (when (memq article (symbol-value
9682                                          (intern (format "gnus-newsgroup-%s"
9683                                                          (caar marks)))))
9684                       (push (cdar marks) to-marks)
9685                       ;; If the other group is the same as this group,
9686                       ;; then we have to add the mark to the list.
9687                       (when (equal to-group gnus-newsgroup-name)
9688                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9689                              (cons to-article
9690                                    (symbol-value
9691                                     (intern (format "gnus-newsgroup-%s"
9692                                                     (caar marks)))))))
9693                       ;; Copy the marks to other group.
9694                       (gnus-add-marked-articles
9695                        to-group (cdar marks) (list to-article) info)))
9696                   (setq marks (cdr marks)))
9697
9698                 (gnus-request-set-mark
9699                  to-group (list (list (list to-article) 'add to-marks))))
9700
9701               (gnus-dribble-enter
9702                (concat "(gnus-group-set-info '"
9703                        (gnus-prin1-to-string (gnus-get-info to-group))
9704                        ")"))))
9705
9706           ;; Update the Xref header in this article to point to
9707           ;; the new crossposted article we have just created.
9708           (when (eq action 'crosspost)
9709             (save-excursion
9710               (set-buffer copy-buf)
9711               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9712               (nnheader-replace-header "Xref" new-xref)
9713               (gnus-request-replace-article
9714                article gnus-newsgroup-name (current-buffer) t)))
9715
9716           ;; run the move/copy/crosspost/respool hook
9717           (run-hook-with-args 'gnus-summary-article-move-hook
9718                               action
9719                               (gnus-data-header
9720                                (assoc article (gnus-data-list nil)))
9721                               gnus-newsgroup-name
9722                               to-newsgroup
9723                               select-method))
9724
9725         ;;;!!!Why is this necessary?
9726         (set-buffer gnus-summary-buffer)
9727
9728         (gnus-summary-goto-subject article)
9729         (when (eq action 'move)
9730           (gnus-summary-mark-article article gnus-canceled-mark))))
9731       (push article articles-to-update-marks))
9732
9733     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9734     ;; Re-activate all groups that have been moved to.
9735     (save-excursion
9736       (set-buffer gnus-group-buffer)
9737       (let ((gnus-group-marked to-groups))
9738         (gnus-group-get-new-news-this-group nil t)))
9739
9740     (gnus-kill-buffer copy-buf)
9741     (gnus-summary-position-point)
9742     (gnus-set-mode-line 'summary)))
9743
9744 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9745   "Copy the current article to some other group.
9746 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9747 When called interactively, if TO-NEWSGROUP is nil, use the value of
9748 the variable `gnus-move-split-methods' for finding a default target
9749 newsgroup.
9750 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9751 re-spool using this method."
9752   (interactive "P")
9753   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9754
9755 (defun gnus-summary-crosspost-article (&optional n)
9756   "Crosspost the current article to some other group."
9757   (interactive "P")
9758   (gnus-summary-move-article n nil nil 'crosspost))
9759
9760 (defcustom gnus-summary-respool-default-method nil
9761   "Default method type for respooling an article.
9762 If nil, use to the current newsgroup method."
9763   :type 'symbol
9764   :group 'gnus-summary-mail)
9765
9766 (defcustom gnus-summary-display-while-building nil
9767   "If non-nil, show and update the summary buffer as it's being built.
9768 If the value is t, update the buffer after every line is inserted.  If
9769 the value is an integer (N), update the display every N lines."
9770   :version "22.1"
9771   :group 'gnus-thread
9772   :type '(choice (const :tag "off" nil)
9773                  number
9774                  (const :tag "frequently" t)))
9775
9776 (defun gnus-summary-respool-article (&optional n method)
9777   "Respool the current article.
9778 The article will be squeezed through the mail spooling process again,
9779 which means that it will be put in some mail newsgroup or other
9780 depending on `nnmail-split-methods'.
9781 If N is a positive number, respool the N next articles.
9782 If N is a negative number, respool the N previous articles.
9783 If N is nil and any articles have been marked with the process mark,
9784 respool those articles instead.
9785
9786 Respooling can be done both from mail groups and \"real\" newsgroups.
9787 In the former case, the articles in question will be moved from the
9788 current group into whatever groups they are destined to.  In the
9789 latter case, they will be copied into the relevant groups."
9790   (interactive
9791    (list current-prefix-arg
9792          (let* ((methods (gnus-methods-using 'respool))
9793                 (methname
9794                  (symbol-name (or gnus-summary-respool-default-method
9795                                   (car (gnus-find-method-for-group
9796                                         gnus-newsgroup-name)))))
9797                 (method
9798                  (gnus-completing-read-with-default
9799                   methname "Backend to use when respooling"
9800                   methods nil t nil 'gnus-mail-method-history))
9801                 ms)
9802            (cond
9803             ((zerop (length (setq ms (gnus-servers-using-backend
9804                                       (intern method)))))
9805              (list (intern method) ""))
9806             ((= 1 (length ms))
9807              (car ms))
9808             (t
9809              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9810                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9811                            ms-alist))))))))
9812   (unless method
9813     (error "No method given for respooling"))
9814   (if (assoc (symbol-name
9815               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9816              (gnus-methods-using 'respool))
9817       (gnus-summary-move-article n nil method)
9818     (gnus-summary-copy-article n nil method)))
9819
9820 (defun gnus-summary-import-article (file &optional edit)
9821   "Import an arbitrary file into a mail newsgroup."
9822   (interactive "fImport file: \nP")
9823   (let ((group gnus-newsgroup-name)
9824         (now (current-time))
9825         atts lines group-art)
9826     (unless (gnus-check-backend-function 'request-accept-article group)
9827       (error "%s does not support article importing" group))
9828     (or (file-readable-p file)
9829         (not (file-regular-p file))
9830         (error "Can't read %s" file))
9831     (save-excursion
9832       (set-buffer (gnus-get-buffer-create " *import file*"))
9833       (erase-buffer)
9834       (nnheader-insert-file-contents file)
9835       (goto-char (point-min))
9836       (if (nnheader-article-p)
9837           (save-restriction
9838             (goto-char (point-min))
9839             (search-forward "\n\n" nil t)
9840             (narrow-to-region (point-min) (1- (point)))
9841             (goto-char (point-min))
9842             (unless (re-search-forward "^date:" nil t)
9843               (goto-char (point-max))
9844               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9845        ;; This doesn't look like an article, so we fudge some headers.
9846         (setq atts (file-attributes file)
9847               lines (count-lines (point-min) (point-max)))
9848         (insert "From: " (read-string "From: ") "\n"
9849                 "Subject: " (read-string "Subject: ") "\n"
9850                 "Date: " (message-make-date (nth 5 atts)) "\n"
9851                 "Message-ID: " (message-make-message-id) "\n"
9852                 "Lines: " (int-to-string lines) "\n"
9853                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9854       (setq group-art (gnus-request-accept-article group nil t))
9855       (kill-buffer (current-buffer)))
9856     (setq gnus-newsgroup-active (gnus-activate-group group))
9857     (forward-line 1)
9858     (gnus-summary-goto-article (cdr group-art) nil t)
9859     (when edit
9860       (gnus-summary-edit-article))))
9861
9862 (defun gnus-summary-create-article ()
9863   "Create an article in a mail newsgroup."
9864   (interactive)
9865   (let ((group gnus-newsgroup-name)
9866         (now (current-time))
9867         group-art)
9868     (unless (gnus-check-backend-function 'request-accept-article group)
9869       (error "%s does not support article importing" group))
9870     (save-excursion
9871       (set-buffer (gnus-get-buffer-create " *import file*"))
9872       (erase-buffer)
9873       (goto-char (point-min))
9874       ;; This doesn't look like an article, so we fudge some headers.
9875       (insert "From: " (read-string "From: ") "\n"
9876               "Subject: " (read-string "Subject: ") "\n"
9877               "Date: " (message-make-date now) "\n"
9878               "Message-ID: " (message-make-message-id) "\n")
9879       (setq group-art (gnus-request-accept-article group nil t))
9880       (kill-buffer (current-buffer)))
9881     (setq gnus-newsgroup-active (gnus-activate-group group))
9882     (forward-line 1)
9883     (gnus-summary-goto-article (cdr group-art) nil t)
9884     (gnus-summary-edit-article)))
9885
9886 (defun gnus-summary-article-posted-p ()
9887   "Say whether the current (mail) article is available from news as well.
9888 This will be the case if the article has both been mailed and posted."
9889   (interactive)
9890   (let ((id (mail-header-references (gnus-summary-article-header)))
9891         (gnus-override-method (car (gnus-refer-article-methods))))
9892     (if (gnus-request-head id "")
9893         (gnus-message 2 "The current message was found on %s"
9894                       gnus-override-method)
9895       (gnus-message 2 "The current message couldn't be found on %s"
9896                     gnus-override-method)
9897       nil)))
9898
9899 (defun gnus-summary-expire-articles (&optional now)
9900   "Expire all articles that are marked as expirable in the current group."
9901   (interactive)
9902   (when (and (not gnus-group-is-exiting-without-update-p)
9903              (gnus-check-backend-function
9904               'request-expire-articles gnus-newsgroup-name))
9905     ;; This backend supports expiry.
9906     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9907            (expirable (if total
9908                           (progn
9909                             ;; We need to update the info for
9910                             ;; this group for `gnus-list-of-read-articles'
9911                             ;; to give us the right answer.
9912                             (gnus-run-hooks 'gnus-exit-group-hook)
9913                             (gnus-summary-update-info)
9914                             (gnus-list-of-read-articles gnus-newsgroup-name))
9915                         (setq gnus-newsgroup-expirable
9916                               (sort gnus-newsgroup-expirable '<))))
9917            (expiry-wait (if now 'immediate
9918                           (gnus-group-find-parameter
9919                            gnus-newsgroup-name 'expiry-wait)))
9920            (nnmail-expiry-target
9921             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9922                 nnmail-expiry-target))
9923            es)
9924       (when expirable
9925         ;; There are expirable articles in this group, so we run them
9926         ;; through the expiry process.
9927         (gnus-message 6 "Expiring articles...")
9928         (unless (gnus-check-group gnus-newsgroup-name)
9929           (error "Can't open server for %s" gnus-newsgroup-name))
9930         ;; The list of articles that weren't expired is returned.
9931         (save-excursion
9932           (if expiry-wait
9933               (let ((nnmail-expiry-wait-function nil)
9934                     (nnmail-expiry-wait expiry-wait))
9935                 (setq es (gnus-request-expire-articles
9936                           expirable gnus-newsgroup-name)))
9937             (setq es (gnus-request-expire-articles
9938                       expirable gnus-newsgroup-name)))
9939           (unless total
9940             (setq gnus-newsgroup-expirable es))
9941           ;; We go through the old list of expirable, and mark all
9942           ;; really expired articles as nonexistent.
9943           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9944             (let ((gnus-use-cache nil))
9945               (dolist (article expirable)
9946                 (when (and (not (memq article es))
9947                            (gnus-data-find article))
9948                   (gnus-summary-mark-article article gnus-canceled-mark)
9949                   (run-hook-with-args 'gnus-summary-article-expire-hook
9950                                       'delete
9951                                       (gnus-data-header
9952                                        (assoc article (gnus-data-list nil)))
9953                                       gnus-newsgroup-name
9954                                       nil
9955                                       nil))))))
9956         (gnus-message 6 "Expiring articles...done")))))
9957
9958 (defun gnus-summary-expire-articles-now ()
9959   "Expunge all expirable articles in the current group.
9960 This means that *all* articles that are marked as expirable will be
9961 deleted forever, right now."
9962   (interactive)
9963   (or gnus-expert-user
9964       (gnus-yes-or-no-p
9965        "Are you really, really sure you want to delete all expirable messages? ")
9966       (error "Phew!"))
9967   (gnus-summary-expire-articles t))
9968
9969 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9970 (defun gnus-summary-delete-article (&optional n)
9971   "Delete the N next (mail) articles.
9972 This command actually deletes articles.  This is not a marking
9973 command.  The article will disappear forever from your life, never to
9974 return.
9975
9976 If N is negative, delete backwards.
9977 If N is nil and articles have been marked with the process mark,
9978 delete these instead.
9979
9980 If `gnus-novice-user' is non-nil you will be asked for
9981 confirmation before the articles are deleted."
9982   (interactive "P")
9983   (unless (gnus-check-backend-function 'request-expire-articles
9984                                        gnus-newsgroup-name)
9985     (error "The current newsgroup does not support article deletion"))
9986   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9987     (error "Couldn't open server"))
9988   ;; Compute the list of articles to delete.
9989   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9990         (nnmail-expiry-target 'delete)
9991         not-deleted)
9992     (if (and gnus-novice-user
9993              (not (gnus-yes-or-no-p
9994                    (format "Do you really want to delete %s forever? "
9995                            (if (> (length articles) 1)
9996                                (format "these %s articles" (length articles))
9997                              "this article")))))
9998         ()
9999       ;; Delete the articles.
10000       (setq not-deleted (gnus-request-expire-articles
10001                          articles gnus-newsgroup-name 'force))
10002       (while articles
10003         (gnus-summary-remove-process-mark (car articles))
10004         ;; The backend might not have been able to delete the article
10005         ;; after all.
10006         (unless (memq (car articles) not-deleted)
10007           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10008         (let* ((article (car articles))
10009                (ghead  (gnus-data-header
10010                                     (assoc article (gnus-data-list nil)))))
10011           (run-hook-with-args 'gnus-summary-article-delete-hook
10012                               'delete ghead gnus-newsgroup-name nil
10013                               nil))
10014         (setq articles (cdr articles)))
10015       (when not-deleted
10016         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10017     (gnus-summary-position-point)
10018     (gnus-set-mode-line 'summary)
10019     not-deleted))
10020
10021 (defun gnus-summary-edit-article (&optional arg)
10022   "Edit the current article.
10023 This will have permanent effect only in mail groups.
10024 If ARG is nil, edit the decoded articles.
10025 If ARG is 1, edit the raw articles.
10026 If ARG is 2, edit the raw articles even in read-only groups.
10027 If ARG is 3, edit the articles with the current handles.
10028 Otherwise, allow editing of articles even in read-only
10029 groups."
10030   (interactive "P")
10031   (let (force raw current-handles)
10032     (cond
10033      ((null arg))
10034      ((eq arg 1)
10035       (setq raw t))
10036      ((eq arg 2)
10037       (setq raw t
10038             force t))
10039      ((eq arg 3)
10040       (setq current-handles
10041             (and (gnus-buffer-live-p gnus-article-buffer)
10042                  (with-current-buffer gnus-article-buffer
10043                    (prog1
10044                        gnus-article-mime-handles
10045                      (setq gnus-article-mime-handles nil))))))
10046      (t
10047       (setq force t)))
10048     (when (and raw (not force)
10049                (member gnus-newsgroup-name '("nndraft:delayed"
10050                                              "nndraft:drafts"
10051                                              "nndraft:queue")))
10052       (error "Can't edit the raw article in group %s"
10053              gnus-newsgroup-name))
10054     (save-excursion
10055       (set-buffer gnus-summary-buffer)
10056       (let ((mail-parse-charset gnus-newsgroup-charset)
10057             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10058         (gnus-set-global-variables)
10059         (when (and (not force)
10060                    (gnus-group-read-only-p))
10061           (error "The current newsgroup does not support article editing"))
10062         (gnus-summary-show-article t)
10063         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10064           (with-current-buffer gnus-article-buffer
10065             (mm-enable-multibyte)))
10066         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10067             (setq raw t))
10068         (gnus-article-edit-article
10069          (if raw 'ignore
10070            `(lambda ()
10071               (let ((mbl mml-buffer-list))
10072                 (setq mml-buffer-list nil)
10073                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10074                   (mime-to-mml ,'current-handles))
10075                 (let ((mbl1 mml-buffer-list))
10076                   (setq mml-buffer-list mbl)
10077                   (set (make-local-variable 'mml-buffer-list) mbl1))
10078                 (gnus-make-local-hook 'kill-buffer-hook)
10079                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10080          `(lambda (no-highlight)
10081             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10082                   (message-options message-options)
10083                   (message-options-set-recipient)
10084                   (mail-parse-ignored-charsets
10085                    ',gnus-newsgroup-ignored-charsets)
10086                   (rfc2047-header-encoding-alist
10087                    ',(let ((charset (gnus-group-name-charset
10088                                      (gnus-find-method-for-group
10089                                       gnus-newsgroup-name)
10090                                      gnus-newsgroup-name)))
10091                        (append (list (cons "Newsgroups" charset)
10092                                      (cons "Followup-To" charset)
10093                                      (cons "Xref" charset))
10094                                rfc2047-header-encoding-alist))))
10095               ,(if (not raw) '(progn
10096                                 (mml-to-mime)
10097                                 (mml-destroy-buffers)
10098                                 (remove-hook 'kill-buffer-hook
10099                                              'mml-destroy-buffers t)
10100                                 (kill-local-variable 'mml-buffer-list)))
10101               (gnus-summary-edit-article-done
10102                ,(or (mail-header-references gnus-current-headers) "")
10103                ,(gnus-group-read-only-p)
10104                ,gnus-summary-buffer no-highlight))))))))
10105
10106 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10107
10108 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10109                                                  no-highlight)
10110   "Make edits to the current article permanent."
10111   (interactive)
10112   (save-excursion
10113    ;; The buffer restriction contains the entire article if it exists.
10114     (when (article-goto-body)
10115       (let ((lines (count-lines (point) (point-max)))
10116             (length (- (point-max) (point)))
10117             (case-fold-search t)
10118             (body (copy-marker (point))))
10119         (goto-char (point-min))
10120         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10121           (delete-region (match-beginning 1) (match-end 1))
10122           (insert (number-to-string length)))
10123         (goto-char (point-min))
10124         (when (re-search-forward
10125                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10126           (delete-region (match-beginning 1) (match-end 1))
10127           (insert (number-to-string length)))
10128         (goto-char (point-min))
10129         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10130           (delete-region (match-beginning 1) (match-end 1))
10131           (insert (number-to-string lines))))))
10132   ;; Replace the article.
10133   (let ((buf (current-buffer)))
10134     (with-temp-buffer
10135       (insert-buffer-substring buf)
10136
10137       (if (and (not read-only)
10138                (not (gnus-request-replace-article
10139                      (cdr gnus-article-current) (car gnus-article-current)
10140                      (current-buffer) t)))
10141           (error "Couldn't replace article")
10142         ;; Update the summary buffer.
10143         (if (and references
10144                  (equal (message-tokenize-header references " ")
10145                         (message-tokenize-header
10146                          (or (message-fetch-field "references") "") " ")))
10147             ;; We only have to update this line.
10148             (save-excursion
10149               (save-restriction
10150                 (message-narrow-to-head)
10151                 (let ((head (buffer-substring-no-properties
10152                              (point-min) (point-max)))
10153                       header)
10154                   (with-temp-buffer
10155                     (insert (format "211 %d Article retrieved.\n"
10156                                     (cdr gnus-article-current)))
10157                     (insert head)
10158                     (insert ".\n")
10159                     (let ((nntp-server-buffer (current-buffer)))
10160                       (setq header (car (gnus-get-newsgroup-headers
10161                                          nil t))))
10162                     (save-excursion
10163                       (set-buffer gnus-summary-buffer)
10164                       (gnus-data-set-header
10165                        (gnus-data-find (cdr gnus-article-current))
10166                        header)
10167                       (gnus-summary-update-article-line
10168                        (cdr gnus-article-current) header)
10169                       (if (gnus-summary-goto-subject
10170                            (cdr gnus-article-current) nil t)
10171                           (gnus-summary-update-secondary-mark
10172                            (cdr gnus-article-current))))))))
10173           ;; Update threads.
10174           (set-buffer (or buffer gnus-summary-buffer))
10175           (gnus-summary-update-article (cdr gnus-article-current))
10176           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10177               (gnus-summary-update-secondary-mark
10178                (cdr gnus-article-current))))
10179         ;; Prettify the article buffer again.
10180         (unless no-highlight
10181           (save-excursion
10182             (set-buffer gnus-article-buffer)
10183             ;;;!!! Fix this -- article should be rehighlighted.
10184             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10185             (set-buffer gnus-original-article-buffer)
10186             (gnus-request-article
10187              (cdr gnus-article-current)
10188              (car gnus-article-current) (current-buffer))))
10189         ;; Prettify the summary buffer line.
10190         (when (gnus-visual-p 'summary-highlight 'highlight)
10191           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10192
10193 (defun gnus-summary-edit-wash (key)
10194   "Perform editing command KEY in the article buffer."
10195   (interactive
10196    (list
10197     (progn
10198       (message "%s" (concat (this-command-keys) "- "))
10199       (read-char))))
10200   (message "")
10201   (gnus-summary-edit-article)
10202   (execute-kbd-macro (concat (this-command-keys) key))
10203   (gnus-article-edit-done))
10204
10205 ;;; Respooling
10206
10207 (defun gnus-summary-respool-query (&optional silent trace)
10208   "Query where the respool algorithm would put this article."
10209   (interactive)
10210   (let (gnus-mark-article-hook)
10211     (gnus-summary-select-article)
10212     (save-excursion
10213       (set-buffer gnus-original-article-buffer)
10214       (let ((groups (nnmail-article-group 'identity trace)))
10215         (unless silent
10216           (if groups
10217               (message "This message would go to %s"
10218                        (mapconcat 'car groups ", "))
10219             (message "This message would go to no groups"))
10220           groups)))))
10221
10222 (defun gnus-summary-respool-trace ()
10223   "Trace where the respool algorithm would put this article.
10224 Display a buffer showing all fancy splitting patterns which matched."
10225   (interactive)
10226   (gnus-summary-respool-query nil t))
10227
10228 ;; Summary marking commands.
10229
10230 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10231   "Mark articles which has the same subject as read, and then select the next.
10232 If UNMARK is positive, remove any kind of mark.
10233 If UNMARK is negative, tick articles."
10234   (interactive "P")
10235   (when unmark
10236     (setq unmark (prefix-numeric-value unmark)))
10237   (let ((count
10238          (gnus-summary-mark-same-subject
10239           (gnus-summary-article-subject) unmark)))
10240     ;; Select next unread article.  If auto-select-same mode, should
10241     ;; select the first unread article.
10242     (gnus-summary-next-article t (and gnus-auto-select-same
10243                                       (gnus-summary-article-subject)))
10244     (gnus-message 7 "%d article%s marked as %s"
10245                   count (if (= count 1) " is" "s are")
10246                   (if unmark "unread" "read"))))
10247
10248 (defun gnus-summary-kill-same-subject (&optional unmark)
10249   "Mark articles which has the same subject as read.
10250 If UNMARK is positive, remove any kind of mark.
10251 If UNMARK is negative, tick articles."
10252   (interactive "P")
10253   (when unmark
10254     (setq unmark (prefix-numeric-value unmark)))
10255   (let ((count
10256          (gnus-summary-mark-same-subject
10257           (gnus-summary-article-subject) unmark)))
10258     ;; If marked as read, go to next unread subject.
10259     (when (null unmark)
10260       ;; Go to next unread subject.
10261       (gnus-summary-next-subject 1 t))
10262     (gnus-message 7 "%d articles are marked as %s"
10263                   count (if unmark "unread" "read"))))
10264
10265 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10266   "Mark articles with same SUBJECT as read, and return marked number.
10267 If optional argument UNMARK is positive, remove any kinds of marks.
10268 If optional argument UNMARK is negative, mark articles as unread instead."
10269   (let ((count 1))
10270     (save-excursion
10271       (cond
10272        ((null unmark)                   ; Mark as read.
10273         (while (and
10274                 (progn
10275                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10276                   (gnus-summary-show-thread) t)
10277                 (gnus-summary-find-subject subject))
10278           (setq count (1+ count))))
10279        ((> unmark 0)                    ; Tick.
10280         (while (and
10281                 (progn
10282                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10283                   (gnus-summary-show-thread) t)
10284                 (gnus-summary-find-subject subject))
10285           (setq count (1+ count))))
10286        (t                               ; Mark as unread.
10287         (while (and
10288                 (progn
10289                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10290                   (gnus-summary-show-thread) t)
10291                 (gnus-summary-find-subject subject))
10292           (setq count (1+ count)))))
10293       (gnus-set-mode-line 'summary)
10294       ;; Return the number of marked articles.
10295       count)))
10296
10297 (defun gnus-summary-mark-as-processable (n &optional unmark)
10298   "Set the process mark on the next N articles.
10299 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10300 the process mark instead.  The difference between N and the actual
10301 number of articles marked is returned."
10302   (interactive "P")
10303   (if (and (null n) (gnus-region-active-p))
10304       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10305     (setq n (prefix-numeric-value n))
10306     (let ((backward (< n 0))
10307           (n (abs n)))
10308       (while (and
10309               (> n 0)
10310               (if unmark
10311                   (gnus-summary-remove-process-mark
10312                    (gnus-summary-article-number))
10313                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10314               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10315         (setq n (1- n)))
10316       (when (/= 0 n)
10317         (gnus-message 7 "No more articles"))
10318       (gnus-summary-recenter)
10319       (gnus-summary-position-point)
10320       n)))
10321
10322 (defun gnus-summary-unmark-as-processable (n)
10323   "Remove the process mark from the next N articles.
10324 If N is negative, unmark backward instead.  The difference between N and
10325 the actual number of articles unmarked is returned."
10326   (interactive "P")
10327   (gnus-summary-mark-as-processable n t))
10328
10329 (defun gnus-summary-unmark-all-processable ()
10330   "Remove the process mark from all articles."
10331   (interactive)
10332   (save-excursion
10333     (while gnus-newsgroup-processable
10334       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10335   (gnus-summary-position-point))
10336
10337 (defun gnus-summary-add-mark (article type)
10338   "Mark ARTICLE with a mark of TYPE."
10339   (let ((vtype (car (assq type gnus-article-mark-lists)))
10340         var)
10341     (if (not vtype)
10342         (error "No such mark type: %s" type)
10343       (setq var (intern (format "gnus-newsgroup-%s" type)))
10344       (set var (cons article (symbol-value var)))
10345       (if (memq type '(processable cached replied forwarded recent saved))
10346           (gnus-summary-update-secondary-mark article)
10347         ;;; !!! This is bogus.  We should find out what primary
10348         ;;; !!! mark we want to set.
10349         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10350
10351 (defun gnus-summary-mark-as-expirable (n)
10352   "Mark N articles forward as expirable.
10353 If N is negative, mark backward instead.  The difference between N and
10354 the actual number of articles marked is returned."
10355   (interactive "p")
10356   (gnus-summary-mark-forward n gnus-expirable-mark))
10357
10358 (defun gnus-summary-mark-as-spam (n)
10359   "Mark N articles forward as spam.
10360 If N is negative, mark backward instead.  The difference between N and
10361 the actual number of articles marked is returned."
10362   (interactive "p")
10363   (gnus-summary-mark-forward n gnus-spam-mark))
10364
10365 (defun gnus-summary-mark-article-as-replied (article)
10366   "Mark ARTICLE as replied to and update the summary line.
10367 ARTICLE can also be a list of articles."
10368   (interactive (list (gnus-summary-article-number)))
10369   (let ((articles (if (listp article) article (list article))))
10370     (dolist (article articles)
10371       (unless (numberp article)
10372         (error "%s is not a number" article))
10373       (push article gnus-newsgroup-replied)
10374       (let ((buffer-read-only nil))
10375         (when (gnus-summary-goto-subject article nil t)
10376           (gnus-summary-update-secondary-mark article))))))
10377
10378 (defun gnus-summary-mark-article-as-forwarded (article)
10379   "Mark ARTICLE as forwarded and update the summary line.
10380 ARTICLE can also be a list of articles."
10381   (let ((articles (if (listp article) article (list article))))
10382     (dolist (article articles)
10383       (push article gnus-newsgroup-forwarded)
10384       (let ((buffer-read-only nil))
10385         (when (gnus-summary-goto-subject article nil t)
10386           (gnus-summary-update-secondary-mark article))))))
10387
10388 (defun gnus-summary-set-bookmark (article)
10389   "Set a bookmark in current article."
10390   (interactive (list (gnus-summary-article-number)))
10391   (when (or (not (get-buffer gnus-article-buffer))
10392             (not gnus-current-article)
10393             (not gnus-article-current)
10394             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10395     (error "No current article selected"))
10396   ;; Remove old bookmark, if one exists.
10397   (gnus-pull article gnus-newsgroup-bookmarks)
10398   ;; Set the new bookmark, which is on the form
10399   ;; (article-number . line-number-in-body).
10400   (push
10401    (cons article
10402          (with-current-buffer gnus-article-buffer
10403            (count-lines
10404             (min (point)
10405                  (save-excursion
10406                    (article-goto-body)
10407                    (point)))
10408             (point))))
10409    gnus-newsgroup-bookmarks)
10410   (gnus-message 6 "A bookmark has been added to the current article."))
10411
10412 (defun gnus-summary-remove-bookmark (article)
10413   "Remove the bookmark from the current article."
10414   (interactive (list (gnus-summary-article-number)))
10415   ;; Remove old bookmark, if one exists.
10416   (if (not (assq article gnus-newsgroup-bookmarks))
10417       (gnus-message 6 "No bookmark in current article.")
10418     (gnus-pull article gnus-newsgroup-bookmarks)
10419     (gnus-message 6 "Removed bookmark.")))
10420
10421 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10422 (defun gnus-summary-mark-as-dormant (n)
10423   "Mark N articles forward as dormant.
10424 If N is negative, mark backward instead.  The difference between N and
10425 the actual number of articles marked is returned."
10426   (interactive "p")
10427   (gnus-summary-mark-forward n gnus-dormant-mark))
10428
10429 (defun gnus-summary-set-process-mark (article)
10430   "Set the process mark on ARTICLE and update the summary line."
10431   (setq gnus-newsgroup-processable
10432         (cons article
10433               (delq article gnus-newsgroup-processable)))
10434   (when (gnus-summary-goto-subject article)
10435     (gnus-summary-show-thread)
10436     (gnus-summary-goto-subject article)
10437     (gnus-summary-update-secondary-mark article)))
10438
10439 (defun gnus-summary-remove-process-mark (&rest articles)
10440   "Remove the process mark from ARTICLES and update the summary line."
10441   (dolist (article articles)
10442     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10443     (when (gnus-summary-goto-subject article)
10444       (gnus-summary-show-thread)
10445       (gnus-summary-goto-subject article)
10446       (gnus-summary-update-secondary-mark article)))
10447   t)
10448
10449 (defun gnus-summary-set-saved-mark (article)
10450   "Set the process mark on ARTICLE and update the summary line."
10451   (push article gnus-newsgroup-saved)
10452   (when (gnus-summary-goto-subject article)
10453     (gnus-summary-update-secondary-mark article)))
10454
10455 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10456   "Mark N articles as read forwards.
10457 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10458 The difference between N and the actual number of articles marked is
10459 returned.
10460 If NO-EXPIRE, auto-expiry will be inhibited."
10461   (interactive "p")
10462   (gnus-summary-show-thread)
10463   (let ((backward (< n 0))
10464         (gnus-summary-goto-unread
10465          (and gnus-summary-goto-unread
10466               (not (eq gnus-summary-goto-unread 'never))
10467               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10468                                     gnus-ticked-mark gnus-dormant-mark)))))
10469         (n (abs n))
10470         (mark (or mark gnus-del-mark)))
10471     (while (and (> n 0)
10472                 (gnus-summary-mark-article nil mark no-expire)
10473                 (zerop (gnus-summary-next-subject
10474                         (if backward -1 1)
10475                         (and gnus-summary-goto-unread
10476                              (not (eq gnus-summary-goto-unread 'never)))
10477                         t)))
10478       (setq n (1- n)))
10479     (when (/= 0 n)
10480       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10481     (gnus-summary-recenter)
10482     (gnus-summary-position-point)
10483     (gnus-set-mode-line 'summary)
10484     n))
10485
10486 (defun gnus-summary-mark-article-as-read (mark)
10487   "Mark the current article quickly as read with MARK."
10488   (let ((article (gnus-summary-article-number)))
10489     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10490     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10491     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10492     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10493     (push (cons article mark) gnus-newsgroup-reads)
10494     ;; Possibly remove from cache, if that is used.
10495     (when gnus-use-cache
10496       (gnus-cache-enter-remove-article article))
10497     ;; Allow the backend to change the mark.
10498     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10499     ;; Check for auto-expiry.
10500     (when (and gnus-newsgroup-auto-expire
10501                (memq mark gnus-auto-expirable-marks))
10502       (setq mark gnus-expirable-mark)
10503       ;; Let the backend know about the mark change.
10504       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10505       (push article gnus-newsgroup-expirable))
10506     ;; Set the mark in the buffer.
10507     (gnus-summary-update-mark mark 'unread)
10508     t))
10509
10510 (defun gnus-summary-mark-article-as-unread (mark)
10511   "Mark the current article quickly as unread with MARK."
10512   (let* ((article (gnus-summary-article-number))
10513          (old-mark (gnus-summary-article-mark article)))
10514     ;; Allow the backend to change the mark.
10515     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10516     (if (eq mark old-mark)
10517         t
10518       (if (<= article 0)
10519           (progn
10520             (gnus-error 1 "Can't mark negative article numbers")
10521             nil)
10522         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10523         (setq gnus-newsgroup-spam-marked
10524               (delq article gnus-newsgroup-spam-marked))
10525         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10526         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10527         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10528         (cond ((= mark gnus-ticked-mark)
10529                (setq gnus-newsgroup-marked
10530                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10531                                               article)))
10532               ((= mark gnus-spam-mark)
10533                (setq gnus-newsgroup-spam-marked
10534                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10535                                               article)))
10536               ((= mark gnus-dormant-mark)
10537                (setq gnus-newsgroup-dormant
10538                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10539                                               article)))
10540               (t
10541                (setq gnus-newsgroup-unreads
10542                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10543                                               article))))
10544         (gnus-pull article gnus-newsgroup-reads)
10545
10546         ;; See whether the article is to be put in the cache.
10547         (and gnus-use-cache
10548              (vectorp (gnus-summary-article-header article))
10549              (save-excursion
10550                (gnus-cache-possibly-enter-article
10551                 gnus-newsgroup-name article
10552                 (= mark gnus-ticked-mark)
10553                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10554
10555         ;; Fix the mark.
10556         (gnus-summary-update-mark mark 'unread)
10557         t))))
10558
10559 (defun gnus-summary-mark-article (&optional article mark no-expire)
10560   "Mark ARTICLE with MARK.  MARK can be any character.
10561 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10562 `??' (dormant) and `?E' (expirable).
10563 If MARK is nil, then the default character `?r' is used.
10564 If ARTICLE is nil, then the article on the current line will be
10565 marked.
10566 If NO-EXPIRE, auto-expiry will be inhibited."
10567   ;; The mark might be a string.
10568   (when (stringp mark)
10569     (setq mark (aref mark 0)))
10570   ;; If no mark is given, then we check auto-expiring.
10571   (when (null mark)
10572     (setq mark gnus-del-mark))
10573   (when (and (not no-expire)
10574              gnus-newsgroup-auto-expire
10575              (memq mark gnus-auto-expirable-marks))
10576     (setq mark gnus-expirable-mark))
10577   (let ((article (or article (gnus-summary-article-number)))
10578         (old-mark (gnus-summary-article-mark article)))
10579     ;; Allow the backend to change the mark.
10580     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10581     (if (eq mark old-mark)
10582         t
10583       (unless article
10584         (error "No article on current line"))
10585       (if (not (if (or (= mark gnus-unread-mark)
10586                        (= mark gnus-ticked-mark)
10587                        (= mark gnus-spam-mark)
10588                        (= mark gnus-dormant-mark))
10589                    (gnus-mark-article-as-unread article mark)
10590                  (gnus-mark-article-as-read article mark)))
10591           t
10592         ;; See whether the article is to be put in the cache.
10593         (and gnus-use-cache
10594              (not (= mark gnus-canceled-mark))
10595              (vectorp (gnus-summary-article-header article))
10596              (save-excursion
10597                (gnus-cache-possibly-enter-article
10598                 gnus-newsgroup-name article
10599                 (= mark gnus-ticked-mark)
10600                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10601
10602         (when (gnus-summary-goto-subject article nil t)
10603           (let ((buffer-read-only nil))
10604             (gnus-summary-show-thread)
10605             ;; Fix the mark.
10606             (gnus-summary-update-mark mark 'unread)
10607             t))))))
10608
10609 (defun gnus-summary-update-secondary-mark (article)
10610   "Update the secondary (read, process, cache) mark."
10611   (gnus-summary-update-mark
10612    (cond ((memq article gnus-newsgroup-processable)
10613           gnus-process-mark)
10614          ((memq article gnus-newsgroup-cached)
10615           gnus-cached-mark)
10616          ((memq article gnus-newsgroup-replied)
10617           gnus-replied-mark)
10618          ((memq article gnus-newsgroup-forwarded)
10619           gnus-forwarded-mark)
10620          ((memq article gnus-newsgroup-saved)
10621           gnus-saved-mark)
10622          ((memq article gnus-newsgroup-recent)
10623           gnus-recent-mark)
10624          ((memq article gnus-newsgroup-unseen)
10625           gnus-unseen-mark)
10626          (t gnus-no-mark))
10627    'replied)
10628   (when (gnus-visual-p 'summary-highlight 'highlight)
10629     (gnus-run-hooks 'gnus-summary-update-hook))
10630   t)
10631
10632 (defun gnus-summary-update-download-mark (article)
10633   "Update the download mark."
10634   (gnus-summary-update-mark
10635    (cond ((memq article gnus-newsgroup-undownloaded)
10636           gnus-undownloaded-mark)
10637          (gnus-newsgroup-agentized
10638           gnus-downloaded-mark)
10639          (t
10640           gnus-no-mark))
10641    'download)
10642   (gnus-summary-update-line t)
10643   t)
10644
10645 (defun gnus-summary-update-mark (mark type)
10646   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10647         (buffer-read-only nil))
10648     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10649     (when forward
10650       (when (looking-at "\r")
10651         (incf forward))
10652       (when (<= (+ forward (point)) (point-max))
10653         ;; Go to the right position on the line.
10654         (goto-char (+ forward (point)))
10655         ;; Replace the old mark with the new mark.
10656         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10657         ;; Optionally update the marks by some user rule.
10658         (when (eq type 'unread)
10659           (gnus-data-set-mark
10660            (gnus-data-find (gnus-summary-article-number)) mark)
10661           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10662
10663 (defun gnus-mark-article-as-read (article &optional mark)
10664   "Enter ARTICLE in the pertinent lists and remove it from others."
10665   ;; Make the article expirable.
10666   (let ((mark (or mark gnus-del-mark)))
10667     (setq gnus-newsgroup-expirable
10668           (if (= mark gnus-expirable-mark)
10669               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10670             (delq article gnus-newsgroup-expirable)))
10671     ;; Remove from unread and marked lists.
10672     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10673     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10674     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10675     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10676     (push (cons article mark) gnus-newsgroup-reads)
10677     ;; Possibly remove from cache, if that is used.
10678     (when gnus-use-cache
10679       (gnus-cache-enter-remove-article article))
10680     t))
10681
10682 (defun gnus-mark-article-as-unread (article &optional mark)
10683   "Enter ARTICLE in the pertinent lists and remove it from others."
10684   (let ((mark (or mark gnus-ticked-mark)))
10685     (if (<= article 0)
10686         (progn
10687           (gnus-error 1 "Can't mark negative article numbers")
10688           nil)
10689       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10690             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10691             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10692             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10693             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10694
10695       ;; Unsuppress duplicates?
10696       (when gnus-suppress-duplicates
10697         (gnus-dup-unsuppress-article article))
10698
10699       (cond ((= mark gnus-ticked-mark)
10700              (setq gnus-newsgroup-marked
10701                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10702             ((= mark gnus-spam-mark)
10703              (setq gnus-newsgroup-spam-marked
10704                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10705                                             article)))
10706             ((= mark gnus-dormant-mark)
10707              (setq gnus-newsgroup-dormant
10708                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10709             (t
10710              (setq gnus-newsgroup-unreads
10711                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10712       (gnus-pull article gnus-newsgroup-reads)
10713       t)))
10714
10715 (defalias 'gnus-summary-mark-as-unread-forward
10716   'gnus-summary-tick-article-forward)
10717 (make-obsolete 'gnus-summary-mark-as-unread-forward
10718                'gnus-summary-tick-article-forward)
10719 (defun gnus-summary-tick-article-forward (n)
10720   "Tick N articles forwards.
10721 If N is negative, tick backwards instead.
10722 The difference between N and the number of articles ticked is returned."
10723   (interactive "p")
10724   (gnus-summary-mark-forward n gnus-ticked-mark))
10725
10726 (defalias 'gnus-summary-mark-as-unread-backward
10727   'gnus-summary-tick-article-backward)
10728 (make-obsolete 'gnus-summary-mark-as-unread-backward
10729                'gnus-summary-tick-article-backward)
10730 (defun gnus-summary-tick-article-backward (n)
10731   "Tick N articles backwards.
10732 The difference between N and the number of articles ticked is returned."
10733   (interactive "p")
10734   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10735
10736 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10737 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10738 (defun gnus-summary-tick-article (&optional article clear-mark)
10739   "Mark current article as unread.
10740 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10741 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10742   (interactive)
10743   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10744                                        gnus-ticked-mark)))
10745
10746 (defun gnus-summary-mark-as-read-forward (n)
10747   "Mark N articles as read forwards.
10748 If N is negative, mark backwards instead.
10749 The difference between N and the actual number of articles marked is
10750 returned."
10751   (interactive "p")
10752   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10753
10754 (defun gnus-summary-mark-as-read-backward (n)
10755   "Mark the N articles as read backwards.
10756 The difference between N and the actual number of articles marked is
10757 returned."
10758   (interactive "p")
10759   (gnus-summary-mark-forward
10760    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10761
10762 (defun gnus-summary-mark-as-read (&optional article mark)
10763   "Mark current article as read.
10764 ARTICLE specifies the article to be marked as read.
10765 MARK specifies a string to be inserted at the beginning of the line."
10766   (gnus-summary-mark-article article mark))
10767
10768 (defun gnus-summary-clear-mark-forward (n)
10769   "Clear marks from N articles forward.
10770 If N is negative, clear backward instead.
10771 The difference between N and the number of marks cleared is returned."
10772   (interactive "p")
10773   (gnus-summary-mark-forward n gnus-unread-mark))
10774
10775 (defun gnus-summary-clear-mark-backward (n)
10776   "Clear marks from N articles backward.
10777 The difference between N and the number of marks cleared is returned."
10778   (interactive "p")
10779   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10780
10781 (defun gnus-summary-mark-unread-as-read ()
10782   "Intended to be used by `gnus-summary-mark-article-hook'."
10783   (when (memq gnus-current-article gnus-newsgroup-unreads)
10784     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10785
10786 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10787   "Intended to be used by `gnus-summary-mark-article-hook'."
10788   (let ((mark (gnus-summary-article-mark)))
10789     (when (or (gnus-unread-mark-p mark)
10790               (gnus-read-mark-p mark))
10791       (gnus-summary-mark-article gnus-current-article
10792                                  (or new-mark gnus-read-mark)))))
10793
10794 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10795   "Intended to be used by `gnus-summary-mark-article-hook'."
10796   (let ((mark (gnus-summary-article-mark)))
10797     (when (or (gnus-unread-mark-p mark)
10798               (gnus-read-mark-p mark))
10799       (gnus-summary-mark-article (gnus-summary-article-number)
10800                                  (or new-mark gnus-read-mark)))))
10801
10802 (defun gnus-summary-mark-unread-as-ticked ()
10803   "Intended to be used by `gnus-summary-mark-article-hook'."
10804   (when (memq gnus-current-article gnus-newsgroup-unreads)
10805     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10806
10807 (defun gnus-summary-mark-region-as-read (point mark all)
10808   "Mark all unread articles between point and mark as read.
10809 If given a prefix, mark all articles between point and mark as read,
10810 even ticked and dormant ones."
10811   (interactive "r\nP")
10812   (save-excursion
10813     (let (article)
10814       (goto-char point)
10815       (beginning-of-line)
10816       (while (and
10817               (< (point) mark)
10818               (progn
10819                 (when (or all
10820                           (memq (setq article (gnus-summary-article-number))
10821                                 gnus-newsgroup-unreads))
10822                   (gnus-summary-mark-article article gnus-del-mark))
10823                 t)
10824               (gnus-summary-find-next))))))
10825
10826 (defun gnus-summary-mark-below (score mark)
10827   "Mark articles with score less than SCORE with MARK."
10828   (interactive "P\ncMark: ")
10829   (setq score (if score
10830                   (prefix-numeric-value score)
10831                 (or gnus-summary-default-score 0)))
10832   (save-excursion
10833     (set-buffer gnus-summary-buffer)
10834     (goto-char (point-min))
10835     (while
10836         (progn
10837           (and (< (gnus-summary-article-score) score)
10838                (gnus-summary-mark-article nil mark))
10839           (gnus-summary-find-next)))))
10840
10841 (defun gnus-summary-kill-below (&optional score)
10842   "Mark articles with score below SCORE as read."
10843   (interactive "P")
10844   (gnus-summary-mark-below score gnus-killed-mark))
10845
10846 (defun gnus-summary-clear-above (&optional score)
10847   "Clear all marks from articles with score above SCORE."
10848   (interactive "P")
10849   (gnus-summary-mark-above score gnus-unread-mark))
10850
10851 (defun gnus-summary-tick-above (&optional score)
10852   "Tick all articles with score above SCORE."
10853   (interactive "P")
10854   (gnus-summary-mark-above score gnus-ticked-mark))
10855
10856 (defun gnus-summary-mark-above (score mark)
10857   "Mark articles with score over SCORE with MARK."
10858   (interactive "P\ncMark: ")
10859   (setq score (if score
10860                   (prefix-numeric-value score)
10861                 (or gnus-summary-default-score 0)))
10862   (save-excursion
10863     (set-buffer gnus-summary-buffer)
10864     (goto-char (point-min))
10865     (while (and (progn
10866                   (when (> (gnus-summary-article-score) score)
10867                     (gnus-summary-mark-article nil mark))
10868                   t)
10869                 (gnus-summary-find-next)))))
10870
10871 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10872 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10873 (defun gnus-summary-limit-include-expunged (&optional no-error)
10874   "Display all the hidden articles that were expunged for low scores."
10875   (interactive)
10876   (let ((buffer-read-only nil))
10877     (let ((scored gnus-newsgroup-scored)
10878           headers h)
10879       (while scored
10880         (unless (gnus-summary-article-header (caar scored))
10881           (and (setq h (gnus-number-to-header (caar scored)))
10882                (< (cdar scored) gnus-summary-expunge-below)
10883                (push h headers)))
10884         (setq scored (cdr scored)))
10885       (if (not headers)
10886           (when (not no-error)
10887             (error "No expunged articles hidden"))
10888         (goto-char (point-min))
10889         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10890         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10891         (mapcar (lambda (x) (push (mail-header-number x)
10892                                   gnus-newsgroup-limit))
10893                 headers)
10894         (gnus-summary-prepare-unthreaded (nreverse headers))
10895         (goto-char (point-min))
10896         (gnus-summary-position-point)
10897         t))))
10898
10899 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10900   "Mark all unread articles in this newsgroup as read.
10901 If prefix argument ALL is non-nil, ticked and dormant articles will
10902 also be marked as read.
10903 If QUIETLY is non-nil, no questions will be asked.
10904
10905 If TO-HERE is non-nil, it should be a point in the buffer.  All
10906 articles before (after, if REVERSE is set) this point will be marked
10907 as read.
10908
10909 Note that this function will only catch up the unread article
10910 in the current summary buffer limitation.
10911
10912 The number of articles marked as read is returned."
10913   (interactive "P")
10914   (prog1
10915       (save-excursion
10916         (when (or quietly
10917                   (not gnus-interactive-catchup) ;Without confirmation?
10918                   gnus-expert-user
10919                   (gnus-y-or-n-p
10920                    (if all
10921                        "Mark absolutely all articles as read? "
10922                      "Mark all unread articles as read? ")))
10923           (if (and not-mark
10924                    (not gnus-newsgroup-adaptive)
10925                    (not gnus-newsgroup-auto-expire)
10926                    (not gnus-suppress-duplicates)
10927                    (or (not gnus-use-cache)
10928                        (eq gnus-use-cache 'passive)))
10929               (progn
10930                 (when all
10931                   (setq gnus-newsgroup-marked nil
10932                         gnus-newsgroup-spam-marked nil
10933                         gnus-newsgroup-dormant nil))
10934                 (setq gnus-newsgroup-unreads
10935                       (gnus-sorted-nunion
10936                        (gnus-sorted-intersection gnus-newsgroup-unreads
10937                                                  gnus-newsgroup-downloadable)
10938                        (gnus-sorted-difference gnus-newsgroup-unfetched
10939                                                gnus-newsgroup-cached))))
10940             ;; We actually mark all articles as canceled, which we
10941             ;; have to do when using auto-expiry or adaptive scoring.
10942             (gnus-summary-show-all-threads)
10943             (if (and to-here reverse)
10944                 (progn
10945                   (goto-char to-here)
10946                   (gnus-summary-mark-current-read-and-unread-as-read
10947                    gnus-catchup-mark)
10948                   (while (gnus-summary-find-next (not all))
10949                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10950               (when (gnus-summary-first-subject (not all))
10951                 (while (and
10952                         (if to-here (< (point) to-here) t)
10953                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10954                         (gnus-summary-find-next (not all))))))
10955             (gnus-set-mode-line 'summary))
10956           t))
10957     (gnus-summary-position-point)))
10958
10959 (defun gnus-summary-catchup-to-here (&optional all)
10960   "Mark all unticked articles before the current one as read.
10961 If ALL is non-nil, also mark ticked and dormant articles as read."
10962   (interactive "P")
10963   (save-excursion
10964     (gnus-save-hidden-threads
10965       (let ((beg (point)))
10966         ;; We check that there are unread articles.
10967         (when (or all (gnus-summary-find-prev))
10968           (gnus-summary-catchup all t beg)))))
10969   (gnus-summary-position-point))
10970
10971 (defun gnus-summary-catchup-from-here (&optional all)
10972   "Mark all unticked articles after (and including) the current one as read.
10973 If ALL is non-nil, also mark ticked and dormant articles as read."
10974   (interactive "P")
10975   (save-excursion
10976     (gnus-save-hidden-threads
10977       (let ((beg (point)))
10978         ;; We check that there are unread articles.
10979         (when (or all (gnus-summary-find-next))
10980           (gnus-summary-catchup all t beg nil t)))))
10981   (gnus-summary-position-point))
10982
10983 (defun gnus-summary-catchup-all (&optional quietly)
10984   "Mark all articles in this newsgroup as read.
10985 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10986 instead, which marks only unread articles as read."
10987   (interactive "P")
10988   (gnus-summary-catchup t quietly))
10989
10990 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10991   "Mark all unread articles in this group as read, then exit.
10992 If prefix argument ALL is non-nil, all articles are marked as read.
10993 If QUIETLY is non-nil, no questions will be asked."
10994   (interactive "P")
10995   (when (gnus-summary-catchup all quietly nil 'fast)
10996     ;; Select next newsgroup or exit.
10997     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10998              (eq gnus-auto-select-next 'quietly))
10999         (gnus-summary-next-group nil)
11000       (gnus-summary-exit))))
11001
11002 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11003   "Mark all articles in this newsgroup as read, and then exit.
11004 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11005 instead, which marks only unread articles as read."
11006   (interactive "P")
11007   (gnus-summary-catchup-and-exit t quietly))
11008
11009 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11010   "Mark all articles in this group as read and select the next group.
11011 If given a prefix, mark all articles, unread as well as ticked, as
11012 read."
11013   (interactive "P")
11014   (save-excursion
11015     (gnus-summary-catchup all))
11016   (gnus-summary-next-group))
11017
11018 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11019   "Mark all articles in this group as read and select the previous group.
11020 If given a prefix, mark all articles, unread as well as ticked, as
11021 read."
11022   (interactive "P")
11023   (save-excursion
11024     (gnus-summary-catchup all))
11025   (gnus-summary-next-group nil nil t))
11026
11027 ;;;
11028 ;;; with article
11029 ;;;
11030
11031 (defmacro gnus-with-article (article &rest forms)
11032   "Select ARTICLE and perform FORMS in the original article buffer.
11033 Then replace the article with the result."
11034   `(progn
11035      ;; We don't want the article to be marked as read.
11036      (let (gnus-mark-article-hook)
11037        (gnus-summary-select-article t t nil ,article))
11038      (set-buffer gnus-original-article-buffer)
11039      ,@forms
11040      (if (not (gnus-check-backend-function
11041                'request-replace-article (car gnus-article-current)))
11042          (gnus-message 5 "Read-only group; not replacing")
11043        (unless (gnus-request-replace-article
11044                 ,article (car gnus-article-current)
11045                 (current-buffer) t)
11046          (error "Couldn't replace article")))
11047      ;; The cache and backlog have to be flushed somewhat.
11048      (when gnus-keep-backlog
11049        (gnus-backlog-remove-article
11050         (car gnus-article-current) (cdr gnus-article-current)))
11051      (when gnus-use-cache
11052        (gnus-cache-update-article
11053         (car gnus-article-current) (cdr gnus-article-current)))))
11054
11055 (put 'gnus-with-article 'lisp-indent-function 1)
11056 (put 'gnus-with-article 'edebug-form-spec '(form body))
11057
11058 ;; Thread-based commands.
11059
11060 (defun gnus-summary-articles-in-thread (&optional article)
11061   "Return a list of all articles in the current thread.
11062 If ARTICLE is non-nil, return all articles in the thread that starts
11063 with that article."
11064   (let* ((article (or article (gnus-summary-article-number)))
11065          (data (gnus-data-find-list article))
11066          (top-level (gnus-data-level (car data)))
11067          (top-subject
11068           (cond ((null gnus-thread-operation-ignore-subject)
11069                  (gnus-simplify-subject-re
11070                   (mail-header-subject (gnus-data-header (car data)))))
11071                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11072                  (gnus-simplify-subject-fuzzy
11073                   (mail-header-subject (gnus-data-header (car data)))))
11074                 (t nil)))
11075          (end-point (save-excursion
11076                       (if (gnus-summary-go-to-next-thread)
11077                           (point) (point-max))))
11078          articles)
11079     (while (and data
11080                 (< (gnus-data-pos (car data)) end-point))
11081       (when (or (not top-subject)
11082                 (string= top-subject
11083                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11084                              (gnus-simplify-subject-fuzzy
11085                               (mail-header-subject
11086                                (gnus-data-header (car data))))
11087                            (gnus-simplify-subject-re
11088                             (mail-header-subject
11089                              (gnus-data-header (car data)))))))
11090         (push (gnus-data-number (car data)) articles))
11091       (unless (and (setq data (cdr data))
11092                    (> (gnus-data-level (car data)) top-level))
11093         (setq data nil)))
11094     ;; Return the list of articles.
11095     (nreverse articles)))
11096
11097 (defun gnus-summary-rethread-current ()
11098   "Rethread the thread the current article is part of."
11099   (interactive)
11100   (let* ((gnus-show-threads t)
11101          (article (gnus-summary-article-number))
11102          (id (mail-header-id (gnus-summary-article-header)))
11103          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11104     (unless id
11105       (error "No article on the current line"))
11106     (gnus-rebuild-thread id)
11107     (gnus-summary-goto-subject article)))
11108
11109 (defun gnus-summary-reparent-thread ()
11110   "Make the current article child of the marked (or previous) article.
11111
11112 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11113 is non-nil or the Subject: of both articles are the same."
11114   (interactive)
11115   (unless (not (gnus-group-read-only-p))
11116     (error "The current newsgroup does not support article editing"))
11117   (unless (<= (length gnus-newsgroup-processable) 1)
11118     (error "No more than one article may be marked"))
11119   (let ((child (gnus-summary-article-number))
11120         ;; First grab the marked article, otherwise one line up.
11121         (parent (if (not (null gnus-newsgroup-processable))
11122                     (car gnus-newsgroup-processable)
11123                   (save-excursion
11124                     (if (eq (forward-line -1) 0)
11125                         (gnus-summary-article-number)
11126                       (error "Beginning of summary buffer"))))))
11127     (gnus-summary-reparent-children parent (list child))))
11128
11129 (defun gnus-summary-reparent-children (parent children)
11130   "Make PARENT the parent of CHILDREN.
11131 When called interactively, PARENT is the current article and CHILDREN
11132 are the process-marked articles."
11133   (interactive
11134    (list (gnus-summary-article-number)
11135          (gnus-summary-work-articles nil)))
11136   (dolist (child children)
11137     (save-window-excursion
11138       (let ((gnus-article-buffer " *reparent*"))
11139         (unless (not (eq parent child))
11140           (error "An article may not be self-referential"))
11141         (let ((message-id (mail-header-id
11142                            (gnus-summary-article-header parent))))
11143           (unless (and message-id (not (equal message-id "")))
11144             (error "No message-id in desired parent"))
11145           (gnus-with-article child
11146             (save-restriction
11147               (goto-char (point-min))
11148               (message-narrow-to-head)
11149               (if (re-search-forward "^References: " nil t)
11150                   (progn
11151                     (re-search-forward "^[^ \t]" nil t)
11152                     (forward-line -1)
11153                     (end-of-line)
11154                     (insert " " message-id))
11155                 (insert "References: " message-id "\n"))))
11156           (set-buffer gnus-summary-buffer)
11157           (gnus-summary-unmark-all-processable)
11158           (gnus-summary-update-article child)
11159           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11160             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11161           (gnus-summary-rethread-current)
11162           (gnus-message 3 "Article %d is now the child of article %d"
11163                         child parent))))))
11164
11165 (defun gnus-summary-toggle-threads (&optional arg)
11166   "Toggle showing conversation threads.
11167 If ARG is positive number, turn showing conversation threads on."
11168   (interactive "P")
11169   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11170     (setq gnus-show-threads
11171           (if (null arg) (not gnus-show-threads)
11172             (> (prefix-numeric-value arg) 0)))
11173     (gnus-summary-prepare)
11174     (gnus-summary-goto-subject current)
11175     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11176     (gnus-summary-position-point)))
11177
11178 (defun gnus-summary-show-all-threads ()
11179   "Show all threads."
11180   (interactive)
11181   (save-excursion
11182     (let ((buffer-read-only nil))
11183       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11184   (gnus-summary-position-point))
11185
11186 (defun gnus-summary-show-thread ()
11187   "Show thread subtrees.
11188 Returns nil if no thread was there to be shown."
11189   (interactive)
11190   (let ((buffer-read-only nil)
11191         (orig (point))
11192         (end (point-at-eol))
11193         ;; Leave point at bol
11194         (beg (progn (beginning-of-line) (point))))
11195     (prog1
11196         ;; Any hidden lines here?
11197         (search-forward "\r" end t)
11198       (subst-char-in-region beg end ?\^M ?\n t)
11199       (goto-char orig)
11200       (gnus-summary-position-point))))
11201
11202 (defun gnus-summary-maybe-hide-threads ()
11203   "If requested, hide the threads that should be hidden."
11204   (when (and gnus-show-threads
11205              gnus-thread-hide-subtree)
11206     (gnus-summary-hide-all-threads
11207      (if (or (consp gnus-thread-hide-subtree)
11208              (functionp gnus-thread-hide-subtree))
11209          (gnus-make-predicate gnus-thread-hide-subtree)
11210        nil))))
11211
11212 ;;; Hiding predicates.
11213
11214 (defun gnus-article-unread-p (header)
11215   (memq (mail-header-number header) gnus-newsgroup-unreads))
11216
11217 (defun gnus-article-unseen-p (header)
11218   (memq (mail-header-number header) gnus-newsgroup-unseen))
11219
11220 (defun gnus-map-articles (predicate articles)
11221   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11222   (apply 'gnus-or (mapcar predicate
11223                           (mapcar (lambda (number)
11224                                     (gnus-summary-article-header number))
11225                                   articles))))
11226
11227 (defun gnus-summary-hide-all-threads (&optional predicate)
11228   "Hide all thread subtrees.
11229 If PREDICATE is supplied, threads that satisfy this predicate
11230 will not be hidden."
11231   (interactive)
11232   (save-excursion
11233     (goto-char (point-min))
11234     (let ((end nil))
11235       (while (not end)
11236         (when (or (not predicate)
11237                   (gnus-map-articles
11238                    predicate (gnus-summary-article-children)))
11239             (gnus-summary-hide-thread))
11240         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11241   (gnus-summary-position-point))
11242
11243 (defun gnus-summary-hide-thread ()
11244   "Hide thread subtrees.
11245 If PREDICATE is supplied, threads that satisfy this predicate
11246 will not be hidden.
11247 Returns nil if no threads were there to be hidden."
11248   (interactive)
11249   (let ((buffer-read-only nil)
11250         (start (point))
11251         (article (gnus-summary-article-number)))
11252     (goto-char start)
11253     ;; Go forward until either the buffer ends or the subthread
11254     ;; ends.
11255     (when (and (not (eobp))
11256                (or (zerop (gnus-summary-next-thread 1 t))
11257                    (goto-char (point-max))))
11258       (prog1
11259           (if (and (> (point) start)
11260                    (search-backward "\n" start t))
11261               (progn
11262                 (subst-char-in-region start (point) ?\n ?\^M)
11263                 (gnus-summary-goto-subject article))
11264             (goto-char start)
11265             nil)))))
11266
11267 (defun gnus-summary-go-to-next-thread (&optional previous)
11268   "Go to the same level (or less) next thread.
11269 If PREVIOUS is non-nil, go to previous thread instead.
11270 Return the article number moved to, or nil if moving was impossible."
11271   (let ((level (gnus-summary-thread-level))
11272         (way (if previous -1 1))
11273         (beg (point)))
11274     (forward-line way)
11275     (while (and (not (eobp))
11276                 (< level (gnus-summary-thread-level)))
11277       (forward-line way))
11278     (if (eobp)
11279         (progn
11280           (goto-char beg)
11281           nil)
11282       (setq beg (point))
11283       (prog1
11284           (gnus-summary-article-number)
11285         (goto-char beg)))))
11286
11287 (defun gnus-summary-next-thread (n &optional silent)
11288   "Go to the same level next N'th thread.
11289 If N is negative, search backward instead.
11290 Returns the difference between N and the number of skips actually
11291 done.
11292
11293 If SILENT, don't output messages."
11294   (interactive "p")
11295   (let ((backward (< n 0))
11296         (n (abs n)))
11297     (while (and (> n 0)
11298                 (gnus-summary-go-to-next-thread backward))
11299       (decf n))
11300     (unless silent
11301       (gnus-summary-position-point))
11302     (when (and (not silent) (/= 0 n))
11303       (gnus-message 7 "No more threads"))
11304     n))
11305
11306 (defun gnus-summary-prev-thread (n)
11307   "Go to the same level previous N'th thread.
11308 Returns the difference between N and the number of skips actually
11309 done."
11310   (interactive "p")
11311   (gnus-summary-next-thread (- n)))
11312
11313 (defun gnus-summary-go-down-thread ()
11314   "Go down one level in the current thread."
11315   (let ((children (gnus-summary-article-children)))
11316     (when children
11317       (gnus-summary-goto-subject (car children)))))
11318
11319 (defun gnus-summary-go-up-thread ()
11320   "Go up one level in the current thread."
11321   (let ((parent (gnus-summary-article-parent)))
11322     (when parent
11323       (gnus-summary-goto-subject parent))))
11324
11325 (defun gnus-summary-down-thread (n)
11326   "Go down thread N steps.
11327 If N is negative, go up instead.
11328 Returns the difference between N and how many steps down that were
11329 taken."
11330   (interactive "p")
11331   (let ((up (< n 0))
11332         (n (abs n)))
11333     (while (and (> n 0)
11334                 (if up (gnus-summary-go-up-thread)
11335                   (gnus-summary-go-down-thread)))
11336       (setq n (1- n)))
11337     (gnus-summary-position-point)
11338     (when (/= 0 n)
11339       (gnus-message 7 "Can't go further"))
11340     n))
11341
11342 (defun gnus-summary-up-thread (n)
11343   "Go up thread N steps.
11344 If N is negative, go down instead.
11345 Returns the difference between N and how many steps down that were
11346 taken."
11347   (interactive "p")
11348   (gnus-summary-down-thread (- n)))
11349
11350 (defun gnus-summary-top-thread ()
11351   "Go to the top of the thread."
11352   (interactive)
11353   (while (gnus-summary-go-up-thread))
11354   (gnus-summary-article-number))
11355
11356 (defun gnus-summary-kill-thread (&optional unmark)
11357   "Mark articles under current thread as read.
11358 If the prefix argument is positive, remove any kinds of marks.
11359 If the prefix argument is negative, tick articles instead."
11360   (interactive "P")
11361   (when unmark
11362     (setq unmark (prefix-numeric-value unmark)))
11363   (let ((articles (gnus-summary-articles-in-thread)))
11364     (save-excursion
11365       ;; Expand the thread.
11366       (gnus-summary-show-thread)
11367       ;; Mark all the articles.
11368       (while articles
11369         (gnus-summary-goto-subject (car articles))
11370         (cond ((null unmark)
11371                (gnus-summary-mark-article-as-read gnus-killed-mark))
11372               ((> unmark 0)
11373                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11374               (t
11375                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11376         (setq articles (cdr articles))))
11377     ;; Hide killed subtrees.
11378     (and (null unmark)
11379          gnus-thread-hide-killed
11380          (gnus-summary-hide-thread))
11381     ;; If marked as read, go to next unread subject.
11382     (when (null unmark)
11383       ;; Go to next unread subject.
11384       (gnus-summary-next-subject 1 t)))
11385   (gnus-set-mode-line 'summary))
11386
11387 ;; Summary sorting commands
11388
11389 (defun gnus-summary-sort-by-number (&optional reverse)
11390   "Sort the summary buffer by article number.
11391 Argument REVERSE means reverse order."
11392   (interactive "P")
11393   (gnus-summary-sort 'number reverse))
11394
11395 (defun gnus-summary-sort-by-random (&optional reverse)
11396   "Randomize the order in the summary buffer.
11397 Argument REVERSE means to randomize in reverse order."
11398   (interactive "P")
11399   (gnus-summary-sort 'random reverse))
11400
11401 (defun gnus-summary-sort-by-author (&optional reverse)
11402   "Sort the summary buffer by author name alphabetically.
11403 If `case-fold-search' is non-nil, case of letters is ignored.
11404 Argument REVERSE means reverse order."
11405   (interactive "P")
11406   (gnus-summary-sort 'author reverse))
11407
11408 (defun gnus-summary-sort-by-recipient (&optional reverse)
11409   "Sort the summary buffer by recipient name alphabetically.
11410 If `case-fold-search' is non-nil, case of letters is ignored.
11411 Argument REVERSE means reverse order."
11412   (interactive "P")
11413   (gnus-summary-sort 'recipient reverse))
11414
11415 (defun gnus-summary-sort-by-subject (&optional reverse)
11416   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11417 If `case-fold-search' is non-nil, case of letters is ignored.
11418 Argument REVERSE means reverse order."
11419   (interactive "P")
11420   (gnus-summary-sort 'subject reverse))
11421
11422 (defun gnus-summary-sort-by-date (&optional reverse)
11423   "Sort the summary buffer by date.
11424 Argument REVERSE means reverse order."
11425   (interactive "P")
11426   (gnus-summary-sort 'date reverse))
11427
11428 (defun gnus-summary-sort-by-score (&optional reverse)
11429   "Sort the summary buffer by score.
11430 Argument REVERSE means reverse order."
11431   (interactive "P")
11432   (gnus-summary-sort 'score reverse))
11433
11434 (defun gnus-summary-sort-by-lines (&optional reverse)
11435   "Sort the summary buffer by the number of lines.
11436 Argument REVERSE means reverse order."
11437   (interactive "P")
11438   (gnus-summary-sort 'lines reverse))
11439
11440 (defun gnus-summary-sort-by-chars (&optional reverse)
11441   "Sort the summary buffer by article length.
11442 Argument REVERSE means reverse order."
11443   (interactive "P")
11444   (gnus-summary-sort 'chars reverse))
11445
11446 (defun gnus-summary-sort-by-original (&optional reverse)
11447   "Sort the summary buffer using the default sorting method.
11448 Argument REVERSE means reverse order."
11449   (interactive "P")
11450   (let* ((buffer-read-only)
11451          (gnus-summary-prepare-hook nil))
11452     ;; We do the sorting by regenerating the threads.
11453     (gnus-summary-prepare)
11454     ;; Hide subthreads if needed.
11455     (gnus-summary-maybe-hide-threads)))
11456
11457 (defun gnus-summary-sort (predicate reverse)
11458   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11459   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11460          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11461          (gnus-thread-sort-functions
11462           (if (not reverse)
11463               thread
11464             `(lambda (t1 t2)
11465                (,thread t2 t1))))
11466          (gnus-sort-gathered-threads-function
11467           gnus-thread-sort-functions)
11468          (gnus-article-sort-functions
11469           (if (not reverse)
11470               article
11471             `(lambda (t1 t2)
11472                (,article t2 t1))))
11473          (buffer-read-only)
11474          (gnus-summary-prepare-hook nil))
11475     ;; We do the sorting by regenerating the threads.
11476     (gnus-summary-prepare)
11477     ;; Hide subthreads if needed.
11478     (gnus-summary-maybe-hide-threads)))
11479
11480 ;; Summary saving commands.
11481
11482 (defun gnus-summary-save-article (&optional n not-saved)
11483   "Save the current article using the default saver function.
11484 If N is a positive number, save the N next articles.
11485 If N is a negative number, save the N previous articles.
11486 If N is nil and any articles have been marked with the process mark,
11487 save those articles instead.
11488 The variable `gnus-default-article-saver' specifies the saver function.
11489
11490 If the optional second argument NOT-SAVED is non-nil, articles saved
11491 will not be marked as saved."
11492   (interactive "P")
11493   (require 'gnus-art)
11494   (let* ((articles (gnus-summary-work-articles n))
11495          (save-buffer (save-excursion
11496                         (nnheader-set-temp-buffer " *Gnus Save*")))
11497          (num (length articles))
11498          ;; Whether to save decoded articles or raw articles.
11499          (decode (when gnus-article-save-coding-system
11500                    (get gnus-default-article-saver :decode)))
11501          ;; When saving many articles in a single file, use the other
11502          ;; function to save articles other than the first one.
11503          (saver2 (get gnus-default-article-saver :function))
11504          (gnus-prompt-before-saving (if saver2
11505                                         t
11506                                       gnus-prompt-before-saving))
11507          (gnus-default-article-saver gnus-default-article-saver)
11508          header file)
11509     (dolist (article articles)
11510       (setq header (gnus-summary-article-header article))
11511       (if (not (vectorp header))
11512           ;; This is a pseudo-article.
11513           (if (assq 'name header)
11514               (gnus-copy-file (cdr (assq 'name header)))
11515             (gnus-message 1 "Article %d is unsaveable" article))
11516         ;; This is a real article.
11517         (save-window-excursion
11518           (let ((gnus-display-mime-function (when decode
11519                                               gnus-display-mime-function))
11520                 (gnus-article-prepare-hook (when decode
11521                                              gnus-article-prepare-hook)))
11522             (gnus-summary-select-article t nil nil article)
11523             (gnus-summary-goto-subject article)))
11524         (save-excursion
11525           (set-buffer save-buffer)
11526           (erase-buffer)
11527           (insert-buffer-substring (if decode
11528                                        gnus-article-buffer
11529                                      gnus-original-article-buffer)))
11530         (setq file (gnus-article-save save-buffer file num))
11531         (gnus-summary-remove-process-mark article)
11532         (unless not-saved
11533           (gnus-summary-set-saved-mark article)))
11534       (when saver2
11535         (setq gnus-default-article-saver saver2
11536               saver2 nil)))
11537     (gnus-kill-buffer save-buffer)
11538     (gnus-summary-position-point)
11539     (gnus-set-mode-line 'summary)
11540     n))
11541
11542 (defun gnus-summary-pipe-output (&optional arg headers)
11543   "Pipe the current article to a subprocess.
11544 If N is a positive number, pipe the N next articles.
11545 If N is a negative number, pipe the N previous articles.
11546 If N is nil and any articles have been marked with the process mark,
11547 pipe those articles instead.
11548 If HEADERS (the symbolic prefix), include the headers, too."
11549   (interactive (gnus-interactive "P\ny"))
11550   (require 'gnus-art)
11551   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11552         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11553     (gnus-summary-save-article arg t))
11554   (let ((buffer (get-buffer "*Shell Command Output*")))
11555     (when (and buffer
11556                (not (zerop (buffer-size buffer))))
11557       (gnus-configure-windows 'pipe))))
11558
11559 (defun gnus-summary-save-article-mail (&optional arg)
11560   "Append the current article to a Unix mail box file.
11561 If N is a positive number, save the N next articles.
11562 If N is a negative number, save the N previous articles.
11563 If N is nil and any articles have been marked with the process mark,
11564 save those articles instead."
11565   (interactive "P")
11566   (require 'gnus-art)
11567   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11568     (gnus-summary-save-article arg)))
11569
11570 (defun gnus-summary-save-article-rmail (&optional arg)
11571   "Append the current article to an rmail file.
11572 If N is a positive number, save the N next articles.
11573 If N is a negative number, save the N previous articles.
11574 If N is nil and any articles have been marked with the process mark,
11575 save those articles instead."
11576   (interactive "P")
11577   (require 'gnus-art)
11578   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11579     (gnus-summary-save-article arg)))
11580
11581 (defun gnus-summary-save-article-file (&optional arg)
11582   "Append the current article to a file.
11583 If N is a positive number, save the N next articles.
11584 If N is a negative number, save the N previous articles.
11585 If N is nil and any articles have been marked with the process mark,
11586 save those articles instead."
11587   (interactive "P")
11588   (require 'gnus-art)
11589   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11590     (gnus-summary-save-article arg)))
11591
11592 (defun gnus-summary-write-article-file (&optional arg)
11593   "Write the current article to a file, deleting the previous file.
11594 If N is a positive number, save the N next articles.
11595 If N is a negative number, save the N previous articles.
11596 If N is nil and any articles have been marked with the process mark,
11597 save those articles instead."
11598   (interactive "P")
11599   (require 'gnus-art)
11600   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11601     (gnus-summary-save-article arg)))
11602
11603 (defun gnus-summary-save-article-body-file (&optional arg)
11604   "Append the current article body to a file.
11605 If N is a positive number, save the N next articles.
11606 If N is a negative number, save the N previous articles.
11607 If N is nil and any articles have been marked with the process mark,
11608 save those articles instead."
11609   (interactive "P")
11610   (require 'gnus-art)
11611   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11612     (gnus-summary-save-article arg)))
11613
11614 (defun gnus-summary-write-article-body-file (&optional arg)
11615   "Write the current article body to a file, deleting the previous file.
11616 If N is a positive number, save the N next articles.
11617 If N is a negative number, save the N previous articles.
11618 If N is nil and any articles have been marked with the process mark,
11619 save those articles instead."
11620   (interactive "P")
11621   (require 'gnus-art)
11622   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11623     (gnus-summary-save-article arg)))
11624
11625 (defun gnus-summary-muttprint (&optional arg)
11626   "Print the current article using Muttprint.
11627 If N is a positive number, save the N next articles.
11628 If N is a negative number, save the N previous articles.
11629 If N is nil and any articles have been marked with the process mark,
11630 save those articles instead."
11631   (interactive "P")
11632   (require 'gnus-art)
11633   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11634     (gnus-summary-save-article arg t)))
11635
11636 (defun gnus-summary-pipe-message (program)
11637   "Pipe the current article through PROGRAM."
11638   (interactive "sProgram: ")
11639   (gnus-summary-select-article)
11640   (let ((mail-header-separator ""))
11641     (gnus-eval-in-buffer-window gnus-article-buffer
11642       (save-restriction
11643         (widen)
11644         (let ((start (window-start))
11645               buffer-read-only)
11646           (message-pipe-buffer-body program)
11647           (set-window-start (get-buffer-window (current-buffer)) start))))))
11648
11649 (defun gnus-get-split-value (methods)
11650   "Return a value based on the split METHODS."
11651   (let (split-name method result match)
11652     (when methods
11653       (save-excursion
11654         (set-buffer gnus-original-article-buffer)
11655         (save-restriction
11656           (nnheader-narrow-to-headers)
11657           (while (and methods (not split-name))
11658             (goto-char (point-min))
11659             (setq method (pop methods))
11660             (setq match (car method))
11661             (when (cond
11662                    ((stringp match)
11663                     ;; Regular expression.
11664                     (ignore-errors
11665                       (re-search-forward match nil t)))
11666                    ((functionp match)
11667                     ;; Function.
11668                     (save-restriction
11669                       (widen)
11670                       (setq result (funcall match gnus-newsgroup-name))))
11671                    ((consp match)
11672                     ;; Form.
11673                     (save-restriction
11674                       (widen)
11675                       (setq result (eval match)))))
11676               (setq split-name (cdr method))
11677               (cond ((stringp result)
11678                      (push (expand-file-name
11679                             result gnus-article-save-directory)
11680                            split-name))
11681                     ((consp result)
11682                      (setq split-name (append result split-name)))))))))
11683     (nreverse split-name)))
11684
11685 (defun gnus-valid-move-group-p (group)
11686   (and (boundp group)
11687        (symbol-name group)
11688        (symbol-value group)
11689        (gnus-get-function (gnus-find-method-for-group
11690                            (symbol-name group)) 'request-accept-article t)))
11691
11692 (defun gnus-read-move-group-name (prompt default articles prefix)
11693   "Read a group name."
11694   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11695          (minibuffer-confirm-incomplete nil) ; XEmacs
11696          (prom
11697           (format "%s %s to"
11698                   prompt
11699                   (if (> (length articles) 1)
11700                       (format "these %d articles" (length articles))
11701                     "this article")))
11702          (to-newsgroup
11703           (cond
11704            ((null split-name)
11705             (gnus-completing-read-with-default
11706              default prom
11707              gnus-active-hashtb
11708              'gnus-valid-move-group-p
11709              nil prefix
11710              'gnus-group-history))
11711            ((= 1 (length split-name))
11712             (gnus-completing-read-with-default
11713              (car split-name) prom
11714              gnus-active-hashtb
11715              'gnus-valid-move-group-p
11716              nil nil
11717              'gnus-group-history))
11718            (t
11719             (gnus-completing-read-with-default
11720              nil prom
11721              (mapcar 'list (nreverse split-name))
11722              nil nil nil
11723              'gnus-group-history))))
11724          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
11725          encoded)
11726     (when to-newsgroup
11727       (if (or (string= to-newsgroup "")
11728               (string= to-newsgroup prefix))
11729           (setq to-newsgroup default))
11730       (unless to-newsgroup
11731         (error "No group name entered"))
11732       (setq encoded (mm-encode-coding-string
11733                      to-newsgroup
11734                      (gnus-group-name-charset to-method to-newsgroup)))
11735       (or (gnus-active encoded)
11736           (gnus-activate-group encoded nil nil to-method)
11737           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11738                                      to-newsgroup))
11739               (or (and (gnus-request-create-group encoded to-method)
11740                        (gnus-activate-group encoded nil nil to-method)
11741                        (gnus-subscribe-group encoded))
11742                   (error "Couldn't create group %s" to-newsgroup)))
11743           (error "No such group: %s" to-newsgroup))
11744       encoded)))
11745
11746 (defvar gnus-summary-save-parts-counter)
11747
11748 (defun gnus-summary-save-parts (type dir n &optional reverse)
11749   "Save parts matching TYPE to DIR.
11750 If REVERSE, save parts that do not match TYPE."
11751   (interactive
11752    (list (read-string "Save parts of type: "
11753                       (or (car gnus-summary-save-parts-type-history)
11754                           gnus-summary-save-parts-default-mime)
11755                       'gnus-summary-save-parts-type-history)
11756          (setq gnus-summary-save-parts-last-directory
11757                (read-file-name "Save to directory: "
11758                                gnus-summary-save-parts-last-directory
11759                                nil t))
11760          current-prefix-arg))
11761   (gnus-summary-iterate n
11762     (let ((gnus-display-mime-function nil)
11763           (gnus-inhibit-treatment t))
11764       (gnus-summary-select-article))
11765     (save-excursion
11766       (set-buffer gnus-article-buffer)
11767       (let ((handles (or gnus-article-mime-handles
11768                          (mm-dissect-buffer nil gnus-article-loose-mime)
11769                          (and gnus-article-emulate-mime
11770                               (mm-uu-dissect))))
11771             (gnus-summary-save-parts-counter 1))
11772         (when handles
11773           (gnus-summary-save-parts-1 type dir handles reverse)
11774           (unless gnus-article-mime-handles ;; Don't destroy this case.
11775             (mm-destroy-parts handles)))))))
11776
11777 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11778   (if (stringp (car handle))
11779       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11780               (cdr handle))
11781     (when (if reverse
11782               (not (string-match type (mm-handle-media-type handle)))
11783             (string-match type (mm-handle-media-type handle)))
11784       (let ((file (expand-file-name
11785                    (gnus-map-function
11786                     mm-file-name-rewrite-functions
11787                     (file-name-nondirectory
11788                      (or
11789                       (mail-content-type-get
11790                        (mm-handle-disposition handle) 'filename)
11791                       (mail-content-type-get
11792                        (mm-handle-type handle) 'name)
11793                       (format "%s.%d.%d" gnus-newsgroup-name
11794                               (cdr gnus-article-current)
11795                               gnus-summary-save-parts-counter))))
11796                    dir)))
11797         (incf gnus-summary-save-parts-counter)
11798         (unless (file-exists-p file)
11799           (mm-save-part-to-file handle file))))))
11800
11801 ;; Summary extract commands
11802
11803 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11804   (let ((buffer-read-only nil)
11805         (article (gnus-summary-article-number))
11806         after-article b e)
11807     (unless (gnus-summary-goto-subject article)
11808       (error "No such article: %d" article))
11809     (gnus-summary-position-point)
11810     ;; If all commands are to be bunched up on one line, we collect
11811     ;; them here.
11812     (unless gnus-view-pseudos-separately
11813       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11814             files action)
11815         (while ps
11816           (setq action (cdr (assq 'action (car ps))))
11817           (setq files (list (cdr (assq 'name (car ps)))))
11818           (while (and ps (cdr ps)
11819                       (string= (or action "1")
11820                                (or (cdr (assq 'action (cadr ps))) "2")))
11821             (push (cdr (assq 'name (cadr ps))) files)
11822             (setcdr ps (cddr ps)))
11823           (when files
11824             (when (not (string-match "%s" action))
11825               (push " " files))
11826             (push " " files)
11827             (when (assq 'execute (car ps))
11828               (setcdr (assq 'execute (car ps))
11829                       (funcall (if (string-match "%s" action)
11830                                    'format 'concat)
11831                                action
11832                                (mapconcat
11833                                 (lambda (f)
11834                                   (if (equal f " ")
11835                                       f
11836                                     (shell-quote-argument f)))
11837                                 files " ")))))
11838           (setq ps (cdr ps)))))
11839     (if (and gnus-view-pseudos (not not-view))
11840         (while pslist
11841           (when (assq 'execute (car pslist))
11842             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11843                                   (eq gnus-view-pseudos 'not-confirm)))
11844           (setq pslist (cdr pslist)))
11845       (save-excursion
11846         (while pslist
11847           (setq after-article (or (cdr (assq 'article (car pslist)))
11848                                   (gnus-summary-article-number)))
11849           (gnus-summary-goto-subject after-article)
11850           (forward-line 1)
11851           (setq b (point))
11852           (insert "    " (file-name-nondirectory
11853                           (cdr (assq 'name (car pslist))))
11854                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11855           (setq e (point))
11856           (forward-line -1)             ; back to `b'
11857           (gnus-add-text-properties
11858            b (1- e) (list 'gnus-number gnus-reffed-article-number
11859                           gnus-mouse-face-prop gnus-mouse-face))
11860           (gnus-data-enter
11861            after-article gnus-reffed-article-number
11862            gnus-unread-mark b (car pslist) 0 (- e b))
11863           (setq gnus-newsgroup-unreads
11864                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11865                                          gnus-reffed-article-number))
11866           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11867           (setq pslist (cdr pslist)))))))
11868
11869 (defun gnus-pseudos< (p1 p2)
11870   (let ((c1 (cdr (assq 'action p1)))
11871         (c2 (cdr (assq 'action p2))))
11872     (and c1 c2 (string< c1 c2))))
11873
11874 (defun gnus-request-pseudo-article (props)
11875   (cond ((assq 'execute props)
11876          (gnus-execute-command (cdr (assq 'execute props)))))
11877   (let ((gnus-current-article (gnus-summary-article-number)))
11878     (gnus-run-hooks 'gnus-mark-article-hook)))
11879
11880 (defun gnus-execute-command (command &optional automatic)
11881   (save-excursion
11882     (gnus-article-setup-buffer)
11883     (set-buffer gnus-article-buffer)
11884     (setq buffer-read-only nil)
11885     (let ((command (if automatic command
11886                      (read-string "Command: " (cons command 0)))))
11887       (erase-buffer)
11888       (insert "$ " command "\n\n")
11889       (if gnus-view-pseudo-asynchronously
11890           (start-process "gnus-execute" (current-buffer) shell-file-name
11891                          shell-command-switch command)
11892         (call-process shell-file-name nil t nil
11893                       shell-command-switch command)))))
11894
11895 ;; Summary kill commands.
11896
11897 (defun gnus-summary-edit-global-kill (article)
11898   "Edit the \"global\" kill file."
11899   (interactive (list (gnus-summary-article-number)))
11900   (gnus-group-edit-global-kill article))
11901
11902 (defun gnus-summary-edit-local-kill ()
11903   "Edit a local kill file applied to the current newsgroup."
11904   (interactive)
11905   (setq gnus-current-headers (gnus-summary-article-header))
11906   (gnus-group-edit-local-kill
11907    (gnus-summary-article-number) gnus-newsgroup-name))
11908
11909 ;;; Header reading.
11910
11911 (defun gnus-read-header (id &optional header)
11912   "Read the headers of article ID and enter them into the Gnus system."
11913   (let ((group gnus-newsgroup-name)
11914         (gnus-override-method
11915          (or
11916           gnus-override-method
11917           (and (gnus-news-group-p gnus-newsgroup-name)
11918                (car (gnus-refer-article-methods)))))
11919         where)
11920     ;; First we check to see whether the header in question is already
11921     ;; fetched.
11922     (if (stringp id)
11923         ;; This is a Message-ID.
11924         (setq header (or header (gnus-id-to-header id)))
11925       ;; This is an article number.
11926       (setq header (or header (gnus-summary-article-header id))))
11927     (if (and header
11928              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11929         ;; We have found the header.
11930         header
11931       ;; We have to really fetch the header to this article.
11932       (save-excursion
11933         (set-buffer nntp-server-buffer)
11934         (when (setq where (gnus-request-head id group))
11935           (nnheader-fold-continuation-lines)
11936           (goto-char (point-max))
11937           (insert ".\n")
11938           (goto-char (point-min))
11939           (insert "211 ")
11940           (princ (cond
11941                   ((numberp id) id)
11942                   ((cdr where) (cdr where))
11943                   (header (mail-header-number header))
11944                   (t gnus-reffed-article-number))
11945                  (current-buffer))
11946           (insert " Article retrieved.\n"))
11947         (if (or (not where)
11948                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11949             ()                          ; Malformed head.
11950           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11951             (when (and (stringp id)
11952                        (or
11953                         (not (string= (gnus-group-real-name group)
11954                                       (car where)))
11955                         (not (gnus-server-equal gnus-override-method
11956                                                 (gnus-group-method group)))))
11957               ;; If we fetched by Message-ID and the article came from
11958               ;; a different group (or server), we fudge some bogus
11959               ;; article numbers for this article.
11960               (mail-header-set-number header gnus-reffed-article-number))
11961             (save-excursion
11962               (set-buffer gnus-summary-buffer)
11963               (decf gnus-reffed-article-number)
11964               (gnus-remove-header (mail-header-number header))
11965               (push header gnus-newsgroup-headers)
11966               (setq gnus-current-headers header)
11967               (push (mail-header-number header) gnus-newsgroup-limit)))
11968           header)))))
11969
11970 (defun gnus-remove-header (number)
11971   "Remove header NUMBER from `gnus-newsgroup-headers'."
11972   (if (and gnus-newsgroup-headers
11973            (= number (mail-header-number (car gnus-newsgroup-headers))))
11974       (pop gnus-newsgroup-headers)
11975     (let ((headers gnus-newsgroup-headers))
11976       (while (and (cdr headers)
11977                   (not (= number (mail-header-number (cadr headers)))))
11978         (pop headers))
11979       (when (cdr headers)
11980         (setcdr headers (cddr headers))))))
11981
11982 ;;;
11983 ;;; summary highlights
11984 ;;;
11985
11986 (defun gnus-highlight-selected-summary ()
11987   "Highlight selected article in summary buffer."
11988   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11989   (when gnus-summary-selected-face
11990     (save-excursion
11991       (let* ((beg (point-at-bol))
11992              (end (point-at-eol))
11993              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11994              (from (if (get-text-property beg gnus-mouse-face-prop)
11995                        beg
11996                      (or (next-single-property-change
11997                           beg gnus-mouse-face-prop nil end)
11998                          beg)))
11999              (to
12000               (if (= from end)
12001                   (- from 2)
12002                 (or (next-single-property-change
12003                      from gnus-mouse-face-prop nil end)
12004                     end))))
12005         ;; If no mouse-face prop on line we will have to = from = end,
12006         ;; so we highlight the entire line instead.
12007         (when (= (+ to 2) from)
12008           (setq from beg)
12009           (setq to end))
12010         (if gnus-newsgroup-selected-overlay
12011             ;; Move old overlay.
12012             (gnus-move-overlay
12013              gnus-newsgroup-selected-overlay from to (current-buffer))
12014           ;; Create new overlay.
12015           (gnus-overlay-put
12016            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12017            'face gnus-summary-selected-face))))))
12018
12019 (defvar gnus-summary-highlight-line-cached nil)
12020 (defvar gnus-summary-highlight-line-trigger nil)
12021
12022 (defun gnus-summary-highlight-line-0 ()
12023   (if (and (eq gnus-summary-highlight-line-trigger
12024                gnus-summary-highlight)
12025            gnus-summary-highlight-line-cached)
12026       gnus-summary-highlight-line-cached
12027     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12028           gnus-summary-highlight-line-cached
12029           (let* ((cond (list 'cond))
12030                  (c cond)
12031                  (list gnus-summary-highlight))
12032             (while list
12033               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12034                               nil))
12035               (setq c (cdr c)
12036                     list (cdr list)))
12037             (gnus-byte-compile (list 'lambda nil cond))))))
12038
12039 (defun gnus-summary-highlight-line ()
12040   "Highlight current line according to `gnus-summary-highlight'."
12041   (let* ((beg (point-at-bol))
12042          (article (or (gnus-summary-article-number) gnus-current-article))
12043          (score (or (cdr (assq article
12044                                gnus-newsgroup-scored))
12045                     gnus-summary-default-score 0))
12046          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12047          (inhibit-read-only t)
12048          (default gnus-summary-default-score)
12049          (default-high gnus-summary-default-high-score)
12050          (default-low gnus-summary-default-low-score)
12051          (uncached (and gnus-summary-use-undownloaded-faces
12052                         (memq article gnus-newsgroup-undownloaded)
12053                         (not (memq article gnus-newsgroup-cached)))))
12054     (let ((face (funcall (gnus-summary-highlight-line-0))))
12055       (unless (eq face (get-text-property beg 'face))
12056         (gnus-put-text-property-excluding-characters-with-faces
12057          beg (point-at-eol) 'face
12058          (setq face (if (boundp face) (symbol-value face) face)))
12059         (when gnus-summary-highlight-line-function
12060           (funcall gnus-summary-highlight-line-function article face))))))
12061
12062 (defun gnus-update-read-articles (group unread &optional compute)
12063   "Update the list of read articles in GROUP.
12064 UNREAD is a sorted list."
12065   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12066         (info (gnus-get-info group))
12067         (prev 1)
12068         read)
12069     (if (or (not info) (not active))
12070         ;; There is no info on this group if it was, in fact,
12071         ;; killed.  Gnus stores no information on killed groups, so
12072         ;; there's nothing to be done.
12073         ;; One could store the information somewhere temporarily,
12074         ;; perhaps...  Hmmm...
12075         ()
12076       ;; Remove any negative articles numbers.
12077       (while (and unread (< (car unread) 0))
12078         (setq unread (cdr unread)))
12079       ;; Remove any expired article numbers
12080       (while (and unread (< (car unread) (car active)))
12081         (setq unread (cdr unread)))
12082       ;; Compute the ranges of read articles by looking at the list of
12083       ;; unread articles.
12084       (while unread
12085         (when (/= (car unread) prev)
12086           (push (if (= prev (1- (car unread))) prev
12087                   (cons prev (1- (car unread))))
12088                 read))
12089         (setq prev (1+ (car unread)))
12090         (setq unread (cdr unread)))
12091       (when (<= prev (cdr active))
12092         (push (cons prev (cdr active)) read))
12093       (setq read (if (> (length read) 1) (nreverse read) read))
12094       (if compute
12095           read
12096         (save-excursion
12097           (let (setmarkundo)
12098             ;; Propagate the read marks to the backend.
12099             (when (gnus-check-backend-function 'request-set-mark group)
12100               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12101                     (add (gnus-remove-from-range read (gnus-info-read info))))
12102                 (when (or add del)
12103                   (unless (gnus-check-group group)
12104                     (error "Can't open server for %s" group))
12105                   (gnus-request-set-mark
12106                    group (delq nil (list (if add (list add 'add '(read)))
12107                                          (if del (list del 'del '(read))))))
12108                   (setq setmarkundo
12109                         `(gnus-request-set-mark
12110                           ,group
12111                           ',(delq nil (list
12112                                        (if del (list del 'add '(read)))
12113                                        (if add (list add 'del '(read))))))))))
12114             (set-buffer gnus-group-buffer)
12115             (gnus-undo-register
12116               `(progn
12117                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12118                  (gnus-info-set-read ',info ',(gnus-info-read info))
12119                  (gnus-get-unread-articles-in-group ',info
12120                                                     (gnus-active ,group))
12121                  (gnus-group-update-group ,group t)
12122                  ,setmarkundo))))
12123         ;; Enter this list into the group info.
12124         (gnus-info-set-read info read)
12125         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12126         (gnus-get-unread-articles-in-group info (gnus-active group))
12127         t))))
12128
12129 (defun gnus-offer-save-summaries ()
12130   "Offer to save all active summary buffers."
12131   (let (buffers)
12132     ;; Go through all buffers and find all summaries.
12133     (dolist (buffer (buffer-list))
12134       (when (and (setq buffer (buffer-name buffer))
12135                  (string-match "Summary" buffer)
12136                  (with-current-buffer buffer
12137                    ;; We check that this is, indeed, a summary buffer.
12138                    (and (eq major-mode 'gnus-summary-mode)
12139                         ;; Also make sure this isn't bogus.
12140                         gnus-newsgroup-prepared
12141                         ;; Also make sure that this isn't a
12142                         ;; dead summary buffer.
12143                         (not gnus-dead-summary-mode))))
12144         (push buffer buffers)))
12145     ;; Go through all these summary buffers and offer to save them.
12146     (when buffers
12147       (save-excursion
12148         (map-y-or-n-p
12149          "Update summary buffer %s? "
12150          (lambda (buf)
12151            (switch-to-buffer buf)
12152            (gnus-summary-exit))
12153          buffers)))))
12154
12155 (defun gnus-summary-setup-default-charset ()
12156   "Setup newsgroup default charset."
12157   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12158       (setq gnus-newsgroup-charset nil)
12159     (let* ((ignored-charsets
12160             (or gnus-newsgroup-ephemeral-ignored-charsets
12161                 (append
12162                  (and gnus-newsgroup-name
12163                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12164                  gnus-newsgroup-ignored-charsets))))
12165       (setq gnus-newsgroup-charset
12166             (or gnus-newsgroup-ephemeral-charset
12167                 (and gnus-newsgroup-name
12168                      (gnus-parameter-charset gnus-newsgroup-name))
12169                 gnus-default-charset))
12170       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12171            ignored-charsets))))
12172
12173 ;;;
12174 ;;; Mime Commands
12175 ;;;
12176
12177 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12178   "Display the current article buffer fully MIME-buttonized.
12179 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12180 treated as multipart/mixed."
12181   (interactive "P")
12182   (require 'gnus-art)
12183   (let ((gnus-unbuttonized-mime-types nil)
12184         (gnus-mime-display-multipart-as-mixed show-all-parts))
12185     (gnus-summary-show-article)))
12186
12187 (defun gnus-summary-repair-multipart (article)
12188   "Add a Content-Type header to a multipart article without one."
12189   (interactive (list (gnus-summary-article-number)))
12190   (gnus-with-article article
12191     (message-narrow-to-head)
12192     (message-remove-header "Mime-Version")
12193     (goto-char (point-max))
12194     (insert "Mime-Version: 1.0\n")
12195     (widen)
12196     (when (search-forward "\n--" nil t)
12197       (let ((separator (buffer-substring (point) (point-at-eol))))
12198         (message-narrow-to-head)
12199         (message-remove-header "Content-Type")
12200         (goto-char (point-max))
12201         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12202                         separator))
12203         (widen))))
12204   (let (gnus-mark-article-hook)
12205     (gnus-summary-select-article t t nil article)))
12206
12207 (defun gnus-summary-toggle-display-buttonized ()
12208   "Toggle the buttonizing of the article buffer."
12209   (interactive)
12210   (require 'gnus-art)
12211   (if (setq gnus-inhibit-mime-unbuttonizing
12212             (not gnus-inhibit-mime-unbuttonizing))
12213       (let ((gnus-unbuttonized-mime-types nil))
12214         (gnus-summary-show-article))
12215     (gnus-summary-show-article)))
12216
12217 ;;;
12218 ;;; Generic summary marking commands
12219 ;;;
12220
12221 (defvar gnus-summary-marking-alist
12222   '((read gnus-del-mark "d")
12223     (unread gnus-unread-mark "u")
12224     (ticked gnus-ticked-mark "!")
12225     (dormant gnus-dormant-mark "?")
12226     (expirable gnus-expirable-mark "e"))
12227   "An alist of names/marks/keystrokes.")
12228
12229 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12230 (defvar gnus-summary-mark-map)
12231
12232 (defun gnus-summary-make-all-marking-commands ()
12233   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12234   (dolist (elem gnus-summary-marking-alist)
12235     (apply 'gnus-summary-make-marking-command elem)))
12236
12237 (defun gnus-summary-make-marking-command (name mark keystroke)
12238   (let ((map (make-sparse-keymap)))
12239     (define-key gnus-summary-generic-mark-map keystroke map)
12240     (dolist (lway `((next "next" next nil "n")
12241                     (next-unread "next unread" next t "N")
12242                     (prev "previous" prev nil "p")
12243                     (prev-unread "previous unread" prev t "P")
12244                     (nomove "" nil nil ,keystroke)))
12245       (let ((func (gnus-summary-make-marking-command-1
12246                    mark (car lway) lway name)))
12247         (setq func (eval func))
12248         (define-key map (nth 4 lway) func)))))
12249
12250 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12251   `(defun ,(intern
12252             (format "gnus-summary-put-mark-as-%s%s"
12253                     name (if (eq way 'nomove)
12254                              ""
12255                            (concat "-" (symbol-name way)))))
12256      (n)
12257      ,(format
12258        "Mark the current article as %s%s.
12259 If N, the prefix, then repeat N times.
12260 If N is negative, move in reverse order.
12261 The difference between N and the actual number of articles marked is
12262 returned."
12263        name (cadr lway))
12264      (interactive "p")
12265      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12266
12267 (defun gnus-summary-generic-mark (n mark move unread)
12268   "Mark N articles with MARK."
12269   (unless (eq major-mode 'gnus-summary-mode)
12270     (error "This command can only be used in the summary buffer"))
12271   (gnus-summary-show-thread)
12272   (let ((nummove
12273          (cond
12274           ((eq move 'next) 1)
12275           ((eq move 'prev) -1)
12276           (t 0))))
12277     (if (zerop nummove)
12278         (setq n 1)
12279       (when (< n 0)
12280         (setq n (abs n)
12281               nummove (* -1 nummove))))
12282     (while (and (> n 0)
12283                 (gnus-summary-mark-article nil mark)
12284                 (zerop (gnus-summary-next-subject nummove unread t)))
12285       (setq n (1- n)))
12286     (when (/= 0 n)
12287       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12288     (gnus-summary-recenter)
12289     (gnus-summary-position-point)
12290     (gnus-set-mode-line 'summary)
12291     n))
12292
12293 (defun gnus-summary-insert-articles (articles)
12294   (when (setq articles
12295               (gnus-sorted-difference articles
12296                                       (mapcar (lambda (h)
12297                                                 (mail-header-number h))
12298                                               gnus-newsgroup-headers)))
12299     (setq gnus-newsgroup-headers
12300           (gnus-merge 'list
12301                       gnus-newsgroup-headers
12302                       (gnus-fetch-headers articles)
12303                       'gnus-article-sort-by-number))
12304     ;; Suppress duplicates?
12305     (when gnus-suppress-duplicates
12306       (gnus-dup-suppress-articles))
12307
12308     ;; We might want to build some more threads first.
12309     (when (and gnus-fetch-old-headers
12310                (eq gnus-headers-retrieved-by 'nov))
12311       (if (eq gnus-fetch-old-headers 'invisible)
12312           (gnus-build-all-threads)
12313         (gnus-build-old-threads)))
12314     ;; Let the Gnus agent mark articles as read.
12315     (when gnus-agent
12316       (gnus-agent-get-undownloaded-list))
12317     ;; Remove list identifiers from subject
12318     (when gnus-list-identifiers
12319       (gnus-summary-remove-list-identifiers))
12320     ;; First and last article in this newsgroup.
12321     (when gnus-newsgroup-headers
12322       (setq gnus-newsgroup-begin
12323             (mail-header-number (car gnus-newsgroup-headers))
12324             gnus-newsgroup-end
12325             (mail-header-number
12326              (gnus-last-element gnus-newsgroup-headers))))
12327     (when gnus-use-scoring
12328       (gnus-possibly-score-headers))))
12329
12330 (defun gnus-summary-insert-old-articles (&optional all)
12331   "Insert all old articles in this group.
12332 If ALL is non-nil, already read articles become readable.
12333 If ALL is a number, fetch this number of articles."
12334   (interactive "P")
12335   (prog1
12336       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12337             older len)
12338         (setq older
12339               ;; Some nntp servers lie about their active range.  When
12340               ;; this happens, the active range can be in the millions.
12341               ;; Use a compressed range to avoid creating a huge list.
12342               (gnus-range-difference (list gnus-newsgroup-active) old))
12343         (setq len (gnus-range-length older))
12344         (cond
12345          ((null older) nil)
12346          ((numberp all)
12347           (if (< all len)
12348               (let ((older-range (nreverse older)))
12349                 (setq older nil)
12350
12351                 (while (> all 0)
12352                   (let* ((r (pop older-range))
12353                          (min (if (numberp r) r (car r)))
12354                          (max (if (numberp r) r (cdr r))))
12355                     (while (and (<= min max)
12356                                 (> all 0))
12357                       (push max older)
12358                       (setq all (1- all)
12359                             max (1- max))))))
12360             (setq older (gnus-uncompress-range older))))
12361          (all
12362           (setq older (gnus-uncompress-range older)))
12363          (t
12364           (when (and (numberp gnus-large-newsgroup)
12365                    (> len gnus-large-newsgroup))
12366               (let* ((cursor-in-echo-area nil)
12367                      (initial (gnus-parameter-large-newsgroup-initial
12368                                gnus-newsgroup-name))
12369                      (input
12370                       (read-string
12371                        (format
12372                         "How many articles from %s (%s %d): "
12373                         (gnus-group-decoded-name gnus-newsgroup-name)
12374                         (if initial "max" "default")
12375                         len)
12376                        (if initial
12377                            (cons (number-to-string initial)
12378                                  0)))))
12379                 (unless (string-match "^[ \t]*$" input)
12380                   (setq all (string-to-number input))
12381                   (if (< all len)
12382                       (let ((older-range (nreverse older)))
12383                         (setq older nil)
12384
12385                         (while (> all 0)
12386                           (let* ((r (pop older-range))
12387                                  (min (if (numberp r) r (car r)))
12388                                  (max (if (numberp r) r (cdr r))))
12389                             (while (and (<= min max)
12390                                         (> all 0))
12391                               (push max older)
12392                               (setq all (1- all)
12393                                     max (1- max))))))))))
12394           (setq older (gnus-uncompress-range older))))
12395         (if (not older)
12396             (message "No old news.")
12397           (gnus-summary-insert-articles older)
12398           (gnus-summary-limit (gnus-sorted-nunion old older))))
12399     (gnus-summary-position-point)))
12400
12401 (defun gnus-summary-insert-new-articles ()
12402   "Insert all new articles in this group."
12403   (interactive)
12404   (prog1
12405       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12406             (old-active gnus-newsgroup-active)
12407             (nnmail-fetched-sources (list t))
12408             i new)
12409         (setq gnus-newsgroup-active
12410               (gnus-activate-group gnus-newsgroup-name 'scan))
12411         (setq i (cdr gnus-newsgroup-active))
12412         (while (> i (cdr old-active))
12413           (push i new)
12414           (decf i))
12415         (if (not new)
12416             (message "No gnus is bad news")
12417           (gnus-summary-insert-articles new)
12418           (setq gnus-newsgroup-unreads
12419                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12420           (gnus-summary-limit (gnus-sorted-nunion old new))))
12421     (gnus-summary-position-point)))
12422
12423 (gnus-summary-make-all-marking-commands)
12424
12425 (gnus-ems-redefine)
12426
12427 (provide 'gnus-sum)
12428
12429 (run-hooks 'gnus-sum-load-hook)
12430
12431 ;; Local Variables:
12432 ;; coding: iso-8859-1
12433 ;; End:
12434
12435 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12436 ;;; gnus-sum.el ends here