Merge from emacs--devo--0
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) 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.  If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 ;; For Emacs < 22.2.
29 (eval-and-compile
30   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
31 (eval-when-compile
32   (require 'cl))
33
34 (defvar tool-bar-mode)
35 (defvar gnus-tmp-header)
36
37 (require 'gnus)
38 (require 'gnus-group)
39 (require 'gnus-spec)
40 (require 'gnus-range)
41 (require 'gnus-int)
42 (require 'gnus-undo)
43 (require 'gnus-util)
44 (require 'gmm-utils)
45 (require 'mm-decode)
46 (require 'nnoo)
47
48 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
49 (autoload 'gnus-cache-write-active "gnus-cache")
50 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
51 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
52 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
53 (autoload 'mm-uu-dissect "mm-uu")
54 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
55   "Deuglify broken Outlook (Express) articles and redisplay."
56   t)
57 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
58 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
59 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
60
61 (defcustom gnus-kill-summary-on-exit t
62   "*If non-nil, kill the summary buffer when you exit from it.
63 If nil, the summary will become a \"*Dead Summary*\" buffer, and
64 it will be killed sometime later."
65   :group 'gnus-summary-exit
66   :type 'boolean)
67
68 (defcustom gnus-summary-next-group-on-exit t
69   "If non-nil, go to the next unread newsgroup on summary exit.
70 See `gnus-group-goto-unread'."
71   :link '(custom-manual "(gnus)Group Maneuvering")
72   :group 'gnus-summary-exit
73   :version "23.1" ;; No Gnus
74   :type 'boolean)
75
76 (defcustom gnus-fetch-old-headers nil
77   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
78 If an unread article in the group refers to an older, already
79 read (or just marked as read) article, the old article will not
80 normally be displayed in the Summary buffer.  If this variable is
81 t, Gnus will attempt to grab the headers to the old articles, and
82 thereby build complete threads.  If it has the value `some', all
83 old headers will be fetched but only enough headers to connect
84 otherwise loose threads will be displayed.  This variable can
85 also be a number.  In that case, no more than that number of old
86 headers will be fetched.  If it has the value `invisible', all
87 old headers will be fetched, but none will be displayed.
88
89 The server has to support NOV for any of this to work.
90
91 This feature can seriously impact performance it ignores all
92 locally cached header entries.  Setting it to t for groups for a
93 server that doesn't expire articles (such as news.gmane.org),
94 leads to very slow summary generation."
95   :group 'gnus-thread
96   :type '(choice (const :tag "off" nil)
97                  (const :tag "on" t)
98                  (const some)
99                  (const invisible)
100                  number
101                  (sexp :menu-tag "other" t)))
102
103 (defcustom gnus-refer-thread-limit 500
104   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
105 If t, fetch all the available old headers."
106   :group 'gnus-thread
107   :type '(choice number
108                  (sexp :menu-tag "other" t)))
109
110 (defcustom gnus-summary-make-false-root 'adopt
111   "*nil means that Gnus won't gather loose threads.
112 If the root of a thread has expired or been read in a previous
113 session, the information necessary to build a complete thread has been
114 lost.  Instead of having many small sub-threads from this original thread
115 scattered all over the summary buffer, Gnus can gather them.
116
117 If non-nil, Gnus will try to gather all loose sub-threads from an
118 original thread into one large thread.
119
120 If this variable is non-nil, it should be one of `none', `adopt',
121 `dummy' or `empty'.
122
123 If this variable is `none', Gnus will not make a false root, but just
124 present the sub-threads after another.
125 If this variable is `dummy', Gnus will create a dummy root that will
126 have all the sub-threads as children.
127 If this variable is `adopt', Gnus will make one of the \"children\"
128 the parent and mark all the step-children as such.
129 If this variable is `empty', the \"children\" are printed with empty
130 subject fields.  (Or rather, they will be printed with a string
131 given by the `gnus-summary-same-subject' variable.)"
132   :group 'gnus-thread
133   :type '(choice (const :tag "off" nil)
134                  (const none)
135                  (const dummy)
136                  (const adopt)
137                  (const empty)))
138
139 (defcustom gnus-summary-make-false-root-always nil
140   "Always make a false dummy root."
141   :version "22.1"
142   :group 'gnus-thread
143   :type 'boolean)
144
145 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
146   "*A regexp to match subjects to be excluded from loose thread gathering.
147 As loose thread gathering is done on subjects only, that means that
148 there can be many false gatherings performed.  By rooting out certain
149 common subjects, gathering might become saner."
150   :group 'gnus-thread
151   :type 'regexp)
152
153 (defcustom gnus-summary-gather-subject-limit nil
154   "*Maximum length of subject comparisons when gathering loose threads.
155 Use nil to compare full subjects.  Setting this variable to a low
156 number will help gather threads that have been corrupted by
157 newsreaders chopping off subject lines, but it might also mean that
158 unrelated articles that have subject that happen to begin with the
159 same few characters will be incorrectly gathered.
160
161 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
162 comparing subjects."
163   :group 'gnus-thread
164   :type '(choice (const :tag "off" nil)
165                  (const fuzzy)
166                  (sexp :menu-tag "on" t)))
167
168 (defcustom gnus-simplify-subject-functions nil
169   "List of functions taking a string argument that simplify subjects.
170 The functions are applied recursively.
171
172 Useful functions to put in this list include:
173 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
174 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
175   :group 'gnus-thread
176   :type '(repeat function))
177
178 (defcustom gnus-simplify-ignored-prefixes nil
179   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
180   :group 'gnus-thread
181   :type '(choice (const :tag "off" nil)
182                  regexp))
183
184 (defcustom gnus-build-sparse-threads nil
185   "*If non-nil, fill in the gaps in threads.
186 If `some', only fill in the gaps that are needed to tie loose threads
187 together.  If `more', fill in all leaf nodes that Gnus can find.  If
188 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
189   :group 'gnus-thread
190   :type '(choice (const :tag "off" nil)
191                  (const some)
192                  (const more)
193                  (sexp :menu-tag "all" t)))
194
195 (defcustom gnus-summary-thread-gathering-function
196   'gnus-gather-threads-by-subject
197   "*Function used for gathering loose threads.
198 There are two pre-defined functions: `gnus-gather-threads-by-subject',
199 which only takes Subjects into consideration; and
200 `gnus-gather-threads-by-references', which compared the References
201 headers of the articles to find matches."
202   :group 'gnus-thread
203   :type '(radio (function-item gnus-gather-threads-by-subject)
204                 (function-item gnus-gather-threads-by-references)
205                 (function :tag "other")))
206
207 (defcustom gnus-summary-same-subject ""
208   "*String indicating that the current article has the same subject as the previous.
209 This variable will only be used if the value of
210 `gnus-summary-make-false-root' is `empty'."
211   :group 'gnus-summary-format
212   :type 'string)
213
214 (defcustom gnus-summary-goto-unread t
215   "*If t, many commands will go to the next unread article.
216 This applies to marking commands as well as other commands that
217 \"naturally\" select the next article, like, for instance, `SPC' at
218 the end of an article.
219
220 If nil, the marking commands do NOT go to the next unread article
221 \(they go to the next article instead).  If `never', commands that
222 usually go to the next unread article, will go to the next article,
223 whether it is read or not."
224   :group 'gnus-summary-marks
225   :link '(custom-manual "(gnus)Setting Marks")
226   :type '(choice (const :tag "off" nil)
227                  (const never)
228                  (sexp :menu-tag "on" t)))
229
230 (defcustom gnus-summary-default-score 0
231   "*Default article score level.
232 All scores generated by the score files will be added to this score.
233 If this variable is nil, scoring will be disabled."
234   :group 'gnus-score-default
235   :type '(choice (const :tag "disable")
236                  integer))
237
238 (defcustom gnus-summary-default-high-score 0
239   "*Default threshold for a high scored article.
240 An article will be highlighted as high scored if its score is greater
241 than this score."
242   :version "22.1"
243   :group 'gnus-score-default
244   :type 'integer)
245
246 (defcustom gnus-summary-default-low-score 0
247   "*Default threshold for a low scored article.
248 An article will be highlighted as low scored if its score is smaller
249 than this score."
250   :version "22.1"
251   :group 'gnus-score-default
252   :type 'integer)
253
254 (defcustom gnus-summary-zcore-fuzz 0
255   "*Fuzziness factor for the zcore in the summary buffer.
256 Articles with scores closer than this to `gnus-summary-default-score'
257 will not be marked."
258   :group 'gnus-summary-format
259   :type 'integer)
260
261 (defcustom gnus-simplify-subject-fuzzy-regexp nil
262   "*Strings to be removed when doing fuzzy matches.
263 This can either be a regular expression or list of regular expressions
264 that will be removed from subject strings if fuzzy subject
265 simplification is selected."
266   :group 'gnus-thread
267   :type '(repeat regexp))
268
269 (defcustom gnus-show-threads t
270   "*If non-nil, display threads in summary mode."
271   :group 'gnus-thread
272   :type 'boolean)
273
274 (defcustom gnus-thread-hide-subtree nil
275   "*If non-nil, hide all threads initially.
276 This can be a predicate specifier which says which threads to hide.
277 If threads are hidden, you have to run the command
278 `gnus-summary-show-thread' by hand or select an article."
279   :group 'gnus-thread
280   :type '(radio (sexp :format "Non-nil\n"
281                       :match (lambda (widget value)
282                                (not (or (consp value) (functionp value))))
283                       :value t)
284                 (const nil)
285                 (sexp :tag "Predicate specifier")))
286
287 (defcustom gnus-thread-hide-killed t
288   "*If non-nil, hide killed threads automatically."
289   :group 'gnus-thread
290   :type 'boolean)
291
292 (defcustom gnus-thread-ignore-subject t
293   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
294 If nil, articles that have different subjects from their parents will
295 start separate threads."
296   :group 'gnus-thread
297   :type 'boolean)
298
299 (defcustom gnus-thread-operation-ignore-subject t
300   "*If non-nil, subjects will be ignored when doing thread commands.
301 This affects commands like `gnus-summary-kill-thread' and
302 `gnus-summary-lower-thread'.
303
304 If this variable is nil, articles in the same thread with different
305 subjects will not be included in the operation in question.  If this
306 variable is `fuzzy', only articles that have subjects that are fuzzily
307 equal will be included."
308   :group 'gnus-thread
309   :type '(choice (const :tag "off" nil)
310                  (const fuzzy)
311                  (sexp :tag "on" t)))
312
313 (defcustom gnus-thread-indent-level 4
314   "*Number that says how much each sub-thread should be indented."
315   :group 'gnus-thread
316   :type 'integer)
317
318 (defcustom gnus-auto-extend-newsgroup t
319   "*If non-nil, extend newsgroup forward and backward when requested."
320   :group 'gnus-summary-choose
321   :type 'boolean)
322
323 (defcustom gnus-auto-select-first t
324   "If non-nil, select an article on group entry.
325 An article is selected automatically when entering a group
326 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
327 `gnus-summary-catchup-and-goto-next-group'.
328
329 Which article is selected is controlled by the variable
330 `gnus-auto-select-subject'.
331
332 If you want to prevent automatic selection of articles in some
333 newsgroups, set the variable to nil in `gnus-select-group-hook'."
334   ;; Commands include...
335   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
336   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
337   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
338   :group 'gnus-group-select
339   :type '(choice (const :tag "none" nil)
340                  (sexp :menu-tag "first" t)))
341
342 (defcustom gnus-auto-select-subject 'unread
343   "*Says what subject to place under point when entering a group.
344
345 This variable can either be the symbols `first' (place point on the
346 first subject), `unread' (place point on the subject line of the first
347 unread article), `best' (place point on the subject line of the
348 higest-scored article), `unseen' (place point on the subject line of
349 the first unseen article), `unseen-or-unread' (place point on the subject
350 line of the first unseen article or, if all article have been seen, on the
351 subject line of the first unread article), or a function to be called to
352 place point on some subject line."
353   :version "22.1"
354   :group 'gnus-group-select
355   :type '(choice (const best)
356                  (const unread)
357                  (const first)
358                  (const unseen)
359                  (const unseen-or-unread)))
360
361 (defcustom gnus-auto-select-next t
362   "*If non-nil, offer to go to the next group from the end of the previous.
363 If the value is t and the next newsgroup is empty, Gnus will exit
364 summary mode and go back to group mode.  If the value is neither nil
365 nor t, Gnus will select the following unread newsgroup.  In
366 particular, if the value is the symbol `quietly', the next unread
367 newsgroup will be selected without any confirmation, and if it is
368 `almost-quietly', the next group will be selected without any
369 confirmation if you are located on the last article in the group.
370 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
371 will go to the next group without confirmation."
372   :group 'gnus-summary-maneuvering
373   :type '(choice (const :tag "off" nil)
374                  (const quietly)
375                  (const almost-quietly)
376                  (const slightly-quietly)
377                  (sexp :menu-tag "on" t)))
378
379 (defcustom gnus-auto-select-same nil
380   "*If non-nil, select the next article with the same subject.
381 If there are no more articles with the same subject, go to
382 the first unread article."
383   :group 'gnus-summary-maneuvering
384   :type 'boolean)
385
386 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
387   "What article should be selected after exiting an ephemeral group.
388 Valid values include:
389
390 `next'
391   Select the next article.
392 `next-unread'
393   Select the next unread article.
394 `next-noselect'
395   Move the cursor to the next article.  This is the default.
396 `next-unread-noselect'
397   Move the cursor to the next unread article.
398
399 If it has any other value or there is no next (unread) article, the
400 article selected before entering to the ephemeral group will appear."
401   :version "23.1" ;; No Gnus
402   :group 'gnus-summary-maneuvering
403   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
404                  (const next) (const next-unread)
405                  (const next-noselect) (const next-unread-noselect)
406                  (sexp :tag "other" :value nil)))
407
408 (defcustom gnus-auto-goto-ignores 'unfetched
409   "*Says how to handle unfetched articles when maneuvering.
410
411 This variable can either be the symbols nil (maneuver to any
412 article), `undownloaded' (maneuvering while unplugged ignores articles
413 that have not been fetched), `always-undownloaded' (maneuvering always
414 ignores articles that have not been fetched), `unfetched' (maneuvering
415 ignores articles whose headers have not been fetched).
416
417 NOTE: The list of unfetched articles will always be nil when plugged
418 and, when unplugged, a subset of the undownloaded article list."
419   :version "22.1"
420   :group 'gnus-summary-maneuvering
421   :type '(choice (const :tag "None" nil)
422                  (const :tag "Undownloaded when unplugged" undownloaded)
423                  (const :tag "Undownloaded" always-undownloaded)
424                  (const :tag "Unfetched" unfetched)))
425
426 (defcustom gnus-summary-check-current nil
427   "*If non-nil, consider the current article when moving.
428 The \"unread\" movement commands will stay on the same line if the
429 current article is unread."
430   :group 'gnus-summary-maneuvering
431   :type 'boolean)
432
433 (defcustom gnus-auto-center-summary 2
434   "*If non-nil, always center the current summary buffer.
435 In particular, if `vertical' do only vertical recentering.  If non-nil
436 and non-`vertical', do both horizontal and vertical recentering."
437   :group 'gnus-summary-maneuvering
438   :type '(choice (const :tag "none" nil)
439                  (const vertical)
440                  (integer :tag "height")
441                  (sexp :menu-tag "both" t)))
442
443 (defvar gnus-auto-center-group t
444   "*If non-nil, always center the group buffer.")
445
446 (defcustom gnus-show-all-headers nil
447   "*If non-nil, don't hide any headers."
448   :group 'gnus-article-hiding
449   :group 'gnus-article-headers
450   :type 'boolean)
451
452 (defcustom gnus-summary-ignore-duplicates nil
453   "*If non-nil, ignore articles with identical Message-ID headers."
454   :group 'gnus-summary
455   :type 'boolean)
456
457 (defcustom gnus-single-article-buffer t
458   "*If non-nil, display all articles in the same buffer.
459 If nil, each group will get its own article buffer."
460   :group 'gnus-article-various
461   :type 'boolean)
462
463 (defcustom gnus-break-pages t
464   "*If non-nil, do page breaking on articles.
465 The page delimiter is specified by the `gnus-page-delimiter'
466 variable."
467   :group 'gnus-article-various
468   :type 'boolean)
469
470 (defcustom gnus-move-split-methods nil
471   "*Variable used to suggest where articles are to be moved to.
472 It uses the same syntax as the `gnus-split-methods' variable.
473 However, whereas `gnus-split-methods' specifies file names as targets,
474 this variable specifies group names."
475   :group 'gnus-summary-mail
476   :type '(repeat (choice (list :value (fun) function)
477                          (cons :value ("" "") regexp (repeat string))
478                          (sexp :value nil))))
479
480 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
481   "Function used to compute default prefix for article move/copy/etc prompts.
482 The function should take one argument, a group name, and return a
483 string with the suggested prefix."
484   :group 'gnus-summary-mail
485   :type 'function)
486
487 ;; FIXME: Although the custom type is `character' for the following variables,
488 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
489
490 (defcustom gnus-unread-mark ?           ;Whitespace
491   "*Mark used for unread articles."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-ticked-mark ?!
496   "*Mark used for ticked articles."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-dormant-mark ??
501   "*Mark used for dormant articles."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-del-mark ?r
506   "*Mark used for del'd articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-read-mark ?R
511   "*Mark used for read articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-expirable-mark ?E
516   "*Mark used for expirable articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-killed-mark ?K
521   "*Mark used for killed articles."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-spam-mark ?$
526   "*Mark used for spam articles."
527   :version "22.1"
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-souped-mark ?F
532   "*Mark used for souped articles."
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-kill-file-mark ?X
537   "*Mark used for articles killed by kill files."
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-low-score-mark ?Y
542   "*Mark used for articles with a low score."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-catchup-mark ?C
547   "*Mark used for articles that are caught up."
548   :group 'gnus-summary-marks
549   :type 'character)
550
551 (defcustom gnus-replied-mark ?A
552   "*Mark used for articles that have been replied to."
553   :group 'gnus-summary-marks
554   :type 'character)
555
556 (defcustom gnus-forwarded-mark ?F
557   "*Mark used for articles that have been forwarded."
558   :version "22.1"
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-recent-mark ?N
563   "*Mark used for articles that are recent."
564   :version "22.1"
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-cached-mark ?*
569   "*Mark used for articles that are in the cache."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-saved-mark ?S
574   "*Mark used for articles that have been saved."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-unseen-mark ?.
579   "*Mark used for articles that haven't been seen."
580   :version "22.1"
581   :group 'gnus-summary-marks
582   :type 'character)
583
584 (defcustom gnus-no-mark ?               ;Whitespace
585   "*Mark used for articles that have no other secondary mark."
586   :version "22.1"
587   :group 'gnus-summary-marks
588   :type 'character)
589
590 (defcustom gnus-ancient-mark ?O
591   "*Mark used for ancient articles."
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-sparse-mark ?Q
596   "*Mark used for sparsely reffed articles."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-canceled-mark ?G
601   "*Mark used for canceled articles."
602   :group 'gnus-summary-marks
603   :type 'character)
604
605 (defcustom gnus-duplicate-mark ?M
606   "*Mark used for duplicate articles."
607   :group 'gnus-summary-marks
608   :type 'character)
609
610 (defcustom gnus-undownloaded-mark ?-
611   "*Mark used for articles that weren't downloaded."
612   :version "22.1"
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-downloaded-mark ?+
617   "*Mark used for articles that were downloaded."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-downloadable-mark ?%
622   "*Mark used for articles that are to be downloaded."
623   :group 'gnus-summary-marks
624   :type 'character)
625
626 (defcustom gnus-unsendable-mark ?=
627   "*Mark used for articles that won't be sent."
628   :group 'gnus-summary-marks
629   :type 'character)
630
631 (defcustom gnus-score-over-mark ?+
632   "*Score mark used for articles with high scores."
633   :group 'gnus-summary-marks
634   :type 'character)
635
636 (defcustom gnus-score-below-mark ?-
637   "*Score mark used for articles with low scores."
638   :group 'gnus-summary-marks
639   :type 'character)
640
641 (defcustom gnus-empty-thread-mark ?     ;Whitespace
642   "*There is no thread under the article."
643   :group 'gnus-summary-marks
644   :type 'character)
645
646 (defcustom gnus-not-empty-thread-mark ?=
647   "*There is a thread under the article."
648   :group 'gnus-summary-marks
649   :type 'character)
650
651 (defcustom gnus-view-pseudo-asynchronously nil
652   "*If non-nil, Gnus will view pseudo-articles asynchronously."
653   :group 'gnus-extract-view
654   :type 'boolean)
655
656 (defcustom gnus-auto-expirable-marks
657   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
658         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
659         gnus-souped-mark gnus-duplicate-mark)
660   "*The list of marks converted into expiration if a group is auto-expirable."
661   :version "21.1"
662   :group 'gnus-summary
663   :type '(repeat character))
664
665 (defcustom gnus-inhibit-user-auto-expire t
666   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
667   :version "21.1"
668   :group 'gnus-summary
669   :type 'boolean)
670
671 (defcustom gnus-view-pseudos nil
672   "*If `automatic', pseudo-articles will be viewed automatically.
673 If `not-confirm', pseudos will be viewed automatically, and the user
674 will not be asked to confirm the command."
675   :group 'gnus-extract-view
676   :type '(choice (const :tag "off" nil)
677                  (const automatic)
678                  (const not-confirm)))
679
680 (defcustom gnus-view-pseudos-separately t
681   "*If non-nil, one pseudo-article will be created for each file to be viewed.
682 If nil, all files that use the same viewing command will be given as a
683 list of parameters to that command."
684   :group 'gnus-extract-view
685   :type 'boolean)
686
687 (defcustom gnus-insert-pseudo-articles t
688   "*If non-nil, insert pseudo-articles when decoding articles."
689   :group 'gnus-extract-view
690   :type 'boolean)
691
692 (defcustom gnus-summary-dummy-line-format
693   "   %(:                             :%) %S\n"
694   "*The format specification for the dummy roots in the summary buffer.
695 It works along the same lines as a normal formatting string,
696 with some simple extensions.
697
698 %S  The subject
699
700 General format specifiers can also be used.
701 See `(gnus)Formatting Variables'."
702   :link '(custom-manual "(gnus)Formatting Variables")
703   :group 'gnus-threading
704   :type 'string)
705
706 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
707   "*The format specification for the summary mode line.
708 It works along the same lines as a normal formatting string,
709 with some simple extensions:
710
711 %G  Group name
712 %p  Unprefixed group name
713 %A  Current article number
714 %z  Current article score
715 %V  Gnus version
716 %U  Number of unread articles in the group
717 %e  Number of unselected articles in the group
718 %Z  A string with unread/unselected article counts
719 %g  Shortish group name
720 %S  Subject of the current article
721 %u  User-defined spec
722 %s  Current score file name
723 %d  Number of dormant articles
724 %r  Number of articles that have been marked as read in this session
725 %E  Number of articles expunged by the score files"
726   :group 'gnus-summary-format
727   :type 'string)
728
729 (defcustom gnus-list-identifiers nil
730   "Regexp that matches list identifiers to be removed from subject.
731 This can also be a list of regexps."
732   :version "21.1"
733   :group 'gnus-summary-format
734   :group 'gnus-article-hiding
735   :type '(choice (const :tag "none" nil)
736                  (regexp :value ".*")
737                  (repeat :value (".*") regexp)))
738
739 (defcustom gnus-summary-mark-below 0
740   "*Mark all articles with a score below this variable as read.
741 This variable is local to each summary buffer and usually set by the
742 score file."
743   :group 'gnus-score-default
744   :type 'integer)
745
746 (defun gnus-widget-reversible-match (widget value)
747   "Ignoring WIDGET, convert VALUE to internal form.
748 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
749   ;; (debug value)
750   (or (symbolp value)
751       (and (listp value)
752            (eq (length value) 2)
753            (eq (nth 0 value) 'not)
754            (symbolp (nth 1 value)))))
755
756 (defun gnus-widget-reversible-to-internal (widget value)
757   "Ignoring WIDGET, convert VALUE to internal form.
758 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
759 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
760   ;; (debug value)
761   (if (atom value)
762       (list value nil)
763     (list (nth 1 value) t)))
764
765 (defun gnus-widget-reversible-to-external (widget value)
766   "Ignoring WIDGET, convert VALUE to external form.
767 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
768 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
769   ;; (debug value)
770   (if (nth 1 value)
771       (list 'not (nth 0 value))
772     (nth 0 value)))
773
774 (define-widget 'gnus-widget-reversible 'group
775   "A `group' that convert values."
776   :match 'gnus-widget-reversible-match
777   :value-to-internal 'gnus-widget-reversible-to-internal
778   :value-to-external 'gnus-widget-reversible-to-external)
779
780 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
781   "*List of functions used for sorting articles in the summary buffer.
782
783 Each function takes two articles and returns non-nil if the first
784 article should be sorted before the other.  If you use more than one
785 function, the primary sort function should be the last.  You should
786 probably always include `gnus-article-sort-by-number' in the list of
787 sorting functions -- preferably first.  Also note that sorting by date
788 is often much slower than sorting by number, and the sorting order is
789 very similar.  (Sorting by date means sorting by the time the message
790 was sent, sorting by number means sorting by arrival time.)
791
792 Each item can also be a list `(not F)' where F is a function;
793 this reverses the sort order.
794
795 Ready-made functions include `gnus-article-sort-by-number',
796 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
797 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
798 and `gnus-article-sort-by-score'.
799
800 When threading is turned on, the variable `gnus-thread-sort-functions'
801 controls how articles are sorted."
802   :group 'gnus-summary-sort
803   :type '(repeat (gnus-widget-reversible
804                   (choice (function-item gnus-article-sort-by-number)
805                           (function-item gnus-article-sort-by-author)
806                           (function-item gnus-article-sort-by-subject)
807                           (function-item gnus-article-sort-by-date)
808                           (function-item gnus-article-sort-by-score)
809                           (function-item gnus-article-sort-by-random)
810                           (function :tag "other"))
811                   (boolean :tag "Reverse order"))))
812
813
814 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
815   "*List of functions used for sorting threads in the summary buffer.
816 By default, threads are sorted by article number.
817
818 Each function takes two threads and returns non-nil if the first
819 thread should be sorted before the other.  If you use more than one
820 function, the primary sort function should be the last.  You should
821 probably always include `gnus-thread-sort-by-number' in the list of
822 sorting functions -- preferably first.  Also note that sorting by date
823 is often much slower than sorting by number, and the sorting order is
824 very similar.  (Sorting by date means sorting by the time the message
825 was sent, sorting by number means sorting by arrival time.)
826
827 Each list item can also be a list `(not F)' where F is a
828 function; this specifies reversed sort order.
829
830 Ready-made functions include `gnus-thread-sort-by-number',
831 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
832 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
833 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
834 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
835 and `gnus-thread-sort-by-total-score' (see
836 `gnus-thread-score-function').
837
838 When threading is turned off, the variable
839 `gnus-article-sort-functions' controls how articles are sorted."
840   :group 'gnus-summary-sort
841   :type '(repeat
842           (gnus-widget-reversible
843            (choice (function-item gnus-thread-sort-by-number)
844                    (function-item gnus-thread-sort-by-author)
845                    (function-item gnus-thread-sort-by-recipient)
846                    (function-item gnus-thread-sort-by-subject)
847                    (function-item gnus-thread-sort-by-date)
848                    (function-item gnus-thread-sort-by-score)
849                    (function-item gnus-thread-sort-by-most-recent-number)
850                    (function-item gnus-thread-sort-by-most-recent-date)
851                    (function-item gnus-thread-sort-by-random)
852                    (function-item gnus-thread-sort-by-total-score)
853                    (function :tag "other"))
854            (boolean :tag "Reverse order"))))
855
856 (defcustom gnus-thread-score-function '+
857   "*Function used for calculating the total score of a thread.
858
859 The function is called with the scores of the article and each
860 subthread and should then return the score of the thread.
861
862 Some functions you can use are `+', `max', or `min'."
863   :group 'gnus-summary-sort
864   :type 'function)
865
866 (defcustom gnus-summary-expunge-below nil
867   "All articles that have a score less than this variable will be expunged.
868 This variable is local to the summary buffers."
869   :group 'gnus-score-default
870   :type '(choice (const :tag "off" nil)
871                  integer))
872
873 (defcustom gnus-thread-expunge-below nil
874   "All threads that have a total score less than this variable will be expunged.
875 See `gnus-thread-score-function' for en explanation of what a
876 \"thread score\" is.
877
878 This variable is local to the summary buffers."
879   :group 'gnus-threading
880   :group 'gnus-score-default
881   :type '(choice (const :tag "off" nil)
882                  integer))
883
884 (defcustom gnus-summary-mode-hook nil
885   "*A hook for Gnus summary mode.
886 This hook is run before any variables are set in the summary buffer."
887   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
888   :group 'gnus-summary-various
889   :type 'hook)
890
891 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
892 (when (featurep 'xemacs)
893   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
894   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
895   (add-hook 'gnus-summary-mode-hook
896             'gnus-xmas-switch-horizontal-scrollbar-off))
897
898 (defcustom gnus-summary-menu-hook nil
899   "*Hook run after the creation of the summary mode menu."
900   :group 'gnus-summary-visual
901   :type 'hook)
902
903 (defcustom gnus-summary-exit-hook nil
904   "*A hook called on exit from the summary buffer.
905 It will be called with point in the group buffer."
906   :group 'gnus-summary-exit
907   :type 'hook)
908
909 (defcustom gnus-summary-prepare-hook nil
910   "*A hook called after the summary buffer has been generated.
911 If you want to modify the summary buffer, you can use this hook."
912   :group 'gnus-summary-various
913   :type 'hook)
914
915 (defcustom gnus-summary-prepared-hook nil
916   "*A hook called as the last thing after the summary buffer has been generated."
917   :group 'gnus-summary-various
918   :type 'hook)
919
920 (defcustom gnus-summary-generate-hook nil
921   "*A hook run just before generating the summary buffer.
922 This hook is commonly used to customize threading variables and the
923 like."
924   :group 'gnus-summary-various
925   :type 'hook)
926
927 (defcustom gnus-select-group-hook nil
928   "*A hook called when a newsgroup is selected.
929
930 If you'd like to simplify subjects like the
931 `gnus-summary-next-same-subject' command does, you can use the
932 following hook:
933
934  (add-hook gnus-select-group-hook
935            (lambda ()
936              (mapcar (lambda (header)
937                        (mail-header-set-subject
938                         header
939                         (gnus-simplify-subject
940                          (mail-header-subject header) 're-only)))
941                      gnus-newsgroup-headers)))"
942   :group 'gnus-group-select
943   :type 'hook)
944
945 (defcustom gnus-select-article-hook nil
946   "*A hook called when an article is selected."
947   :group 'gnus-summary-choose
948   :options '(gnus-agent-fetch-selected-article)
949   :type 'hook)
950
951 (defcustom gnus-visual-mark-article-hook
952   (list 'gnus-highlight-selected-summary)
953   "*Hook run after selecting an article in the summary buffer.
954 It is meant to be used for highlighting the article in some way.  It
955 is not run if `gnus-visual' is nil."
956   :group 'gnus-summary-visual
957   :type 'hook)
958
959 (defcustom gnus-parse-headers-hook nil
960   "*A hook called before parsing the headers."
961   :group 'gnus-various
962   :type 'hook)
963
964 (defcustom gnus-exit-group-hook nil
965   "*A hook called when exiting summary mode.
966 This hook is not called from the non-updating exit commands like `Q'."
967   :group 'gnus-various
968   :type 'hook)
969
970 (defcustom gnus-summary-update-hook
971   (list 'gnus-summary-highlight-line)
972   "*A hook called when a summary line is changed.
973 The hook will not be called if `gnus-visual' is nil.
974
975 The default function `gnus-summary-highlight-line' will
976 highlight the line according to the `gnus-summary-highlight'
977 variable."
978   :group 'gnus-summary-visual
979   :type 'hook)
980
981 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
982   "*A hook called when an article is selected for the first time.
983 The hook is intended to mark an article as read (or unread)
984 automatically when it is selected."
985   :group 'gnus-summary-choose
986   :type 'hook)
987
988 (defcustom gnus-group-no-more-groups-hook nil
989   "*A hook run when returning to group mode having no more (unread) groups."
990   :group 'gnus-group-select
991   :type 'hook)
992
993 (defcustom gnus-ps-print-hook nil
994   "*A hook run before ps-printing something from Gnus."
995   :group 'gnus-summary
996   :type 'hook)
997
998 (defcustom gnus-summary-article-move-hook nil
999   "*A hook called after an article is moved, copied, respooled, or crossposted."
1000   :version "22.1"
1001   :group 'gnus-summary
1002   :type 'hook)
1003
1004 (defcustom gnus-summary-article-delete-hook nil
1005   "*A hook called after an article is deleted."
1006   :version "22.1"
1007   :group 'gnus-summary
1008   :type 'hook)
1009
1010 (defcustom gnus-summary-article-expire-hook nil
1011   "*A hook called after an article is expired."
1012   :version "22.1"
1013   :group 'gnus-summary
1014   :type 'hook)
1015
1016 (defcustom gnus-summary-display-arrow
1017   (and (fboundp 'display-graphic-p)
1018        (display-graphic-p))
1019   "*If non-nil, display an arrow highlighting the current article."
1020   :version "22.1"
1021   :group 'gnus-summary
1022   :type 'boolean)
1023
1024 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1025   "Face used for highlighting the current article in the summary buffer."
1026   :group 'gnus-summary-visual
1027   :type 'face)
1028
1029 (defvar gnus-tmp-downloaded nil)
1030
1031 (defcustom gnus-summary-highlight
1032   '(((eq mark gnus-canceled-mark)
1033      . gnus-summary-cancelled)
1034     ((and uncached (> score default-high))
1035      . gnus-summary-high-undownloaded)
1036     ((and uncached (< score default-low))
1037      . gnus-summary-low-undownloaded)
1038     (uncached
1039      . gnus-summary-normal-undownloaded)
1040     ((and (> score default-high)
1041           (or (eq mark gnus-dormant-mark)
1042               (eq mark gnus-ticked-mark)))
1043      . gnus-summary-high-ticked)
1044     ((and (< score default-low)
1045           (or (eq mark gnus-dormant-mark)
1046               (eq mark gnus-ticked-mark)))
1047      . gnus-summary-low-ticked)
1048     ((or (eq mark gnus-dormant-mark)
1049          (eq mark gnus-ticked-mark))
1050      . gnus-summary-normal-ticked)
1051     ((and (> score default-high) (eq mark gnus-ancient-mark))
1052      . gnus-summary-high-ancient)
1053     ((and (< score default-low) (eq mark gnus-ancient-mark))
1054      . gnus-summary-low-ancient)
1055     ((eq mark gnus-ancient-mark)
1056      . gnus-summary-normal-ancient)
1057     ((and (> score default-high) (eq mark gnus-unread-mark))
1058      . gnus-summary-high-unread)
1059     ((and (< score default-low) (eq mark gnus-unread-mark))
1060      . gnus-summary-low-unread)
1061     ((eq mark gnus-unread-mark)
1062      . gnus-summary-normal-unread)
1063     ((> score default-high)
1064      . gnus-summary-high-read)
1065     ((< score default-low)
1066      . gnus-summary-low-read)
1067     (t
1068      . gnus-summary-normal-read))
1069   "*Controls the highlighting of summary buffer lines.
1070
1071 A list of (FORM . FACE) pairs.  When deciding how a particular
1072 summary line should be displayed, each form is evaluated.  The content
1073 of the face field after the first true form is used.  You can change
1074 how those summary lines are displayed, by editing the face field.
1075
1076 You can use the following variables in the FORM field.
1077
1078 score:        The article's score.
1079 default:      The default article score.
1080 default-high: The default score for high scored articles.
1081 default-low:  The default score for low scored articles.
1082 below:        The score below which articles are automatically marked as read.
1083 mark:         The article's mark.
1084 uncached:     Non-nil if the article is uncached."
1085   :group 'gnus-summary-visual
1086   :type '(repeat (cons (sexp :tag "Form" nil)
1087                        face)))
1088 (put 'gnus-summary-highlight 'risky-local-variable t)
1089
1090 (defcustom gnus-alter-header-function nil
1091   "Function called to allow alteration of article header structures.
1092 The function is called with one parameter, the article header vector,
1093 which it may alter in any way."
1094   :type '(choice (const :tag "None" nil)
1095                  function)
1096   :group 'gnus-summary)
1097
1098 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1099   "Function used to decode a string with encoded words.")
1100
1101 (defvar gnus-decode-encoded-address-function
1102   'mail-decode-encoded-address-string
1103   "Function used to decode addresses with encoded words.")
1104
1105 (defcustom gnus-extra-headers '(To Newsgroups)
1106   "*Extra headers to parse."
1107   :version "21.1"
1108   :group 'gnus-summary
1109   :type '(repeat symbol))
1110
1111 (defcustom gnus-ignored-from-addresses
1112   (and user-mail-address
1113        (not (string= user-mail-address ""))
1114        (regexp-quote user-mail-address))
1115   "*From headers that may be suppressed in favor of To headers.
1116 This can be a regexp or a list of regexps."
1117   :version "21.1"
1118   :group 'gnus-summary
1119   :type '(choice regexp
1120                  (repeat :tag "Regexp List" regexp)))
1121
1122 (defsubst gnus-ignored-from-addresses ()
1123   (gmm-regexp-concat gnus-ignored-from-addresses))
1124
1125 (defcustom gnus-summary-to-prefix "-> "
1126   "*String prefixed to the To field in the summary line when
1127 using `gnus-ignored-from-addresses'."
1128   :version "22.1"
1129   :group 'gnus-summary
1130   :type 'string)
1131
1132 (defcustom gnus-summary-newsgroup-prefix "=> "
1133   "*String prefixed to the Newsgroup field in the summary
1134 line when using `gnus-ignored-from-addresses'."
1135   :version "22.1"
1136   :group 'gnus-summary
1137   :type 'string)
1138
1139 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1140   "List of charsets that should be ignored.
1141 When these charsets are used in the \"charset\" parameter, the
1142 default charset will be used instead."
1143   :version "21.1"
1144   :type '(repeat symbol)
1145   :group 'gnus-charset)
1146
1147 (defcustom gnus-newsgroup-maximum-articles nil
1148   "The maximum number of articles a newsgroup.
1149 If this is a number, old articles in a newsgroup exceeding this number
1150 are silently ignored.  If it is nil, no article is ignored.  Note that
1151 setting this variable to a number might prevent you from reading very
1152 old articles."
1153   :group 'gnus-group-select
1154   :version "22.2"
1155   :type '(choice (const :tag "No limit" nil)
1156                  integer))
1157
1158 (gnus-define-group-parameter
1159  ignored-charsets
1160  :type list
1161  :function-document
1162  "Return the ignored charsets of GROUP."
1163  :variable gnus-group-ignored-charsets-alist
1164  :variable-default
1165  '(("alt\\.chinese\\.text" iso-8859-1))
1166  :variable-document
1167  "Alist of regexps (to match group names) and charsets that should be ignored.
1168 When these charsets are used in the \"charset\" parameter, the
1169 default charset will be used instead."
1170  :variable-group gnus-charset
1171  :variable-type '(repeat (cons (regexp :tag "Group")
1172                                (repeat symbol)))
1173  :parameter-type '(choice :tag "Ignored charsets"
1174                           :value nil
1175                           (repeat (symbol)))
1176  :parameter-document       "\
1177 List of charsets that should be ignored.
1178
1179 When these charsets are used in the \"charset\" parameter, the
1180 default charset will be used instead.")
1181
1182 (defcustom gnus-group-highlight-words-alist nil
1183   "Alist of group regexps and highlight regexps.
1184 This variable uses the same syntax as `gnus-emphasis-alist'."
1185   :version "21.1"
1186   :type '(repeat (cons (regexp :tag "Group")
1187                        (repeat (list (regexp :tag "Highlight regexp")
1188                                      (number :tag "Group for entire word" 0)
1189                                      (number :tag "Group for displayed part" 0)
1190                                      (symbol :tag "Face"
1191                                              gnus-emphasis-highlight-words)))))
1192   :group 'gnus-summary-visual)
1193
1194 (defcustom gnus-summary-show-article-charset-alist
1195   nil
1196   "Alist of number and charset.
1197 The article will be shown with the charset corresponding to the
1198 numbered argument.
1199 For example: ((1 . cn-gb-2312) (2 . big5))."
1200   :version "21.1"
1201   :type '(repeat (cons (number :tag "Argument" 1)
1202                        (symbol :tag "Charset")))
1203   :group 'gnus-charset)
1204
1205 (defcustom gnus-preserve-marks t
1206   "Whether marks are preserved when moving, copying and respooling messages."
1207   :version "21.1"
1208   :type 'boolean
1209   :group 'gnus-summary-marks)
1210
1211 (defcustom gnus-propagate-marks t
1212   "If non-nil, do not propagate marks to the backends."
1213   :version "23.1" ;; No Gnus
1214   :type 'boolean
1215   :group 'gnus-summary-marks)
1216
1217 (defcustom gnus-alter-articles-to-read-function nil
1218   "Function to be called to alter the list of articles to be selected."
1219   :type '(choice (const nil) function)
1220   :group 'gnus-summary)
1221
1222 (defcustom gnus-orphan-score nil
1223   "*All orphans get this score added.  Set in the score file."
1224   :group 'gnus-score-default
1225   :type '(choice (const nil)
1226                  integer))
1227
1228 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1229   "*A regexp to match MIME parts when saving multiple parts of a
1230 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1231 This regexp will be used by default when prompting the user for which
1232 type of files to save."
1233   :group 'gnus-summary
1234   :type 'regexp)
1235
1236 (defcustom gnus-read-all-available-headers nil
1237   "Whether Gnus should parse all headers made available to it.
1238 This is mostly relevant for slow back ends where the user may
1239 wish to widen the summary buffer to include all headers
1240 that were fetched.  Say, for nnultimate groups."
1241   :version "22.1"
1242   :group 'gnus-summary
1243   :type '(choice boolean regexp))
1244
1245 (defcustom gnus-summary-muttprint-program "muttprint"
1246   "Command (and optional arguments) used to run Muttprint."
1247   :version "22.1"
1248   :group 'gnus-summary
1249   :type 'string)
1250
1251 (defcustom gnus-article-loose-mime t
1252   "If non-nil, don't require MIME-Version header.
1253 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1254 supply the MIME-Version header or deliberately strip it from the mail.
1255 If non-nil (the default), Gnus will treat some articles as MIME
1256 even if the MIME-Version header is missing."
1257   :version "22.1"
1258   :type 'boolean
1259   :group 'gnus-article-mime)
1260
1261 (defcustom gnus-article-emulate-mime t
1262   "If non-nil, use MIME emulation for uuencode and the like.
1263 This means that Gnus will search message bodies for text that look
1264 like uuencoded bits, yEncoded bits, and so on, and present that using
1265 the normal Gnus MIME machinery."
1266   :version "22.1"
1267   :type 'boolean
1268   :group 'gnus-article-mime)
1269
1270 ;;; Internal variables
1271
1272 (defvar gnus-summary-display-cache nil)
1273 (defvar gnus-article-mime-handles nil)
1274 (defvar gnus-article-decoded-p nil)
1275 (defvar gnus-article-charset nil)
1276 (defvar gnus-article-ignored-charsets nil)
1277 (defvar gnus-scores-exclude-files nil)
1278 (defvar gnus-page-broken nil)
1279
1280 (defvar gnus-original-article nil)
1281 (defvar gnus-article-internal-prepare-hook nil)
1282 (defvar gnus-newsgroup-process-stack nil)
1283
1284 (defvar gnus-thread-indent-array nil)
1285 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1286 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1287   "Function called to sort the articles within a thread after it has been gathered together.")
1288
1289 (defvar gnus-summary-save-parts-type-history nil)
1290 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1291
1292 ;; Avoid highlighting in kill files.
1293 (defvar gnus-summary-inhibit-highlight nil)
1294 (defvar gnus-newsgroup-selected-overlay nil)
1295 (defvar gnus-inhibit-limiting nil)
1296 (defvar gnus-newsgroup-adaptive-score-file nil)
1297 (defvar gnus-current-score-file nil)
1298 (defvar gnus-current-move-group nil)
1299 (defvar gnus-current-copy-group nil)
1300 (defvar gnus-current-crosspost-group nil)
1301 (defvar gnus-newsgroup-display nil)
1302
1303 (defvar gnus-newsgroup-dependencies nil)
1304 (defvar gnus-newsgroup-adaptive nil)
1305 (defvar gnus-summary-display-article-function nil)
1306 (defvar gnus-summary-highlight-line-function nil
1307   "Function called after highlighting a summary line.")
1308
1309 (defvar gnus-summary-line-format-alist
1310   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1311     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1312     (?s gnus-tmp-subject-or-nil ?s)
1313     (?n gnus-tmp-name ?s)
1314     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1315         ?s)
1316     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1317             gnus-tmp-from) ?s)
1318     (?F gnus-tmp-from ?s)
1319     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1320     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1321     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1322     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1323     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1324     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1325     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1326     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1327     (?L gnus-tmp-lines ?s)
1328     (?O gnus-tmp-downloaded ?c)
1329     (?I gnus-tmp-indentation ?s)
1330     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1331     (?R gnus-tmp-replied ?c)
1332     (?\[ gnus-tmp-opening-bracket ?c)
1333     (?\] gnus-tmp-closing-bracket ?c)
1334     (?\> (make-string gnus-tmp-level ? ) ?s)
1335     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1336     (?i gnus-tmp-score ?d)
1337     (?z gnus-tmp-score-char ?c)
1338     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1339     (?U gnus-tmp-unread ?c)
1340     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1341         ?s)
1342     (?t (gnus-summary-number-of-articles-in-thread
1343          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1344         ?d)
1345     (?e (gnus-summary-number-of-articles-in-thread
1346          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1347         ?c)
1348     (?u gnus-tmp-user-defined ?s)
1349     (?P (gnus-pick-line-number) ?d)
1350     (?B gnus-tmp-thread-tree-header-string ?s)
1351     (user-date (gnus-user-date
1352                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1353   "An alist of format specifications that can appear in summary lines.
1354 These are paired with what variables they correspond with, along with
1355 the type of the variable (string, integer, character, etc).")
1356
1357 (defvar gnus-summary-dummy-line-format-alist
1358   `((?S gnus-tmp-subject ?s)
1359     (?N gnus-tmp-number ?d)
1360     (?u gnus-tmp-user-defined ?s)))
1361
1362 (defvar gnus-summary-mode-line-format-alist
1363   `((?G gnus-tmp-group-name ?s)
1364     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1365     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1366     (?A gnus-tmp-article-number ?d)
1367     (?Z gnus-tmp-unread-and-unselected ?s)
1368     (?V gnus-version ?s)
1369     (?U gnus-tmp-unread-and-unticked ?d)
1370     (?S gnus-tmp-subject ?s)
1371     (?e gnus-tmp-unselected ?d)
1372     (?u gnus-tmp-user-defined ?s)
1373     (?d (length gnus-newsgroup-dormant) ?d)
1374     (?t (length gnus-newsgroup-marked) ?d)
1375     (?h (length gnus-newsgroup-spam-marked) ?d)
1376     (?r (length gnus-newsgroup-reads) ?d)
1377     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1378     (?E gnus-newsgroup-expunged-tally ?d)
1379     (?s (gnus-current-score-file-nondirectory) ?s)))
1380
1381 ;; This is here rather than in gnus-art for compilation reasons.
1382 (defvar gnus-article-mode-line-format-alist
1383   (nconc '((?w (gnus-article-wash-status) ?s)
1384            (?m (gnus-article-mime-part-status) ?s))
1385          gnus-summary-mode-line-format-alist))
1386
1387 (defvar gnus-last-search-regexp nil
1388   "Default regexp for article search command.")
1389
1390 (defvar gnus-last-shell-command nil
1391   "Default shell command on article.")
1392
1393 (defvar gnus-newsgroup-agentized nil
1394   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1395 (defvar gnus-newsgroup-begin nil)
1396 (defvar gnus-newsgroup-end nil)
1397 (defvar gnus-newsgroup-last-rmail nil)
1398 (defvar gnus-newsgroup-last-mail nil)
1399 (defvar gnus-newsgroup-last-folder nil)
1400 (defvar gnus-newsgroup-last-file nil)
1401 (defvar gnus-newsgroup-last-directory nil)
1402 (defvar gnus-newsgroup-auto-expire nil)
1403 (defvar gnus-newsgroup-active nil)
1404
1405 (defvar gnus-newsgroup-data nil)
1406 (defvar gnus-newsgroup-data-reverse nil)
1407 (defvar gnus-newsgroup-limit nil)
1408 (defvar gnus-newsgroup-limits nil)
1409 (defvar gnus-summary-use-undownloaded-faces nil)
1410
1411 (defvar gnus-newsgroup-unreads nil
1412   "Sorted list of unread articles in the current newsgroup.")
1413
1414 (defvar gnus-newsgroup-unselected nil
1415   "Sorted list of unselected unread articles in the current newsgroup.")
1416
1417 (defvar gnus-newsgroup-reads nil
1418   "Alist of read articles and article marks in the current newsgroup.")
1419
1420 (defvar gnus-newsgroup-expunged-tally nil)
1421
1422 (defvar gnus-newsgroup-marked nil
1423   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1424
1425 (defvar gnus-newsgroup-spam-marked nil
1426   "List of ranges of articles that have been marked as spam.")
1427
1428 (defvar gnus-newsgroup-killed nil
1429   "List of ranges of articles that have been through the scoring process.")
1430
1431 (defvar gnus-newsgroup-cached nil
1432   "Sorted list of articles that come from the article cache.")
1433
1434 (defvar gnus-newsgroup-saved nil
1435   "List of articles that have been saved.")
1436
1437 (defvar gnus-newsgroup-kill-headers nil)
1438
1439 (defvar gnus-newsgroup-replied nil
1440   "List of articles that have been replied to in the current newsgroup.")
1441
1442 (defvar gnus-newsgroup-forwarded nil
1443   "List of articles that have been forwarded in the current newsgroup.")
1444
1445 (defvar gnus-newsgroup-recent nil
1446   "List of articles that have are recent in the current newsgroup.")
1447
1448 (defvar gnus-newsgroup-expirable nil
1449   "Sorted list of articles in the current newsgroup that can be expired.")
1450
1451 (defvar gnus-newsgroup-processable nil
1452   "List of articles in the current newsgroup that can be processed.")
1453
1454 (defvar gnus-newsgroup-downloadable nil
1455   "Sorted list of articles in the current newsgroup that can be processed.")
1456
1457 (defvar gnus-newsgroup-unfetched nil
1458   "Sorted list of articles in the current newsgroup whose headers have
1459 not been fetched into the agent.
1460
1461 This list will always be a subset of gnus-newsgroup-undownloaded.")
1462
1463 (defvar gnus-newsgroup-undownloaded nil
1464   "List of articles in the current newsgroup that haven't been downloaded.")
1465
1466 (defvar gnus-newsgroup-unsendable nil
1467   "List of articles in the current newsgroup that won't be sent.")
1468
1469 (defvar gnus-newsgroup-bookmarks nil
1470   "List of articles in the current newsgroup that have bookmarks.")
1471
1472 (defvar gnus-newsgroup-dormant nil
1473   "Sorted list of dormant articles in the current newsgroup.")
1474
1475 (defvar gnus-newsgroup-unseen nil
1476   "List of unseen articles in the current newsgroup.")
1477
1478 (defvar gnus-newsgroup-seen nil
1479   "Range of seen articles in the current newsgroup.")
1480
1481 (defvar gnus-newsgroup-articles nil
1482   "List of articles in the current newsgroup.")
1483
1484 (defvar gnus-newsgroup-scored nil
1485   "List of scored articles in the current newsgroup.")
1486
1487 (defvar gnus-newsgroup-headers nil
1488   "List of article headers in the current newsgroup.")
1489
1490 (defvar gnus-newsgroup-threads nil)
1491
1492 (defvar gnus-newsgroup-prepared nil
1493   "Whether the current group has been prepared properly.")
1494
1495 (defvar gnus-newsgroup-ancient nil
1496   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1497
1498 (defvar gnus-newsgroup-sparse nil)
1499
1500 (defvar gnus-current-article nil)
1501 (defvar gnus-article-current nil)
1502 (defvar gnus-current-headers nil)
1503 (defvar gnus-have-all-headers nil)
1504 (defvar gnus-last-article nil)
1505 (defvar gnus-newsgroup-history nil)
1506 (defvar gnus-newsgroup-charset nil)
1507 (defvar gnus-newsgroup-ephemeral-charset nil)
1508 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1509
1510 (defvar gnus-article-before-search nil)
1511
1512 (defvar gnus-summary-local-variables
1513   '(gnus-newsgroup-name
1514     gnus-newsgroup-begin gnus-newsgroup-end
1515     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1516     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1517     gnus-newsgroup-last-directory
1518     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1519     gnus-newsgroup-unselected gnus-newsgroup-marked
1520     gnus-newsgroup-spam-marked
1521     gnus-newsgroup-reads gnus-newsgroup-saved
1522     gnus-newsgroup-replied gnus-newsgroup-forwarded
1523     gnus-newsgroup-recent
1524     gnus-newsgroup-expirable
1525     gnus-newsgroup-processable gnus-newsgroup-killed
1526     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1527     gnus-newsgroup-unfetched
1528     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1529     gnus-newsgroup-seen gnus-newsgroup-articles
1530     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1531     gnus-newsgroup-headers gnus-newsgroup-threads
1532     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1533     gnus-current-article gnus-current-headers gnus-have-all-headers
1534     gnus-last-article gnus-article-internal-prepare-hook
1535     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1536     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1537     gnus-thread-expunge-below
1538     gnus-score-alist gnus-current-score-file
1539     (gnus-summary-expunge-below . global)
1540     (gnus-summary-mark-below . global)
1541     (gnus-orphan-score . global)
1542     gnus-newsgroup-active gnus-scores-exclude-files
1543     gnus-newsgroup-history gnus-newsgroup-ancient
1544     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1545     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1546     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1547     (gnus-newsgroup-expunged-tally . 0)
1548     gnus-cache-removable-articles gnus-newsgroup-cached
1549     gnus-newsgroup-data gnus-newsgroup-data-reverse
1550     gnus-newsgroup-limit gnus-newsgroup-limits
1551     gnus-newsgroup-charset gnus-newsgroup-display
1552     gnus-summary-use-undownloaded-faces)
1553   "Variables that are buffer-local to the summary buffers.")
1554
1555 (defvar gnus-newsgroup-variables nil
1556   "A list of variables that have separate values in different newsgroups.
1557 A list of newsgroup (summary buffer) local variables, or cons of
1558 variables and their default expressions to be evalled (when the default
1559 values are not nil), that should be made global while the summary buffer
1560 is active.
1561
1562 Note: The default expressions will be evaluated (using function `eval')
1563 before assignment to the local variable rather than just assigned to it.
1564 If the default expression is the symbol `global', that symbol will not
1565 be evaluated but the global value of the local variable will be used
1566 instead.
1567
1568 These variables can be used to set variables in the group parameters
1569 while still allowing them to affect operations done in other buffers.
1570 For example:
1571
1572 \(setq gnus-newsgroup-variables
1573      '(message-use-followup-to
1574        (gnus-visible-headers .
1575          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1576 ")
1577
1578 (eval-when-compile
1579   ;; Bind features so that require will believe that gnus-sum has
1580   ;; already been loaded (avoids infinite recursion)
1581   (let ((features (cons 'gnus-sum features)))
1582     (require 'gnus-art)))
1583
1584 ;; MIME stuff.
1585
1586 (defvar gnus-decode-encoded-word-methods
1587   '(mail-decode-encoded-word-string)
1588   "List of methods used to decode encoded words.
1589
1590 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1591 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1592 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1593 whose names match REGEXP.
1594
1595 For example:
1596 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1597  mail-decode-encoded-word-string
1598  (\"chinese\" . rfc1843-decode-string))")
1599
1600 (defvar gnus-decode-encoded-word-methods-cache nil)
1601
1602 (defun gnus-multi-decode-encoded-word-string (string)
1603   "Apply the functions from `gnus-encoded-word-methods' that match."
1604   (unless (and gnus-decode-encoded-word-methods-cache
1605                (eq gnus-newsgroup-name
1606                    (car gnus-decode-encoded-word-methods-cache)))
1607     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1608     (dolist (method gnus-decode-encoded-word-methods)
1609       (if (symbolp method)
1610           (nconc gnus-decode-encoded-word-methods-cache (list method))
1611         (if (and gnus-newsgroup-name
1612                  (string-match (car method) gnus-newsgroup-name))
1613             (nconc gnus-decode-encoded-word-methods-cache
1614                    (list (cdr method)))))))
1615   (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1616     (setq string (funcall method string))))
1617
1618 ;; Subject simplification.
1619
1620 (defun gnus-simplify-whitespace (str)
1621   "Remove excessive whitespace from STR."
1622   ;; Multiple spaces.
1623   (while (string-match "[ \t][ \t]+" str)
1624     (setq str (concat (substring str 0 (match-beginning 0))
1625                         " "
1626                         (substring str (match-end 0)))))
1627   ;; Leading spaces.
1628   (when (string-match "^[ \t]+" str)
1629     (setq str (substring str (match-end 0))))
1630   ;; Trailing spaces.
1631   (when (string-match "[ \t]+$" str)
1632     (setq str (substring str 0 (match-beginning 0))))
1633   str)
1634
1635 (defun gnus-simplify-all-whitespace (str)
1636   "Remove all whitespace from STR."
1637   (while (string-match "[ \t\n]+" str)
1638     (setq str (replace-match "" nil nil str)))
1639   str)
1640
1641 (defsubst gnus-simplify-subject-re (subject)
1642   "Remove \"Re:\" from subject lines."
1643   (if (string-match message-subject-re-regexp subject)
1644       (substring subject (match-end 0))
1645     subject))
1646
1647 (defun gnus-simplify-subject (subject &optional re-only)
1648   "Remove `Re:' and words in parentheses.
1649 If RE-ONLY is non-nil, strip leading `Re:'s only."
1650   (let ((case-fold-search t))           ;Ignore case.
1651     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1652     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1653       (setq subject (substring subject (match-end 0))))
1654     ;; Remove uninteresting prefixes.
1655     (when (and (not re-only)
1656                gnus-simplify-ignored-prefixes
1657                (string-match gnus-simplify-ignored-prefixes subject))
1658       (setq subject (substring subject (match-end 0))))
1659     ;; Remove words in parentheses from end.
1660     (unless re-only
1661       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1662         (setq subject (substring subject 0 (match-beginning 0)))))
1663     ;; Return subject string.
1664     subject))
1665
1666 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1667 ;; all whitespace.
1668 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1669   (goto-char (point-min))
1670   (while (re-search-forward regexp nil t)
1671     (replace-match (or newtext ""))))
1672
1673 (defun gnus-simplify-buffer-fuzzy ()
1674   "Simplify string in the buffer fuzzily.
1675 The string in the accessible portion of the current buffer is simplified.
1676 It is assumed to be a single-line subject.
1677 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1678 matter is removed.  Additional things can be deleted by setting
1679 `gnus-simplify-subject-fuzzy-regexp'."
1680   (let ((case-fold-search t)
1681         (modified-tick))
1682     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1683
1684     (while (not (eq modified-tick (buffer-modified-tick)))
1685       (setq modified-tick (buffer-modified-tick))
1686       (cond
1687        ((listp gnus-simplify-subject-fuzzy-regexp)
1688         (mapc 'gnus-simplify-buffer-fuzzy-step
1689               gnus-simplify-subject-fuzzy-regexp))
1690        (gnus-simplify-subject-fuzzy-regexp
1691         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1692       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1693       (gnus-simplify-buffer-fuzzy-step
1694        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1695       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1696
1697     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1698     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1699     (gnus-simplify-buffer-fuzzy-step " $")
1700     (gnus-simplify-buffer-fuzzy-step "^ +")))
1701
1702 (defun gnus-simplify-subject-fuzzy (subject)
1703   "Simplify a subject string fuzzily.
1704 See `gnus-simplify-buffer-fuzzy' for details."
1705   (save-excursion
1706     (gnus-set-work-buffer)
1707     (let ((case-fold-search t))
1708       ;; Remove uninteresting prefixes.
1709       (when (and gnus-simplify-ignored-prefixes
1710                  (string-match gnus-simplify-ignored-prefixes subject))
1711         (setq subject (substring subject (match-end 0))))
1712       (insert subject)
1713       (inline (gnus-simplify-buffer-fuzzy))
1714       (buffer-string))))
1715
1716 (defsubst gnus-simplify-subject-fully (subject)
1717   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1718   (cond
1719    (gnus-simplify-subject-functions
1720     (gnus-map-function gnus-simplify-subject-functions subject))
1721    ((null gnus-summary-gather-subject-limit)
1722     (gnus-simplify-subject-re subject))
1723    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1724     (gnus-simplify-subject-fuzzy subject))
1725    ((numberp gnus-summary-gather-subject-limit)
1726     (truncate-string-to-width (gnus-simplify-subject-re subject)
1727                               gnus-summary-gather-subject-limit))
1728    (t
1729     subject)))
1730
1731 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1732   "Check whether two subjects are equal.
1733 If optional argument SIMPLE-FIRST is t, first argument is already
1734 simplified."
1735   (cond
1736    ((null simple-first)
1737     (equal (gnus-simplify-subject-fully s1)
1738            (gnus-simplify-subject-fully s2)))
1739    (t
1740     (equal s1
1741            (gnus-simplify-subject-fully s2)))))
1742
1743 (defun gnus-summary-bubble-group ()
1744   "Increase the score of the current group.
1745 This is a handy function to add to `gnus-summary-exit-hook' to
1746 increase the score of each group you read."
1747   (gnus-group-add-score gnus-newsgroup-name))
1748
1749 \f
1750 ;;;
1751 ;;; Gnus summary mode
1752 ;;;
1753
1754 (put 'gnus-summary-mode 'mode-class 'special)
1755
1756 (defvar gnus-article-commands-menu)
1757
1758 ;; Non-orthogonal keys
1759
1760 (gnus-define-keys gnus-summary-mode-map
1761   " " gnus-summary-next-page
1762   "\177" gnus-summary-prev-page
1763   [delete] gnus-summary-prev-page
1764   [backspace] gnus-summary-prev-page
1765   "\r" gnus-summary-scroll-up
1766   "\M-\r" gnus-summary-scroll-down
1767   "n" gnus-summary-next-unread-article
1768   "p" gnus-summary-prev-unread-article
1769   "N" gnus-summary-next-article
1770   "P" gnus-summary-prev-article
1771   "\M-\C-n" gnus-summary-next-same-subject
1772   "\M-\C-p" gnus-summary-prev-same-subject
1773   "\M-n" gnus-summary-next-unread-subject
1774   "\M-p" gnus-summary-prev-unread-subject
1775   "." gnus-summary-first-unread-article
1776   "," gnus-summary-best-unread-article
1777   "\M-s" gnus-summary-search-article-forward
1778   "\M-r" gnus-summary-search-article-backward
1779   "\M-S" gnus-summary-repeat-search-article-forward
1780   "\M-R" gnus-summary-repeat-search-article-backward
1781   "<" gnus-summary-beginning-of-article
1782   ">" gnus-summary-end-of-article
1783   "j" gnus-summary-goto-article
1784   "^" gnus-summary-refer-parent-article
1785   "\M-^" gnus-summary-refer-article
1786   "u" gnus-summary-tick-article-forward
1787   "!" gnus-summary-tick-article-forward
1788   "U" gnus-summary-tick-article-backward
1789   "d" gnus-summary-mark-as-read-forward
1790   "D" gnus-summary-mark-as-read-backward
1791   "E" gnus-summary-mark-as-expirable
1792   "\M-u" gnus-summary-clear-mark-forward
1793   "\M-U" gnus-summary-clear-mark-backward
1794   "k" gnus-summary-kill-same-subject-and-select
1795   "\C-k" gnus-summary-kill-same-subject
1796   "\M-\C-k" gnus-summary-kill-thread
1797   "\M-\C-l" gnus-summary-lower-thread
1798   "e" gnus-summary-edit-article
1799   "#" gnus-summary-mark-as-processable
1800   "\M-#" gnus-summary-unmark-as-processable
1801   "\M-\C-t" gnus-summary-toggle-threads
1802   "\M-\C-s" gnus-summary-show-thread
1803   "\M-\C-h" gnus-summary-hide-thread
1804   "\M-\C-f" gnus-summary-next-thread
1805   "\M-\C-b" gnus-summary-prev-thread
1806   [(meta down)] gnus-summary-next-thread
1807   [(meta up)] gnus-summary-prev-thread
1808   "\M-\C-u" gnus-summary-up-thread
1809   "\M-\C-d" gnus-summary-down-thread
1810   "&" gnus-summary-execute-command
1811   "c" gnus-summary-catchup-and-exit
1812   "\C-w" gnus-summary-mark-region-as-read
1813   "\C-t" gnus-summary-toggle-truncation
1814   "?" gnus-summary-mark-as-dormant
1815   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1816   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1817   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1818   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1819   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1820   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1821   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1822   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1823   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1824   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1825   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1826   "=" gnus-summary-expand-window
1827   "\C-x\C-s" gnus-summary-reselect-current-group
1828   "\M-g" gnus-summary-rescan-group
1829   "w" gnus-summary-stop-page-breaking
1830   "\C-c\C-r" gnus-summary-caesar-message
1831   "f" gnus-summary-followup
1832   "F" gnus-summary-followup-with-original
1833   "C" gnus-summary-cancel-article
1834   "r" gnus-summary-reply
1835   "R" gnus-summary-reply-with-original
1836   "\C-c\C-f" gnus-summary-mail-forward
1837   "o" gnus-summary-save-article
1838   "\C-o" gnus-summary-save-article-mail
1839   "|" gnus-summary-pipe-output
1840   "\M-k" gnus-summary-edit-local-kill
1841   "\M-K" gnus-summary-edit-global-kill
1842   ;; "V" gnus-version
1843   "\C-c\C-d" gnus-summary-describe-group
1844   "q" gnus-summary-exit
1845   "Q" gnus-summary-exit-no-update
1846   "\C-c\C-i" gnus-info-find-node
1847   gnus-mouse-2 gnus-mouse-pick-article
1848   [follow-link] mouse-face
1849   "m" gnus-summary-mail-other-window
1850   "a" gnus-summary-post-news
1851   "i" gnus-summary-news-other-window
1852   "x" gnus-summary-limit-to-unread
1853   "s" gnus-summary-isearch-article
1854   "t" gnus-summary-toggle-header
1855   "g" gnus-summary-show-article
1856   "l" gnus-summary-goto-last-article
1857   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1858   "\C-d" gnus-summary-enter-digest-group
1859   "\M-\C-d" gnus-summary-read-document
1860   "\M-\C-e" gnus-summary-edit-parameters
1861   "\M-\C-a" gnus-summary-customize-parameters
1862   "\C-c\C-b" gnus-bug
1863   "*" gnus-cache-enter-article
1864   "\M-*" gnus-cache-remove-article
1865   "\M-&" gnus-summary-universal-argument
1866   "\C-l" gnus-recenter
1867   "I" gnus-summary-increase-score
1868   "L" gnus-summary-lower-score
1869   "\M-i" gnus-symbolic-argument
1870   "h" gnus-summary-select-article-buffer
1871
1872   "b" gnus-article-view-part
1873   "\M-t" gnus-summary-toggle-display-buttonized
1874
1875   "V" gnus-summary-score-map
1876   "X" gnus-uu-extract-map
1877   "S" gnus-summary-send-map)
1878
1879 ;; Sort of orthogonal keymap
1880 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1881   "t" gnus-summary-tick-article-forward
1882   "!" gnus-summary-tick-article-forward
1883   "d" gnus-summary-mark-as-read-forward
1884   "r" gnus-summary-mark-as-read-forward
1885   "c" gnus-summary-clear-mark-forward
1886   " " gnus-summary-clear-mark-forward
1887   "e" gnus-summary-mark-as-expirable
1888   "x" gnus-summary-mark-as-expirable
1889   "?" gnus-summary-mark-as-dormant
1890   "b" gnus-summary-set-bookmark
1891   "B" gnus-summary-remove-bookmark
1892   "#" gnus-summary-mark-as-processable
1893   "\M-#" gnus-summary-unmark-as-processable
1894   "S" gnus-summary-limit-include-expunged
1895   "C" gnus-summary-catchup
1896   "H" gnus-summary-catchup-to-here
1897   "h" gnus-summary-catchup-from-here
1898   "\C-c" gnus-summary-catchup-all
1899   "k" gnus-summary-kill-same-subject-and-select
1900   "K" gnus-summary-kill-same-subject
1901   "P" gnus-uu-mark-map)
1902
1903 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1904   "c" gnus-summary-clear-above
1905   "u" gnus-summary-tick-above
1906   "m" gnus-summary-mark-above
1907   "k" gnus-summary-kill-below)
1908
1909 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1910   "/" gnus-summary-limit-to-subject
1911   "n" gnus-summary-limit-to-articles
1912   "b" gnus-summary-limit-to-bodies
1913   "h" gnus-summary-limit-to-headers
1914   "w" gnus-summary-pop-limit
1915   "s" gnus-summary-limit-to-subject
1916   "a" gnus-summary-limit-to-author
1917   "u" gnus-summary-limit-to-unread
1918   "m" gnus-summary-limit-to-marks
1919   "M" gnus-summary-limit-exclude-marks
1920   "v" gnus-summary-limit-to-score
1921   "*" gnus-summary-limit-include-cached
1922   "D" gnus-summary-limit-include-dormant
1923   "T" gnus-summary-limit-include-thread
1924   "d" gnus-summary-limit-exclude-dormant
1925   "t" gnus-summary-limit-to-age
1926   "." gnus-summary-limit-to-unseen
1927   "x" gnus-summary-limit-to-extra
1928   "p" gnus-summary-limit-to-display-predicate
1929   "E" gnus-summary-limit-include-expunged
1930   "c" gnus-summary-limit-exclude-childless-dormant
1931   "C" gnus-summary-limit-mark-excluded-as-read
1932   "o" gnus-summary-insert-old-articles
1933   "N" gnus-summary-insert-new-articles
1934   "S" gnus-summary-limit-to-singletons
1935   "r" gnus-summary-limit-to-replied
1936   "R" gnus-summary-limit-to-recipient
1937   "A" gnus-summary-limit-to-address)
1938
1939 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1940   "n" gnus-summary-next-unread-article
1941   "p" gnus-summary-prev-unread-article
1942   "N" gnus-summary-next-article
1943   "P" gnus-summary-prev-article
1944   "\C-n" gnus-summary-next-same-subject
1945   "\C-p" gnus-summary-prev-same-subject
1946   "\M-n" gnus-summary-next-unread-subject
1947   "\M-p" gnus-summary-prev-unread-subject
1948   "f" gnus-summary-first-unread-article
1949   "b" gnus-summary-best-unread-article
1950   "j" gnus-summary-goto-article
1951   "g" gnus-summary-goto-subject
1952   "l" gnus-summary-goto-last-article
1953   "o" gnus-summary-pop-article)
1954
1955 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1956   "k" gnus-summary-kill-thread
1957   "E" gnus-summary-expire-thread
1958   "l" gnus-summary-lower-thread
1959   "i" gnus-summary-raise-thread
1960   "T" gnus-summary-toggle-threads
1961   "t" gnus-summary-rethread-current
1962   "^" gnus-summary-reparent-thread
1963   "\M-^" gnus-summary-reparent-children
1964   "s" gnus-summary-show-thread
1965   "S" gnus-summary-show-all-threads
1966   "h" gnus-summary-hide-thread
1967   "H" gnus-summary-hide-all-threads
1968   "n" gnus-summary-next-thread
1969   "p" gnus-summary-prev-thread
1970   "u" gnus-summary-up-thread
1971   "o" gnus-summary-top-thread
1972   "d" gnus-summary-down-thread
1973   "#" gnus-uu-mark-thread
1974   "\M-#" gnus-uu-unmark-thread)
1975
1976 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1977   "g" gnus-summary-prepare
1978   "c" gnus-summary-insert-cached-articles
1979   "d" gnus-summary-insert-dormant-articles
1980   "t" gnus-summary-insert-ticked-articles)
1981
1982 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1983   "c" gnus-summary-catchup-and-exit
1984   "C" gnus-summary-catchup-all-and-exit
1985   "E" gnus-summary-exit-no-update
1986   "Q" gnus-summary-exit
1987   "Z" gnus-summary-exit
1988   "n" gnus-summary-catchup-and-goto-next-group
1989   "p" gnus-summary-catchup-and-goto-prev-group
1990   "R" gnus-summary-reselect-current-group
1991   "G" gnus-summary-rescan-group
1992   "N" gnus-summary-next-group
1993   "s" gnus-summary-save-newsrc
1994   "P" gnus-summary-prev-group)
1995
1996 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1997   " " gnus-summary-next-page
1998   "n" gnus-summary-next-page
1999   "\177" gnus-summary-prev-page
2000   [delete] gnus-summary-prev-page
2001   "p" gnus-summary-prev-page
2002   "\r" gnus-summary-scroll-up
2003   "\M-\r" gnus-summary-scroll-down
2004   "<" gnus-summary-beginning-of-article
2005   ">" gnus-summary-end-of-article
2006   "b" gnus-summary-beginning-of-article
2007   "e" gnus-summary-end-of-article
2008   "^" gnus-summary-refer-parent-article
2009   "r" gnus-summary-refer-parent-article
2010   "D" gnus-summary-enter-digest-group
2011   "R" gnus-summary-refer-references
2012   "T" gnus-summary-refer-thread
2013   "g" gnus-summary-show-article
2014   "s" gnus-summary-isearch-article
2015   "P" gnus-summary-print-article
2016   "S" gnus-sticky-article
2017   "M" gnus-mailing-list-insinuate
2018   "t" gnus-article-babel)
2019
2020 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2021   "b" gnus-article-add-buttons
2022   "B" gnus-article-add-buttons-to-head
2023   "o" gnus-article-treat-overstrike
2024   "e" gnus-article-emphasize
2025   "w" gnus-article-fill-cited-article
2026   "Q" gnus-article-fill-long-lines
2027   "L" gnus-article-toggle-truncate-lines
2028   "C" gnus-article-capitalize-sentences
2029   "c" gnus-article-remove-cr
2030   "q" gnus-article-de-quoted-unreadable
2031   "6" gnus-article-de-base64-unreadable
2032   "Z" gnus-article-decode-HZ
2033   "A" gnus-article-treat-ansi-sequences
2034   "h" gnus-article-wash-html
2035   "u" gnus-article-unsplit-urls
2036   "s" gnus-summary-force-verify-and-decrypt
2037   "f" gnus-article-display-x-face
2038   "l" gnus-summary-stop-page-breaking
2039   "r" gnus-summary-caesar-message
2040   "m" gnus-summary-morse-message
2041   "t" gnus-summary-toggle-header
2042   "g" gnus-treat-smiley
2043   "v" gnus-summary-verbose-headers
2044   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2045   "p" gnus-article-verify-x-pgp-sig
2046   "d" gnus-article-treat-dumbquotes
2047   "i" gnus-summary-idna-message)
2048
2049 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2050   ;; mnemonic: deuglif*Y*
2051   "u" gnus-article-outlook-unwrap-lines
2052   "a" gnus-article-outlook-repair-attribution
2053   "c" gnus-article-outlook-rearrange-citation
2054   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2055
2056 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2057   "a" gnus-article-hide
2058   "h" gnus-article-hide-headers
2059   "b" gnus-article-hide-boring-headers
2060   "s" gnus-article-hide-signature
2061   "c" gnus-article-hide-citation
2062   "C" gnus-article-hide-citation-in-followups
2063   "l" gnus-article-hide-list-identifiers
2064   "B" gnus-article-strip-banner
2065   "P" gnus-article-hide-pem
2066   "\C-c" gnus-article-hide-citation-maybe)
2067
2068 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2069   "a" gnus-article-highlight
2070   "h" gnus-article-highlight-headers
2071   "c" gnus-article-highlight-citation
2072   "s" gnus-article-highlight-signature)
2073
2074 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2075   "f" gnus-article-treat-fold-headers
2076   "u" gnus-article-treat-unfold-headers
2077   "n" gnus-article-treat-fold-newsgroups)
2078
2079 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2080   "x" gnus-article-display-x-face
2081   "d" gnus-article-display-face
2082   "s" gnus-treat-smiley
2083   "D" gnus-article-remove-images
2084   "f" gnus-treat-from-picon
2085   "m" gnus-treat-mail-picon
2086   "n" gnus-treat-newsgroups-picon)
2087
2088 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2089   "w" gnus-article-decode-mime-words
2090   "c" gnus-article-decode-charset
2091   "v" gnus-mime-view-all-parts
2092   "b" gnus-article-view-part)
2093
2094 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2095   "z" gnus-article-date-ut
2096   "u" gnus-article-date-ut
2097   "l" gnus-article-date-local
2098   "p" gnus-article-date-english
2099   "e" gnus-article-date-lapsed
2100   "o" gnus-article-date-original
2101   "i" gnus-article-date-iso8601
2102   "s" gnus-article-date-user)
2103
2104 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2105   "t" gnus-article-remove-trailing-blank-lines
2106   "l" gnus-article-strip-leading-blank-lines
2107   "m" gnus-article-strip-multiple-blank-lines
2108   "a" gnus-article-strip-blank-lines
2109   "A" gnus-article-strip-all-blank-lines
2110   "s" gnus-article-strip-leading-space
2111   "e" gnus-article-strip-trailing-space
2112   "w" gnus-article-remove-leading-whitespace)
2113
2114 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2115   "v" gnus-version
2116   "f" gnus-summary-fetch-faq
2117   "d" gnus-summary-describe-group
2118   "h" gnus-summary-describe-briefly
2119   "i" gnus-info-find-node
2120   "c" gnus-group-fetch-charter
2121   "C" gnus-group-fetch-control)
2122
2123 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2124   "e" gnus-summary-expire-articles
2125   "\M-\C-e" gnus-summary-expire-articles-now
2126   "\177" gnus-summary-delete-article
2127   [delete] gnus-summary-delete-article
2128   [backspace] gnus-summary-delete-article
2129   "m" gnus-summary-move-article
2130   "r" gnus-summary-respool-article
2131   "w" gnus-summary-edit-article
2132   "c" gnus-summary-copy-article
2133   "B" gnus-summary-crosspost-article
2134   "q" gnus-summary-respool-query
2135   "t" gnus-summary-respool-trace
2136   "i" gnus-summary-import-article
2137   "I" gnus-summary-create-article
2138   "p" gnus-summary-article-posted-p)
2139
2140 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2141   "o" gnus-summary-save-article
2142   "m" gnus-summary-save-article-mail
2143   "F" gnus-summary-write-article-file
2144   "r" gnus-summary-save-article-rmail
2145   "f" gnus-summary-save-article-file
2146   "b" gnus-summary-save-article-body-file
2147   "B" gnus-summary-write-article-body-file
2148   "h" gnus-summary-save-article-folder
2149   "v" gnus-summary-save-article-vm
2150   "p" gnus-summary-pipe-output
2151   "P" gnus-summary-muttprint
2152   "s" gnus-soup-add-article)
2153
2154 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2155   "b" gnus-summary-display-buttonized
2156   "m" gnus-summary-repair-multipart
2157   "v" gnus-article-view-part
2158   "o" gnus-article-save-part
2159   "O" gnus-article-save-part-and-strip
2160   "r" gnus-article-replace-part
2161   "d" gnus-article-delete-part
2162   "t" gnus-article-view-part-as-type
2163   "j" gnus-article-jump-to-part
2164   "c" gnus-article-copy-part
2165   "C" gnus-article-view-part-as-charset
2166   "e" gnus-article-view-part-externally
2167   "H" gnus-article-browse-html-article
2168   "E" gnus-article-encrypt-body
2169   "i" gnus-article-inline-part
2170   "|" gnus-article-pipe-part)
2171
2172 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2173   "p" gnus-summary-mark-as-processable
2174   "u" gnus-summary-unmark-as-processable
2175   "U" gnus-summary-unmark-all-processable
2176   "v" gnus-uu-mark-over
2177   "s" gnus-uu-mark-series
2178   "r" gnus-uu-mark-region
2179   "g" gnus-uu-unmark-region
2180   "R" gnus-uu-mark-by-regexp
2181   "G" gnus-uu-unmark-by-regexp
2182   "t" gnus-uu-mark-thread
2183   "T" gnus-uu-unmark-thread
2184   "a" gnus-uu-mark-all
2185   "b" gnus-uu-mark-buffer
2186   "S" gnus-uu-mark-sparse
2187   "k" gnus-summary-kill-process-mark
2188   "y" gnus-summary-yank-process-mark
2189   "w" gnus-summary-save-process-mark
2190   "i" gnus-uu-invert-processable)
2191
2192 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2193   ;;"x" gnus-uu-extract-any
2194   "m" gnus-summary-save-parts
2195   "u" gnus-uu-decode-uu
2196   "U" gnus-uu-decode-uu-and-save
2197   "s" gnus-uu-decode-unshar
2198   "S" gnus-uu-decode-unshar-and-save
2199   "o" gnus-uu-decode-save
2200   "O" gnus-uu-decode-save
2201   "b" gnus-uu-decode-binhex
2202   "B" gnus-uu-decode-binhex
2203   "Y" gnus-uu-decode-yenc
2204   "p" gnus-uu-decode-postscript
2205   "P" gnus-uu-decode-postscript-and-save)
2206
2207 (gnus-define-keys
2208     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2209   "u" gnus-uu-decode-uu-view
2210   "U" gnus-uu-decode-uu-and-save-view
2211   "s" gnus-uu-decode-unshar-view
2212   "S" gnus-uu-decode-unshar-and-save-view
2213   "o" gnus-uu-decode-save-view
2214   "O" gnus-uu-decode-save-view
2215   "b" gnus-uu-decode-binhex-view
2216   "B" gnus-uu-decode-binhex-view
2217   "p" gnus-uu-decode-postscript-view
2218   "P" gnus-uu-decode-postscript-and-save-view)
2219
2220 (defvar gnus-article-post-menu nil)
2221
2222 (defconst gnus-summary-menu-maxlen 20)
2223
2224 (defun gnus-summary-menu-split (menu)
2225   ;; If we have lots of elements, divide them into groups of 20
2226   ;; and make a pane (or submenu) for each one.
2227   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2228       (let ((menu menu) sublists next
2229             (i 1))
2230         (while menu
2231           ;; Pull off the next gnus-summary-menu-maxlen elements
2232           ;; and make them the next element of sublist.
2233           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2234           (if next
2235               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2236                       nil))
2237           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2238                                              (aref (car (last menu)) 0)) menu)
2239                                sublists))
2240           (setq i (1+ i))
2241           (setq menu next))
2242         (nreverse sublists))
2243     ;; Few elements--put them all in one pane.
2244     menu))
2245
2246 (defun gnus-summary-make-menu-bar ()
2247   (gnus-turn-off-edit-menu 'summary)
2248
2249   (unless (boundp 'gnus-summary-misc-menu)
2250
2251     (easy-menu-define
2252       gnus-summary-kill-menu gnus-summary-mode-map ""
2253       (cons
2254        "Score"
2255        (nconc
2256         (list
2257          ["Customize" gnus-score-customize t])
2258         (gnus-make-score-map 'increase)
2259         (gnus-make-score-map 'lower)
2260         '(("Mark"
2261            ["Kill below" gnus-summary-kill-below t]
2262            ["Mark above" gnus-summary-mark-above t]
2263            ["Tick above" gnus-summary-tick-above t]
2264            ["Clear above" gnus-summary-clear-above t])
2265           ["Current score" gnus-summary-current-score t]
2266           ["Set score" gnus-summary-set-score t]
2267           ["Switch current score file..." gnus-score-change-score-file t]
2268           ["Set mark below..." gnus-score-set-mark-below t]
2269           ["Set expunge below..." gnus-score-set-expunge-below t]
2270           ["Edit current score file" gnus-score-edit-current-scores t]
2271           ["Edit score file..." gnus-score-edit-file t]
2272           ["Trace score" gnus-score-find-trace t]
2273           ["Find words" gnus-score-find-favourite-words t]
2274           ["Rescore buffer" gnus-summary-rescore t]
2275           ["Increase score..." gnus-summary-increase-score t]
2276           ["Lower score..." gnus-summary-lower-score t]))))
2277
2278     ;; Define both the Article menu in the summary buffer and the
2279     ;; equivalent Commands menu in the article buffer here for
2280     ;; consistency.
2281     (let ((innards
2282            `(("Hide"
2283               ["All" gnus-article-hide t]
2284               ["Headers" gnus-article-hide-headers t]
2285               ["Signature" gnus-article-hide-signature t]
2286               ["Citation" gnus-article-hide-citation t]
2287               ["List identifiers" gnus-article-hide-list-identifiers t]
2288               ["Banner" gnus-article-strip-banner t]
2289               ["Boring headers" gnus-article-hide-boring-headers t])
2290              ("Highlight"
2291               ["All" gnus-article-highlight t]
2292               ["Headers" gnus-article-highlight-headers t]
2293               ["Signature" gnus-article-highlight-signature t]
2294               ["Citation" gnus-article-highlight-citation t])
2295              ("MIME"
2296               ["Words" gnus-article-decode-mime-words t]
2297               ["Charset" gnus-article-decode-charset t]
2298               ["QP" gnus-article-de-quoted-unreadable t]
2299               ["Base64" gnus-article-de-base64-unreadable t]
2300               ["View MIME buttons" gnus-summary-display-buttonized t]
2301               ["View all" gnus-mime-view-all-parts t]
2302               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2303               ["Encrypt body" gnus-article-encrypt-body
2304                :active (not (gnus-group-read-only-p))
2305                ,@(if (featurep 'xemacs) nil
2306                    '(:help "Encrypt the message body on disk"))]
2307               ["Extract all parts..." gnus-summary-save-parts t]
2308               ("Multipart"
2309                ["Repair multipart" gnus-summary-repair-multipart t]
2310                ["Pipe part..." gnus-article-pipe-part t]
2311                ["Inline part" gnus-article-inline-part t]
2312                ["View part as type..." gnus-article-view-part-as-type t]
2313                ["Encrypt body" gnus-article-encrypt-body
2314                 :active (not (gnus-group-read-only-p))
2315                ,@(if (featurep 'xemacs) nil
2316                    '(:help "Encrypt the message body on disk"))]
2317                ["View part externally" gnus-article-view-part-externally t]
2318                ["View HTML parts in browser" gnus-article-browse-html-article t]
2319                ["View part with charset..." gnus-article-view-part-as-charset t]
2320                ["Copy part" gnus-article-copy-part t]
2321                ["Save part..." gnus-article-save-part t]
2322                ["View part" gnus-article-view-part t]))
2323              ("Date"
2324               ["Local" gnus-article-date-local t]
2325               ["ISO8601" gnus-article-date-iso8601 t]
2326               ["UT" gnus-article-date-ut t]
2327               ["Original" gnus-article-date-original t]
2328               ["Lapsed" gnus-article-date-lapsed t]
2329               ["User-defined" gnus-article-date-user t])
2330              ("Display"
2331               ["Remove images" gnus-article-remove-images t]
2332               ["Toggle smiley" gnus-treat-smiley t]
2333               ["Show X-Face" gnus-article-display-x-face t]
2334               ["Show picons in From" gnus-treat-from-picon t]
2335               ["Show picons in mail headers" gnus-treat-mail-picon t]
2336               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2337               ("View as different encoding"
2338                ,@(gnus-summary-menu-split
2339                   (mapcar
2340                    (lambda (cs)
2341                      ;; Since easymenu under Emacs doesn't allow
2342                      ;; lambda forms for menu commands, we should
2343                      ;; provide intern'ed function symbols.
2344                      (let ((command (intern (format "\
2345 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2346                        (fset command
2347                              `(lambda ()
2348                                 (interactive)
2349                                 (let ((gnus-summary-show-article-charset-alist
2350                                        '((1 . ,cs))))
2351                                   (gnus-summary-show-article 1))))
2352                        `[,(symbol-name cs) ,command t]))
2353                    (sort (if (fboundp 'coding-system-list)
2354                              (coding-system-list)
2355                            (mapcar 'car mm-mime-mule-charset-alist))
2356                          'string<)))))
2357              ("Washing"
2358               ("Remove Blanks"
2359                ["Leading" gnus-article-strip-leading-blank-lines t]
2360                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2361                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2362                ["All of the above" gnus-article-strip-blank-lines t]
2363                ["All" gnus-article-strip-all-blank-lines t]
2364                ["Leading space" gnus-article-strip-leading-space t]
2365                ["Trailing space" gnus-article-strip-trailing-space t]
2366                ["Leading space in headers"
2367                 gnus-article-remove-leading-whitespace t])
2368               ["Overstrike" gnus-article-treat-overstrike t]
2369               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2370               ["Emphasis" gnus-article-emphasize t]
2371               ["Word wrap" gnus-article-fill-cited-article t]
2372               ["Fill long lines" gnus-article-fill-long-lines t]
2373               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2374               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2375               ["Remove CR" gnus-article-remove-cr t]
2376               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2377               ["Base64" gnus-article-de-base64-unreadable t]
2378               ["Rot 13" gnus-summary-caesar-message
2379                ,@(if (featurep 'xemacs) '(t)
2380                    '(:help "\"Caesar rotate\" article by 13"))]
2381               ["De-IDNA" gnus-summary-idna-message t]
2382               ["Morse decode" gnus-summary-morse-message t]
2383               ["Unix pipe..." gnus-summary-pipe-message t]
2384               ["Add buttons" gnus-article-add-buttons t]
2385               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2386               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2387               ["Verbose header" gnus-summary-verbose-headers t]
2388               ["Toggle header" gnus-summary-toggle-header t]
2389               ["Unfold headers" gnus-article-treat-unfold-headers t]
2390               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2391               ["Html" gnus-article-wash-html t]
2392               ["Unsplit URLs" gnus-article-unsplit-urls t]
2393               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2394               ["Decode HZ" gnus-article-decode-HZ t]
2395               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2396               ("(Outlook) Deuglify"
2397                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2398                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2399                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2400                ["Full (Outlook) deuglify"
2401                 gnus-article-outlook-deuglify-article t])
2402               )
2403              ("Output"
2404               ["Save in default format..." gnus-summary-save-article
2405                ,@(if (featurep 'xemacs) '(t)
2406                    '(:help "Save article using default method"))]
2407               ["Save in file..." gnus-summary-save-article-file
2408                ,@(if (featurep 'xemacs) '(t)
2409                    '(:help "Save article in file"))]
2410               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2411               ["Save in MH folder..." gnus-summary-save-article-folder t]
2412               ["Save in VM folder..." gnus-summary-save-article-vm t]
2413               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2414               ["Save body in file..." gnus-summary-save-article-body-file t]
2415               ["Pipe through a filter..." gnus-summary-pipe-output t]
2416               ["Add to SOUP packet" gnus-soup-add-article t]
2417               ["Print with Muttprint..." gnus-summary-muttprint t]
2418               ["Print" gnus-summary-print-article
2419                ,@(if (featurep 'xemacs) '(t)
2420                    '(:help "Generate and print a PostScript image"))])
2421              ("Copy, move,... (Backend)"
2422               ,@(if (featurep 'xemacs) nil
2423                   '(:help "Copying, moving, expiring articles..."))
2424               ["Respool article..." gnus-summary-respool-article t]
2425               ["Move article..." gnus-summary-move-article
2426                (gnus-check-backend-function
2427                 'request-move-article gnus-newsgroup-name)]
2428               ["Copy article..." gnus-summary-copy-article t]
2429               ["Crosspost article..." gnus-summary-crosspost-article
2430                (gnus-check-backend-function
2431                 'request-replace-article gnus-newsgroup-name)]
2432               ["Import file..." gnus-summary-import-article
2433                (gnus-check-backend-function
2434                 'request-accept-article gnus-newsgroup-name)]
2435               ["Create article..." gnus-summary-create-article
2436                (gnus-check-backend-function
2437                 'request-accept-article gnus-newsgroup-name)]
2438               ["Check if posted" gnus-summary-article-posted-p t]
2439               ["Edit article" gnus-summary-edit-article
2440                (not (gnus-group-read-only-p))]
2441               ["Delete article" gnus-summary-delete-article
2442                (gnus-check-backend-function
2443                 'request-expire-articles gnus-newsgroup-name)]
2444               ["Query respool" gnus-summary-respool-query t]
2445               ["Trace respool" gnus-summary-respool-trace t]
2446               ["Delete expirable articles" gnus-summary-expire-articles-now
2447                (gnus-check-backend-function
2448                 'request-expire-articles gnus-newsgroup-name)])
2449              ("Extract"
2450               ["Uudecode" gnus-uu-decode-uu
2451                ,@(if (featurep 'xemacs) '(t)
2452                    '(:help "Decode uuencoded article(s)"))]
2453               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2454               ["Unshar" gnus-uu-decode-unshar t]
2455               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2456               ["Save" gnus-uu-decode-save t]
2457               ["Binhex" gnus-uu-decode-binhex t]
2458               ["Postscript" gnus-uu-decode-postscript t]
2459               ["All MIME parts" gnus-summary-save-parts t])
2460              ("Cache"
2461               ["Enter article" gnus-cache-enter-article t]
2462               ["Remove article" gnus-cache-remove-article t])
2463              ["Translate" gnus-article-babel t]
2464              ["Select article buffer" gnus-summary-select-article-buffer t]
2465              ["Make article buffer sticky" gnus-sticky-article t]
2466              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2467              ["Isearch article..." gnus-summary-isearch-article t]
2468              ["Beginning of the article" gnus-summary-beginning-of-article t]
2469              ["End of the article" gnus-summary-end-of-article t]
2470              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2471              ["Fetch referenced articles" gnus-summary-refer-references t]
2472              ["Fetch current thread" gnus-summary-refer-thread t]
2473              ["Fetch article with id..." gnus-summary-refer-article t]
2474              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2475              ["Redisplay" gnus-summary-show-article t]
2476              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2477       (easy-menu-define
2478         gnus-summary-article-menu gnus-summary-mode-map ""
2479         (cons "Article" innards))
2480
2481       (if (not (keymapp gnus-summary-article-menu))
2482           (easy-menu-define
2483             gnus-article-commands-menu gnus-article-mode-map ""
2484             (cons "Commands" innards))
2485         ;; in Emacs, don't share menu.
2486         (setq gnus-article-commands-menu
2487               (copy-keymap gnus-summary-article-menu))
2488         (define-key gnus-article-mode-map [menu-bar commands]
2489           (cons "Commands" gnus-article-commands-menu))))
2490
2491     (easy-menu-define
2492       gnus-summary-thread-menu gnus-summary-mode-map ""
2493       '("Threads"
2494         ["Find all messages in thread" gnus-summary-refer-thread t]
2495         ["Toggle threading" gnus-summary-toggle-threads t]
2496         ["Hide threads" gnus-summary-hide-all-threads t]
2497         ["Show threads" gnus-summary-show-all-threads t]
2498         ["Hide thread" gnus-summary-hide-thread t]
2499         ["Show thread" gnus-summary-show-thread t]
2500         ["Go to next thread" gnus-summary-next-thread t]
2501         ["Go to previous thread" gnus-summary-prev-thread t]
2502         ["Go down thread" gnus-summary-down-thread t]
2503         ["Go up thread" gnus-summary-up-thread t]
2504         ["Top of thread" gnus-summary-top-thread t]
2505         ["Mark thread as read" gnus-summary-kill-thread t]
2506         ["Mark thread as expired" gnus-summary-expire-thread t]
2507         ["Lower thread score" gnus-summary-lower-thread t]
2508         ["Raise thread score" gnus-summary-raise-thread t]
2509         ["Rethread current" gnus-summary-rethread-current t]))
2510
2511     (easy-menu-define
2512       gnus-summary-post-menu gnus-summary-mode-map ""
2513       `("Post"
2514         ["Send a message (mail or news)" gnus-summary-post-news
2515          ,@(if (featurep 'xemacs) '(t)
2516              '(:help "Compose a new message (mail or news)"))]
2517         ["Followup" gnus-summary-followup
2518          ,@(if (featurep 'xemacs) '(t)
2519              '(:help "Post followup to this article"))]
2520         ["Followup and yank" gnus-summary-followup-with-original
2521          ,@(if (featurep 'xemacs) '(t)
2522              '(:help "Post followup to this article, quoting its contents"))]
2523         ["Supersede article" gnus-summary-supersede-article t]
2524         ["Cancel article" gnus-summary-cancel-article
2525          ,@(if (featurep 'xemacs) '(t)
2526              '(:help "Cancel an article you posted"))]
2527         ["Reply" gnus-summary-reply t]
2528         ["Reply and yank" gnus-summary-reply-with-original t]
2529         ["Wide reply" gnus-summary-wide-reply t]
2530         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2531          ,@(if (featurep 'xemacs) '(t)
2532              '(:help "Mail a reply, quoting this article"))]
2533         ["Very wide reply" gnus-summary-very-wide-reply t]
2534         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2535          ,@(if (featurep 'xemacs) '(t)
2536              '(:help "Mail a very wide reply, quoting this article"))]
2537         ["Mail forward" gnus-summary-mail-forward t]
2538         ["Post forward" gnus-summary-post-forward t]
2539         ["Digest and mail" gnus-uu-digest-mail-forward t]
2540         ["Digest and post" gnus-uu-digest-post-forward t]
2541         ["Resend message" gnus-summary-resend-message t]
2542         ["Resend message edit" gnus-summary-resend-message-edit t]
2543         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2544         ["Send a mail" gnus-summary-mail-other-window t]
2545         ["Create a local message" gnus-summary-news-other-window t]
2546         ["Uuencode and post" gnus-uu-post-news
2547          ,@(if (featurep 'xemacs) '(t)
2548              '(:help "Post a uuencoded article"))]
2549         ["Followup via news" gnus-summary-followup-to-mail t]
2550         ["Followup via news and yank"
2551          gnus-summary-followup-to-mail-with-original t]
2552         ["Strip signature on reply"
2553          (lambda ()
2554            (interactive)
2555            (if (not (memq message-cite-function
2556                           '(message-cite-original-without-signature
2557                             message-cite-original)))
2558                ;; Stupid workaround for XEmacs not honoring :visible.
2559                (message "Can't toggle this value of `message-cite-function'")
2560              (setq message-cite-function
2561                    (if (eq message-cite-function
2562                            'message-cite-original-without-signature)
2563                        'message-cite-original
2564                      'message-cite-original-without-signature))))
2565          ;; XEmacs barfs on :visible.
2566          ,@(if (featurep 'xemacs) nil
2567              '(:visible (memq message-cite-function
2568                               '(message-cite-original-without-signature
2569                                 message-cite-original))))
2570          :style toggle
2571          :selected (eq message-cite-function
2572                        'message-cite-original-without-signature)
2573          ,@(if (featurep 'xemacs) nil
2574              '(:help "Strip signature from cited article when replying."))]
2575         ;;("Draft"
2576         ;;["Send" gnus-summary-send-draft t]
2577         ;;["Send bounced" gnus-resend-bounced-mail t])
2578         ))
2579
2580     (cond
2581      ((not (keymapp gnus-summary-post-menu))
2582       (setq gnus-article-post-menu gnus-summary-post-menu))
2583      ((not gnus-article-post-menu)
2584       ;; Don't share post menu.
2585       (setq gnus-article-post-menu
2586             (copy-keymap gnus-summary-post-menu))))
2587     (define-key gnus-article-mode-map [menu-bar post]
2588       (cons "Post" gnus-article-post-menu))
2589
2590     (easy-menu-define
2591       gnus-summary-misc-menu gnus-summary-mode-map ""
2592       `("Gnus"
2593         ("Mark Read"
2594          ["Mark as read" gnus-summary-mark-as-read-forward t]
2595          ["Mark same subject and select"
2596           gnus-summary-kill-same-subject-and-select t]
2597          ["Mark same subject" gnus-summary-kill-same-subject t]
2598          ["Catchup" gnus-summary-catchup
2599           ,@(if (featurep 'xemacs) '(t)
2600               '(:help "Mark unread articles in this group as read"))]
2601          ["Catchup all" gnus-summary-catchup-all t]
2602          ["Catchup to here" gnus-summary-catchup-to-here t]
2603          ["Catchup from here" gnus-summary-catchup-from-here t]
2604          ["Catchup region" gnus-summary-mark-region-as-read
2605           (gnus-mark-active-p)]
2606          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2607         ("Mark Various"
2608          ["Tick" gnus-summary-tick-article-forward t]
2609          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2610          ["Remove marks" gnus-summary-clear-mark-forward t]
2611          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2612          ["Set bookmark" gnus-summary-set-bookmark t]
2613          ["Remove bookmark" gnus-summary-remove-bookmark t])
2614         ("Registry Mark"
2615          ["Important"     gnus-registry-set-article-Important-mark    t]
2616          ["Not Important" gnus-registry-remove-article-Important-mark t]
2617          ["Work"          gnus-registry-set-article-Work-mark         t]
2618          ["Not Work"      gnus-registry-remove-article-Work-mark      t]
2619          ["Later"         gnus-registry-set-article-Later-mark        t]
2620          ["Not Later"     gnus-registry-remove-article-Later-mark     t]
2621          ["Personal"      gnus-registry-set-article-Personal-mark     t]
2622          ["Not Personal"  gnus-registry-remove-article-Personal-mark  t]
2623          ["To Do"         gnus-registry-set-article-To-Do-mark        t]
2624          ["Not To Do"     gnus-registry-remove-article-To-Do-mark     t])
2625         ("Limit to"
2626          ["Marks..." gnus-summary-limit-to-marks t]
2627          ["Subject..." gnus-summary-limit-to-subject t]
2628          ["Author..." gnus-summary-limit-to-author t]
2629          ["Recipient..." gnus-summary-limit-to-recipient t]
2630          ["Address..." gnus-summary-limit-to-address t]
2631          ["Age..." gnus-summary-limit-to-age t]
2632          ["Extra..." gnus-summary-limit-to-extra t]
2633          ["Score..." gnus-summary-limit-to-score t]
2634          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2635          ["Unread" gnus-summary-limit-to-unread t]
2636          ["Unseen" gnus-summary-limit-to-unseen t]
2637          ["Singletons" gnus-summary-limit-to-singletons t]
2638          ["Replied" gnus-summary-limit-to-replied t]
2639          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2640          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2641          ["Pop limit" gnus-summary-pop-limit t]
2642          ["Show dormant" gnus-summary-limit-include-dormant t]
2643          ["Hide childless dormant"
2644           gnus-summary-limit-exclude-childless-dormant t]
2645          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2646          ["Hide marked" gnus-summary-limit-exclude-marks t]
2647          ["Show expunged" gnus-summary-limit-include-expunged t])
2648         ("Process Mark"
2649          ["Set mark" gnus-summary-mark-as-processable t]
2650          ["Remove mark" gnus-summary-unmark-as-processable t]
2651          ["Remove all marks" gnus-summary-unmark-all-processable t]
2652          ["Invert marks" gnus-uu-invert-processable t]
2653          ["Mark above" gnus-uu-mark-over t]
2654          ["Mark series" gnus-uu-mark-series t]
2655          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2656          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2657          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2658          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2659          ["Mark all" gnus-uu-mark-all t]
2660          ["Mark buffer" gnus-uu-mark-buffer t]
2661          ["Mark sparse" gnus-uu-mark-sparse t]
2662          ["Mark thread" gnus-uu-mark-thread t]
2663          ["Unmark thread" gnus-uu-unmark-thread t]
2664          ("Process Mark Sets"
2665           ["Kill" gnus-summary-kill-process-mark t]
2666           ["Yank" gnus-summary-yank-process-mark
2667            gnus-newsgroup-process-stack]
2668           ["Save" gnus-summary-save-process-mark t]
2669           ["Run command on marked..." gnus-summary-universal-argument t]))
2670         ("Scroll article"
2671          ["Page forward" gnus-summary-next-page
2672           ,@(if (featurep 'xemacs) '(t)
2673               '(:help "Show next page of article"))]
2674          ["Page backward" gnus-summary-prev-page
2675           ,@(if (featurep 'xemacs) '(t)
2676               '(:help "Show previous page of article"))]
2677          ["Line forward" gnus-summary-scroll-up t])
2678         ("Move"
2679          ["Next unread article" gnus-summary-next-unread-article t]
2680          ["Previous unread article" gnus-summary-prev-unread-article t]
2681          ["Next article" gnus-summary-next-article t]
2682          ["Previous article" gnus-summary-prev-article t]
2683          ["Next unread subject" gnus-summary-next-unread-subject t]
2684          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2685          ["Next article same subject" gnus-summary-next-same-subject t]
2686          ["Previous article same subject" gnus-summary-prev-same-subject t]
2687          ["First unread article" gnus-summary-first-unread-article t]
2688          ["Best unread article" gnus-summary-best-unread-article t]
2689          ["Go to subject number..." gnus-summary-goto-subject t]
2690          ["Go to article number..." gnus-summary-goto-article t]
2691          ["Go to the last article" gnus-summary-goto-last-article t]
2692          ["Pop article off history" gnus-summary-pop-article t])
2693         ("Sort"
2694          ["Sort by number" gnus-summary-sort-by-number t]
2695          ["Sort by author" gnus-summary-sort-by-author t]
2696          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2697          ["Sort by subject" gnus-summary-sort-by-subject t]
2698          ["Sort by date" gnus-summary-sort-by-date t]
2699          ["Sort by score" gnus-summary-sort-by-score t]
2700          ["Sort by lines" gnus-summary-sort-by-lines t]
2701          ["Sort by characters" gnus-summary-sort-by-chars t]
2702          ["Randomize" gnus-summary-sort-by-random t]
2703          ["Original sort" gnus-summary-sort-by-original t])
2704         ("Help"
2705          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2706          ["Describe group" gnus-summary-describe-group t]
2707          ["Fetch charter" gnus-group-fetch-charter
2708           ,@(if (featurep 'xemacs) nil
2709               '(:help "Display the charter of the current group"))]
2710          ["Fetch control message" gnus-group-fetch-control
2711           ,@(if (featurep 'xemacs) nil
2712               '(:help "Display the archived control message for the current group"))]
2713          ["Read manual" gnus-info-find-node t])
2714         ("Modes"
2715          ["Pick and read" gnus-pick-mode t]
2716          ["Binary" gnus-binary-mode t])
2717         ("Regeneration"
2718          ["Regenerate" gnus-summary-prepare t]
2719          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2720          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2721          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2722          ["Toggle threading" gnus-summary-toggle-threads t])
2723         ["See old articles" gnus-summary-insert-old-articles t]
2724         ["See new articles" gnus-summary-insert-new-articles t]
2725         ["Filter articles..." gnus-summary-execute-command t]
2726         ["Run command on articles..." gnus-summary-universal-argument t]
2727         ["Search articles forward..." gnus-summary-search-article-forward t]
2728         ["Search articles backward..." gnus-summary-search-article-backward t]
2729         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2730         ["Expand window" gnus-summary-expand-window t]
2731         ["Expire expirable articles" gnus-summary-expire-articles
2732          (gnus-check-backend-function
2733           'request-expire-articles gnus-newsgroup-name)]
2734         ["Edit local kill file" gnus-summary-edit-local-kill t]
2735         ["Edit main kill file" gnus-summary-edit-global-kill t]
2736         ["Edit group parameters" gnus-summary-edit-parameters t]
2737         ["Customize group parameters" gnus-summary-customize-parameters t]
2738         ["Send a bug report" gnus-bug t]
2739         ("Exit"
2740          ["Catchup and exit" gnus-summary-catchup-and-exit
2741           ,@(if (featurep 'xemacs) '(t)
2742               '(:help "Mark unread articles in this group as read, then exit"))]
2743          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2744          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2745          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2746          ["Exit group" gnus-summary-exit
2747           ,@(if (featurep 'xemacs) '(t)
2748               '(:help "Exit current group, return to group selection mode"))]
2749          ["Exit group without updating" gnus-summary-exit-no-update t]
2750          ["Exit and goto next group" gnus-summary-next-group t]
2751          ["Exit and goto prev group" gnus-summary-prev-group t]
2752          ["Reselect group" gnus-summary-reselect-current-group t]
2753          ["Rescan group" gnus-summary-rescan-group t]
2754          ["Update dribble" gnus-summary-save-newsrc t])))
2755
2756     (gnus-run-hooks 'gnus-summary-menu-hook)))
2757
2758 (defvar gnus-summary-tool-bar-map nil)
2759
2760 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2761 ;; affect _new_ message buffers.  We might add a function that walks thru all
2762 ;; summary-mode buffers and force the update.
2763 (defun gnus-summary-tool-bar-update (&optional symbol value)
2764   "Update summary mode toolbar.
2765 Setter function for custom variables."
2766   (setq-default gnus-summary-tool-bar-map nil)
2767   (when symbol
2768     ;; When used as ":set" function:
2769     (set-default symbol value))
2770   (when (gnus-buffer-live-p gnus-summary-buffer)
2771     (with-current-buffer gnus-summary-buffer
2772       (gnus-summary-make-tool-bar))))
2773
2774 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2775                                      'gnus-summary-tool-bar-gnome
2776                                    'gnus-summary-tool-bar-retro)
2777   "Specifies the Gnus summary tool bar.
2778
2779 It can be either a list or a symbol refering to a list.  See
2780 `gmm-tool-bar-from-list' for the format of the list.  The
2781 default key map is `gnus-summary-mode-map'.
2782
2783 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2784 `gnus-summary-tool-bar-retro'."
2785   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2786                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2787                  (repeat :tag "User defined list" gmm-tool-bar-item)
2788                  (symbol))
2789   :version "23.1" ;; No Gnus
2790   :initialize 'custom-initialize-default
2791   :set 'gnus-summary-tool-bar-update
2792   :group 'gnus-summary)
2793
2794 (defcustom gnus-summary-tool-bar-gnome
2795   '((gnus-summary-post-news "mail/compose" nil)
2796     (gnus-summary-insert-new-articles "mail/inbox" nil
2797                                       :visible (or (not gnus-agent)
2798                                                    gnus-plugged))
2799     (gnus-summary-reply-with-original "mail/reply")
2800     (gnus-summary-reply "mail/reply" nil :visible nil)
2801     (gnus-summary-followup-with-original "mail/reply-all")
2802     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2803     (gnus-summary-mail-forward "mail/forward")
2804     (gnus-summary-save-article "mail/save")
2805     (gnus-summary-search-article-forward "search" nil :visible nil)
2806     (gnus-summary-print-article "print")
2807     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2808     ;; Some new commands that may need more suitable icons:
2809     (gnus-summary-save-newsrc "save" nil :visible nil)
2810     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2811     (gnus-summary-prev-article "left-arrow")
2812     (gnus-summary-next-article "right-arrow")
2813     (gnus-summary-next-page "next-page")
2814     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2815     ;;
2816     ;; Maybe some sort-by-... could be added:
2817     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2818     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2819     (gnus-summary-mark-as-expirable
2820      "delete" nil
2821      :visible (gnus-check-backend-function 'request-expire-articles
2822                                            gnus-newsgroup-name))
2823     (gnus-summary-mark-as-spam
2824      "mail/spam" t
2825      :visible (and (fboundp 'spam-group-ham-contents-p)
2826                    (spam-group-ham-contents-p gnus-newsgroup-name))
2827      :help "Mark as spam")
2828     (gnus-summary-mark-as-read-forward
2829      "mail/not-spam" nil
2830      :visible (and (fboundp 'spam-group-spam-contents-p)
2831                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2832     ;;
2833     (gnus-summary-exit "exit")
2834     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2835     (gnus-info-find-node "help"))
2836   "List of functions for the summary tool bar (GNOME style).
2837
2838 See `gmm-tool-bar-from-list' for the format of the list."
2839   :type '(repeat gmm-tool-bar-item)
2840   :version "23.1" ;; No Gnus
2841   :initialize 'custom-initialize-default
2842   :set 'gnus-summary-tool-bar-update
2843   :group 'gnus-summary)
2844
2845 (defcustom gnus-summary-tool-bar-retro
2846   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2847     (gnus-summary-next-unread-article "gnus/next-ur")
2848     (gnus-summary-post-news "gnus/post")
2849     (gnus-summary-followup-with-original "gnus/fuwo")
2850     (gnus-summary-followup "gnus/followup")
2851     (gnus-summary-reply-with-original "gnus/reply-wo")
2852     (gnus-summary-reply "gnus/reply")
2853     (gnus-summary-caesar-message "gnus/rot13")
2854     (gnus-uu-decode-uu "gnus/uu-decode")
2855     (gnus-summary-save-article-file "gnus/save-aif")
2856     (gnus-summary-save-article "gnus/save-art")
2857     (gnus-uu-post-news "gnus/uu-post")
2858     (gnus-summary-catchup "gnus/catchup")
2859     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2860     (gnus-summary-exit "gnus/exit-summ")
2861     ;; Some new command that may need more suitable icons:
2862     (gnus-summary-print-article "gnus/print" nil :visible nil)
2863     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2864     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2865     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2866     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2867     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2868     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2869     ;;
2870     (gnus-info-find-node "gnus/help" nil :visible nil))
2871   "List of functions for the summary tool bar (retro look).
2872
2873 See `gmm-tool-bar-from-list' for the format of the list."
2874   :type '(repeat gmm-tool-bar-item)
2875   :version "23.1" ;; No Gnus
2876   :initialize 'custom-initialize-default
2877   :set 'gnus-summary-tool-bar-update
2878   :group 'gnus-summary)
2879
2880 (defcustom gnus-summary-tool-bar-zap-list t
2881   "List of icon items from the global tool bar.
2882 These items are not displayed in the Gnus summary mode tool bar.
2883
2884 See `gmm-tool-bar-from-list' for the format of the list."
2885   :type 'gmm-tool-bar-zap-list
2886   :version "23.1" ;; No Gnus
2887   :initialize 'custom-initialize-default
2888   :set 'gnus-summary-tool-bar-update
2889   :group 'gnus-summary)
2890
2891 (defvar image-load-path)
2892 (defvar tool-bar-map)
2893
2894 (defun gnus-summary-make-tool-bar (&optional force)
2895   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2896 When FORCE, rebuild the tool bar."
2897   (when (and (not (featurep 'xemacs))
2898              (boundp 'tool-bar-mode)
2899              tool-bar-mode
2900              (or (not gnus-summary-tool-bar-map) force))
2901     (let* ((load-path
2902             (gmm-image-load-path-for-library "gnus"
2903                                              "mail/save.xpm"
2904                                              nil t))
2905            (image-load-path (cons (car load-path)
2906                                   (when (boundp 'image-load-path)
2907                                     image-load-path)))
2908            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2909                                         gnus-summary-tool-bar-zap-list
2910                                         'gnus-summary-mode-map)))
2911       (when map
2912         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2913         ;; uses it's value.
2914         (setq gnus-summary-tool-bar-map map))))
2915   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2916
2917 (defun gnus-score-set-default (var value)
2918   "A version of set that updates the GNU Emacs menu-bar."
2919   (set var value)
2920   ;; It is the message that forces the active status to be updated.
2921   (message ""))
2922
2923 (defun gnus-make-score-map (type)
2924   "Make a summary score map of type TYPE."
2925   (if t
2926       nil
2927     (let ((headers '(("author" "from" string)
2928                      ("subject" "subject" string)
2929                      ("article body" "body" string)
2930                      ("article head" "head" string)
2931                      ("xref" "xref" string)
2932                      ("extra header" "extra" string)
2933                      ("lines" "lines" number)
2934                      ("followups to author" "followup" string)))
2935           (types '((number ("less than" <)
2936                            ("greater than" >)
2937                            ("equal" =))
2938                    (string ("substring" s)
2939                            ("exact string" e)
2940                            ("fuzzy string" f)
2941                            ("regexp" r))))
2942           (perms '(("temporary" (current-time-string))
2943                    ("permanent" nil)
2944                    ("immediate" now)))
2945           header)
2946       (list
2947        (apply
2948         'nconc
2949         (list
2950          (if (eq type 'lower)
2951              "Lower score"
2952            "Increase score"))
2953         (let (outh)
2954           (while headers
2955             (setq header (car headers))
2956             (setq outh
2957                   (cons
2958                    (apply
2959                     'nconc
2960                     (list (car header))
2961                     (let ((ts (cdr (assoc (nth 2 header) types)))
2962                           outt)
2963                       (while ts
2964                         (setq outt
2965                               (cons
2966                                (apply
2967                                 'nconc
2968                                 (list (caar ts))
2969                                 (let ((ps perms)
2970                                       outp)
2971                                   (while ps
2972                                     (setq outp
2973                                           (cons
2974                                            (vector
2975                                             (caar ps)
2976                                             (list
2977                                              'gnus-summary-score-entry
2978                                              (nth 1 header)
2979                                              (if (or (string= (nth 1 header)
2980                                                               "head")
2981                                                      (string= (nth 1 header)
2982                                                               "body"))
2983                                                  ""
2984                                                (list 'gnus-summary-header
2985                                                      (nth 1 header)))
2986                                              (list 'quote (nth 1 (car ts)))
2987                                              (list 'gnus-score-delta-default
2988                                                    nil)
2989                                              (nth 1 (car ps))
2990                                              t)
2991                                             t)
2992                                            outp))
2993                                     (setq ps (cdr ps)))
2994                                   (list (nreverse outp))))
2995                                outt))
2996                         (setq ts (cdr ts)))
2997                       (list (nreverse outt))))
2998                    outh))
2999             (setq headers (cdr headers)))
3000           (list (nreverse outh))))))))
3001
3002
3003 (declare-function turn-on-gnus-mailing-list-mode "gnus-ml" ())
3004
3005 \f
3006
3007 (defun gnus-summary-mode (&optional group)
3008   "Major mode for reading articles.
3009
3010 All normal editing commands are switched off.
3011 \\<gnus-summary-mode-map>
3012 Each line in this buffer represents one article.  To read an
3013 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
3014 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
3015 respectively.
3016
3017 You can also post articles and send mail from this buffer.  To
3018 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
3019 of an article, type `\\[gnus-summary-reply]'.
3020
3021 There are approx. one gazillion commands you can execute in this
3022 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
3023
3024 The following commands are available:
3025
3026 \\{gnus-summary-mode-map}"
3027   (interactive)
3028   (kill-all-local-variables)
3029   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
3030     (gnus-summary-make-local-variables))
3031   (gnus-summary-make-local-variables)
3032   (setq gnus-newsgroup-name group)
3033   (when (gnus-visual-p 'summary-menu 'menu)
3034     (gnus-summary-make-menu-bar)
3035     (gnus-summary-make-tool-bar))
3036   (gnus-make-thread-indent-array)
3037   (gnus-simplify-mode-line)
3038   (setq major-mode 'gnus-summary-mode)
3039   (setq mode-name "Summary")
3040   (make-local-variable 'minor-mode-alist)
3041   (use-local-map gnus-summary-mode-map)
3042   (buffer-disable-undo)
3043   (setq buffer-read-only t              ;Disable modification
3044         show-trailing-whitespace nil)
3045   (setq truncate-lines t)
3046   (setq selective-display t)
3047   (setq selective-display-ellipses t)   ;Display `...'
3048   (gnus-summary-set-display-table)
3049   (gnus-set-default-directory)
3050   (make-local-variable 'gnus-summary-line-format)
3051   (make-local-variable 'gnus-summary-line-format-spec)
3052   (make-local-variable 'gnus-summary-dummy-line-format)
3053   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3054   (make-local-variable 'gnus-summary-mark-positions)
3055   (gnus-make-local-hook 'pre-command-hook)
3056   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3057   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3058   (turn-on-gnus-mailing-list-mode)
3059   (mm-enable-multibyte)
3060   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3061   (gnus-update-summary-mark-positions))
3062
3063 (defun gnus-summary-make-local-variables ()
3064   "Make all the local summary buffer variables."
3065   (let (global)
3066     (dolist (local gnus-summary-local-variables)
3067       (if (consp local)
3068           (progn
3069             (if (eq (cdr local) 'global)
3070                 ;; Copy the global value of the variable.
3071                 (setq global (symbol-value (car local)))
3072               ;; Use the value from the list.
3073               (setq global (eval (cdr local))))
3074             (set (make-local-variable (car local)) global))
3075         ;; Simple nil-valued local variable.
3076         (set (make-local-variable local) nil)))))
3077
3078 (defun gnus-summary-clear-local-variables ()
3079   (let ((locals gnus-summary-local-variables))
3080     (while locals
3081       (if (consp (car locals))
3082           (and (symbolp (caar locals))
3083                (set (caar locals) nil))
3084         (and (symbolp (car locals))
3085              (set (car locals) nil)))
3086       (setq locals (cdr locals)))))
3087
3088 ;; Summary data functions.
3089
3090 (defmacro gnus-data-number (data)
3091   `(car ,data))
3092
3093 (defmacro gnus-data-set-number (data number)
3094   `(setcar ,data ,number))
3095
3096 (defmacro gnus-data-mark (data)
3097   `(nth 1 ,data))
3098
3099 (defmacro gnus-data-set-mark (data mark)
3100   `(setcar (nthcdr 1 ,data) ,mark))
3101
3102 (defmacro gnus-data-pos (data)
3103   `(nth 2 ,data))
3104
3105 (defmacro gnus-data-set-pos (data pos)
3106   `(setcar (nthcdr 2 ,data) ,pos))
3107
3108 (defmacro gnus-data-header (data)
3109   `(nth 3 ,data))
3110
3111 (defmacro gnus-data-set-header (data header)
3112   `(setf (nth 3 ,data) ,header))
3113
3114 (defmacro gnus-data-level (data)
3115   `(nth 4 ,data))
3116
3117 (defmacro gnus-data-unread-p (data)
3118   `(= (nth 1 ,data) gnus-unread-mark))
3119
3120 (defmacro gnus-data-read-p (data)
3121   `(/= (nth 1 ,data) gnus-unread-mark))
3122
3123 (defmacro gnus-data-pseudo-p (data)
3124   `(consp (nth 3 ,data)))
3125
3126 (defmacro gnus-data-find (number)
3127   `(assq ,number gnus-newsgroup-data))
3128
3129 (defmacro gnus-data-find-list (number &optional data)
3130   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3131      (memq (assq ,number bdata)
3132            bdata)))
3133
3134 (defmacro gnus-data-make (number mark pos header level)
3135   `(list ,number ,mark ,pos ,header ,level))
3136
3137 (defun gnus-data-enter (after-article number mark pos header level offset)
3138   (let ((data (gnus-data-find-list after-article)))
3139     (unless data
3140       (error "No such article: %d" after-article))
3141     (setcdr data (cons (gnus-data-make number mark pos header level)
3142                        (cdr data)))
3143     (setq gnus-newsgroup-data-reverse nil)
3144     (gnus-data-update-list (cddr data) offset)))
3145
3146 (defun gnus-data-enter-list (after-article list &optional offset)
3147   (when list
3148     (let ((data (and after-article (gnus-data-find-list after-article)))
3149           (ilist list))
3150       (if (not (or data
3151                    after-article))
3152           (let ((odata gnus-newsgroup-data))
3153             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3154             (when offset
3155               (gnus-data-update-list odata offset)))
3156         ;; Find the last element in the list to be spliced into the main
3157         ;; list.
3158         (setq list (last list))
3159         (if (not data)
3160             (progn
3161               (setcdr list gnus-newsgroup-data)
3162               (setq gnus-newsgroup-data ilist)
3163               (when offset
3164                 (gnus-data-update-list (cdr list) offset)))
3165           (setcdr list (cdr data))
3166           (setcdr data ilist)
3167           (when offset
3168             (gnus-data-update-list (cdr list) offset))))
3169       (setq gnus-newsgroup-data-reverse nil))))
3170
3171 (defun gnus-data-remove (article &optional offset)
3172   (let ((data gnus-newsgroup-data))
3173     (if (= (gnus-data-number (car data)) article)
3174         (progn
3175           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3176                 gnus-newsgroup-data-reverse nil)
3177           (when offset
3178             (gnus-data-update-list gnus-newsgroup-data offset)))
3179       (while (cdr data)
3180         (when (= (gnus-data-number (cadr data)) article)
3181           (setcdr data (cddr data))
3182           (when offset
3183             (gnus-data-update-list (cdr data) offset))
3184           (setq data nil
3185                 gnus-newsgroup-data-reverse nil))
3186         (setq data (cdr data))))))
3187
3188 (defmacro gnus-data-list (backward)
3189   `(if ,backward
3190        (or gnus-newsgroup-data-reverse
3191            (setq gnus-newsgroup-data-reverse
3192                  (reverse gnus-newsgroup-data)))
3193      gnus-newsgroup-data))
3194
3195 (defun gnus-data-update-list (data offset)
3196   "Add OFFSET to the POS of all data entries in DATA."
3197   (setq gnus-newsgroup-data-reverse nil)
3198   (while data
3199     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3200     (setq data (cdr data))))
3201
3202 (defun gnus-summary-article-pseudo-p (article)
3203   "Say whether this article is a pseudo article or not."
3204   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3205
3206 (defmacro gnus-summary-article-sparse-p (article)
3207   "Say whether this article is a sparse article or not."
3208   `(memq ,article gnus-newsgroup-sparse))
3209
3210 (defmacro gnus-summary-article-ancient-p (article)
3211   "Say whether this article is a sparse article or not."
3212   `(memq ,article gnus-newsgroup-ancient))
3213
3214 (defun gnus-article-parent-p (number)
3215   "Say whether this article is a parent or not."
3216   (let ((data (gnus-data-find-list number)))
3217     (and (cdr data)              ; There has to be an article after...
3218          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3219             (gnus-data-level (nth 1 data))))))
3220
3221 (defun gnus-article-children (number)
3222   "Return a list of all children to NUMBER."
3223   (let* ((data (gnus-data-find-list number))
3224          (level (gnus-data-level (car data)))
3225          children)
3226     (setq data (cdr data))
3227     (while (and data
3228                 (= (gnus-data-level (car data)) (1+ level)))
3229       (push (gnus-data-number (car data)) children)
3230       (setq data (cdr data)))
3231     children))
3232
3233 (defmacro gnus-summary-skip-intangible ()
3234   "If the current article is intangible, then jump to a different article."
3235   '(let ((to (get-text-property (point) 'gnus-intangible)))
3236      (and to (gnus-summary-goto-subject to))))
3237
3238 (defmacro gnus-summary-article-intangible-p ()
3239   "Say whether this article is intangible or not."
3240   '(get-text-property (point) 'gnus-intangible))
3241
3242 (defun gnus-article-read-p (article)
3243   "Say whether ARTICLE is read or not."
3244   (not (or (memq article gnus-newsgroup-marked)
3245            (memq article gnus-newsgroup-spam-marked)
3246            (memq article gnus-newsgroup-unreads)
3247            (memq article gnus-newsgroup-unselected)
3248            (memq article gnus-newsgroup-dormant))))
3249
3250 ;; Some summary mode macros.
3251
3252 (defmacro gnus-summary-article-number ()
3253   "The article number of the article on the current line.
3254 If there isn't an article number here, then we return the current
3255 article number."
3256   '(progn
3257      (gnus-summary-skip-intangible)
3258      (or (get-text-property (point) 'gnus-number)
3259          (gnus-summary-last-subject))))
3260
3261 (defmacro gnus-summary-article-header (&optional number)
3262   "Return the header of article NUMBER."
3263   `(gnus-data-header (gnus-data-find
3264                       ,(or number '(gnus-summary-article-number)))))
3265
3266 (defmacro gnus-summary-thread-level (&optional number)
3267   "Return the level of thread that starts with article NUMBER."
3268   `(if (and (eq gnus-summary-make-false-root 'dummy)
3269             (get-text-property (point) 'gnus-intangible))
3270        0
3271      (gnus-data-level (gnus-data-find
3272                        ,(or number '(gnus-summary-article-number))))))
3273
3274 (defmacro gnus-summary-article-mark (&optional number)
3275   "Return the mark of article NUMBER."
3276   `(gnus-data-mark (gnus-data-find
3277                     ,(or number '(gnus-summary-article-number)))))
3278
3279 (defmacro gnus-summary-article-pos (&optional number)
3280   "Return the position of the line of article NUMBER."
3281   `(gnus-data-pos (gnus-data-find
3282                    ,(or number '(gnus-summary-article-number)))))
3283
3284 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3285 (defmacro gnus-summary-article-subject (&optional number)
3286   "Return current subject string or nil if nothing."
3287   `(let ((headers
3288           ,(if number
3289                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3290              '(gnus-data-header (assq (gnus-summary-article-number)
3291                                       gnus-newsgroup-data)))))
3292      (and headers
3293           (vectorp headers)
3294           (mail-header-subject headers))))
3295
3296 (defmacro gnus-summary-article-score (&optional number)
3297   "Return current article score."
3298   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3299                   gnus-newsgroup-scored))
3300        gnus-summary-default-score 0))
3301
3302 (defun gnus-summary-article-children (&optional number)
3303   "Return a list of article numbers that are children of article NUMBER."
3304   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3305          (level (gnus-data-level (car data)))
3306          l children)
3307     (while (and (setq data (cdr data))
3308                 (> (setq l (gnus-data-level (car data))) level))
3309       (and (= (1+ level) l)
3310            (push (gnus-data-number (car data))
3311                  children)))
3312     (nreverse children)))
3313
3314 (defun gnus-summary-article-parent (&optional number)
3315   "Return the article number of the parent of article NUMBER."
3316   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3317                                     (gnus-data-list t)))
3318          (level (gnus-data-level (car data))))
3319     (if (zerop level)
3320         ()                              ; This is a root.
3321       ;; We search until we find an article with a level less than
3322       ;; this one.  That function has to be the parent.
3323       (while (and (setq data (cdr data))
3324                   (not (< (gnus-data-level (car data)) level))))
3325       (and data (gnus-data-number (car data))))))
3326
3327 (defun gnus-unread-mark-p (mark)
3328   "Say whether MARK is the unread mark."
3329   (= mark gnus-unread-mark))
3330
3331 (defun gnus-read-mark-p (mark)
3332   "Say whether MARK is one of the marks that mark as read.
3333 This is all marks except unread, ticked, dormant, and expirable."
3334   (not (or (= mark gnus-unread-mark)
3335            (= mark gnus-ticked-mark)
3336            (= mark gnus-spam-mark)
3337            (= mark gnus-dormant-mark)
3338            (= mark gnus-expirable-mark))))
3339
3340 (defmacro gnus-article-mark (number)
3341   "Return the MARK of article NUMBER.
3342 This macro should only be used when computing the mark the \"first\"
3343 time; i.e., when generating the summary lines.  After that,
3344 `gnus-summary-article-mark' should be used to examine the
3345 marks of articles."
3346   `(cond
3347     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3348     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3349     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3350     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3351     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3352     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3353     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3354     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3355            gnus-ancient-mark))))
3356
3357 ;; Saving hidden threads.
3358
3359 (defmacro gnus-save-hidden-threads (&rest forms)
3360   "Save hidden threads, eval FORMS, and restore the hidden threads."
3361   (let ((config (make-symbol "config")))
3362     `(let ((,config (gnus-hidden-threads-configuration)))
3363        (unwind-protect
3364            (save-excursion
3365              ,@forms)
3366          (gnus-restore-hidden-threads-configuration ,config)))))
3367 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3368 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3369
3370 (defun gnus-data-compute-positions ()
3371   "Compute the positions of all articles."
3372   (setq gnus-newsgroup-data-reverse nil)
3373   (let ((data gnus-newsgroup-data))
3374     (save-excursion
3375       (gnus-save-hidden-threads
3376         (gnus-summary-show-all-threads)
3377         (goto-char (point-min))
3378         (while data
3379           (while (get-text-property (point) 'gnus-intangible)
3380             (forward-line 1))
3381           (gnus-data-set-pos (car data) (+ (point) 3))
3382           (setq data (cdr data))
3383           (forward-line 1))))))
3384
3385 (defun gnus-hidden-threads-configuration ()
3386   "Return the current hidden threads configuration."
3387   (save-excursion
3388     (let (config)
3389       (goto-char (point-min))
3390       (while (search-forward "\r" nil t)
3391         (push (1- (point)) config))
3392       config)))
3393
3394 (defun gnus-restore-hidden-threads-configuration (config)
3395   "Restore hidden threads configuration from CONFIG."
3396   (save-excursion
3397     (let (point (inhibit-read-only t))
3398       (while (setq point (pop config))
3399         (when (and (< point (point-max))
3400                    (goto-char point)
3401                    (eq (char-after) ?\n))
3402           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3403
3404 ;; Various summary mode internalish functions.
3405
3406 (defun gnus-mouse-pick-article (e)
3407   (interactive "e")
3408   (mouse-set-point e)
3409   (gnus-summary-next-page nil t))
3410
3411 (defun gnus-summary-set-display-table ()
3412   "Change the display table.
3413 Odd characters have a tendency to mess
3414 up nicely formatted displays - we make all possible glyphs
3415 display only a single character."
3416
3417   ;; We start from the standard display table, if any.
3418   (let ((table (or (copy-sequence standard-display-table)
3419                    (make-display-table)))
3420         (i 32))
3421     ;; Nix out all the control chars...
3422     (while (>= (setq i (1- i)) 0)
3423       (aset table i [??]))
3424    ;; ... but not newline and cr, of course.  (cr is necessary for the
3425     ;; selective display).
3426     (aset table ?\n nil)
3427     (aset table ?\r nil)
3428     ;; We keep TAB as well.
3429     (aset table ?\t nil)
3430     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3431     ;; Emacs 23 (unicode), that are not set already.
3432     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3433                  160
3434                256)))
3435       (while (>= (setq i (1- i)) 127)
3436         ;; Only modify if the entry is nil.
3437         (unless (aref table i)
3438           (aset table i [??]))))
3439     (setq buffer-display-table table)))
3440
3441 (defun gnus-summary-set-article-display-arrow (pos)
3442   "Update the overlay arrow to point to line at position POS."
3443   (when (and gnus-summary-display-arrow
3444              (boundp 'overlay-arrow-position)
3445              (boundp 'overlay-arrow-string))
3446     (save-excursion
3447       (goto-char pos)
3448       (beginning-of-line)
3449       (unless overlay-arrow-position
3450         (setq overlay-arrow-position (make-marker)))
3451       (setq overlay-arrow-string "=>"
3452             overlay-arrow-position (set-marker overlay-arrow-position
3453                                                (point)
3454                                                (current-buffer))))))
3455
3456 (defun gnus-summary-setup-buffer (group)
3457   "Initialize summary buffer."
3458   (let ((buffer (gnus-summary-buffer-name group))
3459         (dead-name (concat "*Dead Summary "
3460                            (gnus-group-decoded-name group) "*")))
3461     ;; If a dead summary buffer exists, we kill it.
3462     (when (gnus-buffer-live-p dead-name)
3463       (gnus-kill-buffer dead-name))
3464     (if (get-buffer buffer)
3465         (progn
3466           (set-buffer buffer)
3467           (setq gnus-summary-buffer (current-buffer))
3468           (not gnus-newsgroup-prepared))
3469       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3470       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3471       (gnus-summary-mode group)
3472       (when gnus-carpal
3473         (gnus-carpal-setup-buffer 'summary))
3474       (when (gnus-group-quit-config group)
3475         (set (make-local-variable 'gnus-single-article-buffer) nil))
3476       (make-local-variable 'gnus-article-buffer)
3477       (make-local-variable 'gnus-article-current)
3478       (make-local-variable 'gnus-original-article-buffer)
3479       (setq gnus-newsgroup-name group)
3480       ;; Set any local variables in the group parameters.
3481       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3482       t)))
3483
3484 (defun gnus-set-global-variables ()
3485   "Set the global equivalents of the buffer-local variables.
3486 They are set to the latest values they had.  These reflect the summary
3487 buffer that was in action when the last article was fetched."
3488   (when (eq major-mode 'gnus-summary-mode)
3489     (setq gnus-summary-buffer (current-buffer))
3490     (let ((name gnus-newsgroup-name)
3491           (marked gnus-newsgroup-marked)
3492           (spam gnus-newsgroup-spam-marked)
3493           (unread gnus-newsgroup-unreads)
3494           (headers gnus-current-headers)
3495           (data gnus-newsgroup-data)
3496           (summary gnus-summary-buffer)
3497           (article-buffer gnus-article-buffer)
3498           (original gnus-original-article-buffer)
3499           (gac gnus-article-current)
3500           (reffed gnus-reffed-article-number)
3501           (score-file gnus-current-score-file)
3502           (default-charset gnus-newsgroup-charset)
3503           vlist)
3504       (let ((locals gnus-newsgroup-variables))
3505         (while locals
3506           (if (consp (car locals))
3507               (push (eval (caar locals)) vlist)
3508             (push (eval (car locals)) vlist))
3509           (setq locals (cdr locals)))
3510         (setq vlist (nreverse vlist)))
3511       (with-current-buffer gnus-group-buffer
3512         (setq gnus-newsgroup-name name
3513               gnus-newsgroup-marked marked
3514               gnus-newsgroup-spam-marked spam
3515               gnus-newsgroup-unreads unread
3516               gnus-current-headers headers
3517               gnus-newsgroup-data data
3518               gnus-article-current gac
3519               gnus-summary-buffer summary
3520               gnus-article-buffer article-buffer
3521               gnus-original-article-buffer original
3522               gnus-reffed-article-number reffed
3523               gnus-current-score-file score-file
3524               gnus-newsgroup-charset default-charset)
3525         (let ((locals gnus-newsgroup-variables))
3526           (while locals
3527             (if (consp (car locals))
3528                 (set (caar locals) (pop vlist))
3529               (set (car locals) (pop vlist)))
3530             (setq locals (cdr locals))))
3531         ;; The article buffer also has local variables.
3532         (when (gnus-buffer-live-p gnus-article-buffer)
3533           (set-buffer gnus-article-buffer)
3534           (setq gnus-summary-buffer summary))))))
3535
3536 (defun gnus-summary-article-unread-p (article)
3537   "Say whether ARTICLE is unread or not."
3538   (memq article gnus-newsgroup-unreads))
3539
3540 (defun gnus-summary-first-article-p (&optional article)
3541   "Return whether ARTICLE is the first article in the buffer."
3542   (if (not (setq article (or article (gnus-summary-article-number))))
3543       nil
3544     (eq article (caar gnus-newsgroup-data))))
3545
3546 (defun gnus-summary-last-article-p (&optional article)
3547   "Return whether ARTICLE is the last article in the buffer."
3548   (if (not (setq article (or article (gnus-summary-article-number))))
3549       ;; All non-existent numbers are the last article.  :-)
3550       t
3551     (not (cdr (gnus-data-find-list article)))))
3552
3553 (defun gnus-make-thread-indent-array (&optional n)
3554   (when (or n
3555             (progn (setq n 200) nil)
3556             (null gnus-thread-indent-array)
3557             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3558     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3559           gnus-thread-indent-array-level gnus-thread-indent-level)
3560     (while (>= n 0)
3561       (aset gnus-thread-indent-array n
3562             (make-string (* n gnus-thread-indent-level) ? ))
3563       (setq n (1- n)))))
3564
3565 (defun gnus-update-summary-mark-positions ()
3566   "Compute where the summary marks are to go."
3567   (save-excursion
3568     (when (gnus-buffer-exists-p gnus-summary-buffer)
3569       (set-buffer gnus-summary-buffer))
3570     (let ((spec gnus-summary-line-format-spec)
3571           pos)
3572       (save-excursion
3573         (gnus-set-work-buffer)
3574         (let ((gnus-tmp-unread ?Z)
3575               (gnus-replied-mark ?Z)
3576               (gnus-score-below-mark ?Z)
3577               (gnus-score-over-mark ?Z)
3578               (gnus-undownloaded-mark ?Z)
3579               (gnus-summary-line-format-spec spec)
3580               (gnus-newsgroup-downloadable '(0))
3581               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3582               case-fold-search ignores)
3583           ;; Here, all marks are bound to Z.
3584           (gnus-summary-insert-line header
3585                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3586           (goto-char (point-min))
3587           ;; Memorize the positions of the same characters as dummy marks.
3588           (while (re-search-forward "[A-D]" nil t)
3589             (push (point) ignores))
3590           (erase-buffer)
3591           ;; We use A-D as dummy marks in order to know column positions
3592           ;; where marks should be inserted.
3593           (setq gnus-tmp-unread ?A
3594                 gnus-replied-mark ?B
3595                 gnus-score-below-mark ?C
3596                 gnus-score-over-mark ?C
3597                 gnus-undownloaded-mark ?D)
3598           (gnus-summary-insert-line header
3599                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3600           ;; Ignore characters which aren't dummy marks.
3601           (dolist (p ignores)
3602             (delete-region (goto-char (1- p)) p)
3603             (insert ?Z))
3604           (goto-char (point-min))
3605           (setq pos (list (cons 'unread
3606                                 (and (search-forward "A" nil t)
3607                                      (- (point) (point-min) 1)))))
3608           (goto-char (point-min))
3609           (push (cons 'replied (and (search-forward "B" nil t)
3610                                     (- (point) (point-min) 1)))
3611                 pos)
3612           (goto-char (point-min))
3613           (push (cons 'score (and (search-forward "C" nil t)
3614                                   (- (point) (point-min) 1)))
3615                 pos)
3616           (goto-char (point-min))
3617           (push (cons 'download (and (search-forward "D" nil t)
3618                                      (- (point) (point-min) 1)))
3619                 pos)))
3620       (setq gnus-summary-mark-positions pos))))
3621
3622 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3623   "Insert a dummy root in the summary buffer."
3624   (beginning-of-line)
3625   (gnus-add-text-properties
3626    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3627    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3628
3629 (defun gnus-summary-extract-address-component (from)
3630   (or (car (funcall gnus-extract-address-components from))
3631       from))
3632
3633 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3634   (let ((mail-parse-charset gnus-newsgroup-charset)
3635         (ignored-from-addresses (gnus-ignored-from-addresses))
3636         ; Is it really necessary to do this next part for each summary line?
3637         ; Luckily, doesn't seem to slow things down much.
3638         (mail-parse-ignored-charsets
3639          (with-current-buffer gnus-summary-buffer
3640            gnus-newsgroup-ignored-charsets)))
3641     (or
3642      (and ignored-from-addresses
3643           (string-match ignored-from-addresses gnus-tmp-from)
3644           (let ((extra-headers (mail-header-extra header))
3645                 to
3646                 newsgroups)
3647             (cond
3648              ((setq to (cdr (assq 'To extra-headers)))
3649               (concat gnus-summary-to-prefix
3650                       (inline
3651                         (gnus-summary-extract-address-component
3652                          (funcall gnus-decode-encoded-address-function to)))))
3653              ((setq newsgroups
3654                     (or
3655                      (cdr (assq 'Newsgroups extra-headers))
3656                      (and
3657                       (memq 'Newsgroups gnus-extra-headers)
3658                       (eq (car (gnus-find-method-for-group
3659                                 gnus-newsgroup-name)) 'nntp)
3660                       (gnus-group-real-name gnus-newsgroup-name))))
3661               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3662      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3663
3664 (defun gnus-summary-insert-line (gnus-tmp-header
3665                                  gnus-tmp-level gnus-tmp-current
3666                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3667                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3668                                  &optional gnus-tmp-dummy gnus-tmp-score
3669                                  gnus-tmp-process)
3670   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3671       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3672                                           gnus-tmp-level)))
3673   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3674          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3675          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3676          (gnus-tmp-score-char
3677           (if (or (null gnus-summary-default-score)
3678                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3679                       gnus-summary-zcore-fuzz))
3680               ?                         ;Whitespace
3681             (if (< gnus-tmp-score gnus-summary-default-score)
3682                 gnus-score-below-mark gnus-score-over-mark)))
3683          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3684          (gnus-tmp-replied
3685           (cond (gnus-tmp-process gnus-process-mark)
3686                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3687                  gnus-cached-mark)
3688                 (gnus-tmp-replied gnus-replied-mark)
3689                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3690                  gnus-forwarded-mark)
3691                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3692                  gnus-saved-mark)
3693                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3694                  gnus-recent-mark)
3695                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3696                  gnus-unseen-mark)
3697                 (t gnus-no-mark)))
3698          (gnus-tmp-downloaded
3699           (cond (undownloaded
3700                  gnus-undownloaded-mark)
3701                 (gnus-newsgroup-agentized
3702                  gnus-downloaded-mark)
3703                 (t
3704                  gnus-no-mark)))
3705          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3706          (gnus-tmp-name
3707           (cond
3708            ((string-match "<[^>]+> *$" gnus-tmp-from)
3709             (let ((beg (match-beginning 0)))
3710               (or (and (string-match "^\".+\"" gnus-tmp-from)
3711                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3712                   (substring gnus-tmp-from 0 beg))))
3713            ((string-match "(.+)" gnus-tmp-from)
3714             (substring gnus-tmp-from
3715                        (1+ (match-beginning 0)) (1- (match-end 0))))
3716            (t gnus-tmp-from)))
3717          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3718          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3719          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3720          (inhibit-read-only t))
3721     (when (string= gnus-tmp-name "")
3722       (setq gnus-tmp-name gnus-tmp-from))
3723     (unless (numberp gnus-tmp-lines)
3724       (setq gnus-tmp-lines -1))
3725     (if (= gnus-tmp-lines -1)
3726         (setq gnus-tmp-lines "?")
3727       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3728       (gnus-put-text-property
3729      (point)
3730      (progn (eval gnus-summary-line-format-spec) (point))
3731        'gnus-number gnus-tmp-number)
3732     (when (gnus-visual-p 'summary-highlight 'highlight)
3733       (forward-line -1)
3734       (gnus-run-hooks 'gnus-summary-update-hook)
3735       (forward-line 1))))
3736
3737 (defun gnus-summary-update-line (&optional dont-update)
3738   "Update summary line after change."
3739   (when (and gnus-summary-default-score
3740              (not gnus-summary-inhibit-highlight))
3741     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3742            (article (gnus-summary-article-number))
3743            (score (gnus-summary-article-score article)))
3744       (unless dont-update
3745         (if (and gnus-summary-mark-below
3746                  (< (gnus-summary-article-score)
3747                     gnus-summary-mark-below))
3748             ;; This article has a low score, so we mark it as read.
3749             (when (memq article gnus-newsgroup-unreads)
3750               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3751           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3752             ;; This article was previously marked as read on account
3753             ;; of a low score, but now it has risen, so we mark it as
3754             ;; unread.
3755             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3756         (gnus-summary-update-mark
3757          (if (or (null gnus-summary-default-score)
3758                  (<= (abs (- score gnus-summary-default-score))
3759                      gnus-summary-zcore-fuzz))
3760              ?                          ;Whitespace
3761            (if (< score gnus-summary-default-score)
3762                gnus-score-below-mark gnus-score-over-mark))
3763          'score))
3764       ;; Do visual highlighting.
3765       (when (gnus-visual-p 'summary-highlight 'highlight)
3766         (gnus-run-hooks 'gnus-summary-update-hook)))))
3767
3768 (defvar gnus-tmp-new-adopts nil)
3769
3770 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3771   "Return the number of articles in THREAD.
3772 This may be 0 in some cases -- if none of the articles in
3773 the thread are to be displayed."
3774   (let* ((number
3775          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3776           (cond
3777            ((not (listp thread))
3778             1)
3779            ((and (consp thread) (cdr thread))
3780             (apply
3781              '+ 1 (mapcar
3782                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3783            ((null thread)
3784             1)
3785            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3786             1)
3787            (t 0))))
3788     (when (and level (zerop level) gnus-tmp-new-adopts)
3789       (incf number
3790             (apply '+ (mapcar
3791                        'gnus-summary-number-of-articles-in-thread
3792                        gnus-tmp-new-adopts))))
3793     (if char
3794         (if (> number 1) gnus-not-empty-thread-mark
3795           gnus-empty-thread-mark)
3796       number)))
3797
3798 (defsubst gnus-summary-line-message-size (head)
3799   "Return pretty-printed version of message size.
3800 This function is intended to be used in
3801 `gnus-summary-line-format-alist'."
3802   (let ((c (or (mail-header-chars head) -1)))
3803     (cond ((< c 0) "n/a")               ; chars not available
3804           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3805           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3806           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3807           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3808
3809
3810 (defun gnus-summary-set-local-parameters (group)
3811   "Go through the local params of GROUP and set all variable specs in that list."
3812   (let ((vars '(quit-config)))          ; Ignore quit-config.
3813     (dolist (elem (gnus-group-find-parameter group))
3814       (and (consp elem)                 ; Has to be a cons.
3815            (consp (cdr elem))           ; The cdr has to be a list.
3816            (symbolp (car elem))         ; Has to be a symbol in there.
3817            (not (memq (car elem) vars))
3818            (ignore-errors               ; So we set it.
3819              (push (car elem) vars)
3820              (make-local-variable (car elem))
3821              (set (car elem) (eval (nth 1 elem))))))))
3822
3823 (defun gnus-summary-read-group (group &optional show-all no-article
3824                                       kill-buffer no-display backward
3825                                       select-articles)
3826   "Start reading news in newsgroup GROUP.
3827 If SHOW-ALL is non-nil, already read articles are also listed.
3828 If NO-ARTICLE is non-nil, no article is selected initially.
3829 If NO-DISPLAY, don't generate a summary buffer."
3830   (let (result)
3831     (while (and group
3832                 (null (setq result
3833                             (let ((gnus-auto-select-next nil))
3834                               (or (gnus-summary-read-group-1
3835                                    group show-all no-article
3836                                    kill-buffer no-display
3837                                    select-articles)
3838                                   (setq show-all nil
3839                                         select-articles nil)))))
3840                 (eq gnus-auto-select-next 'quietly))
3841       (set-buffer gnus-group-buffer)
3842       ;; The entry function called above goes to the next
3843       ;; group automatically, so we go two groups back
3844       ;; if we are searching for the previous group.
3845       (when backward
3846         (gnus-group-prev-unread-group 2))
3847       (if (not (equal group (gnus-group-group-name)))
3848           (setq group (gnus-group-group-name))
3849         (setq group nil)))
3850     result))
3851
3852 (defun gnus-summary-read-group-1 (group show-all no-article
3853                                         kill-buffer no-display
3854                                         &optional select-articles)
3855   ;; Killed foreign groups can't be entered.
3856   ;;  (when (and (not (gnus-group-native-p group))
3857   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3858   ;;    (error "Dead non-native groups can't be entered"))
3859   (gnus-message 5 "Retrieving newsgroup: %s..."
3860                 (gnus-group-decoded-name group))
3861   (let* ((new-group (gnus-summary-setup-buffer group))
3862          (quit-config (gnus-group-quit-config group))
3863          (did-select (and new-group (gnus-select-newsgroup
3864                                      group show-all select-articles))))
3865     (cond
3866      ;; This summary buffer exists already, so we just select it.
3867      ((not new-group)
3868       (gnus-set-global-variables)
3869       (when kill-buffer
3870         (gnus-kill-or-deaden-summary kill-buffer))
3871       (gnus-configure-windows 'summary 'force)
3872       (gnus-set-mode-line 'summary)
3873       (gnus-summary-position-point)
3874       (message "")
3875       t)
3876      ;; We couldn't select this group.
3877      ((null did-select)
3878       (when (and (eq major-mode 'gnus-summary-mode)
3879                  (not (equal (current-buffer) kill-buffer)))
3880         (kill-buffer (current-buffer))
3881         (if (not quit-config)
3882             (progn
3883               ;; Update the info -- marks might need to be removed,
3884               ;; for instance.
3885               (gnus-summary-update-info)
3886               (set-buffer gnus-group-buffer)
3887               (gnus-group-jump-to-group group)
3888               (gnus-group-next-unread-group 1))
3889           (gnus-handle-ephemeral-exit quit-config)))
3890       (let ((grpinfo (gnus-get-info group)))
3891         (if (null (gnus-info-read grpinfo))
3892             (gnus-message 3 "Group %s contains no messages"
3893                           (gnus-group-decoded-name group))
3894           (gnus-message 3 "Can't select group")))
3895       nil)
3896      ;; The user did a `C-g' while prompting for number of articles,
3897      ;; so we exit this group.
3898      ((eq did-select 'quit)
3899       (and (eq major-mode 'gnus-summary-mode)
3900            (not (equal (current-buffer) kill-buffer))
3901            (kill-buffer (current-buffer)))
3902       (when kill-buffer
3903         (gnus-kill-or-deaden-summary kill-buffer))
3904       (if (not quit-config)
3905           (progn
3906             (set-buffer gnus-group-buffer)
3907             (gnus-group-jump-to-group group)
3908             (gnus-group-next-unread-group 1)
3909             (gnus-configure-windows 'group 'force))
3910         (gnus-handle-ephemeral-exit quit-config))
3911       ;; Finally signal the quit.
3912       (signal 'quit nil))
3913      ;; The group was successfully selected.
3914      (t
3915       (gnus-set-global-variables)
3916       ;; Save the active value in effect when the group was entered.
3917       (setq gnus-newsgroup-active
3918             (gnus-copy-sequence
3919              (gnus-active gnus-newsgroup-name)))
3920       ;; You can change the summary buffer in some way with this hook.
3921       (gnus-run-hooks 'gnus-select-group-hook)
3922       (when (memq 'summary (gnus-update-format-specifications
3923                             nil 'summary 'summary-mode 'summary-dummy))
3924         ;; The format specification for the summary line was updated,
3925         ;; so we need to update the mark positions as well.
3926         (gnus-update-summary-mark-positions))
3927       ;; Do score processing.
3928       (when gnus-use-scoring
3929         (gnus-possibly-score-headers))
3930       ;; Check whether to fill in the gaps in the threads.
3931       (when gnus-build-sparse-threads
3932         (gnus-build-sparse-threads))
3933       ;; Find the initial limit.
3934       (if show-all
3935           (let ((gnus-newsgroup-dormant nil))
3936             (gnus-summary-initial-limit show-all))
3937         (gnus-summary-initial-limit show-all))
3938       ;; Generate the summary buffer.
3939       (unless no-display
3940         (gnus-summary-prepare))
3941       (when gnus-use-trees
3942         (gnus-tree-open group)
3943         (setq gnus-summary-highlight-line-function
3944               'gnus-tree-highlight-article))
3945       ;; If the summary buffer is empty, but there are some low-scored
3946       ;; articles or some excluded dormants, we include these in the
3947       ;; buffer.
3948       (when (and (zerop (buffer-size))
3949                  (not no-display))
3950         (cond (gnus-newsgroup-dormant
3951                (gnus-summary-limit-include-dormant))
3952               ((and gnus-newsgroup-scored show-all)
3953                (gnus-summary-limit-include-expunged t))))
3954       ;; Function `gnus-apply-kill-file' must be called in this hook.
3955       (gnus-run-hooks 'gnus-apply-kill-hook)
3956       (if (and (zerop (buffer-size))
3957                (not no-display))
3958           (progn
3959             ;; This newsgroup is empty.
3960             (gnus-summary-catchup-and-exit nil t)
3961             (gnus-message 6 "No unread news")
3962             (when kill-buffer
3963               (gnus-kill-or-deaden-summary kill-buffer))
3964             ;; Return nil from this function.
3965             nil)
3966         ;; Hide conversation thread subtrees.  We cannot do this in
3967         ;; gnus-summary-prepare-hook since kill processing may not
3968         ;; work with hidden articles.
3969         (gnus-summary-maybe-hide-threads)
3970         (when kill-buffer
3971           (gnus-kill-or-deaden-summary kill-buffer))
3972         (gnus-summary-auto-select-subject)
3973         ;; Show first unread article if requested.
3974         (if (and (not no-article)
3975                  (not no-display)
3976                  gnus-newsgroup-unreads
3977                  gnus-auto-select-first)
3978             (progn
3979               (gnus-configure-windows 'summary)
3980               (let ((art (gnus-summary-article-number)))
3981                 (unless (and (not gnus-plugged)
3982                              (or (memq art gnus-newsgroup-undownloaded)
3983                                  (memq art gnus-newsgroup-downloadable)))
3984                   (gnus-summary-goto-article art))))
3985           ;; Don't select any articles.
3986           (gnus-summary-position-point)
3987           (gnus-configure-windows 'summary 'force)
3988           (gnus-set-mode-line 'summary))
3989         (when (and gnus-auto-center-group
3990                    (get-buffer-window gnus-group-buffer t))
3991           ;; Gotta use windows, because recenter does weird stuff if
3992           ;; the current buffer ain't the displayed window.
3993           (let ((owin (selected-window)))
3994             (select-window (get-buffer-window gnus-group-buffer t))
3995             (when (gnus-group-goto-group group)
3996               (recenter))
3997             (select-window owin)))
3998         ;; Mark this buffer as "prepared".
3999         (setq gnus-newsgroup-prepared t)
4000         (gnus-run-hooks 'gnus-summary-prepared-hook)
4001         (unless (gnus-ephemeral-group-p group)
4002           (gnus-group-update-group group))
4003         t)))))
4004
4005 (defun gnus-summary-auto-select-subject ()
4006   "Select the subject line on initial group entry."
4007   (goto-char (point-min))
4008   (cond
4009    ((eq gnus-auto-select-subject 'best)
4010     (gnus-summary-best-unread-subject))
4011    ((eq gnus-auto-select-subject 'unread)
4012     (gnus-summary-first-unread-subject))
4013    ((eq gnus-auto-select-subject 'unseen)
4014     (gnus-summary-first-unseen-subject))
4015    ((eq gnus-auto-select-subject 'unseen-or-unread)
4016     (gnus-summary-first-unseen-or-unread-subject))
4017    ((eq gnus-auto-select-subject 'first)
4018     ;; Do nothing.
4019     )
4020    ((functionp gnus-auto-select-subject)
4021     (funcall gnus-auto-select-subject))))
4022
4023 (defun gnus-summary-prepare ()
4024   "Generate the summary buffer."
4025   (interactive)
4026   (let ((inhibit-read-only t))
4027     (erase-buffer)
4028     (setq gnus-newsgroup-data nil
4029           gnus-newsgroup-data-reverse nil)
4030     (gnus-run-hooks 'gnus-summary-generate-hook)
4031     ;; Generate the buffer, either with threads or without.
4032     (when gnus-newsgroup-headers
4033       (gnus-summary-prepare-threads
4034        (if gnus-show-threads
4035            (gnus-sort-gathered-threads
4036             (funcall gnus-summary-thread-gathering-function
4037                      (gnus-sort-threads
4038                       (gnus-cut-threads (gnus-make-threads)))))
4039          ;; Unthreaded display.
4040          (gnus-sort-articles gnus-newsgroup-headers))))
4041     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4042     ;; Call hooks for modifying summary buffer.
4043     (goto-char (point-min))
4044     (gnus-run-hooks 'gnus-summary-prepare-hook)))
4045
4046 (defsubst gnus-general-simplify-subject (subject)
4047   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4048   (setq subject
4049         (cond
4050          ;; Truncate the subject.
4051          (gnus-simplify-subject-functions
4052           (gnus-map-function gnus-simplify-subject-functions subject))
4053          ((numberp gnus-summary-gather-subject-limit)
4054           (setq subject (gnus-simplify-subject-re subject))
4055           (if (> (length subject) gnus-summary-gather-subject-limit)
4056               (substring subject 0 gnus-summary-gather-subject-limit)
4057             subject))
4058          ;; Fuzzily simplify it.
4059          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4060           (gnus-simplify-subject-fuzzy subject))
4061          ;; Just remove the leading "Re:".
4062          (t
4063           (gnus-simplify-subject-re subject))))
4064
4065   (if (and gnus-summary-gather-exclude-subject
4066            (string-match gnus-summary-gather-exclude-subject subject))
4067       nil                         ; This article shouldn't be gathered
4068     subject))
4069
4070 (defun gnus-summary-simplify-subject-query ()
4071   "Query where the respool algorithm would put this article."
4072   (interactive)
4073   (gnus-summary-select-article)
4074   (message "%s" (gnus-general-simplify-subject (gnus-summary-article-subject))))
4075
4076 (defun gnus-gather-threads-by-subject (threads)
4077   "Gather threads by looking at Subject headers."
4078   (if (not gnus-summary-make-false-root)
4079       threads
4080     (let ((hashtb (gnus-make-hashtable 1024))
4081           (prev threads)
4082           (result threads)
4083           subject hthread whole-subject)
4084       (while threads
4085         (setq subject (gnus-general-simplify-subject
4086                        (setq whole-subject (mail-header-subject
4087                                             (caar threads)))))
4088         (when subject
4089           (if (setq hthread (gnus-gethash subject hashtb))
4090               (progn
4091                 ;; We enter a dummy root into the thread, if we
4092                 ;; haven't done that already.
4093                 (unless (stringp (caar hthread))
4094                   (setcar hthread (list whole-subject (car hthread))))
4095                 ;; We add this new gathered thread to this gathered
4096                 ;; thread.
4097                 (setcdr (car hthread)
4098                         (nconc (cdar hthread) (list (car threads))))
4099                 ;; Remove it from the list of threads.
4100                 (setcdr prev (cdr threads))
4101                 (setq threads prev))
4102             ;; Enter this thread into the hash table.
4103             (gnus-sethash subject
4104                           (if gnus-summary-make-false-root-always
4105                               (progn
4106                                 ;; If you want a dummy root above all
4107                                 ;; threads...
4108                                 (setcar threads (list whole-subject
4109                                                       (car threads)))
4110                                 threads)
4111                             threads)
4112                           hashtb)))
4113         (setq prev threads)
4114         (setq threads (cdr threads)))
4115       result)))
4116
4117 (defun gnus-gather-threads-by-references (threads)
4118   "Gather threads by looking at References headers."
4119   (let ((idhashtb (gnus-make-hashtable 1024))
4120         (thhashtb (gnus-make-hashtable 1024))
4121         (prev threads)
4122         (result threads)
4123         ids references id gthread gid entered ref)
4124     (while threads
4125       (when (setq references (mail-header-references (caar threads)))
4126         (setq id (mail-header-id (caar threads))
4127               ids (inline (gnus-split-references references))
4128               entered nil)
4129         (while (setq ref (pop ids))
4130           (setq ids (delete ref ids))
4131           (if (not (setq gid (gnus-gethash ref idhashtb)))
4132               (progn
4133                 (gnus-sethash ref id idhashtb)
4134                 (gnus-sethash id threads thhashtb))
4135             (setq gthread (gnus-gethash gid thhashtb))
4136             (unless entered
4137               ;; We enter a dummy root into the thread, if we
4138               ;; haven't done that already.
4139               (unless (stringp (caar gthread))
4140                 (setcar gthread (list (mail-header-subject (caar gthread))
4141                                       (car gthread))))
4142               ;; We add this new gathered thread to this gathered
4143               ;; thread.
4144               (setcdr (car gthread)
4145                       (nconc (cdar gthread) (list (car threads)))))
4146             ;; Add it into the thread hash table.
4147             (gnus-sethash id gthread thhashtb)
4148             (setq entered t)
4149             ;; Remove it from the list of threads.
4150             (setcdr prev (cdr threads))
4151             (setq threads prev))))
4152       (setq prev threads)
4153       (setq threads (cdr threads)))
4154     result))
4155
4156 (defun gnus-sort-gathered-threads (threads)
4157   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4158   (let ((result threads))
4159     (while threads
4160       (when (stringp (caar threads))
4161         (setcdr (car threads)
4162                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4163       (setq threads (cdr threads)))
4164     result))
4165
4166 (defun gnus-thread-loop-p (root thread)
4167   "Say whether ROOT is in THREAD."
4168   (let ((stack (list thread))
4169         (infloop 0)
4170         th)
4171     (while (setq thread (pop stack))
4172       (setq th (cdr thread))
4173       (while (and th
4174                   (not (eq (caar th) root)))
4175         (pop th))
4176       (if th
4177           ;; We have found a loop.
4178           (let (ref-dep)
4179             (setcdr thread (delq (car th) (cdr thread)))
4180             (if (boundp (setq ref-dep (intern "none"
4181                                               gnus-newsgroup-dependencies)))
4182                 (setcdr (symbol-value ref-dep)
4183                         (nconc (cdr (symbol-value ref-dep))
4184                                (list (car th))))
4185               (set ref-dep (list nil (car th))))
4186             (setq infloop 1
4187                   stack nil))
4188         ;; Push all the subthreads onto the stack.
4189         (push (cdr thread) stack)))
4190     infloop))
4191
4192 (defun gnus-make-threads ()
4193   "Go through the dependency hashtb and find the roots.  Return all threads."
4194   (let (threads)
4195     (while (catch 'infloop
4196              (mapatoms
4197               (lambda (refs)
4198                 ;; Deal with self-referencing References loops.
4199                 (when (and (car (symbol-value refs))
4200                            (not (zerop
4201                                  (apply
4202                                   '+
4203                                   (mapcar
4204                                    (lambda (thread)
4205                                      (gnus-thread-loop-p
4206                                       (car (symbol-value refs)) thread))
4207                                    (cdr (symbol-value refs)))))))
4208                   (setq threads nil)
4209                   (throw 'infloop t))
4210                 (unless (car (symbol-value refs))
4211                   ;; These threads do not refer back to any other
4212                   ;; articles, so they're roots.
4213                   (setq threads (append (cdr (symbol-value refs)) threads))))
4214               gnus-newsgroup-dependencies)))
4215     threads))
4216
4217 ;; Build the thread tree.
4218 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4219   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4220
4221 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4222 if it was already present.
4223
4224 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4225 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4226 Message-IDs will be renamed to a unique Message-ID before being
4227 entered.
4228
4229 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4230   (let* ((id (mail-header-id header))
4231          (id-dep (and id (intern id dependencies)))
4232          parent-id ref ref-dep ref-header replaced)
4233     ;; Enter this `header' in the `dependencies' table.
4234     (cond
4235      ((not id-dep)
4236       (setq header nil))
4237      ;; The first two cases do the normal part: enter a new `header'
4238      ;; in the `dependencies' table.
4239      ((not (boundp id-dep))
4240       (set id-dep (list header)))
4241      ((null (car (symbol-value id-dep)))
4242       (setcar (symbol-value id-dep) header))
4243
4244      ;; From here the `header' was already present in the
4245      ;; `dependencies' table.
4246      (force-new
4247       ;; Overrides an existing entry;
4248       ;; just set the header part of the entry.
4249       (setcar (symbol-value id-dep) header)
4250       (setq replaced t))
4251
4252      ;; Renames the existing `header' to a unique Message-ID.
4253      ((not gnus-summary-ignore-duplicates)
4254       ;; An article with this Message-ID has already been seen.
4255       ;; We rename the Message-ID.
4256       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4257            (list header))
4258       (mail-header-set-id header id))
4259
4260      ;; The last case ignores an existing entry, except it adds any
4261      ;; additional Xrefs (in case the two articles came from different
4262      ;; servers.
4263      ;; Also sets `header' to `nil' meaning that the `dependencies'
4264      ;; table was *not* modified.
4265      (t
4266       (mail-header-set-xref
4267        (car (symbol-value id-dep))
4268        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4269                    "")
4270                (or (mail-header-xref header) "")))
4271       (setq header nil)))
4272
4273     (when (and header (not replaced))
4274       ;; First check that we are not creating a References loop.
4275       (setq parent-id (gnus-parent-id (mail-header-references header)))
4276       (setq ref parent-id)
4277       (while (and ref
4278                   (setq ref-dep (intern-soft ref dependencies))
4279                   (boundp ref-dep)
4280                   (setq ref-header (car (symbol-value ref-dep))))
4281         (if (string= id ref)
4282             ;; Yuk!  This is a reference loop.  Make the article be a
4283             ;; root article.
4284             (progn
4285               (mail-header-set-references (car (symbol-value id-dep)) "none")
4286               (setq ref nil)
4287               (setq parent-id nil))
4288           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4289       (setq ref-dep (intern (or parent-id "none") dependencies))
4290       (if (boundp ref-dep)
4291           (setcdr (symbol-value ref-dep)
4292                   (nconc (cdr (symbol-value ref-dep))
4293                          (list (symbol-value id-dep))))
4294         (set ref-dep (list nil (symbol-value id-dep)))))
4295     header))
4296
4297 (defun gnus-extract-message-id-from-in-reply-to (string)
4298   (if (string-match "<[^>]+>" string)
4299       (substring string (match-beginning 0) (match-end 0))
4300     nil))
4301
4302 (defun gnus-build-sparse-threads ()
4303   (let ((headers gnus-newsgroup-headers)
4304         (mail-parse-charset gnus-newsgroup-charset)
4305         (gnus-summary-ignore-duplicates t)
4306         header references generation relations
4307         subject child end new-child date)
4308     ;; First we create an alist of generations/relations, where
4309     ;; generations is how much we trust the relation, and the relation
4310     ;; is parent/child.
4311     (gnus-message 7 "Making sparse threads...")
4312     (save-excursion
4313       (nnheader-set-temp-buffer " *gnus sparse threads*")
4314       (while (setq header (pop headers))
4315         (when (and (setq references (mail-header-references header))
4316                    (not (string= references "")))
4317           (insert references)
4318           (setq child (mail-header-id header)
4319                 subject (mail-header-subject header)
4320                 date (mail-header-date header)
4321                 generation 0)
4322           (while (search-backward ">" nil t)
4323             (setq end (1+ (point)))
4324             (when (search-backward "<" nil t)
4325               (setq new-child (buffer-substring (point) end))
4326               (push (list (incf generation)
4327                           child (setq child new-child)
4328                           subject date)
4329                     relations)))
4330           (when child
4331             (push (list (1+ generation) child nil subject) relations))
4332           (erase-buffer)))
4333       (kill-buffer (current-buffer)))
4334     ;; Sort over trustworthiness.
4335     (dolist (relation (sort relations 'car-less-than-car))
4336       (when (gnus-dependencies-add-header
4337              (make-full-mail-header
4338               gnus-reffed-article-number
4339               (nth 3 relation) "" (or (nth 4 relation) "")
4340               (nth 1 relation)
4341               (or (nth 2 relation) "") 0 0 "")
4342              gnus-newsgroup-dependencies nil)
4343         (push gnus-reffed-article-number gnus-newsgroup-limit)
4344         (push gnus-reffed-article-number gnus-newsgroup-sparse)
4345         (push (cons gnus-reffed-article-number gnus-sparse-mark)
4346               gnus-newsgroup-reads)
4347         (decf gnus-reffed-article-number)))
4348     (gnus-message 7 "Making sparse threads...done")))
4349
4350 (defun gnus-build-old-threads ()
4351   ;; Look at all the articles that refer back to old articles, and
4352   ;; fetch the headers for the articles that aren't there.  This will
4353   ;; build complete threads - if the roots haven't been expired by the
4354   ;; server, that is.
4355   (let ((mail-parse-charset gnus-newsgroup-charset)
4356         id heads)
4357     (mapatoms
4358      (lambda (refs)
4359        (when (not (car (symbol-value refs)))
4360          (setq heads (cdr (symbol-value refs)))
4361          (while heads
4362            (if (memq (mail-header-number (caar heads))
4363                      gnus-newsgroup-dormant)
4364                (setq heads (cdr heads))
4365              (setq id (symbol-name refs))
4366              (while (and (setq id (gnus-build-get-header id))
4367                          (not (car (gnus-id-to-thread id)))))
4368              (setq heads nil)))))
4369      gnus-newsgroup-dependencies)))
4370
4371 (defsubst gnus-remove-odd-characters (string)
4372   "Translate STRING into something that doesn't contain weird characters."
4373   (mm-subst-char-in-string
4374    ?\r ?\-
4375    (mm-subst-char-in-string ?\n ?\- string t) t))
4376
4377 ;; This function has to be called with point after the article number
4378 ;; on the beginning of the line.
4379 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4380   (let ((eol (point-at-eol))
4381         (buffer (current-buffer))
4382         header references in-reply-to)
4383
4384     ;; overview: [num subject from date id refs chars lines misc]
4385     (unwind-protect
4386         (let (x)
4387           (narrow-to-region (point) eol)
4388           (unless (eobp)
4389             (forward-char))
4390
4391           (setq header
4392                 (make-full-mail-header
4393                  number                 ; number
4394                  (condition-case ()     ; subject
4395                      (gnus-remove-odd-characters
4396                       (funcall gnus-decode-encoded-word-function
4397                                (setq x (nnheader-nov-field))))
4398                    (error x))
4399                  (condition-case ()     ; from
4400                      (gnus-remove-odd-characters
4401                       (funcall gnus-decode-encoded-address-function
4402                                (setq x (nnheader-nov-field))))
4403                    (error x))
4404                  (nnheader-nov-field)   ; date
4405                  (nnheader-nov-read-message-id number)  ; id
4406                  (setq references (nnheader-nov-field)) ; refs
4407                  (nnheader-nov-read-integer) ; chars
4408                  (nnheader-nov-read-integer) ; lines
4409                  (unless (eobp)
4410                    (if (looking-at "Xref: ")
4411                        (goto-char (match-end 0)))
4412                    (nnheader-nov-field)) ; Xref
4413                  (nnheader-nov-parse-extra)))) ; extra
4414
4415       (widen))
4416
4417     (when (and (string= references "")
4418                (setq in-reply-to (mail-header-extra header))
4419                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4420       (mail-header-set-references
4421        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4422
4423     (when gnus-alter-header-function
4424       (funcall gnus-alter-header-function header))
4425     (gnus-dependencies-add-header header dependencies force-new)))
4426
4427 (defun gnus-build-get-header (id)
4428   "Look through the buffer of NOV lines and find the header to ID.
4429 Enter this line into the dependencies hash table, and return
4430 the id of the parent article (if any)."
4431   (let ((deps gnus-newsgroup-dependencies)
4432         found header)
4433     (prog1
4434         (with-current-buffer nntp-server-buffer
4435           (let ((case-fold-search nil))
4436             (goto-char (point-min))
4437             (while (and (not found)
4438                         (search-forward id nil t))
4439               (beginning-of-line)
4440               (setq found (looking-at
4441                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4442                                    (regexp-quote id))))
4443               (or found (beginning-of-line 2)))
4444             (when found
4445               (beginning-of-line)
4446               (and
4447                (setq header (gnus-nov-parse-line
4448                              (read (current-buffer)) deps))
4449                (gnus-parent-id (mail-header-references header))))))
4450       (when header
4451         (let ((number (mail-header-number header)))
4452           (push number gnus-newsgroup-limit)
4453           (push header gnus-newsgroup-headers)
4454           (if (memq number gnus-newsgroup-unselected)
4455               (progn
4456                 (setq gnus-newsgroup-unreads
4457                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4458                                                number))
4459                 (setq gnus-newsgroup-unselected
4460                       (delq number gnus-newsgroup-unselected)))
4461             (push number gnus-newsgroup-ancient)))))))
4462
4463 (defun gnus-build-all-threads ()
4464   "Read all the headers."
4465   (let ((gnus-summary-ignore-duplicates t)
4466         (mail-parse-charset gnus-newsgroup-charset)
4467         (dependencies gnus-newsgroup-dependencies)
4468         header article)
4469     (with-current-buffer nntp-server-buffer
4470       (let ((case-fold-search nil))
4471         (goto-char (point-min))
4472         (while (not (eobp))
4473           (ignore-errors
4474             (setq article (read (current-buffer))
4475                   header (gnus-nov-parse-line article dependencies)))
4476           (when header
4477             (with-current-buffer gnus-summary-buffer
4478               (push header gnus-newsgroup-headers)
4479               (if (memq (setq article (mail-header-number header))
4480                         gnus-newsgroup-unselected)
4481                   (progn
4482                     (setq gnus-newsgroup-unreads
4483                           (gnus-add-to-sorted-list
4484                            gnus-newsgroup-unreads article))
4485                     (setq gnus-newsgroup-unselected
4486                           (delq article gnus-newsgroup-unselected)))
4487                 (push article gnus-newsgroup-ancient)))
4488             (forward-line 1)))))))
4489
4490 (defun gnus-summary-update-article-line (article header)
4491   "Update the line for ARTICLE using HEADER."
4492   (let* ((id (mail-header-id header))
4493          (thread (gnus-id-to-thread id)))
4494     (unless thread
4495       (error "Article in no thread"))
4496     ;; Update the thread.
4497     (setcar thread header)
4498     (gnus-summary-goto-subject article)
4499     (let* ((datal (gnus-data-find-list article))
4500            (data (car datal))
4501            (inhibit-read-only t)
4502            (level (gnus-summary-thread-level)))
4503       (gnus-delete-line)
4504       (let ((inserted (- (point)
4505                          (progn
4506                            (gnus-summary-insert-line
4507                             header level nil
4508                             (memq article gnus-newsgroup-undownloaded)
4509                             (gnus-article-mark article)
4510                             (memq article gnus-newsgroup-replied)
4511                             (memq article gnus-newsgroup-expirable)
4512                             ;; Only insert the Subject string when it's different
4513                             ;; from the previous Subject string.
4514                             (if (and
4515                                  gnus-show-threads
4516                                  (gnus-subject-equal
4517                                   (condition-case ()
4518                                       (mail-header-subject
4519                                        (gnus-data-header
4520                                         (cadr
4521                                          (gnus-data-find-list
4522                                           article
4523                                           (gnus-data-list t)))))
4524                                     ;; Error on the side of excessive subjects.
4525                                     (error ""))
4526                                   (mail-header-subject header)))
4527                                 ""
4528                               (mail-header-subject header))
4529                             nil (cdr (assq article gnus-newsgroup-scored))
4530                             (memq article gnus-newsgroup-processable))
4531                            (point)))))
4532         (when (cdr datal)
4533           (gnus-data-update-list
4534            (cdr datal)
4535            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4536
4537 (defun gnus-summary-update-article (article &optional iheader)
4538   "Update ARTICLE in the summary buffer."
4539   (set-buffer gnus-summary-buffer)
4540   (let* ((header (gnus-summary-article-header article))
4541          (id (mail-header-id header))
4542          (data (gnus-data-find article))
4543          (thread (gnus-id-to-thread id))
4544          (references (mail-header-references header))
4545          (parent
4546           (gnus-id-to-thread
4547            (or (gnus-parent-id
4548                 (when (and references
4549                            (not (equal "" references)))
4550                   references))
4551                "none")))
4552          (inhibit-read-only t)
4553          (old (car thread)))
4554     (when thread
4555       (unless iheader
4556         (setcar thread nil)
4557         (when parent
4558           (delq thread parent)))
4559       (if (gnus-summary-insert-subject id header)
4560           ;; Set the (possibly) new article number in the data structure.
4561           (gnus-data-set-number data (gnus-id-to-article id))
4562         (setcar thread old)
4563         nil))))
4564
4565 (defun gnus-rebuild-thread (id &optional line)
4566   "Rebuild the thread containing ID.
4567 If LINE, insert the rebuilt thread starting on line LINE."
4568   (let ((inhibit-read-only t)
4569         old-pos current thread data)
4570     (if (not gnus-show-threads)
4571         (setq thread (list (car (gnus-id-to-thread id))))
4572       ;; Get the thread this article is part of.
4573       (setq thread (gnus-remove-thread id)))
4574     (setq old-pos (point-at-bol))
4575     (setq current (save-excursion
4576                     (and (re-search-backward "[\r\n]" nil t)
4577                          (gnus-summary-article-number))))
4578     ;; If this is a gathered thread, we have to go some re-gathering.
4579     (when (stringp (car thread))
4580       (let ((subject (car thread))
4581             roots thr)
4582         (setq thread (cdr thread))
4583         (while thread
4584           (unless (memq (setq thr (gnus-id-to-thread
4585                                    (gnus-root-id
4586                                     (mail-header-id (caar thread)))))
4587                         roots)
4588             (push thr roots))
4589           (setq thread (cdr thread)))
4590         ;; We now have all (unique) roots.
4591         (if (= (length roots) 1)
4592             ;; All the loose roots are now one solid root.
4593             (setq thread (car roots))
4594           (setq thread (cons subject (gnus-sort-threads roots))))))
4595     (let (threads)
4596       ;; We then insert this thread into the summary buffer.
4597       (when line
4598         (goto-char (point-min))
4599         (forward-line (1- line)))
4600       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4601         (if gnus-show-threads
4602             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4603           (gnus-summary-prepare-unthreaded thread))
4604         (setq data (nreverse gnus-newsgroup-data))
4605         (setq threads gnus-newsgroup-threads))
4606       ;; We splice the new data into the data structure.
4607       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4608       ;;!!! then we want to insert at the beginning of the buffer.
4609       ;;!!! That happens to be true with Gnus now, but that may
4610       ;;!!! change in the future.  Perhaps.
4611       (gnus-data-enter-list
4612        (if line nil current) data (- (point) old-pos))
4613       (setq gnus-newsgroup-threads
4614             (nconc threads gnus-newsgroup-threads))
4615       (gnus-data-compute-positions))))
4616
4617 (defun gnus-number-to-header (number)
4618   "Return the header for article NUMBER."
4619   (let ((headers gnus-newsgroup-headers))
4620     (while (and headers
4621                 (not (= number (mail-header-number (car headers)))))
4622       (pop headers))
4623     (when headers
4624       (car headers))))
4625
4626 (defun gnus-parent-headers (in-headers &optional generation)
4627   "Return the headers of the GENERATIONeth parent of HEADERS."
4628   (unless generation
4629     (setq generation 1))
4630   (let ((parent t)
4631         (headers in-headers)
4632         references)
4633     (while (and parent
4634                 (not (zerop generation))
4635                 (setq references (mail-header-references headers)))
4636       (setq headers (if (and references
4637                              (setq parent (gnus-parent-id references)))
4638                         (car (gnus-id-to-thread parent))
4639                       nil))
4640       (decf generation))
4641     (and (not (eq headers in-headers))
4642          headers)))
4643
4644 (defun gnus-id-to-thread (id)
4645   "Return the (sub-)thread where ID appears."
4646   (gnus-gethash id gnus-newsgroup-dependencies))
4647
4648 (defun gnus-id-to-article (id)
4649   "Return the article number of ID."
4650   (let ((thread (gnus-id-to-thread id)))
4651     (when (and thread
4652                (car thread))
4653       (mail-header-number (car thread)))))
4654
4655 (defun gnus-id-to-header (id)
4656   "Return the article headers of ID."
4657   (car (gnus-id-to-thread id)))
4658
4659 (defun gnus-article-displayed-root-p (article)
4660   "Say whether ARTICLE is a root(ish) article."
4661   (let ((level (gnus-summary-thread-level article))
4662         (refs (mail-header-references  (gnus-summary-article-header article)))
4663         particle)
4664     (cond
4665      ((null level) nil)
4666      ((zerop level) t)
4667      ((null refs) t)
4668      ((null (gnus-parent-id refs)) t)
4669      ((and (= 1 level)
4670            (null (setq particle (gnus-id-to-article
4671                                  (gnus-parent-id refs))))
4672            (null (gnus-summary-thread-level particle)))))))
4673
4674 (defun gnus-root-id (id)
4675   "Return the id of the root of the thread where ID appears."
4676   (let (last-id prev)
4677     (while (and id (setq prev (car (gnus-id-to-thread id))))
4678       (setq last-id id
4679             id (gnus-parent-id (mail-header-references prev))))
4680     last-id))
4681
4682 (defun gnus-articles-in-thread (thread)
4683   "Return the list of articles in THREAD."
4684   (cons (mail-header-number (car thread))
4685         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4686
4687 (defun gnus-remove-thread (id &optional dont-remove)
4688   "Remove the thread that has ID in it."
4689   (let (headers thread last-id)
4690     ;; First go up in this thread until we find the root.
4691     (setq last-id (gnus-root-id id)
4692           headers (message-flatten-list (gnus-id-to-thread last-id)))
4693     ;; We have now found the real root of this thread.  It might have
4694     ;; been gathered into some loose thread, so we have to search
4695     ;; through the threads to find the thread we wanted.
4696     (let ((threads gnus-newsgroup-threads)
4697           sub)
4698       (while threads
4699         (setq sub (car threads))
4700         (if (stringp (car sub))
4701             ;; This is a gathered thread, so we look at the roots
4702             ;; below it to find whether this article is in this
4703             ;; gathered root.
4704             (progn
4705               (setq sub (cdr sub))
4706               (while sub
4707                 (when (member (caar sub) headers)
4708                   (setq thread (car threads)
4709                         threads nil
4710                         sub nil))
4711                 (setq sub (cdr sub))))
4712           ;; It's an ordinary thread, so we check it.
4713           (when (eq (car sub) (car headers))
4714             (setq thread sub
4715                   threads nil)))
4716         (setq threads (cdr threads)))
4717       ;; If this article is in no thread, then it's a root.
4718       (if thread
4719           (unless dont-remove
4720             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4721         (setq thread (gnus-id-to-thread last-id)))
4722       (when thread
4723         (prog1
4724             thread                      ; We return this thread.
4725           (unless dont-remove
4726             (if (stringp (car thread))
4727                 (progn
4728                   ;; If we use dummy roots, then we have to remove the
4729                   ;; dummy root as well.
4730                   (when (eq gnus-summary-make-false-root 'dummy)
4731                     ;; We go to the dummy root by going to
4732                     ;; the first sub-"thread", and then one line up.
4733                     (gnus-summary-goto-article
4734                      (mail-header-number (caadr thread)))
4735                     (forward-line -1)
4736                     (gnus-delete-line)
4737                     (gnus-data-compute-positions))
4738                   (setq thread (cdr thread))
4739                   (while thread
4740                     (gnus-remove-thread-1 (car thread))
4741                     (setq thread (cdr thread))))
4742               (gnus-remove-thread-1 thread))))))))
4743
4744 (defun gnus-remove-thread-1 (thread)
4745   "Remove the thread THREAD recursively."
4746   (let ((number (mail-header-number (pop thread)))
4747         d)
4748     (setq thread (reverse thread))
4749     (while thread
4750       (gnus-remove-thread-1 (pop thread)))
4751     (when (setq d (gnus-data-find number))
4752       (goto-char (gnus-data-pos d))
4753       (gnus-summary-show-thread)
4754       (gnus-data-remove
4755        number
4756        (- (point-at-bol)
4757           (prog1
4758               (1+ (point-at-eol))
4759             (gnus-delete-line)))))))
4760
4761 (defun gnus-sort-threads-recursive (threads func)
4762   (sort (mapcar (lambda (thread)
4763                   (cons (car thread)
4764                         (and (cdr thread)
4765                              (gnus-sort-threads-recursive (cdr thread) func))))
4766                 threads) func))
4767
4768 (defun gnus-sort-threads-loop (threads func)
4769   (let* ((superthread (cons nil threads))
4770          (stack (list (cons superthread threads)))
4771          remaining-threads thread)
4772     (while stack
4773       (setq remaining-threads (cdr (car stack)))
4774       (if remaining-threads
4775           (progn (setq thread (car remaining-threads))
4776                  (setcdr (car stack) (cdr remaining-threads))
4777                  (if (cdr thread)
4778                      (push (cons thread (cdr thread)) stack)))
4779         (setq thread (caar stack))
4780         (setcdr thread (sort (cdr thread) func))
4781         (pop stack)))
4782     (cdr superthread)))
4783
4784 (defun gnus-sort-threads (threads)
4785   "Sort THREADS."
4786   (if (not gnus-thread-sort-functions)
4787       threads
4788     (gnus-message 8 "Sorting threads...")
4789     (prog1
4790         (condition-case nil
4791             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4792               (gnus-sort-threads-recursive
4793                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4794           ;; Even after binding max-lisp-eval-depth, the recursive
4795           ;; sorter might fail for very long threads.  In that case,
4796           ;; try using a (less well-tested) non-recursive sorter.
4797           (error (gnus-sort-threads-loop
4798                   threads (gnus-make-sort-function
4799                            gnus-thread-sort-functions))))
4800       (gnus-message 8 "Sorting threads...done"))))
4801
4802 (defun gnus-sort-articles (articles)
4803   "Sort ARTICLES."
4804   (when gnus-article-sort-functions
4805     (gnus-message 7 "Sorting articles...")
4806     (prog1
4807         (setq gnus-newsgroup-headers
4808               (sort articles (gnus-make-sort-function
4809                               gnus-article-sort-functions)))
4810       (gnus-message 7 "Sorting articles...done"))))
4811
4812 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4813 (defmacro gnus-thread-header (thread)
4814   "Return header of first article in THREAD.
4815 Note that THREAD must never, ever be anything else than a variable -
4816 using some other form will lead to serious barfage."
4817   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4818   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4819   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4820         (vector thread) 2))
4821
4822 (defsubst gnus-article-sort-by-number (h1 h2)
4823   "Sort articles by article number."
4824   (< (mail-header-number h1)
4825      (mail-header-number h2)))
4826
4827 (defun gnus-thread-sort-by-number (h1 h2)
4828   "Sort threads by root article number."
4829   (gnus-article-sort-by-number
4830    (gnus-thread-header h1) (gnus-thread-header h2)))
4831
4832 (defsubst gnus-article-sort-by-random (h1 h2)
4833   "Sort articles randomly."
4834   (zerop (random 2)))
4835
4836 (defun gnus-thread-sort-by-random (h1 h2)
4837   "Sort threads randomly."
4838   (gnus-article-sort-by-random
4839    (gnus-thread-header h1) (gnus-thread-header h2)))
4840
4841 (defsubst gnus-article-sort-by-lines (h1 h2)
4842   "Sort articles by article Lines header."
4843   (< (mail-header-lines h1)
4844      (mail-header-lines h2)))
4845
4846 (defun gnus-thread-sort-by-lines (h1 h2)
4847   "Sort threads by root article Lines header."
4848   (gnus-article-sort-by-lines
4849    (gnus-thread-header h1) (gnus-thread-header h2)))
4850
4851 (defsubst gnus-article-sort-by-chars (h1 h2)
4852   "Sort articles by octet length."
4853   (< (mail-header-chars h1)
4854      (mail-header-chars h2)))
4855
4856 (defun gnus-thread-sort-by-chars (h1 h2)
4857   "Sort threads by root article octet length."
4858   (gnus-article-sort-by-chars
4859    (gnus-thread-header h1) (gnus-thread-header h2)))
4860
4861 (defsubst gnus-article-sort-by-author (h1 h2)
4862   "Sort articles by root author."
4863   (gnus-string<
4864    (let ((extract (funcall
4865                    gnus-extract-address-components
4866                    (mail-header-from h1))))
4867      (or (car extract) (cadr extract) ""))
4868    (let ((extract (funcall
4869                    gnus-extract-address-components
4870                    (mail-header-from h2))))
4871      (or (car extract) (cadr extract) ""))))
4872
4873 (defun gnus-thread-sort-by-author (h1 h2)
4874   "Sort threads by root author."
4875   (gnus-article-sort-by-author
4876    (gnus-thread-header h1)  (gnus-thread-header h2)))
4877
4878 (defsubst gnus-article-sort-by-recipient (h1 h2)
4879   "Sort articles by recipient."
4880   (gnus-string<
4881    (let ((extract (funcall
4882                    gnus-extract-address-components
4883                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4884      (or (car extract) (cadr extract)))
4885    (let ((extract (funcall
4886                    gnus-extract-address-components
4887                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4888      (or (car extract) (cadr extract)))))
4889
4890 (defun gnus-thread-sort-by-recipient (h1 h2)
4891   "Sort threads by root recipient."
4892   (gnus-article-sort-by-recipient
4893    (gnus-thread-header h1) (gnus-thread-header h2)))
4894
4895 (defsubst gnus-article-sort-by-subject (h1 h2)
4896   "Sort articles by root subject."
4897   (gnus-string<
4898    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4899    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4900
4901 (defun gnus-thread-sort-by-subject (h1 h2)
4902   "Sort threads by root subject."
4903   (gnus-article-sort-by-subject
4904    (gnus-thread-header h1) (gnus-thread-header h2)))
4905
4906 (defsubst gnus-article-sort-by-date (h1 h2)
4907   "Sort articles by root article date."
4908   (time-less-p
4909    (gnus-date-get-time (mail-header-date h1))
4910    (gnus-date-get-time (mail-header-date h2))))
4911
4912 (defun gnus-thread-sort-by-date (h1 h2)
4913   "Sort threads by root article date."
4914   (gnus-article-sort-by-date
4915    (gnus-thread-header h1) (gnus-thread-header h2)))
4916
4917 (defsubst gnus-article-sort-by-score (h1 h2)
4918   "Sort articles by root article score.
4919 Unscored articles will be counted as having a score of zero."
4920   (> (or (cdr (assq (mail-header-number h1)
4921                     gnus-newsgroup-scored))
4922          gnus-summary-default-score 0)
4923      (or (cdr (assq (mail-header-number h2)
4924                     gnus-newsgroup-scored))
4925          gnus-summary-default-score 0)))
4926
4927 (defun gnus-thread-sort-by-score (h1 h2)
4928   "Sort threads by root article score."
4929   (gnus-article-sort-by-score
4930    (gnus-thread-header h1) (gnus-thread-header h2)))
4931
4932 (defun gnus-thread-sort-by-total-score (h1 h2)
4933   "Sort threads by the sum of all scores in the thread.
4934 Unscored articles will be counted as having a score of zero."
4935   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4936
4937 (defun gnus-thread-total-score (thread)
4938   ;; This function find the total score of THREAD.
4939   (cond
4940    ((null thread)
4941     0)
4942    ((consp thread)
4943     (if (stringp (car thread))
4944         (apply gnus-thread-score-function 0
4945                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4946       (gnus-thread-total-score-1 thread)))
4947    (t
4948     (gnus-thread-total-score-1 (list thread)))))
4949
4950 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4951   "Sort threads such that the thread with the most recently arrived article comes first."
4952   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4953
4954 (defun gnus-thread-highest-number (thread)
4955   "Return the highest article number in THREAD."
4956   (apply 'max (mapcar (lambda (header)
4957                         (mail-header-number header))
4958                       (message-flatten-list thread))))
4959
4960 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4961   "Sort threads such that the thread with the most recently dated article comes first."
4962   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4963
4964 (defun gnus-thread-latest-date (thread)
4965   "Return the highest article date in THREAD."
4966   (let ((previous-time 0))
4967     (apply 'max
4968            (mapcar
4969             (lambda (header)
4970               (setq previous-time
4971                     (condition-case ()
4972                         (time-to-seconds (mail-header-parse-date
4973                                           (mail-header-date header)))
4974                       (error previous-time))))
4975             (sort
4976              (message-flatten-list thread)
4977              (lambda (h1 h2)
4978                (< (mail-header-number h1)
4979                   (mail-header-number h2))))))))
4980
4981 (defun gnus-thread-total-score-1 (root)
4982   ;; This function find the total score of the thread below ROOT.
4983   (setq root (car root))
4984   (apply gnus-thread-score-function
4985          (or (append
4986               (mapcar 'gnus-thread-total-score
4987                       (cdr (gnus-id-to-thread (mail-header-id root))))
4988               (when (> (mail-header-number root) 0)
4989                 (list (or (cdr (assq (mail-header-number root)
4990                                      gnus-newsgroup-scored))
4991                           gnus-summary-default-score 0))))
4992              (list gnus-summary-default-score)
4993              '(0))))
4994
4995 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4996 (defvar gnus-tmp-prev-subject nil)
4997 (defvar gnus-tmp-false-parent nil)
4998 (defvar gnus-tmp-root-expunged nil)
4999 (defvar gnus-tmp-dummy-line nil)
5000
5001 (defun gnus-extra-header (type &optional header)
5002   "Return the extra header of TYPE."
5003   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
5004       ""))
5005
5006 (defvar gnus-tmp-thread-tree-header-string "")
5007
5008 (defcustom gnus-sum-thread-tree-root "> "
5009   "With %B spec, used for the root of a thread.
5010 If nil, use subject instead."
5011   :version "22.1"
5012   :type '(radio (const :format "%v  " nil) string)
5013   :group 'gnus-thread)
5014
5015 (defcustom gnus-sum-thread-tree-false-root "> "
5016   "With %B spec, used for a false root of a thread.
5017 If nil, use subject instead."
5018   :version "22.1"
5019   :type '(radio (const :format "%v  " nil) string)
5020   :group 'gnus-thread)
5021
5022 (defcustom gnus-sum-thread-tree-single-indent ""
5023   "With %B spec, used for a thread with just one message.
5024 If nil, use subject instead."
5025   :version "22.1"
5026   :type '(radio (const :format "%v  " nil) string)
5027   :group 'gnus-thread)
5028
5029 (defcustom gnus-sum-thread-tree-vertical "| "
5030   "With %B spec, used for drawing a vertical line."
5031   :version "22.1"
5032   :type 'string
5033   :group 'gnus-thread)
5034
5035 (defcustom gnus-sum-thread-tree-indent "  "
5036   "With %B spec, used for indenting."
5037   :version "22.1"
5038   :type 'string
5039   :group 'gnus-thread)
5040
5041 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5042   "With %B spec, used for a leaf with brothers."
5043   :version "22.1"
5044   :type 'string
5045   :group 'gnus-thread)
5046
5047 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5048   "With %B spec, used for a leaf without brothers."
5049   :version "22.1"
5050   :type 'string
5051   :group 'gnus-thread)
5052
5053 (defcustom gnus-summary-display-while-building nil
5054   "If non-nil, show and update the summary buffer as it's being built.
5055 If the value is t, update the buffer after every line is inserted.  If
5056 the value is an integer (N), update the display every N lines."
5057   :version "22.1"
5058   :group 'gnus-thread
5059   :type '(choice (const :tag "off" nil)
5060                  number
5061                  (const :tag "frequently" t)))
5062
5063 (defun gnus-summary-prepare-threads (threads)
5064   "Prepare summary buffer from THREADS and indentation LEVEL.
5065 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5066 or a straight list of headers."
5067   (gnus-message 7 "Generating summary...")
5068
5069   (setq gnus-newsgroup-threads threads)
5070   (beginning-of-line)
5071
5072   (let ((gnus-tmp-level 0)
5073         (default-score (or gnus-summary-default-score 0))
5074         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5075         (building-line-count gnus-summary-display-while-building)
5076         (building-count (integerp gnus-summary-display-while-building))
5077         thread number subject stack state gnus-tmp-gathered beg-match
5078         new-roots gnus-tmp-new-adopts thread-end simp-subject
5079         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5080         gnus-tmp-replied gnus-tmp-subject-or-nil
5081         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5082         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5083         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5084         tree-stack)
5085
5086     (setq gnus-tmp-prev-subject nil
5087           gnus-tmp-thread-tree-header-string "")
5088
5089     (if (vectorp (car threads))
5090         ;; If this is a straight (sic) list of headers, then a
5091         ;; threaded summary display isn't required, so we just create
5092         ;; an unthreaded one.
5093         (gnus-summary-prepare-unthreaded threads)
5094
5095       ;; Do the threaded display.
5096
5097       (if gnus-summary-display-while-building
5098           (switch-to-buffer (buffer-name)))
5099       (while (or threads stack gnus-tmp-new-adopts new-roots)
5100
5101         (if (and (= gnus-tmp-level 0)
5102                  (or (not stack)
5103                      (= (caar stack) 0))
5104                  (not gnus-tmp-false-parent)
5105                  (or gnus-tmp-new-adopts new-roots))
5106             (if gnus-tmp-new-adopts
5107                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5108                       thread (list (car gnus-tmp-new-adopts))
5109                       gnus-tmp-header (caar thread)
5110                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5111               (when new-roots
5112                 (setq thread (list (car new-roots))
5113                       gnus-tmp-header (caar thread)
5114                       new-roots (cdr new-roots))))
5115
5116           (if threads
5117               ;; If there are some threads, we do them before the
5118               ;; threads on the stack.
5119               (setq thread threads
5120                     gnus-tmp-header (caar thread))
5121             ;; There were no current threads, so we pop something off
5122             ;; the stack.
5123             (setq state (car stack)
5124                   gnus-tmp-level (car state)
5125                   tree-stack (cadr state)
5126                   thread (caddr state)
5127                   stack (cdr stack)
5128                   gnus-tmp-header (caar thread))))
5129
5130         (setq gnus-tmp-false-parent nil)
5131         (setq gnus-tmp-root-expunged nil)
5132         (setq thread-end nil)
5133
5134         (if (stringp gnus-tmp-header)
5135             ;; The header is a dummy root.
5136             (cond
5137              ((eq gnus-summary-make-false-root 'adopt)
5138               ;; We let the first article adopt the rest.
5139               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5140                                                (cddar thread)))
5141               (setq gnus-tmp-gathered
5142                     (nconc (mapcar
5143                             (lambda (h) (mail-header-number (car h)))
5144                             (cddar thread))
5145                            gnus-tmp-gathered))
5146               (setq thread (cons (list (caar thread)
5147                                        (cadar thread))
5148                                  (cdr thread)))
5149               (setq gnus-tmp-level -1
5150                     gnus-tmp-false-parent t))
5151              ((eq gnus-summary-make-false-root 'empty)
5152               ;; We print adopted articles with empty subject fields.
5153               (setq gnus-tmp-gathered
5154                     (nconc (mapcar
5155                             (lambda (h) (mail-header-number (car h)))
5156                             (cddar thread))
5157                            gnus-tmp-gathered))
5158               (setq gnus-tmp-level -1))
5159              ((eq gnus-summary-make-false-root 'dummy)
5160               ;; We remember that we probably want to output a dummy
5161               ;; root.
5162               (setq gnus-tmp-dummy-line gnus-tmp-header)
5163               (setq gnus-tmp-prev-subject gnus-tmp-header))
5164              (t
5165               ;; We do not make a root for the gathered
5166               ;; sub-threads at all.
5167               (setq gnus-tmp-level -1)))
5168
5169           (setq number (mail-header-number gnus-tmp-header)
5170                 subject (mail-header-subject gnus-tmp-header)
5171                 simp-subject (gnus-simplify-subject-fully subject))
5172
5173           (cond
5174            ;; If the thread has changed subject, we might want to make
5175            ;; this subthread into a root.
5176            ((and (null gnus-thread-ignore-subject)
5177                  (not (zerop gnus-tmp-level))
5178                  gnus-tmp-prev-subject
5179                  (not (string= gnus-tmp-prev-subject simp-subject)))
5180             (setq new-roots (nconc new-roots (list (car thread)))
5181                   thread-end t
5182                   gnus-tmp-header nil))
5183            ;; If the article lies outside the current limit,
5184            ;; then we do not display it.
5185            ((not (memq number gnus-newsgroup-limit))
5186             (setq gnus-tmp-gathered
5187                   (nconc (mapcar
5188                           (lambda (h) (mail-header-number (car h)))
5189                           (cdar thread))
5190                          gnus-tmp-gathered))
5191             (setq gnus-tmp-new-adopts (if (cdar thread)
5192                                           (append gnus-tmp-new-adopts
5193                                                   (cdar thread))
5194                                         gnus-tmp-new-adopts)
5195                   thread-end t
5196                   gnus-tmp-header nil)
5197             (when (zerop gnus-tmp-level)
5198               (setq gnus-tmp-root-expunged t)))
5199            ;; Perhaps this article is to be marked as read?
5200            ((and gnus-summary-mark-below
5201                  (< (or (cdr (assq number gnus-newsgroup-scored))
5202                         default-score)
5203                     gnus-summary-mark-below)
5204                  ;; Don't touch sparse articles.
5205                  (not (gnus-summary-article-sparse-p number))
5206                  (not (gnus-summary-article-ancient-p number)))
5207             (setq gnus-newsgroup-unreads
5208                   (delq number gnus-newsgroup-unreads))
5209             (if gnus-newsgroup-auto-expire
5210                 (setq gnus-newsgroup-expirable
5211                       (gnus-add-to-sorted-list
5212                        gnus-newsgroup-expirable number))
5213               (push (cons number gnus-low-score-mark)
5214                     gnus-newsgroup-reads))))
5215
5216           (when gnus-tmp-header
5217             ;; We may have an old dummy line to output before this
5218             ;; article.
5219             (when (and gnus-tmp-dummy-line
5220                        (gnus-subject-equal
5221                         gnus-tmp-dummy-line
5222                         (mail-header-subject gnus-tmp-header)))
5223               (gnus-summary-insert-dummy-line
5224                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5225               (setq gnus-tmp-dummy-line nil))
5226
5227             ;; Compute the mark.
5228             (setq gnus-tmp-unread (gnus-article-mark number))
5229
5230             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5231                                   gnus-tmp-header gnus-tmp-level)
5232                   gnus-newsgroup-data)
5233
5234             ;; Actually insert the line.
5235             (setq
5236              gnus-tmp-subject-or-nil
5237              (cond
5238               ((and gnus-thread-ignore-subject
5239                     gnus-tmp-prev-subject
5240                     (not (string= gnus-tmp-prev-subject simp-subject)))
5241                subject)
5242               ((zerop gnus-tmp-level)
5243                (if (and (eq gnus-summary-make-false-root 'empty)
5244                         (memq number gnus-tmp-gathered)
5245                         gnus-tmp-prev-subject
5246                         (string= gnus-tmp-prev-subject simp-subject))
5247                    gnus-summary-same-subject
5248                  subject))
5249               (t gnus-summary-same-subject)))
5250             (if (and (eq gnus-summary-make-false-root 'adopt)
5251                      (= gnus-tmp-level 1)
5252                      (memq number gnus-tmp-gathered))
5253                 (setq gnus-tmp-opening-bracket ?\<
5254                       gnus-tmp-closing-bracket ?\>)
5255               (setq gnus-tmp-opening-bracket ?\[
5256                     gnus-tmp-closing-bracket ?\]))
5257             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5258                 (gnus-make-thread-indent-array
5259                  (max (* 2 (length gnus-thread-indent-array))
5260                       gnus-tmp-level)))
5261             (setq
5262              gnus-tmp-indentation
5263              (aref gnus-thread-indent-array gnus-tmp-level)
5264              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5265              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5266                                 gnus-summary-default-score 0)
5267              gnus-tmp-score-char
5268              (if (or (null gnus-summary-default-score)
5269                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5270                          gnus-summary-zcore-fuzz))
5271                  ?                      ;Whitespace
5272                (if (< gnus-tmp-score gnus-summary-default-score)
5273                    gnus-score-below-mark gnus-score-over-mark))
5274              gnus-tmp-replied
5275              (cond ((memq number gnus-newsgroup-processable)
5276                     gnus-process-mark)
5277                    ((memq number gnus-newsgroup-cached)
5278                     gnus-cached-mark)
5279                    ((memq number gnus-newsgroup-replied)
5280                     gnus-replied-mark)
5281                    ((memq number gnus-newsgroup-forwarded)
5282                     gnus-forwarded-mark)
5283                    ((memq number gnus-newsgroup-saved)
5284                     gnus-saved-mark)
5285                    ((memq number gnus-newsgroup-recent)
5286                     gnus-recent-mark)
5287                    ((memq number gnus-newsgroup-unseen)
5288                     gnus-unseen-mark)
5289                    (t gnus-no-mark))
5290              gnus-tmp-downloaded
5291              (cond ((memq number gnus-newsgroup-undownloaded)
5292                     gnus-undownloaded-mark)
5293                    (gnus-newsgroup-agentized
5294                     gnus-downloaded-mark)
5295                    (t
5296                     gnus-no-mark))
5297              gnus-tmp-from (mail-header-from gnus-tmp-header)
5298              gnus-tmp-name
5299              (cond
5300               ((string-match "<[^>]+> *$" gnus-tmp-from)
5301                (setq beg-match (match-beginning 0))
5302                (or (and (string-match "^\".+\"" gnus-tmp-from)
5303                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5304                    (substring gnus-tmp-from 0 beg-match)))
5305               ((string-match "(.+)" gnus-tmp-from)
5306                (substring gnus-tmp-from
5307                           (1+ (match-beginning 0)) (1- (match-end 0))))
5308               (t gnus-tmp-from))
5309
5310              ;; Do the %B string
5311              gnus-tmp-thread-tree-header-string
5312              (cond
5313               ((not gnus-show-threads) "")
5314               ((zerop gnus-tmp-level)
5315                (cond ((cdar thread)
5316                       (or gnus-sum-thread-tree-root subject))
5317                      (gnus-tmp-new-adopts
5318                       (or gnus-sum-thread-tree-false-root subject))
5319                      (t
5320                       (or gnus-sum-thread-tree-single-indent subject))))
5321               (t
5322                (concat (apply 'concat
5323                               (mapcar (lambda (item)
5324                                         (if (= item 1)
5325                                             gnus-sum-thread-tree-vertical
5326                                           gnus-sum-thread-tree-indent))
5327                                       (cdr (reverse tree-stack))))
5328                        (if (nth 1 thread)
5329                            gnus-sum-thread-tree-leaf-with-other
5330                          gnus-sum-thread-tree-single-leaf)))))
5331             (when (string= gnus-tmp-name "")
5332               (setq gnus-tmp-name gnus-tmp-from))
5333             (unless (numberp gnus-tmp-lines)
5334               (setq gnus-tmp-lines -1))
5335             (if (= gnus-tmp-lines -1)
5336                 (setq gnus-tmp-lines "?")
5337               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5338               (gnus-put-text-property
5339              (point)
5340              (progn (eval gnus-summary-line-format-spec) (point))
5341                'gnus-number number)
5342             (when gnus-visual-p
5343               (forward-line -1)
5344               (gnus-run-hooks 'gnus-summary-update-hook)
5345               (forward-line 1))
5346
5347             (setq gnus-tmp-prev-subject simp-subject)))
5348
5349         (when (nth 1 thread)
5350           (push (list (max 0 gnus-tmp-level)
5351                       (copy-sequence tree-stack)
5352                       (nthcdr 1 thread))
5353                 stack))
5354         (push (if (nth 1 thread) 1 0) tree-stack)
5355         (incf gnus-tmp-level)
5356         (setq threads (if thread-end nil (cdar thread)))
5357         (if gnus-summary-display-while-building
5358             (if building-count
5359                 (progn
5360                   ;; use a set frequency
5361                   (setq building-line-count (1- building-line-count))
5362                   (when (= building-line-count 0)
5363                     (sit-for 0)
5364                     (setq building-line-count
5365                           gnus-summary-display-while-building)))
5366               ;; always
5367               (sit-for 0)))
5368         (unless threads
5369           (setq gnus-tmp-level 0)))))
5370   (gnus-message 7 "Generating summary...done"))
5371
5372 (defun gnus-summary-prepare-unthreaded (headers)
5373   "Generate an unthreaded summary buffer based on HEADERS."
5374   (let (header number mark)
5375
5376     (beginning-of-line)
5377
5378     (while headers
5379       ;; We may have to root out some bad articles...
5380       (when (memq (setq number (mail-header-number
5381                                 (setq header (pop headers))))
5382                   gnus-newsgroup-limit)
5383         ;; Mark article as read when it has a low score.
5384         (when (and gnus-summary-mark-below
5385                    (< (or (cdr (assq number gnus-newsgroup-scored))
5386                           gnus-summary-default-score 0)
5387                       gnus-summary-mark-below)
5388                    (not (gnus-summary-article-ancient-p number)))
5389           (setq gnus-newsgroup-unreads
5390                 (delq number gnus-newsgroup-unreads))
5391           (if gnus-newsgroup-auto-expire
5392               (push number gnus-newsgroup-expirable)
5393             (push (cons number gnus-low-score-mark)
5394                   gnus-newsgroup-reads)))
5395
5396         (setq mark (gnus-article-mark number))
5397         (push (gnus-data-make number mark (1+ (point)) header 0)
5398               gnus-newsgroup-data)
5399         (gnus-summary-insert-line
5400          header 0 number
5401          (memq number gnus-newsgroup-undownloaded)
5402          mark (memq number gnus-newsgroup-replied)
5403          (memq number gnus-newsgroup-expirable)
5404          (mail-header-subject header) nil
5405          (cdr (assq number gnus-newsgroup-scored))
5406          (memq number gnus-newsgroup-processable))))))
5407
5408 (defun gnus-summary-remove-list-identifiers ()
5409   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5410   (let ((regexp (if (consp gnus-list-identifiers)
5411                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5412                   gnus-list-identifiers))
5413         changed subject)
5414     (when regexp
5415       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5416       (dolist (header gnus-newsgroup-headers)
5417         (setq subject (mail-header-subject header)
5418               changed nil)
5419         (while (string-match regexp subject)
5420           (setq subject
5421                 (concat (substring subject 0 (match-beginning 1))
5422                         (substring subject (match-end 0)))
5423                 changed t))
5424         (when changed
5425           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5426             (setq subject
5427                   (concat (substring subject 0 (match-beginning 1))
5428                           (substring subject (match-end 1)))))
5429           (mail-header-set-subject header subject))))))
5430
5431 (defun gnus-fetch-headers (articles)
5432   "Fetch headers of ARTICLES."
5433   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5434     (gnus-message 5 "Fetching headers for %s..." name)
5435     (prog1
5436         (if (eq 'nov
5437                 (setq gnus-headers-retrieved-by
5438                       (gnus-retrieve-headers
5439                        articles gnus-newsgroup-name
5440                        ;; We might want to fetch old headers, but
5441                        ;; not if there is only 1 article.
5442                        (and (or (and
5443                                  (not (eq gnus-fetch-old-headers 'some))
5444                                  (not (numberp gnus-fetch-old-headers)))
5445                                 (> (length articles) 1))
5446                             gnus-fetch-old-headers))))
5447             (gnus-get-newsgroup-headers-xover
5448              articles nil nil gnus-newsgroup-name t)
5449           (gnus-get-newsgroup-headers))
5450       (gnus-message 5 "Fetching headers for %s...done" name))))
5451
5452 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5453   "Select newsgroup GROUP.
5454 If READ-ALL is non-nil, all articles in the group are selected.
5455 If SELECT-ARTICLES, only select those articles from GROUP."
5456   (let* ((entry (gnus-group-entry group))
5457          ;;!!! Dirty hack; should be removed.
5458          (gnus-summary-ignore-duplicates
5459           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5460               t
5461             gnus-summary-ignore-duplicates))
5462          (info (nth 2 entry))
5463          charset articles fetched-articles cached)
5464
5465     (unless (gnus-check-server
5466              (set (make-local-variable 'gnus-current-select-method)
5467                   (gnus-find-method-for-group group)))
5468       (error "Couldn't open server"))
5469     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5470
5471     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5472         (gnus-activate-group group)     ; Or we can activate it...
5473         (progn                          ; Or we bug out.
5474           (when (equal major-mode 'gnus-summary-mode)
5475             (gnus-kill-buffer (current-buffer)))
5476           (error
5477            "Couldn't activate group %s: %s"
5478            (mm-decode-coding-string group charset)
5479            (mm-decode-coding-string (gnus-status-message group) charset))))
5480
5481     (unless (gnus-request-group group t)
5482         (when (equal major-mode 'gnus-summary-mode)
5483           (gnus-kill-buffer (current-buffer)))
5484         (error "Couldn't request group %s: %s"
5485                (mm-decode-coding-string group charset)
5486                (mm-decode-coding-string (gnus-status-message group) charset)))
5487
5488     (when gnus-agent
5489       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5490
5491       (setq gnus-summary-use-undownloaded-faces
5492             (gnus-agent-find-parameter
5493              group
5494              'agent-enable-undownloaded-faces)))
5495
5496     (setq gnus-newsgroup-name group
5497           gnus-newsgroup-unselected nil
5498           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5499
5500     (let ((display (gnus-group-find-parameter group 'display)))
5501       (setq gnus-newsgroup-display
5502             (cond
5503              ((not (zerop (or (car-safe read-all) 0)))
5504               ;; The user entered the group with C-u SPC/RET, let's show
5505               ;; all articles.
5506               'gnus-not-ignore)
5507              ((eq display 'all)
5508               'gnus-not-ignore)
5509              ((arrayp display)
5510               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5511              ((numberp display)
5512               ;; The following is probably the "correct" solution, but
5513               ;; it makes Gnus fetch all headers and then limit the
5514               ;; articles (which is slow), so instead we hack the
5515               ;; select-articles parameter instead. -- Simon Josefsson
5516               ;; <jas@kth.se>
5517               ;;
5518               ;; (gnus-byte-compile
5519               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5520               ;;                         display)))))
5521               (setq select-articles
5522                     (gnus-uncompress-range
5523                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5524                              (if (> tmp 0)
5525                                  tmp
5526                                1))
5527                            (cdr (gnus-active group)))))
5528               nil)
5529              (t
5530               nil))))
5531
5532     (gnus-summary-setup-default-charset)
5533
5534     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5535     (when (gnus-virtual-group-p group)
5536       (setq cached gnus-newsgroup-cached))
5537
5538     (setq gnus-newsgroup-unreads
5539           (gnus-sorted-ndifference
5540            (gnus-sorted-ndifference gnus-newsgroup-unreads
5541                                     gnus-newsgroup-marked)
5542            gnus-newsgroup-dormant))
5543
5544     (setq gnus-newsgroup-processable nil)
5545
5546     (gnus-update-read-articles group gnus-newsgroup-unreads)
5547
5548     ;; Adjust and set lists of article marks.
5549     (when info
5550       (gnus-adjust-marked-articles info))
5551     (if (setq articles select-articles)
5552         (setq gnus-newsgroup-unselected
5553               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5554       (setq articles (gnus-articles-to-read group read-all)))
5555
5556     (cond
5557      ((null articles)
5558       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5559       'quit)
5560      ((eq articles 0) nil)
5561      (t
5562       ;; Init the dependencies hash table.
5563       (setq gnus-newsgroup-dependencies
5564             (gnus-make-hashtable (length articles)))
5565       (gnus-set-global-variables)
5566       ;; Retrieve the headers and read them in.
5567
5568       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5569
5570       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5571       (when cached
5572         (setq gnus-newsgroup-cached cached))
5573
5574       ;; Suppress duplicates?
5575       (when gnus-suppress-duplicates
5576         (gnus-dup-suppress-articles))
5577
5578       ;; Set the initial limit.
5579       (setq gnus-newsgroup-limit (copy-sequence articles))
5580       ;; Remove canceled articles from the list of unread articles.
5581       (setq fetched-articles
5582             (mapcar (lambda (headers) (mail-header-number headers))
5583                     gnus-newsgroup-headers))
5584       (setq gnus-newsgroup-articles fetched-articles)
5585       (setq gnus-newsgroup-unreads
5586             (gnus-sorted-nintersection
5587              gnus-newsgroup-unreads fetched-articles))
5588       (gnus-compute-unseen-list)
5589
5590       ;; Removed marked articles that do not exist.
5591       (gnus-update-missing-marks
5592        (gnus-sorted-difference articles fetched-articles))
5593       ;; We might want to build some more threads first.
5594       (when (and gnus-fetch-old-headers
5595                  (eq gnus-headers-retrieved-by 'nov))
5596         (if (eq gnus-fetch-old-headers 'invisible)
5597             (gnus-build-all-threads)
5598           (gnus-build-old-threads)))
5599       ;; Let the Gnus agent mark articles as read.
5600       (when gnus-agent
5601         (gnus-agent-get-undownloaded-list))
5602       ;; Remove list identifiers from subject
5603       (when gnus-list-identifiers
5604         (gnus-summary-remove-list-identifiers))
5605       ;; Check whether auto-expire is to be done in this group.
5606       (setq gnus-newsgroup-auto-expire
5607             (gnus-group-auto-expirable-p group))
5608       ;; Set up the article buffer now, if necessary.
5609       (unless (and gnus-single-article-buffer
5610                    (equal gnus-article-buffer "*Article*"))
5611         (gnus-article-setup-buffer))
5612       ;; First and last article in this newsgroup.
5613       (when gnus-newsgroup-headers
5614         (setq gnus-newsgroup-begin
5615               (mail-header-number (car gnus-newsgroup-headers))
5616               gnus-newsgroup-end
5617               (mail-header-number
5618                (gnus-last-element gnus-newsgroup-headers))))
5619       ;; GROUP is successfully selected.
5620       (or gnus-newsgroup-headers t)))))
5621
5622 (defun gnus-compute-unseen-list ()
5623   ;; The `seen' marks are treated specially.
5624   (if (not gnus-newsgroup-seen)
5625       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5626     (setq gnus-newsgroup-unseen
5627           (gnus-inverse-list-range-intersection
5628            gnus-newsgroup-articles gnus-newsgroup-seen))))
5629
5630 (declare-function gnus-get-predicate "gnus-agent" (predicate))
5631
5632 (defun gnus-summary-display-make-predicate (display)
5633   (require 'gnus-agent)
5634   (when (= (length display) 1)
5635     (setq display (car display)))
5636   (unless gnus-summary-display-cache
5637     (dolist (elem (append '((unread . unread)
5638                             (read . read)
5639                             (unseen . unseen))
5640                           gnus-article-mark-lists))
5641       (push (cons (cdr elem)
5642                   (gnus-byte-compile
5643                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5644             gnus-summary-display-cache)))
5645   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5646         (gnus-category-predicate-cache gnus-summary-display-cache))
5647     (gnus-get-predicate display)))
5648
5649 ;; Uses the dynamically bound `number' variable.
5650 (defvar number)
5651 (defun gnus-article-marked-p (type &optional article)
5652   (let ((article (or article number)))
5653     (cond
5654      ((eq type 'tick)
5655       (memq article gnus-newsgroup-marked))
5656      ((eq type 'spam)
5657       (memq article gnus-newsgroup-spam-marked))
5658      ((eq type 'unsend)
5659       (memq article gnus-newsgroup-unsendable))
5660      ((eq type 'undownload)
5661       (memq article gnus-newsgroup-undownloaded))
5662      ((eq type 'download)
5663       (memq article gnus-newsgroup-downloadable))
5664      ((eq type 'unread)
5665       (memq article gnus-newsgroup-unreads))
5666      ((eq type 'read)
5667       (memq article gnus-newsgroup-reads))
5668      ((eq type 'dormant)
5669       (memq article gnus-newsgroup-dormant) )
5670      ((eq type 'expire)
5671       (memq article gnus-newsgroup-expirable))
5672      ((eq type 'reply)
5673       (memq article gnus-newsgroup-replied))
5674      ((eq type 'killed)
5675       (memq article gnus-newsgroup-killed))
5676      ((eq type 'bookmark)
5677       (assq article gnus-newsgroup-bookmarks))
5678      ((eq type 'score)
5679       (assq article gnus-newsgroup-scored))
5680      ((eq type 'save)
5681       (memq article gnus-newsgroup-saved))
5682      ((eq type 'cache)
5683       (memq article gnus-newsgroup-cached))
5684      ((eq type 'forward)
5685       (memq article gnus-newsgroup-forwarded))
5686      ((eq type 'seen)
5687       (not (memq article gnus-newsgroup-unseen)))
5688      ((eq type 'recent)
5689       (memq article gnus-newsgroup-recent))
5690      (t t))))
5691
5692 (defun gnus-articles-to-read (group &optional read-all)
5693   "Find out what articles the user wants to read."
5694   (let* ((articles
5695           ;; Select all articles if `read-all' is non-nil, or if there
5696           ;; are no unread articles.
5697           (if (or read-all
5698                   (and (zerop (length gnus-newsgroup-marked))
5699                        (zerop (length gnus-newsgroup-unreads)))
5700                   ;; Fetch all if the predicate is non-nil.
5701                   gnus-newsgroup-display)
5702               ;; We want to select the headers for all the articles in
5703               ;; the group, so we select either all the active
5704               ;; articles in the group, or (if that's nil), the
5705               ;; articles in the cache.
5706               (or
5707                (if gnus-newsgroup-maximum-articles
5708                    (let ((active (gnus-active group)))
5709                      (gnus-uncompress-range
5710                       (cons (max (car active)
5711                                  (- (cdr active)
5712                                     gnus-newsgroup-maximum-articles
5713                                     -1))
5714                             (cdr active))))
5715                  (gnus-uncompress-range (gnus-active group)))
5716                (gnus-cache-articles-in-group group))
5717             ;; Select only the "normal" subset of articles.
5718             (gnus-sorted-nunion
5719              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5720              gnus-newsgroup-unreads)))
5721          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5722          (scored (length scored-list))
5723          (number (length articles))
5724          (marked (+ (length gnus-newsgroup-marked)
5725                     (length gnus-newsgroup-dormant)))
5726          (select
5727           (cond
5728            ((numberp read-all)
5729             read-all)
5730            ((numberp gnus-newsgroup-display)
5731             gnus-newsgroup-display)
5732            (t
5733             (condition-case ()
5734                 (cond
5735                  ((and (or (<= scored marked) (= scored number))
5736                        (numberp gnus-large-newsgroup)
5737                        (> number gnus-large-newsgroup))
5738                   (let* ((cursor-in-echo-area nil)
5739                          (initial (gnus-parameter-large-newsgroup-initial
5740                                    gnus-newsgroup-name))
5741                          (input
5742                           (read-string
5743                            (format
5744                             "How many articles from %s (%s %d): "
5745                             (gnus-group-decoded-name gnus-newsgroup-name)
5746                             (if initial "max" "default")
5747                             number)
5748                            (if initial
5749                                (cons (number-to-string initial)
5750                                      0)))))
5751                     (if (string-match "^[ \t]*$" input) number input)))
5752                  ((and (> scored marked) (< scored number)
5753                        (> (- scored number) 20))
5754                   (let ((input
5755                          (read-string
5756                           (format "%s %s (%d scored, %d total): "
5757                                   "How many articles from"
5758                                   (gnus-group-decoded-name group)
5759                                   scored number))))
5760                     (if (string-match "^[ \t]*$" input)
5761                         number input)))
5762                  (t number))
5763               (quit
5764                (message "Quit getting the articles to read")
5765                nil))))))
5766     (setq select (if (stringp select) (string-to-number select) select))
5767     (if (or (null select) (zerop select))
5768         select
5769       (if (and (not (zerop scored)) (<= (abs select) scored))
5770           (progn
5771             (setq articles (sort scored-list '<))
5772             (setq number (length articles)))
5773         (setq articles (copy-sequence articles)))
5774
5775       (when (< (abs select) number)
5776         (if (< select 0)
5777             ;; Select the N oldest articles.
5778             (setcdr (nthcdr (1- (abs select)) articles) nil)
5779           ;; Select the N most recent articles.
5780           (setq articles (nthcdr (- number select) articles))))
5781       (setq gnus-newsgroup-unselected
5782             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5783       (when gnus-alter-articles-to-read-function
5784         (setq articles
5785               (sort
5786                (funcall gnus-alter-articles-to-read-function
5787                         gnus-newsgroup-name articles)
5788                '<)))
5789       articles)))
5790
5791 (defun gnus-killed-articles (killed articles)
5792   (let (out)
5793     (while articles
5794       (when (inline (gnus-member-of-range (car articles) killed))
5795         (push (car articles) out))
5796       (setq articles (cdr articles)))
5797     out))
5798
5799 (defun gnus-uncompress-marks (marks)
5800   "Uncompress the mark ranges in MARKS."
5801   (let ((uncompressed '(score bookmark))
5802         out)
5803     (while marks
5804       (if (memq (caar marks) uncompressed)
5805           (push (car marks) out)
5806         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5807       (setq marks (cdr marks)))
5808     out))
5809
5810 (defun gnus-article-mark-to-type (mark)
5811   "Return the type of MARK."
5812   (or (cadr (assq mark gnus-article-special-mark-lists))
5813       'list))
5814
5815 (defun gnus-article-unpropagatable-p (mark)
5816   "Return whether MARK should be propagated to back end."
5817   (memq mark gnus-article-unpropagated-mark-lists))
5818
5819 (defun gnus-adjust-marked-articles (info)
5820   "Set all article lists and remove all marks that are no longer valid."
5821   (let* ((marked-lists (gnus-info-marks info))
5822          (active (gnus-active (gnus-info-group info)))
5823          (min (car active))
5824          (max (cdr active))
5825          (types gnus-article-mark-lists)
5826          marks var articles article mark mark-type
5827          bgn end)
5828
5829     (dolist (marks marked-lists)
5830       (setq mark (car marks)
5831             mark-type (gnus-article-mark-to-type mark)
5832             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5833
5834       ;; We set the variable according to the type of the marks list,
5835       ;; and then adjust the marks to a subset of the active articles.
5836       (cond
5837        ;; Adjust "simple" lists - compressed yet unsorted
5838        ((eq mark-type 'list)
5839         ;; Simultaneously uncompress and clip to active range
5840         ;; See gnus-uncompress-range for a description of possible marks
5841         (let (l lh)
5842           (if (not (cadr marks))
5843               (set var nil)
5844             (setq articles (if (numberp (cddr marks))
5845                                (list (cdr marks))
5846                              (cdr marks))
5847                   lh (cons nil nil)
5848                   l lh)
5849
5850             (while (setq article (pop articles))
5851               (cond ((consp article)
5852                      (setq bgn (max (car article) min)
5853                            end (min (cdr article) max))
5854                      (while (<= bgn end)
5855                        (setq l (setcdr l (cons bgn nil))
5856                              bgn (1+ bgn))))
5857                     ((and (<= min article)
5858                           (>= max article))
5859                      (setq l (setcdr l (cons article nil))))))
5860             (set var (cdr lh)))))
5861        ;; Adjust assocs.
5862        ((eq mark-type 'tuple)
5863         (set var (setq articles (cdr marks)))
5864         (when (not (listp (cdr (symbol-value var))))
5865           (set var (list (symbol-value var))))
5866         (when (not (listp (cdr articles)))
5867           (setq articles (list articles)))
5868         (while articles
5869           (when (or (not (consp (setq article (pop articles))))
5870                     (< (car article) min)
5871                     (> (car article) max))
5872             (set var (delq article (symbol-value var))))))
5873        ;; Adjust ranges (sloppily).
5874        ((eq mark-type 'range)
5875         (cond
5876          ((eq mark 'seen)
5877           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5878           ;; It should be (seen (NUM1 . NUM2)).
5879           (when (numberp (cddr marks))
5880             (setcdr marks (list (cdr marks))))
5881           (setq articles (cdr marks))
5882           (while (and articles
5883                       (or (and (consp (car articles))
5884                                (> min (cdar articles)))
5885                           (and (numberp (car articles))
5886                                (> min (car articles)))))
5887             (pop articles))
5888           (set var articles))))))))
5889
5890 (defun gnus-update-missing-marks (missing)
5891   "Go through the list of MISSING articles and remove them from the mark lists."
5892   (when missing
5893     (let (var m)
5894       ;; Go through all types.
5895       (dolist (elem gnus-article-mark-lists)
5896         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5897           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5898           (when (symbol-value var)
5899             ;; This list has articles.  So we delete all missing
5900             ;; articles from it.
5901             (setq m missing)
5902             (while m
5903               (set var (delq (pop m) (symbol-value var))))))))))
5904
5905 (defun gnus-update-marks ()
5906   "Enter the various lists of marked articles into the newsgroup info list."
5907   (let ((types gnus-article-mark-lists)
5908         (info (gnus-get-info gnus-newsgroup-name))
5909         type list newmarked symbol delta-marks)
5910     (when info
5911       ;; Add all marks lists to the list of marks lists.
5912       (while (setq type (pop types))
5913         (setq list (symbol-value
5914                     (setq symbol
5915                           (intern (format "gnus-newsgroup-%s" (car type))))))
5916
5917         (when list
5918           ;; Get rid of the entries of the articles that have the
5919           ;; default score.
5920           (when (and (eq (cdr type) 'score)
5921                      gnus-save-score
5922                      list)
5923             (let* ((arts list)
5924                    (prev (cons nil list))
5925                    (all prev))
5926               (while arts
5927                 (if (or (not (consp (car arts)))
5928                         (= (cdar arts) gnus-summary-default-score))
5929                     (setcdr prev (cdr arts))
5930                   (setq prev arts))
5931                 (setq arts (cdr arts)))
5932               (setq list (cdr all)))))
5933
5934         (when (eq (cdr type) 'seen)
5935           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5936
5937         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5938           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5939
5940         (when (and (gnus-check-backend-function
5941                     'request-set-mark gnus-newsgroup-name)
5942                    (not (gnus-article-unpropagatable-p (cdr type))))
5943           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5944                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5945                  (add (gnus-remove-from-range
5946                        (gnus-copy-sequence list) old)))
5947             (when add
5948               (push (list add 'add (list (cdr type))) delta-marks))
5949             (when del
5950               (push (list del 'del (list (cdr type))) delta-marks))))
5951
5952         (when list
5953           (push (cons (cdr type) list) newmarked)))
5954
5955       (when delta-marks
5956         (unless (gnus-check-group gnus-newsgroup-name)
5957           (error "Can't open server for %s" gnus-newsgroup-name))
5958         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5959
5960       ;; Enter these new marks into the info of the group.
5961       (if (nthcdr 3 info)
5962           (setcar (nthcdr 3 info) newmarked)
5963         ;; Add the marks lists to the end of the info.
5964         (when newmarked
5965           (setcdr (nthcdr 2 info) (list newmarked))))
5966
5967       ;; Cut off the end of the info if there's nothing else there.
5968       (let ((i 5))
5969         (while (and (> i 2)
5970                     (not (nth i info)))
5971           (when (nthcdr (decf i) info)
5972             (setcdr (nthcdr i info) nil)))))))
5973
5974 (defun gnus-set-mode-line (where)
5975   "Set the mode line of the article or summary buffers.
5976 If WHERE is `summary', the summary mode line format will be used."
5977   ;; Is this mode line one we keep updated?
5978   (when (and (memq where gnus-updated-mode-lines)
5979              (symbol-value
5980               (intern (format "gnus-%s-mode-line-format-spec" where))))
5981     (let (mode-string)
5982       ;; We evaluate this in the summary buffer since these
5983       ;; variables are buffer-local to that buffer.
5984       (with-current-buffer gnus-summary-buffer
5985         ;; We bind all these variables that are used in the `eval' form
5986         ;; below.
5987         (let* ((mformat (symbol-value
5988                          (intern
5989                           (format "gnus-%s-mode-line-format-spec" where))))
5990                (gnus-tmp-group-name (gnus-mode-string-quote
5991                                      (gnus-group-decoded-name
5992                                       gnus-newsgroup-name)))
5993                (gnus-tmp-article-number (or gnus-current-article 0))
5994                (gnus-tmp-unread gnus-newsgroup-unreads)
5995                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5996                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5997                (gnus-tmp-unread-and-unselected
5998                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5999                             (zerop gnus-tmp-unselected))
6000                        "")
6001                       ((zerop gnus-tmp-unselected)
6002                        (format "{%d more}" gnus-tmp-unread-and-unticked))
6003                       (t (format "{%d(+%d) more}"
6004                                  gnus-tmp-unread-and-unticked
6005                                  gnus-tmp-unselected))))
6006                (gnus-tmp-subject
6007                 (if (and gnus-current-headers
6008                          (vectorp gnus-current-headers))
6009                     (gnus-mode-string-quote
6010                      (mail-header-subject gnus-current-headers))
6011                   ""))
6012                bufname-length max-len
6013                gnus-tmp-header) ;; passed as argument to any user-format-funcs
6014           (setq mode-string (eval mformat))
6015           (setq bufname-length (if (string-match "%b" mode-string)
6016                                    (- (length
6017                                        (buffer-name
6018                                         (if (eq where 'summary)
6019                                             nil
6020                                           (get-buffer gnus-article-buffer))))
6021                                       2)
6022                                  0))
6023           (setq max-len (max 4 (if gnus-mode-non-string-length
6024                                    (- (window-width)
6025                                       gnus-mode-non-string-length
6026                                       bufname-length)
6027                                  (length mode-string))))
6028           ;; We might have to chop a bit of the string off...
6029           (when (> (length mode-string) max-len)
6030             (setq mode-string
6031                   (concat (truncate-string-to-width mode-string (- max-len 3))
6032                           "...")))
6033           ;; Pad the mode string a bit.
6034           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
6035       ;; Update the mode line.
6036       (setq mode-line-buffer-identification
6037             (gnus-mode-line-buffer-identification (list mode-string)))
6038       (set-buffer-modified-p t))))
6039
6040 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6041   "Go through the HEADERS list and add all Xrefs to a hash table.
6042 The resulting hash table is returned, or nil if no Xrefs were found."
6043   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
6044          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
6045          (xref-hashtb (gnus-make-hashtable))
6046          start group entry number xrefs header)
6047     (while headers
6048       (setq header (pop headers))
6049       (when (and (setq xrefs (mail-header-xref header))
6050                  (not (memq (setq number (mail-header-number header))
6051                             unreads)))
6052         (setq start 0)
6053         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6054           (setq start (match-end 0))
6055           (setq group (if prefix
6056                           (concat prefix (substring xrefs (match-beginning 1)
6057                                                     (match-end 1)))
6058                         (substring xrefs (match-beginning 1) (match-end 1))))
6059           (setq number
6060                 (string-to-number (substring xrefs (match-beginning 2)
6061                                           (match-end 2))))
6062           (if (setq entry (gnus-gethash group xref-hashtb))
6063               (setcdr entry (cons number (cdr entry)))
6064             (gnus-sethash group (cons number nil) xref-hashtb)))))
6065     (and start xref-hashtb)))
6066
6067 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6068   "Look through all the headers and mark the Xrefs as read."
6069   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6070         name info xref-hashtb idlist method nth4)
6071     (save-excursion
6072       (set-buffer gnus-group-buffer)
6073       (when (setq xref-hashtb
6074                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6075         (mapatoms
6076          (lambda (group)
6077            (unless (string= from-newsgroup (setq name (symbol-name group)))
6078              (setq idlist (symbol-value group))
6079              ;; Dead groups are not updated.
6080              (and (prog1
6081                       (setq info (gnus-get-info name))
6082                     (when (stringp (setq nth4 (gnus-info-method info)))
6083                       (setq nth4 (gnus-server-to-method nth4))))
6084                   ;; Only do the xrefs if the group has the same
6085                   ;; select method as the group we have just read.
6086                   (or (gnus-methods-equal-p
6087                        nth4 (gnus-find-method-for-group from-newsgroup))
6088                       virtual
6089                       (equal nth4 (setq method (gnus-find-method-for-group
6090                                                 from-newsgroup)))
6091                       (and (equal (car nth4) (car method))
6092                            (equal (nth 1 nth4) (nth 1 method))))
6093                   gnus-use-cross-reference
6094                   (or (not (eq gnus-use-cross-reference t))
6095                       virtual
6096                       ;; Only do cross-references on subscribed
6097                       ;; groups, if that is what is wanted.
6098                       (<= (gnus-info-level info) gnus-level-subscribed))
6099                   (gnus-group-make-articles-read name idlist))))
6100          xref-hashtb)))))
6101
6102 (defun gnus-compute-read-articles (group articles)
6103   (let* ((entry (gnus-group-entry group))
6104          (info (nth 2 entry))
6105          (active (gnus-active group))
6106          ninfo)
6107     (when entry
6108       ;; First peel off all invalid article numbers.
6109       (when active
6110         (let ((ids articles)
6111               id first)
6112           (while (setq id (pop ids))
6113             (when (and first (> id (cdr active)))
6114               ;; We'll end up in this situation in one particular
6115               ;; obscure situation.  If you re-scan a group and get
6116               ;; a new article that is cross-posted to a different
6117               ;; group that has not been re-scanned, you might get
6118               ;; crossposted article that has a higher number than
6119               ;; Gnus believes possible.  So we re-activate this
6120               ;; group as well.  This might mean doing the
6121               ;; crossposting thingy will *increase* the number
6122               ;; of articles in some groups.  Tsk, tsk.
6123               (setq active (or (gnus-activate-group group) active)))
6124             (when (or (> id (cdr active))
6125                       (< id (car active)))
6126               (setq articles (delq id articles))))))
6127       ;; If the read list is nil, we init it.
6128       (if (and active
6129                (null (gnus-info-read info))
6130                (> (car active) 1))
6131           (setq ninfo (cons 1 (1- (car active))))
6132         (setq ninfo (gnus-info-read info)))
6133       ;; Then we add the read articles to the range.
6134       (gnus-add-to-range
6135        ninfo (setq articles (sort articles '<))))))
6136
6137 (defun gnus-group-make-articles-read (group articles)
6138   "Update the info of GROUP to say that ARTICLES are read."
6139   (let* ((num 0)
6140          (entry (gnus-group-entry group))
6141          (info (nth 2 entry))
6142          (active (gnus-active group))
6143          range)
6144     (when entry
6145       (setq range (gnus-compute-read-articles group articles))
6146       (with-current-buffer gnus-group-buffer
6147         (gnus-undo-register
6148           `(progn
6149              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6150              (gnus-info-set-read ',info ',(gnus-info-read info))
6151              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6152              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6153              (gnus-group-update-group ,group t))))
6154       ;; Add the read articles to the range.
6155       (gnus-info-set-read info range)
6156       (gnus-request-set-mark group (list (list range 'add '(read))))
6157       ;; Then we have to re-compute how many unread
6158       ;; articles there are in this group.
6159       (when active
6160         (cond
6161          ((not range)
6162           (setq num (- (1+ (cdr active)) (car active))))
6163          ((not (listp (cdr range)))
6164           (setq num (- (cdr active) (- (1+ (cdr range))
6165                                        (car range)))))
6166          (t
6167           (while range
6168             (if (numberp (car range))
6169                 (setq num (1+ num))
6170               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6171             (setq range (cdr range)))
6172           (setq num (- (cdr active) num))))
6173         ;; Update the number of unread articles.
6174         (setcar entry num)
6175         ;; Update the group buffer.
6176         (unless (gnus-ephemeral-group-p group)
6177           (gnus-group-update-group group t))))))
6178
6179 (defvar gnus-newsgroup-none-id 0)
6180
6181 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6182   (let ((cur nntp-server-buffer)
6183         (dependencies
6184          (or dependencies
6185              (with-current-buffer gnus-summary-buffer
6186                gnus-newsgroup-dependencies)))
6187         headers id end ref number
6188         (mail-parse-charset gnus-newsgroup-charset)
6189         (mail-parse-ignored-charsets
6190          (save-current-buffer (condition-case nil
6191                                   (set-buffer gnus-summary-buffer)
6192                                 (error))
6193                               gnus-newsgroup-ignored-charsets)))
6194     (with-current-buffer nntp-server-buffer
6195       ;; Translate all TAB characters into SPACE characters.
6196       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6197       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6198       (ietf-drums-unfold-fws)
6199       (gnus-run-hooks 'gnus-parse-headers-hook)
6200       (let ((case-fold-search t)
6201             in-reply-to header p lines chars)
6202         (goto-char (point-min))
6203         ;; Search to the beginning of the next header.  Error messages
6204         ;; do not begin with 2 or 3.
6205         (while (re-search-forward "^[23][0-9]+ " nil t)
6206           (setq id nil
6207                 ref nil)
6208           ;; This implementation of this function, with nine
6209           ;; search-forwards instead of the one re-search-forward and
6210           ;; a case (which basically was the old function) is actually
6211           ;; about twice as fast, even though it looks messier.  You
6212           ;; can't have everything, I guess.  Speed and elegance
6213           ;; doesn't always go hand in hand.
6214           (setq
6215            header
6216            (vector
6217             ;; Number.
6218             (prog1
6219                 (setq number (read cur))
6220               (end-of-line)
6221               (setq p (point))
6222               (narrow-to-region (point)
6223                                 (or (and (search-forward "\n.\n" nil t)
6224                                          (- (point) 2))
6225                                     (point))))
6226             ;; Subject.
6227             (progn
6228               (goto-char p)
6229               (if (search-forward "\nsubject:" nil t)
6230                   (funcall gnus-decode-encoded-word-function
6231                            (nnheader-header-value))
6232                 "(none)"))
6233             ;; From.
6234             (progn
6235               (goto-char p)
6236               (if (search-forward "\nfrom:" nil t)
6237                   (funcall gnus-decode-encoded-address-function
6238                            (nnheader-header-value))
6239                 "(nobody)"))
6240             ;; Date.
6241             (progn
6242               (goto-char p)
6243               (if (search-forward "\ndate:" nil t)
6244                   (nnheader-header-value) ""))
6245             ;; Message-ID.
6246             (progn
6247               (goto-char p)
6248               (setq id (if (re-search-forward
6249                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6250                            ;; We do it this way to make sure the Message-ID
6251                            ;; is (somewhat) syntactically valid.
6252                            (buffer-substring (match-beginning 1)
6253                                              (match-end 1))
6254                          ;; If there was no message-id, we just fake one
6255                          ;; to make subsequent routines simpler.
6256                          (nnheader-generate-fake-message-id number))))
6257             ;; References.
6258             (progn
6259               (goto-char p)
6260               (if (search-forward "\nreferences:" nil t)
6261                   (progn
6262                     (setq end (point))
6263                     (prog1
6264                         (nnheader-header-value)
6265                       (setq ref
6266                             (buffer-substring
6267                              (progn
6268                                (end-of-line)
6269                                (search-backward ">" end t)
6270                                (1+ (point)))
6271                              (progn
6272                                (search-backward "<" end t)
6273                                (point))))))
6274                 ;; Get the references from the in-reply-to header if there
6275                 ;; were no references and the in-reply-to header looks
6276                 ;; promising.
6277                 (if (and (search-forward "\nin-reply-to:" nil t)
6278                          (setq in-reply-to (nnheader-header-value))
6279                          (string-match "<[^>]+>" in-reply-to))
6280                     (let (ref2)
6281                       (setq ref (substring in-reply-to (match-beginning 0)
6282                                            (match-end 0)))
6283                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6284                         (setq ref2 (substring in-reply-to (match-beginning 0)
6285                                               (match-end 0)))
6286                         (when (> (length ref2) (length ref))
6287                           (setq ref ref2)))
6288                       ref)
6289                   (setq ref nil))))
6290             ;; Chars.
6291             (progn
6292               (goto-char p)
6293               (if (search-forward "\nchars: " nil t)
6294                   (if (numberp (setq chars (ignore-errors (read cur))))
6295                       chars -1)
6296                 -1))
6297             ;; Lines.
6298             (progn
6299               (goto-char p)
6300               (if (search-forward "\nlines: " nil t)
6301                   (if (numberp (setq lines (ignore-errors (read cur))))
6302                       lines -1)
6303                 -1))
6304             ;; Xref.
6305             (progn
6306               (goto-char p)
6307               (and (search-forward "\nxref:" nil t)
6308                    (nnheader-header-value)))
6309             ;; Extra.
6310             (when gnus-extra-headers
6311               (let ((extra gnus-extra-headers)
6312                     out)
6313                 (while extra
6314                   (goto-char p)
6315                   (when (search-forward
6316                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6317                     (push (cons (car extra) (nnheader-header-value))
6318                           out))
6319                   (pop extra))
6320                 out))))
6321           (when (equal id ref)
6322             (setq ref nil))
6323
6324           (when gnus-alter-header-function
6325             (funcall gnus-alter-header-function header)
6326             (setq id (mail-header-id header)
6327                   ref (gnus-parent-id (mail-header-references header))))
6328
6329           (when (setq header
6330                       (gnus-dependencies-add-header
6331                        header dependencies force-new))
6332             (push header headers))
6333           (goto-char (point-max))
6334           (widen))
6335         (nreverse headers)))))
6336
6337 ;; Goes through the xover lines and returns a list of vectors
6338 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6339                                                   force-new dependencies
6340                                                   group also-fetch-heads)
6341   "Parse the news overview data in the server buffer.
6342 Return a list of headers that match SEQUENCE (see
6343 `nntp-retrieve-headers')."
6344   ;; Get the Xref when the users reads the articles since most/some
6345   ;; NNTP servers do not include Xrefs when using XOVER.
6346   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6347   (let ((mail-parse-charset gnus-newsgroup-charset)
6348         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6349         (cur nntp-server-buffer)
6350         (dependencies (or dependencies gnus-newsgroup-dependencies))
6351         (allp (cond
6352                ((eq gnus-read-all-available-headers t)
6353                 t)
6354                ((and (stringp gnus-read-all-available-headers)
6355                      group)
6356                 (string-match gnus-read-all-available-headers group))
6357                (t
6358                 nil)))
6359         number headers header)
6360     (with-current-buffer nntp-server-buffer
6361       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6362       ;; Allow the user to mangle the headers before parsing them.
6363       (gnus-run-hooks 'gnus-parse-headers-hook)
6364       (goto-char (point-min))
6365       (gnus-parse-without-error
6366         (while (and (or sequence allp)
6367                     (not (eobp)))
6368           (setq number (read cur))
6369           (when (not allp)
6370             (while (and sequence
6371                         (< (car sequence) number))
6372               (setq sequence (cdr sequence))))
6373           (when (and (or allp
6374                          (and sequence
6375                               (eq number (car sequence))))
6376                      (progn
6377                        (setq sequence (cdr sequence))
6378                        (setq header (inline
6379                                       (gnus-nov-parse-line
6380                                        number dependencies force-new)))))
6381             (push header headers))
6382           (forward-line 1)))
6383       ;; A common bug in inn is that if you have posted an article and
6384       ;; then retrieves the active file, it will answer correctly --
6385       ;; the new article is included.  However, a NOV entry for the
6386       ;; article may not have been generated yet, so this may fail.
6387       ;; We work around this problem by retrieving the last few
6388       ;; headers using HEAD.
6389       (if (or (not also-fetch-heads)
6390               (not sequence))
6391           ;; We (probably) got all the headers.
6392           (nreverse headers)
6393         (let ((gnus-nov-is-evil t))
6394           (nconc
6395            (nreverse headers)
6396            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6397              (gnus-get-newsgroup-headers))))))))
6398
6399 (defun gnus-article-get-xrefs ()
6400   "Fill in the Xref value in `gnus-current-headers', if necessary.
6401 This is meant to be called in `gnus-article-internal-prepare-hook'."
6402   (let ((headers (with-current-buffer gnus-summary-buffer
6403                    gnus-current-headers)))
6404     (or (not gnus-use-cross-reference)
6405         (not headers)
6406         (and (mail-header-xref headers)
6407              (not (string= (mail-header-xref headers) "")))
6408         (let ((case-fold-search t)
6409               xref)
6410           (save-restriction
6411             (nnheader-narrow-to-headers)
6412             (goto-char (point-min))
6413             (when (or (and (not (eobp))
6414                            (eq (downcase (char-after)) ?x)
6415                            (looking-at "Xref:"))
6416                       (search-forward "\nXref:" nil t))
6417               (goto-char (1+ (match-end 0)))
6418               (setq xref (buffer-substring (point) (point-at-eol)))
6419               (mail-header-set-xref headers xref)))))))
6420
6421 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6422   "Find article ID and insert the summary line for that article.
6423 OLD-HEADER can either be a header or a line number to insert
6424 the subject line on."
6425   (let* ((line (and (numberp old-header) old-header))
6426          (old-header (and (vectorp old-header) old-header))
6427          (header (cond ((and old-header use-old-header)
6428                         old-header)
6429                        ((and (numberp id)
6430                              (gnus-number-to-header id))
6431                         (gnus-number-to-header id))
6432                        (t
6433                         (gnus-read-header id))))
6434          (number (and (numberp id) id))
6435          d)
6436     (when header
6437       ;; Rebuild the thread that this article is part of and go to the
6438       ;; article we have fetched.
6439       (when (and (not gnus-show-threads)
6440                  old-header)
6441         (when (and number
6442                    (setq d (gnus-data-find (mail-header-number old-header))))
6443           (goto-char (gnus-data-pos d))
6444           (gnus-data-remove
6445            number
6446            (- (point-at-bol)
6447               (prog1
6448                   (1+ (point-at-eol))
6449                 (gnus-delete-line))))))
6450       ;; Remove list identifiers from subject.
6451       (when gnus-list-identifiers
6452         (let ((gnus-newsgroup-headers (list header)))
6453           (gnus-summary-remove-list-identifiers)))
6454       (when old-header
6455         (mail-header-set-number header (mail-header-number old-header)))
6456       (setq gnus-newsgroup-sparse
6457             (delq (setq number (mail-header-number header))
6458                   gnus-newsgroup-sparse))
6459       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6460       (push number gnus-newsgroup-limit)
6461       (gnus-rebuild-thread (mail-header-id header) line)
6462       (gnus-summary-goto-subject number nil t))
6463     (when (and (numberp number)
6464                (> number 0))
6465       ;; We have to update the boundaries even if we can't fetch the
6466       ;; article if ID is a number -- so that the next `P' or `N'
6467       ;; command will fetch the previous (or next) article even
6468       ;; if the one we tried to fetch this time has been canceled.
6469       (when (> number gnus-newsgroup-end)
6470         (setq gnus-newsgroup-end number))
6471       (when (< number gnus-newsgroup-begin)
6472         (setq gnus-newsgroup-begin number))
6473       (setq gnus-newsgroup-unselected
6474             (delq number gnus-newsgroup-unselected)))
6475     ;; Report back a success?
6476     (and header (mail-header-number header))))
6477
6478 ;;; Process/prefix in the summary buffer
6479
6480 (defun gnus-summary-work-articles (n)
6481   "Return a list of articles to be worked upon.
6482 The prefix argument, the list of process marked articles, and the
6483 current article will be taken into consideration."
6484   (with-current-buffer gnus-summary-buffer
6485     (cond
6486      (n
6487       ;; A numerical prefix has been given.
6488       (setq n (prefix-numeric-value n))
6489       (let ((backward (< n 0))
6490             (n (abs (prefix-numeric-value n)))
6491             articles article)
6492         (save-excursion
6493           (while
6494               (and (> n 0)
6495                    (push (setq article (gnus-summary-article-number))
6496                          articles)
6497                    (if backward
6498                        (gnus-summary-find-prev nil article)
6499                      (gnus-summary-find-next nil article)))
6500             (decf n)))
6501         (nreverse articles)))
6502      ((and (gnus-region-active-p) (mark))
6503       (message "region active")
6504       ;; Work on the region between point and mark.
6505       (let ((max (max (point) (mark)))
6506             articles article)
6507         (save-excursion
6508           (goto-char (min (point) (mark)))
6509           (while
6510               (and
6511                (push (setq article (gnus-summary-article-number)) articles)
6512                (gnus-summary-find-next nil article)
6513                (< (point) max)))
6514           (nreverse articles))))
6515      (gnus-newsgroup-processable
6516       ;; There are process-marked articles present.
6517       ;; Save current state.
6518       (gnus-summary-save-process-mark)
6519       ;; Return the list.
6520       (reverse gnus-newsgroup-processable))
6521      (t
6522       ;; Just return the current article.
6523       (list (gnus-summary-article-number))))))
6524
6525 (defmacro gnus-summary-iterate (arg &rest forms)
6526   "Iterate over the process/prefixed articles and do FORMS.
6527 ARG is the interactive prefix given to the command.  FORMS will be
6528 executed with point over the summary line of the articles."
6529   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6530     `(let ((,articles (gnus-summary-work-articles ,arg)))
6531        (while ,articles
6532          (gnus-summary-goto-subject (car ,articles))
6533          ,@forms
6534          (pop ,articles)))))
6535
6536 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6537 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6538
6539 (defun gnus-summary-save-process-mark ()
6540   "Push the current set of process marked articles on the stack."
6541   (interactive)
6542   (push (copy-sequence gnus-newsgroup-processable)
6543         gnus-newsgroup-process-stack))
6544
6545 (defun gnus-summary-kill-process-mark ()
6546   "Push the current set of process marked articles on the stack and unmark."
6547   (interactive)
6548   (gnus-summary-save-process-mark)
6549   (gnus-summary-unmark-all-processable))
6550
6551 (defun gnus-summary-yank-process-mark ()
6552   "Pop the last process mark state off the stack and restore it."
6553   (interactive)
6554   (unless gnus-newsgroup-process-stack
6555     (error "Empty mark stack"))
6556   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6557
6558 (defun gnus-summary-process-mark-set (set)
6559   "Make SET into the current process marked articles."
6560   (gnus-summary-unmark-all-processable)
6561   (mapc 'gnus-summary-set-process-mark set))
6562
6563 ;;; Searching and stuff
6564
6565 (defun gnus-summary-search-group (&optional backward use-level)
6566   "Search for next unread newsgroup.
6567 If optional argument BACKWARD is non-nil, search backward instead."
6568   (with-current-buffer gnus-group-buffer
6569     (when (gnus-group-search-forward
6570            backward nil (if use-level (gnus-group-group-level) nil))
6571       (gnus-group-group-name))))
6572
6573 (defun gnus-summary-best-group (&optional exclude-group)
6574   "Find the name of the best unread group.
6575 If EXCLUDE-GROUP, do not go to this group."
6576   (with-current-buffer gnus-group-buffer
6577     (save-excursion
6578       (gnus-group-best-unread-group exclude-group))))
6579
6580 (defun gnus-summary-find-next (&optional unread article backward)
6581   (if backward
6582       (gnus-summary-find-prev unread article)
6583     (let* ((dummy (gnus-summary-article-intangible-p))
6584            (article (or article (gnus-summary-article-number)))
6585            (data (gnus-data-find-list article))
6586            result)
6587       (when (and (not dummy)
6588                  (or (not gnus-summary-check-current)
6589                      (not unread)
6590                      (not (gnus-data-unread-p (car data)))))
6591         (setq data (cdr data)))
6592       (when (setq result
6593                   (if unread
6594                       (progn
6595                         (while data
6596                           (unless (memq (gnus-data-number (car data))
6597                                         (cond
6598                                          ((eq gnus-auto-goto-ignores
6599                                               'always-undownloaded)
6600                                           gnus-newsgroup-undownloaded)
6601                                          (gnus-plugged
6602                                           nil)
6603                                          ((eq gnus-auto-goto-ignores
6604                                               'unfetched)
6605                                           gnus-newsgroup-unfetched)
6606                                          ((eq gnus-auto-goto-ignores
6607                                               'undownloaded)
6608                                           gnus-newsgroup-undownloaded)))
6609                             (when (gnus-data-unread-p (car data))
6610                               (setq result (car data)
6611                                     data nil)))
6612                           (setq data (cdr data)))
6613                         result)
6614                     (car data)))
6615         (goto-char (gnus-data-pos result))
6616         (gnus-data-number result)))))
6617
6618 (defun gnus-summary-find-prev (&optional unread article)
6619   (let* ((eobp (eobp))
6620          (article (or article (gnus-summary-article-number)))
6621          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6622          result)
6623     (when (and (not eobp)
6624                (or (not gnus-summary-check-current)
6625                    (not unread)
6626                    (not (gnus-data-unread-p (car data)))))
6627       (setq data (cdr data)))
6628     (when (setq result
6629                 (if unread
6630                     (progn
6631                       (while data
6632                         (unless (memq (gnus-data-number (car data))
6633                                       (cond
6634                                        ((eq gnus-auto-goto-ignores
6635                                             'always-undownloaded)
6636                                         gnus-newsgroup-undownloaded)
6637                                        (gnus-plugged
6638                                         nil)
6639                                        ((eq gnus-auto-goto-ignores
6640                                             'unfetched)
6641                                         gnus-newsgroup-unfetched)
6642                                        ((eq gnus-auto-goto-ignores
6643                                             'undownloaded)
6644                                         gnus-newsgroup-undownloaded)))
6645                           (when (gnus-data-unread-p (car data))
6646                             (setq result (car data)
6647                                   data nil)))
6648                         (setq data (cdr data)))
6649                       result)
6650                   (car data)))
6651       (goto-char (gnus-data-pos result))
6652       (gnus-data-number result))))
6653
6654 (defun gnus-summary-find-subject (subject &optional unread backward article)
6655   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6656          (article (or article (gnus-summary-article-number)))
6657          (articles (gnus-data-list backward))
6658          (arts (gnus-data-find-list article articles))
6659          result)
6660     (when (or (not gnus-summary-check-current)
6661               (not unread)
6662               (not (gnus-data-unread-p (car arts))))
6663       (setq arts (cdr arts)))
6664     (while arts
6665       (and (or (not unread)
6666                (gnus-data-unread-p (car arts)))
6667            (vectorp (gnus-data-header (car arts)))
6668            (gnus-subject-equal
6669             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6670            (setq result (car arts)
6671                  arts nil))
6672       (setq arts (cdr arts)))
6673     (and result
6674          (goto-char (gnus-data-pos result))
6675          (gnus-data-number result))))
6676
6677 (defun gnus-summary-search-forward (&optional unread subject backward)
6678   "Search forward for an article.
6679 If UNREAD, look for unread articles.  If SUBJECT, look for
6680 articles with that subject.  If BACKWARD, search backward instead."
6681   (cond (subject (gnus-summary-find-subject subject unread backward))
6682         (backward (gnus-summary-find-prev unread))
6683         (t (gnus-summary-find-next unread))))
6684
6685 (defun gnus-recenter (&optional n)
6686   "Center point in window and redisplay frame.
6687 Also do horizontal recentering."
6688   (interactive "P")
6689   (when (and gnus-auto-center-summary
6690              (not (eq gnus-auto-center-summary 'vertical)))
6691     (gnus-horizontal-recenter))
6692   (recenter n))
6693
6694 (defun gnus-summary-recenter ()
6695   "Center point in the summary window.
6696 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6697 displayed, no centering will be performed."
6698   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6699   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6700   (interactive)
6701   ;; The user has to want it.
6702   (when gnus-auto-center-summary
6703     (let* ((top (cond ((< (window-height) 4) 0)
6704                       ((< (window-height) 7) 1)
6705                       (t (if (numberp gnus-auto-center-summary)
6706                              gnus-auto-center-summary
6707                            (/ (1- (window-height)) 2)))))
6708            (height (1- (window-height)))
6709            (bottom (save-excursion (goto-char (point-max))
6710                                    (forward-line (- height))
6711                                    (point)))
6712            (window (get-buffer-window (current-buffer))))
6713       (when (get-buffer-window gnus-article-buffer)
6714         ;; Only do recentering when the article buffer is displayed,
6715         ;; Set the window start to either `bottom', which is the biggest
6716         ;; possible valid number, or the second line from the top,
6717         ;; whichever is the least.
6718         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6719           (if (> bottom top-pos)
6720               ;; Keep the second line from the top visible
6721               (set-window-start window top-pos)
6722             ;; Try to keep the bottom line visible; if it's partially
6723             ;; obscured, either scroll one more line to make it fully
6724             ;; visible, or revert to using TOP-POS.
6725             (save-excursion
6726               (goto-char (point-max))
6727               (forward-line -1)
6728               (let ((last-line-start (point)))
6729                 (goto-char bottom)
6730                 (set-window-start window (point) t)
6731                 (when (not (pos-visible-in-window-p last-line-start window))
6732                   (forward-line 1)
6733                   (set-window-start window (min (point) top-pos) t)))))))
6734       ;; Do horizontal recentering while we're at it.
6735       (when (and (get-buffer-window (current-buffer) t)
6736                  (not (eq gnus-auto-center-summary 'vertical)))
6737         (let ((selected (selected-window)))
6738           (select-window (get-buffer-window (current-buffer) t))
6739           (gnus-summary-position-point)
6740           (gnus-horizontal-recenter)
6741           (select-window selected))))))
6742
6743 (defun gnus-summary-jump-to-group (newsgroup)
6744   "Move point to NEWSGROUP in group mode buffer."
6745   ;; Keep update point of group mode buffer if visible.
6746   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6747       (save-window-excursion
6748         ;; Take care of tree window mode.
6749         (when (get-buffer-window gnus-group-buffer)
6750           (pop-to-buffer gnus-group-buffer))
6751         (gnus-group-jump-to-group newsgroup))
6752     (save-excursion
6753       ;; Take care of tree window mode.
6754       (if (get-buffer-window gnus-group-buffer 0)
6755           (pop-to-buffer gnus-group-buffer)
6756         (set-buffer gnus-group-buffer))
6757       (gnus-group-jump-to-group newsgroup))))
6758
6759 ;; This function returns a list of article numbers based on the
6760 ;; difference between the ranges of read articles in this group and
6761 ;; the range of active articles.
6762 (defun gnus-list-of-unread-articles (group)
6763   (let* ((read (gnus-info-read (gnus-get-info group)))
6764          (active (or (gnus-active group) (gnus-activate-group group)))
6765          (last (or (cdr active)
6766                    (error "Group %s couldn't be activated " group)))
6767          (bottom (if gnus-newsgroup-maximum-articles
6768                      (max (car active)
6769                           (- last gnus-newsgroup-maximum-articles -1))
6770                    (car active)))
6771          first nlast unread)
6772     ;; If none are read, then all are unread.
6773     (if (not read)
6774         (setq first bottom)
6775       ;; If the range of read articles is a single range, then the
6776       ;; first unread article is the article after the last read
6777       ;; article.  Sounds logical, doesn't it?
6778       (if (and (not (listp (cdr read)))
6779                (or (< (car read) bottom)
6780                    (progn (setq read (list read))
6781                           nil)))
6782           (setq first (max bottom (1+ (cdr read))))
6783         ;; `read' is a list of ranges.
6784         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6785                                   (caar read)))
6786                   1)
6787           (setq first bottom))
6788         (while read
6789           (when first
6790             (while (< first nlast)
6791               (setq unread (cons first unread)
6792                     first (1+ first))))
6793           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6794           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6795           (setq read (cdr read)))))
6796     ;; And add the last unread articles.
6797     (while (<= first last)
6798       (setq unread (cons first unread)
6799             first (1+ first)))
6800     ;; Return the list of unread articles.
6801     (delq 0 (nreverse unread))))
6802
6803 (defun gnus-list-of-read-articles (group)
6804   "Return a list of unread, unticked and non-dormant articles."
6805   (let* ((info (gnus-get-info group))
6806          (marked (gnus-info-marks info))
6807          (active (gnus-active group)))
6808     (and info active
6809          (gnus-list-range-difference
6810           (gnus-list-range-difference
6811            (gnus-sorted-complement
6812             (gnus-uncompress-range
6813              (if gnus-newsgroup-maximum-articles
6814                  (cons (max (car active)
6815                             (- (cdr active)
6816                                gnus-newsgroup-maximum-articles
6817                                -1))
6818                        (cdr active))
6819                active))
6820             (gnus-list-of-unread-articles group))
6821            (cdr (assq 'dormant marked)))
6822           (cdr (assq 'tick marked))))))
6823
6824 ;; This function returns a sequence of article numbers based on the
6825 ;; difference between the ranges of read articles in this group and
6826 ;; the range of active articles.
6827 (defun gnus-sequence-of-unread-articles (group)
6828   (let* ((read (gnus-info-read (gnus-get-info group)))
6829          (active (or (gnus-active group) (gnus-activate-group group)))
6830          (last (cdr active))
6831          (bottom (if gnus-newsgroup-maximum-articles
6832                      (max (car active)
6833                           (- last gnus-newsgroup-maximum-articles -1))
6834                    (car active)))
6835          first nlast unread)
6836     ;; If none are read, then all are unread.
6837     (if (not read)
6838         (setq first bottom)
6839       ;; If the range of read articles is a single range, then the
6840       ;; first unread article is the article after the last read
6841       ;; article.  Sounds logical, doesn't it?
6842       (if (and (not (listp (cdr read)))
6843                (or (< (car read) bottom)
6844                    (progn (setq read (list read))
6845                           nil)))
6846           (setq first (max bottom (1+ (cdr read))))
6847         ;; `read' is a list of ranges.
6848         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6849                                   (caar read)))
6850                   1)
6851           (setq first bottom))
6852         (while read
6853           (when first
6854             (push (cons first nlast) unread))
6855           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6856           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6857           (setq read (cdr read)))))
6858     ;; And add the last unread articles.
6859     (cond ((not (and first last))
6860            nil)
6861           ((< first last)
6862            (push (cons first last) unread))
6863           ((= first last)
6864            (push first unread)))
6865     ;; Return the sequence of unread articles.
6866     (delq 0 (nreverse unread))))
6867
6868 ;; Various summary commands
6869
6870 (defun gnus-summary-select-article-buffer ()
6871   "Reconfigure windows to show article buffer."
6872   (interactive)
6873   (if (not (gnus-buffer-live-p gnus-article-buffer))
6874       (error "There is no article buffer for this summary buffer")
6875     (gnus-configure-windows 'article)
6876     (select-window (get-buffer-window gnus-article-buffer))))
6877
6878 (defun gnus-summary-universal-argument (arg)
6879   "Perform any operation on all articles that are process/prefixed."
6880   (interactive "P")
6881   (let ((articles (gnus-summary-work-articles arg))
6882         func article)
6883     (if (eq
6884          (setq
6885           func
6886           (key-binding
6887            (read-key-sequence
6888             (substitute-command-keys
6889              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6890          'undefined)
6891         (gnus-error 1 "Undefined key")
6892       (save-excursion
6893         (while articles
6894           (gnus-summary-goto-subject (setq article (pop articles)))
6895           (let (gnus-newsgroup-processable)
6896             (command-execute func))
6897           (gnus-summary-remove-process-mark article)))))
6898   (gnus-summary-position-point))
6899
6900 (defun gnus-summary-toggle-truncation (&optional arg)
6901   "Toggle truncation of summary lines.
6902 With ARG, turn line truncation on if ARG is positive."
6903   (interactive "P")
6904   (setq truncate-lines
6905         (if (null arg) (not truncate-lines)
6906           (> (prefix-numeric-value arg) 0)))
6907   (redraw-display))
6908
6909 (defun gnus-summary-find-for-reselect ()
6910   "Return the number of an article to stay on across a reselect.
6911 The current article is considered, then following articles, then previous
6912 articles.  An article is sought which is not cancelled and isn't a temporary
6913 insertion from another group.  If there's no such then return a dummy 0."
6914   (let (found)
6915     (dolist (rev '(nil t))
6916       (unless found      ; don't demand the reverse list if we don't need it
6917         (let ((data (gnus-data-find-list
6918                      (gnus-summary-article-number) (gnus-data-list rev))))
6919           (while (and data (not found))
6920             (if (and (< 0 (gnus-data-number (car data)))
6921                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6922                 (setq found (gnus-data-number (car data))))
6923             (setq data (cdr data))))))
6924     (or found 0)))
6925
6926 (defun gnus-summary-reselect-current-group (&optional all rescan)
6927   "Exit and then reselect the current newsgroup.
6928 The prefix argument ALL means to select all articles."
6929   (interactive "P")
6930   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6931     (error "Ephemeral groups can't be reselected"))
6932   (let ((current-subject (gnus-summary-find-for-reselect))
6933         (group gnus-newsgroup-name))
6934     (setq gnus-newsgroup-begin nil)
6935     (gnus-summary-exit nil 'leave-hidden)
6936     ;; We have to adjust the point of group mode buffer because
6937     ;; point was moved to the next unread newsgroup by exiting.
6938     (gnus-summary-jump-to-group group)
6939     (when rescan
6940       (save-excursion
6941         (gnus-group-get-new-news-this-group 1)))
6942     (gnus-group-read-group all t)
6943     (gnus-summary-goto-subject current-subject nil t)))
6944
6945 (defun gnus-summary-rescan-group (&optional all)
6946   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6947   (interactive "P")
6948   (gnus-summary-reselect-current-group all t))
6949
6950 (defun gnus-summary-update-info (&optional non-destructive)
6951   (save-excursion
6952     (let ((group gnus-newsgroup-name))
6953       (when group
6954         (when gnus-newsgroup-kill-headers
6955           (setq gnus-newsgroup-killed
6956                 (gnus-compress-sequence
6957                  (gnus-sorted-union
6958                   (gnus-list-range-intersection
6959                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6960                   gnus-newsgroup-unreads)
6961                  t)))
6962         (unless (listp (cdr gnus-newsgroup-killed))
6963           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6964         (let ((headers gnus-newsgroup-headers))
6965           ;; Set the new ranges of read articles.
6966           (with-current-buffer gnus-group-buffer
6967             (gnus-undo-force-boundary))
6968           (gnus-update-read-articles
6969            group (gnus-sorted-union
6970                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6971           ;; Set the current article marks.
6972           (let ((gnus-newsgroup-scored
6973                  (if (and (not gnus-save-score)
6974                           (not non-destructive))
6975                      nil
6976                    gnus-newsgroup-scored)))
6977             (save-excursion
6978               (gnus-update-marks)))
6979           ;; Do the cross-ref thing.
6980           (when gnus-use-cross-reference
6981             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6982           ;; Do not switch windows but change the buffer to work.
6983           (set-buffer gnus-group-buffer)
6984           (unless (gnus-ephemeral-group-p group)
6985             (gnus-group-update-group group)))))))
6986
6987 (defun gnus-summary-save-newsrc (&optional force)
6988   "Save the current number of read/marked articles in the dribble buffer.
6989 The dribble buffer will then be saved.
6990 If FORCE (the prefix), also save the .newsrc file(s)."
6991   (interactive "P")
6992   (gnus-summary-update-info t)
6993   (if force
6994       (gnus-save-newsrc-file)
6995     (gnus-dribble-save)))
6996
6997 (declare-function gnus-cache-write-active "gnus-cache" (&optional force))
6998
6999 (defun gnus-summary-exit (&optional temporary leave-hidden)
7000   "Exit reading current newsgroup, and then return to group selection mode.
7001 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
7002   (interactive)
7003   (gnus-set-global-variables)
7004   (when (gnus-buffer-live-p gnus-article-buffer)
7005     (with-current-buffer gnus-article-buffer
7006       (mm-destroy-parts gnus-article-mime-handles)
7007       ;; Set it to nil for safety reason.
7008       (setq gnus-article-mime-handle-alist nil)
7009       (setq gnus-article-mime-handles nil)))
7010   (gnus-kill-save-kill-buffer)
7011   (gnus-async-halt-prefetch)
7012   (let* ((group gnus-newsgroup-name)
7013          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
7014          (gnus-group-is-exiting-p t)
7015          (mode major-mode)
7016          (group-point nil)
7017          (buf (current-buffer)))
7018     (unless quit-config
7019       ;; Do adaptive scoring, and possibly save score files.
7020       (when gnus-newsgroup-adaptive
7021         (gnus-score-adaptive))
7022       (when gnus-use-scoring
7023         (gnus-score-save)))
7024     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
7025     ;; If we have several article buffers, we kill them at exit.
7026     (unless gnus-single-article-buffer
7027       (when (gnus-buffer-live-p gnus-article-buffer)
7028         (with-current-buffer gnus-article-buffer
7029           ;; Don't kill sticky article buffers
7030           (unless (eq major-mode 'gnus-sticky-article-mode)
7031             (gnus-kill-buffer gnus-article-buffer)
7032             (setq gnus-article-current nil))))
7033       (gnus-kill-buffer gnus-original-article-buffer))
7034     (when gnus-use-cache
7035       (gnus-cache-possibly-remove-articles)
7036       (gnus-cache-save-buffers))
7037     (gnus-async-prefetch-remove-group group)
7038     (when gnus-suppress-duplicates
7039       (gnus-dup-enter-articles))
7040     (when gnus-use-trees
7041       (gnus-tree-close group))
7042     (when gnus-use-cache
7043       (gnus-cache-write-active))
7044     ;; Remove entries for this group.
7045     (nnmail-purge-split-history (gnus-group-real-name group))
7046     ;; Make all changes in this group permanent.
7047     (unless quit-config
7048       (gnus-run-hooks 'gnus-exit-group-hook)
7049       (gnus-summary-update-info))
7050     (gnus-close-group group)
7051     ;; Make sure where we were, and go to next newsgroup.
7052     (set-buffer gnus-group-buffer)
7053     (unless quit-config
7054       (gnus-group-jump-to-group group))
7055     (gnus-run-hooks 'gnus-summary-exit-hook)
7056     (unless (or quit-config
7057                 (not gnus-summary-next-group-on-exit)
7058                 ;; If this group has disappeared from the summary
7059                 ;; buffer, don't skip forwards.
7060                 (not (string= group (gnus-group-group-name))))
7061       (gnus-group-next-unread-group 1))
7062     (setq group-point (point))
7063     (if temporary
7064         nil                             ;Nothing to do.
7065       (set-buffer buf)
7066       (if (not gnus-kill-summary-on-exit)
7067           (progn
7068             (gnus-deaden-summary)
7069             (setq mode nil))
7070         ;; We set all buffer-local variables to nil.  It is unclear why
7071         ;; this is needed, but if we don't, buffer-local variables are
7072         ;; not garbage-collected, it seems.  This would the lead to en
7073         ;; ever-growing Emacs.
7074         (gnus-summary-clear-local-variables)
7075         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7076           (gnus-summary-clear-local-variables))
7077         (when (get-buffer gnus-article-buffer)
7078           (bury-buffer gnus-article-buffer))
7079         ;; Return to group mode buffer.
7080         (when (eq mode 'gnus-summary-mode)
7081           (gnus-kill-buffer buf)))
7082       (setq gnus-current-select-method gnus-select-method)
7083       (set-buffer gnus-group-buffer)
7084       (if quit-config
7085           (gnus-handle-ephemeral-exit quit-config)
7086         (goto-char group-point)
7087         ;; If gnus-group-buffer is already displayed, make sure we also move
7088         ;; the cursor in the window that displays it.
7089         (let ((win (get-buffer-window (current-buffer) 0)))
7090           (if win (set-window-point win (point))))
7091         (unless leave-hidden
7092           (gnus-configure-windows 'group 'force)))
7093       ;; Clear the current group name.
7094       (unless quit-config
7095         (setq gnus-newsgroup-name nil)))))
7096
7097 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7098 (defun gnus-summary-exit-no-update (&optional no-questions)
7099   "Quit reading current newsgroup without updating read article info."
7100   (interactive)
7101   (let* ((group gnus-newsgroup-name)
7102          (gnus-group-is-exiting-p t)
7103          (gnus-group-is-exiting-without-update-p t)
7104          (quit-config (gnus-group-quit-config group)))
7105     (when (or no-questions
7106               gnus-expert-user
7107               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7108       (gnus-async-halt-prefetch)
7109       (run-hooks 'gnus-summary-prepare-exit-hook)
7110       (when (gnus-buffer-live-p gnus-article-buffer)
7111         (with-current-buffer gnus-article-buffer
7112           (mm-destroy-parts gnus-article-mime-handles)
7113           ;; Set it to nil for safety reason.
7114           (setq gnus-article-mime-handle-alist nil)
7115           (setq gnus-article-mime-handles nil)))
7116       ;; If we have several article buffers, we kill them at exit.
7117       (unless gnus-single-article-buffer
7118         (gnus-kill-buffer gnus-article-buffer)
7119         (gnus-kill-buffer gnus-original-article-buffer)
7120         (setq gnus-article-current nil))
7121       (if (not gnus-kill-summary-on-exit)
7122           (gnus-deaden-summary)
7123         (gnus-close-group group)
7124         (gnus-summary-clear-local-variables)
7125         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7126           (gnus-summary-clear-local-variables))
7127         (gnus-kill-buffer gnus-summary-buffer))
7128       (unless gnus-single-article-buffer
7129         (setq gnus-article-current nil))
7130       (when gnus-use-trees
7131         (gnus-tree-close group))
7132       (gnus-async-prefetch-remove-group group)
7133       (when (get-buffer gnus-article-buffer)
7134         (bury-buffer gnus-article-buffer))
7135       ;; Return to the group buffer.
7136       (gnus-configure-windows 'group 'force)
7137       ;; Clear the current group name.
7138       (setq gnus-newsgroup-name nil)
7139       (unless (gnus-ephemeral-group-p group)
7140         (gnus-group-update-group group))
7141       (when (equal (gnus-group-group-name) group)
7142         (gnus-group-next-unread-group 1))
7143       (when quit-config
7144         (gnus-handle-ephemeral-exit quit-config)))))
7145
7146 (defun gnus-handle-ephemeral-exit (quit-config)
7147   "Handle movement when leaving an ephemeral group.
7148 The state which existed when entering the ephemeral is reset."
7149   (if (not (buffer-name (car quit-config)))
7150       (gnus-configure-windows 'group 'force)
7151     (set-buffer (car quit-config))
7152     (cond ((eq major-mode 'gnus-summary-mode)
7153            (gnus-set-global-variables))
7154           ((eq major-mode 'gnus-article-mode)
7155            (save-current-buffer
7156              ;; The `gnus-summary-buffer' variable may point
7157              ;; to the old summary buffer when using a single
7158              ;; article buffer.
7159              (unless (gnus-buffer-live-p gnus-summary-buffer)
7160                (set-buffer gnus-group-buffer))
7161              (set-buffer gnus-summary-buffer)
7162              (gnus-set-global-variables))))
7163     (if (or (eq (cdr quit-config) 'article)
7164             (eq (cdr quit-config) 'pick))
7165         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7166             (gnus-configure-windows 'pick 'force)
7167           (gnus-configure-windows (cdr quit-config) 'force))
7168       (gnus-configure-windows (cdr quit-config) 'force))
7169     (when (eq major-mode 'gnus-summary-mode)
7170       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7171                                                      next-unread-noselect))
7172           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7173                                   'next-noselect)
7174                               (gnus-summary-next-subject 1 nil t))
7175                              ((eq gnus-auto-select-on-ephemeral-exit
7176                                   'next-unread-noselect)
7177                               (gnus-summary-next-subject 1 t t))))
7178             ;; Hide the article buffer which displays the article different
7179             ;; from the one that the cursor points to in the summary buffer.
7180             (gnus-configure-windows 'summary 'force))
7181         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7182                (gnus-summary-next-subject 1))
7183               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7184                (gnus-summary-next-subject 1 t))))
7185       (gnus-summary-recenter)
7186       (gnus-summary-position-point))))
7187
7188 ;;; Dead summaries.
7189
7190 (defvar gnus-dead-summary-mode-map nil)
7191
7192 (unless gnus-dead-summary-mode-map
7193   (setq gnus-dead-summary-mode-map (make-keymap))
7194   (suppress-keymap gnus-dead-summary-mode-map)
7195   (substitute-key-definition
7196    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7197   (dolist (key '("\C-d" "\r" "\177" [delete]))
7198     (define-key gnus-dead-summary-mode-map
7199       key 'gnus-summary-wake-up-the-dead))
7200   (dolist (key '("q" "Q"))
7201     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7202
7203 (defvar gnus-dead-summary-mode nil
7204   "Minor mode for Gnus summary buffers.")
7205
7206 (defun gnus-dead-summary-mode (&optional arg)
7207   "Minor mode for Gnus summary buffers."
7208   (interactive "P")
7209   (when (eq major-mode 'gnus-summary-mode)
7210     (make-local-variable 'gnus-dead-summary-mode)
7211     (setq gnus-dead-summary-mode
7212           (if (null arg) (not gnus-dead-summary-mode)
7213             (> (prefix-numeric-value arg) 0)))
7214     (when gnus-dead-summary-mode
7215       (add-minor-mode
7216        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7217
7218 (defun gnus-deaden-summary ()
7219   "Make the current summary buffer into a dead summary buffer."
7220   ;; Kill any previous dead summary buffer.
7221   (when (and gnus-dead-summary
7222              (buffer-name gnus-dead-summary))
7223     (with-current-buffer gnus-dead-summary
7224       (when gnus-dead-summary-mode
7225         (kill-buffer (current-buffer)))))
7226   ;; Make this the current dead summary.
7227   (setq gnus-dead-summary (current-buffer))
7228   (gnus-dead-summary-mode 1)
7229   (let ((name (buffer-name)))
7230     (when (string-match "Summary" name)
7231       (rename-buffer
7232        (concat (substring name 0 (match-beginning 0)) "Dead "
7233                (substring name (match-beginning 0)))
7234        t)
7235       (bury-buffer))))
7236
7237 (defun gnus-kill-or-deaden-summary (buffer)
7238   "Kill or deaden the summary BUFFER."
7239   (save-excursion
7240     (when (and (buffer-name buffer)
7241                (not gnus-single-article-buffer))
7242       (with-current-buffer buffer
7243         (gnus-kill-buffer gnus-article-buffer)
7244         (gnus-kill-buffer gnus-original-article-buffer)))
7245     (cond
7246      ;; Kill the buffer.
7247      (gnus-kill-summary-on-exit
7248       (when (and gnus-use-trees
7249                  (gnus-buffer-exists-p buffer))
7250         (with-current-buffer buffer
7251           (gnus-tree-close gnus-newsgroup-name)))
7252       (gnus-kill-buffer buffer))
7253      ;; Deaden the buffer.
7254      ((gnus-buffer-exists-p buffer)
7255       (with-current-buffer buffer
7256         (gnus-deaden-summary))))))
7257
7258 (defun gnus-summary-wake-up-the-dead (&rest args)
7259   "Wake up the dead summary buffer."
7260   (interactive)
7261   (gnus-dead-summary-mode -1)
7262   (let ((name (buffer-name)))
7263     (when (string-match "Dead " name)
7264       (rename-buffer
7265        (concat (substring name 0 (match-beginning 0))
7266                (substring name (match-end 0)))
7267        t)))
7268   (gnus-message 3 "This dead summary is now alive again"))
7269
7270 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7271 (defun gnus-summary-fetch-faq (&optional faq-dir)
7272   "Fetch the FAQ for the current group.
7273 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7274 in."
7275   (interactive
7276    (list
7277     (when current-prefix-arg
7278       (completing-read
7279        "FAQ dir: " (and (listp gnus-group-faq-directory)
7280                         (mapcar 'list
7281                                 gnus-group-faq-directory))))))
7282   (let (gnus-faq-buffer)
7283     (when (setq gnus-faq-buffer
7284                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7285       (gnus-configure-windows 'summary-faq))))
7286
7287 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7288 (defun gnus-summary-describe-group (&optional force)
7289   "Describe the current newsgroup."
7290   (interactive "P")
7291   (gnus-group-describe-group force gnus-newsgroup-name))
7292
7293 (defun gnus-summary-describe-briefly ()
7294   "Describe summary mode commands briefly."
7295   (interactive)
7296   (gnus-message 6 (substitute-command-keys "\\<gnus-summary-mode-map>\\[gnus-summary-next-page]:Select  \\[gnus-summary-next-unread-article]:Forward  \\[gnus-summary-prev-unread-article]:Backward  \\[gnus-summary-exit]:Exit  \\[gnus-info-find-node]:Run Info        \\[gnus-summary-describe-briefly]:This help")))
7297
7298 ;; Walking around group mode buffer from summary mode.
7299
7300 (defun gnus-summary-next-group (&optional no-article target-group backward)
7301   "Exit current newsgroup and then select next unread newsgroup.
7302 If prefix argument NO-ARTICLE is non-nil, no article is selected
7303 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7304 previous group instead."
7305   (interactive "P")
7306   ;; Stop pre-fetching.
7307   (gnus-async-halt-prefetch)
7308   (let ((current-group gnus-newsgroup-name)
7309         (current-buffer (current-buffer))
7310         entered)
7311     ;; First we semi-exit this group to update Xrefs and all variables.
7312     ;; We can't do a real exit, because the window conf must remain
7313     ;; the same in case the user is prompted for info, and we don't
7314     ;; want the window conf to change before that...
7315     (gnus-summary-exit t)
7316     (while (not entered)
7317       ;; Then we find what group we are supposed to enter.
7318       (set-buffer gnus-group-buffer)
7319       (gnus-group-jump-to-group current-group)
7320       (setq target-group
7321             (or target-group
7322                 (if (eq gnus-keep-same-level 'best)
7323                     (gnus-summary-best-group gnus-newsgroup-name)
7324                   (gnus-summary-search-group backward gnus-keep-same-level))))
7325       (if (not target-group)
7326           ;; There are no further groups, so we return to the group
7327           ;; buffer.
7328           (progn
7329             (gnus-message 5 "Returning to the group buffer")
7330             (setq entered t)
7331             (when (gnus-buffer-live-p current-buffer)
7332               (set-buffer current-buffer)
7333               (gnus-summary-exit))
7334             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7335         ;; We try to enter the target group.
7336         (gnus-group-jump-to-group target-group)
7337         (let ((unreads (gnus-group-group-unread)))
7338           (if (and (or (eq t unreads)
7339                        (and unreads (not (zerop unreads))))
7340                    (gnus-summary-read-group
7341                     target-group nil no-article
7342                     (and (buffer-name current-buffer) current-buffer)
7343                     nil backward))
7344               (setq entered t)
7345             (setq current-group target-group
7346                   target-group nil)))))))
7347
7348 (defun gnus-summary-prev-group (&optional no-article)
7349   "Exit current newsgroup and then select previous unread newsgroup.
7350 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7351   (interactive "P")
7352   (gnus-summary-next-group no-article nil t))
7353
7354 ;; Walking around summary lines.
7355
7356 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7357   "Go to the first subject satisfying any non-nil constraint.
7358 If UNREAD is non-nil, the article should be unread.
7359 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7360 If UNSEEN is non-nil, the article should be unseen.
7361 Returns the article selected or nil if there are no matching articles."
7362   (interactive "P")
7363   (cond
7364    ;; Empty summary.
7365    ((null gnus-newsgroup-data)
7366     (gnus-message 3 "No articles in the group")
7367     nil)
7368    ;; Pick the first article.
7369    ((not (or unread undownloaded unseen))
7370     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7371     (gnus-data-number (car gnus-newsgroup-data)))
7372    ;; Find the first unread article.
7373    (t
7374     (let ((data gnus-newsgroup-data))
7375       (while (and data
7376                   (let ((num (gnus-data-number (car data))))
7377                     (or (memq num gnus-newsgroup-unfetched)
7378                         (not (or (and unread
7379                                       (memq num gnus-newsgroup-unreads))
7380                                  (and undownloaded
7381                                       (memq num gnus-newsgroup-undownloaded))
7382                                  (and unseen
7383                                       (memq num gnus-newsgroup-unseen)))))))
7384         (setq data (cdr data)))
7385       (prog1
7386           (if data
7387               (progn
7388                 (goto-char (gnus-data-pos (car data)))
7389                 (gnus-data-number (car data)))
7390             (gnus-message 3 "No more%s articles"
7391                           (let* ((r (when unread " unread"))
7392                                  (d (when undownloaded " undownloaded"))
7393                                  (s (when unseen " unseen"))
7394                                  (l (delq nil (list r d s))))
7395                             (cond ((= 3 (length l))
7396                                    (concat r "," d ", or" s))
7397                                   ((= 2 (length l))
7398                                    (concat (car l) ", or" (cadr l)))
7399                                   ((= 1 (length l))
7400                                    (car l))
7401                                   (t
7402                                    ""))))
7403             nil
7404             )
7405         (gnus-summary-position-point))))))
7406
7407 (defun gnus-summary-next-subject (n &optional unread dont-display)
7408   "Go to next N'th summary line.
7409 If N is negative, go to the previous N'th subject line.
7410 If UNREAD is non-nil, only unread articles are selected.
7411 The difference between N and the actual number of steps taken is
7412 returned."
7413   (interactive "p")
7414   (let ((backward (< n 0))
7415         (n (abs n)))
7416     (while (and (> n 0)
7417                 (if backward
7418                     (gnus-summary-find-prev unread)
7419                   (gnus-summary-find-next unread)))
7420       (unless (zerop (setq n (1- n)))
7421         (gnus-summary-show-thread)))
7422     (when (/= 0 n)
7423       (gnus-message 7 "No more%s articles"
7424                     (if unread " unread" "")))
7425     (unless dont-display
7426       (gnus-summary-recenter)
7427       (gnus-summary-position-point))
7428     n))
7429
7430 (defun gnus-summary-next-unread-subject (n)
7431   "Go to next N'th unread summary line."
7432   (interactive "p")
7433   (gnus-summary-next-subject n t))
7434
7435 (defun gnus-summary-prev-subject (n &optional unread)
7436   "Go to previous N'th summary line.
7437 If optional argument UNREAD is non-nil, only unread article is selected."
7438   (interactive "p")
7439   (gnus-summary-next-subject (- n) unread))
7440
7441 (defun gnus-summary-prev-unread-subject (n)
7442   "Go to previous N'th unread summary line."
7443   (interactive "p")
7444   (gnus-summary-next-subject (- n) t))
7445
7446 (defun gnus-summary-goto-subjects (articles)
7447   "Insert the subject header for ARTICLES in the current buffer."
7448   (save-excursion
7449     (dolist (article articles)
7450       (gnus-summary-goto-subject article t)))
7451   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7452   (gnus-summary-position-point))
7453
7454 (defun gnus-summary-goto-subject (article &optional force silent)
7455   "Go to the subject line of ARTICLE.
7456 If FORCE, also allow jumping to articles not currently shown."
7457   (interactive "nArticle number: ")
7458   (unless (numberp article)
7459     (error "Article %s is not a number" article))
7460   (let ((b (point))
7461         (data (gnus-data-find article)))
7462     ;; We read in the article if we have to.
7463     (and (not data)
7464          force
7465          (gnus-summary-insert-subject
7466           article
7467           (if (or (numberp force) (vectorp force)) force)
7468           t)
7469          (setq data (gnus-data-find article)))
7470     (goto-char b)
7471     (if (not data)
7472         (progn
7473           (unless silent
7474             (gnus-message 3 "Can't find article %d" article))
7475           nil)
7476       (let ((pt (gnus-data-pos data)))
7477         (goto-char pt)
7478         (gnus-summary-set-article-display-arrow pt))
7479       (gnus-summary-position-point)
7480       article)))
7481
7482 ;; Walking around summary lines with displaying articles.
7483
7484 (defun gnus-summary-expand-window (&optional arg)
7485   "Make the summary buffer take up the entire Emacs frame.
7486 Given a prefix, will force an `article' buffer configuration."
7487   (interactive "P")
7488   (if arg
7489       (gnus-configure-windows 'article 'force)
7490     (gnus-configure-windows 'summary 'force)))
7491
7492 (defun gnus-summary-display-article (article &optional all-header)
7493   "Display ARTICLE in article buffer."
7494   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7495                (with-current-buffer gnus-article-buffer
7496                  (eq major-mode 'gnus-article-mode)))
7497     (gnus-article-setup-buffer))
7498   (gnus-set-global-variables)
7499   (with-current-buffer gnus-article-buffer
7500     (setq gnus-article-charset gnus-newsgroup-charset)
7501     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7502     (mm-enable-multibyte))
7503   (if (null article)
7504       nil
7505     (prog1
7506         (if gnus-summary-display-article-function
7507             (funcall gnus-summary-display-article-function article all-header)
7508           (gnus-article-prepare article all-header))
7509       (gnus-run-hooks 'gnus-select-article-hook)
7510       (when (and gnus-current-article
7511                  (not (zerop gnus-current-article)))
7512         (gnus-summary-goto-subject gnus-current-article))
7513       (gnus-summary-recenter)
7514       (when (and gnus-use-trees gnus-show-threads)
7515         (gnus-possibly-generate-tree article)
7516         (gnus-highlight-selected-tree article))
7517       ;; Successfully display article.
7518       (gnus-article-set-window-start
7519        (cdr (assq article gnus-newsgroup-bookmarks))))))
7520
7521 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7522   "Select the current article.
7523 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7524 non-nil, the article will be re-fetched even if it already present in
7525 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7526 be displayed."
7527   ;; Make sure we are in the summary buffer to work around bbdb bug.
7528   (unless (eq major-mode 'gnus-summary-mode)
7529     (set-buffer gnus-summary-buffer))
7530   (let ((article (or article (gnus-summary-article-number)))
7531         (all-headers (not (not all-headers))) ;Must be t or nil.
7532         gnus-summary-display-article-function)
7533     (and (not pseudo)
7534          (gnus-summary-article-pseudo-p article)
7535          (error "This is a pseudo-article"))
7536     (with-current-buffer gnus-summary-buffer
7537       (if (or (and gnus-single-article-buffer
7538                    (or (null gnus-current-article)
7539                        (null gnus-article-current)
7540                        (null (get-buffer gnus-article-buffer))
7541                        (not (eq article (cdr gnus-article-current)))
7542                        (not (equal (car gnus-article-current)
7543                                    gnus-newsgroup-name))))
7544               (and (not gnus-single-article-buffer)
7545                    (or (null gnus-current-article)
7546                        (not (eq gnus-current-article article))))
7547               force)
7548           ;; The requested article is different from the current article.
7549           (progn
7550             (gnus-summary-display-article article all-headers)
7551             (when (gnus-buffer-live-p gnus-article-buffer)
7552               (with-current-buffer gnus-article-buffer
7553                 (if (not gnus-article-decoded-p) ;; a local variable
7554                     (mm-disable-multibyte))))
7555             (gnus-article-set-window-start
7556              (cdr (assq article gnus-newsgroup-bookmarks)))
7557             article)
7558         'old))))
7559
7560 (defun gnus-summary-force-verify-and-decrypt ()
7561   "Display buttons for signed/encrypted parts and verify/decrypt them."
7562   (interactive)
7563   (let ((mm-verify-option 'known)
7564         (mm-decrypt-option 'known)
7565         (gnus-article-emulate-mime t)
7566         (gnus-buttonized-mime-types (append (list "multipart/signed"
7567                                                   "multipart/encrypted")
7568                                             gnus-buttonized-mime-types)))
7569     (gnus-summary-select-article nil 'force)))
7570
7571 (defun gnus-summary-set-current-mark (&optional current-mark)
7572   "Obsolete function."
7573   nil)
7574
7575 (defun gnus-summary-next-article (&optional unread subject backward push)
7576   "Select the next article.
7577 If UNREAD, only unread articles are selected.
7578 If SUBJECT, only articles with SUBJECT are selected.
7579 If BACKWARD, the previous article is selected instead of the next."
7580   (interactive "P")
7581   ;; Make sure we are in the summary buffer.
7582   (unless (eq major-mode 'gnus-summary-mode)
7583     (set-buffer gnus-summary-buffer))
7584   (cond
7585    ;; Is there such an article?
7586    ((and (gnus-summary-search-forward unread subject backward)
7587          (or (gnus-summary-display-article (gnus-summary-article-number))
7588              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7589     (gnus-summary-position-point))
7590    ;; If not, we try the first unread, if that is wanted.
7591    ((and subject
7592          gnus-auto-select-same
7593          (gnus-summary-first-unread-article))
7594     (gnus-summary-position-point)
7595     (gnus-message 6 "Wrapped"))
7596    ;; Try to get next/previous article not displayed in this group.
7597    ((and gnus-auto-extend-newsgroup
7598          (not unread) (not subject))
7599     (gnus-summary-goto-article
7600      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7601      nil (count-lines (point-min) (point))))
7602    ;; Go to next/previous group.
7603    (t
7604     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7605       (gnus-summary-jump-to-group gnus-newsgroup-name))
7606     (let ((cmd last-command-char)
7607           (point
7608            (with-current-buffer gnus-group-buffer
7609              (point)))
7610           (group
7611            (if (eq gnus-keep-same-level 'best)
7612                (gnus-summary-best-group gnus-newsgroup-name)
7613              (gnus-summary-search-group backward gnus-keep-same-level))))
7614       ;; For some reason, the group window gets selected.  We change
7615       ;; it back.
7616       (select-window (get-buffer-window (current-buffer)))
7617       ;; Select next unread newsgroup automagically.
7618       (cond
7619        ((or (not gnus-auto-select-next)
7620             (not cmd))
7621         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7622        ((or (eq gnus-auto-select-next 'quietly)
7623             (and (eq gnus-auto-select-next 'slightly-quietly)
7624                  push)
7625             (and (eq gnus-auto-select-next 'almost-quietly)
7626                  (gnus-summary-last-article-p)))
7627         ;; Select quietly.
7628         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7629             (gnus-summary-exit)
7630           (gnus-message 7 "No more%s articles (%s)..."
7631                         (if unread " unread" "")
7632                         (if group (concat "selecting " group)
7633                           "exiting"))
7634           (gnus-summary-next-group nil group backward)))
7635        (t
7636         (when (gnus-key-press-event-p last-input-event)
7637           (gnus-summary-walk-group-buffer
7638            gnus-newsgroup-name cmd unread backward point))))))))
7639
7640 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7641   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7642                       (?\C-p (gnus-group-prev-unread-group 1))))
7643         (cursor-in-echo-area t)
7644         keve key group ended prompt)
7645     (with-current-buffer gnus-group-buffer
7646       (goto-char start)
7647       (setq group
7648             (if (eq gnus-keep-same-level 'best)
7649                 (gnus-summary-best-group gnus-newsgroup-name)
7650               (gnus-summary-search-group backward gnus-keep-same-level))))
7651     (while (not ended)
7652       (setq prompt
7653             (format
7654              "No more%s articles%s " (if unread " unread" "")
7655              (if (and group
7656                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7657                  (format " (Type %s for %s [%s])"
7658                          (single-key-description cmd)
7659                          (gnus-group-decoded-name group)
7660                          (gnus-group-unread group))
7661                (format " (Type %s to exit %s)"
7662                        (single-key-description cmd)
7663                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7664       ;; Confirm auto selection.
7665       (setq key (car (setq keve (gnus-read-event-char prompt)))
7666             ended t)
7667       (cond
7668        ((assq key keystrokes)
7669         (let ((obuf (current-buffer)))
7670           (switch-to-buffer gnus-group-buffer)
7671           (when group
7672             (gnus-group-jump-to-group group))
7673           (eval (cadr (assq key keystrokes)))
7674           (setq group (gnus-group-group-name))
7675           (switch-to-buffer obuf))
7676         (setq ended nil))
7677        ((equal key cmd)
7678         (if (or (not group)
7679                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7680             (gnus-summary-exit)
7681           (gnus-summary-next-group nil group backward)))
7682        (t
7683         (push (cdr keve) unread-command-events))))))
7684
7685 (defun gnus-summary-next-unread-article ()
7686   "Select unread article after current one."
7687   (interactive)
7688   (gnus-summary-next-article
7689    (or (not (eq gnus-summary-goto-unread 'never))
7690        (gnus-summary-last-article-p (gnus-summary-article-number)))
7691    (and gnus-auto-select-same
7692         (gnus-summary-article-subject))))
7693
7694 (defun gnus-summary-prev-article (&optional unread subject)
7695   "Select the article before the current one.
7696 If UNREAD is non-nil, only unread articles are selected."
7697   (interactive "P")
7698   (gnus-summary-next-article unread subject t))
7699
7700 (defun gnus-summary-prev-unread-article ()
7701   "Select unread article before current one."
7702   (interactive)
7703   (gnus-summary-prev-article
7704    (or (not (eq gnus-summary-goto-unread 'never))
7705        (gnus-summary-first-article-p (gnus-summary-article-number)))
7706    (and gnus-auto-select-same
7707         (gnus-summary-article-subject))))
7708
7709 (defun gnus-summary-next-page (&optional lines circular stop)
7710   "Show next page of the selected article.
7711 If at the end of the current article, select the next article.
7712 LINES says how many lines should be scrolled up.
7713
7714 If CIRCULAR is non-nil, go to the start of the article instead of
7715 selecting the next article when reaching the end of the current
7716 article.
7717
7718 If STOP is non-nil, just stop when reaching the end of the message.
7719
7720 Also see the variable `gnus-article-skip-boring'."
7721   (interactive "P")
7722   (setq gnus-summary-buffer (current-buffer))
7723   (gnus-set-global-variables)
7724   (let ((article (gnus-summary-article-number))
7725         (article-window (get-buffer-window gnus-article-buffer t))
7726         endp)
7727     ;; If the buffer is empty, we have no article.
7728     (unless article
7729       (error "No article to select"))
7730     (gnus-configure-windows 'article)
7731     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7732         (if (and (eq gnus-summary-goto-unread 'never)
7733                  (not (gnus-summary-last-article-p article)))
7734             (gnus-summary-next-article)
7735           (gnus-summary-next-unread-article))
7736       (if (or (null gnus-current-article)
7737               (null gnus-article-current)
7738               (/= article (cdr gnus-article-current))
7739               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7740           ;; Selected subject is different from current article's.
7741           (gnus-summary-display-article article)
7742         (when article-window
7743           (gnus-eval-in-buffer-window gnus-article-buffer
7744             (setq endp (or (gnus-article-next-page lines)
7745                            (gnus-article-only-boring-p))))
7746           (when endp
7747             (cond (stop
7748                    (gnus-message 3 "End of message"))
7749                   (circular
7750                    (gnus-summary-beginning-of-article))
7751                   (lines
7752                    (gnus-message 3 "End of message"))
7753                   ((null lines)
7754                    (if (and (eq gnus-summary-goto-unread 'never)
7755                             (not (gnus-summary-last-article-p article)))
7756                        (gnus-summary-next-article)
7757                      (gnus-summary-next-unread-article))))))))
7758     (gnus-summary-recenter)
7759     (gnus-summary-position-point)))
7760
7761 (defun gnus-summary-prev-page (&optional lines move)
7762   "Show previous page of selected article.
7763 Argument LINES specifies lines to be scrolled down.
7764 If MOVE, move to the previous unread article if point is at
7765 the beginning of the buffer."
7766   (interactive "P")
7767   (let ((article (gnus-summary-article-number))
7768         (article-window (get-buffer-window gnus-article-buffer t))
7769         endp)
7770     (gnus-configure-windows 'article)
7771     (if (or (null gnus-current-article)
7772             (null gnus-article-current)
7773             (/= article (cdr gnus-article-current))
7774             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7775         ;; Selected subject is different from current article's.
7776         (gnus-summary-display-article article)
7777       (gnus-summary-recenter)
7778       (when article-window
7779         (gnus-eval-in-buffer-window gnus-article-buffer
7780           (setq endp (gnus-article-prev-page lines)))
7781         (when (and move endp)
7782           (cond (lines
7783                  (gnus-message 3 "Beginning of message"))
7784                 ((null lines)
7785                  (if (and (eq gnus-summary-goto-unread 'never)
7786                           (not (gnus-summary-first-article-p article)))
7787                      (gnus-summary-prev-article)
7788                    (gnus-summary-prev-unread-article))))))))
7789   (gnus-summary-position-point))
7790
7791 (defun gnus-summary-prev-page-or-article (&optional lines)
7792   "Show previous page of selected article.
7793 Argument LINES specifies lines to be scrolled down.
7794 If at the beginning of the article, go to the next article."
7795   (interactive "P")
7796   (gnus-summary-prev-page lines t))
7797
7798 (defun gnus-summary-scroll-up (lines)
7799   "Scroll up (or down) one line current article.
7800 Argument LINES specifies lines to be scrolled up (or down if negative)."
7801   (interactive "p")
7802   (gnus-configure-windows 'article)
7803   (gnus-summary-show-thread)
7804   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7805     (gnus-eval-in-buffer-window gnus-article-buffer
7806       (cond ((> lines 0)
7807              (when (gnus-article-next-page lines)
7808                (gnus-message 3 "End of message")))
7809             ((< lines 0)
7810              (gnus-article-prev-page (- lines))))))
7811   (gnus-summary-recenter)
7812   (gnus-summary-position-point))
7813
7814 (defun gnus-summary-scroll-down (lines)
7815   "Scroll down (or up) one line current article.
7816 Argument LINES specifies lines to be scrolled down (or up if negative)."
7817   (interactive "p")
7818   (gnus-summary-scroll-up (- lines)))
7819
7820 (defun gnus-summary-next-same-subject ()
7821   "Select next article which has the same subject as current one."
7822   (interactive)
7823   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7824
7825 (defun gnus-summary-prev-same-subject ()
7826   "Select previous article which has the same subject as current one."
7827   (interactive)
7828   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7829
7830 (defun gnus-summary-next-unread-same-subject ()
7831   "Select next unread article which has the same subject as current one."
7832   (interactive)
7833   (gnus-summary-next-article t (gnus-summary-article-subject)))
7834
7835 (defun gnus-summary-prev-unread-same-subject ()
7836   "Select previous unread article which has the same subject as current one."
7837   (interactive)
7838   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7839
7840 (defun gnus-summary-first-unread-article ()
7841   "Select the first unread article.
7842 Return nil if there are no unread articles."
7843   (interactive)
7844   (prog1
7845       (when (gnus-summary-first-subject t)
7846         (gnus-summary-show-thread)
7847         (gnus-summary-first-subject t)
7848         (gnus-summary-display-article (gnus-summary-article-number)))
7849     (gnus-summary-position-point)))
7850
7851 (defun gnus-summary-first-unread-subject ()
7852   "Place the point on the subject line of the first unread article.
7853 Return nil if there are no unread articles."
7854   (interactive)
7855   (prog1
7856       (when (gnus-summary-first-subject t)
7857         (gnus-summary-show-thread)
7858         (gnus-summary-first-subject t))
7859     (gnus-summary-position-point)))
7860
7861 (defun gnus-summary-first-unseen-subject ()
7862   "Place the point on the subject line of the first unseen article.
7863 Return nil if there are no unseen articles."
7864   (interactive)
7865   (prog1
7866       (when (gnus-summary-first-subject nil nil t)
7867         (gnus-summary-show-thread)
7868         (gnus-summary-first-subject nil nil t))
7869     (gnus-summary-position-point)))
7870
7871 (defun gnus-summary-first-unseen-or-unread-subject ()
7872   "Place the point on the subject line of the first unseen article or,
7873 if all article have been seen, on the subject line of the first unread
7874 article."
7875   (interactive)
7876   (prog1
7877       (unless (when (gnus-summary-first-subject nil nil t)
7878                 (gnus-summary-show-thread)
7879                 (gnus-summary-first-subject nil nil t))
7880         (when (gnus-summary-first-subject t)
7881           (gnus-summary-show-thread)
7882           (gnus-summary-first-subject t)))
7883     (gnus-summary-position-point)))
7884
7885 (defun gnus-summary-first-article ()
7886   "Select the first article.
7887 Return nil if there are no articles."
7888   (interactive)
7889   (prog1
7890       (when (gnus-summary-first-subject)
7891         (gnus-summary-show-thread)
7892         (gnus-summary-first-subject)
7893         (gnus-summary-display-article (gnus-summary-article-number)))
7894     (gnus-summary-position-point)))
7895
7896 (defun gnus-summary-best-unread-article (&optional arg)
7897   "Select the unread article with the highest score.
7898 If given a prefix argument, select the next unread article that has a
7899 score higher than the default score."
7900   (interactive "P")
7901   (let ((article (if arg
7902                      (gnus-summary-better-unread-subject)
7903                    (gnus-summary-best-unread-subject))))
7904     (if article
7905         (gnus-summary-goto-article article)
7906       (error "No unread articles"))))
7907
7908 (defun gnus-summary-best-unread-subject ()
7909   "Select the unread subject with the highest score."
7910   (interactive)
7911   (let ((best -1000000)
7912         (data gnus-newsgroup-data)
7913         article score)
7914     (while data
7915       (and (gnus-data-unread-p (car data))
7916            (> (setq score
7917                     (gnus-summary-article-score (gnus-data-number (car data))))
7918               best)
7919            (setq best score
7920                  article (gnus-data-number (car data))))
7921       (setq data (cdr data)))
7922     (when article
7923       (gnus-summary-goto-subject article))
7924     (gnus-summary-position-point)
7925     article))
7926
7927 (defun gnus-summary-better-unread-subject ()
7928   "Select the first unread subject that has a score over the default score."
7929   (interactive)
7930   (let ((data gnus-newsgroup-data)
7931         article score)
7932     (while (and (setq article (gnus-data-number (car data)))
7933                 (or (gnus-data-read-p (car data))
7934                     (not (> (gnus-summary-article-score article)
7935                             gnus-summary-default-score))))
7936       (setq data (cdr data)))
7937     (when article
7938       (gnus-summary-goto-subject article))
7939     (gnus-summary-position-point)
7940     article))
7941
7942 (defun gnus-summary-last-subject ()
7943   "Go to the last displayed subject line in the group."
7944   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7945     (when article
7946       (gnus-summary-goto-subject article))))
7947
7948 (defun gnus-summary-goto-article (article &optional all-headers force)
7949   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7950 If ALL-HEADERS is non-nil, no header lines are hidden.
7951 If FORCE, go to the article even if it isn't displayed.  If FORCE
7952 is a number, it is the line the article is to be displayed on."
7953   (interactive
7954    (list
7955     (completing-read
7956      "Article number or Message-ID: "
7957      (mapcar (lambda (number) (list (int-to-string number)))
7958              gnus-newsgroup-limit))
7959     current-prefix-arg
7960     t))
7961   (prog1
7962       (if (and (stringp article)
7963                (string-match "@\\|%40" article))
7964           (gnus-summary-refer-article article)
7965         (when (stringp article)
7966           (setq article (string-to-number article)))
7967         (if (gnus-summary-goto-subject article force)
7968             (gnus-summary-display-article article all-headers)
7969           (gnus-message 4 "Couldn't go to article %s" article) nil))
7970     (gnus-summary-position-point)))
7971
7972 (defun gnus-summary-goto-last-article ()
7973   "Go to the previously read article."
7974   (interactive)
7975   (prog1
7976       (when gnus-last-article
7977         (gnus-summary-goto-article gnus-last-article nil t))
7978     (gnus-summary-position-point)))
7979
7980 (defun gnus-summary-pop-article (number)
7981   "Pop one article off the history and go to the previous.
7982 NUMBER articles will be popped off."
7983   (interactive "p")
7984   (let (to)
7985     (setq gnus-newsgroup-history
7986           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7987     (if to
7988         (gnus-summary-goto-article (car to) nil t)
7989       (error "Article history empty")))
7990   (gnus-summary-position-point))
7991
7992 ;; Summary commands and functions for limiting the summary buffer.
7993
7994 (defun gnus-summary-limit-to-articles (n)
7995   "Limit the summary buffer to the next N articles.
7996 If not given a prefix, use the process marked articles instead."
7997   (interactive "P")
7998   (prog1
7999       (let ((articles (gnus-summary-work-articles n)))
8000         (setq gnus-newsgroup-processable nil)
8001         (gnus-summary-limit articles))
8002     (gnus-summary-position-point)))
8003
8004 (defun gnus-summary-pop-limit (&optional total)
8005   "Restore the previous limit.
8006 If given a prefix, remove all limits."
8007   (interactive "P")
8008   (when total
8009     (setq gnus-newsgroup-limits
8010           (list (mapcar (lambda (h) (mail-header-number h))
8011                         gnus-newsgroup-headers))))
8012   (unless gnus-newsgroup-limits
8013     (error "No limit to pop"))
8014   (prog1
8015       (gnus-summary-limit nil 'pop)
8016     (gnus-summary-position-point)))
8017
8018 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
8019   "Limit the summary buffer to articles that have subjects that match a regexp.
8020 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
8021   (interactive
8022    (list (read-string (if current-prefix-arg
8023                           "Exclude subject (regexp): "
8024                         "Limit to subject (regexp): "))
8025          nil current-prefix-arg))
8026   (unless header
8027     (setq header "subject"))
8028   (when (not (equal "" subject))
8029     (prog1
8030         (let ((articles (gnus-summary-find-matching
8031                          (or header "subject") subject 'all nil nil
8032                          not-matching)))
8033           (unless articles
8034             (error "Found no matches for \"%s\"" subject))
8035           (gnus-summary-limit articles))
8036       (gnus-summary-position-point))))
8037
8038 (defun gnus-summary-limit-to-author (from &optional not-matching)
8039   "Limit the summary buffer to articles that have authors that match a regexp.
8040 If NOT-MATCHING, excluding articles that have authors that match a regexp."
8041   (interactive
8042    (list (read-string (if current-prefix-arg
8043                           "Exclude author (regexp): "
8044                         "Limit to author (regexp): "))
8045          current-prefix-arg))
8046   (gnus-summary-limit-to-subject from "from" not-matching))
8047
8048 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8049   "Limit the summary buffer to articles with the given RECIPIENT.
8050
8051 If NOT-MATCHING, exclude RECIPIENT.
8052
8053 To and Cc headers are checked.  You need to include them in
8054 `nnmail-extra-headers'."
8055   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8056   (interactive
8057    (list (read-string (format "%s recipient (regexp): "
8058                               (if current-prefix-arg "Exclude" "Limit to")))
8059          current-prefix-arg))
8060   (when (not (equal "" recipient))
8061     (prog1 (let* ((to
8062                    (if (memq 'To nnmail-extra-headers)
8063                        (gnus-summary-find-matching
8064                         (cons 'extra 'To) recipient 'all nil nil
8065                         not-matching)
8066                      (gnus-message
8067                       1 "`To' isn't present in `nnmail-extra-headers'")
8068                      (sit-for 1)
8069                      nil))
8070                   (cc
8071                    (if (memq 'Cc nnmail-extra-headers)
8072                        (gnus-summary-find-matching
8073                         (cons 'extra 'Cc) recipient 'all nil nil
8074                         not-matching)
8075                      (gnus-message
8076                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8077                      (sit-for 1)
8078                      nil))
8079                   (articles
8080                    (if not-matching
8081                        ;; We need the numbers that are in both lists:
8082                        (mapcar (lambda (a)
8083                                  (and (memq a to) a))
8084                                cc)
8085                      (nconc to cc))))
8086              (unless articles
8087                (error "Found no matches for \"%s\"" recipient))
8088              (gnus-summary-limit articles))
8089       (gnus-summary-position-point))))
8090
8091 (defun gnus-summary-limit-to-address (address &optional not-matching)
8092   "Limit the summary buffer to articles with the given ADDRESS.
8093
8094 If NOT-MATCHING, exclude ADDRESS.
8095
8096 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8097 in `nnmail-extra-headers'."
8098   (interactive
8099    (list (read-string (format "%s address (regexp): "
8100                               (if current-prefix-arg "Exclude" "Limit to")))
8101          current-prefix-arg))
8102   (when (not (equal "" address))
8103     (prog1 (let* ((to
8104                    (if (memq 'To nnmail-extra-headers)
8105                        (gnus-summary-find-matching
8106                         (cons 'extra 'To) address 'all nil nil
8107                         not-matching)
8108                      (gnus-message
8109                       1 "`To' isn't present in `nnmail-extra-headers'")
8110                      (sit-for 1)
8111                      t))
8112                   (cc
8113                    (if (memq 'Cc nnmail-extra-headers)
8114                        (gnus-summary-find-matching
8115                         (cons 'extra 'Cc) address 'all nil nil
8116                         not-matching)
8117                      (gnus-message
8118                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8119                      (sit-for 1)
8120                      t))
8121                   (from
8122                    (gnus-summary-find-matching "from" address
8123                                                'all nil nil not-matching))
8124                   (articles
8125                    (if not-matching
8126                        ;; We need the numbers that are in all lists:
8127                        (if (eq cc t)
8128                            (if (eq to t)
8129                                from
8130                              (mapcar (lambda (a) (car (memq a from))) to))
8131                          (if (eq to t)
8132                              (mapcar (lambda (a) (car (memq a from))) cc)
8133                            (mapcar (lambda (a) (car (memq a from)))
8134                                    (mapcar (lambda (a) (car (memq a to)))
8135                                            cc))))
8136                      (nconc (if (eq to t) nil to)
8137                             (if (eq cc t) nil cc)
8138                             from))))
8139              (unless articles
8140                (error "Found no matches for \"%s\"" address))
8141              (gnus-summary-limit articles))
8142       (gnus-summary-position-point))))
8143
8144 (defun gnus-summary-limit-strange-charsets-predicate (header)
8145   (let ((string (concat (mail-header-subject header)
8146                         (mail-header-from header)))
8147         charset found)
8148     (dotimes (i (1- (length string)))
8149       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8150       (when (string-match "unicode\\|big\\|japanese" charset)
8151         (setq found t)))
8152     found))
8153
8154 (defun gnus-summary-limit-to-predicate (predicate)
8155   "Limit to articles where PREDICATE returns non-nil.
8156 PREDICATE will be called with the header structures of the
8157 articles."
8158   (let ((articles nil)
8159         (case-fold-search t))
8160     (dolist (header gnus-newsgroup-headers)
8161       (when (funcall predicate header)
8162         (push (mail-header-number header) articles)))
8163     (gnus-summary-limit (nreverse articles))))
8164
8165 (defun gnus-summary-limit-to-age (age &optional younger-p)
8166   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8167 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8168 articles that are younger than AGE days."
8169   (interactive
8170    (let ((younger current-prefix-arg)
8171          (days-got nil)
8172          days)
8173      (while (not days-got)
8174        (setq days (if younger
8175                       (read-string "Limit to articles younger than (in days, older when negative): ")
8176                     (read-string
8177                      "Limit to articles older than (in days, younger when negative): ")))
8178        (when (> (length days) 0)
8179          (setq days (read days)))
8180        (if (numberp days)
8181            (progn
8182              (setq days-got t)
8183              (when (< days 0)
8184                (setq younger (not younger))
8185                (setq days (* days -1))))
8186          (message "Please enter a number.")
8187          (sleep-for 1)))
8188      (list days younger)))
8189   (prog1
8190       (let ((data gnus-newsgroup-data)
8191             (cutoff (days-to-time age))
8192             articles d date is-younger)
8193         (while (setq d (pop data))
8194           (when (and (vectorp (gnus-data-header d))
8195                      (setq date (mail-header-date (gnus-data-header d))))
8196             (setq is-younger (time-less-p
8197                               (time-since (condition-case ()
8198                                               (date-to-time date)
8199                                             (error '(0 0))))
8200                               cutoff))
8201             (when (if younger-p
8202                       is-younger
8203                     (not is-younger))
8204               (push (gnus-data-number d) articles))))
8205         (gnus-summary-limit (nreverse articles)))
8206     (gnus-summary-position-point)))
8207
8208 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8209   "Limit the summary buffer to articles that match an 'extra' header."
8210   (interactive
8211    (let ((header
8212           (intern
8213            (gnus-completing-read-with-default
8214             (symbol-name (car gnus-extra-headers))
8215             (if current-prefix-arg
8216                 "Exclude extra header"
8217               "Limit extra header")
8218             (mapcar (lambda (x)
8219                       (cons (symbol-name x) x))
8220                     gnus-extra-headers)
8221             nil
8222             t))))
8223      (list header
8224            (read-string (format "%s header %s (regexp): "
8225                                 (if current-prefix-arg "Exclude" "Limit to")
8226                                 header))
8227            current-prefix-arg)))
8228   (when (not (equal "" regexp))
8229     (prog1
8230         (let ((articles (gnus-summary-find-matching
8231                          (cons 'extra header) regexp 'all nil nil
8232                          not-matching)))
8233           (unless articles
8234             (error "Found no matches for \"%s\"" regexp))
8235           (gnus-summary-limit articles))
8236       (gnus-summary-position-point))))
8237
8238 (defun gnus-summary-limit-to-display-predicate ()
8239   "Limit the summary buffer to the predicated in the `display' group parameter."
8240   (interactive)
8241   (unless gnus-newsgroup-display
8242     (error "There is no `display' group parameter"))
8243   (let (articles)
8244     (dolist (number gnus-newsgroup-articles)
8245       (when (funcall gnus-newsgroup-display)
8246         (push number articles)))
8247     (gnus-summary-limit articles))
8248   (gnus-summary-position-point))
8249
8250 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8251 (make-obsolete
8252  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8253
8254 (defun gnus-summary-limit-to-unread (&optional all)
8255   "Limit the summary buffer to articles that are not marked as read.
8256 If ALL is non-nil, limit strictly to unread articles."
8257   (interactive "P")
8258   (if all
8259       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8260     (gnus-summary-limit-to-marks
8261      ;; Concat all the marks that say that an article is read and have
8262      ;; those removed.
8263      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8264            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8265            gnus-low-score-mark gnus-expirable-mark
8266            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8267            gnus-duplicate-mark gnus-souped-mark)
8268      'reverse)))
8269
8270 (defun gnus-summary-limit-to-headers (match &optional reverse)
8271   "Limit the summary buffer to articles that have headers that match MATCH.
8272 If REVERSE (the prefix), limit to articles that don't match."
8273   (interactive "sMatch headers (regexp): \nP")
8274   (gnus-summary-limit-to-bodies match reverse t))
8275
8276 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8277   "Limit the summary buffer to articles that have bodies that match MATCH.
8278 If REVERSE (the prefix), limit to articles that don't match."
8279   (interactive "sMatch body (regexp): \nP")
8280   (let ((articles nil)
8281         (gnus-select-article-hook nil)  ;Disable hook.
8282         (gnus-article-prepare-hook nil)
8283         (gnus-use-article-prefetch nil)
8284         (gnus-keep-backlog nil)
8285         (gnus-break-pages nil)
8286         (gnus-summary-display-arrow nil)
8287         (gnus-updated-mode-lines nil)
8288         (gnus-auto-center-summary nil)
8289         (gnus-display-mime-function nil))
8290     (dolist (data gnus-newsgroup-data)
8291       (let (gnus-mark-article-hook)
8292         (gnus-summary-select-article t t nil (gnus-data-number data)))
8293       (save-excursion
8294         (set-buffer gnus-article-buffer)
8295         (article-goto-body)
8296         (let* ((case-fold-search t)
8297                (found (if headersp
8298                           (re-search-backward match nil t)
8299                         (re-search-forward match nil t))))
8300           (when (or (and found
8301                          (not reverse))
8302                     (and (not found)
8303                          reverse))
8304             (push (gnus-data-number data) articles)))))
8305     (if (not articles)
8306         (message "No messages matched")
8307       (gnus-summary-limit articles)))
8308   (gnus-summary-position-point))
8309
8310 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8311   "Limit the summary buffer to articles that aren't part on any thread.
8312 If THREADSP (the prefix), limit to articles that are in threads."
8313   (interactive "P")
8314   (let ((articles nil)
8315         thread-articles
8316         threads)
8317     (dolist (thread gnus-newsgroup-threads)
8318       (if (stringp (car thread))
8319           (dolist (thread (cdr thread))
8320             (push thread threads))
8321         (push thread threads)))
8322     (dolist (thread threads)
8323       (setq thread-articles (gnus-articles-in-thread thread))
8324       (when (or (and threadsp
8325                      (> (length thread-articles) 1))
8326                 (and (not threadsp)
8327                      (= (length thread-articles) 1)))
8328         (setq articles (nconc thread-articles articles))))
8329     (if (not articles)
8330         (message "No messages matched")
8331       (gnus-summary-limit articles))
8332     (gnus-summary-position-point)))
8333
8334 (defun gnus-summary-limit-to-replied (&optional unreplied)
8335   "Limit the summary buffer to replied articles.
8336 If UNREPLIED (the prefix), limit to unreplied articles."
8337   (interactive "P")
8338   (if unreplied
8339       (gnus-summary-limit
8340        (gnus-set-difference gnus-newsgroup-articles
8341         gnus-newsgroup-replied))
8342     (gnus-summary-limit gnus-newsgroup-replied))
8343   (gnus-summary-position-point))
8344
8345 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8346 (make-obsolete 'gnus-summary-delete-marked-with
8347                'gnus-summary-limit-exclude-marks)
8348
8349 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8350   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8351 If REVERSE, limit the summary buffer to articles that are marked
8352 with MARKS.  MARKS can either be a string of marks or a list of marks.
8353 Returns how many articles were removed."
8354   (interactive "sMarks: ")
8355   (gnus-summary-limit-to-marks marks t))
8356
8357 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8358   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8359 If REVERSE (the prefix), limit the summary buffer to articles that are
8360 not marked with MARKS.  MARKS can either be a string of marks or a
8361 list of marks.
8362 Returns how many articles were removed."
8363   (interactive "sMarks: \nP")
8364   (prog1
8365       (let ((data gnus-newsgroup-data)
8366             (marks (if (listp marks) marks
8367                      (append marks nil))) ; Transform to list.
8368             articles)
8369         (while data
8370           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8371                   (memq (gnus-data-mark (car data)) marks))
8372             (push (gnus-data-number (car data)) articles))
8373           (setq data (cdr data)))
8374         (gnus-summary-limit articles))
8375     (gnus-summary-position-point)))
8376
8377 (defun gnus-summary-limit-to-score (score)
8378   "Limit to articles with score at or above SCORE."
8379   (interactive "NLimit to articles with score of at least: ")
8380   (let ((data gnus-newsgroup-data)
8381         articles)
8382     (while data
8383       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8384                 score)
8385         (push (gnus-data-number (car data)) articles))
8386       (setq data (cdr data)))
8387     (prog1
8388         (gnus-summary-limit articles)
8389       (gnus-summary-position-point))))
8390
8391 (defun gnus-summary-limit-to-unseen ()
8392   "Limit to unseen articles."
8393   (interactive)
8394   (prog1
8395       (gnus-summary-limit gnus-newsgroup-unseen)
8396     (gnus-summary-position-point)))
8397
8398 (defun gnus-summary-limit-include-thread (id)
8399   "Display all the hidden articles that is in the thread with ID in it.
8400 When called interactively, ID is the Message-ID of the current
8401 article."
8402   (interactive (list (mail-header-id (gnus-summary-article-header))))
8403   (let ((articles (gnus-articles-in-thread
8404                    (gnus-id-to-thread (gnus-root-id id)))))
8405     (prog1
8406         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8407       (gnus-summary-limit-include-matching-articles
8408        "subject"
8409        (regexp-quote (gnus-simplify-subject-re
8410                       (mail-header-subject (gnus-id-to-header id)))))
8411       (gnus-summary-position-point))))
8412
8413 (defun gnus-summary-limit-include-matching-articles (header regexp)
8414   "Display all the hidden articles that have HEADERs that match REGEXP."
8415   (interactive (list (read-string "Match on header: ")
8416                      (read-string "Regexp: ")))
8417   (let ((articles (gnus-find-matching-articles header regexp)))
8418     (prog1
8419         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8420       (gnus-summary-position-point))))
8421
8422 (defun gnus-summary-insert-dormant-articles ()
8423   "Insert all the dormant articles for this group into the current buffer."
8424   (interactive)
8425   (let ((gnus-verbose (max 6 gnus-verbose)))
8426     (if (not gnus-newsgroup-dormant)
8427         (gnus-message 3 "No dormant articles for this group")
8428       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8429
8430 (defun gnus-summary-insert-ticked-articles ()
8431   "Insert ticked articles for this group into the current buffer."
8432   (interactive)
8433   (let ((gnus-verbose (max 6 gnus-verbose)))
8434     (if (not gnus-newsgroup-marked)
8435         (gnus-message 3 "No ticked articles for this group")
8436       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8437
8438 (defun gnus-summary-limit-include-dormant ()
8439   "Display all the hidden articles that are marked as dormant.
8440 Note that this command only works on a subset of the articles currently
8441 fetched for this group."
8442   (interactive)
8443   (unless gnus-newsgroup-dormant
8444     (error "There are no dormant articles in this group"))
8445   (prog1
8446       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8447     (gnus-summary-position-point)))
8448
8449 (defun gnus-summary-limit-exclude-dormant ()
8450   "Hide all dormant articles."
8451   (interactive)
8452   (prog1
8453       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8454     (gnus-summary-position-point)))
8455
8456 (defun gnus-summary-limit-exclude-childless-dormant ()
8457   "Hide all dormant articles that have no children."
8458   (interactive)
8459   (let ((data (gnus-data-list t))
8460         articles d children)
8461     ;; Find all articles that are either not dormant or have
8462     ;; children.
8463     (while (setq d (pop data))
8464       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8465                 (and (setq children
8466                            (gnus-article-children (gnus-data-number d)))
8467                      (let (found)
8468                        (while children
8469                          (when (memq (car children) articles)
8470                            (setq children nil
8471                                  found t))
8472                          (pop children))
8473                        found)))
8474         (push (gnus-data-number d) articles)))
8475     ;; Do the limiting.
8476     (prog1
8477         (gnus-summary-limit articles)
8478       (gnus-summary-position-point))))
8479
8480 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8481   "Mark all unread excluded articles as read.
8482 If ALL, mark even excluded ticked and dormants as read."
8483   (interactive "P")
8484   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8485   (let ((articles (gnus-sorted-ndifference
8486                    (sort
8487                     (mapcar (lambda (h) (mail-header-number h))
8488                             gnus-newsgroup-headers)
8489                     '<)
8490                    gnus-newsgroup-limit))
8491         article)
8492     (setq gnus-newsgroup-unreads
8493           (gnus-sorted-intersection gnus-newsgroup-unreads
8494                                     gnus-newsgroup-limit))
8495     (if all
8496         (setq gnus-newsgroup-dormant nil
8497               gnus-newsgroup-marked nil
8498               gnus-newsgroup-reads
8499               (nconc
8500                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8501                gnus-newsgroup-reads))
8502       (while (setq article (pop articles))
8503         (unless (or (memq article gnus-newsgroup-dormant)
8504                     (memq article gnus-newsgroup-marked))
8505           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8506
8507 (defun gnus-summary-limit (articles &optional pop)
8508   (if pop
8509       ;; We pop the previous limit off the stack and use that.
8510       (setq articles (car gnus-newsgroup-limits)
8511             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8512     ;; We use the new limit, so we push the old limit on the stack.
8513     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8514   ;; Set the limit.
8515   (setq gnus-newsgroup-limit articles)
8516   (let ((total (length gnus-newsgroup-data))
8517         (data (gnus-data-find-list (gnus-summary-article-number)))
8518         (gnus-summary-mark-below nil)   ; Inhibit this.
8519         found)
8520     ;; This will do all the work of generating the new summary buffer
8521     ;; according to the new limit.
8522     (gnus-summary-prepare)
8523     ;; Hide any threads, possibly.
8524     (gnus-summary-maybe-hide-threads)
8525     ;; Try to return to the article you were at, or one in the
8526     ;; neighborhood.
8527     (when data
8528       ;; We try to find some article after the current one.
8529       (while data
8530         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8531           (setq data nil
8532                 found t))
8533         (setq data (cdr data))))
8534     (unless found
8535       ;; If there is no data, that means that we were after the last
8536       ;; article.  The same goes when we can't find any articles
8537       ;; after the current one.
8538       (goto-char (point-max))
8539       (gnus-summary-find-prev))
8540     (gnus-set-mode-line 'summary)
8541     ;; We return how many articles were removed from the summary
8542     ;; buffer as a result of the new limit.
8543     (- total (length gnus-newsgroup-data))))
8544
8545 (defsubst gnus-invisible-cut-children (threads)
8546   (let ((num 0))
8547     (while threads
8548       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8549         (incf num))
8550       (pop threads))
8551     (< num 2)))
8552
8553 (defsubst gnus-cut-thread (thread)
8554   "Go forwards in the thread until we find an article that we want to display."
8555   (when (or (eq gnus-fetch-old-headers 'some)
8556             (eq gnus-fetch-old-headers 'invisible)
8557             (numberp gnus-fetch-old-headers)
8558             (eq gnus-build-sparse-threads 'some)
8559             (eq gnus-build-sparse-threads 'more))
8560     ;; Deal with old-fetched headers and sparse threads.
8561     (while (and
8562             thread
8563             (or
8564              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8565              (gnus-summary-article-ancient-p
8566               (mail-header-number (car thread))))
8567             (if (or (<= (length (cdr thread)) 1)
8568                     (eq gnus-fetch-old-headers 'invisible))
8569                 (setq gnus-newsgroup-limit
8570                       (delq (mail-header-number (car thread))
8571                             gnus-newsgroup-limit)
8572                       thread (cadr thread))
8573               (when (gnus-invisible-cut-children (cdr thread))
8574                 (let ((th (cdr thread)))
8575                   (while th
8576                     (if (memq (mail-header-number (caar th))
8577                               gnus-newsgroup-limit)
8578                         (setq thread (car th)
8579                               th nil)
8580                       (setq th (cdr th))))))))))
8581   thread)
8582
8583 (defun gnus-cut-threads (threads)
8584   "Cut off all uninteresting articles from the beginning of THREADS."
8585   (when (or (eq gnus-fetch-old-headers 'some)
8586             (eq gnus-fetch-old-headers 'invisible)
8587             (numberp gnus-fetch-old-headers)
8588             (eq gnus-build-sparse-threads 'some)
8589             (eq gnus-build-sparse-threads 'more))
8590     (let ((th threads))
8591       (while th
8592         (setcar th (gnus-cut-thread (car th)))
8593         (setq th (cdr th)))))
8594   ;; Remove nixed out threads.
8595   (delq nil threads))
8596
8597 (defun gnus-summary-initial-limit (&optional show-if-empty)
8598   "Figure out what the initial limit is supposed to be on group entry.
8599 This entails weeding out unwanted dormants, low-scored articles,
8600 fetch-old-headers verbiage, and so on."
8601   ;; Most groups have nothing to remove.
8602   (unless (or gnus-inhibit-limiting
8603               (and (null gnus-newsgroup-dormant)
8604                    (eq gnus-newsgroup-display 'gnus-not-ignore)
8605                    (not (eq gnus-fetch-old-headers 'some))
8606                    (not (numberp gnus-fetch-old-headers))
8607                    (not (eq gnus-fetch-old-headers 'invisible))
8608                    (null gnus-summary-expunge-below)
8609                    (not (eq gnus-build-sparse-threads 'some))
8610                    (not (eq gnus-build-sparse-threads 'more))
8611                    (null gnus-thread-expunge-below)
8612                    (not gnus-use-nocem)))
8613     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8614     (setq gnus-newsgroup-limit nil)
8615     (mapatoms
8616      (lambda (node)
8617        (unless (car (symbol-value node))
8618          ;; These threads have no parents -- they are roots.
8619          (let ((nodes (cdr (symbol-value node)))
8620                thread)
8621            (while nodes
8622              (if (and gnus-thread-expunge-below
8623                       (< (gnus-thread-total-score (car nodes))
8624                          gnus-thread-expunge-below))
8625                  (gnus-expunge-thread (pop nodes))
8626                (setq thread (pop nodes))
8627                (gnus-summary-limit-children thread))))))
8628      gnus-newsgroup-dependencies)
8629     ;; If this limitation resulted in an empty group, we might
8630     ;; pop the previous limit and use it instead.
8631     (when (and (not gnus-newsgroup-limit)
8632                show-if-empty)
8633       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8634     gnus-newsgroup-limit))
8635
8636 (defun gnus-summary-limit-children (thread)
8637   "Return 1 if this subthread is visible and 0 if it is not."
8638   ;; First we get the number of visible children to this thread.  This
8639   ;; is done by recursing down the thread using this function, so this
8640   ;; will really go down to a leaf article first, before slowly
8641   ;; working its way up towards the root.
8642   (when thread
8643     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8644            (children
8645            (if (cdr thread)
8646                (apply '+ (mapcar 'gnus-summary-limit-children
8647                                  (cdr thread)))
8648              0))
8649           (number (mail-header-number (car thread)))
8650           score)
8651       (if (and
8652            (not (memq number gnus-newsgroup-marked))
8653            (or
8654             ;; If this article is dormant and has absolutely no visible
8655             ;; children, then this article isn't visible.
8656             (and (memq number gnus-newsgroup-dormant)
8657                  (zerop children))
8658             ;; If this is "fetch-old-headered" and there is no
8659             ;; visible children, then we don't want this article.
8660             (and (or (eq gnus-fetch-old-headers 'some)
8661                      (numberp gnus-fetch-old-headers))
8662                  (gnus-summary-article-ancient-p number)
8663                  (zerop children))
8664             ;; If this is "fetch-old-headered" and `invisible', then
8665             ;; we don't want this article.
8666             (and (eq gnus-fetch-old-headers 'invisible)
8667                  (gnus-summary-article-ancient-p number))
8668             ;; If this is a sparsely inserted article with no children,
8669             ;; we don't want it.
8670             (and (eq gnus-build-sparse-threads 'some)
8671                  (gnus-summary-article-sparse-p number)
8672                  (zerop children))
8673             ;; If we use expunging, and this article is really
8674             ;; low-scored, then we don't want this article.
8675             (when (and gnus-summary-expunge-below
8676                        (< (setq score
8677                                 (or (cdr (assq number gnus-newsgroup-scored))
8678                                     gnus-summary-default-score))
8679                           gnus-summary-expunge-below))
8680               ;; We increase the expunge-tally here, but that has
8681               ;; nothing to do with the limits, really.
8682               (incf gnus-newsgroup-expunged-tally)
8683               ;; We also mark as read here, if that's wanted.
8684               (when (and gnus-summary-mark-below
8685                          (< score gnus-summary-mark-below))
8686                 (setq gnus-newsgroup-unreads
8687                       (delq number gnus-newsgroup-unreads))
8688                 (if gnus-newsgroup-auto-expire
8689                     (push number gnus-newsgroup-expirable)
8690                   (push (cons number gnus-low-score-mark)
8691                         gnus-newsgroup-reads)))
8692               t)
8693             ;; Do the `display' group parameter.
8694             (and gnus-newsgroup-display
8695                  (not (funcall gnus-newsgroup-display)))
8696             ;; Check NoCeM things.
8697             (when (and gnus-use-nocem
8698                        (gnus-nocem-unwanted-article-p
8699                         (mail-header-id (car thread))))
8700               (setq gnus-newsgroup-unreads
8701                     (delq number gnus-newsgroup-unreads))
8702               t)))
8703           ;; Nope, invisible article.
8704           0
8705         ;; Ok, this article is to be visible, so we add it to the limit
8706         ;; and return 1.
8707         (push number gnus-newsgroup-limit)
8708         1))))
8709
8710 (defun gnus-expunge-thread (thread)
8711   "Mark all articles in THREAD as read."
8712   (let* ((number (mail-header-number (car thread))))
8713     (incf gnus-newsgroup-expunged-tally)
8714     ;; We also mark as read here, if that's wanted.
8715     (setq gnus-newsgroup-unreads
8716           (delq number gnus-newsgroup-unreads))
8717     (if gnus-newsgroup-auto-expire
8718         (push number gnus-newsgroup-expirable)
8719       (push (cons number gnus-low-score-mark)
8720             gnus-newsgroup-reads)))
8721   ;; Go recursively through all subthreads.
8722   (mapcar 'gnus-expunge-thread (cdr thread)))
8723
8724 ;; Summary article oriented commands
8725
8726 (defun gnus-summary-refer-parent-article (n)
8727   "Refer parent article N times.
8728 If N is negative, go to ancestor -N instead.
8729 The difference between N and the number of articles fetched is returned."
8730   (interactive "p")
8731   (let ((skip 1)
8732         error header ref)
8733     (when (not (natnump n))
8734       (setq skip (abs n)
8735             n 1))
8736     (while (and (> n 0)
8737                 (not error))
8738       (setq header (gnus-summary-article-header))
8739       (if (and (eq (mail-header-number header)
8740                    (cdr gnus-article-current))
8741                (equal gnus-newsgroup-name
8742                       (car gnus-article-current)))
8743           ;; If we try to find the parent of the currently
8744           ;; displayed article, then we take a look at the actual
8745           ;; References header, since this is slightly more
8746           ;; reliable than the References field we got from the
8747           ;; server.
8748           (with-current-buffer gnus-original-article-buffer
8749             (nnheader-narrow-to-headers)
8750             (unless (setq ref (message-fetch-field "references"))
8751               (when (setq ref (message-fetch-field "in-reply-to"))
8752                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8753             (widen))
8754         (setq ref
8755               ;; It's not the current article, so we take a bet on
8756               ;; the value we got from the server.
8757               (mail-header-references header)))
8758       (if (and ref
8759                (not (equal ref "")))
8760           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8761             (gnus-message 1 "Couldn't find parent"))
8762         (gnus-message 1 "No references in article %d"
8763                       (gnus-summary-article-number))
8764         (setq error t))
8765       (decf n))
8766     (gnus-summary-position-point)
8767     n))
8768
8769 (defun gnus-summary-refer-references ()
8770   "Fetch all articles mentioned in the References header.
8771 Return the number of articles fetched."
8772   (interactive)
8773   (let ((ref (mail-header-references (gnus-summary-article-header)))
8774         (current (gnus-summary-article-number))
8775         (n 0))
8776     (if (or (not ref)
8777             (equal ref ""))
8778         (error "No References in the current article")
8779       ;; For each Message-ID in the References header...
8780       (while (string-match "<[^>]*>" ref)
8781         (incf n)
8782         ;; ... fetch that article.
8783         (gnus-summary-refer-article
8784          (prog1 (match-string 0 ref)
8785            (setq ref (substring ref (match-end 0))))))
8786       (gnus-summary-goto-subject current)
8787       (gnus-summary-position-point)
8788       n)))
8789
8790 (defun gnus-summary-refer-thread (&optional limit)
8791   "Fetch all articles in the current thread.
8792 If LIMIT (the numerical prefix), fetch that many old headers instead
8793 of what's specified by the `gnus-refer-thread-limit' variable."
8794   (interactive "P")
8795   (let ((id (mail-header-id (gnus-summary-article-header)))
8796         (limit (if limit (prefix-numeric-value limit)
8797                  gnus-refer-thread-limit)))
8798     (unless (eq gnus-fetch-old-headers 'invisible)
8799       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8800       ;; Retrieve the headers and read them in.
8801       (if (eq (if (numberp limit)
8802                   (gnus-retrieve-headers
8803                    (list (min
8804                           (+ (mail-header-number
8805                               (gnus-summary-article-header))
8806                              limit)
8807                           gnus-newsgroup-end))
8808                    gnus-newsgroup-name (* limit 2))
8809                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8810                 ;; headers.
8811                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8812                                        gnus-newsgroup-name limit))
8813               'nov)
8814           (gnus-build-all-threads)
8815         (error "Can't fetch thread from back ends that don't support NOV"))
8816       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8817     (gnus-summary-limit-include-thread id)))
8818
8819 (defun gnus-summary-refer-article (message-id)
8820   "Fetch an article specified by MESSAGE-ID."
8821   (interactive "sMessage-ID: ")
8822   (when (and (stringp message-id)
8823              (not (zerop (length message-id))))
8824     (setq message-id (gnus-replace-in-string message-id " " ""))
8825     ;; Construct the correct Message-ID if necessary.
8826     ;; Suggested by tale@pawl.rpi.edu.
8827     (unless (string-match "^<" message-id)
8828       (setq message-id (concat "<" message-id)))
8829     (unless (string-match ">$" message-id)
8830       (setq message-id (concat message-id ">")))
8831     ;; People often post MIDs from URLs, so unhex it:
8832     (unless (string-match "@" message-id)
8833       (setq message-id (gnus-url-unhex-string message-id)))
8834     (let* ((header (gnus-id-to-header message-id))
8835            (sparse (and header
8836                         (gnus-summary-article-sparse-p
8837                          (mail-header-number header))
8838                         (memq (mail-header-number header)
8839                               gnus-newsgroup-limit)))
8840            number)
8841       (cond
8842        ;; If the article is present in the buffer we just go to it.
8843        ((and header
8844              (or (not (gnus-summary-article-sparse-p
8845                        (mail-header-number header)))
8846                  sparse))
8847         (prog1
8848             (gnus-summary-goto-article
8849              (mail-header-number header) nil t)
8850           (when sparse
8851             (gnus-summary-update-article (mail-header-number header)))))
8852        (t
8853         ;; We fetch the article.
8854         (catch 'found
8855           (dolist (gnus-override-method (gnus-refer-article-methods))
8856             (when (and (gnus-check-server gnus-override-method)
8857                        ;; Fetch the header,
8858                        (setq number (gnus-summary-insert-subject message-id)))
8859               ;; and display the article.
8860               (gnus-summary-select-article nil nil nil number)
8861               (throw 'found t)))
8862           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8863
8864 (defun gnus-refer-article-methods ()
8865   "Return a list of referable methods."
8866   (cond
8867    ;; No method, so we default to current and native.
8868    ((null gnus-refer-article-method)
8869     (list gnus-current-select-method gnus-select-method))
8870    ;; Current.
8871    ((eq 'current gnus-refer-article-method)
8872     (list gnus-current-select-method))
8873    ;; List of select methods.
8874    ((not (and (symbolp (car gnus-refer-article-method))
8875               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8876     (let (out)
8877       (dolist (method gnus-refer-article-method)
8878         (push (if (eq 'current method)
8879                   gnus-current-select-method
8880                 method)
8881               out))
8882       (nreverse out)))
8883    ;; One single select method.
8884    (t
8885     (list gnus-refer-article-method))))
8886
8887 (defun gnus-summary-edit-parameters ()
8888   "Edit the group parameters of the current group."
8889   (interactive)
8890   (gnus-group-edit-group gnus-newsgroup-name 'params))
8891
8892 (defun gnus-summary-customize-parameters ()
8893   "Customize the group parameters of the current group."
8894   (interactive)
8895   (gnus-group-customize gnus-newsgroup-name))
8896
8897 (defun gnus-summary-enter-digest-group (&optional force)
8898   "Enter an nndoc group based on the current article.
8899 If FORCE, force a digest interpretation.  If not, try
8900 to guess what the document format is."
8901   (interactive "P")
8902   (let ((conf gnus-current-window-configuration))
8903     (save-window-excursion
8904       (save-excursion
8905         (let (gnus-article-prepare-hook
8906               gnus-display-mime-function
8907               gnus-break-pages)
8908           (gnus-summary-select-article))))
8909     (setq gnus-current-window-configuration conf)
8910     (let* ((name (format "%s-%d"
8911                          (gnus-group-prefixed-name
8912                           gnus-newsgroup-name (list 'nndoc ""))
8913                          (with-current-buffer gnus-summary-buffer
8914                            gnus-current-article)))
8915            (ogroup gnus-newsgroup-name)
8916            (params (append (gnus-info-params (gnus-get-info ogroup))
8917                            (list (cons 'to-group ogroup))
8918                            (list (cons 'parent-group ogroup))
8919                            (list (cons 'save-article-group ogroup))))
8920            (case-fold-search t)
8921            (buf (current-buffer))
8922            dig to-address)
8923       (with-current-buffer gnus-original-article-buffer
8924         ;; Have the digest group inherit the main mail address of
8925         ;; the parent article.
8926         (when (setq to-address (or (gnus-fetch-field "reply-to")
8927                                    (gnus-fetch-field "from")))
8928           (setq params
8929                 (append
8930                  (list (cons 'to-address
8931                              (funcall gnus-decode-encoded-address-function
8932                                       to-address))))))
8933         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8934         (insert-buffer-substring gnus-original-article-buffer)
8935         ;; Remove lines that may lead nndoc to misinterpret the
8936         ;; document type.
8937         (narrow-to-region
8938          (goto-char (point-min))
8939          (or (search-forward "\n\n" nil t) (point)))
8940         (goto-char (point-min))
8941         (delete-matching-lines "^Path:\\|^From ")
8942         (widen))
8943       (unwind-protect
8944           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8945                     (gnus-newsgroup-ephemeral-ignored-charsets
8946                      gnus-newsgroup-ignored-charsets))
8947                 (gnus-group-read-ephemeral-group
8948                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8949                               (nndoc-article-type
8950                                ,(if force 'mbox 'guess)))
8951                  t nil nil nil
8952                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8953                                                         "ADAPT")))))
8954               ;; Make all postings to this group go to the parent group.
8955               (nconc (gnus-info-params (gnus-get-info name))
8956                      params)
8957             ;; Couldn't select this doc group.
8958             (switch-to-buffer buf)
8959             (gnus-set-global-variables)
8960             (gnus-configure-windows 'summary)
8961             (gnus-message 3 "Article couldn't be entered?"))
8962         (kill-buffer dig)))))
8963
8964 (defun gnus-summary-read-document (n)
8965   "Open a new group based on the current article(s).
8966 This will allow you to read digests and other similar
8967 documents as newsgroups.
8968 Obeys the standard process/prefix convention."
8969   (interactive "P")
8970   (let* ((ogroup gnus-newsgroup-name)
8971          (params (append (gnus-info-params (gnus-get-info ogroup))
8972                          (list (cons 'to-group ogroup))))
8973          group egroup groups vgroup)
8974     (dolist (article (gnus-summary-work-articles n))
8975       (setq group (format "%s-%d" gnus-newsgroup-name article))
8976       (gnus-summary-remove-process-mark article)
8977       (when (gnus-summary-display-article article)
8978         (save-excursion
8979           (with-temp-buffer
8980             (insert-buffer-substring gnus-original-article-buffer)
8981             ;; Remove some headers that may lead nndoc to make
8982             ;; the wrong guess.
8983             (message-narrow-to-head)
8984             (goto-char (point-min))
8985             (delete-matching-lines "^Path:\\|^From ")
8986             (widen)
8987             (if (setq egroup
8988                       (gnus-group-read-ephemeral-group
8989                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8990                                      (nndoc-article-type guess))
8991                        t nil t))
8992                 (progn
8993                   ;; Make all postings to this group go to the parent group.
8994                   (nconc (gnus-info-params (gnus-get-info egroup))
8995                          params)
8996                   (push egroup groups))
8997               ;; Couldn't select this doc group.
8998               (gnus-error 3 "Article couldn't be entered"))))))
8999     ;; Now we have selected all the documents.
9000     (cond
9001      ((not groups)
9002       (error "None of the articles could be interpreted as documents"))
9003      ((gnus-group-read-ephemeral-group
9004        (setq vgroup (format
9005                      "nnvirtual:%s-%s" gnus-newsgroup-name
9006                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
9007        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
9008        t
9009        (cons (current-buffer) 'summary)))
9010      (t
9011       (error "Couldn't select virtual nndoc group")))))
9012
9013 (defun gnus-summary-isearch-article (&optional regexp-p)
9014   "Do incremental search forward on the current article.
9015 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
9016   (interactive "P")
9017   (gnus-summary-select-article)
9018   (gnus-configure-windows 'article)
9019   (gnus-eval-in-buffer-window gnus-article-buffer
9020     (save-restriction
9021       (widen)
9022       (isearch-forward regexp-p))))
9023
9024 (defun gnus-summary-repeat-search-article-forward ()
9025   "Repeat the previous search forwards."
9026   (interactive)
9027   (unless gnus-last-search-regexp
9028     (error "No previous search"))
9029   (gnus-summary-search-article-forward gnus-last-search-regexp))
9030
9031 (defun gnus-summary-repeat-search-article-backward ()
9032   "Repeat the previous search backwards."
9033   (interactive)
9034   (unless gnus-last-search-regexp
9035     (error "No previous search"))
9036   (gnus-summary-search-article-forward gnus-last-search-regexp t))
9037
9038 (defun gnus-summary-search-article-forward (regexp &optional backward)
9039   "Search for an article containing REGEXP forward.
9040 If BACKWARD, search backward instead."
9041   (interactive
9042    (list (read-string
9043           (format "Search article %s (regexp%s): "
9044                   (if current-prefix-arg "backward" "forward")
9045                   (if gnus-last-search-regexp
9046                       (concat ", default " gnus-last-search-regexp)
9047                     "")))
9048          current-prefix-arg))
9049   (if (string-equal regexp "")
9050       (setq regexp (or gnus-last-search-regexp ""))
9051     (setq gnus-last-search-regexp regexp)
9052     (setq gnus-article-before-search gnus-current-article))
9053   ;; Intentionally set gnus-last-article.
9054   (setq gnus-last-article gnus-article-before-search)
9055   (let ((gnus-last-article gnus-last-article))
9056     (if (gnus-summary-search-article regexp backward)
9057         (gnus-summary-show-thread)
9058       (signal 'search-failed (list regexp)))))
9059
9060 (defun gnus-summary-search-article-backward (regexp)
9061   "Search for an article containing REGEXP backward."
9062   (interactive
9063    (list (read-string
9064           (format "Search article backward (regexp%s): "
9065                   (if gnus-last-search-regexp
9066                       (concat ", default " gnus-last-search-regexp)
9067                     "")))))
9068   (gnus-summary-search-article-forward regexp 'backward))
9069
9070 (defun gnus-summary-search-article (regexp &optional backward)
9071   "Search for an article containing REGEXP.
9072 Optional argument BACKWARD means do search for backward.
9073 `gnus-select-article-hook' is not called during the search."
9074   ;; We have to require this here to make sure that the following
9075   ;; dynamic binding isn't shadowed by autoloading.
9076   (require 'gnus-async)
9077   (require 'gnus-art)
9078   (let ((gnus-select-article-hook nil)  ;Disable hook.
9079         (gnus-article-prepare-hook nil)
9080         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9081         (gnus-use-article-prefetch nil)
9082         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9083         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9084         (gnus-visual nil)
9085         (gnus-keep-backlog nil)
9086         (gnus-break-pages nil)
9087         (gnus-summary-display-arrow nil)
9088         (gnus-updated-mode-lines nil)
9089         (gnus-auto-center-summary nil)
9090         (sum (current-buffer))
9091         (gnus-display-mime-function nil)
9092         (found nil)
9093         point)
9094     (gnus-save-hidden-threads
9095       (gnus-summary-select-article)
9096       (set-buffer gnus-article-buffer)
9097       (goto-char (window-point (get-buffer-window (current-buffer))))
9098       (when backward
9099         (forward-line -1))
9100       (while (not found)
9101         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9102         (if (if backward
9103                 (re-search-backward regexp nil t)
9104               (re-search-forward regexp nil t))
9105             ;; We found the regexp.
9106             (progn
9107               (setq found 'found)
9108               (beginning-of-line)
9109               (set-window-start
9110                (get-buffer-window (current-buffer))
9111                (point))
9112               (forward-line 1)
9113               (set-window-point
9114                (get-buffer-window (current-buffer))
9115                (point))
9116               (set-buffer sum)
9117               (setq point (point)))
9118           ;; We didn't find it, so we go to the next article.
9119           (set-buffer sum)
9120           (setq found 'not)
9121           (while (eq found 'not)
9122             (if (not (if backward (gnus-summary-find-prev)
9123                        (gnus-summary-find-next)))
9124                 ;; No more articles.
9125                 (setq found t)
9126               ;; Select the next article and adjust point.
9127               (unless (gnus-summary-article-sparse-p
9128                        (gnus-summary-article-number))
9129                 (setq found nil)
9130                 (gnus-summary-select-article)
9131                 (set-buffer gnus-article-buffer)
9132                 (widen)
9133                 (goto-char (if backward (point-max) (point-min))))))))
9134       (gnus-message 7 ""))
9135     ;; Return whether we found the regexp.
9136     (when (eq found 'found)
9137       (goto-char point)
9138       (gnus-summary-show-thread)
9139       (gnus-summary-goto-subject gnus-current-article)
9140       (gnus-summary-position-point)
9141       t)))
9142
9143 (defun gnus-find-matching-articles (header regexp)
9144   "Return a list of all articles that match REGEXP on HEADER.
9145 This search includes all articles in the current group that Gnus has
9146 fetched headers for, whether they are displayed or not."
9147   (let ((articles nil)
9148         ;; Can't eta-reduce because it's a macro.
9149         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9150         (case-fold-search t))
9151     (dolist (header gnus-newsgroup-headers)
9152       (when (string-match regexp (funcall func header))
9153         (push (mail-header-number header) articles)))
9154     (nreverse articles)))
9155
9156 (defun gnus-summary-find-matching (header regexp &optional backward unread
9157                                           not-case-fold not-matching)
9158   "Return a list of all articles that match REGEXP on HEADER.
9159 The search stars on the current article and goes forwards unless
9160 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9161 If UNREAD is non-nil, only unread articles will
9162 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9163 in the comparisons. If NOT-MATCHING, return a list of all articles that
9164 not match REGEXP on HEADER."
9165   (let ((case-fold-search (not not-case-fold))
9166         articles d func)
9167     (if (consp header)
9168         (if (eq (car header) 'extra)
9169             (setq func
9170                   `(lambda (h)
9171                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9172                          "")))
9173           (error "%s is an invalid header" header))
9174       (unless (fboundp (intern (concat "mail-header-" header)))
9175         (error "%s is not a valid header" header))
9176       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9177     (dolist (d (if (eq backward 'all)
9178                    gnus-newsgroup-data
9179                  (gnus-data-find-list
9180                   (gnus-summary-article-number)
9181                   (gnus-data-list backward))))
9182       (when (and (or (not unread)       ; We want all articles...
9183                      (gnus-data-unread-p d)) ; Or just unreads.
9184                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9185                  (if not-matching
9186                      (not (string-match
9187                            regexp
9188                            (funcall func (gnus-data-header d))))
9189                    (string-match regexp
9190                                  (funcall func (gnus-data-header d)))))
9191         (push (gnus-data-number d) articles))) ; Success!
9192     (nreverse articles)))
9193
9194 (defun gnus-summary-execute-command (header regexp command &optional backward)
9195   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9196 If HEADER is an empty string (or nil), the match is done on the entire
9197 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9198   (interactive
9199    (list (let ((completion-ignore-case t))
9200            (completing-read
9201             "Header name: "
9202             (mapcar (lambda (header) (list (format "%s" header)))
9203                     (append
9204                      '("Number" "Subject" "From" "Lines" "Date"
9205                        "Message-ID" "Xref" "References" "Body")
9206                      gnus-extra-headers))
9207             nil 'require-match))
9208          (read-string "Regexp: ")
9209          (read-key-sequence "Command: ")
9210          current-prefix-arg))
9211   (when (equal header "Body")
9212     (setq header ""))
9213   ;; Hidden thread subtrees must be searched as well.
9214   (gnus-summary-show-all-threads)
9215   ;; We don't want to change current point nor window configuration.
9216   (save-excursion
9217     (save-window-excursion
9218       (let (gnus-visual
9219             gnus-treat-strip-trailing-blank-lines
9220             gnus-treat-strip-leading-blank-lines
9221             gnus-treat-strip-multiple-blank-lines
9222             gnus-treat-hide-boring-headers
9223             gnus-treat-fold-newsgroups
9224             gnus-article-prepare-hook)
9225         (gnus-message 6 "Executing %s..." (key-description command))
9226         ;; We'd like to execute COMMAND interactively so as to give arguments.
9227         (gnus-execute header regexp
9228                       `(call-interactively ',(key-binding command))
9229                       backward)
9230         (gnus-message 6 "Executing %s...done" (key-description command))))))
9231
9232 (defun gnus-summary-beginning-of-article ()
9233   "Scroll the article back to the beginning."
9234   (interactive)
9235   (gnus-summary-select-article)
9236   (gnus-configure-windows 'article)
9237   (gnus-eval-in-buffer-window gnus-article-buffer
9238     (widen)
9239     (goto-char (point-min))
9240     (when gnus-break-pages
9241       (gnus-narrow-to-page))))
9242
9243 (defun gnus-summary-end-of-article ()
9244   "Scroll to the end of the article."
9245   (interactive)
9246   (gnus-summary-select-article)
9247   (gnus-configure-windows 'article)
9248   (gnus-eval-in-buffer-window gnus-article-buffer
9249     (widen)
9250     (goto-char (point-max))
9251     (recenter -3)
9252     (when gnus-break-pages
9253       (gnus-narrow-to-page))))
9254
9255 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9256   "Truncate to LEN and quote all \"(\"'s in STRING."
9257   (gnus-replace-in-string (if (and len (> (length string) len))
9258                               (substring string 0 len)
9259                             string)
9260                           "[()]" "\\\\\\&"))
9261
9262 (defun gnus-summary-print-article (&optional filename n)
9263   "Generate and print a PostScript image of the process-marked (mail) articles.
9264
9265 If used interactively, print the current article if none are
9266 process-marked.  With prefix arg, prompt the user for the name of the
9267 file to save in.
9268
9269 When used from Lisp, accept two optional args FILENAME and N.  N means
9270 to print the next N articles.  If N is negative, print the N previous
9271 articles.  If N is nil and articles have been marked with the process
9272 mark, print these instead.
9273
9274 If the optional first argument FILENAME is nil, send the image to the
9275 printer.  If FILENAME is a string, save the PostScript image in a file with
9276 that name.  If FILENAME is a number, prompt the user for the name of the file
9277 to save in."
9278   (interactive (list (ps-print-preprint current-prefix-arg)))
9279   (dolist (article (gnus-summary-work-articles n))
9280     (gnus-summary-select-article nil nil 'pseudo article)
9281     (gnus-eval-in-buffer-window gnus-article-buffer
9282       (gnus-print-buffer))
9283     (gnus-summary-remove-process-mark article))
9284   (ps-despool filename))
9285
9286 (defun gnus-print-buffer ()
9287   (let ((buffer (generate-new-buffer " *print*")))
9288     (unwind-protect
9289         (progn
9290           (copy-to-buffer buffer (point-min) (point-max))
9291           (set-buffer buffer)
9292           (gnus-remove-text-with-property 'gnus-decoration)
9293           (when (gnus-visual-p 'article-highlight 'highlight)
9294             ;; Copy-to-buffer doesn't copy overlay.  So redo
9295             ;; highlight.
9296             (let ((gnus-article-buffer buffer))
9297               (gnus-article-highlight-citation t)
9298               (gnus-article-highlight-signature)
9299               (gnus-article-emphasize)
9300               (gnus-article-delete-invisible-text)))
9301           (let ((ps-left-header
9302                  (list
9303                   (concat "("
9304                           (gnus-summary-print-truncate-and-quote
9305                            (mail-header-subject gnus-current-headers)
9306                            66) ")")
9307                   (concat "("
9308                           (gnus-summary-print-truncate-and-quote
9309                            (mail-header-from gnus-current-headers)
9310                            45) ")")))
9311                 (ps-right-header
9312                  (list
9313                   "/pagenumberstring load"
9314                   (concat "("
9315                           (mail-header-date gnus-current-headers) ")"))))
9316             (gnus-run-hooks 'gnus-ps-print-hook)
9317             (save-excursion
9318               (if ps-print-color-p
9319                   (ps-spool-buffer-with-faces)
9320                 (ps-spool-buffer)))))
9321       (kill-buffer buffer))))
9322
9323 (defun gnus-summary-show-article (&optional arg)
9324   "Force redisplaying of the current article.
9325 If ARG (the prefix) is a number, show the article with the charset
9326 defined in `gnus-summary-show-article-charset-alist', or the charset
9327 input.
9328 If ARG (the prefix) is non-nil and not a number, show the raw article
9329 without any article massaging functions being run.  Normally, the key
9330 strokes are `C-u g'."
9331   (interactive "P")
9332   (cond
9333    ((numberp arg)
9334     (gnus-summary-show-article t)
9335     (let ((gnus-newsgroup-charset
9336            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9337                (mm-read-coding-system
9338                 "View as charset: " ;; actually it is coding system.
9339                 (with-current-buffer gnus-article-buffer
9340                   (mm-detect-coding-region (point) (point-max))))))
9341           (gnus-newsgroup-ignored-charsets 'gnus-all))
9342       (gnus-summary-select-article nil 'force)
9343       (let ((deps gnus-newsgroup-dependencies)
9344             head header lines)
9345         (with-current-buffer gnus-original-article-buffer
9346           (save-restriction
9347             (message-narrow-to-head)
9348             (setq head (buffer-string))
9349             (goto-char (point-min))
9350             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9351               (goto-char (point-max))
9352               (widen)
9353               (setq lines (1- (count-lines (point) (point-max))))))
9354           (with-temp-buffer
9355             (insert (format "211 %d Article retrieved.\n"
9356                             (cdr gnus-article-current)))
9357             (insert head)
9358             (if lines (insert (format "Lines: %d\n" lines)))
9359             (insert ".\n")
9360             (let ((nntp-server-buffer (current-buffer)))
9361               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9362         (gnus-data-set-header
9363          (gnus-data-find (cdr gnus-article-current))
9364          header)
9365         (gnus-summary-update-article-line
9366          (cdr gnus-article-current) header)
9367         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9368           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9369    ((not arg)
9370     ;; Select the article the normal way.
9371     (gnus-summary-select-article nil 'force))
9372    (t
9373     ;; We have to require this here to make sure that the following
9374     ;; dynamic binding isn't shadowed by autoloading.
9375     (require 'gnus-async)
9376     (require 'gnus-art)
9377     ;; Bind the article treatment functions to nil.
9378     (let ((gnus-have-all-headers t)
9379           gnus-article-prepare-hook
9380           gnus-article-decode-hook
9381           gnus-display-mime-function
9382           gnus-break-pages)
9383       ;; Destroy any MIME parts.
9384       (when (gnus-buffer-live-p gnus-article-buffer)
9385         (with-current-buffer gnus-article-buffer
9386           (mm-destroy-parts gnus-article-mime-handles)
9387           ;; Set it to nil for safety reason.
9388           (setq gnus-article-mime-handle-alist nil)
9389           (setq gnus-article-mime-handles nil)))
9390       (gnus-summary-select-article nil 'force))))
9391   (gnus-summary-goto-subject gnus-current-article)
9392   (gnus-summary-position-point))
9393
9394 (defun gnus-summary-show-raw-article ()
9395   "Show the raw article without any article massaging functions being run."
9396   (interactive)
9397   (gnus-summary-show-article t))
9398
9399 (defun gnus-summary-verbose-headers (&optional arg)
9400   "Toggle permanent full header display.
9401 If ARG is a positive number, turn header display on.
9402 If ARG is a negative number, turn header display off."
9403   (interactive "P")
9404   (setq gnus-show-all-headers
9405         (cond ((or (not (numberp arg))
9406                    (zerop arg))
9407                (not gnus-show-all-headers))
9408               ((natnump arg)
9409                t)))
9410   (gnus-summary-show-article))
9411
9412 (defun gnus-summary-toggle-header (&optional arg)
9413   "Show the headers if they are hidden, or hide them if they are shown.
9414 If ARG is a positive number, show the entire header.
9415 If ARG is a negative number, hide the unwanted header lines."
9416   (interactive "P")
9417   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9418                      (get-buffer-window gnus-article-buffer t))))
9419     (with-current-buffer gnus-article-buffer
9420       (widen)
9421       (article-narrow-to-head)
9422       (let* ((inhibit-read-only t)
9423              (inhibit-point-motion-hooks t)
9424              (hidden (if (numberp arg)
9425                          (>= arg 0)
9426                        (or (not (looking-at "[^ \t\n]+:"))
9427                            (gnus-article-hidden-text-p 'headers))))
9428              s e)
9429         (delete-region (point-min) (point-max))
9430         (with-current-buffer gnus-original-article-buffer
9431           (goto-char (setq s (point-min)))
9432           (setq e (if (search-forward "\n\n" nil t)
9433                       (1- (point))
9434                     (point-max))))
9435         (insert-buffer-substring gnus-original-article-buffer s e)
9436         (run-hooks 'gnus-article-decode-hook)
9437         (if hidden
9438             (let ((gnus-treat-hide-headers nil)
9439                   (gnus-treat-hide-boring-headers nil))
9440               (gnus-delete-wash-type 'headers)
9441               (gnus-treat-article 'head))
9442           (gnus-treat-article 'head))
9443         (widen)
9444         (if window
9445             (set-window-start window (goto-char (point-min))))
9446         (if gnus-break-pages
9447             (gnus-narrow-to-page)
9448           (when (gnus-visual-p 'page-marker)
9449             (let ((inhibit-read-only t))
9450               (gnus-remove-text-with-property 'gnus-prev)
9451               (gnus-remove-text-with-property 'gnus-next))))
9452         (gnus-set-mode-line 'article)))))
9453
9454 (defun gnus-summary-show-all-headers ()
9455   "Make all header lines visible."
9456   (interactive)
9457   (gnus-summary-toggle-header 1))
9458
9459 (defun gnus-summary-caesar-message (&optional arg)
9460   "Caesar rotate the current article by 13.
9461 With a non-numerical prefix, also rotate headers.  A numerical
9462 prefix specifies how many places to rotate each letter forward."
9463   (interactive "P")
9464   (gnus-summary-select-article)
9465   (let ((mail-header-separator ""))
9466     (gnus-eval-in-buffer-window gnus-article-buffer
9467       (save-restriction
9468         (widen)
9469         (let ((start (window-start))
9470               (inhibit-read-only t))
9471           (if (equal arg '(4))
9472               (message-caesar-buffer-body nil t)
9473             (message-caesar-buffer-body arg))
9474           (set-window-start (get-buffer-window (current-buffer)) start)))))
9475   ;; Create buttons and stuff...
9476   (gnus-treat-article nil))
9477
9478 (declare-function idna-to-unicode "ext:idna" (str))
9479
9480 (defun gnus-summary-idna-message (&optional arg)
9481   "Decode IDNA encoded domain names in the current articles.
9482 IDNA encoded domain names looks like `xn--bar'.  If a string
9483 remain unencoded after running this function, it is likely an
9484 invalid IDNA string (`xn--bar' is invalid).
9485
9486 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9487 installed for this command to work."
9488   (interactive "P")
9489   (if (not (and (condition-case nil (require 'idna)
9490                   (file-error))
9491                 (mm-coding-system-p 'utf-8)
9492                 (executable-find (symbol-value 'idna-program))))
9493       (gnus-message
9494        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9495     (gnus-summary-select-article)
9496     (let ((mail-header-separator ""))
9497       (gnus-eval-in-buffer-window gnus-article-buffer
9498         (save-restriction
9499           (widen)
9500           (let ((start (window-start))
9501                 buffer-read-only)
9502             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9503               (replace-match (idna-to-unicode (match-string 1))))
9504             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9505
9506 (defun gnus-summary-morse-message (&optional arg)
9507   "Morse decode the current article."
9508   (interactive "P")
9509   (gnus-summary-select-article)
9510   (let ((mail-header-separator ""))
9511     (gnus-eval-in-buffer-window gnus-article-buffer
9512       (save-excursion
9513         (save-restriction
9514           (widen)
9515           (let ((pos (window-start))
9516                 (inhibit-read-only t))
9517             (goto-char (point-min))
9518             (when (message-goto-body)
9519               (gnus-narrow-to-body))
9520             (goto-char (point-min))
9521             (while (search-forward "·" (point-max) t)
9522               (replace-match "."))
9523             (unmorse-region (point-min) (point-max))
9524             (widen)
9525             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9526
9527 (defun gnus-summary-stop-page-breaking ()
9528   "Stop page breaking in the current article."
9529   (interactive)
9530   (gnus-summary-select-article)
9531   (gnus-eval-in-buffer-window gnus-article-buffer
9532     (widen)
9533     (when (gnus-visual-p 'page-marker)
9534       (let ((inhibit-read-only t))
9535         (gnus-remove-text-with-property 'gnus-prev)
9536         (gnus-remove-text-with-property 'gnus-next))
9537       (setq gnus-page-broken nil))))
9538
9539 (defun gnus-summary-move-article (&optional n to-newsgroup
9540                                             select-method action)
9541   "Move the current article to a different newsgroup.
9542 If N is a positive number, move the N next articles.
9543 If N is a negative number, move the N previous articles.
9544 If N is nil and any articles have been marked with the process mark,
9545 move those articles instead.
9546 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9547 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9548 re-spool using this method.
9549
9550 When called interactively with TO-NEWSGROUP being nil, the value of
9551 the variable `gnus-move-split-methods' is used for finding a default
9552 for the target newsgroup.
9553
9554 For this function to work, both the current newsgroup and the
9555 newsgroup that you want to move to have to support the `request-move'
9556 and `request-accept' functions.
9557
9558 ACTION can be either `move' (the default), `crosspost' or `copy'."
9559   (interactive "P")
9560   (unless action
9561     (setq action 'move))
9562   ;; Check whether the source group supports the required functions.
9563   (cond ((and (eq action 'move)
9564               (not (gnus-check-backend-function
9565                     'request-move-article gnus-newsgroup-name)))
9566          (error "The current group does not support article moving"))
9567         ((and (eq action 'crosspost)
9568               (not (gnus-check-backend-function
9569                     'request-replace-article gnus-newsgroup-name)))
9570          (error "The current group does not support article editing")))
9571   (let ((articles (gnus-summary-work-articles n))
9572         (prefix (if (gnus-check-backend-function
9573                      'request-move-article gnus-newsgroup-name)
9574                     (funcall gnus-move-group-prefix-function
9575                              gnus-newsgroup-name)
9576                   ""))
9577         (names '((move "Move" "Moving")
9578                  (copy "Copy" "Copying")
9579                  (crosspost "Crosspost" "Crossposting")))
9580         (copy-buf (save-excursion
9581                     (nnheader-set-temp-buffer " *copy article*")))
9582         art-group to-method new-xref article to-groups
9583         articles-to-update-marks encoded)
9584     (unless (assq action names)
9585       (error "Unknown action %s" action))
9586     ;; Read the newsgroup name.
9587     (when (and (not to-newsgroup)
9588                (not select-method))
9589       (if (and gnus-move-split-methods
9590                (not
9591                 (and (memq gnus-current-article articles)
9592                      (gnus-buffer-live-p gnus-original-article-buffer))))
9593           ;; When `gnus-move-split-methods' is non-nil, we have to
9594           ;; select an article to give `gnus-read-move-group-name' an
9595           ;; opportunity to suggest an appropriate default.  However,
9596           ;; we needn't render or mark the article.
9597           (let ((gnus-display-mime-function nil)
9598                 (gnus-article-prepare-hook nil)
9599                 (gnus-mark-article-hook nil))
9600             (gnus-summary-select-article nil nil nil (car articles))))
9601       (setq to-newsgroup (gnus-read-move-group-name
9602                           (cadr (assq action names))
9603                           (symbol-value
9604                            (intern (format "gnus-current-%s-group" action)))
9605                           articles prefix)
9606             encoded to-newsgroup
9607             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9608       (set (intern (format "gnus-current-%s-group" action))
9609            (mm-decode-coding-string
9610             to-newsgroup
9611             (gnus-group-name-charset to-method to-newsgroup))))
9612     (unless to-method
9613       (setq to-method (or select-method
9614                           (gnus-server-to-method
9615                            (gnus-group-method to-newsgroup)))))
9616     (setq to-newsgroup
9617           (or encoded
9618               (and to-newsgroup
9619                    (mm-encode-coding-string
9620                     to-newsgroup
9621                     (gnus-group-name-charset to-method to-newsgroup)))))
9622     ;; Check the method we are to move this article to...
9623     (unless (gnus-check-backend-function
9624              'request-accept-article (car to-method))
9625       (error "%s does not support article copying" (car to-method)))
9626     (unless (gnus-check-server to-method)
9627       (error "Can't open server %s" (car to-method)))
9628     (gnus-message 6 "%s to %s: %s..."
9629                   (caddr (assq action names))
9630                   (or (car select-method)
9631                       (gnus-group-decoded-name to-newsgroup))
9632                   articles)
9633     (while articles
9634       (setq article (pop articles))
9635       (setq
9636        art-group
9637        (cond
9638         ;; Move the article.
9639         ((eq action 'move)
9640          ;; Remove this article from future suppression.
9641          (gnus-dup-unsuppress-article article)
9642          (let* ((from-method (gnus-find-method-for-group
9643                               gnus-newsgroup-name))
9644                 (to-method (or select-method
9645                                (gnus-find-method-for-group to-newsgroup)))
9646                 (move-is-internal (gnus-method-equal from-method to-method)))
9647            (gnus-request-move-article
9648             article                     ; Article to move
9649             gnus-newsgroup-name         ; From newsgroup
9650             (nth 1 (gnus-find-method-for-group
9651                     gnus-newsgroup-name)) ; Server
9652             (list 'gnus-request-accept-article
9653                   to-newsgroup (list 'quote select-method)
9654                   (not articles) t)     ; Accept form
9655             (not articles)              ; Only save nov last time
9656             move-is-internal)))         ; is this move internal?
9657         ;; Copy the article.
9658         ((eq action 'copy)
9659          (with-current-buffer copy-buf
9660            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9661              (save-restriction
9662                (nnheader-narrow-to-headers)
9663                (dolist (hdr gnus-copy-article-ignored-headers)
9664                  (message-remove-header hdr t)))
9665              (gnus-request-accept-article
9666               to-newsgroup select-method (not articles) t))))
9667         ;; Crosspost the article.
9668         ((eq action 'crosspost)
9669          (let ((xref (message-tokenize-header
9670                       (mail-header-xref (gnus-summary-article-header article))
9671                       " ")))
9672            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9673                                   ":" (number-to-string article)))
9674            (unless xref
9675              (setq xref (list (system-name))))
9676            (setq new-xref
9677                  (concat
9678                   (mapconcat 'identity
9679                              (delete "Xref:" (delete new-xref xref))
9680                              " ")
9681                   " " new-xref))
9682            (with-current-buffer copy-buf
9683              ;; First put the article in the destination group.
9684              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9685              (when (consp (setq art-group
9686                                 (gnus-request-accept-article
9687                                  to-newsgroup select-method (not articles) t)))
9688                (setq new-xref (concat new-xref " " (car art-group)
9689                                       ":"
9690                                       (number-to-string (cdr art-group))))
9691                ;; Now we have the new Xrefs header, so we insert
9692                ;; it and replace the new article.
9693                (nnheader-replace-header "Xref" new-xref)
9694                (gnus-request-replace-article
9695                 (cdr art-group) to-newsgroup (current-buffer) t)
9696                art-group))))))
9697       (cond
9698        ((not art-group)
9699         (gnus-message 1 "Couldn't %s article %s: %s"
9700                       (cadr (assq action names)) article
9701                       (nnheader-get-report (car to-method))))
9702        ((eq art-group 'junk)
9703         (when (eq action 'move)
9704           (gnus-summary-mark-article article gnus-canceled-mark)
9705           (gnus-message 4 "Deleted article %s" article)
9706           ;; run the delete hook
9707           (run-hook-with-args 'gnus-summary-article-delete-hook
9708                               action
9709                               (gnus-data-header
9710                                (assoc article (gnus-data-list nil)))
9711                               gnus-newsgroup-name nil
9712                               select-method)))
9713        (t
9714         (let* ((pto-group (gnus-group-prefixed-name
9715                            (car art-group) to-method))
9716                (info (gnus-get-info pto-group))
9717                (to-group (gnus-info-group info))
9718                to-marks)
9719           ;; Update the group that has been moved to.
9720           (when (and info
9721                      (memq action '(move copy)))
9722             (unless (member to-group to-groups)
9723               (push to-group to-groups))
9724
9725             (unless (memq article gnus-newsgroup-unreads)
9726               (push 'read to-marks)
9727               (gnus-info-set-read
9728                info (gnus-add-to-range (gnus-info-read info)
9729                                        (list (cdr art-group)))))
9730
9731             ;; See whether the article is to be put in the cache.
9732             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9733                              gnus-article-mark-lists
9734                            (delete '(expirable . expire)
9735                                    (copy-sequence gnus-article-mark-lists))))
9736                   (to-article (cdr art-group)))
9737
9738               ;; Enter the article into the cache in the new group,
9739               ;; if that is required.
9740               (when gnus-use-cache
9741                 (gnus-cache-possibly-enter-article
9742                  to-group to-article
9743                  (memq article gnus-newsgroup-marked)
9744                  (memq article gnus-newsgroup-dormant)
9745                  (memq article gnus-newsgroup-unreads)))
9746
9747               (when gnus-preserve-marks
9748                 ;; Copy any marks over to the new group.
9749                 (when (and (equal to-group gnus-newsgroup-name)
9750                            (not (memq article gnus-newsgroup-unreads)))
9751                   ;; Mark this article as read in this group.
9752                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9753                   (setcdr (gnus-active to-group) to-article)
9754                   (setcdr gnus-newsgroup-active to-article))
9755
9756                 (while marks
9757                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9758                     (when (memq article (symbol-value
9759                                          (intern (format "gnus-newsgroup-%s"
9760                                                          (caar marks)))))
9761                       (push (cdar marks) to-marks)
9762                       ;; If the other group is the same as this group,
9763                       ;; then we have to add the mark to the list.
9764                       (when (equal to-group gnus-newsgroup-name)
9765                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9766                              (cons to-article
9767                                    (symbol-value
9768                                     (intern (format "gnus-newsgroup-%s"
9769                                                     (caar marks)))))))
9770                       ;; Copy the marks to other group.
9771                       (gnus-add-marked-articles
9772                        to-group (cdar marks) (list to-article) info)))
9773                   (setq marks (cdr marks)))
9774
9775                 (gnus-request-set-mark
9776                  to-group (list (list (list to-article) 'add to-marks))))
9777
9778               (gnus-dribble-enter
9779                (concat "(gnus-group-set-info '"
9780                        (gnus-prin1-to-string (gnus-get-info to-group))
9781                        ")"))))
9782
9783           ;; Update the Xref header in this article to point to
9784           ;; the new crossposted article we have just created.
9785           (when (eq action 'crosspost)
9786             (with-current-buffer copy-buf
9787               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9788               (nnheader-replace-header "Xref" new-xref)
9789               (gnus-request-replace-article
9790                article gnus-newsgroup-name (current-buffer) t)))
9791
9792           ;; run the move/copy/crosspost/respool hook
9793           (run-hook-with-args 'gnus-summary-article-move-hook
9794                               action
9795                               (gnus-data-header
9796                                (assoc article (gnus-data-list nil)))
9797                               gnus-newsgroup-name
9798                               to-newsgroup
9799                               select-method))
9800
9801         ;;;!!!Why is this necessary?
9802         (set-buffer gnus-summary-buffer)
9803
9804         (gnus-summary-goto-subject article)
9805         (when (eq action 'move)
9806           (gnus-summary-mark-article article gnus-canceled-mark))))
9807       (push article articles-to-update-marks))
9808
9809     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9810     ;; Re-activate all groups that have been moved to.
9811     (with-current-buffer gnus-group-buffer
9812       (let ((gnus-group-marked to-groups))
9813         (gnus-group-get-new-news-this-group nil t)))
9814
9815     (gnus-kill-buffer copy-buf)
9816     (gnus-summary-position-point)
9817     (gnus-set-mode-line 'summary)))
9818
9819 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9820   "Copy the current article to some other group.
9821 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9822 When called interactively, if TO-NEWSGROUP is nil, use the value of
9823 the variable `gnus-move-split-methods' for finding a default target
9824 newsgroup.
9825 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9826 re-spool using this method."
9827   (interactive "P")
9828   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9829
9830 (defun gnus-summary-crosspost-article (&optional n)
9831   "Crosspost the current article to some other group."
9832   (interactive "P")
9833   (gnus-summary-move-article n nil nil 'crosspost))
9834
9835 (defcustom gnus-summary-respool-default-method nil
9836   "Default method type for respooling an article.
9837 If nil, use to the current newsgroup method."
9838   :type 'symbol
9839   :group 'gnus-summary-mail)
9840
9841 (defun gnus-summary-respool-article (&optional n method)
9842   "Respool the current article.
9843 The article will be squeezed through the mail spooling process again,
9844 which means that it will be put in some mail newsgroup or other
9845 depending on `nnmail-split-methods'.
9846 If N is a positive number, respool the N next articles.
9847 If N is a negative number, respool the N previous articles.
9848 If N is nil and any articles have been marked with the process mark,
9849 respool those articles instead.
9850
9851 Respooling can be done both from mail groups and \"real\" newsgroups.
9852 In the former case, the articles in question will be moved from the
9853 current group into whatever groups they are destined to.  In the
9854 latter case, they will be copied into the relevant groups."
9855   (interactive
9856    (list current-prefix-arg
9857          (let* ((methods (gnus-methods-using 'respool))
9858                 (methname
9859                  (symbol-name (or gnus-summary-respool-default-method
9860                                   (car (gnus-find-method-for-group
9861                                         gnus-newsgroup-name)))))
9862                 (method
9863                  (gnus-completing-read-with-default
9864                   methname "Backend to use when respooling"
9865                   methods nil t nil 'gnus-mail-method-history))
9866                 ms)
9867            (cond
9868             ((zerop (length (setq ms (gnus-servers-using-backend
9869                                       (intern method)))))
9870              (list (intern method) ""))
9871             ((= 1 (length ms))
9872              (car ms))
9873             (t
9874              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9875                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9876                            ms-alist))))))))
9877   (unless method
9878     (error "No method given for respooling"))
9879   (if (assoc (symbol-name
9880               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9881              (gnus-methods-using 'respool))
9882       (gnus-summary-move-article n nil method)
9883     (gnus-summary-copy-article n nil method)))
9884
9885 (defun gnus-summary-import-article (file &optional edit)
9886   "Import an arbitrary file into a mail newsgroup."
9887   (interactive "fImport file: \nP")
9888   (let ((group gnus-newsgroup-name)
9889         (now (current-time))
9890         atts lines group-art)
9891     (unless (gnus-check-backend-function 'request-accept-article group)
9892       (error "%s does not support article importing" group))
9893     (or (file-readable-p file)
9894         (not (file-regular-p file))
9895         (error "Can't read %s" file))
9896     (with-current-buffer (gnus-get-buffer-create " *import file*")
9897       (erase-buffer)
9898       (nnheader-insert-file-contents file)
9899       (goto-char (point-min))
9900       (if (nnheader-article-p)
9901           (save-restriction
9902             (goto-char (point-min))
9903             (search-forward "\n\n" nil t)
9904             (narrow-to-region (point-min) (1- (point)))
9905             (goto-char (point-min))
9906             (unless (re-search-forward "^date:" nil t)
9907               (goto-char (point-max))
9908               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9909        ;; This doesn't look like an article, so we fudge some headers.
9910         (setq atts (file-attributes file)
9911               lines (count-lines (point-min) (point-max)))
9912         (insert "From: " (read-string "From: ") "\n"
9913                 "Subject: " (read-string "Subject: ") "\n"
9914                 "Date: " (message-make-date (nth 5 atts)) "\n"
9915                 "Message-ID: " (message-make-message-id) "\n"
9916                 "Lines: " (int-to-string lines) "\n"
9917                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9918       (setq group-art (gnus-request-accept-article group nil t))
9919       (kill-buffer (current-buffer)))
9920     (setq gnus-newsgroup-active (gnus-activate-group group))
9921     (forward-line 1)
9922     (gnus-summary-goto-article (cdr group-art) nil t)
9923     (when edit
9924       (gnus-summary-edit-article))))
9925
9926 (defun gnus-summary-create-article ()
9927   "Create an article in a mail newsgroup."
9928   (interactive)
9929   (let ((group gnus-newsgroup-name)
9930         (now (current-time))
9931         group-art)
9932     (unless (gnus-check-backend-function 'request-accept-article group)
9933       (error "%s does not support article importing" group))
9934     (with-current-buffer (gnus-get-buffer-create " *import file*")
9935       (erase-buffer)
9936       (goto-char (point-min))
9937       ;; This doesn't look like an article, so we fudge some headers.
9938       (insert "From: " (read-string "From: ") "\n"
9939               "Subject: " (read-string "Subject: ") "\n"
9940               "Date: " (message-make-date now) "\n"
9941               "Message-ID: " (message-make-message-id) "\n")
9942       (setq group-art (gnus-request-accept-article group nil t))
9943       (kill-buffer (current-buffer)))
9944     (setq gnus-newsgroup-active (gnus-activate-group group))
9945     (forward-line 1)
9946     (gnus-summary-goto-article (cdr group-art) nil t)
9947     (gnus-summary-edit-article)))
9948
9949 (defun gnus-summary-article-posted-p ()
9950   "Say whether the current (mail) article is available from news as well.
9951 This will be the case if the article has both been mailed and posted."
9952   (interactive)
9953   (let ((id (mail-header-references (gnus-summary-article-header)))
9954         (gnus-override-method (car (gnus-refer-article-methods))))
9955     (if (gnus-request-head id "")
9956         (gnus-message 2 "The current message was found on %s"
9957                       gnus-override-method)
9958       (gnus-message 2 "The current message couldn't be found on %s"
9959                     gnus-override-method)
9960       nil)))
9961
9962 (defun gnus-summary-expire-articles (&optional now)
9963   "Expire all articles that are marked as expirable in the current group."
9964   (interactive)
9965   (when (and (not gnus-group-is-exiting-without-update-p)
9966              (gnus-check-backend-function
9967               'request-expire-articles gnus-newsgroup-name))
9968     ;; This backend supports expiry.
9969     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9970            (expirable (if total
9971                           (progn
9972                             ;; We need to update the info for
9973                             ;; this group for `gnus-list-of-read-articles'
9974                             ;; to give us the right answer.
9975                             (gnus-run-hooks 'gnus-exit-group-hook)
9976                             (gnus-summary-update-info)
9977                             (gnus-list-of-read-articles gnus-newsgroup-name))
9978                         (setq gnus-newsgroup-expirable
9979                               (sort gnus-newsgroup-expirable '<))))
9980            (expiry-wait (if now 'immediate
9981                           (gnus-group-find-parameter
9982                            gnus-newsgroup-name 'expiry-wait)))
9983            (nnmail-expiry-target
9984             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9985                 nnmail-expiry-target))
9986            es)
9987       (when expirable
9988         ;; There are expirable articles in this group, so we run them
9989         ;; through the expiry process.
9990         (gnus-message 6 "Expiring articles...")
9991         (unless (gnus-check-group gnus-newsgroup-name)
9992           (error "Can't open server for %s" gnus-newsgroup-name))
9993         ;; The list of articles that weren't expired is returned.
9994         (save-excursion
9995           (if expiry-wait
9996               (let ((nnmail-expiry-wait-function nil)
9997                     (nnmail-expiry-wait expiry-wait))
9998                 (setq es (gnus-request-expire-articles
9999                           expirable gnus-newsgroup-name)))
10000             (setq es (gnus-request-expire-articles
10001                       expirable gnus-newsgroup-name)))
10002           (unless total
10003             (setq gnus-newsgroup-expirable es))
10004           ;; We go through the old list of expirable, and mark all
10005           ;; really expired articles as nonexistent.
10006           (unless (eq es expirable) ;If nothing was expired, we don't mark.
10007             (let ((gnus-use-cache nil))
10008               (dolist (article expirable)
10009                 (when (and (not (memq article es))
10010                            (gnus-data-find article))
10011                   (gnus-summary-mark-article article gnus-canceled-mark)
10012                   (run-hook-with-args 'gnus-summary-article-expire-hook
10013                                       'delete
10014                                       (gnus-data-header
10015                                        (assoc article (gnus-data-list nil)))
10016                                       gnus-newsgroup-name
10017                                       nil
10018                                       nil))))))
10019         (gnus-message 6 "Expiring articles...done")))))
10020
10021 (defun gnus-summary-expire-articles-now ()
10022   "Expunge all expirable articles in the current group.
10023 This means that *all* articles that are marked as expirable will be
10024 deleted forever, right now."
10025   (interactive)
10026   (or gnus-expert-user
10027       (gnus-yes-or-no-p
10028        "Are you really, really sure you want to delete all expirable messages? ")
10029       (error "Phew!"))
10030   (gnus-summary-expire-articles t))
10031
10032 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10033 (defun gnus-summary-delete-article (&optional n)
10034   "Delete the N next (mail) articles.
10035 This command actually deletes articles.  This is not a marking
10036 command.  The article will disappear forever from your life, never to
10037 return.
10038
10039 If N is negative, delete backwards.
10040 If N is nil and articles have been marked with the process mark,
10041 delete these instead.
10042
10043 If `gnus-novice-user' is non-nil you will be asked for
10044 confirmation before the articles are deleted."
10045   (interactive "P")
10046   (unless (gnus-check-backend-function 'request-expire-articles
10047                                        gnus-newsgroup-name)
10048     (error "The current newsgroup does not support article deletion"))
10049   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10050     (error "Couldn't open server"))
10051   ;; Compute the list of articles to delete.
10052   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10053         (nnmail-expiry-target 'delete)
10054         not-deleted)
10055     (if (and gnus-novice-user
10056              (not (gnus-yes-or-no-p
10057                    (format "Do you really want to delete %s forever? "
10058                            (if (> (length articles) 1)
10059                                (format "these %s articles" (length articles))
10060                              "this article")))))
10061         ()
10062       ;; Delete the articles.
10063       (setq not-deleted (gnus-request-expire-articles
10064                          articles gnus-newsgroup-name 'force))
10065       (while articles
10066         (gnus-summary-remove-process-mark (car articles))
10067         ;; The backend might not have been able to delete the article
10068         ;; after all.
10069         (unless (memq (car articles) not-deleted)
10070           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10071         (let* ((article (car articles))
10072                (ghead  (gnus-data-header
10073                                     (assoc article (gnus-data-list nil)))))
10074           (run-hook-with-args 'gnus-summary-article-delete-hook
10075                               'delete ghead gnus-newsgroup-name nil
10076                               nil))
10077         (setq articles (cdr articles)))
10078       (when not-deleted
10079         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10080     (gnus-summary-position-point)
10081     (gnus-set-mode-line 'summary)
10082     not-deleted))
10083
10084 (defun gnus-summary-edit-article (&optional arg)
10085   "Edit the current article.
10086 This will have permanent effect only in mail groups.
10087 If ARG is nil, edit the decoded articles.
10088 If ARG is 1, edit the raw articles.
10089 If ARG is 2, edit the raw articles even in read-only groups.
10090 If ARG is 3, edit the articles with the current handles.
10091 Otherwise, allow editing of articles even in read-only
10092 groups."
10093   (interactive "P")
10094   (let (force raw current-handles)
10095     (cond
10096      ((null arg))
10097      ((eq arg 1)
10098       (setq raw t))
10099      ((eq arg 2)
10100       (setq raw t
10101             force t))
10102      ((eq arg 3)
10103       (setq current-handles
10104             (and (gnus-buffer-live-p gnus-article-buffer)
10105                  (with-current-buffer gnus-article-buffer
10106                    (prog1
10107                        gnus-article-mime-handles
10108                      (setq gnus-article-mime-handles nil))))))
10109      (t
10110       (setq force t)))
10111     (when (and raw (not force)
10112                (member gnus-newsgroup-name '("nndraft:delayed"
10113                                              "nndraft:drafts"
10114                                              "nndraft:queue")))
10115       (error "Can't edit the raw article in group %s"
10116              gnus-newsgroup-name))
10117     (with-current-buffer gnus-summary-buffer
10118       (let ((mail-parse-charset gnus-newsgroup-charset)
10119             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10120         (gnus-set-global-variables)
10121         (when (and (not force)
10122                    (gnus-group-read-only-p))
10123           (error "The current newsgroup does not support article editing"))
10124         (gnus-summary-show-article t)
10125         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10126           (with-current-buffer gnus-article-buffer
10127             (mm-enable-multibyte)))
10128         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10129             (setq raw t))
10130         (gnus-article-edit-article
10131          (if raw 'ignore
10132            `(lambda ()
10133               (let ((mbl mml-buffer-list))
10134                 (setq mml-buffer-list nil)
10135                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10136                   (mime-to-mml ,'current-handles))
10137                 (let ((mbl1 mml-buffer-list))
10138                   (setq mml-buffer-list mbl)
10139                   (set (make-local-variable 'mml-buffer-list) mbl1))
10140                 (gnus-make-local-hook 'kill-buffer-hook)
10141                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10142          `(lambda (no-highlight)
10143             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10144                   (message-options message-options)
10145                   (message-options-set-recipient)
10146                   (mail-parse-ignored-charsets
10147                    ',gnus-newsgroup-ignored-charsets)
10148                   (rfc2047-header-encoding-alist
10149                    ',(let ((charset (gnus-group-name-charset
10150                                      (gnus-find-method-for-group
10151                                       gnus-newsgroup-name)
10152                                      gnus-newsgroup-name)))
10153                        (append (list (cons "Newsgroups" charset)
10154                                      (cons "Followup-To" charset)
10155                                      (cons "Xref" charset))
10156                                rfc2047-header-encoding-alist))))
10157               ,(if (not raw) '(progn
10158                                 (mml-to-mime)
10159                                 (mml-destroy-buffers)
10160                                 (remove-hook 'kill-buffer-hook
10161                                              'mml-destroy-buffers t)
10162                                 (kill-local-variable 'mml-buffer-list)))
10163               (gnus-summary-edit-article-done
10164                ,(or (mail-header-references gnus-current-headers) "")
10165                ,(gnus-group-read-only-p)
10166                ,gnus-summary-buffer no-highlight))))))))
10167
10168 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10169
10170 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10171                                                  no-highlight)
10172   "Make edits to the current article permanent."
10173   (interactive)
10174   (save-excursion
10175    ;; The buffer restriction contains the entire article if it exists.
10176     (when (article-goto-body)
10177       (let ((lines (count-lines (point) (point-max)))
10178             (length (- (point-max) (point)))
10179             (case-fold-search t)
10180             (body (copy-marker (point))))
10181         (goto-char (point-min))
10182         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10183           (delete-region (match-beginning 1) (match-end 1))
10184           (insert (number-to-string length)))
10185         (goto-char (point-min))
10186         (when (re-search-forward
10187                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10188           (delete-region (match-beginning 1) (match-end 1))
10189           (insert (number-to-string length)))
10190         (goto-char (point-min))
10191         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10192           (delete-region (match-beginning 1) (match-end 1))
10193           (insert (number-to-string lines))))))
10194   ;; Replace the article.
10195   (let ((buf (current-buffer)))
10196     (with-temp-buffer
10197       (insert-buffer-substring buf)
10198
10199       (if (and (not read-only)
10200                (not (gnus-request-replace-article
10201                      (cdr gnus-article-current) (car gnus-article-current)
10202                      (current-buffer) t)))
10203           (error "Couldn't replace article")
10204         ;; Update the summary buffer.
10205         (if (and references
10206                  (equal (message-tokenize-header references " ")
10207                         (message-tokenize-header
10208                          (or (message-fetch-field "references") "") " ")))
10209             ;; We only have to update this line.
10210             (save-excursion
10211               (save-restriction
10212                 (message-narrow-to-head)
10213                 (let ((head (buffer-substring-no-properties
10214                              (point-min) (point-max)))
10215                       header)
10216                   (with-temp-buffer
10217                     (insert (format "211 %d Article retrieved.\n"
10218                                     (cdr gnus-article-current)))
10219                     (insert head)
10220                     (insert ".\n")
10221                     (let ((nntp-server-buffer (current-buffer)))
10222                       (setq header (car (gnus-get-newsgroup-headers
10223                                          nil t))))
10224                     (with-current-buffer gnus-summary-buffer
10225                       (gnus-data-set-header
10226                        (gnus-data-find (cdr gnus-article-current))
10227                        header)
10228                       (gnus-summary-update-article-line
10229                        (cdr gnus-article-current) header)
10230                       (if (gnus-summary-goto-subject
10231                            (cdr gnus-article-current) nil t)
10232                           (gnus-summary-update-secondary-mark
10233                            (cdr gnus-article-current))))))))
10234           ;; Update threads.
10235           (set-buffer (or buffer gnus-summary-buffer))
10236           (gnus-summary-update-article (cdr gnus-article-current))
10237           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10238               (gnus-summary-update-secondary-mark
10239                (cdr gnus-article-current))))
10240         ;; Prettify the article buffer again.
10241         (unless no-highlight
10242           (with-current-buffer gnus-article-buffer
10243             ;;;!!! Fix this -- article should be rehighlighted.
10244             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10245             (set-buffer gnus-original-article-buffer)
10246             (gnus-request-article
10247              (cdr gnus-article-current)
10248              (car gnus-article-current) (current-buffer))))
10249         ;; Prettify the summary buffer line.
10250         (when (gnus-visual-p 'summary-highlight 'highlight)
10251           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10252
10253 (defun gnus-summary-edit-wash (key)
10254   "Perform editing command KEY in the article buffer."
10255   (interactive
10256    (list
10257     (progn
10258       (message "%s" (concat (this-command-keys) "- "))
10259       (read-char))))
10260   (message "")
10261   (gnus-summary-edit-article)
10262   (execute-kbd-macro (concat (this-command-keys) key))
10263   (gnus-article-edit-done))
10264
10265 ;;; Respooling
10266
10267 (defun gnus-summary-respool-query (&optional silent trace)
10268   "Query where the respool algorithm would put this article."
10269   (interactive)
10270   (let (gnus-mark-article-hook)
10271     (gnus-summary-select-article)
10272     (with-current-buffer gnus-original-article-buffer
10273       (let ((groups (nnmail-article-group 'identity trace)))
10274         (unless silent
10275           (if groups
10276               (message "This message would go to %s"
10277                        (mapconcat 'car groups ", "))
10278             (message "This message would go to no groups"))
10279           groups)))))
10280
10281 (defun gnus-summary-respool-trace ()
10282   "Trace where the respool algorithm would put this article.
10283 Display a buffer showing all fancy splitting patterns which matched."
10284   (interactive)
10285   (gnus-summary-respool-query nil t))
10286
10287 ;; Summary marking commands.
10288
10289 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10290   "Mark articles which has the same subject as read, and then select the next.
10291 If UNMARK is positive, remove any kind of mark.
10292 If UNMARK is negative, tick articles."
10293   (interactive "P")
10294   (when unmark
10295     (setq unmark (prefix-numeric-value unmark)))
10296   (let ((count
10297          (gnus-summary-mark-same-subject
10298           (gnus-summary-article-subject) unmark)))
10299     ;; Select next unread article.  If auto-select-same mode, should
10300     ;; select the first unread article.
10301     (gnus-summary-next-article t (and gnus-auto-select-same
10302                                       (gnus-summary-article-subject)))
10303     (gnus-message 7 "%d article%s marked as %s"
10304                   count (if (= count 1) " is" "s are")
10305                   (if unmark "unread" "read"))))
10306
10307 (defun gnus-summary-kill-same-subject (&optional unmark)
10308   "Mark articles which has the same subject as read.
10309 If UNMARK is positive, remove any kind of mark.
10310 If UNMARK is negative, tick articles."
10311   (interactive "P")
10312   (when unmark
10313     (setq unmark (prefix-numeric-value unmark)))
10314   (let ((count
10315          (gnus-summary-mark-same-subject
10316           (gnus-summary-article-subject) unmark)))
10317     ;; If marked as read, go to next unread subject.
10318     (when (null unmark)
10319       ;; Go to next unread subject.
10320       (gnus-summary-next-subject 1 t))
10321     (gnus-message 7 "%d articles are marked as %s"
10322                   count (if unmark "unread" "read"))))
10323
10324 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10325   "Mark articles with same SUBJECT as read, and return marked number.
10326 If optional argument UNMARK is positive, remove any kinds of marks.
10327 If optional argument UNMARK is negative, mark articles as unread instead."
10328   (let ((count 1))
10329     (save-excursion
10330       (cond
10331        ((null unmark)                   ; Mark as read.
10332         (while (and
10333                 (progn
10334                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10335                   (gnus-summary-show-thread) t)
10336                 (gnus-summary-find-subject subject))
10337           (setq count (1+ count))))
10338        ((> unmark 0)                    ; Tick.
10339         (while (and
10340                 (progn
10341                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10342                   (gnus-summary-show-thread) t)
10343                 (gnus-summary-find-subject subject))
10344           (setq count (1+ count))))
10345        (t                               ; Mark as unread.
10346         (while (and
10347                 (progn
10348                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10349                   (gnus-summary-show-thread) t)
10350                 (gnus-summary-find-subject subject))
10351           (setq count (1+ count)))))
10352       (gnus-set-mode-line 'summary)
10353       ;; Return the number of marked articles.
10354       count)))
10355
10356 (defun gnus-summary-mark-as-processable (n &optional unmark)
10357   "Set the process mark on the next N articles.
10358 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10359 the process mark instead.  The difference between N and the actual
10360 number of articles marked is returned."
10361   (interactive "P")
10362   (if (and (null n) (gnus-region-active-p))
10363       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10364     (setq n (prefix-numeric-value n))
10365     (let ((backward (< n 0))
10366           (n (abs n)))
10367       (while (and
10368               (> n 0)
10369               (if unmark
10370                   (gnus-summary-remove-process-mark
10371                    (gnus-summary-article-number))
10372                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10373               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10374         (setq n (1- n)))
10375       (when (/= 0 n)
10376         (gnus-message 7 "No more articles"))
10377       (gnus-summary-recenter)
10378       (gnus-summary-position-point)
10379       n)))
10380
10381 (defun gnus-summary-unmark-as-processable (n)
10382   "Remove the process mark from the next N articles.
10383 If N is negative, unmark backward instead.  The difference between N and
10384 the actual number of articles unmarked is returned."
10385   (interactive "P")
10386   (gnus-summary-mark-as-processable n t))
10387
10388 (defun gnus-summary-unmark-all-processable ()
10389   "Remove the process mark from all articles."
10390   (interactive)
10391   (save-excursion
10392     (while gnus-newsgroup-processable
10393       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10394   (gnus-summary-position-point))
10395
10396 (defun gnus-summary-add-mark (article type)
10397   "Mark ARTICLE with a mark of TYPE."
10398   (let ((vtype (car (assq type gnus-article-mark-lists)))
10399         var)
10400     (if (not vtype)
10401         (error "No such mark type: %s" type)
10402       (setq var (intern (format "gnus-newsgroup-%s" type)))
10403       (set var (cons article (symbol-value var)))
10404       (if (memq type '(processable cached replied forwarded recent saved))
10405           (gnus-summary-update-secondary-mark article)
10406         ;;; !!! This is bogus.  We should find out what primary
10407         ;;; !!! mark we want to set.
10408         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10409
10410 (defun gnus-summary-mark-as-expirable (n)
10411   "Mark N articles forward as expirable.
10412 If N is negative, mark backward instead.  The difference between N and
10413 the actual number of articles marked is returned."
10414   (interactive "p")
10415   (gnus-summary-mark-forward n gnus-expirable-mark))
10416
10417 (defun gnus-summary-mark-as-spam (n)
10418   "Mark N articles forward as spam.
10419 If N is negative, mark backward instead.  The difference between N and
10420 the actual number of articles marked is returned."
10421   (interactive "p")
10422   (gnus-summary-mark-forward n gnus-spam-mark))
10423
10424 (defun gnus-summary-mark-article-as-replied (article)
10425   "Mark ARTICLE as replied to and update the summary line.
10426 ARTICLE can also be a list of articles."
10427   (interactive (list (gnus-summary-article-number)))
10428   (let ((articles (if (listp article) article (list article))))
10429     (dolist (article articles)
10430       (unless (numberp article)
10431         (error "%s is not a number" article))
10432       (push article gnus-newsgroup-replied)
10433       (let ((inhibit-read-only t))
10434         (when (gnus-summary-goto-subject article nil t)
10435           (gnus-summary-update-secondary-mark article))))))
10436
10437 (defun gnus-summary-mark-article-as-forwarded (article)
10438   "Mark ARTICLE as forwarded and update the summary line.
10439 ARTICLE can also be a list of articles."
10440   (let ((articles (if (listp article) article (list article))))
10441     (dolist (article articles)
10442       (push article gnus-newsgroup-forwarded)
10443       (let ((inhibit-read-only t))
10444         (when (gnus-summary-goto-subject article nil t)
10445           (gnus-summary-update-secondary-mark article))))))
10446
10447 (defun gnus-summary-set-bookmark (article)
10448   "Set a bookmark in current article."
10449   (interactive (list (gnus-summary-article-number)))
10450   (when (or (not (get-buffer gnus-article-buffer))
10451             (not gnus-current-article)
10452             (not gnus-article-current)
10453             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10454     (error "No current article selected"))
10455   ;; Remove old bookmark, if one exists.
10456   (gnus-pull article gnus-newsgroup-bookmarks)
10457   ;; Set the new bookmark, which is on the form
10458   ;; (article-number . line-number-in-body).
10459   (push
10460    (cons article
10461          (with-current-buffer gnus-article-buffer
10462            (count-lines
10463             (min (point)
10464                  (save-excursion
10465                    (article-goto-body)
10466                    (point)))
10467             (point))))
10468    gnus-newsgroup-bookmarks)
10469   (gnus-message 6 "A bookmark has been added to the current article."))
10470
10471 (defun gnus-summary-remove-bookmark (article)
10472   "Remove the bookmark from the current article."
10473   (interactive (list (gnus-summary-article-number)))
10474   ;; Remove old bookmark, if one exists.
10475   (if (not (assq article gnus-newsgroup-bookmarks))
10476       (gnus-message 6 "No bookmark in current article.")
10477     (gnus-pull article gnus-newsgroup-bookmarks)
10478     (gnus-message 6 "Removed bookmark.")))
10479
10480 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10481 (defun gnus-summary-mark-as-dormant (n)
10482   "Mark N articles forward as dormant.
10483 If N is negative, mark backward instead.  The difference between N and
10484 the actual number of articles marked is returned."
10485   (interactive "p")
10486   (gnus-summary-mark-forward n gnus-dormant-mark))
10487
10488 (defun gnus-summary-set-process-mark (article)
10489   "Set the process mark on ARTICLE and update the summary line."
10490   (setq gnus-newsgroup-processable
10491         (cons article
10492               (delq article gnus-newsgroup-processable)))
10493   (when (gnus-summary-goto-subject article)
10494     (gnus-summary-show-thread)
10495     (gnus-summary-goto-subject article)
10496     (gnus-summary-update-secondary-mark article)))
10497
10498 (defun gnus-summary-remove-process-mark (&rest articles)
10499   "Remove the process mark from ARTICLES and update the summary line."
10500   (dolist (article articles)
10501     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10502     (when (gnus-summary-goto-subject article)
10503       (gnus-summary-show-thread)
10504       (gnus-summary-goto-subject article)
10505       (gnus-summary-update-secondary-mark article)))
10506   t)
10507
10508 (defun gnus-summary-set-saved-mark (article)
10509   "Set the process mark on ARTICLE and update the summary line."
10510   (push article gnus-newsgroup-saved)
10511   (when (gnus-summary-goto-subject article)
10512     (gnus-summary-update-secondary-mark article)))
10513
10514 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10515   "Mark N articles as read forwards.
10516 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10517 The difference between N and the actual number of articles marked is
10518 returned.
10519 If NO-EXPIRE, auto-expiry will be inhibited."
10520   (interactive "p")
10521   (gnus-summary-show-thread)
10522   (let ((backward (< n 0))
10523         (gnus-summary-goto-unread
10524          (and gnus-summary-goto-unread
10525               (not (eq gnus-summary-goto-unread 'never))
10526               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10527                                     gnus-ticked-mark gnus-dormant-mark)))))
10528         (n (abs n))
10529         (mark (or mark gnus-del-mark)))
10530     (while (and (> n 0)
10531                 (gnus-summary-mark-article nil mark no-expire)
10532                 (zerop (gnus-summary-next-subject
10533                         (if backward -1 1)
10534                         (and gnus-summary-goto-unread
10535                              (not (eq gnus-summary-goto-unread 'never)))
10536                         t)))
10537       (setq n (1- n)))
10538     (when (/= 0 n)
10539       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10540     (gnus-summary-recenter)
10541     (gnus-summary-position-point)
10542     (gnus-set-mode-line 'summary)
10543     n))
10544
10545 (defun gnus-summary-mark-article-as-read (mark)
10546   "Mark the current article quickly as read with MARK."
10547   (let ((article (gnus-summary-article-number)))
10548     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10549     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10550     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10551     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10552     (push (cons article mark) gnus-newsgroup-reads)
10553     ;; Possibly remove from cache, if that is used.
10554     (when gnus-use-cache
10555       (gnus-cache-enter-remove-article article))
10556     ;; Allow the backend to change the mark.
10557     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10558     ;; Check for auto-expiry.
10559     (when (and gnus-newsgroup-auto-expire
10560                (memq mark gnus-auto-expirable-marks))
10561       (setq mark gnus-expirable-mark)
10562       ;; Let the backend know about the mark change.
10563       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10564       (push article gnus-newsgroup-expirable))
10565     ;; Set the mark in the buffer.
10566     (gnus-summary-update-mark mark 'unread)
10567     t))
10568
10569 (defun gnus-summary-mark-article-as-unread (mark)
10570   "Mark the current article quickly as unread with MARK."
10571   (let* ((article (gnus-summary-article-number))
10572          (old-mark (gnus-summary-article-mark article)))
10573     ;; Allow the backend to change the mark.
10574     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10575     (if (eq mark old-mark)
10576         t
10577       (if (<= article 0)
10578           (progn
10579             (gnus-error 1 "Can't mark negative article numbers")
10580             nil)
10581         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10582         (setq gnus-newsgroup-spam-marked
10583               (delq article gnus-newsgroup-spam-marked))
10584         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10585         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10586         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10587         (cond ((= mark gnus-ticked-mark)
10588                (setq gnus-newsgroup-marked
10589                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10590                                               article)))
10591               ((= mark gnus-spam-mark)
10592                (setq gnus-newsgroup-spam-marked
10593                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10594                                               article)))
10595               ((= mark gnus-dormant-mark)
10596                (setq gnus-newsgroup-dormant
10597                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10598                                               article)))
10599               (t
10600                (setq gnus-newsgroup-unreads
10601                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10602                                               article))))
10603         (gnus-pull article gnus-newsgroup-reads)
10604
10605         ;; See whether the article is to be put in the cache.
10606         (and gnus-use-cache
10607              (vectorp (gnus-summary-article-header article))
10608              (save-excursion
10609                (gnus-cache-possibly-enter-article
10610                 gnus-newsgroup-name article
10611                 (= mark gnus-ticked-mark)
10612                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10613
10614         ;; Fix the mark.
10615         (gnus-summary-update-mark mark 'unread)
10616         t))))
10617
10618 (defun gnus-summary-mark-article (&optional article mark no-expire)
10619   "Mark ARTICLE with MARK.  MARK can be any character.
10620 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10621 `??' (dormant) and `?E' (expirable).
10622 If MARK is nil, then the default character `?r' is used.
10623 If ARTICLE is nil, then the article on the current line will be
10624 marked.
10625 If NO-EXPIRE, auto-expiry will be inhibited."
10626   ;; The mark might be a string.
10627   (when (stringp mark)
10628     (setq mark (aref mark 0)))
10629   ;; If no mark is given, then we check auto-expiring.
10630   (when (null mark)
10631     (setq mark gnus-del-mark))
10632   (when (and (not no-expire)
10633              gnus-newsgroup-auto-expire
10634              (memq mark gnus-auto-expirable-marks))
10635     (setq mark gnus-expirable-mark))
10636   (let ((article (or article (gnus-summary-article-number)))
10637         (old-mark (gnus-summary-article-mark article)))
10638     ;; Allow the backend to change the mark.
10639     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10640     (if (eq mark old-mark)
10641         t
10642       (unless article
10643         (error "No article on current line"))
10644       (if (not (if (or (= mark gnus-unread-mark)
10645                        (= mark gnus-ticked-mark)
10646                        (= mark gnus-spam-mark)
10647                        (= mark gnus-dormant-mark))
10648                    (gnus-mark-article-as-unread article mark)
10649                  (gnus-mark-article-as-read article mark)))
10650           t
10651         ;; See whether the article is to be put in the cache.
10652         (and gnus-use-cache
10653              (not (= mark gnus-canceled-mark))
10654              (vectorp (gnus-summary-article-header article))
10655              (save-excursion
10656                (gnus-cache-possibly-enter-article
10657                 gnus-newsgroup-name article
10658                 (= mark gnus-ticked-mark)
10659                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10660
10661         (when (gnus-summary-goto-subject article nil t)
10662           (let ((inhibit-read-only t))
10663             (gnus-summary-show-thread)
10664             ;; Fix the mark.
10665             (gnus-summary-update-mark mark 'unread)
10666             t))))))
10667
10668 (defun gnus-summary-update-secondary-mark (article)
10669   "Update the secondary (read, process, cache) mark."
10670   (gnus-summary-update-mark
10671    (cond ((memq article gnus-newsgroup-processable)
10672           gnus-process-mark)
10673          ((memq article gnus-newsgroup-cached)
10674           gnus-cached-mark)
10675          ((memq article gnus-newsgroup-replied)
10676           gnus-replied-mark)
10677          ((memq article gnus-newsgroup-forwarded)
10678           gnus-forwarded-mark)
10679          ((memq article gnus-newsgroup-saved)
10680           gnus-saved-mark)
10681          ((memq article gnus-newsgroup-recent)
10682           gnus-recent-mark)
10683          ((memq article gnus-newsgroup-unseen)
10684           gnus-unseen-mark)
10685          (t gnus-no-mark))
10686    'replied)
10687   (when (gnus-visual-p 'summary-highlight 'highlight)
10688     (gnus-run-hooks 'gnus-summary-update-hook))
10689   t)
10690
10691 (defun gnus-summary-update-download-mark (article)
10692   "Update the download mark."
10693   (gnus-summary-update-mark
10694    (cond ((memq article gnus-newsgroup-undownloaded)
10695           gnus-undownloaded-mark)
10696          (gnus-newsgroup-agentized
10697           gnus-downloaded-mark)
10698          (t
10699           gnus-no-mark))
10700    'download)
10701   (gnus-summary-update-line t)
10702   t)
10703
10704 (defun gnus-summary-update-mark (mark type)
10705   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10706         (inhibit-read-only t))
10707     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10708     (when forward
10709       (when (looking-at "\r")
10710         (incf forward))
10711       (when (<= (+ forward (point)) (point-max))
10712         ;; Go to the right position on the line.
10713         (goto-char (+ forward (point)))
10714         ;; Replace the old mark with the new mark.
10715         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10716         ;; Optionally update the marks by some user rule.
10717         (when (eq type 'unread)
10718           (gnus-data-set-mark
10719            (gnus-data-find (gnus-summary-article-number)) mark)
10720           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10721
10722 (defun gnus-mark-article-as-read (article &optional mark)
10723   "Enter ARTICLE in the pertinent lists and remove it from others."
10724   ;; Make the article expirable.
10725   (let ((mark (or mark gnus-del-mark)))
10726     (setq gnus-newsgroup-expirable
10727           (if (= mark gnus-expirable-mark)
10728               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10729             (delq article gnus-newsgroup-expirable)))
10730     ;; Remove from unread and marked lists.
10731     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10732     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10733     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10734     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10735     (push (cons article mark) gnus-newsgroup-reads)
10736     ;; Possibly remove from cache, if that is used.
10737     (when gnus-use-cache
10738       (gnus-cache-enter-remove-article article))
10739     t))
10740
10741 (defun gnus-mark-article-as-unread (article &optional mark)
10742   "Enter ARTICLE in the pertinent lists and remove it from others."
10743   (let ((mark (or mark gnus-ticked-mark)))
10744     (if (<= article 0)
10745         (progn
10746           (gnus-error 1 "Can't mark negative article numbers")
10747           nil)
10748       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10749             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10750             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10751             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10752             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10753
10754       ;; Unsuppress duplicates?
10755       (when gnus-suppress-duplicates
10756         (gnus-dup-unsuppress-article article))
10757
10758       (cond ((= mark gnus-ticked-mark)
10759              (setq gnus-newsgroup-marked
10760                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10761             ((= mark gnus-spam-mark)
10762              (setq gnus-newsgroup-spam-marked
10763                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10764                                             article)))
10765             ((= mark gnus-dormant-mark)
10766              (setq gnus-newsgroup-dormant
10767                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10768             (t
10769              (setq gnus-newsgroup-unreads
10770                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10771       (gnus-pull article gnus-newsgroup-reads)
10772       t)))
10773
10774 (defalias 'gnus-summary-mark-as-unread-forward
10775   'gnus-summary-tick-article-forward)
10776 (make-obsolete 'gnus-summary-mark-as-unread-forward
10777                'gnus-summary-tick-article-forward)
10778 (defun gnus-summary-tick-article-forward (n)
10779   "Tick N articles forwards.
10780 If N is negative, tick backwards instead.
10781 The difference between N and the number of articles ticked is returned."
10782   (interactive "p")
10783   (gnus-summary-mark-forward n gnus-ticked-mark))
10784
10785 (defalias 'gnus-summary-mark-as-unread-backward
10786   'gnus-summary-tick-article-backward)
10787 (make-obsolete 'gnus-summary-mark-as-unread-backward
10788                'gnus-summary-tick-article-backward)
10789 (defun gnus-summary-tick-article-backward (n)
10790   "Tick N articles backwards.
10791 The difference between N and the number of articles ticked is returned."
10792   (interactive "p")
10793   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10794
10795 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10796 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10797 (defun gnus-summary-tick-article (&optional article clear-mark)
10798   "Mark current article as unread.
10799 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10800 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10801   (interactive)
10802   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10803                                        gnus-ticked-mark)))
10804
10805 (defun gnus-summary-mark-as-read-forward (n)
10806   "Mark N articles as read forwards.
10807 If N is negative, mark backwards instead.
10808 The difference between N and the actual number of articles marked is
10809 returned."
10810   (interactive "p")
10811   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10812
10813 (defun gnus-summary-mark-as-read-backward (n)
10814   "Mark the N articles as read backwards.
10815 The difference between N and the actual number of articles marked is
10816 returned."
10817   (interactive "p")
10818   (gnus-summary-mark-forward
10819    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10820
10821 (defun gnus-summary-mark-as-read (&optional article mark)
10822   "Mark current article as read.
10823 ARTICLE specifies the article to be marked as read.
10824 MARK specifies a string to be inserted at the beginning of the line."
10825   (gnus-summary-mark-article article mark))
10826
10827 (defun gnus-summary-clear-mark-forward (n)
10828   "Clear marks from N articles forward.
10829 If N is negative, clear backward instead.
10830 The difference between N and the number of marks cleared is returned."
10831   (interactive "p")
10832   (gnus-summary-mark-forward n gnus-unread-mark))
10833
10834 (defun gnus-summary-clear-mark-backward (n)
10835   "Clear marks from N articles backward.
10836 The difference between N and the number of marks cleared is returned."
10837   (interactive "p")
10838   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10839
10840 (defun gnus-summary-mark-unread-as-read ()
10841   "Intended to be used by `gnus-mark-article-hook'."
10842   (when (memq gnus-current-article gnus-newsgroup-unreads)
10843     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10844
10845 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10846   "Intended to be used by `gnus-mark-article-hook'."
10847   (let ((mark (gnus-summary-article-mark)))
10848     (when (or (gnus-unread-mark-p mark)
10849               (gnus-read-mark-p mark))
10850       (gnus-summary-mark-article gnus-current-article
10851                                  (or new-mark gnus-read-mark)))))
10852
10853 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10854   "Intended to be used by `gnus-mark-article-hook'."
10855   (let ((mark (gnus-summary-article-mark)))
10856     (when (or (gnus-unread-mark-p mark)
10857               (gnus-read-mark-p mark))
10858       (gnus-summary-mark-article (gnus-summary-article-number)
10859                                  (or new-mark gnus-read-mark)))))
10860
10861 (defun gnus-summary-mark-unread-as-ticked ()
10862   "Intended to be used by `gnus-mark-article-hook'."
10863   (when (memq gnus-current-article gnus-newsgroup-unreads)
10864     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10865
10866 (defun gnus-summary-mark-region-as-read (point mark all)
10867   "Mark all unread articles between point and mark as read.
10868 If given a prefix, mark all articles between point and mark as read,
10869 even ticked and dormant ones."
10870   (interactive "r\nP")
10871   (save-excursion
10872     (let (article)
10873       (goto-char point)
10874       (beginning-of-line)
10875       (while (and
10876               (< (point) mark)
10877               (progn
10878                 (when (or all
10879                           (memq (setq article (gnus-summary-article-number))
10880                                 gnus-newsgroup-unreads))
10881                   (gnus-summary-mark-article article gnus-del-mark))
10882                 t)
10883               (gnus-summary-find-next))))))
10884
10885 (defun gnus-summary-mark-below (score mark)
10886   "Mark articles with score less than SCORE with MARK."
10887   (interactive "P\ncMark: ")
10888   (setq score (if score
10889                   (prefix-numeric-value score)
10890                 (or gnus-summary-default-score 0)))
10891   (with-current-buffer gnus-summary-buffer
10892     (goto-char (point-min))
10893     (while
10894         (progn
10895           (and (< (gnus-summary-article-score) score)
10896                (gnus-summary-mark-article nil mark))
10897           (gnus-summary-find-next)))))
10898
10899 (defun gnus-summary-kill-below (&optional score)
10900   "Mark articles with score below SCORE as read."
10901   (interactive "P")
10902   (gnus-summary-mark-below score gnus-killed-mark))
10903
10904 (defun gnus-summary-clear-above (&optional score)
10905   "Clear all marks from articles with score above SCORE."
10906   (interactive "P")
10907   (gnus-summary-mark-above score gnus-unread-mark))
10908
10909 (defun gnus-summary-tick-above (&optional score)
10910   "Tick all articles with score above SCORE."
10911   (interactive "P")
10912   (gnus-summary-mark-above score gnus-ticked-mark))
10913
10914 (defun gnus-summary-mark-above (score mark)
10915   "Mark articles with score over SCORE with MARK."
10916   (interactive "P\ncMark: ")
10917   (setq score (if score
10918                   (prefix-numeric-value score)
10919                 (or gnus-summary-default-score 0)))
10920   (with-current-buffer gnus-summary-buffer
10921     (goto-char (point-min))
10922     (while (and (progn
10923                   (when (> (gnus-summary-article-score) score)
10924                     (gnus-summary-mark-article nil mark))
10925                   t)
10926                 (gnus-summary-find-next)))))
10927
10928 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10929 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10930 (defun gnus-summary-limit-include-expunged (&optional no-error)
10931   "Display all the hidden articles that were expunged for low scores."
10932   (interactive)
10933   (let ((inhibit-read-only t))
10934     (let ((scored gnus-newsgroup-scored)
10935           headers h)
10936       (while scored
10937         (unless (gnus-summary-article-header (caar scored))
10938           (and (setq h (gnus-number-to-header (caar scored)))
10939                (< (cdar scored) gnus-summary-expunge-below)
10940                (push h headers)))
10941         (setq scored (cdr scored)))
10942       (if (not headers)
10943           (when (not no-error)
10944             (error "No expunged articles hidden"))
10945         (goto-char (point-min))
10946         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10947         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10948         (dolist (x headers)
10949           (push (mail-header-number x) gnus-newsgroup-limit))
10950         (gnus-summary-prepare-unthreaded (nreverse headers))
10951         (goto-char (point-min))
10952         (gnus-summary-position-point)
10953         t))))
10954
10955 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10956   "Mark all unread articles in this newsgroup as read.
10957 If prefix argument ALL is non-nil, ticked and dormant articles will
10958 also be marked as read.
10959 If QUIETLY is non-nil, no questions will be asked.
10960
10961 If TO-HERE is non-nil, it should be a point in the buffer.  All
10962 articles before (after, if REVERSE is set) this point will be marked
10963 as read.
10964
10965 Note that this function will only catch up the unread article
10966 in the current summary buffer limitation.
10967
10968 The number of articles marked as read is returned."
10969   (interactive "P")
10970   (prog1
10971       (save-excursion
10972         (when (or quietly
10973                   (not gnus-interactive-catchup) ;Without confirmation?
10974                   gnus-expert-user
10975                   (gnus-y-or-n-p
10976                    (if all
10977                        "Mark absolutely all articles as read? "
10978                      "Mark all unread articles as read? ")))
10979           (if (and not-mark
10980                    (not gnus-newsgroup-adaptive)
10981                    (not gnus-newsgroup-auto-expire)
10982                    (not gnus-suppress-duplicates)
10983                    (or (not gnus-use-cache)
10984                        (eq gnus-use-cache 'passive)))
10985               (progn
10986                 (when all
10987                   (setq gnus-newsgroup-marked nil
10988                         gnus-newsgroup-spam-marked nil
10989                         gnus-newsgroup-dormant nil))
10990                 (setq gnus-newsgroup-unreads
10991                       (gnus-sorted-nunion
10992                        (gnus-sorted-intersection gnus-newsgroup-unreads
10993                                                  gnus-newsgroup-downloadable)
10994                        (gnus-sorted-difference gnus-newsgroup-unfetched
10995                                                gnus-newsgroup-cached))))
10996             ;; We actually mark all articles as canceled, which we
10997             ;; have to do when using auto-expiry or adaptive scoring.
10998             (gnus-summary-show-all-threads)
10999             (if (and to-here reverse)
11000                 (progn
11001                   (goto-char to-here)
11002                   (gnus-summary-mark-current-read-and-unread-as-read
11003                    gnus-catchup-mark)
11004                   (while (gnus-summary-find-next (not all))
11005                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
11006               (when (gnus-summary-first-subject (not all))
11007                 (while (and
11008                         (if to-here (< (point) to-here) t)
11009                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
11010                         (gnus-summary-find-next (not all))))))
11011             (gnus-set-mode-line 'summary))
11012           t))
11013     (gnus-summary-position-point)))
11014
11015 (defun gnus-summary-catchup-to-here (&optional all)
11016   "Mark all unticked articles before the current one as read.
11017 If ALL is non-nil, also mark ticked and dormant articles as read."
11018   (interactive "P")
11019   (save-excursion
11020     (gnus-save-hidden-threads
11021       (let ((beg (point)))
11022         ;; We check that there are unread articles.
11023         (when (or all (gnus-summary-find-prev))
11024           (gnus-summary-catchup all t beg)))))
11025   (gnus-summary-position-point))
11026
11027 (defun gnus-summary-catchup-from-here (&optional all)
11028   "Mark all unticked articles after (and including) the current one as read.
11029 If ALL is non-nil, also mark ticked and dormant articles as read."
11030   (interactive "P")
11031   (save-excursion
11032     (gnus-save-hidden-threads
11033       (let ((beg (point)))
11034         ;; We check that there are unread articles.
11035         (when (or all (gnus-summary-find-next))
11036           (gnus-summary-catchup all t beg nil t)))))
11037   (gnus-summary-position-point))
11038
11039 (defun gnus-summary-catchup-all (&optional quietly)
11040   "Mark all articles in this newsgroup as read.
11041 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11042 instead, which marks only unread articles as read."
11043   (interactive "P")
11044   (gnus-summary-catchup t quietly))
11045
11046 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11047   "Mark all unread articles in this group as read, then exit.
11048 If prefix argument ALL is non-nil, all articles are marked as read.
11049 If QUIETLY is non-nil, no questions will be asked."
11050   (interactive "P")
11051   (when (gnus-summary-catchup all quietly nil 'fast)
11052     ;; Select next newsgroup or exit.
11053     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11054              (eq gnus-auto-select-next 'quietly))
11055         (gnus-summary-next-group nil)
11056       (gnus-summary-exit))))
11057
11058 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11059   "Mark all articles in this newsgroup as read, and then exit.
11060 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11061 instead, which marks only unread articles as read."
11062   (interactive "P")
11063   (gnus-summary-catchup-and-exit t quietly))
11064
11065 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11066   "Mark all articles in this group as read and select the next group.
11067 If given a prefix, mark all articles, unread as well as ticked, as
11068 read."
11069   (interactive "P")
11070   (save-excursion
11071     (gnus-summary-catchup all))
11072   (gnus-summary-next-group))
11073
11074 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11075   "Mark all articles in this group as read and select the previous group.
11076 If given a prefix, mark all articles, unread as well as ticked, as
11077 read."
11078   (interactive "P")
11079   (save-excursion
11080     (gnus-summary-catchup all))
11081   (gnus-summary-next-group nil nil t))
11082
11083 ;;;
11084 ;;; with article
11085 ;;;
11086
11087 (defmacro gnus-with-article (article &rest forms)
11088   "Select ARTICLE and perform FORMS in the original article buffer.
11089 Then replace the article with the result."
11090   `(progn
11091      ;; We don't want the article to be marked as read.
11092      (let (gnus-mark-article-hook)
11093        (gnus-summary-select-article t t nil ,article))
11094      (set-buffer gnus-original-article-buffer)
11095      ,@forms
11096      (if (not (gnus-check-backend-function
11097                'request-replace-article (car gnus-article-current)))
11098          (gnus-message 5 "Read-only group; not replacing")
11099        (unless (gnus-request-replace-article
11100                 ,article (car gnus-article-current)
11101                 (current-buffer) t)
11102          (error "Couldn't replace article")))
11103      ;; The cache and backlog have to be flushed somewhat.
11104      (when gnus-keep-backlog
11105        (gnus-backlog-remove-article
11106         (car gnus-article-current) (cdr gnus-article-current)))
11107      (when gnus-use-cache
11108        (gnus-cache-update-article
11109         (car gnus-article-current) (cdr gnus-article-current)))))
11110
11111 (put 'gnus-with-article 'lisp-indent-function 1)
11112 (put 'gnus-with-article 'edebug-form-spec '(form body))
11113
11114 ;; Thread-based commands.
11115
11116 (defun gnus-summary-articles-in-thread (&optional article)
11117   "Return a list of all articles in the current thread.
11118 If ARTICLE is non-nil, return all articles in the thread that starts
11119 with that article."
11120   (let* ((article (or article (gnus-summary-article-number)))
11121          (data (gnus-data-find-list article))
11122          (top-level (gnus-data-level (car data)))
11123          (top-subject
11124           (cond ((null gnus-thread-operation-ignore-subject)
11125                  (gnus-simplify-subject-re
11126                   (mail-header-subject (gnus-data-header (car data)))))
11127                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11128                  (gnus-simplify-subject-fuzzy
11129                   (mail-header-subject (gnus-data-header (car data)))))
11130                 (t nil)))
11131          (end-point (save-excursion
11132                       (if (gnus-summary-go-to-next-thread)
11133                           (point) (point-max))))
11134          articles)
11135     (while (and data
11136                 (< (gnus-data-pos (car data)) end-point))
11137       (when (or (not top-subject)
11138                 (string= top-subject
11139                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11140                              (gnus-simplify-subject-fuzzy
11141                               (mail-header-subject
11142                                (gnus-data-header (car data))))
11143                            (gnus-simplify-subject-re
11144                             (mail-header-subject
11145                              (gnus-data-header (car data)))))))
11146         (push (gnus-data-number (car data)) articles))
11147       (unless (and (setq data (cdr data))
11148                    (> (gnus-data-level (car data)) top-level))
11149         (setq data nil)))
11150     ;; Return the list of articles.
11151     (nreverse articles)))
11152
11153 (defun gnus-summary-rethread-current ()
11154   "Rethread the thread the current article is part of."
11155   (interactive)
11156   (let* ((gnus-show-threads t)
11157          (article (gnus-summary-article-number))
11158          (id (mail-header-id (gnus-summary-article-header)))
11159          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11160     (unless id
11161       (error "No article on the current line"))
11162     (gnus-rebuild-thread id)
11163     (gnus-summary-goto-subject article)))
11164
11165 (defun gnus-summary-reparent-thread ()
11166   "Make the current article child of the marked (or previous) article.
11167
11168 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11169 is non-nil or the Subject: of both articles are the same."
11170   (interactive)
11171   (unless (not (gnus-group-read-only-p))
11172     (error "The current newsgroup does not support article editing"))
11173   (unless (<= (length gnus-newsgroup-processable) 1)
11174     (error "No more than one article may be marked"))
11175   (let ((child (gnus-summary-article-number))
11176         ;; First grab the marked article, otherwise one line up.
11177         (parent (if (not (null gnus-newsgroup-processable))
11178                     (car gnus-newsgroup-processable)
11179                   (save-excursion
11180                     (if (eq (forward-line -1) 0)
11181                         (gnus-summary-article-number)
11182                       (error "Beginning of summary buffer"))))))
11183     (gnus-summary-reparent-children parent (list child))))
11184
11185 (defun gnus-summary-reparent-children (parent children)
11186   "Make PARENT the parent of CHILDREN.
11187 When called interactively, PARENT is the current article and CHILDREN
11188 are the process-marked articles."
11189   (interactive
11190    (list (gnus-summary-article-number)
11191          (gnus-summary-work-articles nil)))
11192   (dolist (child children)
11193     (save-window-excursion
11194       (let ((gnus-article-buffer " *reparent*"))
11195         (unless (not (eq parent child))
11196           (error "An article may not be self-referential"))
11197         (let ((message-id (mail-header-id
11198                            (gnus-summary-article-header parent))))
11199           (unless (and message-id (not (equal message-id "")))
11200             (error "No message-id in desired parent"))
11201           (gnus-with-article child
11202             (save-restriction
11203               (goto-char (point-min))
11204               (message-narrow-to-head)
11205               (if (re-search-forward "^References: " nil t)
11206                   (progn
11207                     (re-search-forward "^[^ \t]" nil t)
11208                     (forward-line -1)
11209                     (end-of-line)
11210                     (insert " " message-id))
11211                 (insert "References: " message-id "\n"))))
11212           (set-buffer gnus-summary-buffer)
11213           (gnus-summary-unmark-all-processable)
11214           (gnus-summary-update-article child)
11215           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11216             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11217           (gnus-summary-rethread-current)
11218           (gnus-message 3 "Article %d is now the child of article %d"
11219                         child parent))))))
11220
11221 (defun gnus-summary-toggle-threads (&optional arg)
11222   "Toggle showing conversation threads.
11223 If ARG is positive number, turn showing conversation threads on."
11224   (interactive "P")
11225   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11226     (setq gnus-show-threads
11227           (if (null arg) (not gnus-show-threads)
11228             (> (prefix-numeric-value arg) 0)))
11229     (gnus-summary-prepare)
11230     (gnus-summary-goto-subject current)
11231     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11232     (gnus-summary-position-point)))
11233
11234 (defun gnus-summary-show-all-threads ()
11235   "Show all threads."
11236   (interactive)
11237   (save-excursion
11238     (let ((buffer-read-only nil))
11239       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11240   (gnus-summary-position-point))
11241
11242 (defun gnus-summary-show-thread ()
11243   "Show thread subtrees.
11244 Returns nil if no thread was there to be shown."
11245   (interactive)
11246   (let ((buffer-read-only nil)
11247         (orig (point))
11248         (end (point-at-eol))
11249         ;; Leave point at bol
11250         (beg (progn (beginning-of-line) (point))))
11251     (prog1
11252         ;; Any hidden lines here?
11253         (search-forward "\r" end t)
11254       (subst-char-in-region beg end ?\^M ?\n t)
11255       (goto-char orig)
11256       (gnus-summary-position-point))))
11257
11258 (defun gnus-summary-maybe-hide-threads ()
11259   "If requested, hide the threads that should be hidden."
11260   (when (and gnus-show-threads
11261              gnus-thread-hide-subtree)
11262     (gnus-summary-hide-all-threads
11263      (if (or (consp gnus-thread-hide-subtree)
11264              (functionp gnus-thread-hide-subtree))
11265          (gnus-make-predicate gnus-thread-hide-subtree)
11266        nil))))
11267
11268 ;;; Hiding predicates.
11269
11270 (defun gnus-article-unread-p (header)
11271   (memq (mail-header-number header) gnus-newsgroup-unreads))
11272
11273 (defun gnus-article-unseen-p (header)
11274   (memq (mail-header-number header) gnus-newsgroup-unseen))
11275
11276 (defun gnus-map-articles (predicate articles)
11277   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11278   (apply 'gnus-or (mapcar predicate
11279                           (mapcar (lambda (number)
11280                                     (gnus-summary-article-header number))
11281                                   articles))))
11282
11283 (defun gnus-summary-hide-all-threads (&optional predicate)
11284   "Hide all thread subtrees.
11285 If PREDICATE is supplied, threads that satisfy this predicate
11286 will not be hidden."
11287   (interactive)
11288   (save-excursion
11289     (goto-char (point-min))
11290     (let ((end nil))
11291       (while (not end)
11292         (when (or (not predicate)
11293                   (gnus-map-articles
11294                    predicate (gnus-summary-article-children)))
11295             (gnus-summary-hide-thread))
11296         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11297   (gnus-summary-position-point))
11298
11299 (defun gnus-summary-hide-thread ()
11300   "Hide thread subtrees.
11301 If PREDICATE is supplied, threads that satisfy this predicate
11302 will not be hidden.
11303 Returns nil if no threads were there to be hidden."
11304   (interactive)
11305   (let ((buffer-read-only nil)
11306         (start (point))
11307         (article (gnus-summary-article-number)))
11308     (goto-char start)
11309     ;; Go forward until either the buffer ends or the subthread ends.
11310     (when (and (not (eobp))
11311                (or (zerop (gnus-summary-next-thread 1 t))
11312                    (goto-char (point-max))))
11313       (prog1
11314           (if (and (> (point) start)
11315                    (search-backward "\n" start t))
11316               (progn
11317                 (subst-char-in-region start (point) ?\n ?\^M)
11318                 (gnus-summary-goto-subject article))
11319             (goto-char start)
11320             nil)))))
11321
11322 (defun gnus-summary-go-to-next-thread (&optional previous)
11323   "Go to the same level (or less) next thread.
11324 If PREVIOUS is non-nil, go to previous thread instead.
11325 Return the article number moved to, or nil if moving was impossible."
11326   (let ((level (gnus-summary-thread-level))
11327         (way (if previous -1 1))
11328         (beg (point)))
11329     (forward-line way)
11330     (while (and (not (eobp))
11331                 (< level (gnus-summary-thread-level)))
11332       (forward-line way))
11333     (if (eobp)
11334         (progn
11335           (goto-char beg)
11336           nil)
11337       (setq beg (point))
11338       (prog1
11339           (gnus-summary-article-number)
11340         (goto-char beg)))))
11341
11342 (defun gnus-summary-next-thread (n &optional silent)
11343   "Go to the same level next N'th thread.
11344 If N is negative, search backward instead.
11345 Returns the difference between N and the number of skips actually
11346 done.
11347
11348 If SILENT, don't output messages."
11349   (interactive "p")
11350   (let ((backward (< n 0))
11351         (n (abs n)))
11352     (while (and (> n 0)
11353                 (gnus-summary-go-to-next-thread backward))
11354       (decf n))
11355     (unless silent
11356       (gnus-summary-position-point))
11357     (when (and (not silent) (/= 0 n))
11358       (gnus-message 7 "No more threads"))
11359     n))
11360
11361 (defun gnus-summary-prev-thread (n)
11362   "Go to the same level previous N'th thread.
11363 Returns the difference between N and the number of skips actually
11364 done."
11365   (interactive "p")
11366   (gnus-summary-next-thread (- n)))
11367
11368 (defun gnus-summary-go-down-thread ()
11369   "Go down one level in the current thread."
11370   (let ((children (gnus-summary-article-children)))
11371     (when children
11372       (gnus-summary-goto-subject (car children)))))
11373
11374 (defun gnus-summary-go-up-thread ()
11375   "Go up one level in the current thread."
11376   (let ((parent (gnus-summary-article-parent)))
11377     (when parent
11378       (gnus-summary-goto-subject parent))))
11379
11380 (defun gnus-summary-down-thread (n)
11381   "Go down thread N steps.
11382 If N is negative, go up instead.
11383 Returns the difference between N and how many steps down that were
11384 taken."
11385   (interactive "p")
11386   (let ((up (< n 0))
11387         (n (abs n)))
11388     (while (and (> n 0)
11389                 (if up (gnus-summary-go-up-thread)
11390                   (gnus-summary-go-down-thread)))
11391       (setq n (1- n)))
11392     (gnus-summary-position-point)
11393     (when (/= 0 n)
11394       (gnus-message 7 "Can't go further"))
11395     n))
11396
11397 (defun gnus-summary-up-thread (n)
11398   "Go up thread N steps.
11399 If N is negative, go down instead.
11400 Returns the difference between N and how many steps down that were
11401 taken."
11402   (interactive "p")
11403   (gnus-summary-down-thread (- n)))
11404
11405 (defun gnus-summary-top-thread ()
11406   "Go to the top of the thread."
11407   (interactive)
11408   (while (gnus-summary-go-up-thread))
11409   (gnus-summary-article-number))
11410
11411 (defun gnus-summary-expire-thread ()
11412   "Mark articles under current thread as expired."
11413   (interactive)
11414   (gnus-summary-kill-thread 0))
11415
11416 (defun gnus-summary-kill-thread (&optional unmark)
11417   "Mark articles under current thread as read.
11418 If the prefix argument is positive, remove any kinds of marks.
11419 If the prefix argument is zero, mark thread as expired.
11420 If the prefix argument is negative, tick articles instead."
11421   (interactive "P")
11422   (when unmark
11423     (setq unmark (prefix-numeric-value unmark)))
11424   (let ((articles (gnus-summary-articles-in-thread))
11425         (hide (or (null unmark) (= unmark 0))))
11426     (save-excursion
11427       ;; Expand the thread.
11428       (gnus-summary-show-thread)
11429       ;; Mark all the articles.
11430       (while articles
11431         (gnus-summary-goto-subject (car articles))
11432         (cond ((null unmark)
11433                (gnus-summary-mark-article-as-read gnus-killed-mark))
11434               ((> unmark 0)
11435                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11436               ((= unmark 0)
11437                (gnus-summary-mark-article-as-unread gnus-expirable-mark))
11438               (t
11439                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11440         (setq articles (cdr articles))))
11441     ;; Hide killed subtrees when hide is true.
11442     (and hide
11443          gnus-thread-hide-killed
11444          (gnus-summary-hide-thread))
11445     ;; If hide is t, go to next unread subject.
11446     (when hide
11447       ;; Go to next unread subject.
11448       (gnus-summary-next-subject 1 t)))
11449   (gnus-set-mode-line 'summary))
11450
11451 ;; Summary sorting commands
11452
11453 (defun gnus-summary-sort-by-number (&optional reverse)
11454   "Sort the summary buffer by article number.
11455 Argument REVERSE means reverse order."
11456   (interactive "P")
11457   (gnus-summary-sort 'number reverse))
11458
11459 (defun gnus-summary-sort-by-random (&optional reverse)
11460   "Randomize the order in the summary buffer.
11461 Argument REVERSE means to randomize in reverse order."
11462   (interactive "P")
11463   (gnus-summary-sort 'random reverse))
11464
11465 (defun gnus-summary-sort-by-author (&optional reverse)
11466   "Sort the summary buffer by author name alphabetically.
11467 If `case-fold-search' is non-nil, case of letters is ignored.
11468 Argument REVERSE means reverse order."
11469   (interactive "P")
11470   (gnus-summary-sort 'author reverse))
11471
11472 (defun gnus-summary-sort-by-recipient (&optional reverse)
11473   "Sort the summary buffer by recipient name alphabetically.
11474 If `case-fold-search' is non-nil, case of letters is ignored.
11475 Argument REVERSE means reverse order."
11476   (interactive "P")
11477   (gnus-summary-sort 'recipient reverse))
11478
11479 (defun gnus-summary-sort-by-subject (&optional reverse)
11480   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11481 If `case-fold-search' is non-nil, case of letters is ignored.
11482 Argument REVERSE means reverse order."
11483   (interactive "P")
11484   (gnus-summary-sort 'subject reverse))
11485
11486 (defun gnus-summary-sort-by-date (&optional reverse)
11487   "Sort the summary buffer by date.
11488 Argument REVERSE means reverse order."
11489   (interactive "P")
11490   (gnus-summary-sort 'date reverse))
11491
11492 (defun gnus-summary-sort-by-score (&optional reverse)
11493   "Sort the summary buffer by score.
11494 Argument REVERSE means reverse order."
11495   (interactive "P")
11496   (gnus-summary-sort 'score reverse))
11497
11498 (defun gnus-summary-sort-by-lines (&optional reverse)
11499   "Sort the summary buffer by the number of lines.
11500 Argument REVERSE means reverse order."
11501   (interactive "P")
11502   (gnus-summary-sort 'lines reverse))
11503
11504 (defun gnus-summary-sort-by-chars (&optional reverse)
11505   "Sort the summary buffer by article length.
11506 Argument REVERSE means reverse order."
11507   (interactive "P")
11508   (gnus-summary-sort 'chars reverse))
11509
11510 (defun gnus-summary-sort-by-original (&optional reverse)
11511   "Sort the summary buffer using the default sorting method.
11512 Argument REVERSE means reverse order."
11513   (interactive "P")
11514   (let* ((inhibit-read-only t)
11515          (gnus-summary-prepare-hook nil))
11516     ;; We do the sorting by regenerating the threads.
11517     (gnus-summary-prepare)
11518     ;; Hide subthreads if needed.
11519     (gnus-summary-maybe-hide-threads)))
11520
11521 (defun gnus-summary-sort (predicate reverse)
11522   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11523   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11524          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11525          (gnus-thread-sort-functions
11526           (if (not reverse)
11527               thread
11528             `(lambda (t1 t2)
11529                (,thread t2 t1))))
11530          (gnus-sort-gathered-threads-function
11531           gnus-thread-sort-functions)
11532          (gnus-article-sort-functions
11533           (if (not reverse)
11534               article
11535             `(lambda (t1 t2)
11536                (,article t2 t1))))
11537          (inhibit-read-only t)
11538          (gnus-summary-prepare-hook nil))
11539     ;; We do the sorting by regenerating the threads.
11540     (gnus-summary-prepare)
11541     ;; Hide subthreads if needed.
11542     (gnus-summary-maybe-hide-threads)))
11543
11544 ;; Summary saving commands.
11545
11546 (defun gnus-summary-save-article (&optional n not-saved)
11547   "Save the current article using the default saver function.
11548 If N is a positive number, save the N next articles.
11549 If N is a negative number, save the N previous articles.
11550 If N is nil and any articles have been marked with the process mark,
11551 save those articles instead.
11552 The variable `gnus-default-article-saver' specifies the saver function.
11553
11554 If the optional second argument NOT-SAVED is non-nil, articles saved
11555 will not be marked as saved."
11556   (interactive "P")
11557   (require 'gnus-art)
11558   (let* ((articles (gnus-summary-work-articles n))
11559          (save-buffer (save-excursion
11560                         (nnheader-set-temp-buffer " *Gnus Save*")))
11561          (num (length articles))
11562          ;; Whether to save decoded articles or raw articles.
11563          (decode (when gnus-article-save-coding-system
11564                    (get gnus-default-article-saver :decode)))
11565          ;; When saving many articles in a single file, use the other
11566          ;; function to save articles other than the first one.
11567          (saver2 (get gnus-default-article-saver :function))
11568          (gnus-prompt-before-saving (if saver2
11569                                         t
11570                                       gnus-prompt-before-saving))
11571          (gnus-default-article-saver gnus-default-article-saver)
11572          header file)
11573     (dolist (article articles)
11574       (setq header (gnus-summary-article-header article))
11575       (if (not (vectorp header))
11576           ;; This is a pseudo-article.
11577           (if (assq 'name header)
11578               (gnus-copy-file (cdr (assq 'name header)))
11579             (gnus-message 1 "Article %d is unsaveable" article))
11580         ;; This is a real article.
11581         (save-window-excursion
11582           (let ((gnus-display-mime-function (when decode
11583                                               gnus-display-mime-function))
11584                 (gnus-article-prepare-hook (when decode
11585                                              gnus-article-prepare-hook)))
11586             (gnus-summary-select-article t nil nil article)
11587             (gnus-summary-goto-subject article)))
11588         (with-current-buffer save-buffer
11589           (erase-buffer)
11590           (insert-buffer-substring (if decode
11591                                        gnus-article-buffer
11592                                      gnus-original-article-buffer)))
11593         (setq file (gnus-article-save save-buffer file num))
11594         (gnus-summary-remove-process-mark article)
11595         (unless not-saved
11596           (gnus-summary-set-saved-mark article)))
11597       (when saver2
11598         (setq gnus-default-article-saver saver2
11599               saver2 nil)))
11600     (gnus-kill-buffer save-buffer)
11601     (gnus-summary-position-point)
11602     (gnus-set-mode-line 'summary)
11603     n))
11604
11605 (defun gnus-summary-pipe-output (&optional arg headers)
11606   "Pipe the current article to a subprocess.
11607 If N is a positive number, pipe the N next articles.
11608 If N is a negative number, pipe the N previous articles.
11609 If N is nil and any articles have been marked with the process mark,
11610 pipe those articles instead.
11611 If HEADERS (the symbolic prefix), include the headers, too."
11612   (interactive (gnus-interactive "P\ny"))
11613   (require 'gnus-art)
11614   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11615         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11616     (gnus-summary-save-article arg t))
11617   (let ((buffer (get-buffer "*Shell Command Output*")))
11618     (when (and buffer
11619                (not (zerop (buffer-size buffer))))
11620       (gnus-configure-windows 'pipe))))
11621
11622 (defun gnus-summary-save-article-mail (&optional arg)
11623   "Append the current article to a Unix mail box file.
11624 If N is a positive number, save the N next articles.
11625 If N is a negative number, save the N previous articles.
11626 If N is nil and any articles have been marked with the process mark,
11627 save those articles instead."
11628   (interactive "P")
11629   (require 'gnus-art)
11630   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11631     (gnus-summary-save-article arg)))
11632
11633 (defun gnus-summary-save-article-rmail (&optional arg)
11634   "Append the current article to an rmail file.
11635 If N is a positive number, save the N next articles.
11636 If N is a negative number, save the N previous articles.
11637 If N is nil and any articles have been marked with the process mark,
11638 save those articles instead."
11639   (interactive "P")
11640   (require 'gnus-art)
11641   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11642     (gnus-summary-save-article arg)))
11643
11644 (defun gnus-summary-save-article-file (&optional arg)
11645   "Append the current article to a file.
11646 If N is a positive number, save the N next articles.
11647 If N is a negative number, save the N previous articles.
11648 If N is nil and any articles have been marked with the process mark,
11649 save those articles instead."
11650   (interactive "P")
11651   (require 'gnus-art)
11652   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11653     (gnus-summary-save-article arg)))
11654
11655 (defun gnus-summary-write-article-file (&optional arg)
11656   "Write the current article to a file, deleting the previous file.
11657 If N is a positive number, save the N next articles.
11658 If N is a negative number, save the N previous articles.
11659 If N is nil and any articles have been marked with the process mark,
11660 save those articles instead."
11661   (interactive "P")
11662   (require 'gnus-art)
11663   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11664     (gnus-summary-save-article arg)))
11665
11666 (defun gnus-summary-save-article-body-file (&optional arg)
11667   "Append the current article body to a file.
11668 If N is a positive number, save the N next articles.
11669 If N is a negative number, save the N previous articles.
11670 If N is nil and any articles have been marked with the process mark,
11671 save those articles instead."
11672   (interactive "P")
11673   (require 'gnus-art)
11674   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11675     (gnus-summary-save-article arg)))
11676
11677 (defun gnus-summary-write-article-body-file (&optional arg)
11678   "Write the current article body to a file, deleting the previous file.
11679 If N is a positive number, save the N next articles.
11680 If N is a negative number, save the N previous articles.
11681 If N is nil and any articles have been marked with the process mark,
11682 save those articles instead."
11683   (interactive "P")
11684   (require 'gnus-art)
11685   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11686     (gnus-summary-save-article arg)))
11687
11688 (defun gnus-summary-muttprint (&optional arg)
11689   "Print the current article using Muttprint.
11690 If N is a positive number, save the N next articles.
11691 If N is a negative number, save the N previous articles.
11692 If N is nil and any articles have been marked with the process mark,
11693 save those articles instead."
11694   (interactive "P")
11695   (require 'gnus-art)
11696   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11697     (gnus-summary-save-article arg t)))
11698
11699 (defun gnus-summary-pipe-message (program)
11700   "Pipe the current article through PROGRAM."
11701   (interactive "sProgram: ")
11702   (gnus-summary-select-article)
11703   (let ((mail-header-separator ""))
11704     (gnus-eval-in-buffer-window gnus-article-buffer
11705       (save-restriction
11706         (widen)
11707         (let ((start (window-start))
11708               (inhibit-read-only t))
11709           (message-pipe-buffer-body program)
11710           (set-window-start (get-buffer-window (current-buffer)) start))))))
11711
11712 (defun gnus-get-split-value (methods)
11713   "Return a value based on the split METHODS."
11714   (let (split-name method result match)
11715     (when methods
11716       (with-current-buffer gnus-original-article-buffer
11717         (save-restriction
11718           (nnheader-narrow-to-headers)
11719           (while (and methods (not split-name))
11720             (goto-char (point-min))
11721             (setq method (pop methods))
11722             (setq match (car method))
11723             (when (cond
11724                    ((stringp match)
11725                     ;; Regular expression.
11726                     (ignore-errors
11727                       (re-search-forward match nil t)))
11728                    ((functionp match)
11729                     ;; Function.
11730                     (save-restriction
11731                       (widen)
11732                       (setq result (funcall match gnus-newsgroup-name))))
11733                    ((consp match)
11734                     ;; Form.
11735                     (save-restriction
11736                       (widen)
11737                       (setq result (eval match)))))
11738               (setq split-name (cdr method))
11739               (cond ((stringp result)
11740                      (push (expand-file-name
11741                             result gnus-article-save-directory)
11742                            split-name))
11743                     ((consp result)
11744                      (setq split-name (append result split-name)))))))))
11745     (nreverse split-name)))
11746
11747 (defun gnus-valid-move-group-p (group)
11748   (and (boundp group)
11749        (symbol-name group)
11750        (symbol-value group)
11751        (gnus-get-function (gnus-find-method-for-group
11752                            (symbol-name group)) 'request-accept-article t)))
11753
11754 (defun gnus-read-move-group-name (prompt default articles prefix)
11755   "Read a group name."
11756   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11757          (minibuffer-confirm-incomplete nil) ; XEmacs
11758          (prom
11759           (format "%s %s to"
11760                   prompt
11761                   (if (> (length articles) 1)
11762                       (format "these %d articles" (length articles))
11763                     "this article")))
11764          (to-newsgroup
11765           (let (active group)
11766             (when (or (null split-name) (= 1 (length split-name)))
11767               (setq active (gnus-make-hashtable (length gnus-active-hashtb)))
11768               (mapatoms (lambda (symbol)
11769                           (setq group (symbol-name symbol))
11770                           (when (string-match "[^\000-\177]" group)
11771                             (setq group (gnus-group-decoded-name group)))
11772                           (set (intern group active) group))
11773                         gnus-active-hashtb))
11774             (cond
11775              ((null split-name)
11776               (gnus-completing-read-with-default
11777                default prom active 'gnus-valid-move-group-p nil prefix
11778                'gnus-group-history))
11779              ((= 1 (length split-name))
11780               (gnus-completing-read-with-default
11781                (car split-name) prom active 'gnus-valid-move-group-p nil nil
11782                'gnus-group-history))
11783              (t
11784               (gnus-completing-read-with-default
11785                nil prom (mapcar 'list (nreverse split-name)) nil nil nil
11786                'gnus-group-history)))))
11787          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
11788          encoded)
11789     (when to-newsgroup
11790       (if (or (string= to-newsgroup "")
11791               (string= to-newsgroup prefix))
11792           (setq to-newsgroup default))
11793       (unless to-newsgroup
11794         (error "No group name entered"))
11795       (setq encoded (mm-encode-coding-string
11796                      to-newsgroup
11797                      (gnus-group-name-charset to-method to-newsgroup)))
11798       (or (gnus-active encoded)
11799           (gnus-activate-group encoded nil nil to-method)
11800           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11801                                      to-newsgroup))
11802               (or (and (gnus-request-create-group encoded to-method)
11803                        (gnus-activate-group encoded nil nil to-method)
11804                        (gnus-subscribe-group encoded))
11805                   (error "Couldn't create group %s" to-newsgroup)))
11806           (error "No such group: %s" to-newsgroup))
11807       encoded)))
11808
11809 (defvar gnus-summary-save-parts-counter)
11810 (declare-function mm-uu-dissect "mm-uu" (&optional noheader mime-type))
11811
11812 (defun gnus-summary-save-parts (type dir n &optional reverse)
11813   "Save parts matching TYPE to DIR.
11814 If REVERSE, save parts that do not match TYPE."
11815   (interactive
11816    (list (read-string "Save parts of type: "
11817                       (or (car gnus-summary-save-parts-type-history)
11818                           gnus-summary-save-parts-default-mime)
11819                       'gnus-summary-save-parts-type-history)
11820          (setq gnus-summary-save-parts-last-directory
11821                (read-file-name "Save to directory: "
11822                                gnus-summary-save-parts-last-directory
11823                                nil t))
11824          current-prefix-arg))
11825   (gnus-summary-iterate n
11826     (let ((gnus-display-mime-function nil)
11827           gnus-article-prepare-hook
11828           gnus-article-decode-hook
11829           gnus-display-mime-function
11830           gnus-break-pages
11831           (gnus-inhibit-treatment t))
11832       (gnus-summary-select-article))
11833     (with-current-buffer gnus-article-buffer
11834       (let ((handles (or gnus-article-mime-handles
11835                          (mm-dissect-buffer nil gnus-article-loose-mime)
11836                          (and gnus-article-emulate-mime
11837                               (mm-uu-dissect))))
11838             (gnus-summary-save-parts-counter 1))
11839         (when handles
11840           (gnus-summary-save-parts-1 type dir handles reverse)
11841           (unless gnus-article-mime-handles ;; Don't destroy this case.
11842             (mm-destroy-parts handles)))))))
11843
11844 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11845   (if (stringp (car handle))
11846       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11847               (cdr handle))
11848     (when (if reverse
11849               (not (string-match type (mm-handle-media-type handle)))
11850             (string-match type (mm-handle-media-type handle)))
11851       (let ((file (expand-file-name
11852                    (gnus-map-function
11853                     mm-file-name-rewrite-functions
11854                     (file-name-nondirectory
11855                      (or
11856                       (mail-content-type-get
11857                        (mm-handle-disposition handle) 'filename)
11858                       (mail-content-type-get
11859                        (mm-handle-type handle) 'name)
11860                       (format "%s.%d.%d" gnus-newsgroup-name
11861                               (cdr gnus-article-current)
11862                               gnus-summary-save-parts-counter))))
11863                    dir)))
11864         (incf gnus-summary-save-parts-counter)
11865         (unless (file-exists-p file)
11866           (mm-save-part-to-file handle file))))))
11867
11868 ;; Summary extract commands
11869
11870 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11871   (let ((inhibit-read-only t)
11872         (article (gnus-summary-article-number))
11873         after-article b e)
11874     (unless (gnus-summary-goto-subject article)
11875       (error "No such article: %d" article))
11876     (gnus-summary-position-point)
11877     ;; If all commands are to be bunched up on one line, we collect
11878     ;; them here.
11879     (unless gnus-view-pseudos-separately
11880       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11881             files action)
11882         (while ps
11883           (setq action (cdr (assq 'action (car ps))))
11884           (setq files (list (cdr (assq 'name (car ps)))))
11885           (while (and ps (cdr ps)
11886                       (string= (or action "1")
11887                                (or (cdr (assq 'action (cadr ps))) "2")))
11888             (push (cdr (assq 'name (cadr ps))) files)
11889             (setcdr ps (cddr ps)))
11890           (when files
11891             (when (not (string-match "%s" action))
11892               (push " " files))
11893             (push " " files)
11894             (when (assq 'execute (car ps))
11895               (setcdr (assq 'execute (car ps))
11896                       (funcall (if (string-match "%s" action)
11897                                    'format 'concat)
11898                                action
11899                                (mapconcat
11900                                 (lambda (f)
11901                                   (if (equal f " ")
11902                                       f
11903                                     (shell-quote-argument f)))
11904                                 files " ")))))
11905           (setq ps (cdr ps)))))
11906     (if (and gnus-view-pseudos (not not-view))
11907         (while pslist
11908           (when (assq 'execute (car pslist))
11909             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11910                                   (eq gnus-view-pseudos 'not-confirm)))
11911           (setq pslist (cdr pslist)))
11912       (save-excursion
11913         (while pslist
11914           (setq after-article (or (cdr (assq 'article (car pslist)))
11915                                   (gnus-summary-article-number)))
11916           (gnus-summary-goto-subject after-article)
11917           (forward-line 1)
11918           (setq b (point))
11919           (insert "    " (file-name-nondirectory
11920                           (cdr (assq 'name (car pslist))))
11921                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11922           (setq e (point))
11923           (forward-line -1)             ; back to `b'
11924           (gnus-add-text-properties
11925            b (1- e) (list 'gnus-number gnus-reffed-article-number
11926                           gnus-mouse-face-prop gnus-mouse-face))
11927           (gnus-data-enter
11928            after-article gnus-reffed-article-number
11929            gnus-unread-mark b (car pslist) 0 (- e b))
11930           (setq gnus-newsgroup-unreads
11931                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11932                                          gnus-reffed-article-number))
11933           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11934           (setq pslist (cdr pslist)))))))
11935
11936 (defun gnus-pseudos< (p1 p2)
11937   (let ((c1 (cdr (assq 'action p1)))
11938         (c2 (cdr (assq 'action p2))))
11939     (and c1 c2 (string< c1 c2))))
11940
11941 (defun gnus-request-pseudo-article (props)
11942   (cond ((assq 'execute props)
11943          (gnus-execute-command (cdr (assq 'execute props)))))
11944   (let ((gnus-current-article (gnus-summary-article-number)))
11945     (gnus-run-hooks 'gnus-mark-article-hook)))
11946
11947 (defun gnus-execute-command (command &optional automatic)
11948   (save-excursion
11949     (gnus-article-setup-buffer)
11950     (set-buffer gnus-article-buffer)
11951     (setq buffer-read-only nil)
11952     (let ((command (if automatic command
11953                      (read-string "Command: " (cons command 0)))))
11954       (erase-buffer)
11955       (insert "$ " command "\n\n")
11956       (if gnus-view-pseudo-asynchronously
11957           (start-process "gnus-execute" (current-buffer) shell-file-name
11958                          shell-command-switch command)
11959         (call-process shell-file-name nil t nil
11960                       shell-command-switch command)))))
11961
11962 ;; Summary kill commands.
11963
11964 (defun gnus-summary-edit-global-kill (article)
11965   "Edit the \"global\" kill file."
11966   (interactive (list (gnus-summary-article-number)))
11967   (gnus-group-edit-global-kill article))
11968
11969 (defun gnus-summary-edit-local-kill ()
11970   "Edit a local kill file applied to the current newsgroup."
11971   (interactive)
11972   (setq gnus-current-headers (gnus-summary-article-header))
11973   (gnus-group-edit-local-kill
11974    (gnus-summary-article-number) gnus-newsgroup-name))
11975
11976 ;;; Header reading.
11977
11978 (defun gnus-read-header (id &optional header)
11979   "Read the headers of article ID and enter them into the Gnus system."
11980   (let ((group gnus-newsgroup-name)
11981         (gnus-override-method
11982          (or
11983           gnus-override-method
11984           (and (gnus-news-group-p gnus-newsgroup-name)
11985                (car (gnus-refer-article-methods)))))
11986         where)
11987     ;; First we check to see whether the header in question is already
11988     ;; fetched.
11989     (if (stringp id)
11990         ;; This is a Message-ID.
11991         (setq header (or header (gnus-id-to-header id)))
11992       ;; This is an article number.
11993       (setq header (or header (gnus-summary-article-header id))))
11994     (if (and header
11995              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11996         ;; We have found the header.
11997         header
11998       ;; We have to really fetch the header to this article.
11999       (with-current-buffer nntp-server-buffer
12000         (when (setq where (gnus-request-head id group))
12001           (nnheader-fold-continuation-lines)
12002           (goto-char (point-max))
12003           (insert ".\n")
12004           (goto-char (point-min))
12005           (insert "211 ")
12006           (princ (cond
12007                   ((numberp id) id)
12008                   ((cdr where) (cdr where))
12009                   (header (mail-header-number header))
12010                   (t gnus-reffed-article-number))
12011                  (current-buffer))
12012           (insert " Article retrieved.\n"))
12013         (if (or (not where)
12014                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
12015             ()                          ; Malformed head.
12016           (unless (gnus-summary-article-sparse-p (mail-header-number header))
12017             (when (and (stringp id)
12018                        (or
12019                         (not (string= (gnus-group-real-name group)
12020                                       (car where)))
12021                         (not (gnus-server-equal gnus-override-method
12022                                                 (gnus-group-method group)))))
12023               ;; If we fetched by Message-ID and the article came from
12024               ;; a different group (or server), we fudge some bogus
12025               ;; article numbers for this article.
12026               (mail-header-set-number header gnus-reffed-article-number))
12027             (with-current-buffer gnus-summary-buffer
12028               (decf gnus-reffed-article-number)
12029               (gnus-remove-header (mail-header-number header))
12030               (push header gnus-newsgroup-headers)
12031               (setq gnus-current-headers header)
12032               (push (mail-header-number header) gnus-newsgroup-limit)))
12033           header)))))
12034
12035 (defun gnus-remove-header (number)
12036   "Remove header NUMBER from `gnus-newsgroup-headers'."
12037   (if (and gnus-newsgroup-headers
12038            (= number (mail-header-number (car gnus-newsgroup-headers))))
12039       (pop gnus-newsgroup-headers)
12040     (let ((headers gnus-newsgroup-headers))
12041       (while (and (cdr headers)
12042                   (not (= number (mail-header-number (cadr headers)))))
12043         (pop headers))
12044       (when (cdr headers)
12045         (setcdr headers (cddr headers))))))
12046
12047 ;;;
12048 ;;; summary highlights
12049 ;;;
12050
12051 (defun gnus-highlight-selected-summary ()
12052   "Highlight selected article in summary buffer."
12053   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12054   (when gnus-summary-selected-face
12055     (save-excursion
12056       (let* ((beg (point-at-bol))
12057              (end (point-at-eol))
12058              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12059              (from (if (get-text-property beg gnus-mouse-face-prop)
12060                        beg
12061                      (or (next-single-property-change
12062                           beg gnus-mouse-face-prop nil end)
12063                          beg)))
12064              (to
12065               (if (= from end)
12066                   (- from 2)
12067                 (or (next-single-property-change
12068                      from gnus-mouse-face-prop nil end)
12069                     end))))
12070         ;; If no mouse-face prop on line we will have to = from = end,
12071         ;; so we highlight the entire line instead.
12072         (when (= (+ to 2) from)
12073           (setq from beg)
12074           (setq to end))
12075         (if gnus-newsgroup-selected-overlay
12076             ;; Move old overlay.
12077             (gnus-move-overlay
12078              gnus-newsgroup-selected-overlay from to (current-buffer))
12079           ;; Create new overlay.
12080           (gnus-overlay-put
12081            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12082            'face gnus-summary-selected-face))))))
12083
12084 (defvar gnus-summary-highlight-line-cached nil)
12085 (defvar gnus-summary-highlight-line-trigger nil)
12086
12087 (defun gnus-summary-highlight-line-0 ()
12088   (if (and (eq gnus-summary-highlight-line-trigger
12089                gnus-summary-highlight)
12090            gnus-summary-highlight-line-cached)
12091       gnus-summary-highlight-line-cached
12092     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12093           gnus-summary-highlight-line-cached
12094           (let* ((cond (list 'cond))
12095                  (c cond)
12096                  (list gnus-summary-highlight))
12097             (while list
12098               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12099                               nil))
12100               (setq c (cdr c)
12101                     list (cdr list)))
12102             (gnus-byte-compile (list 'lambda nil cond))))))
12103
12104 (defun gnus-summary-highlight-line ()
12105   "Highlight current line according to `gnus-summary-highlight'."
12106   (let* ((beg (point-at-bol))
12107          (article (or (gnus-summary-article-number) gnus-current-article))
12108          (score (or (cdr (assq article
12109                                gnus-newsgroup-scored))
12110                     gnus-summary-default-score 0))
12111          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12112          (inhibit-read-only t)
12113          (default gnus-summary-default-score)
12114          (default-high gnus-summary-default-high-score)
12115          (default-low gnus-summary-default-low-score)
12116          (uncached (and gnus-summary-use-undownloaded-faces
12117                         (memq article gnus-newsgroup-undownloaded)
12118                         (not (memq article gnus-newsgroup-cached)))))
12119     (let ((face (funcall (gnus-summary-highlight-line-0))))
12120       (unless (eq face (get-text-property beg 'face))
12121         (gnus-put-text-property-excluding-characters-with-faces
12122          beg (point-at-eol) 'face
12123          (setq face (if (boundp face) (symbol-value face) face)))
12124         (when gnus-summary-highlight-line-function
12125           (funcall gnus-summary-highlight-line-function article face))))))
12126
12127 (defun gnus-update-read-articles (group unread &optional compute)
12128   "Update the list of read articles in GROUP.
12129 UNREAD is a sorted list."
12130   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12131         (info (gnus-get-info group))
12132         (prev 1)
12133         read)
12134     (if (or (not info) (not active))
12135         ;; There is no info on this group if it was, in fact,
12136         ;; killed.  Gnus stores no information on killed groups, so
12137         ;; there's nothing to be done.
12138         ;; One could store the information somewhere temporarily,
12139         ;; perhaps...  Hmmm...
12140         ()
12141       ;; Remove any negative articles numbers.
12142       (while (and unread (< (car unread) 0))
12143         (setq unread (cdr unread)))
12144       ;; Remove any expired article numbers
12145       (while (and unread (< (car unread) (car active)))
12146         (setq unread (cdr unread)))
12147       ;; Compute the ranges of read articles by looking at the list of
12148       ;; unread articles.
12149       (while unread
12150         (when (/= (car unread) prev)
12151           (push (if (= prev (1- (car unread))) prev
12152                   (cons prev (1- (car unread))))
12153                 read))
12154         (setq prev (1+ (car unread)))
12155         (setq unread (cdr unread)))
12156       (when (<= prev (cdr active))
12157         (push (cons prev (cdr active)) read))
12158       (setq read (if (> (length read) 1) (nreverse read) read))
12159       (if compute
12160           read
12161         (save-excursion
12162           (let (setmarkundo)
12163             ;; Propagate the read marks to the backend.
12164             (when (and gnus-propagate-marks
12165                        (gnus-check-backend-function 'request-set-mark group))
12166               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12167                     (add (gnus-remove-from-range read (gnus-info-read info))))
12168                 (when (or add del)
12169                   (unless (gnus-check-group group)
12170                     (error "Can't open server for %s" group))
12171                   (gnus-request-set-mark
12172                    group (delq nil (list (if add (list add 'add '(read)))
12173                                          (if del (list del 'del '(read))))))
12174                   (setq setmarkundo
12175                         `(gnus-request-set-mark
12176                           ,group
12177                           ',(delq nil (list
12178                                        (if del (list del 'add '(read)))
12179                                        (if add (list add 'del '(read))))))))))
12180             (set-buffer gnus-group-buffer)
12181             (gnus-undo-register
12182               `(progn
12183                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12184                  (gnus-info-set-read ',info ',(gnus-info-read info))
12185                  (gnus-get-unread-articles-in-group ',info
12186                                                     (gnus-active ,group))
12187                  (gnus-group-update-group ,group t)
12188                  ,setmarkundo))))
12189         ;; Enter this list into the group info.
12190         (gnus-info-set-read info read)
12191         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12192         (gnus-get-unread-articles-in-group info (gnus-active group))
12193         t))))
12194
12195 (defun gnus-offer-save-summaries ()
12196   "Offer to save all active summary buffers."
12197   (let (buffers)
12198     ;; Go through all buffers and find all summaries.
12199     (dolist (buffer (buffer-list))
12200       (when (and (setq buffer (buffer-name buffer))
12201                  (string-match "Summary" buffer)
12202                  (with-current-buffer buffer
12203                    ;; We check that this is, indeed, a summary buffer.
12204                    (and (eq major-mode 'gnus-summary-mode)
12205                         ;; Also make sure this isn't bogus.
12206                         gnus-newsgroup-prepared
12207                         ;; Also make sure that this isn't a
12208                         ;; dead summary buffer.
12209                         (not gnus-dead-summary-mode))))
12210         (push buffer buffers)))
12211     ;; Go through all these summary buffers and offer to save them.
12212     (when buffers
12213       (save-excursion
12214         (map-y-or-n-p
12215          "Update summary buffer %s? "
12216          (lambda (buf)
12217            (switch-to-buffer buf)
12218            (gnus-summary-exit))
12219          buffers)))))
12220
12221 (defun gnus-summary-setup-default-charset ()
12222   "Setup newsgroup default charset."
12223   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12224       (setq gnus-newsgroup-charset nil)
12225     (let* ((ignored-charsets
12226             (or gnus-newsgroup-ephemeral-ignored-charsets
12227                 (append
12228                  (and gnus-newsgroup-name
12229                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12230                  gnus-newsgroup-ignored-charsets))))
12231       (setq gnus-newsgroup-charset
12232             (or gnus-newsgroup-ephemeral-charset
12233                 (and gnus-newsgroup-name
12234                      (gnus-parameter-charset gnus-newsgroup-name))
12235                 gnus-default-charset))
12236       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12237            ignored-charsets))))
12238
12239 ;;;
12240 ;;; Mime Commands
12241 ;;;
12242
12243 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12244   "Display the current article buffer fully MIME-buttonized.
12245 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12246 treated as multipart/mixed."
12247   (interactive "P")
12248   (require 'gnus-art)
12249   (let ((gnus-unbuttonized-mime-types nil)
12250         (gnus-mime-display-multipart-as-mixed show-all-parts))
12251     (gnus-summary-show-article)))
12252
12253 (defun gnus-summary-repair-multipart (article)
12254   "Add a Content-Type header to a multipart article without one."
12255   (interactive (list (gnus-summary-article-number)))
12256   (gnus-with-article article
12257     (message-narrow-to-head)
12258     (message-remove-header "Mime-Version")
12259     (goto-char (point-max))
12260     (insert "Mime-Version: 1.0\n")
12261     (widen)
12262     (when (search-forward "\n--" nil t)
12263       (let ((separator (buffer-substring (point) (point-at-eol))))
12264         (message-narrow-to-head)
12265         (message-remove-header "Content-Type")
12266         (goto-char (point-max))
12267         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12268                         separator))
12269         (widen))))
12270   (let (gnus-mark-article-hook)
12271     (gnus-summary-select-article t t nil article)))
12272
12273 (defun gnus-summary-toggle-display-buttonized ()
12274   "Toggle the buttonizing of the article buffer."
12275   (interactive)
12276   (require 'gnus-art)
12277   (if (setq gnus-inhibit-mime-unbuttonizing
12278             (not gnus-inhibit-mime-unbuttonizing))
12279       (let ((gnus-unbuttonized-mime-types nil))
12280         (gnus-summary-show-article))
12281     (gnus-summary-show-article)))
12282
12283 ;;;
12284 ;;; Generic summary marking commands
12285 ;;;
12286
12287 (defvar gnus-summary-marking-alist
12288   '((read gnus-del-mark "d")
12289     (unread gnus-unread-mark "u")
12290     (ticked gnus-ticked-mark "!")
12291     (dormant gnus-dormant-mark "?")
12292     (expirable gnus-expirable-mark "e"))
12293   "An alist of names/marks/keystrokes.")
12294
12295 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12296 (defvar gnus-summary-mark-map)
12297
12298 (defun gnus-summary-make-all-marking-commands ()
12299   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12300   (dolist (elem gnus-summary-marking-alist)
12301     (apply 'gnus-summary-make-marking-command elem)))
12302
12303 (defun gnus-summary-make-marking-command (name mark keystroke)
12304   (let ((map (make-sparse-keymap)))
12305     (define-key gnus-summary-generic-mark-map keystroke map)
12306     (dolist (lway `((next "next" next nil "n")
12307                     (next-unread "next unread" next t "N")
12308                     (prev "previous" prev nil "p")
12309                     (prev-unread "previous unread" prev t "P")
12310                     (nomove "" nil nil ,keystroke)))
12311       (let ((func (gnus-summary-make-marking-command-1
12312                    mark (car lway) lway name)))
12313         (setq func (eval func))
12314         (define-key map (nth 4 lway) func)))))
12315
12316 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12317   `(defun ,(intern
12318             (format "gnus-summary-put-mark-as-%s%s"
12319                     name (if (eq way 'nomove)
12320                              ""
12321                            (concat "-" (symbol-name way)))))
12322      (n)
12323      ,(format
12324        "Mark the current article as %s%s.
12325 If N, the prefix, then repeat N times.
12326 If N is negative, move in reverse order.
12327 The difference between N and the actual number of articles marked is
12328 returned."
12329        name (cadr lway))
12330      (interactive "p")
12331      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12332
12333 (defun gnus-summary-generic-mark (n mark move unread)
12334   "Mark N articles with MARK."
12335   (unless (eq major-mode 'gnus-summary-mode)
12336     (error "This command can only be used in the summary buffer"))
12337   (gnus-summary-show-thread)
12338   (let ((nummove
12339          (cond
12340           ((eq move 'next) 1)
12341           ((eq move 'prev) -1)
12342           (t 0))))
12343     (if (zerop nummove)
12344         (setq n 1)
12345       (when (< n 0)
12346         (setq n (abs n)
12347               nummove (* -1 nummove))))
12348     (while (and (> n 0)
12349                 (gnus-summary-mark-article nil mark)
12350                 (zerop (gnus-summary-next-subject nummove unread t)))
12351       (setq n (1- n)))
12352     (when (/= 0 n)
12353       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12354     (gnus-summary-recenter)
12355     (gnus-summary-position-point)
12356     (gnus-set-mode-line 'summary)
12357     n))
12358
12359 (defun gnus-summary-insert-articles (articles)
12360   (when (setq articles
12361               (gnus-sorted-difference articles
12362                                       (mapcar (lambda (h)
12363                                                 (mail-header-number h))
12364                                               gnus-newsgroup-headers)))
12365     (setq gnus-newsgroup-headers
12366           (gnus-merge 'list
12367                       gnus-newsgroup-headers
12368                       (gnus-fetch-headers articles)
12369                       'gnus-article-sort-by-number))
12370     ;; Suppress duplicates?
12371     (when gnus-suppress-duplicates
12372       (gnus-dup-suppress-articles))
12373
12374     (if (and gnus-fetch-old-headers
12375              (eq gnus-headers-retrieved-by 'nov))
12376         ;; We might want to build some more threads first.
12377         (if (eq gnus-fetch-old-headers 'invisible)
12378             (gnus-build-all-threads)
12379           (gnus-build-old-threads))
12380       ;; Mark the inserted articles that are unread as unread.
12381       (setq gnus-newsgroup-unreads
12382             (gnus-sorted-nunion
12383              gnus-newsgroup-unreads
12384              (gnus-sorted-nintersection
12385               (gnus-list-of-unread-articles gnus-newsgroup-name)
12386               articles)))
12387       ;; Mark the inserted articles as selected so that the information
12388       ;; of the marks having been changed by a user may be updated when
12389       ;; exiting this group.  See `gnus-summary-update-info'.
12390       (dolist (art articles)
12391         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12392     ;; Let the Gnus agent mark articles as read.
12393     (when gnus-agent
12394       (gnus-agent-get-undownloaded-list))
12395     ;; Remove list identifiers from subject
12396     (when gnus-list-identifiers
12397       (gnus-summary-remove-list-identifiers))
12398     ;; First and last article in this newsgroup.
12399     (when gnus-newsgroup-headers
12400       (setq gnus-newsgroup-begin
12401             (mail-header-number (car gnus-newsgroup-headers))
12402             gnus-newsgroup-end
12403             (mail-header-number
12404              (gnus-last-element gnus-newsgroup-headers))))
12405     (when gnus-use-scoring
12406       (gnus-possibly-score-headers))))
12407
12408 (defun gnus-summary-insert-old-articles (&optional all)
12409   "Insert all old articles in this group.
12410 If ALL is non-nil, already read articles become readable.
12411 If ALL is a number, fetch this number of articles."
12412   (interactive "P")
12413   (prog1
12414       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12415             older len)
12416         (setq older
12417               ;; Some nntp servers lie about their active range.  When
12418               ;; this happens, the active range can be in the millions.
12419               ;; Use a compressed range to avoid creating a huge list.
12420               (gnus-range-difference (list gnus-newsgroup-active) old))
12421         (setq len (gnus-range-length older))
12422         (cond
12423          ((null older) nil)
12424          ((numberp all)
12425           (if (< all len)
12426               (let ((older-range (nreverse older)))
12427                 (setq older nil)
12428
12429                 (while (> all 0)
12430                   (let* ((r (pop older-range))
12431                          (min (if (numberp r) r (car r)))
12432                          (max (if (numberp r) r (cdr r))))
12433                     (while (and (<= min max)
12434                                 (> all 0))
12435                       (push max older)
12436                       (setq all (1- all)
12437                             max (1- max))))))
12438             (setq older (gnus-uncompress-range older))))
12439          (all
12440           (setq older (gnus-uncompress-range older)))
12441          (t
12442           (when (and (numberp gnus-large-newsgroup)
12443                    (> len gnus-large-newsgroup))
12444               (let* ((cursor-in-echo-area nil)
12445                      (initial (gnus-parameter-large-newsgroup-initial
12446                                gnus-newsgroup-name))
12447                      (input
12448                       (read-string
12449                        (format
12450                         "How many articles from %s (%s %d): "
12451                         (gnus-group-decoded-name gnus-newsgroup-name)
12452                         (if initial "max" "default")
12453                         len)
12454                        (if initial
12455                            (cons (number-to-string initial)
12456                                  0)))))
12457                 (unless (string-match "^[ \t]*$" input)
12458                   (setq all (string-to-number input))
12459                   (if (< all len)
12460                       (let ((older-range (nreverse older)))
12461                         (setq older nil)
12462
12463                         (while (> all 0)
12464                           (let* ((r (pop older-range))
12465                                  (min (if (numberp r) r (car r)))
12466                                  (max (if (numberp r) r (cdr r))))
12467                             (while (and (<= min max)
12468                                         (> all 0))
12469                               (push max older)
12470                               (setq all (1- all)
12471                                     max (1- max))))))))))
12472           (setq older (gnus-uncompress-range older))))
12473         (if (not older)
12474             (message "No old news.")
12475           (gnus-summary-insert-articles older)
12476           (gnus-summary-limit (gnus-sorted-nunion old older))))
12477     (gnus-summary-position-point)))
12478
12479 (defun gnus-summary-insert-new-articles ()
12480   "Insert all new articles in this group."
12481   (interactive)
12482   (prog1
12483       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12484             (old-active gnus-newsgroup-active)
12485             (nnmail-fetched-sources (list t))
12486             i new)
12487         (setq gnus-newsgroup-active
12488               (gnus-activate-group gnus-newsgroup-name 'scan))
12489         (setq i (cdr gnus-newsgroup-active))
12490         (while (> i (cdr old-active))
12491           (push i new)
12492           (decf i))
12493         (if (not new)
12494             (message "No gnus is bad news")
12495           (gnus-summary-insert-articles new)
12496           (setq gnus-newsgroup-unreads
12497                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12498           (gnus-summary-limit (gnus-sorted-nunion old new))))
12499     (gnus-summary-position-point)))
12500
12501 (gnus-summary-make-all-marking-commands)
12502
12503 (gnus-ems-redefine)
12504
12505 (provide 'gnus-sum)
12506
12507 (run-hooks 'gnus-sum-load-hook)
12508
12509 ;; Local Variables:
12510 ;; coding: iso-8859-1
12511 ;; End:
12512
12513 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12514 ;;; gnus-sum.el ends here