(gnus-handle-ephemeral-exit): Set the right select-method when not
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996-2011 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 ;; For Emacs <22.2 and XEmacs.
28 (eval-and-compile
29   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
30 (eval-when-compile
31   (require 'cl))
32 (eval-when-compile
33   (when (featurep 'xemacs)
34     (require 'easy-mmode))) ; for `define-minor-mode'
35
36 (defvar tool-bar-mode)
37 (defvar gnus-tmp-header)
38
39 (require 'gnus)
40 (require 'gnus-group)
41 (require 'gnus-spec)
42 (require 'gnus-range)
43 (require 'gnus-int)
44 (require 'gnus-undo)
45 (require 'gnus-util)
46 (require 'gmm-utils)
47 (require 'mm-decode)
48 (require 'nnoo)
49
50 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
51 (autoload 'gnus-cache-write-active "gnus-cache")
52 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
53 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
54 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
55 (autoload 'mm-uu-dissect "mm-uu")
56 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
57   "Deuglify broken Outlook (Express) articles and redisplay."
58   t)
59 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
60 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
61 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
62 (autoload 'nnir-article-rsv "nnir" nil nil 'macro)
63 (autoload 'nnir-article-group "nnir" nil nil 'macro)
64
65 (defcustom gnus-kill-summary-on-exit t
66   "*If non-nil, kill the summary buffer when you exit from it.
67 If nil, the summary will become a \"*Dead Summary*\" buffer, and
68 it will be killed sometime later."
69   :group 'gnus-summary-exit
70   :type 'boolean)
71
72 (defcustom gnus-summary-next-group-on-exit t
73   "If non-nil, go to the next unread newsgroup on summary exit.
74 See `gnus-group-goto-unread'."
75   :link '(custom-manual "(gnus)Group Maneuvering")
76   :group 'gnus-summary-exit
77   :version "23.1" ;; No Gnus
78   :type 'boolean)
79
80 (defcustom gnus-summary-stop-at-end-of-message nil
81   "If non-nil, don't select the next message when using `SPC'."
82   :link '(custom-manual "(gnus)Group Maneuvering")
83   :group 'gnus-summary-maneuvering
84   :version "24.1"
85   :type 'boolean)
86
87 (defcustom gnus-fetch-old-headers nil
88   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
89 If an unread article in the group refers to an older, already
90 read (or just marked as read) article, the old article will not
91 normally be displayed in the Summary buffer.  If this variable is
92 t, Gnus will attempt to grab the headers to the old articles, and
93 thereby build complete threads.  If it has the value `some', all
94 old headers will be fetched but only enough headers to connect
95 otherwise loose threads will be displayed.  This variable can
96 also be a number.  In that case, no more than that number of old
97 headers will be fetched.  If it has the value `invisible', all
98 old headers will be fetched, but none will be displayed.
99
100 The server has to support NOV for any of this to work.
101
102 This feature can seriously impact performance it ignores all
103 locally cached header entries.  Setting it to t for groups for a
104 server that doesn't expire articles (such as news.gmane.org),
105 leads to very slow summary generation."
106   :group 'gnus-thread
107   :type '(choice (const :tag "off" nil)
108                  (const :tag "on" t)
109                  (const some)
110                  (const invisible)
111                  number
112                  (sexp :menu-tag "other" t)))
113
114 (defcustom gnus-refer-thread-limit 500
115   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
116 If t, fetch all the available old headers."
117   :group 'gnus-thread
118   :type '(choice number
119                  (sexp :menu-tag "other" t)))
120
121 (defcustom gnus-summary-make-false-root 'adopt
122   "*nil means that Gnus won't gather loose threads.
123 If the root of a thread has expired or been read in a previous
124 session, the information necessary to build a complete thread has been
125 lost.  Instead of having many small sub-threads from this original thread
126 scattered all over the summary buffer, Gnus can gather them.
127
128 If non-nil, Gnus will try to gather all loose sub-threads from an
129 original thread into one large thread.
130
131 If this variable is non-nil, it should be one of `none', `adopt',
132 `dummy' or `empty'.
133
134 If this variable is `none', Gnus will not make a false root, but just
135 present the sub-threads after another.
136 If this variable is `dummy', Gnus will create a dummy root that will
137 have all the sub-threads as children.
138 If this variable is `adopt', Gnus will make one of the \"children\"
139 the parent and mark all the step-children as such.
140 If this variable is `empty', the \"children\" are printed with empty
141 subject fields.  (Or rather, they will be printed with a string
142 given by the `gnus-summary-same-subject' variable.)"
143   :group 'gnus-thread
144   :type '(choice (const :tag "off" nil)
145                  (const none)
146                  (const dummy)
147                  (const adopt)
148                  (const empty)))
149
150 (defcustom gnus-summary-make-false-root-always nil
151   "Always make a false dummy root."
152   :version "22.1"
153   :group 'gnus-thread
154   :type 'boolean)
155
156 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
157   "*A regexp to match subjects to be excluded from loose thread gathering.
158 As loose thread gathering is done on subjects only, that means that
159 there can be many false gatherings performed.  By rooting out certain
160 common subjects, gathering might become saner."
161   :group 'gnus-thread
162   :type 'regexp)
163
164 (defcustom gnus-summary-gather-subject-limit nil
165   "*Maximum length of subject comparisons when gathering loose threads.
166 Use nil to compare full subjects.  Setting this variable to a low
167 number will help gather threads that have been corrupted by
168 newsreaders chopping off subject lines, but it might also mean that
169 unrelated articles that have subject that happen to begin with the
170 same few characters will be incorrectly gathered.
171
172 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
173 comparing subjects."
174   :group 'gnus-thread
175   :type '(choice (const :tag "off" nil)
176                  (const fuzzy)
177                  (sexp :menu-tag "on" t)))
178
179 (defcustom gnus-simplify-subject-functions nil
180   "List of functions taking a string argument that simplify subjects.
181 The functions are applied recursively.
182
183 Useful functions to put in this list include:
184 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
185 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
186   :group 'gnus-thread
187   :type '(repeat function))
188
189 (defcustom gnus-simplify-ignored-prefixes nil
190   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
191   :group 'gnus-thread
192   :type '(choice (const :tag "off" nil)
193                  regexp))
194
195 (defcustom gnus-build-sparse-threads nil
196   "*If non-nil, fill in the gaps in threads.
197 If `some', only fill in the gaps that are needed to tie loose threads
198 together.  If `more', fill in all leaf nodes that Gnus can find.  If
199 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
200   :group 'gnus-thread
201   :type '(choice (const :tag "off" nil)
202                  (const some)
203                  (const more)
204                  (sexp :menu-tag "all" t)))
205
206 (defcustom gnus-summary-thread-gathering-function
207   'gnus-gather-threads-by-subject
208   "*Function used for gathering loose threads.
209 There are two pre-defined functions: `gnus-gather-threads-by-subject',
210 which only takes Subjects into consideration; and
211 `gnus-gather-threads-by-references', which compared the References
212 headers of the articles to find matches."
213   :group 'gnus-thread
214   :type '(radio (function-item gnus-gather-threads-by-subject)
215                 (function-item gnus-gather-threads-by-references)
216                 (function :tag "other")))
217
218 (defcustom gnus-summary-same-subject ""
219   "*String indicating that the current article has the same subject as the previous.
220 This variable will only be used if the value of
221 `gnus-summary-make-false-root' is `empty'."
222   :group 'gnus-summary-format
223   :type 'string)
224
225 (defcustom gnus-summary-goto-unread nil
226   "*If t, many commands will go to the next unread article.
227 This applies to marking commands as well as other commands that
228 \"naturally\" select the next article, like, for instance, `SPC' at
229 the end of an article.
230
231 If nil, the marking commands do NOT go to the next unread article
232 \(they go to the next article instead).  If `never', commands that
233 usually go to the next unread article, will go to the next article,
234 whether it is read or not."
235   :version "24.1"
236   :group 'gnus-summary-marks
237   :link '(custom-manual "(gnus)Setting Marks")
238   :type '(choice (const :tag "off" nil)
239                  (const never)
240                  (sexp :menu-tag "on" t)))
241
242 (defcustom gnus-summary-default-score 0
243   "*Default article score level.
244 All scores generated by the score files will be added to this score.
245 If this variable is nil, scoring will be disabled."
246   :group 'gnus-score-default
247   :type '(choice (const :tag "disable")
248                  integer))
249
250 (defcustom gnus-summary-default-high-score 0
251   "*Default threshold for a high scored article.
252 An article will be highlighted as high scored if its score is greater
253 than this score."
254   :version "22.1"
255   :group 'gnus-score-default
256   :type 'integer)
257
258 (defcustom gnus-summary-default-low-score 0
259   "*Default threshold for a low scored article.
260 An article will be highlighted as low scored if its score is smaller
261 than this score."
262   :version "22.1"
263   :group 'gnus-score-default
264   :type 'integer)
265
266 (defcustom gnus-summary-zcore-fuzz 0
267   "*Fuzziness factor for the zcore in the summary buffer.
268 Articles with scores closer than this to `gnus-summary-default-score'
269 will not be marked."
270   :group 'gnus-summary-format
271   :type 'integer)
272
273 (defcustom gnus-simplify-subject-fuzzy-regexp nil
274   "*Strings to be removed when doing fuzzy matches.
275 This can either be a regular expression or list of regular expressions
276 that will be removed from subject strings if fuzzy subject
277 simplification is selected."
278   :group 'gnus-thread
279   :type '(repeat regexp))
280
281 (defcustom gnus-show-threads t
282   "*If non-nil, display threads in summary mode."
283   :group 'gnus-thread
284   :type 'boolean)
285
286 (defcustom gnus-thread-hide-subtree nil
287   "*If non-nil, hide all threads initially.
288 This can be a predicate specifier which says which threads to hide.
289 If threads are hidden, you have to run the command
290 `gnus-summary-show-thread' by hand or select an article."
291   :group 'gnus-thread
292   :type '(radio (sexp :format "Non-nil\n"
293                       :match (lambda (widget value)
294                                (not (or (consp value) (functionp value))))
295                       :value t)
296                 (const nil)
297                 (sexp :tag "Predicate specifier")))
298
299 (defcustom gnus-thread-hide-killed t
300   "*If non-nil, hide killed threads automatically."
301   :group 'gnus-thread
302   :type 'boolean)
303
304 (defcustom gnus-thread-ignore-subject t
305   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
306 If nil, articles that have different subjects from their parents will
307 start separate threads."
308   :group 'gnus-thread
309   :type 'boolean)
310
311 (defcustom gnus-thread-operation-ignore-subject t
312   "*If non-nil, subjects will be ignored when doing thread commands.
313 This affects commands like `gnus-summary-kill-thread' and
314 `gnus-summary-lower-thread'.
315
316 If this variable is nil, articles in the same thread with different
317 subjects will not be included in the operation in question.  If this
318 variable is `fuzzy', only articles that have subjects that are fuzzily
319 equal will be included."
320   :group 'gnus-thread
321   :type '(choice (const :tag "off" nil)
322                  (const fuzzy)
323                  (sexp :tag "on" t)))
324
325 (defcustom gnus-thread-indent-level 4
326   "*Number that says how much each sub-thread should be indented."
327   :group 'gnus-thread
328   :type 'integer)
329
330 (defcustom gnus-auto-extend-newsgroup t
331   "*If non-nil, extend newsgroup forward and backward when requested."
332   :group 'gnus-summary-choose
333   :type 'boolean)
334
335 (defcustom gnus-auto-select-first t
336   "If non-nil, select an article on group entry.
337 An article is selected automatically when entering a group
338 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
339 `gnus-summary-catchup-and-goto-next-group'.
340
341 Which article is selected is controlled by the variable
342 `gnus-auto-select-subject'.
343
344 If you want to prevent automatic selection of articles in some
345 newsgroups, set the variable to nil in `gnus-select-group-hook'."
346   ;; Commands include...
347   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
348   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
349   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
350   :group 'gnus-group-select
351   :type '(choice (const :tag "none" nil)
352                  (sexp :menu-tag "first" t)))
353
354 (defcustom gnus-auto-select-subject 'unseen-or-unread
355   "*Says what subject to place under point when entering a group.
356
357 This variable can either be the symbols `first' (place point on the
358 first subject), `unread' (place point on the subject line of the first
359 unread article), `best' (place point on the subject line of the
360 higest-scored article), `unseen' (place point on the subject line of
361 the first unseen article), `unseen-or-unread' (place point on the subject
362 line of the first unseen article or, if all articles have been seen, on the
363 subject line of the first unread article), or a function to be called to
364 place point on some subject line."
365   :version "24.1"
366   :group 'gnus-group-select
367   :type '(choice (const best)
368                  (const unread)
369                  (const first)
370                  (const unseen)
371                  (const unseen-or-unread)))
372
373 (defcustom gnus-auto-select-next t
374   "*If non-nil, offer to go to the next group from the end of the previous.
375 If the value is t and the next newsgroup is empty, Gnus will exit
376 summary mode and go back to group mode.  If the value is neither nil
377 nor t, Gnus will select the following unread newsgroup.  In
378 particular, if the value is the symbol `quietly', the next unread
379 newsgroup will be selected without any confirmation, and if it is
380 `almost-quietly', the next group will be selected without any
381 confirmation if you are located on the last article in the group.
382 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
383 will go to the next group without confirmation."
384   :group 'gnus-summary-maneuvering
385   :type '(choice (const :tag "off" nil)
386                  (const quietly)
387                  (const almost-quietly)
388                  (const slightly-quietly)
389                  (sexp :menu-tag "on" t)))
390
391 (defcustom gnus-auto-select-same nil
392   "*If non-nil, select the next article with the same subject.
393 If there are no more articles with the same subject, go to
394 the first unread article."
395   :group 'gnus-summary-maneuvering
396   :type 'boolean)
397
398 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
399   "What article should be selected after exiting an ephemeral group.
400 Valid values include:
401
402 `next'
403   Select the next article.
404 `next-unread'
405   Select the next unread article.
406 `next-noselect'
407   Move the cursor to the next article.  This is the default.
408 `next-unread-noselect'
409   Move the cursor to the next unread article.
410
411 If it has any other value or there is no next (unread) article, the
412 article selected before entering to the ephemeral group will appear."
413   :version "23.1" ;; No Gnus
414   :group 'gnus-summary-maneuvering
415   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
416                  (const next) (const next-unread)
417                  (const next-noselect) (const next-unread-noselect)
418                  (sexp :tag "other" :value nil)))
419
420 (defcustom gnus-auto-goto-ignores 'unfetched
421   "*Says how to handle unfetched articles when maneuvering.
422
423 This variable can either be the symbols nil (maneuver to any
424 article), `undownloaded' (maneuvering while unplugged ignores articles
425 that have not been fetched), `always-undownloaded' (maneuvering always
426 ignores articles that have not been fetched), `unfetched' (maneuvering
427 ignores articles whose headers have not been fetched).
428
429 NOTE: The list of unfetched articles will always be nil when plugged
430 and, when unplugged, a subset of the undownloaded article list."
431   :version "22.1"
432   :group 'gnus-summary-maneuvering
433   :type '(choice (const :tag "None" nil)
434                  (const :tag "Undownloaded when unplugged" undownloaded)
435                  (const :tag "Undownloaded" always-undownloaded)
436                  (const :tag "Unfetched" unfetched)))
437
438 (defcustom gnus-summary-check-current nil
439   "*If non-nil, consider the current article when moving.
440 The \"unread\" movement commands will stay on the same line if the
441 current article is unread."
442   :group 'gnus-summary-maneuvering
443   :type 'boolean)
444
445 (defcustom gnus-auto-center-summary 2
446   "*If non-nil, always center the current summary buffer.
447 In particular, if `vertical' do only vertical recentering.  If non-nil
448 and non-`vertical', do both horizontal and vertical recentering."
449   :group 'gnus-summary-maneuvering
450   :type '(choice (const :tag "none" nil)
451                  (const vertical)
452                  (integer :tag "height")
453                  (sexp :menu-tag "both" t)))
454
455 (defcustom gnus-auto-center-group t
456   "If non-nil, always center the group buffer."
457   :group 'gnus-summary-maneuvering
458   :type 'boolean)
459
460 (defcustom gnus-show-all-headers nil
461   "*If non-nil, don't hide any headers."
462   :group 'gnus-article-hiding
463   :group 'gnus-article-headers
464   :type 'boolean)
465
466 (defcustom gnus-summary-ignore-duplicates nil
467   "*If non-nil, ignore articles with identical Message-ID headers."
468   :group 'gnus-summary
469   :type 'boolean)
470
471 (defcustom gnus-single-article-buffer nil
472   "*If non-nil, display all articles in the same buffer.
473 If nil, each group will get its own article buffer."
474   :version "24.1"
475   :group 'gnus-article-various
476   :type 'boolean)
477
478 (defcustom gnus-widen-article-window nil
479   "If non-nil, selecting the article buffer will display only the article buffer."
480   :version "24.1"
481   :group 'gnus-article-various
482   :type 'boolean)
483
484 (defcustom gnus-break-pages t
485   "*If non-nil, do page breaking on articles.
486 The page delimiter is specified by the `gnus-page-delimiter'
487 variable."
488   :group 'gnus-article-various
489   :type 'boolean)
490
491 (defcustom gnus-move-split-methods nil
492   "*Variable used to suggest where articles are to be moved to.
493 It uses the same syntax as the `gnus-split-methods' variable.
494 However, whereas `gnus-split-methods' specifies file names as targets,
495 this variable specifies group names."
496   :group 'gnus-summary-mail
497   :type '(repeat (choice (list :value (fun) function)
498                          (cons :value ("" "") regexp (repeat string))
499                          (sexp :value nil))))
500
501 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
502   "Function used to compute default prefix for article move/copy/etc prompts.
503 The function should take one argument, a group name, and return a
504 string with the suggested prefix."
505   :group 'gnus-summary-mail
506   :type 'function)
507
508 ;; FIXME: Although the custom type is `character' for the following variables,
509 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
510
511 (defcustom gnus-unread-mark ?           ;Whitespace
512   "*Mark used for unread articles."
513   :group 'gnus-summary-marks
514   :type 'character)
515
516 (defcustom gnus-ticked-mark ?!
517   "*Mark used for ticked articles."
518   :group 'gnus-summary-marks
519   :type 'character)
520
521 (defcustom gnus-dormant-mark ??
522   "*Mark used for dormant articles."
523   :group 'gnus-summary-marks
524   :type 'character)
525
526 (defcustom gnus-del-mark ?r
527   "*Mark used for del'd articles."
528   :group 'gnus-summary-marks
529   :type 'character)
530
531 (defcustom gnus-read-mark ?R
532   "*Mark used for read articles."
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-expirable-mark ?E
537   "*Mark used for expirable articles."
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-killed-mark ?K
542   "*Mark used for killed articles."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-spam-mark ?$
547   "*Mark used for spam articles."
548   :version "22.1"
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-kill-file-mark ?X
553   "*Mark used for articles killed by kill files."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-low-score-mark ?Y
558   "*Mark used for articles with a low score."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-catchup-mark ?C
563   "*Mark used for articles that are caught up."
564   :group 'gnus-summary-marks
565   :type 'character)
566
567 (defcustom gnus-replied-mark ?A
568   "*Mark used for articles that have been replied to."
569   :group 'gnus-summary-marks
570   :type 'character)
571
572 (defcustom gnus-forwarded-mark ?F
573   "*Mark used for articles that have been forwarded."
574   :version "22.1"
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-recent-mark ?N
579   "*Mark used for articles that are recent."
580   :version "22.1"
581   :group 'gnus-summary-marks
582   :type 'character)
583
584 (defcustom gnus-cached-mark ?*
585   "*Mark used for articles that are in the cache."
586   :group 'gnus-summary-marks
587   :type 'character)
588
589 (defcustom gnus-saved-mark ?S
590   "*Mark used for articles that have been saved."
591   :group 'gnus-summary-marks
592   :type 'character)
593
594 (defcustom gnus-unseen-mark ?.
595   "*Mark used for articles that haven't been seen."
596   :version "22.1"
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-no-mark ?               ;Whitespace
601   "*Mark used for articles that have no other secondary mark."
602   :version "22.1"
603   :group 'gnus-summary-marks
604   :type 'character)
605
606 (defcustom gnus-ancient-mark ?O
607   "*Mark used for ancient articles."
608   :group 'gnus-summary-marks
609   :type 'character)
610
611 (defcustom gnus-sparse-mark ?Q
612   "*Mark used for sparsely reffed articles."
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-canceled-mark ?G
617   "*Mark used for canceled articles."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-duplicate-mark ?M
622   "*Mark used for duplicate articles."
623   :group 'gnus-summary-marks
624   :type 'character)
625
626 (defcustom gnus-undownloaded-mark ?-
627   "*Mark used for articles that weren't downloaded."
628   :version "22.1"
629   :group 'gnus-summary-marks
630   :type 'character)
631
632 (defcustom gnus-downloaded-mark ?+
633   "*Mark used for articles that were downloaded."
634   :group 'gnus-summary-marks
635   :type 'character)
636
637 (defcustom gnus-downloadable-mark ?%
638   "*Mark used for articles that are to be downloaded."
639   :group 'gnus-summary-marks
640   :type 'character)
641
642 (defcustom gnus-unsendable-mark ?=
643   "*Mark used for articles that won't be sent."
644   :group 'gnus-summary-marks
645   :type 'character)
646
647 (defcustom gnus-score-over-mark ?+
648   "*Score mark used for articles with high scores."
649   :group 'gnus-summary-marks
650   :type 'character)
651
652 (defcustom gnus-score-below-mark ?-
653   "*Score mark used for articles with low scores."
654   :group 'gnus-summary-marks
655   :type 'character)
656
657 (defcustom gnus-empty-thread-mark ?     ;Whitespace
658   "*There is no thread under the article."
659   :group 'gnus-summary-marks
660   :type 'character)
661
662 (defcustom gnus-not-empty-thread-mark ?=
663   "*There is a thread under the article."
664   :group 'gnus-summary-marks
665   :type 'character)
666
667 (defcustom gnus-view-pseudo-asynchronously nil
668   "*If non-nil, Gnus will view pseudo-articles asynchronously."
669   :group 'gnus-extract-view
670   :type 'boolean)
671
672 (defcustom gnus-auto-expirable-marks
673   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
674         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
675         gnus-duplicate-mark)
676   "*The list of marks converted into expiration if a group is auto-expirable."
677   :version "24.1"
678   :group 'gnus-summary
679   :type '(repeat character))
680
681 (defcustom gnus-inhibit-user-auto-expire t
682   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
683   :version "21.1"
684   :group 'gnus-summary
685   :type 'boolean)
686
687 (defcustom gnus-mark-copied-or-moved-articles-as-expirable nil
688   "If non-nil, mark articles copied or moved to auto-expire group as expirable.
689 If nil, the expirable marks will be unchanged except that the marks
690 will be removed when copying or moving articles to a group that has
691 not turned auto-expire on.  If non-nil, articles that have been read
692 will be marked as expirable when being copied or moved to a group in
693 which auto-expire is turned on."
694   :version "23.2"
695   :type 'boolean
696   :group 'gnus-summary-marks)
697
698 (defcustom gnus-view-pseudos nil
699   "*If `automatic', pseudo-articles will be viewed automatically.
700 If `not-confirm', pseudos will be viewed automatically, and the user
701 will not be asked to confirm the command."
702   :group 'gnus-extract-view
703   :type '(choice (const :tag "off" nil)
704                  (const automatic)
705                  (const not-confirm)))
706
707 (defcustom gnus-view-pseudos-separately t
708   "*If non-nil, one pseudo-article will be created for each file to be viewed.
709 If nil, all files that use the same viewing command will be given as a
710 list of parameters to that command."
711   :group 'gnus-extract-view
712   :type 'boolean)
713
714 (defcustom gnus-insert-pseudo-articles t
715   "*If non-nil, insert pseudo-articles when decoding articles."
716   :group 'gnus-extract-view
717   :type 'boolean)
718
719 (defcustom gnus-summary-dummy-line-format
720   "   %(:                             :%) %S\n"
721   "*The format specification for the dummy roots in the summary buffer.
722 It works along the same lines as a normal formatting string,
723 with some simple extensions.
724
725 %S  The subject
726
727 General format specifiers can also be used.
728 See `(gnus)Formatting Variables'."
729   :link '(custom-manual "(gnus)Formatting Variables")
730   :group 'gnus-threading
731   :type 'string)
732
733 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
734   "*The format specification for the summary mode line.
735 It works along the same lines as a normal formatting string,
736 with some simple extensions:
737
738 %G  Group name
739 %p  Unprefixed group name
740 %A  Current article number
741 %z  Current article score
742 %V  Gnus version
743 %U  Number of unread articles in the group
744 %e  Number of unselected articles in the group
745 %Z  A string with unread/unselected article counts
746 %g  Shortish group name
747 %S  Subject of the current article
748 %u  User-defined spec
749 %s  Current score file name
750 %d  Number of dormant articles
751 %r  Number of articles that have been marked as read in this session
752 %E  Number of articles expunged by the score files"
753   :group 'gnus-summary-format
754   :type 'string)
755
756 (defcustom gnus-list-identifiers nil
757   "Regexp that matches list identifiers to be removed from subject.
758 This can also be a list of regexps."
759   :version "21.1"
760   :group 'gnus-summary-format
761   :group 'gnus-article-hiding
762   :type '(choice (const :tag "none" nil)
763                  (regexp :value ".*")
764                  (repeat :value (".*") regexp)))
765
766 (defcustom gnus-summary-mark-below 0
767   "*Mark all articles with a score below this variable as read.
768 This variable is local to each summary buffer and usually set by the
769 score file."
770   :group 'gnus-score-default
771   :type 'integer)
772
773 (defun gnus-widget-reversible-match (widget value)
774   "Ignoring WIDGET, convert VALUE to internal form.
775 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
776   ;; (debug value)
777   (or (symbolp value)
778       (and (listp value)
779            (eq (length value) 2)
780            (eq (nth 0 value) 'not)
781            (symbolp (nth 1 value)))))
782
783 (defun gnus-widget-reversible-to-internal (widget value)
784   "Ignoring WIDGET, convert VALUE to internal form.
785 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
786 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
787   ;; (debug value)
788   (if (atom value)
789       (list value nil)
790     (list (nth 1 value) t)))
791
792 (defun gnus-widget-reversible-to-external (widget value)
793   "Ignoring WIDGET, convert VALUE to external form.
794 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
795 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
796   ;; (debug value)
797   (if (nth 1 value)
798       (list 'not (nth 0 value))
799     (nth 0 value)))
800
801 (define-widget 'gnus-widget-reversible 'group
802   "A `group' that convert values."
803   :match 'gnus-widget-reversible-match
804   :value-to-internal 'gnus-widget-reversible-to-internal
805   :value-to-external 'gnus-widget-reversible-to-external)
806
807 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
808   "*List of functions used for sorting articles in the summary buffer.
809
810 Each function takes two articles and returns non-nil if the first
811 article should be sorted before the other.  If you use more than one
812 function, the primary sort function should be the last.  You should
813 probably always include `gnus-article-sort-by-number' in the list of
814 sorting functions -- preferably first.  Also note that sorting by date
815 is often much slower than sorting by number, and the sorting order is
816 very similar.  (Sorting by date means sorting by the time the message
817 was sent, sorting by number means sorting by arrival time.)
818
819 Each item can also be a list `(not F)' where F is a function;
820 this reverses the sort order.
821
822 Ready-made functions include `gnus-article-sort-by-number',
823 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
824 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
825 and `gnus-article-sort-by-score'.
826
827 When threading is turned on, the variable `gnus-thread-sort-functions'
828 controls how articles are sorted."
829   :group 'gnus-summary-sort
830   :type '(repeat (gnus-widget-reversible
831                   (choice (function-item gnus-article-sort-by-number)
832                           (function-item gnus-article-sort-by-author)
833                           (function-item gnus-article-sort-by-subject)
834                           (function-item gnus-article-sort-by-date)
835                           (function-item gnus-article-sort-by-score)
836                           (function-item gnus-article-sort-by-random)
837                           (function :tag "other"))
838                   (boolean :tag "Reverse order"))))
839
840
841 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
842   "*List of functions used for sorting threads in the summary buffer.
843 By default, threads are sorted by article number.
844
845 Each function takes two threads and returns non-nil if the first
846 thread should be sorted before the other.  If you use more than one
847 function, the primary sort function should be the last.  You should
848 probably always include `gnus-thread-sort-by-number' in the list of
849 sorting functions -- preferably first.  Also note that sorting by date
850 is often much slower than sorting by number, and the sorting order is
851 very similar.  (Sorting by date means sorting by the time the message
852 was sent, sorting by number means sorting by arrival time.)
853
854 Each list item can also be a list `(not F)' where F is a
855 function; this specifies reversed sort order.
856
857 Ready-made functions include `gnus-thread-sort-by-number',
858 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
859 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
860 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
861 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
862 and `gnus-thread-sort-by-total-score' (see
863 `gnus-thread-score-function').
864
865 When threading is turned off, the variable
866 `gnus-article-sort-functions' controls how articles are sorted."
867   :group 'gnus-summary-sort
868   :type '(repeat
869           (gnus-widget-reversible
870            (choice (function-item gnus-thread-sort-by-number)
871                    (function-item gnus-thread-sort-by-author)
872                    (function-item gnus-thread-sort-by-recipient)
873                    (function-item gnus-thread-sort-by-subject)
874                    (function-item gnus-thread-sort-by-date)
875                    (function-item gnus-thread-sort-by-score)
876                    (function-item gnus-thread-sort-by-most-recent-number)
877                    (function-item gnus-thread-sort-by-most-recent-date)
878                    (function-item gnus-thread-sort-by-random)
879                    (function-item gnus-thread-sort-by-total-score)
880                    (function :tag "other"))
881            (boolean :tag "Reverse order"))))
882
883 (defcustom gnus-thread-score-function '+
884   "*Function used for calculating the total score of a thread.
885
886 The function is called with the scores of the article and each
887 subthread and should then return the score of the thread.
888
889 Some functions you can use are `+', `max', or `min'."
890   :group 'gnus-summary-sort
891   :type 'function)
892
893 (defcustom gnus-summary-expunge-below nil
894   "All articles that have a score less than this variable will be expunged.
895 This variable is local to the summary buffers."
896   :group 'gnus-score-default
897   :type '(choice (const :tag "off" nil)
898                  integer))
899
900 (defcustom gnus-thread-expunge-below nil
901   "All threads that have a total score less than this variable will be expunged.
902 See `gnus-thread-score-function' for en explanation of what a
903 \"thread score\" is.
904
905 This variable is local to the summary buffers."
906   :group 'gnus-threading
907   :group 'gnus-score-default
908   :type '(choice (const :tag "off" nil)
909                  integer))
910
911 (defcustom gnus-summary-mode-hook nil
912   "*A hook for Gnus summary mode.
913 This hook is run before any variables are set in the summary buffer."
914   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
915   :group 'gnus-summary-various
916   :type 'hook)
917
918 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
919 (when (featurep 'xemacs)
920   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
921   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
922   (add-hook 'gnus-summary-mode-hook
923             'gnus-xmas-switch-horizontal-scrollbar-off))
924
925 (defcustom gnus-summary-menu-hook nil
926   "*Hook run after the creation of the summary mode menu."
927   :group 'gnus-summary-visual
928   :type 'hook)
929
930 (defcustom gnus-summary-exit-hook nil
931   "*A hook called on exit from the summary buffer.
932 It will be called with point in the group buffer."
933   :group 'gnus-summary-exit
934   :type 'hook)
935
936 (defcustom gnus-summary-prepare-hook nil
937   "*A hook called after the summary buffer has been generated.
938 If you want to modify the summary buffer, you can use this hook."
939   :group 'gnus-summary-various
940   :type 'hook)
941
942 (defcustom gnus-summary-prepared-hook nil
943   "*A hook called as the last thing after the summary buffer has been generated."
944   :group 'gnus-summary-various
945   :type 'hook)
946
947 (defcustom gnus-summary-generate-hook nil
948   "*A hook run just before generating the summary buffer.
949 This hook is commonly used to customize threading variables and the
950 like."
951   :group 'gnus-summary-various
952   :type 'hook)
953
954 (defcustom gnus-select-group-hook nil
955   "*A hook called when a newsgroup is selected.
956
957 If you'd like to simplify subjects like the
958 `gnus-summary-next-same-subject' command does, you can use the
959 following hook:
960
961  (add-hook gnus-select-group-hook
962            (lambda ()
963              (mapcar (lambda (header)
964                        (mail-header-set-subject
965                         header
966                         (gnus-simplify-subject
967                          (mail-header-subject header) 're-only)))
968                      gnus-newsgroup-headers)))"
969   :group 'gnus-group-select
970   :type 'hook)
971
972 (defcustom gnus-select-article-hook nil
973   "*A hook called when an article is selected."
974   :group 'gnus-summary-choose
975   :options '(gnus-agent-fetch-selected-article)
976   :type 'hook)
977
978 (defcustom gnus-visual-mark-article-hook
979   (list 'gnus-highlight-selected-summary)
980   "*Hook run after selecting an article in the summary buffer.
981 It is meant to be used for highlighting the article in some way.  It
982 is not run if `gnus-visual' is nil."
983   :group 'gnus-summary-visual
984   :type 'hook)
985
986 (defcustom gnus-parse-headers-hook nil
987   "*A hook called before parsing the headers."
988   :group 'gnus-various
989   :type 'hook)
990
991 (defcustom gnus-exit-group-hook nil
992   "*A hook called when exiting summary mode.
993 This hook is not called from the non-updating exit commands like `Q'."
994   :group 'gnus-various
995   :type 'hook)
996
997 (defcustom gnus-summary-update-hook nil
998   "*A hook called when a summary line is changed.
999 The hook will not be called if `gnus-visual' is nil.
1000
1001 The default function `gnus-summary-highlight-line' will
1002 highlight the line according to the `gnus-summary-highlight'
1003 variable."
1004   :group 'gnus-summary-visual
1005   :type 'hook)
1006
1007 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
1008   "*A hook called when an article is selected for the first time.
1009 The hook is intended to mark an article as read (or unread)
1010 automatically when it is selected."
1011   :group 'gnus-summary-choose
1012   :type 'hook)
1013
1014 (defcustom gnus-group-no-more-groups-hook nil
1015   "*A hook run when returning to group mode having no more (unread) groups."
1016   :group 'gnus-group-select
1017   :type 'hook)
1018
1019 (defcustom gnus-ps-print-hook nil
1020   "*A hook run before ps-printing something from Gnus."
1021   :group 'gnus-summary
1022   :type 'hook)
1023
1024 (defcustom gnus-summary-article-move-hook nil
1025   "*A hook called after an article is moved, copied, respooled, or crossposted."
1026   :version "22.1"
1027   :group 'gnus-summary
1028   :type 'hook)
1029
1030 (defcustom gnus-summary-article-delete-hook nil
1031   "*A hook called after an article is deleted."
1032   :version "22.1"
1033   :group 'gnus-summary
1034   :type 'hook)
1035
1036 (defcustom gnus-summary-article-expire-hook nil
1037   "*A hook called after an article is expired."
1038   :version "22.1"
1039   :group 'gnus-summary
1040   :type 'hook)
1041
1042 (defcustom gnus-summary-display-arrow
1043   (and (fboundp 'display-graphic-p)
1044        (display-graphic-p))
1045   "*If non-nil, display an arrow highlighting the current article."
1046   :version "22.1"
1047   :group 'gnus-summary
1048   :type 'boolean)
1049
1050 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1051   "Face used for highlighting the current article in the summary buffer."
1052   :group 'gnus-summary-visual
1053   :type 'face)
1054
1055 (defvar gnus-tmp-downloaded nil)
1056
1057 (defcustom gnus-summary-highlight
1058   '(((eq mark gnus-canceled-mark)
1059      . gnus-summary-cancelled)
1060     ((and uncached (> score default-high))
1061      . gnus-summary-high-undownloaded)
1062     ((and uncached (< score default-low))
1063      . gnus-summary-low-undownloaded)
1064     (uncached
1065      . gnus-summary-normal-undownloaded)
1066     ((and (> score default-high)
1067           (or (eq mark gnus-dormant-mark)
1068               (eq mark gnus-ticked-mark)))
1069      . gnus-summary-high-ticked)
1070     ((and (< score default-low)
1071           (or (eq mark gnus-dormant-mark)
1072               (eq mark gnus-ticked-mark)))
1073      . gnus-summary-low-ticked)
1074     ((or (eq mark gnus-dormant-mark)
1075          (eq mark gnus-ticked-mark))
1076      . gnus-summary-normal-ticked)
1077     ((and (> score default-high) (eq mark gnus-ancient-mark))
1078      . gnus-summary-high-ancient)
1079     ((and (< score default-low) (eq mark gnus-ancient-mark))
1080      . gnus-summary-low-ancient)
1081     ((eq mark gnus-ancient-mark)
1082      . gnus-summary-normal-ancient)
1083     ((and (> score default-high) (eq mark gnus-unread-mark))
1084      . gnus-summary-high-unread)
1085     ((and (< score default-low) (eq mark gnus-unread-mark))
1086      . gnus-summary-low-unread)
1087     ((eq mark gnus-unread-mark)
1088      . gnus-summary-normal-unread)
1089     ((> score default-high)
1090      . gnus-summary-high-read)
1091     ((< score default-low)
1092      . gnus-summary-low-read)
1093     (t
1094      . gnus-summary-normal-read))
1095   "*Controls the highlighting of summary buffer lines.
1096
1097 A list of (FORM . FACE) pairs.  When deciding how a particular
1098 summary line should be displayed, each form is evaluated.  The content
1099 of the face field after the first true form is used.  You can change
1100 how those summary lines are displayed, by editing the face field.
1101
1102 You can use the following variables in the FORM field.
1103
1104 score:        The article's score.
1105 default:      The default article score.
1106 default-high: The default score for high scored articles.
1107 default-low:  The default score for low scored articles.
1108 below:        The score below which articles are automatically marked as read.
1109 mark:         The article's mark.
1110 uncached:     Non-nil if the article is uncached."
1111   :group 'gnus-summary-visual
1112   :type '(repeat (cons (sexp :tag "Form" nil)
1113                        face)))
1114 (put 'gnus-summary-highlight 'risky-local-variable t)
1115
1116 (defcustom gnus-alter-header-function nil
1117   "Function called to allow alteration of article header structures.
1118 The function is called with one parameter, the article header vector,
1119 which it may alter in any way."
1120   :type '(choice (const :tag "None" nil)
1121                  function)
1122   :group 'gnus-summary)
1123
1124 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1125   "Function used to decode a string with encoded words.")
1126
1127 (defvar gnus-decode-encoded-address-function
1128   'mail-decode-encoded-address-string
1129   "Function used to decode addresses with encoded words.")
1130
1131 (defcustom gnus-extra-headers '(To Cc Keywords Gcc Newsgroups)
1132   "*Extra headers to parse."
1133   :version "24.1"                       ; added Cc Keywords Gcc
1134   :group 'gnus-summary
1135   :type '(repeat symbol))
1136
1137 (defcustom gnus-ignored-from-addresses
1138   (and user-mail-address
1139        (not (string= user-mail-address ""))
1140        (regexp-quote user-mail-address))
1141   "*From headers that may be suppressed in favor of To headers.
1142 This can be a regexp or a list of regexps."
1143   :version "21.1"
1144   :group 'gnus-summary
1145   :type '(choice regexp
1146                  (repeat :tag "Regexp List" regexp)))
1147
1148 (defsubst gnus-ignored-from-addresses ()
1149   (gmm-regexp-concat gnus-ignored-from-addresses))
1150
1151 (defcustom gnus-summary-to-prefix "-> "
1152   "*String prefixed to the To field in the summary line when
1153 using `gnus-ignored-from-addresses'."
1154   :version "22.1"
1155   :group 'gnus-summary
1156   :type 'string)
1157
1158 (defcustom gnus-summary-newsgroup-prefix "=> "
1159   "*String prefixed to the Newsgroup field in the summary
1160 line when using `gnus-ignored-from-addresses'."
1161   :version "22.1"
1162   :group 'gnus-summary
1163   :type 'string)
1164
1165 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1166   "List of charsets that should be ignored.
1167 When these charsets are used in the \"charset\" parameter, the
1168 default charset will be used instead."
1169   :version "21.1"
1170   :type '(repeat symbol)
1171   :group 'gnus-charset)
1172
1173 (defcustom gnus-newsgroup-maximum-articles nil
1174   "The maximum number of articles a newsgroup.
1175 If this is a number, old articles in a newsgroup exceeding this number
1176 are silently ignored.  If it is nil, no article is ignored.  Note that
1177 setting this variable to a number might prevent you from reading very
1178 old articles."
1179   :group 'gnus-group-select
1180   :version "22.2"
1181   :type '(choice (const :tag "No limit" nil)
1182                  integer))
1183
1184 (gnus-define-group-parameter
1185  ignored-charsets
1186  :type list
1187  :function-document
1188  "Return the ignored charsets of GROUP."
1189  :variable gnus-group-ignored-charsets-alist
1190  :variable-default
1191  '(("alt\\.chinese\\.text" iso-8859-1))
1192  :variable-document
1193  "Alist of regexps (to match group names) and charsets that should be ignored.
1194 When these charsets are used in the \"charset\" parameter, the
1195 default charset will be used instead."
1196  :variable-group gnus-charset
1197  :variable-type '(repeat (cons (regexp :tag "Group")
1198                                (repeat symbol)))
1199  :parameter-type '(choice :tag "Ignored charsets"
1200                           :value nil
1201                           (repeat (symbol)))
1202  :parameter-document       "\
1203 List of charsets that should be ignored.
1204
1205 When these charsets are used in the \"charset\" parameter, the
1206 default charset will be used instead.")
1207
1208 (defcustom gnus-group-highlight-words-alist nil
1209   "Alist of group regexps and highlight regexps.
1210 This variable uses the same syntax as `gnus-emphasis-alist'."
1211   :version "21.1"
1212   :type '(repeat (cons (regexp :tag "Group")
1213                        (repeat (list (regexp :tag "Highlight regexp")
1214                                      (number :tag "Group for entire word" 0)
1215                                      (number :tag "Group for displayed part" 0)
1216                                      (symbol :tag "Face"
1217                                              gnus-emphasis-highlight-words)))))
1218   :group 'gnus-summary-visual)
1219
1220 (defcustom gnus-summary-show-article-charset-alist
1221   nil
1222   "Alist of number and charset.
1223 The article will be shown with the charset corresponding to the
1224 numbered argument.
1225 For example: ((1 . cn-gb-2312) (2 . big5))."
1226   :version "21.1"
1227   :type '(repeat (cons (number :tag "Argument" 1)
1228                        (symbol :tag "Charset")))
1229   :group 'gnus-charset)
1230
1231 (defcustom gnus-preserve-marks t
1232   "Whether marks are preserved when moving, copying and respooling messages."
1233   :version "21.1"
1234   :type 'boolean
1235   :group 'gnus-summary-marks)
1236
1237 (defcustom gnus-propagate-marks nil
1238   "If non-nil, Gnus will store and retrieve marks from the backends.
1239 This means that marks will be stored both in .newsrc.eld and in
1240 the backend, and will slow operation down somewhat."
1241   :type 'boolean
1242   :group 'gnus-summary-marks)
1243
1244 (defcustom gnus-alter-articles-to-read-function nil
1245   "Function to be called to alter the list of articles to be selected."
1246   :type '(choice (const nil) function)
1247   :group 'gnus-summary)
1248
1249 (defcustom gnus-orphan-score nil
1250   "*All orphans get this score added.  Set in the score file."
1251   :group 'gnus-score-default
1252   :type '(choice (const nil)
1253                  integer))
1254
1255 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1256   "*A regexp to match MIME parts when saving multiple parts of a
1257 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1258 This regexp will be used by default when prompting the user for which
1259 type of files to save."
1260   :group 'gnus-summary
1261   :type 'regexp)
1262
1263 (defcustom gnus-read-all-available-headers nil
1264   "Whether Gnus should parse all headers made available to it.
1265 This is mostly relevant for slow back ends where the user may
1266 wish to widen the summary buffer to include all headers
1267 that were fetched."
1268   :version "22.1"
1269   :group 'gnus-summary
1270   :type '(choice boolean regexp))
1271
1272 (defcustom gnus-summary-pipe-output-default-command nil
1273   "Command (and optional arguments) used to pipe article to subprocess.
1274 This will be used as the default command if it is non-nil.  The value
1275 will be updated if you modify it when executing the command
1276 `gnus-summary-pipe-output' or the function `gnus-summary-save-in-pipe'."
1277   :version "23.1" ;; No Gnus
1278   :group 'gnus-summary
1279   :type '(radio (const :tag "None" nil) (string :tag "Command")))
1280
1281 (defcustom gnus-summary-muttprint-program "muttprint"
1282   "Command (and optional arguments) used to run Muttprint.
1283 The value will be updated if you modify it when executing the command
1284 `gnus-summary-muttprint'."
1285   :version "22.1"
1286   :group 'gnus-summary
1287   :type 'string)
1288
1289 (defcustom gnus-article-loose-mime t
1290   "If non-nil, don't require MIME-Version header.
1291 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1292 supply the MIME-Version header or deliberately strip it from the mail.
1293 If non-nil (the default), Gnus will treat some articles as MIME
1294 even if the MIME-Version header is missing."
1295   :version "22.1"
1296   :type 'boolean
1297   :group 'gnus-article-mime)
1298
1299 (defcustom gnus-article-emulate-mime t
1300   "If non-nil, use MIME emulation for uuencode and the like.
1301 This means that Gnus will search message bodies for text that look
1302 like uuencoded bits, yEncoded bits, and so on, and present that using
1303 the normal Gnus MIME machinery."
1304   :version "22.1"
1305   :type 'boolean
1306   :group 'gnus-article-mime)
1307
1308 ;;; Internal variables
1309
1310 (defvar gnus-summary-display-cache nil)
1311 (defvar gnus-article-mime-handles nil)
1312 (defvar gnus-article-decoded-p nil)
1313 (defvar gnus-article-charset nil)
1314 (defvar gnus-article-ignored-charsets nil)
1315 (defvar gnus-scores-exclude-files nil)
1316 (defvar gnus-page-broken nil)
1317
1318 (defvar gnus-original-article nil)
1319 (defvar gnus-article-internal-prepare-hook nil)
1320 (defvar gnus-newsgroup-process-stack nil)
1321
1322 (defvar gnus-thread-indent-array nil)
1323 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1324 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1325   "Function called to sort the articles within a thread after it has been gathered together.")
1326
1327 (defvar gnus-summary-save-parts-type-history nil)
1328 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1329
1330 ;; Avoid highlighting in kill files.
1331 (defvar gnus-summary-inhibit-highlight nil)
1332 (defvar gnus-newsgroup-selected-overlay nil)
1333 (defvar gnus-inhibit-limiting nil)
1334 (defvar gnus-newsgroup-adaptive-score-file nil)
1335 (defvar gnus-current-score-file nil)
1336 (defvar gnus-current-move-group nil)
1337 (defvar gnus-current-copy-group nil)
1338 (defvar gnus-current-crosspost-group nil)
1339 (defvar gnus-newsgroup-display nil)
1340
1341 (defvar gnus-newsgroup-dependencies nil)
1342 (defvar gnus-newsgroup-adaptive nil)
1343 (defvar gnus-summary-display-article-function nil)
1344 (defvar gnus-summary-highlight-line-function nil
1345   "Function called after highlighting a summary line.")
1346
1347 (defvar gnus-summary-line-format-alist
1348   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1349     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1350     (?s gnus-tmp-subject-or-nil ?s)
1351     (?n gnus-tmp-name ?s)
1352     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1353         ?s)
1354     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1355             gnus-tmp-from) ?s)
1356     (?F gnus-tmp-from ?s)
1357     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1358     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1359     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1360     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1361     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1362     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1363     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1364     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1365     (?L gnus-tmp-lines ?s)
1366     (?Z (or ,(gnus-macroexpand-all
1367               '(nnir-article-rsv (mail-header-number gnus-tmp-header)))
1368             0) ?d)
1369     (?G (or ,(gnus-macroexpand-all
1370               '(nnir-article-group (mail-header-number gnus-tmp-header)))
1371             "") ?s)
1372     (?g (or ,(gnus-macroexpand-all
1373               '(gnus-group-short-name
1374                 (nnir-article-group (mail-header-number gnus-tmp-header))))
1375             "") ?s)
1376     (?O gnus-tmp-downloaded ?c)
1377     (?I gnus-tmp-indentation ?s)
1378     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1379     (?R gnus-tmp-replied ?c)
1380     (?\[ gnus-tmp-opening-bracket ?c)
1381     (?\] gnus-tmp-closing-bracket ?c)
1382     (?\> (make-string gnus-tmp-level ? ) ?s)
1383     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1384     (?i gnus-tmp-score ?d)
1385     (?z gnus-tmp-score-char ?c)
1386     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1387     (?U gnus-tmp-unread ?c)
1388     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1389         ?s)
1390     (?t (gnus-summary-number-of-articles-in-thread
1391          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1392         ?d)
1393     (?e (gnus-summary-number-of-articles-in-thread
1394          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1395         ?c)
1396     (?u gnus-tmp-user-defined ?s)
1397     (?P (gnus-pick-line-number) ?d)
1398     (?B gnus-tmp-thread-tree-header-string ?s)
1399     (user-date (gnus-user-date
1400                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1401   "An alist of format specifications that can appear in summary lines.
1402 These are paired with what variables they correspond with, along with
1403 the type of the variable (string, integer, character, etc).")
1404
1405 (defvar gnus-summary-dummy-line-format-alist
1406   `((?S gnus-tmp-subject ?s)
1407     (?N gnus-tmp-number ?d)
1408     (?u gnus-tmp-user-defined ?s)))
1409
1410 (defvar gnus-summary-mode-line-format-alist
1411   `((?G gnus-tmp-group-name ?s)
1412     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1413     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1414     (?A gnus-tmp-article-number ?d)
1415     (?Z gnus-tmp-unread-and-unselected ?s)
1416     (?V gnus-version ?s)
1417     (?U gnus-tmp-unread-and-unticked ?d)
1418     (?S gnus-tmp-subject ?s)
1419     (?e gnus-tmp-unselected ?d)
1420     (?u gnus-tmp-user-defined ?s)
1421     (?d (length gnus-newsgroup-dormant) ?d)
1422     (?t (length gnus-newsgroup-marked) ?d)
1423     (?h (length gnus-newsgroup-spam-marked) ?d)
1424     (?r (length gnus-newsgroup-reads) ?d)
1425     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1426     (?E gnus-newsgroup-expunged-tally ?d)
1427     (?s (gnus-current-score-file-nondirectory) ?s)))
1428
1429 ;; This is here rather than in gnus-art for compilation reasons.
1430 (defvar gnus-article-mode-line-format-alist
1431   (nconc '((?w (gnus-article-wash-status) ?s)
1432            (?m (gnus-article-mime-part-status) ?s))
1433          gnus-summary-mode-line-format-alist))
1434
1435 (defvar gnus-last-search-regexp nil
1436   "Default regexp for article search command.")
1437
1438 (defvar gnus-last-shell-command nil
1439   "Default shell command on article.")
1440
1441 (defvar gnus-newsgroup-agentized nil
1442   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1443 (defvar gnus-newsgroup-begin nil)
1444 (defvar gnus-newsgroup-end nil)
1445 (defvar gnus-newsgroup-last-rmail nil)
1446 (defvar gnus-newsgroup-last-mail nil)
1447 (defvar gnus-newsgroup-last-folder nil)
1448 (defvar gnus-newsgroup-last-file nil)
1449 (defvar gnus-newsgroup-last-directory nil)
1450 (defvar gnus-newsgroup-auto-expire nil)
1451 (defvar gnus-newsgroup-active nil)
1452 (defvar gnus-newsgroup-highest nil)
1453
1454 (defvar gnus-newsgroup-data nil)
1455 (defvar gnus-newsgroup-data-reverse nil)
1456 (defvar gnus-newsgroup-limit nil)
1457 (defvar gnus-newsgroup-limits nil)
1458 (defvar gnus-summary-use-undownloaded-faces nil)
1459
1460 (defvar gnus-newsgroup-unreads nil
1461   "Sorted list of unread articles in the current newsgroup.")
1462
1463 (defvar gnus-newsgroup-unselected nil
1464   "Sorted list of unselected unread articles in the current newsgroup.")
1465
1466 (defvar gnus-newsgroup-reads nil
1467   "Alist of read articles and article marks in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-expunged-tally nil)
1470
1471 (defvar gnus-newsgroup-marked nil
1472   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1473
1474 (defvar gnus-newsgroup-spam-marked nil
1475   "List of ranges of articles that have been marked as spam.")
1476
1477 (defvar gnus-newsgroup-killed nil
1478   "List of ranges of articles that have been through the scoring process.")
1479
1480 (defvar gnus-newsgroup-cached nil
1481   "Sorted list of articles that come from the article cache.")
1482
1483 (defvar gnus-newsgroup-saved nil
1484   "List of articles that have been saved.")
1485
1486 (defvar gnus-newsgroup-kill-headers nil)
1487
1488 (defvar gnus-newsgroup-replied nil
1489   "List of articles that have been replied to in the current newsgroup.")
1490
1491 (defvar gnus-newsgroup-forwarded nil
1492   "List of articles that have been forwarded in the current newsgroup.")
1493
1494 (defvar gnus-newsgroup-recent nil
1495   "List of articles that have are recent in the current newsgroup.")
1496
1497 (defvar gnus-newsgroup-expirable nil
1498   "Sorted list of articles in the current newsgroup that can be expired.")
1499
1500 (defvar gnus-newsgroup-processable nil
1501   "List of articles in the current newsgroup that can be processed.")
1502
1503 (defvar gnus-newsgroup-downloadable nil
1504   "Sorted list of articles in the current newsgroup that can be processed.")
1505
1506 (defvar gnus-newsgroup-unfetched nil
1507   "Sorted list of articles in the current newsgroup whose headers have
1508 not been fetched into the agent.
1509
1510 This list will always be a subset of gnus-newsgroup-undownloaded.")
1511
1512 (defvar gnus-newsgroup-undownloaded nil
1513   "List of articles in the current newsgroup that haven't been downloaded.")
1514
1515 (defvar gnus-newsgroup-unsendable nil
1516   "List of articles in the current newsgroup that won't be sent.")
1517
1518 (defvar gnus-newsgroup-bookmarks nil
1519   "List of articles in the current newsgroup that have bookmarks.")
1520
1521 (defvar gnus-newsgroup-dormant nil
1522   "Sorted list of dormant articles in the current newsgroup.")
1523
1524 (defvar gnus-newsgroup-unseen nil
1525   "List of unseen articles in the current newsgroup.")
1526
1527 (defvar gnus-newsgroup-seen nil
1528   "Range of seen articles in the current newsgroup.")
1529
1530 (defvar gnus-newsgroup-articles nil
1531   "List of articles in the current newsgroup.")
1532
1533 (defvar gnus-newsgroup-scored nil
1534   "List of scored articles in the current newsgroup.")
1535
1536 (defvar gnus-newsgroup-headers nil
1537   "List of article headers in the current newsgroup.")
1538
1539 (defvar gnus-newsgroup-threads nil)
1540
1541 (defvar gnus-newsgroup-prepared nil
1542   "Whether the current group has been prepared properly.")
1543
1544 (defvar gnus-newsgroup-ancient nil
1545   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1546
1547 (defvar gnus-newsgroup-sparse nil)
1548
1549 (defvar gnus-current-article nil)
1550 (defvar gnus-article-current nil)
1551 (defvar gnus-current-headers nil)
1552 (defvar gnus-have-all-headers nil)
1553 (defvar gnus-last-article nil)
1554 (defvar gnus-newsgroup-history nil)
1555 (defvar gnus-newsgroup-charset nil)
1556 (defvar gnus-newsgroup-ephemeral-charset nil)
1557 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1558
1559 (defvar gnus-article-before-search nil)
1560
1561 (defvar gnus-summary-local-variables
1562   '(gnus-newsgroup-name
1563
1564     ;; Marks lists
1565     gnus-newsgroup-unreads
1566     gnus-newsgroup-unselected
1567     gnus-newsgroup-marked
1568     gnus-newsgroup-spam-marked
1569     gnus-newsgroup-reads
1570     gnus-newsgroup-saved
1571     gnus-newsgroup-replied
1572     gnus-newsgroup-forwarded
1573     gnus-newsgroup-recent
1574     gnus-newsgroup-expirable
1575     gnus-newsgroup-killed
1576     gnus-newsgroup-unseen
1577     gnus-newsgroup-seen
1578     gnus-newsgroup-cached
1579     gnus-newsgroup-downloadable
1580     gnus-newsgroup-undownloaded
1581     gnus-newsgroup-unsendable
1582
1583     gnus-newsgroup-begin gnus-newsgroup-end
1584     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1585     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1586     gnus-newsgroup-last-directory
1587     gnus-newsgroup-auto-expire
1588     gnus-newsgroup-processable
1589     gnus-newsgroup-unfetched
1590     gnus-newsgroup-articles
1591     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1592     gnus-newsgroup-headers gnus-newsgroup-threads
1593     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1594     gnus-current-article gnus-current-headers gnus-have-all-headers
1595     gnus-last-article gnus-article-internal-prepare-hook
1596     (gnus-summary-article-delete-hook . global)
1597     (gnus-summary-article-move-hook . global)
1598     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1599     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1600     gnus-thread-expunge-below
1601     gnus-score-alist gnus-current-score-file
1602     (gnus-summary-expunge-below . global)
1603     (gnus-summary-mark-below . global)
1604     (gnus-orphan-score . global)
1605     gnus-newsgroup-active gnus-scores-exclude-files
1606     gnus-newsgroup-highest
1607     gnus-newsgroup-history gnus-newsgroup-ancient
1608     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1609     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1610     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1611     (gnus-newsgroup-expunged-tally . 0)
1612     gnus-cache-removable-articles
1613     gnus-newsgroup-data gnus-newsgroup-data-reverse
1614     gnus-newsgroup-limit gnus-newsgroup-limits
1615     gnus-newsgroup-charset gnus-newsgroup-display
1616     gnus-summary-use-undownloaded-faces)
1617   "Variables that are buffer-local to the summary buffers.")
1618
1619 (defvar gnus-newsgroup-variables nil
1620   "A list of variables that have separate values in different newsgroups.
1621 A list of newsgroup (summary buffer) local variables, or cons of
1622 variables and their default expressions to be evalled (when the default
1623 values are not nil), that should be made global while the summary buffer
1624 is active.
1625
1626 Note: The default expressions will be evaluated (using function `eval')
1627 before assignment to the local variable rather than just assigned to it.
1628 If the default expression is the symbol `global', that symbol will not
1629 be evaluated but the global value of the local variable will be used
1630 instead.
1631
1632 These variables can be used to set variables in the group parameters
1633 while still allowing them to affect operations done in other buffers.
1634 For example:
1635
1636 \(setq gnus-newsgroup-variables
1637      '(message-use-followup-to
1638        (gnus-visible-headers .
1639          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1640 ")
1641
1642 (eval-when-compile
1643   ;; Bind features so that require will believe that gnus-sum has
1644   ;; already been loaded (avoids infinite recursion)
1645   (let ((features (cons 'gnus-sum features)))
1646     (require 'gnus-art)))
1647
1648 ;; MIME stuff.
1649
1650 (defvar gnus-decode-encoded-word-methods
1651   '(mail-decode-encoded-word-string)
1652   "List of methods used to decode encoded words.
1653
1654 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1655 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1656 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1657 whose names match REGEXP.
1658
1659 For example:
1660 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1661  mail-decode-encoded-word-string
1662  (\"chinese\" . rfc1843-decode-string))")
1663
1664 (defvar gnus-decode-encoded-word-methods-cache nil)
1665
1666 (defun gnus-multi-decode-encoded-word-string (string)
1667   "Apply the functions from `gnus-encoded-word-methods' that match."
1668   (unless (and gnus-decode-encoded-word-methods-cache
1669                (eq gnus-newsgroup-name
1670                    (car gnus-decode-encoded-word-methods-cache)))
1671     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1672     (dolist (method gnus-decode-encoded-word-methods)
1673       (if (symbolp method)
1674           (nconc gnus-decode-encoded-word-methods-cache (list method))
1675         (if (and gnus-newsgroup-name
1676                  (string-match (car method) gnus-newsgroup-name))
1677             (nconc gnus-decode-encoded-word-methods-cache
1678                    (list (cdr method)))))))
1679   (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1680     (setq string (funcall method string))))
1681
1682 ;; Subject simplification.
1683
1684 (defun gnus-simplify-whitespace (str)
1685   "Remove excessive whitespace from STR."
1686   ;; Multiple spaces.
1687   (while (string-match "[ \t][ \t]+" str)
1688     (setq str (concat (substring str 0 (match-beginning 0))
1689                         " "
1690                         (substring str (match-end 0)))))
1691   ;; Leading spaces.
1692   (when (string-match "^[ \t]+" str)
1693     (setq str (substring str (match-end 0))))
1694   ;; Trailing spaces.
1695   (when (string-match "[ \t]+$" str)
1696     (setq str (substring str 0 (match-beginning 0))))
1697   str)
1698
1699 (defun gnus-simplify-all-whitespace (str)
1700   "Remove all whitespace from STR."
1701   (while (string-match "[ \t\n]+" str)
1702     (setq str (replace-match "" nil nil str)))
1703   str)
1704
1705 (defsubst gnus-simplify-subject-re (subject)
1706   "Remove \"Re:\" from subject lines."
1707   (if (string-match message-subject-re-regexp subject)
1708       (substring subject (match-end 0))
1709     subject))
1710
1711 (defun gnus-simplify-subject (subject &optional re-only)
1712   "Remove `Re:' and words in parentheses.
1713 If RE-ONLY is non-nil, strip leading `Re:'s only."
1714   (let ((case-fold-search t))           ;Ignore case.
1715     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1716     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1717       (setq subject (substring subject (match-end 0))))
1718     ;; Remove uninteresting prefixes.
1719     (when (and (not re-only)
1720                gnus-simplify-ignored-prefixes
1721                (string-match gnus-simplify-ignored-prefixes subject))
1722       (setq subject (substring subject (match-end 0))))
1723     ;; Remove words in parentheses from end.
1724     (unless re-only
1725       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1726         (setq subject (substring subject 0 (match-beginning 0)))))
1727     ;; Return subject string.
1728     subject))
1729
1730 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1731 ;; all whitespace.
1732 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1733   (goto-char (point-min))
1734   (while (re-search-forward regexp nil t)
1735     (replace-match (or newtext ""))))
1736
1737 (defun gnus-simplify-buffer-fuzzy (regexp)
1738   "Simplify string in the buffer fuzzily.
1739 The string in the accessible portion of the current buffer is simplified.
1740 It is assumed to be a single-line subject.
1741 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1742 matter is removed.  Additional things can be deleted by setting
1743 `gnus-simplify-subject-fuzzy-regexp'."
1744   (let ((case-fold-search t)
1745         (modified-tick))
1746     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1747
1748     (while (not (eq modified-tick (buffer-modified-tick)))
1749       (setq modified-tick (buffer-modified-tick))
1750       (cond
1751        ((listp regexp)
1752         (mapc 'gnus-simplify-buffer-fuzzy-step regexp))
1753        (regexp
1754         (gnus-simplify-buffer-fuzzy-step regexp)))
1755       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1756       (gnus-simplify-buffer-fuzzy-step
1757        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1758       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1759
1760     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1761     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1762     (gnus-simplify-buffer-fuzzy-step " $")
1763     (gnus-simplify-buffer-fuzzy-step "^ +")))
1764
1765 (defun gnus-simplify-subject-fuzzy (subject)
1766   "Simplify a subject string fuzzily.
1767 See `gnus-simplify-buffer-fuzzy' for details."
1768   (save-excursion
1769     (let ((regexp gnus-simplify-subject-fuzzy-regexp))
1770       (gnus-set-work-buffer)
1771       (let ((case-fold-search t))
1772         ;; Remove uninteresting prefixes.
1773         (when (and gnus-simplify-ignored-prefixes
1774                    (string-match gnus-simplify-ignored-prefixes subject))
1775           (setq subject (substring subject (match-end 0))))
1776         (insert subject)
1777         (inline (gnus-simplify-buffer-fuzzy regexp))
1778         (buffer-string)))))
1779
1780 (defsubst gnus-simplify-subject-fully (subject)
1781   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1782   (cond
1783    (gnus-simplify-subject-functions
1784     (gnus-map-function gnus-simplify-subject-functions subject))
1785    ((null gnus-summary-gather-subject-limit)
1786     (gnus-simplify-subject-re subject))
1787    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1788     (gnus-simplify-subject-fuzzy subject))
1789    ((numberp gnus-summary-gather-subject-limit)
1790     (truncate-string-to-width (gnus-simplify-subject-re subject)
1791                               gnus-summary-gather-subject-limit))
1792    (t
1793     subject)))
1794
1795 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1796   "Check whether two subjects are equal.
1797 If optional argument SIMPLE-FIRST is t, first argument is already
1798 simplified."
1799   (cond
1800    ((null simple-first)
1801     (equal (gnus-simplify-subject-fully s1)
1802            (gnus-simplify-subject-fully s2)))
1803    (t
1804     (equal s1
1805            (gnus-simplify-subject-fully s2)))))
1806
1807 (defun gnus-summary-bubble-group ()
1808   "Increase the score of the current group.
1809 This is a handy function to add to `gnus-summary-exit-hook' to
1810 increase the score of each group you read."
1811   (gnus-group-add-score gnus-newsgroup-name))
1812
1813 \f
1814 ;;;
1815 ;;; Gnus summary mode
1816 ;;;
1817
1818 (put 'gnus-summary-mode 'mode-class 'special)
1819
1820 (defvar gnus-article-commands-menu)
1821
1822 ;; Non-orthogonal keys
1823
1824 (gnus-define-keys gnus-summary-mode-map
1825   " " gnus-summary-next-page
1826   "\177" gnus-summary-prev-page
1827   [delete] gnus-summary-prev-page
1828   [backspace] gnus-summary-prev-page
1829   "\r" gnus-summary-scroll-up
1830   "\M-\r" gnus-summary-scroll-down
1831   "n" gnus-summary-next-unread-article
1832   "p" gnus-summary-prev-unread-article
1833   "N" gnus-summary-next-article
1834   "P" gnus-summary-prev-article
1835   "\M-\C-n" gnus-summary-next-same-subject
1836   "\M-\C-p" gnus-summary-prev-same-subject
1837   "\M-n" gnus-summary-next-unread-subject
1838   "\M-p" gnus-summary-prev-unread-subject
1839   "." gnus-summary-first-unread-article
1840   "," gnus-summary-best-unread-article
1841   "\M-s" gnus-summary-search-article-forward
1842   "\M-r" gnus-summary-search-article-backward
1843   "\M-S" gnus-summary-repeat-search-article-forward
1844   "\M-R" gnus-summary-repeat-search-article-backward
1845   "<" gnus-summary-beginning-of-article
1846   ">" gnus-summary-end-of-article
1847   "j" gnus-summary-goto-article
1848   "^" gnus-summary-refer-parent-article
1849   "\M-^" gnus-summary-refer-article
1850   "u" gnus-summary-tick-article-forward
1851   "!" gnus-summary-tick-article-forward
1852   "U" gnus-summary-tick-article-backward
1853   "d" gnus-summary-mark-as-read-forward
1854   "D" gnus-summary-mark-as-read-backward
1855   "E" gnus-summary-mark-as-expirable
1856   "\M-u" gnus-summary-clear-mark-forward
1857   "\M-U" gnus-summary-clear-mark-backward
1858   "k" gnus-summary-kill-same-subject-and-select
1859   "\C-k" gnus-summary-kill-same-subject
1860   "\M-\C-k" gnus-summary-kill-thread
1861   "\M-\C-l" gnus-summary-lower-thread
1862   "e" gnus-summary-edit-article
1863   "#" gnus-summary-mark-as-processable
1864   "\M-#" gnus-summary-unmark-as-processable
1865   "\M-\C-t" gnus-summary-toggle-threads
1866   "\M-\C-s" gnus-summary-show-thread
1867   "\M-\C-h" gnus-summary-hide-thread
1868   "\M-\C-f" gnus-summary-next-thread
1869   "\M-\C-b" gnus-summary-prev-thread
1870   [(meta down)] gnus-summary-next-thread
1871   [(meta up)] gnus-summary-prev-thread
1872   "\M-\C-u" gnus-summary-up-thread
1873   "\M-\C-d" gnus-summary-down-thread
1874   "&" gnus-summary-execute-command
1875   "c" gnus-summary-catchup-and-exit
1876   "\C-w" gnus-summary-mark-region-as-read
1877   "\C-t" gnus-summary-toggle-truncation
1878   "?" gnus-summary-mark-as-dormant
1879   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1880   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1881   "\C-c\C-s\C-m\C-n" gnus-summary-sort-by-most-recent-number
1882   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1883   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1884   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1885   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1886   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1887   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1888   "\C-c\C-s\C-m\C-d" gnus-summary-sort-by-most-recent-date
1889   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1890   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1891   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1892   "=" gnus-summary-expand-window
1893   "\C-x\C-s" gnus-summary-reselect-current-group
1894   "\M-g" gnus-summary-rescan-group
1895   "\C-c\C-r" gnus-summary-caesar-message
1896   "f" gnus-summary-followup
1897   "F" gnus-summary-followup-with-original
1898   "C" gnus-summary-cancel-article
1899   "r" gnus-summary-reply
1900   "R" gnus-summary-reply-with-original
1901   "\C-c\C-f" gnus-summary-mail-forward
1902   "o" gnus-summary-save-article
1903   "\C-o" gnus-summary-save-article-mail
1904   "|" gnus-summary-pipe-output
1905   "\M-k" gnus-summary-edit-local-kill
1906   "\M-K" gnus-summary-edit-global-kill
1907   ;; "V" gnus-version
1908   "\C-c\C-d" gnus-summary-describe-group
1909   "q" gnus-summary-exit
1910   "Q" gnus-summary-exit-no-update
1911   "\C-c\C-i" gnus-info-find-node
1912   gnus-mouse-2 gnus-mouse-pick-article
1913   [follow-link] mouse-face
1914   "m" gnus-summary-mail-other-window
1915   "a" gnus-summary-post-news
1916   "x" gnus-summary-limit-to-unread
1917   "s" gnus-summary-isearch-article
1918   [tab] gnus-summary-widget-forward
1919   "t" gnus-summary-toggle-header
1920   "g" gnus-summary-show-article
1921   "l" gnus-summary-goto-last-article
1922   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1923   "\C-d" gnus-summary-enter-digest-group
1924   "\M-\C-d" gnus-summary-read-document
1925   "\M-\C-e" gnus-summary-edit-parameters
1926   "\M-\C-a" gnus-summary-customize-parameters
1927   "\C-c\C-b" gnus-bug
1928   "*" gnus-cache-enter-article
1929   "\M-*" gnus-cache-remove-article
1930   "\M-&" gnus-summary-universal-argument
1931   "\C-l" gnus-recenter
1932   "I" gnus-summary-increase-score
1933   "L" gnus-summary-lower-score
1934   "\M-i" gnus-symbolic-argument
1935   "h" gnus-summary-select-article-buffer
1936
1937   "b" gnus-article-view-part
1938   "\M-t" gnus-summary-toggle-display-buttonized
1939
1940   "V" gnus-summary-score-map
1941   "X" gnus-uu-extract-map
1942   "S" gnus-summary-send-map)
1943
1944 ;; Sort of orthogonal keymap
1945 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1946   "t" gnus-summary-tick-article-forward
1947   "!" gnus-summary-tick-article-forward
1948   "d" gnus-summary-mark-as-read-forward
1949   "r" gnus-summary-mark-as-read-forward
1950   "c" gnus-summary-clear-mark-forward
1951   " " gnus-summary-clear-mark-forward
1952   "e" gnus-summary-mark-as-expirable
1953   "x" gnus-summary-mark-as-expirable
1954   "?" gnus-summary-mark-as-dormant
1955   "b" gnus-summary-set-bookmark
1956   "B" gnus-summary-remove-bookmark
1957   "#" gnus-summary-mark-as-processable
1958   "\M-#" gnus-summary-unmark-as-processable
1959   "S" gnus-summary-limit-include-expunged
1960   "C" gnus-summary-catchup
1961   "H" gnus-summary-catchup-to-here
1962   "h" gnus-summary-catchup-from-here
1963   "\C-c" gnus-summary-catchup-all
1964   "k" gnus-summary-kill-same-subject-and-select
1965   "K" gnus-summary-kill-same-subject
1966   "P" gnus-uu-mark-map)
1967
1968 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1969   "c" gnus-summary-clear-above
1970   "u" gnus-summary-tick-above
1971   "m" gnus-summary-mark-above
1972   "k" gnus-summary-kill-below)
1973
1974 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1975   "/" gnus-summary-limit-to-subject
1976   "n" gnus-summary-limit-to-articles
1977   "b" gnus-summary-limit-to-bodies
1978   "h" gnus-summary-limit-to-headers
1979   "w" gnus-summary-pop-limit
1980   "s" gnus-summary-limit-to-subject
1981   "a" gnus-summary-limit-to-author
1982   "u" gnus-summary-limit-to-unread
1983   "m" gnus-summary-limit-to-marks
1984   "M" gnus-summary-limit-exclude-marks
1985   "v" gnus-summary-limit-to-score
1986   "*" gnus-summary-limit-include-cached
1987   "D" gnus-summary-limit-include-dormant
1988   "T" gnus-summary-limit-include-thread
1989   "d" gnus-summary-limit-exclude-dormant
1990   "t" gnus-summary-limit-to-age
1991   "." gnus-summary-limit-to-unseen
1992   "x" gnus-summary-limit-to-extra
1993   "p" gnus-summary-limit-to-display-predicate
1994   "E" gnus-summary-limit-include-expunged
1995   "c" gnus-summary-limit-exclude-childless-dormant
1996   "C" gnus-summary-limit-mark-excluded-as-read
1997   "o" gnus-summary-insert-old-articles
1998   "N" gnus-summary-insert-new-articles
1999   "S" gnus-summary-limit-to-singletons
2000   "r" gnus-summary-limit-to-replied
2001   "R" gnus-summary-limit-to-recipient
2002   "A" gnus-summary-limit-to-address)
2003
2004 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
2005   "n" gnus-summary-next-unread-article
2006   "p" gnus-summary-prev-unread-article
2007   "N" gnus-summary-next-article
2008   "P" gnus-summary-prev-article
2009   "\C-n" gnus-summary-next-same-subject
2010   "\C-p" gnus-summary-prev-same-subject
2011   "\M-n" gnus-summary-next-unread-subject
2012   "\M-p" gnus-summary-prev-unread-subject
2013   "f" gnus-summary-first-unread-article
2014   "b" gnus-summary-best-unread-article
2015   "j" gnus-summary-goto-article
2016   "g" gnus-summary-goto-subject
2017   "l" gnus-summary-goto-last-article
2018   "o" gnus-summary-pop-article)
2019
2020 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
2021   "k" gnus-summary-kill-thread
2022   "E" gnus-summary-expire-thread
2023   "l" gnus-summary-lower-thread
2024   "i" gnus-summary-raise-thread
2025   "T" gnus-summary-toggle-threads
2026   "t" gnus-summary-rethread-current
2027   "^" gnus-summary-reparent-thread
2028   "\M-^" gnus-summary-reparent-children
2029   "s" gnus-summary-show-thread
2030   "S" gnus-summary-show-all-threads
2031   "h" gnus-summary-hide-thread
2032   "H" gnus-summary-hide-all-threads
2033   "n" gnus-summary-next-thread
2034   "p" gnus-summary-prev-thread
2035   "u" gnus-summary-up-thread
2036   "o" gnus-summary-top-thread
2037   "d" gnus-summary-down-thread
2038   "#" gnus-uu-mark-thread
2039   "\M-#" gnus-uu-unmark-thread)
2040
2041 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
2042   "g" gnus-summary-prepare
2043   "c" gnus-summary-insert-cached-articles
2044   "d" gnus-summary-insert-dormant-articles
2045   "t" gnus-summary-insert-ticked-articles)
2046
2047 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
2048   "c" gnus-summary-catchup-and-exit
2049   "C" gnus-summary-catchup-all-and-exit
2050   "E" gnus-summary-exit-no-update
2051   "Q" gnus-summary-exit
2052   "Z" gnus-summary-exit
2053   "n" gnus-summary-catchup-and-goto-next-group
2054   "p" gnus-summary-catchup-and-goto-prev-group
2055   "R" gnus-summary-reselect-current-group
2056   "G" gnus-summary-rescan-group
2057   "N" gnus-summary-next-group
2058   "s" gnus-summary-save-newsrc
2059   "P" gnus-summary-prev-group)
2060
2061 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
2062   " " gnus-summary-next-page
2063   "n" gnus-summary-next-page
2064   "\177" gnus-summary-prev-page
2065   [delete] gnus-summary-prev-page
2066   "p" gnus-summary-prev-page
2067   "\r" gnus-summary-scroll-up
2068   "\M-\r" gnus-summary-scroll-down
2069   "<" gnus-summary-beginning-of-article
2070   ">" gnus-summary-end-of-article
2071   "b" gnus-summary-beginning-of-article
2072   "e" gnus-summary-end-of-article
2073   "^" gnus-summary-refer-parent-article
2074   "r" gnus-summary-refer-parent-article
2075   "C" gnus-summary-show-complete-article
2076   "D" gnus-summary-enter-digest-group
2077   "R" gnus-summary-refer-references
2078   "T" gnus-summary-refer-thread
2079   "W" gnus-warp-to-article
2080   "g" gnus-summary-show-article
2081   "s" gnus-summary-isearch-article
2082   [tab] gnus-summary-widget-forward
2083   "P" gnus-summary-print-article
2084   "S" gnus-sticky-article
2085   "M" gnus-mailing-list-insinuate
2086   "t" gnus-article-babel)
2087
2088 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2089   "b" gnus-article-add-buttons
2090   "B" gnus-article-add-buttons-to-head
2091   "o" gnus-article-treat-overstrike
2092   "e" gnus-article-emphasize
2093   "w" gnus-article-fill-cited-article
2094   "Q" gnus-article-fill-long-lines
2095   "L" gnus-article-toggle-truncate-lines
2096   "C" gnus-article-capitalize-sentences
2097   "c" gnus-article-remove-cr
2098   "q" gnus-article-de-quoted-unreadable
2099   "6" gnus-article-de-base64-unreadable
2100   "Z" gnus-article-decode-HZ
2101   "A" gnus-article-treat-ansi-sequences
2102   "h" gnus-article-wash-html
2103   "u" gnus-article-unsplit-urls
2104   "s" gnus-summary-force-verify-and-decrypt
2105   "f" gnus-article-display-x-face
2106   "l" gnus-summary-stop-page-breaking
2107   "r" gnus-summary-caesar-message
2108   "m" gnus-summary-morse-message
2109   "t" gnus-summary-toggle-header
2110   "g" gnus-treat-smiley
2111   "v" gnus-summary-verbose-headers
2112   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2113   "p" gnus-article-verify-x-pgp-sig
2114   "d" gnus-article-treat-dumbquotes
2115   "U" gnus-article-treat-non-ascii
2116   "i" gnus-summary-idna-message)
2117
2118 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2119   ;; mnemonic: deuglif*Y*
2120   "u" gnus-article-outlook-unwrap-lines
2121   "a" gnus-article-outlook-repair-attribution
2122   "c" gnus-article-outlook-rearrange-citation
2123   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2124
2125 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2126   "a" gnus-article-hide
2127   "h" gnus-article-hide-headers
2128   "b" gnus-article-hide-boring-headers
2129   "s" gnus-article-hide-signature
2130   "c" gnus-article-hide-citation
2131   "C" gnus-article-hide-citation-in-followups
2132   "l" gnus-article-hide-list-identifiers
2133   "B" gnus-article-strip-banner
2134   "P" gnus-article-hide-pem
2135   "\C-c" gnus-article-hide-citation-maybe)
2136
2137 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2138   "a" gnus-article-highlight
2139   "h" gnus-article-highlight-headers
2140   "c" gnus-article-highlight-citation
2141   "s" gnus-article-highlight-signature)
2142
2143 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2144   "f" gnus-article-treat-fold-headers
2145   "u" gnus-article-treat-unfold-headers
2146   "n" gnus-article-treat-fold-newsgroups)
2147
2148 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2149   "x" gnus-article-display-x-face
2150   "d" gnus-article-display-face
2151   "s" gnus-treat-smiley
2152   "D" gnus-article-remove-images
2153   "W" gnus-article-show-images
2154   "f" gnus-treat-from-picon
2155   "m" gnus-treat-mail-picon
2156   "n" gnus-treat-newsgroups-picon
2157   "g" gnus-treat-from-gravatar
2158   "h" gnus-treat-mail-gravatar)
2159
2160 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2161   "w" gnus-article-decode-mime-words
2162   "c" gnus-article-decode-charset
2163   "v" gnus-mime-view-all-parts
2164   "b" gnus-article-view-part)
2165
2166 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2167   "z" gnus-article-date-ut
2168   "u" gnus-article-date-ut
2169   "l" gnus-article-date-local
2170   "p" gnus-article-date-english
2171   "e" gnus-article-date-lapsed
2172   "o" gnus-article-date-original
2173   "i" gnus-article-date-iso8601
2174   "s" gnus-article-date-user)
2175
2176 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2177   "t" gnus-article-remove-trailing-blank-lines
2178   "l" gnus-article-strip-leading-blank-lines
2179   "m" gnus-article-strip-multiple-blank-lines
2180   "a" gnus-article-strip-blank-lines
2181   "A" gnus-article-strip-all-blank-lines
2182   "s" gnus-article-strip-leading-space
2183   "e" gnus-article-strip-trailing-space
2184   "w" gnus-article-remove-leading-whitespace)
2185
2186 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2187   "v" gnus-version
2188   "d" gnus-summary-describe-group
2189   "h" gnus-summary-describe-briefly
2190   "i" gnus-info-find-node)
2191
2192 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2193   "e" gnus-summary-expire-articles
2194   "\M-\C-e" gnus-summary-expire-articles-now
2195   "\177" gnus-summary-delete-article
2196   [delete] gnus-summary-delete-article
2197   [backspace] gnus-summary-delete-article
2198   "m" gnus-summary-move-article
2199   "r" gnus-summary-respool-article
2200   "w" gnus-summary-edit-article
2201   "c" gnus-summary-copy-article
2202   "B" gnus-summary-crosspost-article
2203   "q" gnus-summary-respool-query
2204   "t" gnus-summary-respool-trace
2205   "i" gnus-summary-import-article
2206   "I" gnus-summary-create-article
2207   "p" gnus-summary-article-posted-p)
2208
2209 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2210   "o" gnus-summary-save-article
2211   "m" gnus-summary-save-article-mail
2212   "F" gnus-summary-write-article-file
2213   "r" gnus-summary-save-article-rmail
2214   "f" gnus-summary-save-article-file
2215   "b" gnus-summary-save-article-body-file
2216   "B" gnus-summary-write-article-body-file
2217   "h" gnus-summary-save-article-folder
2218   "v" gnus-summary-save-article-vm
2219   "p" gnus-summary-pipe-output
2220   "P" gnus-summary-muttprint)
2221
2222 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2223   "b" gnus-summary-display-buttonized
2224   "m" gnus-summary-repair-multipart
2225   "v" gnus-article-view-part
2226   "o" gnus-article-save-part
2227   "O" gnus-article-save-part-and-strip
2228   "r" gnus-article-replace-part
2229   "d" gnus-article-delete-part
2230   "t" gnus-article-view-part-as-type
2231   "j" gnus-article-jump-to-part
2232   "c" gnus-article-copy-part
2233   "C" gnus-article-view-part-as-charset
2234   "e" gnus-article-view-part-externally
2235   "H" gnus-article-browse-html-article
2236   "E" gnus-article-encrypt-body
2237   "i" gnus-article-inline-part
2238   "|" gnus-article-pipe-part)
2239
2240 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2241   "p" gnus-summary-mark-as-processable
2242   "u" gnus-summary-unmark-as-processable
2243   "U" gnus-summary-unmark-all-processable
2244   "v" gnus-uu-mark-over
2245   "s" gnus-uu-mark-series
2246   "r" gnus-uu-mark-region
2247   "g" gnus-uu-unmark-region
2248   "R" gnus-uu-mark-by-regexp
2249   "G" gnus-uu-unmark-by-regexp
2250   "t" gnus-uu-mark-thread
2251   "T" gnus-uu-unmark-thread
2252   "a" gnus-uu-mark-all
2253   "b" gnus-uu-mark-buffer
2254   "S" gnus-uu-mark-sparse
2255   "k" gnus-summary-kill-process-mark
2256   "y" gnus-summary-yank-process-mark
2257   "w" gnus-summary-save-process-mark
2258   "i" gnus-uu-invert-processable)
2259
2260 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2261   ;;"x" gnus-uu-extract-any
2262   "m" gnus-summary-save-parts
2263   "u" gnus-uu-decode-uu
2264   "U" gnus-uu-decode-uu-and-save
2265   "s" gnus-uu-decode-unshar
2266   "S" gnus-uu-decode-unshar-and-save
2267   "o" gnus-uu-decode-save
2268   "O" gnus-uu-decode-save
2269   "b" gnus-uu-decode-binhex
2270   "B" gnus-uu-decode-binhex
2271   "Y" gnus-uu-decode-yenc
2272   "p" gnus-uu-decode-postscript
2273   "P" gnus-uu-decode-postscript-and-save)
2274
2275 (gnus-define-keys
2276     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2277   "u" gnus-uu-decode-uu-view
2278   "U" gnus-uu-decode-uu-and-save-view
2279   "s" gnus-uu-decode-unshar-view
2280   "S" gnus-uu-decode-unshar-and-save-view
2281   "o" gnus-uu-decode-save-view
2282   "O" gnus-uu-decode-save-view
2283   "b" gnus-uu-decode-binhex-view
2284   "B" gnus-uu-decode-binhex-view
2285   "p" gnus-uu-decode-postscript-view
2286   "P" gnus-uu-decode-postscript-and-save-view)
2287
2288 (defvar gnus-article-post-menu nil)
2289
2290 (defconst gnus-summary-menu-maxlen 20)
2291
2292 (defun gnus-summary-menu-split (menu)
2293   ;; If we have lots of elements, divide them into groups of 20
2294   ;; and make a pane (or submenu) for each one.
2295   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2296       (let ((menu menu) sublists next
2297             (i 1))
2298         (while menu
2299           ;; Pull off the next gnus-summary-menu-maxlen elements
2300           ;; and make them the next element of sublist.
2301           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2302           (if next
2303               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2304                       nil))
2305           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2306                                              (aref (car (last menu)) 0)) menu)
2307                                sublists))
2308           (setq i (1+ i))
2309           (setq menu next))
2310         (nreverse sublists))
2311     ;; Few elements--put them all in one pane.
2312     menu))
2313
2314 (defun gnus-summary-make-menu-bar ()
2315   (gnus-turn-off-edit-menu 'summary)
2316
2317   (unless (boundp 'gnus-summary-misc-menu)
2318
2319     (easy-menu-define
2320       gnus-summary-kill-menu gnus-summary-mode-map ""
2321       (cons
2322        "Score"
2323        (nconc
2324         (list
2325          ["Customize" gnus-score-customize t])
2326         (gnus-make-score-map 'increase)
2327         (gnus-make-score-map 'lower)
2328         '(("Mark"
2329            ["Kill below" gnus-summary-kill-below t]
2330            ["Mark above" gnus-summary-mark-above t]
2331            ["Tick above" gnus-summary-tick-above t]
2332            ["Clear above" gnus-summary-clear-above t])
2333           ["Current score" gnus-summary-current-score t]
2334           ["Set score" gnus-summary-set-score t]
2335           ["Switch current score file..." gnus-score-change-score-file t]
2336           ["Set mark below..." gnus-score-set-mark-below t]
2337           ["Set expunge below..." gnus-score-set-expunge-below t]
2338           ["Edit current score file" gnus-score-edit-current-scores t]
2339           ["Edit score file..." gnus-score-edit-file t]
2340           ["Trace score" gnus-score-find-trace t]
2341           ["Find words" gnus-score-find-favourite-words t]
2342           ["Rescore buffer" gnus-summary-rescore t]
2343           ["Increase score..." gnus-summary-increase-score t]
2344           ["Lower score..." gnus-summary-lower-score t]))))
2345
2346     ;; Define both the Article menu in the summary buffer and the
2347     ;; equivalent Commands menu in the article buffer here for
2348     ;; consistency.
2349     (let ((innards
2350            `(("Hide"
2351               ["All" gnus-article-hide t]
2352               ["Headers" gnus-article-hide-headers t]
2353               ["Signature" gnus-article-hide-signature t]
2354               ["Citation" gnus-article-hide-citation t]
2355               ["List identifiers" gnus-article-hide-list-identifiers t]
2356               ["Banner" gnus-article-strip-banner t]
2357               ["Boring headers" gnus-article-hide-boring-headers t])
2358              ("Highlight"
2359               ["All" gnus-article-highlight t]
2360               ["Headers" gnus-article-highlight-headers t]
2361               ["Signature" gnus-article-highlight-signature t]
2362               ["Citation" gnus-article-highlight-citation t])
2363              ("MIME"
2364               ["Words" gnus-article-decode-mime-words t]
2365               ["Charset" gnus-article-decode-charset t]
2366               ["QP" gnus-article-de-quoted-unreadable t]
2367               ["Base64" gnus-article-de-base64-unreadable t]
2368               ["View MIME buttons" gnus-summary-display-buttonized t]
2369               ["View all" gnus-mime-view-all-parts t]
2370               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2371               ["Encrypt body" gnus-article-encrypt-body
2372                :active (not (gnus-group-read-only-p))
2373                ,@(if (featurep 'xemacs) nil
2374                    '(:help "Encrypt the message body on disk"))]
2375               ["Extract all parts..." gnus-summary-save-parts t]
2376               ("Multipart"
2377                ["Repair multipart" gnus-summary-repair-multipart t]
2378                ["Pipe part..." gnus-article-pipe-part t]
2379                ["Inline part" gnus-article-inline-part t]
2380                ["View part as type..." gnus-article-view-part-as-type t]
2381                ["Encrypt body" gnus-article-encrypt-body
2382                 :active (not (gnus-group-read-only-p))
2383                ,@(if (featurep 'xemacs) nil
2384                    '(:help "Encrypt the message body on disk"))]
2385                ["View part externally" gnus-article-view-part-externally t]
2386                ["View HTML parts in browser" gnus-article-browse-html-article t]
2387                ["View part with charset..." gnus-article-view-part-as-charset t]
2388                ["Copy part" gnus-article-copy-part t]
2389                ["Save part..." gnus-article-save-part t]
2390                ["View part" gnus-article-view-part t]))
2391              ("Date"
2392               ["Local" gnus-article-date-local t]
2393               ["ISO8601" gnus-article-date-iso8601 t]
2394               ["UT" gnus-article-date-ut t]
2395               ["Original" gnus-article-date-original t]
2396               ["Lapsed" gnus-article-date-lapsed t]
2397               ["User-defined" gnus-article-date-user t])
2398              ("Display"
2399               ["Remove images" gnus-article-remove-images t]
2400               ["Toggle smiley" gnus-treat-smiley t]
2401               ["Show X-Face" gnus-article-display-x-face t]
2402               ["Show picons in From" gnus-treat-from-picon t]
2403               ["Show picons in mail headers" gnus-treat-mail-picon t]
2404               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2405               ["Show Gravatars in From" gnus-treat-from-gravatar t]
2406               ["Show Gravatars in mail headers" gnus-treat-mail-gravatar t]
2407               ("View as different encoding"
2408                ,@(gnus-summary-menu-split
2409                   (mapcar
2410                    (lambda (cs)
2411                      ;; Since easymenu under Emacs doesn't allow
2412                      ;; lambda forms for menu commands, we should
2413                      ;; provide intern'ed function symbols.
2414                      (let ((command (intern (format "\
2415 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2416                        (fset command
2417                              `(lambda ()
2418                                 (interactive)
2419                                 (let ((gnus-summary-show-article-charset-alist
2420                                        '((1 . ,cs))))
2421                                   (gnus-summary-show-article 1))))
2422                        `[,(symbol-name cs) ,command t]))
2423                    (sort (if (fboundp 'coding-system-list)
2424                              (coding-system-list)
2425                            (mapcar 'car mm-mime-mule-charset-alist))
2426                          'string<)))))
2427              ("Washing"
2428               ("Remove Blanks"
2429                ["Leading" gnus-article-strip-leading-blank-lines t]
2430                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2431                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2432                ["All of the above" gnus-article-strip-blank-lines t]
2433                ["All" gnus-article-strip-all-blank-lines t]
2434                ["Leading space" gnus-article-strip-leading-space t]
2435                ["Trailing space" gnus-article-strip-trailing-space t]
2436                ["Leading space in headers"
2437                 gnus-article-remove-leading-whitespace t])
2438               ["Overstrike" gnus-article-treat-overstrike t]
2439               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2440               ["Non-ASCII" gnus-article-treat-non-ascii t]
2441               ["Emphasis" gnus-article-emphasize t]
2442               ["Word wrap" gnus-article-fill-cited-article t]
2443               ["Fill long lines" gnus-article-fill-long-lines t]
2444               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2445               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2446               ["Remove CR" gnus-article-remove-cr t]
2447               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2448               ["Base64" gnus-article-de-base64-unreadable t]
2449               ["Rot 13" gnus-summary-caesar-message
2450                ,@(if (featurep 'xemacs) '(t)
2451                    '(:help "\"Caesar rotate\" article by 13"))]
2452               ["De-IDNA" gnus-summary-idna-message t]
2453               ["Morse decode" gnus-summary-morse-message t]
2454               ["Unix pipe..." gnus-summary-pipe-message t]
2455               ["Add buttons" gnus-article-add-buttons t]
2456               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2457               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2458               ["Verbose header" gnus-summary-verbose-headers t]
2459               ["Toggle header" gnus-summary-toggle-header t]
2460               ["Unfold headers" gnus-article-treat-unfold-headers t]
2461               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2462               ["Html" gnus-article-wash-html t]
2463               ["Unsplit URLs" gnus-article-unsplit-urls t]
2464               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2465               ["Decode HZ" gnus-article-decode-HZ t]
2466               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2467               ("(Outlook) Deuglify"
2468                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2469                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2470                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2471                ["Full (Outlook) deuglify"
2472                 gnus-article-outlook-deuglify-article t])
2473               )
2474              ("Output"
2475               ["Save in default format..." gnus-summary-save-article
2476                ,@(if (featurep 'xemacs) '(t)
2477                    '(:help "Save article using default method"))]
2478               ["Save in file..." gnus-summary-save-article-file
2479                ,@(if (featurep 'xemacs) '(t)
2480                    '(:help "Save article in file"))]
2481               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2482               ["Save in MH folder..." gnus-summary-save-article-folder t]
2483               ["Save in VM folder..." gnus-summary-save-article-vm t]
2484               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2485               ["Save body in file..." gnus-summary-save-article-body-file t]
2486               ["Pipe through a filter..." gnus-summary-pipe-output t]
2487               ["Print with Muttprint..." gnus-summary-muttprint t]
2488               ["Print" gnus-summary-print-article
2489                ,@(if (featurep 'xemacs) '(t)
2490                    '(:help "Generate and print a PostScript image"))])
2491              ("Copy, move,... (Backend)"
2492               ,@(if (featurep 'xemacs) nil
2493                   '(:help "Copying, moving, expiring articles..."))
2494               ["Respool article..." gnus-summary-respool-article t]
2495               ["Move article..." gnus-summary-move-article
2496                (gnus-check-backend-function
2497                 'request-move-article gnus-newsgroup-name)]
2498               ["Copy article..." gnus-summary-copy-article t]
2499               ["Crosspost article..." gnus-summary-crosspost-article
2500                (gnus-check-backend-function
2501                 'request-replace-article gnus-newsgroup-name)]
2502               ["Import file..." gnus-summary-import-article
2503                (gnus-check-backend-function
2504                 'request-accept-article gnus-newsgroup-name)]
2505               ["Create article..." gnus-summary-create-article
2506                (gnus-check-backend-function
2507                 'request-accept-article gnus-newsgroup-name)]
2508               ["Check if posted" gnus-summary-article-posted-p t]
2509               ["Edit article" gnus-summary-edit-article
2510                (not (gnus-group-read-only-p))]
2511               ["Delete article" gnus-summary-delete-article
2512                (gnus-check-backend-function
2513                 'request-expire-articles gnus-newsgroup-name)]
2514               ["Query respool" gnus-summary-respool-query t]
2515               ["Trace respool" gnus-summary-respool-trace t]
2516               ["Delete expirable articles" gnus-summary-expire-articles-now
2517                (gnus-check-backend-function
2518                 'request-expire-articles gnus-newsgroup-name)])
2519              ("Extract"
2520               ["Uudecode" gnus-uu-decode-uu
2521                ,@(if (featurep 'xemacs) '(t)
2522                    '(:help "Decode uuencoded article(s)"))]
2523               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2524               ["Unshar" gnus-uu-decode-unshar t]
2525               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2526               ["Save" gnus-uu-decode-save t]
2527               ["Binhex" gnus-uu-decode-binhex t]
2528               ["Postscript" gnus-uu-decode-postscript t]
2529               ["All MIME parts" gnus-summary-save-parts t])
2530              ("Cache"
2531               ["Enter article" gnus-cache-enter-article t]
2532               ["Remove article" gnus-cache-remove-article t])
2533              ["Translate" gnus-article-babel t]
2534              ["Select article buffer" gnus-summary-select-article-buffer t]
2535              ["Make article buffer sticky" gnus-sticky-article t]
2536              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2537              ["Isearch article..." gnus-summary-isearch-article t]
2538              ["Beginning of the article" gnus-summary-beginning-of-article t]
2539              ["End of the article" gnus-summary-end-of-article t]
2540              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2541              ["Fetch referenced articles" gnus-summary-refer-references t]
2542              ["Fetch current thread" gnus-summary-refer-thread t]
2543              ["Fetch article with id..." gnus-summary-refer-article t]
2544              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2545              ["Redisplay" gnus-summary-show-article t]
2546              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2547       (easy-menu-define
2548         gnus-summary-article-menu gnus-summary-mode-map ""
2549         (cons "Article" innards))
2550
2551       (if (not (keymapp gnus-summary-article-menu))
2552           (easy-menu-define
2553             gnus-article-commands-menu gnus-article-mode-map ""
2554             (cons "Commands" innards))
2555         ;; in Emacs, don't share menu.
2556         (setq gnus-article-commands-menu
2557               (copy-keymap gnus-summary-article-menu))
2558         (define-key gnus-article-mode-map [menu-bar commands]
2559           (cons "Commands" gnus-article-commands-menu))))
2560
2561     (easy-menu-define
2562       gnus-summary-thread-menu gnus-summary-mode-map ""
2563       '("Threads"
2564         ["Find all messages in thread" gnus-summary-refer-thread t]
2565         ["Toggle threading" gnus-summary-toggle-threads t]
2566         ["Hide threads" gnus-summary-hide-all-threads t]
2567         ["Show threads" gnus-summary-show-all-threads t]
2568         ["Hide thread" gnus-summary-hide-thread t]
2569         ["Show thread" gnus-summary-show-thread t]
2570         ["Go to next thread" gnus-summary-next-thread t]
2571         ["Go to previous thread" gnus-summary-prev-thread t]
2572         ["Go down thread" gnus-summary-down-thread t]
2573         ["Go up thread" gnus-summary-up-thread t]
2574         ["Top of thread" gnus-summary-top-thread t]
2575         ["Mark thread as read" gnus-summary-kill-thread t]
2576         ["Mark thread as expired" gnus-summary-expire-thread t]
2577         ["Lower thread score" gnus-summary-lower-thread t]
2578         ["Raise thread score" gnus-summary-raise-thread t]
2579         ["Rethread current" gnus-summary-rethread-current t]))
2580
2581     (easy-menu-define
2582       gnus-summary-post-menu gnus-summary-mode-map ""
2583       `("Post"
2584         ["Send a message (mail or news)" gnus-summary-post-news
2585          ,@(if (featurep 'xemacs) '(t)
2586              '(:help "Compose a new message (mail or news)"))]
2587         ["Followup" gnus-summary-followup
2588          ,@(if (featurep 'xemacs) '(t)
2589              '(:help "Post followup to this article"))]
2590         ["Followup and yank" gnus-summary-followup-with-original
2591          ,@(if (featurep 'xemacs) '(t)
2592              '(:help "Post followup to this article, quoting its contents"))]
2593         ["Supersede article" gnus-summary-supersede-article t]
2594         ["Cancel article" gnus-summary-cancel-article
2595          ,@(if (featurep 'xemacs) '(t)
2596              '(:help "Cancel an article you posted"))]
2597         ["Reply" gnus-summary-reply t]
2598         ["Reply and yank" gnus-summary-reply-with-original t]
2599         ["Wide reply" gnus-summary-wide-reply t]
2600         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2601          ,@(if (featurep 'xemacs) '(t)
2602              '(:help "Mail a reply, quoting this article"))]
2603         ["Very wide reply" gnus-summary-very-wide-reply t]
2604         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2605          ,@(if (featurep 'xemacs) '(t)
2606              '(:help "Mail a very wide reply, quoting this article"))]
2607         ["Mail forward" gnus-summary-mail-forward t]
2608         ["Post forward" gnus-summary-post-forward t]
2609         ["Digest and mail" gnus-uu-digest-mail-forward t]
2610         ["Digest and post" gnus-uu-digest-post-forward t]
2611         ["Resend message" gnus-summary-resend-message t]
2612         ["Resend message edit" gnus-summary-resend-message-edit t]
2613         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2614         ["Send a mail" gnus-summary-mail-other-window t]
2615         ["Create a local message" gnus-summary-news-other-window t]
2616         ["Uuencode and post" gnus-uu-post-news
2617          ,@(if (featurep 'xemacs) '(t)
2618              '(:help "Post a uuencoded article"))]
2619         ["Followup via news" gnus-summary-followup-to-mail t]
2620         ["Followup via news and yank"
2621          gnus-summary-followup-to-mail-with-original t]
2622         ["Strip signature on reply"
2623          (lambda ()
2624            (interactive)
2625            (if (not (memq message-cite-function
2626                           '(message-cite-original-without-signature
2627                             message-cite-original)))
2628                ;; Stupid workaround for XEmacs not honoring :visible.
2629                (message "Can't toggle this value of `message-cite-function'")
2630              (setq message-cite-function
2631                    (if (eq message-cite-function
2632                            'message-cite-original-without-signature)
2633                        'message-cite-original
2634                      'message-cite-original-without-signature))))
2635          ;; XEmacs barfs on :visible.
2636          ,@(if (featurep 'xemacs) nil
2637              '(:visible (memq message-cite-function
2638                               '(message-cite-original-without-signature
2639                                 message-cite-original))))
2640          :style toggle
2641          :selected (eq message-cite-function
2642                        'message-cite-original-without-signature)
2643          ,@(if (featurep 'xemacs) nil
2644              '(:help "Strip signature from cited article when replying."))]
2645         ;;("Draft"
2646         ;;["Send" gnus-summary-send-draft t]
2647         ;;["Send bounced" gnus-resend-bounced-mail t])
2648         ))
2649
2650     (cond
2651      ((not (keymapp gnus-summary-post-menu))
2652       (setq gnus-article-post-menu gnus-summary-post-menu))
2653      ((not gnus-article-post-menu)
2654       ;; Don't share post menu.
2655       (setq gnus-article-post-menu
2656             (copy-keymap gnus-summary-post-menu))))
2657     (define-key gnus-article-mode-map [menu-bar post]
2658       (cons "Post" gnus-article-post-menu))
2659
2660     (easy-menu-define
2661       gnus-summary-misc-menu gnus-summary-mode-map ""
2662       `("Gnus"
2663         ("Mark Read"
2664          ["Mark as read" gnus-summary-mark-as-read-forward t]
2665          ["Mark same subject and select"
2666           gnus-summary-kill-same-subject-and-select t]
2667          ["Mark same subject" gnus-summary-kill-same-subject t]
2668          ["Catchup" gnus-summary-catchup
2669           ,@(if (featurep 'xemacs) '(t)
2670               '(:help "Mark unread articles in this group as read"))]
2671          ["Catchup all" gnus-summary-catchup-all t]
2672          ["Catchup to here" gnus-summary-catchup-to-here t]
2673          ["Catchup from here" gnus-summary-catchup-from-here t]
2674          ["Catchup region" gnus-summary-mark-region-as-read
2675           (gnus-mark-active-p)]
2676          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2677         ("Mark Various"
2678          ["Tick" gnus-summary-tick-article-forward t]
2679          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2680          ["Remove marks" gnus-summary-clear-mark-forward t]
2681          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2682          ["Set bookmark" gnus-summary-set-bookmark t]
2683          ["Remove bookmark" gnus-summary-remove-bookmark t])
2684         ("Limit to"
2685          ["Marks..." gnus-summary-limit-to-marks t]
2686          ["Subject..." gnus-summary-limit-to-subject t]
2687          ["Author..." gnus-summary-limit-to-author t]
2688          ["Recipient..." gnus-summary-limit-to-recipient t]
2689          ["Address..." gnus-summary-limit-to-address t]
2690          ["Age..." gnus-summary-limit-to-age t]
2691          ["Extra..." gnus-summary-limit-to-extra t]
2692          ["Score..." gnus-summary-limit-to-score t]
2693          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2694          ["Unread" gnus-summary-limit-to-unread t]
2695          ["Unseen" gnus-summary-limit-to-unseen t]
2696          ["Singletons" gnus-summary-limit-to-singletons t]
2697          ["Replied" gnus-summary-limit-to-replied t]
2698          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2699          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2700          ["Pop limit" gnus-summary-pop-limit t]
2701          ["Show dormant" gnus-summary-limit-include-dormant t]
2702          ["Hide childless dormant"
2703           gnus-summary-limit-exclude-childless-dormant t]
2704          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2705          ["Hide marked" gnus-summary-limit-exclude-marks t]
2706          ["Show expunged" gnus-summary-limit-include-expunged t])
2707         ("Process Mark"
2708          ["Set mark" gnus-summary-mark-as-processable t]
2709          ["Remove mark" gnus-summary-unmark-as-processable t]
2710          ["Remove all marks" gnus-summary-unmark-all-processable t]
2711          ["Invert marks" gnus-uu-invert-processable t]
2712          ["Mark above" gnus-uu-mark-over t]
2713          ["Mark series" gnus-uu-mark-series t]
2714          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2715          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2716          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2717          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2718          ["Mark all" gnus-uu-mark-all t]
2719          ["Mark buffer" gnus-uu-mark-buffer t]
2720          ["Mark sparse" gnus-uu-mark-sparse t]
2721          ["Mark thread" gnus-uu-mark-thread t]
2722          ["Unmark thread" gnus-uu-unmark-thread t]
2723          ("Process Mark Sets"
2724           ["Kill" gnus-summary-kill-process-mark t]
2725           ["Yank" gnus-summary-yank-process-mark
2726            gnus-newsgroup-process-stack]
2727           ["Save" gnus-summary-save-process-mark t]
2728           ["Run command on marked..." gnus-summary-universal-argument t]))
2729         ("Registry Marks")
2730         ("Scroll article"
2731          ["Page forward" gnus-summary-next-page
2732           ,@(if (featurep 'xemacs) '(t)
2733               '(:help "Show next page of article"))]
2734          ["Page backward" gnus-summary-prev-page
2735           ,@(if (featurep 'xemacs) '(t)
2736               '(:help "Show previous page of article"))]
2737          ["Line forward" gnus-summary-scroll-up t])
2738         ("Move"
2739          ["Next unread article" gnus-summary-next-unread-article t]
2740          ["Previous unread article" gnus-summary-prev-unread-article t]
2741          ["Next article" gnus-summary-next-article t]
2742          ["Previous article" gnus-summary-prev-article t]
2743          ["Next unread subject" gnus-summary-next-unread-subject t]
2744          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2745          ["Next article same subject" gnus-summary-next-same-subject t]
2746          ["Previous article same subject" gnus-summary-prev-same-subject t]
2747          ["First unread article" gnus-summary-first-unread-article t]
2748          ["Best unread article" gnus-summary-best-unread-article t]
2749          ["Go to subject number..." gnus-summary-goto-subject t]
2750          ["Go to article number..." gnus-summary-goto-article t]
2751          ["Go to the last article" gnus-summary-goto-last-article t]
2752          ["Pop article off history" gnus-summary-pop-article t])
2753         ("Sort"
2754          ["Sort by number" gnus-summary-sort-by-number t]
2755          ["Sort by most recent number" gnus-summary-sort-by-most-recent-number t]
2756          ["Sort by author" gnus-summary-sort-by-author t]
2757          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2758          ["Sort by subject" gnus-summary-sort-by-subject t]
2759          ["Sort by date" gnus-summary-sort-by-date t]
2760          ["Sort by most recent date" gnus-summary-sort-by-most-recent-date t]
2761          ["Sort by score" gnus-summary-sort-by-score t]
2762          ["Sort by lines" gnus-summary-sort-by-lines t]
2763          ["Sort by characters" gnus-summary-sort-by-chars t]
2764          ["Randomize" gnus-summary-sort-by-random t]
2765          ["Original sort" gnus-summary-sort-by-original t])
2766         ("Help"
2767          ["Describe group" gnus-summary-describe-group t]
2768          ["Read manual" gnus-info-find-node t])
2769         ("Modes"
2770          ["Pick and read" gnus-pick-mode t]
2771          ["Binary" gnus-binary-mode t])
2772         ("Regeneration"
2773          ["Regenerate" gnus-summary-prepare t]
2774          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2775          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2776          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2777          ["Toggle threading" gnus-summary-toggle-threads t])
2778         ["See old articles" gnus-summary-insert-old-articles t]
2779         ["See new articles" gnus-summary-insert-new-articles t]
2780         ["Filter articles..." gnus-summary-execute-command t]
2781         ["Run command on articles..." gnus-summary-universal-argument t]
2782         ["Search articles forward..." gnus-summary-search-article-forward t]
2783         ["Search articles backward..." gnus-summary-search-article-backward t]
2784         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2785         ["Expand window" gnus-summary-expand-window t]
2786         ["Expire expirable articles" gnus-summary-expire-articles
2787          (gnus-check-backend-function
2788           'request-expire-articles gnus-newsgroup-name)]
2789         ["Edit local kill file" gnus-summary-edit-local-kill t]
2790         ["Edit main kill file" gnus-summary-edit-global-kill t]
2791         ["Edit group parameters" gnus-summary-edit-parameters t]
2792         ["Customize group parameters" gnus-summary-customize-parameters t]
2793         ["Send a bug report" gnus-bug t]
2794         ("Exit"
2795          ["Catchup and exit" gnus-summary-catchup-and-exit
2796           ,@(if (featurep 'xemacs) '(t)
2797               '(:help "Mark unread articles in this group as read, then exit"))]
2798          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2799          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2800          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2801          ["Exit group" gnus-summary-exit
2802           ,@(if (featurep 'xemacs) '(t)
2803               '(:help "Exit current group, return to group selection mode"))]
2804          ["Exit group without updating" gnus-summary-exit-no-update t]
2805          ["Exit and goto next group" gnus-summary-next-group t]
2806          ["Exit and goto prev group" gnus-summary-prev-group t]
2807          ["Reselect group" gnus-summary-reselect-current-group t]
2808          ["Rescan group" gnus-summary-rescan-group t]
2809          ["Update dribble" gnus-summary-save-newsrc t])))
2810
2811     (gnus-run-hooks 'gnus-summary-menu-hook)))
2812
2813 (defvar gnus-summary-tool-bar-map nil)
2814
2815 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2816 ;; affect _new_ message buffers.  We might add a function that walks thru all
2817 ;; summary-mode buffers and force the update.
2818 (defun gnus-summary-tool-bar-update (&optional symbol value)
2819   "Update summary mode toolbar.
2820 Setter function for custom variables."
2821   (setq-default gnus-summary-tool-bar-map nil)
2822   (when symbol
2823     ;; When used as ":set" function:
2824     (set-default symbol value))
2825   (when (gnus-buffer-live-p gnus-summary-buffer)
2826     (with-current-buffer gnus-summary-buffer
2827       (gnus-summary-make-tool-bar))))
2828
2829 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2830                                      'gnus-summary-tool-bar-gnome
2831                                    'gnus-summary-tool-bar-retro)
2832   "Specifies the Gnus summary tool bar.
2833
2834 It can be either a list or a symbol refering to a list.  See
2835 `gmm-tool-bar-from-list' for the format of the list.  The
2836 default key map is `gnus-summary-mode-map'.
2837
2838 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2839 `gnus-summary-tool-bar-retro'."
2840   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2841                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2842                  (repeat :tag "User defined list" gmm-tool-bar-item)
2843                  (symbol))
2844   :version "23.1" ;; No Gnus
2845   :initialize 'custom-initialize-default
2846   :set 'gnus-summary-tool-bar-update
2847   :group 'gnus-summary)
2848
2849 (defcustom gnus-summary-tool-bar-gnome
2850   '((gnus-summary-post-news "mail/compose" nil)
2851     (gnus-summary-insert-new-articles "mail/inbox" nil
2852                                       :visible (or (not gnus-agent)
2853                                                    gnus-plugged))
2854     (gnus-summary-reply-with-original "mail/reply")
2855     (gnus-summary-reply "mail/reply" nil :visible nil)
2856     (gnus-summary-followup-with-original "mail/reply-all")
2857     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2858     (gnus-summary-mail-forward "mail/forward")
2859     (gnus-summary-save-article "mail/save")
2860     (gnus-summary-search-article-forward "search" nil :visible nil)
2861     (gnus-summary-print-article "print")
2862     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2863     ;; Some new commands that may need more suitable icons:
2864     (gnus-summary-save-newsrc "save" nil :visible nil)
2865     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2866     (gnus-summary-prev-article "left-arrow")
2867     (gnus-summary-next-article "right-arrow")
2868     (gnus-summary-next-page "next-page")
2869     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2870     ;;
2871     ;; Maybe some sort-by-... could be added:
2872     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2873     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2874     (gnus-summary-mark-as-expirable
2875      "delete" nil
2876      :visible (gnus-check-backend-function 'request-expire-articles
2877                                            gnus-newsgroup-name))
2878     (gnus-summary-mark-as-spam
2879      "mail/spam" t
2880      :visible (and (fboundp 'spam-group-ham-contents-p)
2881                    (spam-group-ham-contents-p gnus-newsgroup-name))
2882      :help "Mark as spam")
2883     (gnus-summary-mark-as-read-forward
2884      "mail/not-spam" nil
2885      :visible (and (fboundp 'spam-group-spam-contents-p)
2886                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2887     ;;
2888     (gnus-summary-exit "exit")
2889     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2890     (gnus-info-find-node "help"))
2891   "List of functions for the summary tool bar (GNOME style).
2892
2893 See `gmm-tool-bar-from-list' for the format of the list."
2894   :type '(repeat gmm-tool-bar-item)
2895   :version "23.1" ;; No Gnus
2896   :initialize 'custom-initialize-default
2897   :set 'gnus-summary-tool-bar-update
2898   :group 'gnus-summary)
2899
2900 (defcustom gnus-summary-tool-bar-retro
2901   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2902     (gnus-summary-next-unread-article "gnus/next-ur")
2903     (gnus-summary-post-news "gnus/post")
2904     (gnus-summary-followup-with-original "gnus/fuwo")
2905     (gnus-summary-followup "gnus/followup")
2906     (gnus-summary-reply-with-original "gnus/reply-wo")
2907     (gnus-summary-reply "gnus/reply")
2908     (gnus-summary-caesar-message "gnus/rot13")
2909     (gnus-uu-decode-uu "gnus/uu-decode")
2910     (gnus-summary-save-article-file "gnus/save-aif")
2911     (gnus-summary-save-article "gnus/save-art")
2912     (gnus-uu-post-news "gnus/uu-post")
2913     (gnus-summary-catchup "gnus/catchup")
2914     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2915     (gnus-summary-exit "gnus/exit-summ")
2916     ;; Some new command that may need more suitable icons:
2917     (gnus-summary-print-article "gnus/print" nil :visible nil)
2918     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2919     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2920     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2921     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2922     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2923     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2924     ;;
2925     (gnus-info-find-node "gnus/help" nil :visible nil))
2926   "List of functions for the summary tool bar (retro look).
2927
2928 See `gmm-tool-bar-from-list' for the format of the list."
2929   :type '(repeat gmm-tool-bar-item)
2930   :version "23.1" ;; No Gnus
2931   :initialize 'custom-initialize-default
2932   :set 'gnus-summary-tool-bar-update
2933   :group 'gnus-summary)
2934
2935 (defcustom gnus-summary-tool-bar-zap-list t
2936   "List of icon items from the global tool bar.
2937 These items are not displayed in the Gnus summary mode tool bar.
2938
2939 See `gmm-tool-bar-from-list' for the format of the list."
2940   :type 'gmm-tool-bar-zap-list
2941   :version "23.1" ;; No Gnus
2942   :initialize 'custom-initialize-default
2943   :set 'gnus-summary-tool-bar-update
2944   :group 'gnus-summary)
2945
2946 (defvar image-load-path)
2947 (defvar tool-bar-map)
2948
2949 (defun gnus-summary-make-tool-bar (&optional force)
2950   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2951 When FORCE, rebuild the tool bar."
2952   (when (and (not (featurep 'xemacs))
2953              (boundp 'tool-bar-mode)
2954              tool-bar-mode
2955              (or (not gnus-summary-tool-bar-map) force))
2956     (let* ((load-path
2957             (gmm-image-load-path-for-library "gnus"
2958                                              "mail/save.xpm"
2959                                              nil t))
2960            (image-load-path (cons (car load-path)
2961                                   (when (boundp 'image-load-path)
2962                                     image-load-path)))
2963            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2964                                         gnus-summary-tool-bar-zap-list
2965                                         'gnus-summary-mode-map)))
2966       (when map
2967         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2968         ;; uses it's value.
2969         (setq gnus-summary-tool-bar-map map))))
2970   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2971
2972 (defun gnus-score-set-default (var value)
2973   "A version of set that updates the GNU Emacs menu-bar."
2974   (set var value)
2975   ;; It is the message that forces the active status to be updated.
2976   (message ""))
2977
2978 (defun gnus-make-score-map (type)
2979   "Make a summary score map of type TYPE."
2980   (if t
2981       nil
2982     (let ((headers '(("author" "from" string)
2983                      ("subject" "subject" string)
2984                      ("article body" "body" string)
2985                      ("article head" "head" string)
2986                      ("xref" "xref" string)
2987                      ("extra header" "extra" string)
2988                      ("lines" "lines" number)
2989                      ("followups to author" "followup" string)))
2990           (types '((number ("less than" <)
2991                            ("greater than" >)
2992                            ("equal" =))
2993                    (string ("substring" s)
2994                            ("exact string" e)
2995                            ("fuzzy string" f)
2996                            ("regexp" r))))
2997           (perms '(("temporary" (current-time-string))
2998                    ("permanent" nil)
2999                    ("immediate" now)))
3000           header)
3001       (list
3002        (apply
3003         'nconc
3004         (list
3005          (if (eq type 'lower)
3006              "Lower score"
3007            "Increase score"))
3008         (let (outh)
3009           (while headers
3010             (setq header (car headers))
3011             (setq outh
3012                   (cons
3013                    (apply
3014                     'nconc
3015                     (list (car header))
3016                     (let ((ts (cdr (assoc (nth 2 header) types)))
3017                           outt)
3018                       (while ts
3019                         (setq outt
3020                               (cons
3021                                (apply
3022                                 'nconc
3023                                 (list (caar ts))
3024                                 (let ((ps perms)
3025                                       outp)
3026                                   (while ps
3027                                     (setq outp
3028                                           (cons
3029                                            (vector
3030                                             (caar ps)
3031                                             (list
3032                                              'gnus-summary-score-entry
3033                                              (nth 1 header)
3034                                              (if (or (string= (nth 1 header)
3035                                                               "head")
3036                                                      (string= (nth 1 header)
3037                                                               "body"))
3038                                                  ""
3039                                                (list 'gnus-summary-header
3040                                                      (nth 1 header)))
3041                                              (list 'quote (nth 1 (car ts)))
3042                                              (list 'gnus-score-delta-default
3043                                                    nil)
3044                                              (nth 1 (car ps))
3045                                              t)
3046                                             t)
3047                                            outp))
3048                                     (setq ps (cdr ps)))
3049                                   (list (nreverse outp))))
3050                                outt))
3051                         (setq ts (cdr ts)))
3052                       (list (nreverse outt))))
3053                    outh))
3054             (setq headers (cdr headers)))
3055           (list (nreverse outh))))))))
3056
3057
3058 (declare-function turn-on-gnus-mailing-list-mode "gnus-ml" ())
3059 (defvar bookmark-make-record-function)
3060 \f
3061
3062 (defun gnus-summary-mode (&optional group)
3063   "Major mode for reading articles.
3064
3065 All normal editing commands are switched off.
3066 \\<gnus-summary-mode-map>
3067 Each line in this buffer represents one article.  To read an
3068 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
3069 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
3070 respectively.
3071
3072 You can also post articles and send mail from this buffer.  To
3073 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
3074 of an article, type `\\[gnus-summary-reply]'.
3075
3076 There are approx. one gazillion commands you can execute in this
3077 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
3078
3079 The following commands are available:
3080
3081 \\{gnus-summary-mode-map}"
3082   (interactive)
3083   (kill-all-local-variables)
3084   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
3085     (gnus-summary-make-local-variables))
3086   (gnus-summary-make-local-variables)
3087   (setq gnus-newsgroup-name group)
3088   (when (gnus-visual-p 'summary-menu 'menu)
3089     (gnus-summary-make-menu-bar)
3090     (gnus-summary-make-tool-bar))
3091   (gnus-make-thread-indent-array)
3092   (gnus-simplify-mode-line)
3093   (setq major-mode 'gnus-summary-mode)
3094   (setq mode-name "Summary")
3095   (use-local-map gnus-summary-mode-map)
3096   (buffer-disable-undo)
3097   (setq buffer-read-only t              ;Disable modification
3098         show-trailing-whitespace nil)
3099   (setq truncate-lines t)
3100   (add-to-invisibility-spec '(gnus-sum . t))
3101   (gnus-summary-set-display-table)
3102   (gnus-set-default-directory)
3103   (make-local-variable 'gnus-summary-line-format)
3104   (make-local-variable 'gnus-summary-line-format-spec)
3105   (make-local-variable 'gnus-summary-dummy-line-format)
3106   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3107   (make-local-variable 'gnus-summary-mark-positions)
3108   (gnus-make-local-hook 'pre-command-hook)
3109   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3110   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3111   (turn-on-gnus-mailing-list-mode)
3112   (mm-enable-multibyte)
3113   (set (make-local-variable 'bookmark-make-record-function)
3114        'gnus-summary-bookmark-make-record)
3115   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3116   (gnus-update-summary-mark-positions))
3117
3118 (defun gnus-summary-make-local-variables ()
3119   "Make all the local summary buffer variables."
3120   (let (global)
3121     (dolist (local gnus-summary-local-variables)
3122       (if (consp local)
3123           (progn
3124             (if (eq (cdr local) 'global)
3125                 ;; Copy the global value of the variable.
3126                 (setq global (symbol-value (car local)))
3127               ;; Use the value from the list.
3128               (setq global (eval (cdr local))))
3129             (set (make-local-variable (car local)) global))
3130         ;; Simple nil-valued local variable.
3131         (set (make-local-variable local) nil)))))
3132
3133 ;; Summary data functions.
3134
3135 (defmacro gnus-data-number (data)
3136   `(car ,data))
3137
3138 (defmacro gnus-data-set-number (data number)
3139   `(setcar ,data ,number))
3140
3141 (defmacro gnus-data-mark (data)
3142   `(nth 1 ,data))
3143
3144 (defmacro gnus-data-set-mark (data mark)
3145   `(setcar (nthcdr 1 ,data) ,mark))
3146
3147 (defmacro gnus-data-pos (data)
3148   `(nth 2 ,data))
3149
3150 (defmacro gnus-data-set-pos (data pos)
3151   `(setcar (nthcdr 2 ,data) ,pos))
3152
3153 (defmacro gnus-data-header (data)
3154   `(nth 3 ,data))
3155
3156 (defmacro gnus-data-set-header (data header)
3157   `(setf (nth 3 ,data) ,header))
3158
3159 (defmacro gnus-data-level (data)
3160   `(nth 4 ,data))
3161
3162 (defmacro gnus-data-unread-p (data)
3163   `(= (nth 1 ,data) gnus-unread-mark))
3164
3165 (defmacro gnus-data-read-p (data)
3166   `(/= (nth 1 ,data) gnus-unread-mark))
3167
3168 (defmacro gnus-data-pseudo-p (data)
3169   `(consp (nth 3 ,data)))
3170
3171 (defmacro gnus-data-find (number)
3172   `(assq ,number gnus-newsgroup-data))
3173
3174 (defmacro gnus-data-find-list (number &optional data)
3175   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3176      (memq (assq ,number bdata)
3177            bdata)))
3178
3179 (defmacro gnus-data-make (number mark pos header level)
3180   `(list ,number ,mark ,pos ,header ,level))
3181
3182 (defun gnus-data-enter (after-article number mark pos header level offset)
3183   (let ((data (gnus-data-find-list after-article)))
3184     (unless data
3185       (error "No such article: %d" after-article))
3186     (setcdr data (cons (gnus-data-make number mark pos header level)
3187                        (cdr data)))
3188     (setq gnus-newsgroup-data-reverse nil)
3189     (gnus-data-update-list (cddr data) offset)))
3190
3191 (defun gnus-data-enter-list (after-article list &optional offset)
3192   (when list
3193     (let ((data (and after-article (gnus-data-find-list after-article)))
3194           (ilist list))
3195       (if (not (or data
3196                    after-article))
3197           (let ((odata gnus-newsgroup-data))
3198             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3199             (when offset
3200               (gnus-data-update-list odata offset)))
3201         ;; Find the last element in the list to be spliced into the main
3202         ;; list.
3203         (setq list (last list))
3204         (if (not data)
3205             (progn
3206               (setcdr list gnus-newsgroup-data)
3207               (setq gnus-newsgroup-data ilist)
3208               (when offset
3209                 (gnus-data-update-list (cdr list) offset)))
3210           (setcdr list (cdr data))
3211           (setcdr data ilist)
3212           (when offset
3213             (gnus-data-update-list (cdr list) offset))))
3214       (setq gnus-newsgroup-data-reverse nil))))
3215
3216 (defun gnus-data-remove (article &optional offset)
3217   (let ((data gnus-newsgroup-data))
3218     (if (= (gnus-data-number (car data)) article)
3219         (progn
3220           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3221                 gnus-newsgroup-data-reverse nil)
3222           (when offset
3223             (gnus-data-update-list gnus-newsgroup-data offset)))
3224       (while (cdr data)
3225         (when (= (gnus-data-number (cadr data)) article)
3226           (setcdr data (cddr data))
3227           (when offset
3228             (gnus-data-update-list (cdr data) offset))
3229           (setq data nil
3230                 gnus-newsgroup-data-reverse nil))
3231         (setq data (cdr data))))))
3232
3233 (defmacro gnus-data-list (backward)
3234   `(if ,backward
3235        (or gnus-newsgroup-data-reverse
3236            (setq gnus-newsgroup-data-reverse
3237                  (reverse gnus-newsgroup-data)))
3238      gnus-newsgroup-data))
3239
3240 (defun gnus-data-update-list (data offset)
3241   "Add OFFSET to the POS of all data entries in DATA."
3242   (setq gnus-newsgroup-data-reverse nil)
3243   (while data
3244     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3245     (setq data (cdr data))))
3246
3247 (defun gnus-summary-article-pseudo-p (article)
3248   "Say whether this article is a pseudo article or not."
3249   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3250
3251 (defmacro gnus-summary-article-sparse-p (article)
3252   "Say whether this article is a sparse article or not."
3253   `(memq ,article gnus-newsgroup-sparse))
3254
3255 (defmacro gnus-summary-article-ancient-p (article)
3256   "Say whether this article is a sparse article or not."
3257   `(memq ,article gnus-newsgroup-ancient))
3258
3259 (defun gnus-article-parent-p (number)
3260   "Say whether this article is a parent or not."
3261   (let ((data (gnus-data-find-list number)))
3262     (and (cdr data)              ; There has to be an article after...
3263          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3264             (gnus-data-level (nth 1 data))))))
3265
3266 (defun gnus-article-children (number)
3267   "Return a list of all children to NUMBER."
3268   (let* ((data (gnus-data-find-list number))
3269          (level (gnus-data-level (car data)))
3270          children)
3271     (setq data (cdr data))
3272     (while (and data
3273                 (= (gnus-data-level (car data)) (1+ level)))
3274       (push (gnus-data-number (car data)) children)
3275       (setq data (cdr data)))
3276     children))
3277
3278 (defmacro gnus-summary-skip-intangible ()
3279   "If the current article is intangible, then jump to a different article."
3280   '(let ((to (get-text-property (point) 'gnus-intangible)))
3281      (and to (gnus-summary-goto-subject to))))
3282
3283 (defmacro gnus-summary-article-intangible-p ()
3284   "Say whether this article is intangible or not."
3285   '(get-text-property (point) 'gnus-intangible))
3286
3287 (defun gnus-article-read-p (article)
3288   "Say whether ARTICLE is read or not."
3289   (not (or (memq article gnus-newsgroup-marked)
3290            (memq article gnus-newsgroup-spam-marked)
3291            (memq article gnus-newsgroup-unreads)
3292            (memq article gnus-newsgroup-unselected)
3293            (memq article gnus-newsgroup-dormant))))
3294
3295 ;; Some summary mode macros.
3296
3297 (defmacro gnus-summary-article-number ()
3298   "The article number of the article on the current line.
3299 If there isn't an article number here, then we return the current
3300 article number."
3301   '(progn
3302      (gnus-summary-skip-intangible)
3303      (or (get-text-property (point) 'gnus-number)
3304          (gnus-summary-last-subject))))
3305
3306 (defmacro gnus-summary-article-header (&optional number)
3307   "Return the header of article NUMBER."
3308   `(gnus-data-header (gnus-data-find
3309                       ,(or number '(gnus-summary-article-number)))))
3310
3311 (defmacro gnus-summary-thread-level (&optional number)
3312   "Return the level of thread that starts with article NUMBER."
3313   `(if (and (eq gnus-summary-make-false-root 'dummy)
3314             (get-text-property (point) 'gnus-intangible))
3315        0
3316      (gnus-data-level (gnus-data-find
3317                        ,(or number '(gnus-summary-article-number))))))
3318
3319 (defmacro gnus-summary-article-mark (&optional number)
3320   "Return the mark of article NUMBER."
3321   `(gnus-data-mark (gnus-data-find
3322                     ,(or number '(gnus-summary-article-number)))))
3323
3324 (defmacro gnus-summary-article-pos (&optional number)
3325   "Return the position of the line of article NUMBER."
3326   `(gnus-data-pos (gnus-data-find
3327                    ,(or number '(gnus-summary-article-number)))))
3328
3329 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3330 (defmacro gnus-summary-article-subject (&optional number)
3331   "Return current subject string or nil if nothing."
3332   `(let ((headers
3333           ,(if number
3334                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3335              '(gnus-data-header (assq (gnus-summary-article-number)
3336                                       gnus-newsgroup-data)))))
3337      (and headers
3338           (vectorp headers)
3339           (mail-header-subject headers))))
3340
3341 (defmacro gnus-summary-article-score (&optional number)
3342   "Return current article score."
3343   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3344                   gnus-newsgroup-scored))
3345        gnus-summary-default-score 0))
3346
3347 (defun gnus-summary-article-children (&optional number)
3348   "Return a list of article numbers that are children of article NUMBER."
3349   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3350          (level (gnus-data-level (car data)))
3351          l children)
3352     (while (and (setq data (cdr data))
3353                 (> (setq l (gnus-data-level (car data))) level))
3354       (and (= (1+ level) l)
3355            (push (gnus-data-number (car data))
3356                  children)))
3357     (nreverse children)))
3358
3359 (defun gnus-summary-article-parent (&optional number)
3360   "Return the article number of the parent of article NUMBER."
3361   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3362                                     (gnus-data-list t)))
3363          (level (gnus-data-level (car data))))
3364     (if (zerop level)
3365         ()                              ; This is a root.
3366       ;; We search until we find an article with a level less than
3367       ;; this one.  That function has to be the parent.
3368       (while (and (setq data (cdr data))
3369                   (not (< (gnus-data-level (car data)) level))))
3370       (and data (gnus-data-number (car data))))))
3371
3372 (defun gnus-unread-mark-p (mark)
3373   "Say whether MARK is the unread mark."
3374   (= mark gnus-unread-mark))
3375
3376 (defun gnus-read-mark-p (mark)
3377   "Say whether MARK is one of the marks that mark as read.
3378 This is all marks except unread, ticked, dormant, and expirable."
3379   (not (or (= mark gnus-unread-mark)
3380            (= mark gnus-ticked-mark)
3381            (= mark gnus-spam-mark)
3382            (= mark gnus-dormant-mark)
3383            (= mark gnus-expirable-mark))))
3384
3385 (defmacro gnus-article-mark (number)
3386   "Return the MARK of article NUMBER.
3387 This macro should only be used when computing the mark the \"first\"
3388 time; i.e., when generating the summary lines.  After that,
3389 `gnus-summary-article-mark' should be used to examine the
3390 marks of articles."
3391   `(cond
3392     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3393     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3394     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3395     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3396     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3397     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3398     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3399     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3400            gnus-ancient-mark))))
3401
3402 ;; Saving hidden threads.
3403
3404 (defmacro gnus-save-hidden-threads (&rest forms)
3405   "Save hidden threads, eval FORMS, and restore the hidden threads."
3406   (let ((config (make-symbol "config")))
3407     `(let ((,config (gnus-hidden-threads-configuration)))
3408        (unwind-protect
3409            (save-excursion
3410              ,@forms)
3411          (gnus-restore-hidden-threads-configuration ,config)))))
3412 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3413 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3414
3415 (defun gnus-data-compute-positions ()
3416   "Compute the positions of all articles."
3417   (setq gnus-newsgroup-data-reverse nil)
3418   (let ((data gnus-newsgroup-data))
3419     (save-excursion
3420       (gnus-save-hidden-threads
3421         (gnus-summary-show-all-threads)
3422         (goto-char (point-min))
3423         (while data
3424           (while (get-text-property (point) 'gnus-intangible)
3425             (forward-line 1))
3426           (gnus-data-set-pos (car data) (+ (point) 3))
3427           (setq data (cdr data))
3428           (forward-line 1))))))
3429
3430 (defun gnus-hidden-threads-configuration ()
3431   "Return the current hidden threads configuration."
3432   (save-excursion
3433     (let (config)
3434       (goto-char (point-min))
3435       (while (not (eobp))
3436         (when (eq (get-char-property (point-at-eol) 'invisible) 'gnus-sum)
3437           (push (save-excursion (forward-line 0) (point)) config))
3438         (forward-line 1))
3439       config)))
3440
3441 (defun gnus-restore-hidden-threads-configuration (config)
3442   "Restore hidden threads configuration from CONFIG."
3443   (save-excursion
3444     (let (point (inhibit-read-only t))
3445       (while (setq point (pop config))
3446         (goto-char point)
3447         (gnus-summary-hide-thread)))))
3448
3449 ;; Various summary mode internalish functions.
3450
3451 (defun gnus-mouse-pick-article (e)
3452   (interactive "e")
3453   (mouse-set-point e)
3454   (gnus-summary-next-page nil t))
3455
3456 (defun gnus-summary-set-display-table ()
3457   "Change the display table.
3458 Odd characters have a tendency to mess
3459 up nicely formatted displays - we make all possible glyphs
3460 display only a single character."
3461
3462   ;; We start from the standard display table, if any.
3463   (let ((table (or (copy-sequence standard-display-table)
3464                    (make-display-table)))
3465         (i 32))
3466     ;; Nix out all the control chars...
3467     (while (>= (setq i (1- i)) 0)
3468       (gnus-put-display-table i [??] table))
3469    ;; ... but not newline and cr, of course.  (cr is necessary for the
3470     ;; selective display).
3471     (gnus-put-display-table ?\n nil table)
3472     (gnus-put-display-table ?\r nil table)
3473     ;; We keep TAB as well.
3474     (gnus-put-display-table ?\t nil table)
3475     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3476     ;; Emacs 23 (unicode), that are not set already.
3477     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3478                  160
3479                256)))
3480       (while (>= (setq i (1- i)) 127)
3481         ;; Only modify if the entry is nil.
3482         (unless (gnus-get-display-table i table)
3483           (gnus-put-display-table i [??] table))))
3484     (setq buffer-display-table table)))
3485
3486 (defun gnus-summary-set-article-display-arrow (pos)
3487   "Update the overlay arrow to point to line at position POS."
3488   (when gnus-summary-display-arrow
3489     (make-local-variable 'overlay-arrow-position)
3490     (make-local-variable 'overlay-arrow-string)
3491     (save-excursion
3492       (goto-char pos)
3493       (beginning-of-line)
3494       (unless overlay-arrow-position
3495         (setq overlay-arrow-position (make-marker)))
3496       (setq overlay-arrow-string "=>"
3497             overlay-arrow-position (set-marker overlay-arrow-position
3498                                                (point)
3499                                                (current-buffer))))))
3500
3501 (defun gnus-summary-setup-buffer (group)
3502   "Initialize summary buffer."
3503   (let ((buffer (gnus-summary-buffer-name group))
3504         (dead-name (concat "*Dead Summary "
3505                            (gnus-group-decoded-name group) "*")))
3506     ;; If a dead summary buffer exists, we kill it.
3507     (when (gnus-buffer-live-p dead-name)
3508       (gnus-kill-buffer dead-name))
3509     (if (get-buffer buffer)
3510         (progn
3511           (set-buffer buffer)
3512           (setq gnus-summary-buffer (current-buffer))
3513           (not gnus-newsgroup-prepared))
3514       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3515       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3516       (gnus-summary-mode group)
3517       (when (gnus-group-quit-config group)
3518         (set (make-local-variable 'gnus-single-article-buffer) nil))
3519       (make-local-variable 'gnus-article-buffer)
3520       (make-local-variable 'gnus-article-current)
3521       (make-local-variable 'gnus-original-article-buffer)
3522       (setq gnus-newsgroup-name group)
3523       ;; Set any local variables in the group parameters.
3524       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3525       t)))
3526
3527 (defun gnus-set-global-variables ()
3528   "Set the global equivalents of the buffer-local variables.
3529 They are set to the latest values they had.  These reflect the summary
3530 buffer that was in action when the last article was fetched."
3531   (when (eq major-mode 'gnus-summary-mode)
3532     (setq gnus-summary-buffer (current-buffer))
3533     (let ((name gnus-newsgroup-name)
3534           (marked gnus-newsgroup-marked)
3535           (spam gnus-newsgroup-spam-marked)
3536           (unread gnus-newsgroup-unreads)
3537           (headers gnus-current-headers)
3538           (data gnus-newsgroup-data)
3539           (summary gnus-summary-buffer)
3540           (article-buffer gnus-article-buffer)
3541           (original gnus-original-article-buffer)
3542           (gac gnus-article-current)
3543           (reffed gnus-reffed-article-number)
3544           (score-file gnus-current-score-file)
3545           (default-charset gnus-newsgroup-charset)
3546           vlist)
3547       (let ((locals gnus-newsgroup-variables))
3548         (while locals
3549           (if (consp (car locals))
3550               (push (eval (caar locals)) vlist)
3551             (push (eval (car locals)) vlist))
3552           (setq locals (cdr locals)))
3553         (setq vlist (nreverse vlist)))
3554       (with-current-buffer gnus-group-buffer
3555         (setq gnus-newsgroup-name name
3556               gnus-newsgroup-marked marked
3557               gnus-newsgroup-spam-marked spam
3558               gnus-newsgroup-unreads unread
3559               gnus-current-headers headers
3560               gnus-newsgroup-data data
3561               gnus-article-current gac
3562               gnus-summary-buffer summary
3563               gnus-article-buffer article-buffer
3564               gnus-original-article-buffer original
3565               gnus-reffed-article-number reffed
3566               gnus-current-score-file score-file
3567               gnus-newsgroup-charset default-charset)
3568         (let ((locals gnus-newsgroup-variables))
3569           (while locals
3570             (if (consp (car locals))
3571                 (set (caar locals) (pop vlist))
3572               (set (car locals) (pop vlist)))
3573             (setq locals (cdr locals))))
3574         ;; The article buffer also has local variables.
3575         (when (gnus-buffer-live-p gnus-article-buffer)
3576           (set-buffer gnus-article-buffer)
3577           (setq gnus-summary-buffer summary))))))
3578
3579 (defun gnus-summary-article-unread-p (article)
3580   "Say whether ARTICLE is unread or not."
3581   (memq article gnus-newsgroup-unreads))
3582
3583 (defun gnus-summary-first-article-p (&optional article)
3584   "Return whether ARTICLE is the first article in the buffer."
3585   (if (not (setq article (or article (gnus-summary-article-number))))
3586       nil
3587     (eq article (caar gnus-newsgroup-data))))
3588
3589 (defun gnus-summary-last-article-p (&optional article)
3590   "Return whether ARTICLE is the last article in the buffer."
3591   (if (not (setq article (or article (gnus-summary-article-number))))
3592       ;; All non-existent numbers are the last article.  :-)
3593       t
3594     (not (cdr (gnus-data-find-list article)))))
3595
3596 (defun gnus-make-thread-indent-array (&optional n)
3597   (when (or n
3598             (progn (setq n 200) nil)
3599             (null gnus-thread-indent-array)
3600             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3601     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3602           gnus-thread-indent-array-level gnus-thread-indent-level)
3603     (while (>= n 0)
3604       (aset gnus-thread-indent-array n
3605             (make-string (* n gnus-thread-indent-level) ? ))
3606       (setq n (1- n)))))
3607
3608 (defun gnus-update-summary-mark-positions ()
3609   "Compute where the summary marks are to go."
3610   (save-excursion
3611     (when (gnus-buffer-exists-p gnus-summary-buffer)
3612       (set-buffer gnus-summary-buffer))
3613     (let ((spec gnus-summary-line-format-spec)
3614           pos)
3615       (save-excursion
3616         (gnus-set-work-buffer)
3617         (let ((gnus-tmp-unread ?Z)
3618               (gnus-replied-mark ?Z)
3619               (gnus-score-below-mark ?Z)
3620               (gnus-score-over-mark ?Z)
3621               (gnus-undownloaded-mark ?Z)
3622               (gnus-summary-line-format-spec spec)
3623               (gnus-newsgroup-downloadable '(0))
3624               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3625               case-fold-search ignores)
3626           ;; Here, all marks are bound to Z.
3627           (gnus-summary-insert-line header
3628                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3629           (goto-char (point-min))
3630           ;; Memorize the positions of the same characters as dummy marks.
3631           (while (re-search-forward "[A-D]" nil t)
3632             (push (point) ignores))
3633           (erase-buffer)
3634           ;; We use A-D as dummy marks in order to know column positions
3635           ;; where marks should be inserted.
3636           (setq gnus-tmp-unread ?A
3637                 gnus-replied-mark ?B
3638                 gnus-score-below-mark ?C
3639                 gnus-score-over-mark ?C
3640                 gnus-undownloaded-mark ?D)
3641           (gnus-summary-insert-line header
3642                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3643           ;; Ignore characters which aren't dummy marks.
3644           (dolist (p ignores)
3645             (delete-region (goto-char (1- p)) p)
3646             (insert ?Z))
3647           (goto-char (point-min))
3648           (setq pos (list (cons 'unread
3649                                 (and (search-forward "A" nil t)
3650                                      (- (point) (point-min) 1)))))
3651           (goto-char (point-min))
3652           (push (cons 'replied (and (search-forward "B" nil t)
3653                                     (- (point) (point-min) 1)))
3654                 pos)
3655           (goto-char (point-min))
3656           (push (cons 'score (and (search-forward "C" nil t)
3657                                   (- (point) (point-min) 1)))
3658                 pos)
3659           (goto-char (point-min))
3660           (push (cons 'download (and (search-forward "D" nil t)
3661                                      (- (point) (point-min) 1)))
3662                 pos)))
3663       (setq gnus-summary-mark-positions pos))))
3664
3665 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3666   "Insert a dummy root in the summary buffer."
3667   (beginning-of-line)
3668   (gnus-add-text-properties
3669    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3670    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3671
3672 (defun gnus-summary-extract-address-component (from)
3673   (or (car (funcall gnus-extract-address-components from))
3674       from))
3675
3676 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3677   (let ((mail-parse-charset gnus-newsgroup-charset)
3678         (ignored-from-addresses (gnus-ignored-from-addresses))
3679         ; Is it really necessary to do this next part for each summary line?
3680         ; Luckily, doesn't seem to slow things down much.
3681         (mail-parse-ignored-charsets
3682          (with-current-buffer gnus-summary-buffer
3683            gnus-newsgroup-ignored-charsets)))
3684     (or
3685      (and ignored-from-addresses
3686           (string-match ignored-from-addresses gnus-tmp-from)
3687           (let ((extra-headers (mail-header-extra header))
3688                 to
3689                 newsgroups)
3690             (cond
3691              ((setq to (cdr (assq 'To extra-headers)))
3692               (concat gnus-summary-to-prefix
3693                       (inline
3694                         (gnus-summary-extract-address-component
3695                          (funcall gnus-decode-encoded-address-function to)))))
3696              ((setq newsgroups
3697                     (or
3698                      (cdr (assq 'Newsgroups extra-headers))
3699                      (and
3700                       (memq 'Newsgroups gnus-extra-headers)
3701                       (eq (car (gnus-find-method-for-group
3702                                 gnus-newsgroup-name)) 'nntp)
3703                       (gnus-group-real-name gnus-newsgroup-name))))
3704               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3705      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3706
3707 (defun gnus-summary-insert-line (gnus-tmp-header
3708                                  gnus-tmp-level gnus-tmp-current
3709                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3710                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3711                                  &optional gnus-tmp-dummy gnus-tmp-score
3712                                  gnus-tmp-process)
3713   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3714       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3715                                           gnus-tmp-level)))
3716   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3717          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3718          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3719          (gnus-tmp-score-char
3720           (if (or (null gnus-summary-default-score)
3721                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3722                       gnus-summary-zcore-fuzz))
3723               ?                         ;Whitespace
3724             (if (< gnus-tmp-score gnus-summary-default-score)
3725                 gnus-score-below-mark gnus-score-over-mark)))
3726          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3727          (gnus-tmp-replied
3728           (cond (gnus-tmp-process gnus-process-mark)
3729                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3730                  gnus-cached-mark)
3731                 (gnus-tmp-replied gnus-replied-mark)
3732                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3733                  gnus-forwarded-mark)
3734                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3735                  gnus-saved-mark)
3736                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3737                  gnus-recent-mark)
3738                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3739                  gnus-unseen-mark)
3740                 (t gnus-no-mark)))
3741          (gnus-tmp-downloaded
3742           (cond (undownloaded
3743                  gnus-undownloaded-mark)
3744                 (gnus-newsgroup-agentized
3745                  gnus-downloaded-mark)
3746                 (t
3747                  gnus-no-mark)))
3748          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3749          (gnus-tmp-name
3750           (cond
3751            ((string-match "<[^>]+> *$" gnus-tmp-from)
3752             (let ((beg (match-beginning 0)))
3753               (or (and (string-match "^\".+\"" gnus-tmp-from)
3754                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3755                   (substring gnus-tmp-from 0 beg))))
3756            ((string-match "(.+)" gnus-tmp-from)
3757             (substring gnus-tmp-from
3758                        (1+ (match-beginning 0)) (1- (match-end 0))))
3759            (t gnus-tmp-from)))
3760          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3761          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3762          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3763          (inhibit-read-only t))
3764     (when (string= gnus-tmp-name "")
3765       (setq gnus-tmp-name gnus-tmp-from))
3766     (unless (numberp gnus-tmp-lines)
3767       (setq gnus-tmp-lines -1))
3768     (if (= gnus-tmp-lines -1)
3769         (setq gnus-tmp-lines "?")
3770       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3771     (condition-case ()
3772         (gnus-put-text-property
3773          (point)
3774          (progn (eval gnus-summary-line-format-spec) (point))
3775          'gnus-number gnus-tmp-number)
3776       (error (gnus-message 5 "Error updating the summary line")))
3777     (when (gnus-visual-p 'summary-highlight 'highlight)
3778       (forward-line -1)
3779       (gnus-summary-highlight-line)
3780       (gnus-run-hooks 'gnus-summary-update-hook)
3781       (forward-line 1))))
3782
3783 (defun gnus-summary-update-line (&optional dont-update)
3784   "Update summary line after change."
3785   (when (and gnus-summary-default-score
3786              (not gnus-summary-inhibit-highlight))
3787     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3788            (article (gnus-summary-article-number))
3789            (score (gnus-summary-article-score article)))
3790       (unless dont-update
3791         (if (and gnus-summary-mark-below
3792                  (< (gnus-summary-article-score)
3793                     gnus-summary-mark-below))
3794             ;; This article has a low score, so we mark it as read.
3795             (when (memq article gnus-newsgroup-unreads)
3796               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3797           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3798             ;; This article was previously marked as read on account
3799             ;; of a low score, but now it has risen, so we mark it as
3800             ;; unread.
3801             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3802         (gnus-summary-update-mark
3803          (if (or (null gnus-summary-default-score)
3804                  (<= (abs (- score gnus-summary-default-score))
3805                      gnus-summary-zcore-fuzz))
3806              ?                          ;Whitespace
3807            (if (< score gnus-summary-default-score)
3808                gnus-score-below-mark gnus-score-over-mark))
3809          'score))
3810       ;; Do visual highlighting.
3811       (when (gnus-visual-p 'summary-highlight 'highlight)
3812         (gnus-summary-highlight-line)
3813         (gnus-run-hooks 'gnus-summary-update-hook)))))
3814
3815 (defvar gnus-tmp-new-adopts nil)
3816
3817 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3818   "Return the number of articles in THREAD.
3819 This may be 0 in some cases -- if none of the articles in
3820 the thread are to be displayed."
3821   (let* ((number
3822          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3823           (cond
3824            ((not (listp thread))
3825             1)
3826            ((and (consp thread) (cdr thread))
3827             (apply
3828              '+ 1 (mapcar
3829                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3830            ((null thread)
3831             1)
3832            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3833             1)
3834            (t 0))))
3835     (when (and level (zerop level) gnus-tmp-new-adopts)
3836       (incf number
3837             (apply '+ (mapcar
3838                        'gnus-summary-number-of-articles-in-thread
3839                        gnus-tmp-new-adopts))))
3840     (if char
3841         (if (> number 1) gnus-not-empty-thread-mark
3842           gnus-empty-thread-mark)
3843       number)))
3844
3845 (defsubst gnus-summary-line-message-size (head)
3846   "Return pretty-printed version of message size.
3847 This function is intended to be used in
3848 `gnus-summary-line-format-alist'."
3849   (let ((c (or (mail-header-chars head) -1)))
3850     (cond ((< c 0) "n/a")               ; chars not available
3851           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3852           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3853           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3854           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3855
3856 (defcustom gnus-user-date-format-alist
3857   '(((gnus-seconds-today) . "Today, %H:%M")
3858     ((+ 86400 (gnus-seconds-today)) . "Yesterday, %H:%M")
3859     (604800 . "%A %H:%M")               ; That's one week
3860     ((gnus-seconds-month) . "%A %d")
3861     ((gnus-seconds-year) . "%B %d")
3862     (t . "%b %d %Y"))                   ; This one is used when no other
3863                                         ; does match
3864   "Specifies date format depending on age of article.
3865 This is an alist of items (AGE . FORMAT).  AGE can be a number (of
3866 seconds) or a Lisp expression evaluating to a number.  When the age of
3867 the article is less than this number, then use `format-time-string'
3868 with the corresponding FORMAT for displaying the date of the article.
3869 If AGE is not a number or a Lisp expression evaluating to a
3870 non-number, then the corresponding FORMAT is used as a default value.
3871
3872 Note that the list is processed from the beginning, so it should be
3873 sorted by ascending AGE.  Also note that items following the first
3874 non-number AGE will be ignored.
3875
3876 You can use the functions `gnus-seconds-today', `gnus-seconds-month'
3877 and `gnus-seconds-year' in the AGE spec.  They return the number of
3878 seconds passed since the start of today, of this month, of this year,
3879 respectively."
3880   :version "24.1"
3881   :group 'gnus-summary-format
3882   :type '(alist :key-type sexp :value-type string))
3883
3884 (defun gnus-user-date (messy-date)
3885   "Format the messy-date according to `gnus-user-date-format-alist'.
3886 Returns \"  ?  \" if there's bad input or if another error occurs.
3887 Input should look like this: \"Sun, 14 Oct 2001 13:34:39 +0200\"."
3888   (condition-case ()
3889       (let* ((messy-date (gnus-float-time (gnus-date-get-time messy-date)))
3890              (now (gnus-float-time))
3891              ;;If we don't find something suitable we'll use this one
3892              (my-format "%b %d '%y"))
3893         (let* ((difference (- now messy-date))
3894                (templist gnus-user-date-format-alist)
3895                (top (eval (caar templist))))
3896           (while (if (numberp top) (< top difference) (not top))
3897             (progn
3898               (setq templist (cdr templist))
3899               (setq top (eval (caar templist)))))
3900           (if (stringp (cdr (car templist)))
3901               (setq my-format (cdr (car templist)))))
3902         (format-time-string (eval my-format) (seconds-to-time messy-date)))
3903     (error "  ?   ")))
3904
3905 (defun gnus-summary-set-local-parameters (group)
3906   "Go through the local params of GROUP and set all variable specs in that list."
3907   (let ((vars '(quit-config active)))   ; Ignore things that aren't
3908                                         ; really variables.
3909     (dolist (elem (gnus-group-find-parameter group))
3910       (and (consp elem)                 ; Has to be a cons.
3911            (consp (cdr elem))           ; The cdr has to be a list.
3912            (symbolp (car elem))         ; Has to be a symbol in there.
3913            (not (memq (car elem) vars))
3914            (ignore-errors
3915              (push (car elem) vars)
3916              ;; Variables like `gnus-show-threads' that are globally
3917              ;; bound, if used as group parameters, need to get to be
3918              ;; buffer-local, whereas just parameters like `gcc-self',
3919              ;; `timestamp', etc. should not be bound as variables.
3920              (if (boundp (car elem))
3921                  (set (make-local-variable (car elem)) (eval (nth 1 elem)))
3922                (eval (nth 1 elem))))))))
3923
3924 (defun gnus-summary-read-group (group &optional show-all no-article
3925                                       kill-buffer no-display backward
3926                                       select-articles)
3927   "Start reading news in newsgroup GROUP.
3928 If SHOW-ALL is non-nil, already read articles are also listed.
3929 If NO-ARTICLE is non-nil, no article is selected initially.
3930 If NO-DISPLAY, don't generate a summary buffer."
3931   (let (result)
3932     (while (and group
3933                 (null (setq result
3934                             (let ((gnus-auto-select-next nil))
3935                               (or (gnus-summary-read-group-1
3936                                    group show-all no-article
3937                                    kill-buffer no-display
3938                                    select-articles)
3939                                   (setq show-all nil
3940                                         select-articles nil)))))
3941                 (eq gnus-auto-select-next 'quietly))
3942       (set-buffer gnus-group-buffer)
3943       ;; The entry function called above goes to the next
3944       ;; group automatically, so we go two groups back
3945       ;; if we are searching for the previous group.
3946       (when backward
3947         (gnus-group-prev-unread-group 2))
3948       (if (not (equal group (gnus-group-group-name)))
3949           (setq group (gnus-group-group-name))
3950         (setq group nil)))
3951     result))
3952
3953 (defun gnus-summary-read-group-1 (group show-all no-article
3954                                         kill-buffer no-display
3955                                         &optional select-articles)
3956   ;; Killed foreign groups can't be entered.
3957   ;;  (when (and (not (gnus-group-native-p group))
3958   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3959   ;;    (error "Dead non-native groups can't be entered"))
3960   (gnus-message 5 "Retrieving newsgroup: %s..."
3961                 (gnus-group-decoded-name group))
3962   (let* ((new-group (gnus-summary-setup-buffer group))
3963          (quit-config (gnus-group-quit-config group))
3964          (did-select (and new-group (gnus-select-newsgroup
3965                                      group show-all select-articles))))
3966     (cond
3967      ;; This summary buffer exists already, so we just select it.
3968      ((not new-group)
3969       (gnus-set-global-variables)
3970       (when kill-buffer
3971         (gnus-kill-or-deaden-summary kill-buffer))
3972       (gnus-configure-windows 'summary 'force)
3973       (gnus-set-mode-line 'summary)
3974       (gnus-summary-position-point)
3975       (message "")
3976       t)
3977      ;; We couldn't select this group.
3978      ((null did-select)
3979       (when (and (eq major-mode 'gnus-summary-mode)
3980                  (not (equal (current-buffer) kill-buffer)))
3981         (kill-buffer (current-buffer))
3982         (if (not quit-config)
3983             (progn
3984               ;; Update the info -- marks might need to be removed,
3985               ;; for instance.
3986               (gnus-summary-update-info)
3987               (set-buffer gnus-group-buffer)
3988               (gnus-group-jump-to-group group)
3989               (gnus-group-next-unread-group 1))
3990           (gnus-handle-ephemeral-exit quit-config)))
3991       (if (null (gnus-list-of-unread-articles group))
3992           (gnus-message 3 "Group %s contains no messages" group)
3993         (gnus-message 3 "Can't select group"))
3994       nil)
3995      ;; The user did a `C-g' while prompting for number of articles,
3996      ;; so we exit this group.
3997      ((eq did-select 'quit)
3998       (and (eq major-mode 'gnus-summary-mode)
3999            (not (equal (current-buffer) kill-buffer))
4000            (kill-buffer (current-buffer)))
4001       (when kill-buffer
4002         (gnus-kill-or-deaden-summary kill-buffer))
4003       (if (not quit-config)
4004           (progn
4005             (set-buffer gnus-group-buffer)
4006             (gnus-group-jump-to-group group)
4007             (gnus-configure-windows 'group 'force))
4008         (gnus-handle-ephemeral-exit quit-config))
4009       ;; Finally signal the quit.
4010       (signal 'quit nil))
4011      ;; The group was successfully selected.
4012      (t
4013       (gnus-set-global-variables)
4014       ;; Save the active value in effect when the group was entered.
4015       (setq gnus-newsgroup-active
4016             (gnus-copy-sequence
4017              (gnus-active gnus-newsgroup-name)))
4018       (setq gnus-newsgroup-highest (cdr gnus-newsgroup-active))
4019       ;; You can change the summary buffer in some way with this hook.
4020       (gnus-run-hooks 'gnus-select-group-hook)
4021       (when (memq 'summary (gnus-update-format-specifications
4022                             nil 'summary 'summary-mode 'summary-dummy))
4023         ;; The format specification for the summary line was updated,
4024         ;; so we need to update the mark positions as well.
4025         (gnus-update-summary-mark-positions))
4026       ;; Do score processing.
4027       (when gnus-use-scoring
4028         (gnus-possibly-score-headers))
4029       ;; Check whether to fill in the gaps in the threads.
4030       (when gnus-build-sparse-threads
4031         (gnus-build-sparse-threads))
4032       ;; Find the initial limit.
4033       (if show-all
4034           (let ((gnus-newsgroup-dormant nil))
4035             (gnus-summary-initial-limit show-all))
4036         (gnus-summary-initial-limit show-all))
4037       ;; Generate the summary buffer.
4038       (unless no-display
4039         (gnus-summary-prepare))
4040       (when gnus-use-trees
4041         (gnus-tree-open group)
4042         (setq gnus-summary-highlight-line-function
4043               'gnus-tree-highlight-article))
4044       ;; If the summary buffer is empty, but there are some low-scored
4045       ;; articles or some excluded dormants, we include these in the
4046       ;; buffer.
4047       (when (and (zerop (buffer-size))
4048                  (not no-display))
4049         (cond (gnus-newsgroup-dormant
4050                (gnus-summary-limit-include-dormant))
4051               ((and gnus-newsgroup-scored show-all)
4052                (gnus-summary-limit-include-expunged t))))
4053       ;; Function `gnus-apply-kill-file' must be called in this hook.
4054       (gnus-run-hooks 'gnus-apply-kill-hook)
4055       (if (and (zerop (buffer-size))
4056                (not no-display))
4057           (progn
4058             ;; This newsgroup is empty.
4059             (gnus-summary-catchup-and-exit nil t)
4060             (gnus-message 6 "No unread news")
4061             (when kill-buffer
4062               (gnus-kill-or-deaden-summary kill-buffer))
4063             ;; Return nil from this function.
4064             nil)
4065         ;; Hide conversation thread subtrees.  We cannot do this in
4066         ;; gnus-summary-prepare-hook since kill processing may not
4067         ;; work with hidden articles.
4068         (gnus-summary-maybe-hide-threads)
4069         (gnus-configure-windows 'summary)
4070         (when kill-buffer
4071           (gnus-kill-or-deaden-summary kill-buffer))
4072         (gnus-summary-auto-select-subject)
4073         ;; Show first unread article if requested.
4074         (if (and (not no-article)
4075                  (not no-display)
4076                  gnus-newsgroup-unreads
4077                  gnus-auto-select-first)
4078             (progn
4079               (let ((art (gnus-summary-article-number)))
4080                 (unless (and (not gnus-plugged)
4081                              (or (memq art gnus-newsgroup-undownloaded)
4082                                  (memq art gnus-newsgroup-downloadable)))
4083                   (gnus-summary-goto-article art))))
4084           ;; Don't select any articles.
4085           (gnus-summary-position-point)
4086           (gnus-configure-windows 'summary 'force)
4087           (gnus-set-mode-line 'summary))
4088         (when (and gnus-auto-center-group
4089                    (get-buffer-window gnus-group-buffer t))
4090           ;; Gotta use windows, because recenter does weird stuff if
4091           ;; the current buffer ain't the displayed window.
4092           (let ((owin (selected-window)))
4093             (select-window (get-buffer-window gnus-group-buffer t))
4094             (when (gnus-group-goto-group group)
4095               (recenter))
4096             (select-window owin)))
4097         ;; Mark this buffer as "prepared".
4098         (setq gnus-newsgroup-prepared t)
4099         (gnus-run-hooks 'gnus-summary-prepared-hook)
4100         (unless (gnus-ephemeral-group-p group)
4101           (gnus-group-update-group group nil t))
4102         t)))))
4103
4104 (defun gnus-summary-auto-select-subject ()
4105   "Select the subject line on initial group entry."
4106   (goto-char (point-min))
4107   (cond
4108    ((eq gnus-auto-select-subject 'best)
4109     (gnus-summary-best-unread-subject))
4110    ((eq gnus-auto-select-subject 'unread)
4111     (gnus-summary-first-unread-subject))
4112    ((eq gnus-auto-select-subject 'unseen)
4113     (gnus-summary-first-unseen-subject))
4114    ((eq gnus-auto-select-subject 'unseen-or-unread)
4115     (gnus-summary-first-unseen-or-unread-subject))
4116    ((eq gnus-auto-select-subject 'first)
4117     ;; Do nothing.
4118     )
4119    ((functionp gnus-auto-select-subject)
4120     (funcall gnus-auto-select-subject))))
4121
4122 (defun gnus-summary-prepare ()
4123   "Generate the summary buffer."
4124   (interactive)
4125   (let ((inhibit-read-only t))
4126     (erase-buffer)
4127     (setq gnus-newsgroup-data nil
4128           gnus-newsgroup-data-reverse nil)
4129     (gnus-run-hooks 'gnus-summary-generate-hook)
4130     ;; Generate the buffer, either with threads or without.
4131     (when gnus-newsgroup-headers
4132       (gnus-summary-prepare-threads
4133        (if gnus-show-threads
4134            (gnus-sort-gathered-threads
4135             (funcall gnus-summary-thread-gathering-function
4136                      (gnus-sort-threads
4137                       (gnus-cut-threads (gnus-make-threads)))))
4138          ;; Unthreaded display.
4139          (gnus-sort-articles gnus-newsgroup-headers))))
4140     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4141     ;; Call hooks for modifying summary buffer.
4142     (goto-char (point-min))
4143     (gnus-run-hooks 'gnus-summary-prepare-hook)))
4144
4145 (defsubst gnus-general-simplify-subject (subject)
4146   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4147   (setq subject
4148         (cond
4149          ;; Truncate the subject.
4150          (gnus-simplify-subject-functions
4151           (gnus-map-function gnus-simplify-subject-functions subject))
4152          ((numberp gnus-summary-gather-subject-limit)
4153           (setq subject (gnus-simplify-subject-re subject))
4154           (if (> (length subject) gnus-summary-gather-subject-limit)
4155               (substring subject 0 gnus-summary-gather-subject-limit)
4156             subject))
4157          ;; Fuzzily simplify it.
4158          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4159           (gnus-simplify-subject-fuzzy subject))
4160          ;; Just remove the leading "Re:".
4161          (t
4162           (gnus-simplify-subject-re subject))))
4163
4164   (if (and gnus-summary-gather-exclude-subject
4165            (string-match gnus-summary-gather-exclude-subject subject))
4166       nil                         ; This article shouldn't be gathered
4167     subject))
4168
4169 (defun gnus-summary-simplify-subject-query ()
4170   "Query where the respool algorithm would put this article."
4171   (interactive)
4172   (gnus-summary-select-article)
4173   (message "%s" (gnus-general-simplify-subject (gnus-summary-article-subject))))
4174
4175 (defun gnus-gather-threads-by-subject (threads)
4176   "Gather threads by looking at Subject headers."
4177   (if (not gnus-summary-make-false-root)
4178       threads
4179     (let ((hashtb (gnus-make-hashtable 1024))
4180           (prev threads)
4181           (result threads)
4182           subject hthread whole-subject)
4183       (while threads
4184         (setq subject (gnus-general-simplify-subject
4185                        (setq whole-subject (mail-header-subject
4186                                             (caar threads)))))
4187         (when subject
4188           (if (setq hthread (gnus-gethash subject hashtb))
4189               (progn
4190                 ;; We enter a dummy root into the thread, if we
4191                 ;; haven't done that already.
4192                 (unless (stringp (caar hthread))
4193                   (setcar hthread (list whole-subject (car hthread))))
4194                 ;; We add this new gathered thread to this gathered
4195                 ;; thread.
4196                 (setcdr (car hthread)
4197                         (nconc (cdar hthread) (list (car threads))))
4198                 ;; Remove it from the list of threads.
4199                 (setcdr prev (cdr threads))
4200                 (setq threads prev))
4201             ;; Enter this thread into the hash table.
4202             (gnus-sethash subject
4203                           (if gnus-summary-make-false-root-always
4204                               (progn
4205                                 ;; If you want a dummy root above all
4206                                 ;; threads...
4207                                 (setcar threads (list whole-subject
4208                                                       (car threads)))
4209                                 threads)
4210                             threads)
4211                           hashtb)))
4212         (setq prev threads)
4213         (setq threads (cdr threads)))
4214       result)))
4215
4216 (defun gnus-gather-threads-by-references (threads)
4217   "Gather threads by looking at References headers."
4218   (let ((idhashtb (gnus-make-hashtable 1024))
4219         (thhashtb (gnus-make-hashtable 1024))
4220         (prev threads)
4221         (result threads)
4222         ids references id gthread gid entered ref)
4223     (while threads
4224       (when (setq references (mail-header-references (caar threads)))
4225         (setq id (mail-header-id (caar threads))
4226               ids (inline (gnus-split-references references))
4227               entered nil)
4228         (while (setq ref (pop ids))
4229           (setq ids (delete ref ids))
4230           (if (not (setq gid (gnus-gethash ref idhashtb)))
4231               (progn
4232                 (gnus-sethash ref id idhashtb)
4233                 (gnus-sethash id threads thhashtb))
4234             (setq gthread (gnus-gethash gid thhashtb))
4235             (unless entered
4236               ;; We enter a dummy root into the thread, if we
4237               ;; haven't done that already.
4238               (unless (stringp (caar gthread))
4239                 (setcar gthread (list (mail-header-subject (caar gthread))
4240                                       (car gthread))))
4241               ;; We add this new gathered thread to this gathered
4242               ;; thread.
4243               (setcdr (car gthread)
4244                       (nconc (cdar gthread) (list (car threads)))))
4245             ;; Add it into the thread hash table.
4246             (gnus-sethash id gthread thhashtb)
4247             (setq entered t)
4248             ;; Remove it from the list of threads.
4249             (setcdr prev (cdr threads))
4250             (setq threads prev))))
4251       (setq prev threads)
4252       (setq threads (cdr threads)))
4253     result))
4254
4255 (defun gnus-sort-gathered-threads (threads)
4256   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4257   (let ((result threads))
4258     (while threads
4259       (when (stringp (caar threads))
4260         (setcdr (car threads)
4261                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4262       (setq threads (cdr threads)))
4263     result))
4264
4265 (defun gnus-thread-loop-p (root thread)
4266   "Say whether ROOT is in THREAD."
4267   (let ((stack (list thread))
4268         (infloop 0)
4269         th)
4270     (while (setq thread (pop stack))
4271       (setq th (cdr thread))
4272       (while (and th
4273                   (not (eq (caar th) root)))
4274         (pop th))
4275       (if th
4276           ;; We have found a loop.
4277           (let (ref-dep)
4278             (setcdr thread (delq (car th) (cdr thread)))
4279             (if (boundp (setq ref-dep (intern "none"
4280                                               gnus-newsgroup-dependencies)))
4281                 (setcdr (symbol-value ref-dep)
4282                         (nconc (cdr (symbol-value ref-dep))
4283                                (list (car th))))
4284               (set ref-dep (list nil (car th))))
4285             (setq infloop 1
4286                   stack nil))
4287         ;; Push all the subthreads onto the stack.
4288         (push (cdr thread) stack)))
4289     infloop))
4290
4291 (defun gnus-make-threads ()
4292   "Go through the dependency hashtb and find the roots.  Return all threads."
4293   (let (threads)
4294     (while (catch 'infloop
4295              (mapatoms
4296               (lambda (refs)
4297                 ;; Deal with self-referencing References loops.
4298                 (when (and (car (symbol-value refs))
4299                            (not (zerop
4300                                  (apply
4301                                   '+
4302                                   (mapcar
4303                                    (lambda (thread)
4304                                      (gnus-thread-loop-p
4305                                       (car (symbol-value refs)) thread))
4306                                    (cdr (symbol-value refs)))))))
4307                   (setq threads nil)
4308                   (throw 'infloop t))
4309                 (unless (car (symbol-value refs))
4310                   ;; These threads do not refer back to any other
4311                   ;; articles, so they're roots.
4312                   (setq threads (append (cdr (symbol-value refs)) threads))))
4313               gnus-newsgroup-dependencies)))
4314     threads))
4315
4316 ;; Build the thread tree.
4317 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4318   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4319
4320 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4321 if it was already present.
4322
4323 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4324 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4325 Message-IDs will be renamed to a unique Message-ID before being
4326 entered.
4327
4328 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4329   (let* ((id (mail-header-id header))
4330          (id-dep (and id (intern id dependencies)))
4331          parent-id ref ref-dep ref-header replaced)
4332     ;; Enter this `header' in the `dependencies' table.
4333     (cond
4334      ((not id-dep)
4335       (setq header nil))
4336      ;; The first two cases do the normal part: enter a new `header'
4337      ;; in the `dependencies' table.
4338      ((not (boundp id-dep))
4339       (set id-dep (list header)))
4340      ((null (car (symbol-value id-dep)))
4341       (setcar (symbol-value id-dep) header))
4342
4343      ;; From here the `header' was already present in the
4344      ;; `dependencies' table.
4345      (force-new
4346       ;; Overrides an existing entry;
4347       ;; just set the header part of the entry.
4348       (setcar (symbol-value id-dep) header)
4349       (setq replaced t))
4350
4351      ;; Renames the existing `header' to a unique Message-ID.
4352      ((not gnus-summary-ignore-duplicates)
4353       ;; An article with this Message-ID has already been seen.
4354       ;; We rename the Message-ID.
4355       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4356            (list header))
4357       (mail-header-set-id header id))
4358
4359      ;; The last case ignores an existing entry, except it adds any
4360      ;; additional Xrefs (in case the two articles came from different
4361      ;; servers.
4362      ;; Also sets `header' to `nil' meaning that the `dependencies'
4363      ;; table was *not* modified.
4364      (t
4365       (mail-header-set-xref
4366        (car (symbol-value id-dep))
4367        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4368                    "")
4369                (or (mail-header-xref header) "")))
4370       (setq header nil)))
4371
4372     (when (and header (not replaced))
4373       ;; First check that we are not creating a References loop.
4374       (setq parent-id (gnus-parent-id (mail-header-references header)))
4375       (setq ref parent-id)
4376       (while (and ref
4377                   (setq ref-dep (intern-soft ref dependencies))
4378                   (boundp ref-dep)
4379                   (setq ref-header (car (symbol-value ref-dep))))
4380         (if (string= id ref)
4381             ;; Yuk!  This is a reference loop.  Make the article be a
4382             ;; root article.
4383             (progn
4384               (mail-header-set-references (car (symbol-value id-dep)) "none")
4385               (setq ref nil)
4386               (setq parent-id nil))
4387           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4388       (setq ref-dep (intern (or parent-id "none") dependencies))
4389       (if (boundp ref-dep)
4390           (setcdr (symbol-value ref-dep)
4391                   (nconc (cdr (symbol-value ref-dep))
4392                          (list (symbol-value id-dep))))
4393         (set ref-dep (list nil (symbol-value id-dep)))))
4394     header))
4395
4396 (defun gnus-extract-message-id-from-in-reply-to (string)
4397   (if (string-match "<[^>]+>" string)
4398       (substring string (match-beginning 0) (match-end 0))
4399     nil))
4400
4401 (defun gnus-build-sparse-threads ()
4402   (let ((headers gnus-newsgroup-headers)
4403         (mail-parse-charset gnus-newsgroup-charset)
4404         (gnus-summary-ignore-duplicates t)
4405         header references generation relations
4406         subject child end new-child date)
4407     ;; First we create an alist of generations/relations, where
4408     ;; generations is how much we trust the relation, and the relation
4409     ;; is parent/child.
4410     (gnus-message 7 "Making sparse threads...")
4411     (save-excursion
4412       (nnheader-set-temp-buffer " *gnus sparse threads*")
4413       (while (setq header (pop headers))
4414         (when (and (setq references (mail-header-references header))
4415                    (not (string= references "")))
4416           (insert references)
4417           (setq child (mail-header-id header)
4418                 subject (mail-header-subject header)
4419                 date (mail-header-date header)
4420                 generation 0)
4421           (while (search-backward ">" nil t)
4422             (setq end (1+ (point)))
4423             (when (search-backward "<" nil t)
4424               (setq new-child (buffer-substring (point) end))
4425               (push (list (incf generation)
4426                           child (setq child new-child)
4427                           subject date)
4428                     relations)))
4429           (when child
4430             (push (list (1+ generation) child nil subject) relations))
4431           (erase-buffer)))
4432       (kill-buffer (current-buffer)))
4433     ;; Sort over trustworthiness.
4434     (dolist (relation (sort relations 'car-less-than-car))
4435       (when (gnus-dependencies-add-header
4436              (make-full-mail-header
4437               gnus-reffed-article-number
4438               (nth 3 relation) "" (or (nth 4 relation) "")
4439               (nth 1 relation)
4440               (or (nth 2 relation) "") 0 0 "")
4441              gnus-newsgroup-dependencies nil)
4442         (push gnus-reffed-article-number gnus-newsgroup-limit)
4443         (push gnus-reffed-article-number gnus-newsgroup-sparse)
4444         (push (cons gnus-reffed-article-number gnus-sparse-mark)
4445               gnus-newsgroup-reads)
4446         (decf gnus-reffed-article-number)))
4447     (gnus-message 7 "Making sparse threads...done")))
4448
4449 (defun gnus-build-old-threads ()
4450   ;; Look at all the articles that refer back to old articles, and
4451   ;; fetch the headers for the articles that aren't there.  This will
4452   ;; build complete threads - if the roots haven't been expired by the
4453   ;; server, that is.
4454   (let ((mail-parse-charset gnus-newsgroup-charset)
4455         id heads)
4456     (mapatoms
4457      (lambda (refs)
4458        (when (not (car (symbol-value refs)))
4459          (setq heads (cdr (symbol-value refs)))
4460          (while heads
4461            (if (memq (mail-header-number (caar heads))
4462                      gnus-newsgroup-dormant)
4463                (setq heads (cdr heads))
4464              (setq id (symbol-name refs))
4465              (while (and (setq id (gnus-build-get-header id))
4466                          (not (car (gnus-id-to-thread id)))))
4467              (setq heads nil)))))
4468      gnus-newsgroup-dependencies)))
4469
4470 (defsubst gnus-remove-odd-characters (string)
4471   "Translate STRING into something that doesn't contain weird characters."
4472   (mm-subst-char-in-string
4473    ?\r ?\-
4474    (mm-subst-char-in-string ?\n ?\- string t) t))
4475
4476 ;; This function has to be called with point after the article number
4477 ;; on the beginning of the line.
4478 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4479   (let ((eol (point-at-eol))
4480         (buffer (current-buffer))
4481         header references in-reply-to)
4482
4483     ;; overview: [num subject from date id refs chars lines misc]
4484     (unwind-protect
4485         (let (x)
4486           (narrow-to-region (point) eol)
4487           (unless (eobp)
4488             (forward-char))
4489
4490           (setq header
4491                 (make-full-mail-header
4492                  number                 ; number
4493                  (condition-case ()     ; subject
4494                      (gnus-remove-odd-characters
4495                       (funcall gnus-decode-encoded-word-function
4496                                (setq x (nnheader-nov-field))))
4497                    (error x))
4498                  (condition-case ()     ; from
4499                      (gnus-remove-odd-characters
4500                       (funcall gnus-decode-encoded-address-function
4501                                (setq x (nnheader-nov-field))))
4502                    (error x))
4503                  (nnheader-nov-field)   ; date
4504                  (nnheader-nov-read-message-id number)  ; id
4505                  (setq references (nnheader-nov-field)) ; refs
4506                  (nnheader-nov-read-integer) ; chars
4507                  (nnheader-nov-read-integer) ; lines
4508                  (unless (eobp)
4509                    (if (looking-at "Xref: ")
4510                        (goto-char (match-end 0)))
4511                    (nnheader-nov-field)) ; Xref
4512                  (nnheader-nov-parse-extra)))) ; extra
4513
4514       (widen))
4515
4516     (when (and (string= references "")
4517                (setq in-reply-to (mail-header-extra header))
4518                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4519       (mail-header-set-references
4520        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4521
4522     (when gnus-alter-header-function
4523       (funcall gnus-alter-header-function header))
4524     (gnus-dependencies-add-header header dependencies force-new)))
4525
4526 (defun gnus-build-get-header (id)
4527   "Look through the buffer of NOV lines and find the header to ID.
4528 Enter this line into the dependencies hash table, and return
4529 the id of the parent article (if any)."
4530   (let ((deps gnus-newsgroup-dependencies)
4531         found header)
4532     (prog1
4533         (with-current-buffer nntp-server-buffer
4534           (let ((case-fold-search nil))
4535             (goto-char (point-min))
4536             (while (and (not found)
4537                         (search-forward id nil t))
4538               (beginning-of-line)
4539               (setq found (looking-at
4540                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4541                                    (regexp-quote id))))
4542               (or found (beginning-of-line 2)))
4543             (when found
4544               (beginning-of-line)
4545               (and
4546                (setq header (gnus-nov-parse-line
4547                              (read (current-buffer)) deps))
4548                (gnus-parent-id (mail-header-references header))))))
4549       (when header
4550         (let ((number (mail-header-number header)))
4551           (push number gnus-newsgroup-limit)
4552           (push header gnus-newsgroup-headers)
4553           (if (memq number gnus-newsgroup-unselected)
4554               (progn
4555                 (setq gnus-newsgroup-unreads
4556                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4557                                                number))
4558                 (setq gnus-newsgroup-unselected
4559                       (delq number gnus-newsgroup-unselected)))
4560             (push number gnus-newsgroup-ancient)))))))
4561
4562 (defun gnus-build-all-threads ()
4563   "Read all the headers."
4564   (let ((gnus-summary-ignore-duplicates t)
4565         (mail-parse-charset gnus-newsgroup-charset)
4566         (dependencies gnus-newsgroup-dependencies)
4567         header article)
4568     (with-current-buffer nntp-server-buffer
4569       (let ((case-fold-search nil))
4570         (goto-char (point-min))
4571         (while (not (eobp))
4572           (ignore-errors
4573             (setq article (read (current-buffer))
4574                   header (gnus-nov-parse-line article dependencies t)))
4575           (when header
4576             (with-current-buffer gnus-summary-buffer
4577               (push header gnus-newsgroup-headers)
4578               (if (memq (setq article (mail-header-number header))
4579                         gnus-newsgroup-unselected)
4580                   (progn
4581                     (setq gnus-newsgroup-unreads
4582                           (gnus-add-to-sorted-list
4583                            gnus-newsgroup-unreads article))
4584                     (setq gnus-newsgroup-unselected
4585                           (delq article gnus-newsgroup-unselected)))
4586                 (push article gnus-newsgroup-ancient)))
4587             (forward-line 1)))))))
4588
4589 (defun gnus-summary-update-article-line (article header)
4590   "Update the line for ARTICLE using HEADER."
4591   (let* ((id (mail-header-id header))
4592          (thread (gnus-id-to-thread id)))
4593     (unless thread
4594       (error "Article in no thread"))
4595     ;; Update the thread.
4596     (setcar thread header)
4597     (gnus-summary-goto-subject article)
4598     (let* ((datal (gnus-data-find-list article))
4599            (data (car datal))
4600            (inhibit-read-only t)
4601            (level (gnus-summary-thread-level)))
4602       (gnus-delete-line)
4603       (let ((inserted (- (point)
4604                          (progn
4605                            (gnus-summary-insert-line
4606                             header level nil
4607                             (memq article gnus-newsgroup-undownloaded)
4608                             (gnus-article-mark article)
4609                             (memq article gnus-newsgroup-replied)
4610                             (memq article gnus-newsgroup-expirable)
4611                             ;; Only insert the Subject string when it's different
4612                             ;; from the previous Subject string.
4613                             (if (and
4614                                  gnus-show-threads
4615                                  (gnus-subject-equal
4616                                   (condition-case ()
4617                                       (mail-header-subject
4618                                        (gnus-data-header
4619                                         (cadr
4620                                          (gnus-data-find-list
4621                                           article
4622                                           (gnus-data-list t)))))
4623                                     ;; Error on the side of excessive subjects.
4624                                     (error ""))
4625                                   (mail-header-subject header)))
4626                                 ""
4627                               (mail-header-subject header))
4628                             nil (cdr (assq article gnus-newsgroup-scored))
4629                             (memq article gnus-newsgroup-processable))
4630                            (point)))))
4631         (when (cdr datal)
4632           (gnus-data-update-list
4633            (cdr datal)
4634            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4635
4636 (defun gnus-summary-update-article (article &optional iheader)
4637   "Update ARTICLE in the summary buffer."
4638   (set-buffer gnus-summary-buffer)
4639   (let* ((header (gnus-summary-article-header article))
4640          (id (mail-header-id header))
4641          (data (gnus-data-find article))
4642          (thread (gnus-id-to-thread id))
4643          (references (mail-header-references header))
4644          (parent
4645           (gnus-id-to-thread
4646            (or (gnus-parent-id
4647                 (when (and references
4648                            (not (equal "" references)))
4649                   references))
4650                "none")))
4651          (inhibit-read-only t)
4652          (old (car thread)))
4653     (when thread
4654       (unless iheader
4655         (setcar thread nil)
4656         (when parent
4657           (delq thread parent)))
4658       (if (gnus-summary-insert-subject id header)
4659           ;; Set the (possibly) new article number in the data structure.
4660           (gnus-data-set-number data (gnus-id-to-article id))
4661         (setcar thread old)
4662         nil))))
4663
4664 (defun gnus-rebuild-thread (id &optional line)
4665   "Rebuild the thread containing ID.
4666 If LINE, insert the rebuilt thread starting on line LINE."
4667   (let ((inhibit-read-only t)
4668         old-pos current thread data)
4669     (if (not gnus-show-threads)
4670         (setq thread (list (car (gnus-id-to-thread id))))
4671       ;; Get the thread this article is part of.
4672       (setq thread (gnus-remove-thread id)))
4673     (setq old-pos (point-at-bol))
4674     (setq current (save-excursion
4675                     (and (re-search-backward "[\r\n]" nil t)
4676                          (gnus-summary-article-number))))
4677     ;; If this is a gathered thread, we have to go some re-gathering.
4678     (when (stringp (car thread))
4679       (let ((subject (car thread))
4680             roots thr)
4681         (setq thread (cdr thread))
4682         (while thread
4683           (unless (memq (setq thr (gnus-id-to-thread
4684                                    (gnus-root-id
4685                                     (mail-header-id (caar thread)))))
4686                         roots)
4687             (push thr roots))
4688           (setq thread (cdr thread)))
4689         ;; We now have all (unique) roots.
4690         (if (= (length roots) 1)
4691             ;; All the loose roots are now one solid root.
4692             (setq thread (car roots))
4693           (setq thread (cons subject (gnus-sort-threads roots))))))
4694     (let (threads)
4695       ;; We then insert this thread into the summary buffer.
4696       (when line
4697         (goto-char (point-min))
4698         (forward-line (1- line)))
4699       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4700         (if gnus-show-threads
4701             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4702           (gnus-summary-prepare-unthreaded thread))
4703         (setq data (nreverse gnus-newsgroup-data))
4704         (setq threads gnus-newsgroup-threads))
4705       ;; We splice the new data into the data structure.
4706       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4707       ;;!!! then we want to insert at the beginning of the buffer.
4708       ;;!!! That happens to be true with Gnus now, but that may
4709       ;;!!! change in the future.  Perhaps.
4710       (gnus-data-enter-list
4711        (if line nil current) data (- (point) old-pos))
4712       (setq gnus-newsgroup-threads
4713             (nconc threads gnus-newsgroup-threads))
4714       (gnus-data-compute-positions))))
4715
4716 (defun gnus-number-to-header (number)
4717   "Return the header for article NUMBER."
4718   (let ((headers gnus-newsgroup-headers))
4719     (while (and headers
4720                 (not (= number (mail-header-number (car headers)))))
4721       (pop headers))
4722     (when headers
4723       (car headers))))
4724
4725 (defun gnus-parent-headers (in-headers &optional generation)
4726   "Return the headers of the GENERATIONeth parent of HEADERS."
4727   (unless generation
4728     (setq generation 1))
4729   (let ((parent t)
4730         (headers in-headers)
4731         references)
4732     (while (and parent
4733                 (not (zerop generation))
4734                 (setq references (mail-header-references headers)))
4735       (setq headers (if (and references
4736                              (setq parent (gnus-parent-id references)))
4737                         (car (gnus-id-to-thread parent))
4738                       nil))
4739       (decf generation))
4740     (and (not (eq headers in-headers))
4741          headers)))
4742
4743 (defun gnus-id-to-thread (id)
4744   "Return the (sub-)thread where ID appears."
4745   (gnus-gethash id gnus-newsgroup-dependencies))
4746
4747 (defun gnus-id-to-article (id)
4748   "Return the article number of ID."
4749   (let ((thread (gnus-id-to-thread id)))
4750     (when (and thread
4751                (car thread))
4752       (mail-header-number (car thread)))))
4753
4754 (defun gnus-id-to-header (id)
4755   "Return the article headers of ID."
4756   (car (gnus-id-to-thread id)))
4757
4758 (defun gnus-article-displayed-root-p (article)
4759   "Say whether ARTICLE is a root(ish) article."
4760   (let ((level (gnus-summary-thread-level article))
4761         (refs (mail-header-references  (gnus-summary-article-header article)))
4762         particle)
4763     (cond
4764      ((null level) nil)
4765      ((zerop level) t)
4766      ((null refs) t)
4767      ((null (gnus-parent-id refs)) t)
4768      ((and (= 1 level)
4769            (null (setq particle (gnus-id-to-article
4770                                  (gnus-parent-id refs))))
4771            (null (gnus-summary-thread-level particle)))))))
4772
4773 (defun gnus-root-id (id)
4774   "Return the id of the root of the thread where ID appears."
4775   (let (last-id prev)
4776     (while (and id (setq prev (car (gnus-id-to-thread id))))
4777       (setq last-id id
4778             id (gnus-parent-id (mail-header-references prev))))
4779     last-id))
4780
4781 (defun gnus-articles-in-thread (thread)
4782   "Return the list of articles in THREAD."
4783   (cons (mail-header-number (car thread))
4784         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4785
4786 (defun gnus-remove-thread (id &optional dont-remove)
4787   "Remove the thread that has ID in it."
4788   (let (headers thread last-id)
4789     ;; First go up in this thread until we find the root.
4790     (setq last-id (gnus-root-id id)
4791           headers (message-flatten-list (gnus-id-to-thread last-id)))
4792     ;; We have now found the real root of this thread.  It might have
4793     ;; been gathered into some loose thread, so we have to search
4794     ;; through the threads to find the thread we wanted.
4795     (let ((threads gnus-newsgroup-threads)
4796           sub)
4797       (while threads
4798         (setq sub (car threads))
4799         (if (stringp (car sub))
4800             ;; This is a gathered thread, so we look at the roots
4801             ;; below it to find whether this article is in this
4802             ;; gathered root.
4803             (progn
4804               (setq sub (cdr sub))
4805               (while sub
4806                 (when (member (caar sub) headers)
4807                   (setq thread (car threads)
4808                         threads nil
4809                         sub nil))
4810                 (setq sub (cdr sub))))
4811           ;; It's an ordinary thread, so we check it.
4812           (when (eq (car sub) (car headers))
4813             (setq thread sub
4814                   threads nil)))
4815         (setq threads (cdr threads)))
4816       ;; If this article is in no thread, then it's a root.
4817       (if thread
4818           (unless dont-remove
4819             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4820         (setq thread (gnus-id-to-thread last-id)))
4821       (when thread
4822         (prog1
4823             thread                      ; We return this thread.
4824           (unless dont-remove
4825             (if (stringp (car thread))
4826                 (progn
4827                   ;; If we use dummy roots, then we have to remove the
4828                   ;; dummy root as well.
4829                   (when (eq gnus-summary-make-false-root 'dummy)
4830                     ;; We go to the dummy root by going to
4831                     ;; the first sub-"thread", and then one line up.
4832                     (gnus-summary-goto-article
4833                      (mail-header-number (caadr thread)))
4834                     (forward-line -1)
4835                     (gnus-delete-line)
4836                     (gnus-data-compute-positions))
4837                   (setq thread (cdr thread))
4838                   (while thread
4839                     (gnus-remove-thread-1 (car thread))
4840                     (setq thread (cdr thread))))
4841               (gnus-remove-thread-1 thread))))))))
4842
4843 (defun gnus-remove-thread-1 (thread)
4844   "Remove the thread THREAD recursively."
4845   (let ((number (mail-header-number (pop thread)))
4846         d)
4847     (setq thread (reverse thread))
4848     (while thread
4849       (gnus-remove-thread-1 (pop thread)))
4850     (when (setq d (gnus-data-find number))
4851       (goto-char (gnus-data-pos d))
4852       (gnus-summary-show-thread)
4853       (gnus-data-remove
4854        number
4855        (- (point-at-bol)
4856           (prog1
4857               (1+ (point-at-eol))
4858             (gnus-delete-line)))))))
4859
4860 (defun gnus-sort-threads-recursive (threads func)
4861   (sort (mapcar (lambda (thread)
4862                   (cons (car thread)
4863                         (and (cdr thread)
4864                              (gnus-sort-threads-recursive (cdr thread) func))))
4865                 threads) func))
4866
4867 (defun gnus-sort-threads-loop (threads func)
4868   (let* ((superthread (cons nil threads))
4869          (stack (list (cons superthread threads)))
4870          remaining-threads thread)
4871     (while stack
4872       (setq remaining-threads (cdr (car stack)))
4873       (if remaining-threads
4874           (progn (setq thread (car remaining-threads))
4875                  (setcdr (car stack) (cdr remaining-threads))
4876                  (if (cdr thread)
4877                      (push (cons thread (cdr thread)) stack)))
4878         (setq thread (caar stack))
4879         (setcdr thread (sort (cdr thread) func))
4880         (pop stack)))
4881     (cdr superthread)))
4882
4883 (defun gnus-sort-threads (threads)
4884   "Sort THREADS."
4885   (if (not gnus-thread-sort-functions)
4886       threads
4887     (gnus-message 8 "Sorting threads...")
4888     (prog1
4889         (condition-case nil
4890             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4891               (gnus-sort-threads-recursive
4892                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4893           ;; Even after binding max-lisp-eval-depth, the recursive
4894           ;; sorter might fail for very long threads.  In that case,
4895           ;; try using a (less well-tested) non-recursive sorter.
4896           (error (gnus-message 9 "Sorting threads with loop...")
4897                  (gnus-sort-threads-loop
4898                   threads (gnus-make-sort-function
4899                            gnus-thread-sort-functions))))
4900       (gnus-message 8 "Sorting threads...done"))))
4901
4902 (defun gnus-sort-articles (articles)
4903   "Sort ARTICLES."
4904   (when gnus-article-sort-functions
4905     (gnus-message 7 "Sorting articles...")
4906     (prog1
4907         (setq gnus-newsgroup-headers
4908               (sort articles (gnus-make-sort-function
4909                               gnus-article-sort-functions)))
4910       (gnus-message 7 "Sorting articles...done"))))
4911
4912 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4913 (defmacro gnus-thread-header (thread)
4914   "Return header of first article in THREAD.
4915 Note that THREAD must never, ever be anything else than a variable -
4916 using some other form will lead to serious barfage."
4917   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4918   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4919   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4920         (vector thread) 2))
4921
4922 (defsubst gnus-article-sort-by-number (h1 h2)
4923   "Sort articles by article number."
4924   (< (mail-header-number h1)
4925      (mail-header-number h2)))
4926
4927 (defun gnus-thread-sort-by-number (h1 h2)
4928   "Sort threads by root article number."
4929   (gnus-article-sort-by-number
4930    (gnus-thread-header h1) (gnus-thread-header h2)))
4931
4932 (defsubst gnus-article-sort-by-random (h1 h2)
4933   "Sort articles randomly."
4934   (zerop (random 2)))
4935
4936 (defun gnus-thread-sort-by-random (h1 h2)
4937   "Sort threads randomly."
4938   (gnus-article-sort-by-random
4939    (gnus-thread-header h1) (gnus-thread-header h2)))
4940
4941 (defsubst gnus-article-sort-by-lines (h1 h2)
4942   "Sort articles by article Lines header."
4943   (< (mail-header-lines h1)
4944      (mail-header-lines h2)))
4945
4946 (defun gnus-thread-sort-by-lines (h1 h2)
4947   "Sort threads by root article Lines header."
4948   (gnus-article-sort-by-lines
4949    (gnus-thread-header h1) (gnus-thread-header h2)))
4950
4951 (defsubst gnus-article-sort-by-chars (h1 h2)
4952   "Sort articles by octet length."
4953   (< (mail-header-chars h1)
4954      (mail-header-chars h2)))
4955
4956 (defun gnus-thread-sort-by-chars (h1 h2)
4957   "Sort threads by root article octet length."
4958   (gnus-article-sort-by-chars
4959    (gnus-thread-header h1) (gnus-thread-header h2)))
4960
4961 (defsubst gnus-article-sort-by-author (h1 h2)
4962   "Sort articles by root author."
4963   (gnus-string<
4964    (let ((extract (funcall
4965                    gnus-extract-address-components
4966                    (mail-header-from h1))))
4967      (or (car extract) (cadr extract) ""))
4968    (let ((extract (funcall
4969                    gnus-extract-address-components
4970                    (mail-header-from h2))))
4971      (or (car extract) (cadr extract) ""))))
4972
4973 (defun gnus-thread-sort-by-author (h1 h2)
4974   "Sort threads by root author."
4975   (gnus-article-sort-by-author
4976    (gnus-thread-header h1)  (gnus-thread-header h2)))
4977
4978 (defsubst gnus-article-sort-by-recipient (h1 h2)
4979   "Sort articles by recipient."
4980   (gnus-string<
4981    (let ((extract (funcall
4982                    gnus-extract-address-components
4983                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4984      (or (car extract) (cadr extract)))
4985    (let ((extract (funcall
4986                    gnus-extract-address-components
4987                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4988      (or (car extract) (cadr extract)))))
4989
4990 (defun gnus-thread-sort-by-recipient (h1 h2)
4991   "Sort threads by root recipient."
4992   (gnus-article-sort-by-recipient
4993    (gnus-thread-header h1) (gnus-thread-header h2)))
4994
4995 (defsubst gnus-article-sort-by-subject (h1 h2)
4996   "Sort articles by root subject."
4997   (gnus-string<
4998    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4999    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
5000
5001 (defun gnus-thread-sort-by-subject (h1 h2)
5002   "Sort threads by root subject."
5003   (gnus-article-sort-by-subject
5004    (gnus-thread-header h1) (gnus-thread-header h2)))
5005
5006 (defsubst gnus-article-sort-by-date (h1 h2)
5007   "Sort articles by root article date."
5008   (time-less-p
5009    (gnus-date-get-time (mail-header-date h1))
5010    (gnus-date-get-time (mail-header-date h2))))
5011
5012 (defun gnus-thread-sort-by-date (h1 h2)
5013   "Sort threads by root article date."
5014   (gnus-article-sort-by-date
5015    (gnus-thread-header h1) (gnus-thread-header h2)))
5016
5017 (defsubst gnus-article-sort-by-score (h1 h2)
5018   "Sort articles by root article score.
5019 Unscored articles will be counted as having a score of zero."
5020   (> (or (cdr (assq (mail-header-number h1)
5021                     gnus-newsgroup-scored))
5022          gnus-summary-default-score 0)
5023      (or (cdr (assq (mail-header-number h2)
5024                     gnus-newsgroup-scored))
5025          gnus-summary-default-score 0)))
5026
5027 (defun gnus-thread-sort-by-score (h1 h2)
5028   "Sort threads by root article score."
5029   (gnus-article-sort-by-score
5030    (gnus-thread-header h1) (gnus-thread-header h2)))
5031
5032 (defun gnus-thread-sort-by-total-score (h1 h2)
5033   "Sort threads by the sum of all scores in the thread.
5034 Unscored articles will be counted as having a score of zero."
5035   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
5036
5037 (defun gnus-thread-total-score (thread)
5038   ;; This function find the total score of THREAD.
5039   (cond
5040    ((null thread)
5041     0)
5042    ((consp thread)
5043     (if (stringp (car thread))
5044         (apply gnus-thread-score-function 0
5045                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
5046       (gnus-thread-total-score-1 thread)))
5047    (t
5048     (gnus-thread-total-score-1 (list thread)))))
5049
5050 (defun gnus-article-sort-by-most-recent-number (h1 h2)
5051   "Sort articles by number."
5052   (gnus-article-sort-by-number h1 h2))
5053
5054 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
5055   "Sort threads such that the thread with the most recently arrived article comes first."
5056   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
5057
5058 (defun gnus-thread-highest-number (thread)
5059   "Return the highest article number in THREAD."
5060   (apply 'max (mapcar (lambda (header)
5061                         (mail-header-number header))
5062                       (message-flatten-list thread))))
5063
5064 (defun gnus-article-sort-by-most-recent-date (h1 h2)
5065   "Sort articles by number."
5066   (gnus-article-sort-by-date h1 h2))
5067
5068 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
5069   "Sort threads such that the thread with the most recently dated article comes first."
5070   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
5071
5072 ; Since this is called not only to sort the top-level threads, but
5073 ; also in recursive sorts to order the articles within a thread, each
5074 ; article will be processed many times.  Thus it speeds things up
5075 ; quite a bit to use gnus-date-get-time, which caches the time value.
5076 (defun gnus-thread-latest-date (thread)
5077   "Return the highest article date in THREAD."
5078   (apply 'max
5079          (mapcar (lambda (header) (gnus-float-time
5080                                    (gnus-date-get-time
5081                                     (mail-header-date header))))
5082                  (message-flatten-list thread))))
5083
5084 (defun gnus-thread-total-score-1 (root)
5085   ;; This function find the total score of the thread below ROOT.
5086   (setq root (car root))
5087   (apply gnus-thread-score-function
5088          (or (append
5089               (mapcar 'gnus-thread-total-score
5090                       (cdr (gnus-id-to-thread (mail-header-id root))))
5091               (when (> (mail-header-number root) 0)
5092                 (list (or (cdr (assq (mail-header-number root)
5093                                      gnus-newsgroup-scored))
5094                           gnus-summary-default-score 0))))
5095              (list gnus-summary-default-score)
5096              '(0))))
5097
5098 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
5099 (defvar gnus-tmp-prev-subject nil)
5100 (defvar gnus-tmp-false-parent nil)
5101 (defvar gnus-tmp-root-expunged nil)
5102 (defvar gnus-tmp-dummy-line nil)
5103
5104 (defun gnus-extra-header (type &optional header)
5105   "Return the extra header of TYPE."
5106   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
5107       ""))
5108
5109 (defvar gnus-tmp-thread-tree-header-string "")
5110
5111 (defcustom gnus-sum-thread-tree-root "> "
5112   "With %B spec, used for the root of a thread.
5113 If nil, use subject instead."
5114   :version "22.1"
5115   :type '(radio (const :format "%v  " nil) string)
5116   :group 'gnus-thread)
5117
5118 (defcustom gnus-sum-thread-tree-false-root "> "
5119   "With %B spec, used for a false root of a thread.
5120 If nil, use subject instead."
5121   :version "22.1"
5122   :type '(radio (const :format "%v  " nil) string)
5123   :group 'gnus-thread)
5124
5125 (defcustom gnus-sum-thread-tree-single-indent ""
5126   "With %B spec, used for a thread with just one message.
5127 If nil, use subject instead."
5128   :version "22.1"
5129   :type '(radio (const :format "%v  " nil) string)
5130   :group 'gnus-thread)
5131
5132 (defcustom gnus-sum-thread-tree-vertical "| "
5133   "With %B spec, used for drawing a vertical line."
5134   :version "22.1"
5135   :type 'string
5136   :group 'gnus-thread)
5137
5138 (defcustom gnus-sum-thread-tree-indent "  "
5139   "With %B spec, used for indenting."
5140   :version "22.1"
5141   :type 'string
5142   :group 'gnus-thread)
5143
5144 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5145   "With %B spec, used for a leaf with brothers."
5146   :version "22.1"
5147   :type 'string
5148   :group 'gnus-thread)
5149
5150 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5151   "With %B spec, used for a leaf without brothers."
5152   :version "22.1"
5153   :type 'string
5154   :group 'gnus-thread)
5155
5156 (defcustom gnus-summary-display-while-building nil
5157   "If non-nil, show and update the summary buffer as it's being built.
5158 If the value is t, update the buffer after every line is inserted.  If
5159 the value is an integer (N), update the display every N lines."
5160   :version "22.1"
5161   :group 'gnus-thread
5162   :type '(choice (const :tag "off" nil)
5163                  number
5164                  (const :tag "frequently" t)))
5165
5166 (defun gnus-summary-prepare-threads (threads)
5167   "Prepare summary buffer from THREADS and indentation LEVEL.
5168 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5169 or a straight list of headers."
5170   (gnus-message 7 "Generating summary...")
5171
5172   (setq gnus-newsgroup-threads threads)
5173   (beginning-of-line)
5174
5175   (let ((gnus-tmp-level 0)
5176         (default-score (or gnus-summary-default-score 0))
5177         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5178         (building-line-count gnus-summary-display-while-building)
5179         (building-count (integerp gnus-summary-display-while-building))
5180         thread number subject stack state gnus-tmp-gathered beg-match
5181         new-roots gnus-tmp-new-adopts thread-end simp-subject
5182         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5183         gnus-tmp-replied gnus-tmp-subject-or-nil
5184         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5185         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5186         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5187         tree-stack)
5188
5189     (setq gnus-tmp-prev-subject nil
5190           gnus-tmp-thread-tree-header-string "")
5191
5192     (if (vectorp (car threads))
5193         ;; If this is a straight (sic) list of headers, then a
5194         ;; threaded summary display isn't required, so we just create
5195         ;; an unthreaded one.
5196         (gnus-summary-prepare-unthreaded threads)
5197
5198       ;; Do the threaded display.
5199
5200       (if gnus-summary-display-while-building
5201           (switch-to-buffer (buffer-name)))
5202       (while (or threads stack gnus-tmp-new-adopts new-roots)
5203
5204         (if (and (= gnus-tmp-level 0)
5205                  (or (not stack)
5206                      (= (caar stack) 0))
5207                  (not gnus-tmp-false-parent)
5208                  (or gnus-tmp-new-adopts new-roots))
5209             (if gnus-tmp-new-adopts
5210                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5211                       thread (list (car gnus-tmp-new-adopts))
5212                       gnus-tmp-header (caar thread)
5213                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5214               (when new-roots
5215                 (setq thread (list (car new-roots))
5216                       gnus-tmp-header (caar thread)
5217                       new-roots (cdr new-roots))))
5218
5219           (if threads
5220               ;; If there are some threads, we do them before the
5221               ;; threads on the stack.
5222               (setq thread threads
5223                     gnus-tmp-header (caar thread))
5224             ;; There were no current threads, so we pop something off
5225             ;; the stack.
5226             (setq state (car stack)
5227                   gnus-tmp-level (car state)
5228                   tree-stack (cadr state)
5229                   thread (caddr state)
5230                   stack (cdr stack)
5231                   gnus-tmp-header (caar thread))))
5232
5233         (setq gnus-tmp-false-parent nil)
5234         (setq gnus-tmp-root-expunged nil)
5235         (setq thread-end nil)
5236
5237         (if (stringp gnus-tmp-header)
5238             ;; The header is a dummy root.
5239             (cond
5240              ((eq gnus-summary-make-false-root 'adopt)
5241               ;; We let the first article adopt the rest.
5242               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5243                                                (cddar thread)))
5244               (setq gnus-tmp-gathered
5245                     (nconc (mapcar
5246                             (lambda (h) (mail-header-number (car h)))
5247                             (cddar thread))
5248                            gnus-tmp-gathered))
5249               (setq thread (cons (list (caar thread)
5250                                        (cadar thread))
5251                                  (cdr thread)))
5252               (setq gnus-tmp-level -1
5253                     gnus-tmp-false-parent t))
5254              ((eq gnus-summary-make-false-root 'empty)
5255               ;; We print adopted articles with empty subject fields.
5256               (setq gnus-tmp-gathered
5257                     (nconc (mapcar
5258                             (lambda (h) (mail-header-number (car h)))
5259                             (cddar thread))
5260                            gnus-tmp-gathered))
5261               (setq gnus-tmp-level -1))
5262              ((eq gnus-summary-make-false-root 'dummy)
5263               ;; We remember that we probably want to output a dummy
5264               ;; root.
5265               (setq gnus-tmp-dummy-line gnus-tmp-header)
5266               (setq gnus-tmp-prev-subject gnus-tmp-header))
5267              (t
5268               ;; We do not make a root for the gathered
5269               ;; sub-threads at all.
5270               (setq gnus-tmp-level -1)))
5271
5272           (setq number (mail-header-number gnus-tmp-header)
5273                 subject (mail-header-subject gnus-tmp-header)
5274                 simp-subject (gnus-simplify-subject-fully subject))
5275
5276           (cond
5277            ;; If the thread has changed subject, we might want to make
5278            ;; this subthread into a root.
5279            ((and (null gnus-thread-ignore-subject)
5280                  (not (zerop gnus-tmp-level))
5281                  gnus-tmp-prev-subject
5282                  (not (string= gnus-tmp-prev-subject simp-subject)))
5283             (setq new-roots (nconc new-roots (list (car thread)))
5284                   thread-end t
5285                   gnus-tmp-header nil))
5286            ;; If the article lies outside the current limit,
5287            ;; then we do not display it.
5288            ((not (memq number gnus-newsgroup-limit))
5289             (setq gnus-tmp-gathered
5290                   (nconc (mapcar
5291                           (lambda (h) (mail-header-number (car h)))
5292                           (cdar thread))
5293                          gnus-tmp-gathered))
5294             (setq gnus-tmp-new-adopts (if (cdar thread)
5295                                           (append gnus-tmp-new-adopts
5296                                                   (cdar thread))
5297                                         gnus-tmp-new-adopts)
5298                   thread-end t
5299                   gnus-tmp-header nil)
5300             (when (zerop gnus-tmp-level)
5301               (setq gnus-tmp-root-expunged t)))
5302            ;; Perhaps this article is to be marked as read?
5303            ((and gnus-summary-mark-below
5304                  (< (or (cdr (assq number gnus-newsgroup-scored))
5305                         default-score)
5306                     gnus-summary-mark-below)
5307                  ;; Don't touch sparse articles.
5308                  (not (gnus-summary-article-sparse-p number))
5309                  (not (gnus-summary-article-ancient-p number)))
5310             (setq gnus-newsgroup-unreads
5311                   (delq number gnus-newsgroup-unreads))
5312             (if gnus-newsgroup-auto-expire
5313                 (setq gnus-newsgroup-expirable
5314                       (gnus-add-to-sorted-list
5315                        gnus-newsgroup-expirable number))
5316               (push (cons number gnus-low-score-mark)
5317                     gnus-newsgroup-reads))))
5318
5319           (when gnus-tmp-header
5320             ;; We may have an old dummy line to output before this
5321             ;; article.
5322             (when (and gnus-tmp-dummy-line
5323                        (gnus-subject-equal
5324                         gnus-tmp-dummy-line
5325                         (mail-header-subject gnus-tmp-header)))
5326               (gnus-summary-insert-dummy-line
5327                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5328               (setq gnus-tmp-dummy-line nil))
5329
5330             ;; Compute the mark.
5331             (setq gnus-tmp-unread (gnus-article-mark number))
5332
5333             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5334                                   gnus-tmp-header gnus-tmp-level)
5335                   gnus-newsgroup-data)
5336
5337             ;; Actually insert the line.
5338             (setq
5339              gnus-tmp-subject-or-nil
5340              (cond
5341               ((and gnus-thread-ignore-subject
5342                     gnus-tmp-prev-subject
5343                     (not (string= gnus-tmp-prev-subject simp-subject)))
5344                subject)
5345               ((zerop gnus-tmp-level)
5346                (if (and (eq gnus-summary-make-false-root 'empty)
5347                         (memq number gnus-tmp-gathered)
5348                         gnus-tmp-prev-subject
5349                         (string= gnus-tmp-prev-subject simp-subject))
5350                    gnus-summary-same-subject
5351                  subject))
5352               (t gnus-summary-same-subject)))
5353             (if (and (eq gnus-summary-make-false-root 'adopt)
5354                      (= gnus-tmp-level 1)
5355                      (memq number gnus-tmp-gathered))
5356                 (setq gnus-tmp-opening-bracket ?\<
5357                       gnus-tmp-closing-bracket ?\>)
5358               (setq gnus-tmp-opening-bracket ?\[
5359                     gnus-tmp-closing-bracket ?\]))
5360             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5361                 (gnus-make-thread-indent-array
5362                  (max (* 2 (length gnus-thread-indent-array))
5363                       gnus-tmp-level)))
5364             (setq
5365              gnus-tmp-indentation
5366              (aref gnus-thread-indent-array gnus-tmp-level)
5367              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5368              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5369                                 gnus-summary-default-score 0)
5370              gnus-tmp-score-char
5371              (if (or (null gnus-summary-default-score)
5372                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5373                          gnus-summary-zcore-fuzz))
5374                  ?                      ;Whitespace
5375                (if (< gnus-tmp-score gnus-summary-default-score)
5376                    gnus-score-below-mark gnus-score-over-mark))
5377              gnus-tmp-replied
5378              (cond ((memq number gnus-newsgroup-processable)
5379                     gnus-process-mark)
5380                    ((memq number gnus-newsgroup-cached)
5381                     gnus-cached-mark)
5382                    ((memq number gnus-newsgroup-replied)
5383                     gnus-replied-mark)
5384                    ((memq number gnus-newsgroup-forwarded)
5385                     gnus-forwarded-mark)
5386                    ((memq number gnus-newsgroup-saved)
5387                     gnus-saved-mark)
5388                    ((memq number gnus-newsgroup-recent)
5389                     gnus-recent-mark)
5390                    ((memq number gnus-newsgroup-unseen)
5391                     gnus-unseen-mark)
5392                    (t gnus-no-mark))
5393              gnus-tmp-downloaded
5394              (cond ((memq number gnus-newsgroup-undownloaded)
5395                     gnus-undownloaded-mark)
5396                    (gnus-newsgroup-agentized
5397                     gnus-downloaded-mark)
5398                    (t
5399                     gnus-no-mark))
5400              gnus-tmp-from (mail-header-from gnus-tmp-header)
5401              gnus-tmp-name
5402              (cond
5403               ((string-match "<[^>]+> *$" gnus-tmp-from)
5404                (setq beg-match (match-beginning 0))
5405                (or (and (string-match "^\".+\"" gnus-tmp-from)
5406                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5407                    (substring gnus-tmp-from 0 beg-match)))
5408               ((string-match "(.+)" gnus-tmp-from)
5409                (substring gnus-tmp-from
5410                           (1+ (match-beginning 0)) (1- (match-end 0))))
5411               (t gnus-tmp-from))
5412
5413              ;; Do the %B string
5414              gnus-tmp-thread-tree-header-string
5415              (cond
5416               ((not gnus-show-threads) "")
5417               ((zerop gnus-tmp-level)
5418                (cond ((cdar thread)
5419                       (or gnus-sum-thread-tree-root subject))
5420                      (gnus-tmp-new-adopts
5421                       (or gnus-sum-thread-tree-false-root subject))
5422                      (t
5423                       (or gnus-sum-thread-tree-single-indent subject))))
5424               (t
5425                (concat (apply 'concat
5426                               (mapcar (lambda (item)
5427                                         (if (= item 1)
5428                                             gnus-sum-thread-tree-vertical
5429                                           gnus-sum-thread-tree-indent))
5430                                       (cdr (reverse tree-stack))))
5431                        (if (nth 1 thread)
5432                            gnus-sum-thread-tree-leaf-with-other
5433                          gnus-sum-thread-tree-single-leaf)))))
5434             (when (string= gnus-tmp-name "")
5435               (setq gnus-tmp-name gnus-tmp-from))
5436             (unless (numberp gnus-tmp-lines)
5437               (setq gnus-tmp-lines -1))
5438             (if (= gnus-tmp-lines -1)
5439                 (setq gnus-tmp-lines "?")
5440               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5441             (gnus-put-text-property
5442              (point)
5443              (progn (eval gnus-summary-line-format-spec) (point))
5444              'gnus-number number)
5445             (when gnus-visual-p
5446               (forward-line -1)
5447               (gnus-summary-highlight-line)
5448               (when gnus-summary-update-hook
5449                 (gnus-run-hooks 'gnus-summary-update-hook))
5450               (forward-line 1))
5451
5452             (setq gnus-tmp-prev-subject simp-subject)))
5453
5454         (when (nth 1 thread)
5455           (push (list (max 0 gnus-tmp-level)
5456                       (copy-sequence tree-stack)
5457                       (nthcdr 1 thread))
5458                 stack))
5459         (push (if (nth 1 thread) 1 0) tree-stack)
5460         (incf gnus-tmp-level)
5461         (setq threads (if thread-end nil (cdar thread)))
5462         (if gnus-summary-display-while-building
5463             (if building-count
5464                 (progn
5465                   ;; use a set frequency
5466                   (setq building-line-count (1- building-line-count))
5467                   (when (= building-line-count 0)
5468                     (sit-for 0)
5469                     (setq building-line-count
5470                           gnus-summary-display-while-building)))
5471               ;; always
5472               (sit-for 0)))
5473         (unless threads
5474           (setq gnus-tmp-level 0)))))
5475   (gnus-message 7 "Generating summary...done"))
5476
5477 (defun gnus-summary-prepare-unthreaded (headers)
5478   "Generate an unthreaded summary buffer based on HEADERS."
5479   (let (header number mark)
5480
5481     (beginning-of-line)
5482
5483     (while headers
5484       ;; We may have to root out some bad articles...
5485       (when (memq (setq number (mail-header-number
5486                                 (setq header (pop headers))))
5487                   gnus-newsgroup-limit)
5488         ;; Mark article as read when it has a low score.
5489         (when (and gnus-summary-mark-below
5490                    (< (or (cdr (assq number gnus-newsgroup-scored))
5491                           gnus-summary-default-score 0)
5492                       gnus-summary-mark-below)
5493                    (not (gnus-summary-article-ancient-p number)))
5494           (setq gnus-newsgroup-unreads
5495                 (delq number gnus-newsgroup-unreads))
5496           (if gnus-newsgroup-auto-expire
5497               (push number gnus-newsgroup-expirable)
5498             (push (cons number gnus-low-score-mark)
5499                   gnus-newsgroup-reads)))
5500
5501         (setq mark (gnus-article-mark number))
5502         (push (gnus-data-make number mark (1+ (point)) header 0)
5503               gnus-newsgroup-data)
5504         (gnus-summary-insert-line
5505          header 0 number
5506          (memq number gnus-newsgroup-undownloaded)
5507          mark (memq number gnus-newsgroup-replied)
5508          (memq number gnus-newsgroup-expirable)
5509          (mail-header-subject header) nil
5510          (cdr (assq number gnus-newsgroup-scored))
5511          (memq number gnus-newsgroup-processable))))))
5512
5513 (defun gnus-group-get-list-identifiers (group)
5514   "Get list identifier regexp for GROUP."
5515   (or (gnus-parameter-list-identifier group)
5516       (if (consp gnus-list-identifiers)
5517           (mapconcat 'identity gnus-list-identifiers " *\\|")
5518         gnus-list-identifiers)))
5519
5520 (defun gnus-summary-remove-list-identifiers ()
5521   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5522   (let ((regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
5523         changed subject)
5524     (when regexp
5525       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5526       (dolist (header gnus-newsgroup-headers)
5527         (setq subject (mail-header-subject header)
5528               changed nil)
5529         (while (string-match regexp subject)
5530           (setq subject
5531                 (concat (substring subject 0 (match-beginning 1))
5532                         (substring subject (match-end 0)))
5533                 changed t))
5534         (when changed
5535           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5536             (setq subject
5537                   (concat (substring subject 0 (match-beginning 1))
5538                           (substring subject (match-end 1)))))
5539           (mail-header-set-subject header subject))))))
5540
5541 (defun gnus-fetch-headers (articles &optional limit force-new dependencies)
5542   "Fetch headers of ARTICLES."
5543   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5544     (gnus-message 5 "Fetching headers for %s..." name)
5545     (prog1
5546         (if (eq 'nov
5547                 (setq gnus-headers-retrieved-by
5548                       (gnus-retrieve-headers
5549                        articles gnus-newsgroup-name
5550                        (or limit
5551                            ;; We might want to fetch old headers, but
5552                            ;; not if there is only 1 article.
5553                            (and (or (and
5554                                      (not (eq gnus-fetch-old-headers 'some))
5555                                      (not (numberp gnus-fetch-old-headers)))
5556                                     (> (length articles) 1))
5557                                 gnus-fetch-old-headers)))))
5558             (gnus-get-newsgroup-headers-xover
5559              articles force-new dependencies gnus-newsgroup-name t)
5560           (gnus-get-newsgroup-headers dependencies force-new))
5561       (gnus-message 5 "Fetching headers for %s...done" name))))
5562
5563 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5564   "Select newsgroup GROUP.
5565 If READ-ALL is non-nil, all articles in the group are selected.
5566 If SELECT-ARTICLES, only select those articles from GROUP."
5567   (let* ((entry (gnus-group-entry group))
5568          ;;!!! Dirty hack; should be removed.
5569          (gnus-summary-ignore-duplicates
5570           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5571               t
5572             gnus-summary-ignore-duplicates))
5573          (info (nth 2 entry))
5574          charset articles fetched-articles cached)
5575
5576     (unless (gnus-check-server
5577              (set (make-local-variable 'gnus-current-select-method)
5578                   (gnus-find-method-for-group group)))
5579       (error "Couldn't open server"))
5580     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5581
5582     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5583         (gnus-activate-group group)     ; Or we can activate it...
5584         (progn                          ; Or we bug out.
5585           (when (equal major-mode 'gnus-summary-mode)
5586             (gnus-kill-buffer (current-buffer)))
5587           (error
5588            "Couldn't activate group %s: %s"
5589            (mm-decode-coding-string group charset)
5590            (mm-decode-coding-string (gnus-status-message group) charset))))
5591
5592     (unless (gnus-request-group group t)
5593       (when (equal major-mode 'gnus-summary-mode)
5594         (gnus-kill-buffer (current-buffer)))
5595       (error "Couldn't request group %s: %s"
5596              (mm-decode-coding-string group charset)
5597              (mm-decode-coding-string (gnus-status-message group) charset)))
5598
5599     (when (and gnus-agent
5600                (gnus-active group))
5601       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5602
5603       (setq gnus-summary-use-undownloaded-faces
5604             (gnus-agent-find-parameter
5605              group
5606              'agent-enable-undownloaded-faces)))
5607
5608     (setq gnus-newsgroup-name group
5609           gnus-newsgroup-unselected nil
5610           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5611
5612     (let ((display (gnus-group-find-parameter group 'display)))
5613       (setq gnus-newsgroup-display
5614             (cond
5615              ((not (zerop (or (car-safe read-all) 0)))
5616               ;; The user entered the group with C-u SPC/RET, let's show
5617               ;; all articles.
5618               'gnus-not-ignore)
5619              ((eq display 'all)
5620               'gnus-not-ignore)
5621              ((arrayp display)
5622               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5623              ((numberp display)
5624               ;; The following is probably the "correct" solution, but
5625               ;; it makes Gnus fetch all headers and then limit the
5626               ;; articles (which is slow), so instead we hack the
5627               ;; select-articles parameter instead. -- Simon Josefsson
5628               ;; <jas@kth.se>
5629               ;;
5630               ;; (gnus-byte-compile
5631               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5632               ;;                         display)))))
5633               (setq select-articles
5634                     (gnus-uncompress-range
5635                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5636                              (if (> tmp 0)
5637                                  tmp
5638                                1))
5639                            (cdr (gnus-active group)))))
5640               nil)
5641              (t
5642               nil))))
5643
5644     (gnus-summary-setup-default-charset)
5645
5646     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5647     (when (gnus-virtual-group-p group)
5648       (setq cached gnus-newsgroup-cached))
5649
5650     (setq gnus-newsgroup-unreads
5651           (gnus-sorted-ndifference
5652            (gnus-sorted-ndifference gnus-newsgroup-unreads
5653                                     gnus-newsgroup-marked)
5654            gnus-newsgroup-dormant))
5655
5656     (setq gnus-newsgroup-processable nil)
5657
5658     (gnus-update-read-articles group gnus-newsgroup-unreads t)
5659
5660     ;; Adjust and set lists of article marks.
5661     (when info
5662       (gnus-adjust-marked-articles info))
5663     (if (setq articles select-articles)
5664         (setq gnus-newsgroup-unselected
5665               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5666       (setq articles (gnus-articles-to-read group read-all)))
5667
5668     (cond
5669      ((null articles)
5670       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5671       'quit)
5672      ((eq articles 0) nil)
5673      (t
5674       ;; Init the dependencies hash table.
5675       (setq gnus-newsgroup-dependencies
5676             (gnus-make-hashtable (length articles)))
5677       (gnus-set-global-variables)
5678       ;; Retrieve the headers and read them in.
5679
5680       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5681
5682       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5683       (when cached
5684         (setq gnus-newsgroup-cached cached))
5685
5686       ;; Suppress duplicates?
5687       (when gnus-suppress-duplicates
5688         (gnus-dup-suppress-articles))
5689
5690       ;; Set the initial limit.
5691       (setq gnus-newsgroup-limit (copy-sequence articles))
5692       ;; Remove canceled articles from the list of unread articles.
5693       (setq fetched-articles
5694             (mapcar (lambda (headers) (mail-header-number headers))
5695                     gnus-newsgroup-headers))
5696       (setq gnus-newsgroup-articles fetched-articles)
5697       (setq gnus-newsgroup-unreads
5698             (gnus-sorted-nintersection
5699              gnus-newsgroup-unreads fetched-articles))
5700       (gnus-compute-unseen-list)
5701
5702       ;; Removed marked articles that do not exist.
5703       (gnus-update-missing-marks
5704        (gnus-sorted-difference articles fetched-articles))
5705       ;; We might want to build some more threads first.
5706       (when (and gnus-fetch-old-headers
5707                  (eq gnus-headers-retrieved-by 'nov))
5708         (if (eq gnus-fetch-old-headers 'invisible)
5709             (gnus-build-all-threads)
5710           (gnus-build-old-threads)))
5711       ;; Let the Gnus agent mark articles as read.
5712       (when gnus-agent
5713         (gnus-agent-get-undownloaded-list))
5714       ;; Remove list identifiers from subject
5715       (gnus-summary-remove-list-identifiers)
5716       ;; Check whether auto-expire is to be done in this group.
5717       (setq gnus-newsgroup-auto-expire
5718             (and (gnus-group-auto-expirable-p group)
5719                  (not (gnus-group-read-only-p group))))
5720       ;; Set up the article buffer now, if necessary.
5721       (unless (and gnus-single-article-buffer
5722                    (equal gnus-article-buffer "*Article*"))
5723         (gnus-article-setup-buffer))
5724       ;; First and last article in this newsgroup.
5725       (when gnus-newsgroup-headers
5726         (setq gnus-newsgroup-begin
5727               (mail-header-number (car gnus-newsgroup-headers))
5728               gnus-newsgroup-end
5729               (mail-header-number
5730                (gnus-last-element gnus-newsgroup-headers))))
5731       ;; GROUP is successfully selected.
5732       (or gnus-newsgroup-headers t)))))
5733
5734 (defun gnus-compute-unseen-list ()
5735   ;; The `seen' marks are treated specially.
5736   (if (not gnus-newsgroup-seen)
5737       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5738     (setq gnus-newsgroup-unseen
5739           (gnus-inverse-list-range-intersection
5740            gnus-newsgroup-articles gnus-newsgroup-seen))))
5741
5742 (declare-function gnus-get-predicate "gnus-agent" (predicate))
5743
5744 (defun gnus-summary-display-make-predicate (display)
5745   (require 'gnus-agent)
5746   (when (= (length display) 1)
5747     (setq display (car display)))
5748   (unless gnus-summary-display-cache
5749     (dolist (elem (append '((unread . unread)
5750                             (read . read)
5751                             (unseen . unseen))
5752                           gnus-article-mark-lists))
5753       (push (cons (cdr elem)
5754                   (gnus-byte-compile    ;Why bother?
5755                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5756             gnus-summary-display-cache)))
5757   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5758         (gnus-category-predicate-cache gnus-summary-display-cache))
5759     (gnus-get-predicate display)))
5760
5761 ;; Uses the dynamically bound `gnus-number' variable.
5762 (defvar gnus-number)
5763 (defun gnus-article-marked-p (type &optional article)
5764   (let ((article (or article gnus-number)))
5765     (cond
5766      ((eq type 'tick)
5767       (memq article gnus-newsgroup-marked))
5768      ((eq type 'spam)
5769       (memq article gnus-newsgroup-spam-marked))
5770      ((eq type 'unsend)
5771       (memq article gnus-newsgroup-unsendable))
5772      ((eq type 'undownload)
5773       (memq article gnus-newsgroup-undownloaded))
5774      ((eq type 'download)
5775       (memq article gnus-newsgroup-downloadable))
5776      ((eq type 'unread)
5777       (memq article gnus-newsgroup-unreads))
5778      ((eq type 'read)
5779       (memq article gnus-newsgroup-reads))
5780      ((eq type 'dormant)
5781       (memq article gnus-newsgroup-dormant) )
5782      ((eq type 'expire)
5783       (memq article gnus-newsgroup-expirable))
5784      ((eq type 'reply)
5785       (memq article gnus-newsgroup-replied))
5786      ((eq type 'killed)
5787       (memq article gnus-newsgroup-killed))
5788      ((eq type 'bookmark)
5789       (assq article gnus-newsgroup-bookmarks))
5790      ((eq type 'score)
5791       (assq article gnus-newsgroup-scored))
5792      ((eq type 'save)
5793       (memq article gnus-newsgroup-saved))
5794      ((eq type 'cache)
5795       (memq article gnus-newsgroup-cached))
5796      ((eq type 'forward)
5797       (memq article gnus-newsgroup-forwarded))
5798      ((eq type 'seen)
5799       (not (memq article gnus-newsgroup-unseen)))
5800      ((eq type 'recent)
5801       (memq article gnus-newsgroup-recent))
5802      (t t))))
5803
5804 (defun gnus-articles-to-read (group &optional read-all)
5805   "Find out what articles the user wants to read."
5806   (let* ((only-read-p t)
5807          (articles
5808           ;; Select all articles if `read-all' is non-nil, or if there
5809           ;; are no unread articles.
5810           (if (or read-all
5811                   (and (zerop (length gnus-newsgroup-marked))
5812                        (zerop (length gnus-newsgroup-unreads)))
5813                   ;; Fetch all if the predicate is non-nil.
5814                   gnus-newsgroup-display)
5815               ;; We want to select the headers for all the articles in
5816               ;; the group, so we select either all the active
5817               ;; articles in the group, or (if that's nil), the
5818               ;; articles in the cache.
5819               (or
5820                (if gnus-newsgroup-maximum-articles
5821                    (let ((active (gnus-active group)))
5822                      (gnus-uncompress-range
5823                       (cons (max (car active)
5824                                  (- (cdr active)
5825                                     gnus-newsgroup-maximum-articles
5826                                     -1))
5827                             (cdr active))))
5828                  (gnus-uncompress-range (gnus-active group)))
5829                (gnus-cache-articles-in-group group))
5830             ;; Select only the "normal" subset of articles.
5831             (setq only-read-p nil)
5832             (gnus-sorted-nunion
5833              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5834              gnus-newsgroup-unreads)))
5835          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5836          (scored (length scored-list))
5837          (number (length articles))
5838          (marked (+ (length gnus-newsgroup-marked)
5839                     (length gnus-newsgroup-dormant)))
5840          (select
5841           (cond
5842            ((numberp read-all)
5843             read-all)
5844            ((numberp gnus-newsgroup-display)
5845             gnus-newsgroup-display)
5846            (t
5847             (condition-case ()
5848                 (cond
5849                  ((and (or (<= scored marked) (= scored number))
5850                        (numberp gnus-large-newsgroup)
5851                        (> number gnus-large-newsgroup))
5852                   (let* ((cursor-in-echo-area nil)
5853                          (initial (gnus-parameter-large-newsgroup-initial
5854                                    gnus-newsgroup-name))
5855                          (default (if only-read-p
5856                                       (or initial gnus-large-newsgroup)
5857                                     number))
5858                          (input
5859                           (read-string
5860                            (if only-read-p
5861                                (format
5862                               "How many articles from %s (available %d, default %d): "
5863                               (gnus-group-decoded-name
5864                                (gnus-group-real-name gnus-newsgroup-name))
5865                               number default)
5866                              (format
5867                                 "How many articles from %s (%d available): "
5868                                 (gnus-group-decoded-name
5869                                  (gnus-group-real-name gnus-newsgroup-name))
5870                                 default))
5871                            nil
5872                            nil
5873                            (number-to-string default))))
5874                     (if (string-match "^[ \t]*$" input) number input)))
5875                  ((and (> scored marked) (< scored number)
5876                        (> (- scored number) 20))
5877                   (let ((input
5878                          (read-string
5879                           (format "%s %s (%d scored, %d total): "
5880                                   "How many articles from"
5881                                   (gnus-group-decoded-name
5882                                    (gnus-group-real-name gnus-newsgroup-name))
5883                                   scored number))))
5884                     (if (string-match "^[ \t]*$" input)
5885                         number input)))
5886                  (t number))
5887               (quit
5888                (message "Quit getting the articles to read")
5889                nil))))))
5890     (setq select (if (stringp select) (string-to-number select) select))
5891     (if (or (null select) (zerop select))
5892         select
5893       (if (and (not (zerop scored)) (<= (abs select) scored))
5894           (progn
5895             (setq articles (sort scored-list '<))
5896             (setq number (length articles)))
5897         (setq articles (copy-sequence articles)))
5898
5899       (when (< (abs select) number)
5900         (if (< select 0)
5901             ;; Select the N oldest articles.
5902             (setcdr (nthcdr (1- (abs select)) articles) nil)
5903           ;; Select the N most recent articles.
5904           (setq articles (nthcdr (- number select) articles))))
5905       (setq gnus-newsgroup-unselected
5906             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5907       (when gnus-alter-articles-to-read-function
5908         (setq articles
5909               (sort
5910                (funcall gnus-alter-articles-to-read-function
5911                         gnus-newsgroup-name articles)
5912                '<)))
5913       articles)))
5914
5915 (defun gnus-killed-articles (killed articles)
5916   (let (out)
5917     (while articles
5918       (when (inline (gnus-member-of-range (car articles) killed))
5919         (push (car articles) out))
5920       (setq articles (cdr articles)))
5921     out))
5922
5923 (defun gnus-uncompress-marks (marks)
5924   "Uncompress the mark ranges in MARKS."
5925   (let ((uncompressed '(score bookmark))
5926         out)
5927     (while marks
5928       (if (memq (caar marks) uncompressed)
5929           (push (car marks) out)
5930         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5931       (setq marks (cdr marks)))
5932     out))
5933
5934 (defun gnus-article-mark-to-type (mark)
5935   "Return the type of MARK."
5936   (or (cadr (assq mark gnus-article-special-mark-lists))
5937       'list))
5938
5939 (defun gnus-article-unpropagatable-p (mark)
5940   "Return whether MARK should be propagated to back end."
5941   (memq mark gnus-article-unpropagated-mark-lists))
5942
5943 (defun gnus-adjust-marked-articles (info)
5944   "Set all article lists and remove all marks that are no longer valid."
5945   (let* ((marked-lists (gnus-info-marks info))
5946          (active (gnus-active (gnus-info-group info)))
5947          (min (car active))
5948          (max (cdr active))
5949          (types gnus-article-mark-lists)
5950          marks var articles article mark mark-type
5951          bgn end)
5952     ;; Hack to avoid adjusting marks for imap.
5953     (when (eq (car (gnus-find-method-for-group (gnus-info-group info)))
5954               'nnimap)
5955       (setq min 1))
5956
5957     (dolist (marks marked-lists)
5958       (setq mark (car marks)
5959             mark-type (gnus-article-mark-to-type mark)
5960             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5961
5962       ;; We set the variable according to the type of the marks list,
5963       ;; and then adjust the marks to a subset of the active articles.
5964       (cond
5965        ;; Adjust "simple" lists - compressed yet unsorted
5966        ((eq mark-type 'list)
5967         ;; Simultaneously uncompress and clip to active range
5968         ;; See gnus-uncompress-range for a description of possible marks
5969         (let (l lh)
5970           (if (not (cadr marks))
5971               (set var nil)
5972             (setq articles (if (numberp (cddr marks))
5973                                (list (cdr marks))
5974                              (cdr marks))
5975                   lh (cons nil nil)
5976                   l lh)
5977
5978             (while (setq article (pop articles))
5979               (cond ((consp article)
5980                      (setq bgn (max (car article) min)
5981                            end (min (cdr article) max))
5982                      (while (<= bgn end)
5983                        (setq l (setcdr l (cons bgn nil))
5984                              bgn (1+ bgn))))
5985                     ((and (<= min article)
5986                           (>= max article))
5987                      (setq l (setcdr l (cons article nil))))))
5988             (set var (cdr lh)))))
5989        ;; Adjust assocs.
5990        ((eq mark-type 'tuple)
5991         (set var (setq articles (cdr marks)))
5992         (when (not (listp (cdr (symbol-value var))))
5993           (set var (list (symbol-value var))))
5994         (when (not (listp (cdr articles)))
5995           (setq articles (list articles)))
5996         (while articles
5997           (when (or (not (consp (setq article (pop articles))))
5998                     (< (car article) min)
5999                     (> (car article) max))
6000             (set var (delq article (symbol-value var))))))
6001        ;; Adjust ranges (sloppily).
6002        ((eq mark-type 'range)
6003         (cond
6004          ((eq mark 'seen)
6005           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
6006           ;; It should be (seen (NUM1 . NUM2)).
6007           (when (numberp (cddr marks))
6008             (setcdr marks (list (cdr marks))))
6009           (setq articles (cdr marks))
6010           (while (and articles
6011                       (or (and (consp (car articles))
6012                                (> min (cdar articles)))
6013                           (and (numberp (car articles))
6014                                (> min (car articles)))))
6015             (pop articles))
6016           (set var articles))))))))
6017
6018 (defun gnus-update-missing-marks (missing)
6019   "Go through the list of MISSING articles and remove them from the mark lists."
6020   (when missing
6021     (let (var m)
6022       ;; Go through all types.
6023       (dolist (elem gnus-article-mark-lists)
6024         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
6025           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
6026           (when (symbol-value var)
6027             ;; This list has articles.  So we delete all missing
6028             ;; articles from it.
6029             (setq m missing)
6030             (while m
6031               (set var (delq (pop m) (symbol-value var))))))))))
6032
6033 (defun gnus-update-marks ()
6034   "Enter the various lists of marked articles into the newsgroup info list."
6035   (let ((types gnus-article-mark-lists)
6036         (info (gnus-get-info gnus-newsgroup-name))
6037         type list newmarked symbol delta-marks)
6038     (when info
6039       ;; Add all marks lists to the list of marks lists.
6040       (while (setq type (pop types))
6041         (setq list (symbol-value
6042                     (setq symbol
6043                           (intern (format "gnus-newsgroup-%s" (car type))))))
6044
6045         (when list
6046           ;; Get rid of the entries of the articles that have the
6047           ;; default score.
6048           (when (and (eq (cdr type) 'score)
6049                      gnus-save-score
6050                      list)
6051             (let* ((arts list)
6052                    (prev (cons nil list))
6053                    (all prev))
6054               (while arts
6055                 (if (or (not (consp (car arts)))
6056                         (= (cdar arts) gnus-summary-default-score))
6057                     (setcdr prev (cdr arts))
6058                   (setq prev arts))
6059                 (setq arts (cdr arts)))
6060               (setq list (cdr all)))))
6061
6062         (when (eq (cdr type) 'seen)
6063           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
6064
6065         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
6066           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
6067
6068         (when (and (gnus-check-backend-function
6069                     'request-set-mark gnus-newsgroup-name)
6070                    (not (gnus-article-unpropagatable-p (cdr type))))
6071           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
6072                  ;; Don't do anything about marks for articles we
6073                  ;; didn't actually get any headers for.
6074                  (del
6075                   (gnus-list-range-intersection
6076                    gnus-newsgroup-articles
6077                    (gnus-remove-from-range (gnus-copy-sequence old) list)))
6078                  (add
6079                   (gnus-list-range-intersection
6080                    gnus-newsgroup-articles
6081                    (gnus-remove-from-range
6082                     (gnus-copy-sequence list) old))))
6083             (when add
6084               (push (list add 'add (list (cdr type))) delta-marks))
6085             (when del
6086               ;; Don't delete marks from outside the active range.
6087               ;; This shouldn't happen, but is a sanity check.
6088               (setq del (gnus-sorted-range-intersection
6089                          (gnus-active gnus-newsgroup-name) del))
6090               (push (list del 'del (list (cdr type))) delta-marks))))
6091
6092         (when list
6093           (push (cons (cdr type) list) newmarked)))
6094
6095       (when delta-marks
6096         (unless (gnus-check-group gnus-newsgroup-name)
6097           (error "Can't open server for %s" gnus-newsgroup-name))
6098         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
6099
6100       ;; Enter these new marks into the info of the group.
6101       (if (nthcdr 3 info)
6102           (setcar (nthcdr 3 info) newmarked)
6103         ;; Add the marks lists to the end of the info.
6104         (when newmarked
6105           (setcdr (nthcdr 2 info) (list newmarked))))
6106
6107       ;; Cut off the end of the info if there's nothing else there.
6108       (let ((i 5))
6109         (while (and (> i 2)
6110                     (not (nth i info)))
6111           (when (nthcdr (decf i) info)
6112             (setcdr (nthcdr i info) nil)))))))
6113
6114 (defun gnus-set-mode-line (where)
6115   "Set the mode line of the article or summary buffers.
6116 If WHERE is `summary', the summary mode line format will be used."
6117   ;; Is this mode line one we keep updated?
6118   (when (and (memq where gnus-updated-mode-lines)
6119              (symbol-value
6120               (intern (format "gnus-%s-mode-line-format-spec" where))))
6121     (let (mode-string)
6122       ;; We evaluate this in the summary buffer since these
6123       ;; variables are buffer-local to that buffer.
6124       (with-current-buffer gnus-summary-buffer
6125         ;; We bind all these variables that are used in the `eval' form
6126         ;; below.
6127         (let* ((mformat (symbol-value
6128                          (intern
6129                           (format "gnus-%s-mode-line-format-spec" where))))
6130                (gnus-tmp-group-name (gnus-mode-string-quote
6131                                      (gnus-group-decoded-name
6132                                       gnus-newsgroup-name)))
6133                (gnus-tmp-article-number (or gnus-current-article 0))
6134                (gnus-tmp-unread gnus-newsgroup-unreads)
6135                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
6136                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
6137                (gnus-tmp-unread-and-unselected
6138                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
6139                             (zerop gnus-tmp-unselected))
6140                        "")
6141                       ((zerop gnus-tmp-unselected)
6142                        (format "{%d more}" gnus-tmp-unread-and-unticked))
6143                       (t (format "{%d(+%d) more}"
6144                                  gnus-tmp-unread-and-unticked
6145                                  gnus-tmp-unselected))))
6146                (gnus-tmp-subject
6147                 (if (and gnus-current-headers
6148                          (vectorp gnus-current-headers))
6149                     (gnus-mode-string-quote
6150                      (mail-header-subject gnus-current-headers))
6151                   ""))
6152                bufname-length max-len
6153                gnus-tmp-header) ;; passed as argument to any user-format-funcs
6154           (setq mode-string (eval mformat))
6155           (setq bufname-length (if (string-match "%b" mode-string)
6156                                    (- (length
6157                                        (buffer-name
6158                                         (if (eq where 'summary)
6159                                             nil
6160                                           (get-buffer gnus-article-buffer))))
6161                                       2)
6162                                  0))
6163           (setq max-len (max 4 (if gnus-mode-non-string-length
6164                                    (- (window-width)
6165                                       gnus-mode-non-string-length
6166                                       bufname-length)
6167                                  (length mode-string))))
6168           ;; We might have to chop a bit of the string off...
6169           (when (> (length mode-string) max-len)
6170             (setq mode-string
6171                   (concat (truncate-string-to-width mode-string (- max-len 3))
6172                           "...")))))
6173       ;; Update the mode line.
6174       (setq mode-line-buffer-identification
6175             (gnus-mode-line-buffer-identification (list mode-string)))
6176       (set-buffer-modified-p t))))
6177
6178 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6179   "Go through the HEADERS list and add all Xrefs to a hash table.
6180 The resulting hash table is returned, or nil if no Xrefs were found."
6181   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
6182          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
6183          (xref-hashtb (gnus-make-hashtable))
6184          start group entry number xrefs header)
6185     (while headers
6186       (setq header (pop headers))
6187       (when (and (setq xrefs (mail-header-xref header))
6188                  (not (memq (setq number (mail-header-number header))
6189                             unreads)))
6190         (setq start 0)
6191         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6192           (setq start (match-end 0))
6193           (setq group (if prefix
6194                           (concat prefix (substring xrefs (match-beginning 1)
6195                                                     (match-end 1)))
6196                         (substring xrefs (match-beginning 1) (match-end 1))))
6197           (setq number
6198                 (string-to-number (substring xrefs (match-beginning 2)
6199                                           (match-end 2))))
6200           (if (setq entry (gnus-gethash group xref-hashtb))
6201               (setcdr entry (cons number (cdr entry)))
6202             (gnus-sethash group (cons number nil) xref-hashtb)))))
6203     (and start xref-hashtb)))
6204
6205 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6206   "Look through all the headers and mark the Xrefs as read."
6207   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6208         name info xref-hashtb idlist method nth4)
6209     (with-current-buffer gnus-group-buffer
6210       (when (setq xref-hashtb
6211                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6212         (mapatoms
6213          (lambda (group)
6214            (unless (string= from-newsgroup (setq name (symbol-name group)))
6215              (setq idlist (symbol-value group))
6216              ;; Dead groups are not updated.
6217              (and (prog1
6218                       (setq info (gnus-get-info name))
6219                     (when (stringp (setq nth4 (gnus-info-method info)))
6220                       (setq nth4 (gnus-server-to-method nth4))))
6221                   ;; Only do the xrefs if the group has the same
6222                   ;; select method as the group we have just read.
6223                   (or (gnus-methods-equal-p
6224                        nth4 (gnus-find-method-for-group from-newsgroup))
6225                       virtual
6226                       (equal nth4 (setq method (gnus-find-method-for-group
6227                                                 from-newsgroup)))
6228                       (and (equal (car nth4) (car method))
6229                            (equal (nth 1 nth4) (nth 1 method))))
6230                   gnus-use-cross-reference
6231                   (or (not (eq gnus-use-cross-reference t))
6232                       virtual
6233                       ;; Only do cross-references on subscribed
6234                       ;; groups, if that is what is wanted.
6235                       (<= (gnus-info-level info) gnus-level-subscribed))
6236                   (gnus-group-make-articles-read name idlist))))
6237          xref-hashtb)))))
6238
6239 (defun gnus-compute-read-articles (group articles)
6240   (let* ((entry (gnus-group-entry group))
6241          (info (nth 2 entry))
6242          (active (gnus-active group))
6243          ninfo)
6244     (when entry
6245       ;; First peel off all invalid article numbers.
6246       (when active
6247         (let ((ids articles)
6248               id first)
6249           (while (setq id (pop ids))
6250             (when (and first (> id (cdr active)))
6251               ;; We'll end up in this situation in one particular
6252               ;; obscure situation.  If you re-scan a group and get
6253               ;; a new article that is cross-posted to a different
6254               ;; group that has not been re-scanned, you might get
6255               ;; crossposted article that has a higher number than
6256               ;; Gnus believes possible.  So we re-activate this
6257               ;; group as well.  This might mean doing the
6258               ;; crossposting thingy will *increase* the number
6259               ;; of articles in some groups.  Tsk, tsk.
6260               (setq active (or (gnus-activate-group group) active)))
6261             (when (or (> id (cdr active))
6262                       (< id (car active)))
6263               (setq articles (delq id articles))))))
6264       ;; If the read list is nil, we init it.
6265       (if (and active
6266                (null (gnus-info-read info))
6267                (> (car active) 1))
6268           (setq ninfo (cons 1 (1- (car active))))
6269         (setq ninfo (gnus-info-read info)))
6270       ;; Then we add the read articles to the range.
6271       (gnus-add-to-range
6272        ninfo (setq articles (sort articles '<))))))
6273
6274 (defun gnus-group-make-articles-read (group articles)
6275   "Update the info of GROUP to say that ARTICLES are read."
6276   (let* ((num 0)
6277          (entry (gnus-group-entry group))
6278          (info (nth 2 entry))
6279          (active (gnus-active group))
6280          range)
6281     (if (not entry)
6282         ;; Group that Gnus doesn't know exists, but still allow the
6283         ;; backend to set marks.
6284         (gnus-request-set-mark
6285          group (list (list (gnus-compress-sequence (sort articles #'<))
6286                            'add '(read))))
6287       ;; Normal, subscribed groups.
6288       (setq range (gnus-compute-read-articles group articles))
6289       (with-current-buffer gnus-group-buffer
6290         (gnus-undo-register
6291           `(progn
6292              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6293              (gnus-info-set-read ',info ',(gnus-info-read info))
6294              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6295              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6296              (gnus-group-update-group ,group t))))
6297       ;; Add the read articles to the range.
6298       (gnus-info-set-read info range)
6299       (gnus-request-set-mark group (list (list range 'add '(read))))
6300       ;; Then we have to re-compute how many unread
6301       ;; articles there are in this group.
6302       (when active
6303         (cond
6304          ((not range)
6305           (setq num (- (1+ (cdr active)) (car active))))
6306          ((not (listp (cdr range)))
6307           (setq num (- (cdr active) (- (1+ (cdr range))
6308                                        (car range)))))
6309          (t
6310           (while range
6311             (if (numberp (car range))
6312                 (setq num (1+ num))
6313               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6314             (setq range (cdr range)))
6315           (setq num (- (cdr active) num))))
6316         ;; Update the number of unread articles.
6317         (setcar entry num)
6318         ;; Update the group buffer.
6319         (unless (gnus-ephemeral-group-p group)
6320           (gnus-group-update-group group t))))))
6321
6322 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6323   (let ((cur nntp-server-buffer)
6324         (dependencies
6325          (or dependencies
6326              (with-current-buffer gnus-summary-buffer
6327                gnus-newsgroup-dependencies)))
6328         headers id end ref number
6329         (mail-parse-charset gnus-newsgroup-charset)
6330         (mail-parse-ignored-charsets
6331          (save-current-buffer (condition-case nil
6332                                   (set-buffer gnus-summary-buffer)
6333                                 (error))
6334                               gnus-newsgroup-ignored-charsets)))
6335     (with-current-buffer nntp-server-buffer
6336       ;; Translate all TAB characters into SPACE characters.
6337       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6338       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6339       (ietf-drums-unfold-fws)
6340       (gnus-run-hooks 'gnus-parse-headers-hook)
6341       (let ((case-fold-search t)
6342             in-reply-to header p lines chars)
6343         (goto-char (point-min))
6344         ;; Search to the beginning of the next header.  Error messages
6345         ;; do not begin with 2 or 3.
6346         (while (re-search-forward "^[23][0-9]+ " nil t)
6347           (setq id nil
6348                 ref nil)
6349           ;; This implementation of this function, with nine
6350           ;; search-forwards instead of the one re-search-forward and
6351           ;; a case (which basically was the old function) is actually
6352           ;; about twice as fast, even though it looks messier.  You
6353           ;; can't have everything, I guess.  Speed and elegance
6354           ;; doesn't always go hand in hand.
6355           (setq
6356            header
6357            (vector
6358             ;; Number.
6359             (prog1
6360                 (setq number (read cur))
6361               (end-of-line)
6362               (setq p (point))
6363               (narrow-to-region (point)
6364                                 (or (and (search-forward "\n.\n" nil t)
6365                                          (- (point) 2))
6366                                     (point))))
6367             ;; Subject.
6368             (progn
6369               (goto-char p)
6370               (if (search-forward "\nsubject:" nil t)
6371                   (funcall gnus-decode-encoded-word-function
6372                            (nnheader-header-value))
6373                 "(none)"))
6374             ;; From.
6375             (progn
6376               (goto-char p)
6377               (if (search-forward "\nfrom:" nil t)
6378                   (funcall gnus-decode-encoded-address-function
6379                            (nnheader-header-value))
6380                 "(nobody)"))
6381             ;; Date.
6382             (progn
6383               (goto-char p)
6384               (if (search-forward "\ndate:" nil t)
6385                   (nnheader-header-value) ""))
6386             ;; Message-ID.
6387             (progn
6388               (goto-char p)
6389               (setq id (if (re-search-forward
6390                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6391                            ;; We do it this way to make sure the Message-ID
6392                            ;; is (somewhat) syntactically valid.
6393                            (buffer-substring (match-beginning 1)
6394                                              (match-end 1))
6395                          ;; If there was no message-id, we just fake one
6396                          ;; to make subsequent routines simpler.
6397                          (nnheader-generate-fake-message-id number))))
6398             ;; References.
6399             (progn
6400               (goto-char p)
6401               (if (search-forward "\nreferences:" nil t)
6402                   (progn
6403                     (setq end (point))
6404                     (prog1
6405                         (nnheader-header-value)
6406                       (setq ref
6407                             (buffer-substring
6408                              (progn
6409                                (end-of-line)
6410                                (search-backward ">" end t)
6411                                (1+ (point)))
6412                              (progn
6413                                (search-backward "<" end t)
6414                                (point))))))
6415                 ;; Get the references from the in-reply-to header if there
6416                 ;; were no references and the in-reply-to header looks
6417                 ;; promising.
6418                 (if (and (search-forward "\nin-reply-to:" nil t)
6419                          (setq in-reply-to (nnheader-header-value))
6420                          (string-match "<[^>]+>" in-reply-to))
6421                     (let (ref2)
6422                       (setq ref (substring in-reply-to (match-beginning 0)
6423                                            (match-end 0)))
6424                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6425                         (setq ref2 (substring in-reply-to (match-beginning 0)
6426                                               (match-end 0)))
6427                         (when (> (length ref2) (length ref))
6428                           (setq ref ref2)))
6429                       ref)
6430                   (setq ref nil))))
6431             ;; Chars.
6432             (progn
6433               (goto-char p)
6434               (if (search-forward "\nchars: " nil t)
6435                   (if (numberp (setq chars (ignore-errors (read cur))))
6436                       chars -1)
6437                 -1))
6438             ;; Lines.
6439             (progn
6440               (goto-char p)
6441               (if (search-forward "\nlines: " nil t)
6442                   (if (numberp (setq lines (ignore-errors (read cur))))
6443                       lines -1)
6444                 -1))
6445             ;; Xref.
6446             (progn
6447               (goto-char p)
6448               (and (search-forward "\nxref:" nil t)
6449                    (nnheader-header-value)))
6450             ;; Extra.
6451             (when gnus-extra-headers
6452               (let ((extra gnus-extra-headers)
6453                     out)
6454                 (while extra
6455                   (goto-char p)
6456                   (when (search-forward
6457                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6458                     (push (cons (car extra) (nnheader-header-value))
6459                           out))
6460                   (pop extra))
6461                 out))))
6462           (when (equal id ref)
6463             (setq ref nil))
6464
6465           (when gnus-alter-header-function
6466             (funcall gnus-alter-header-function header)
6467             (setq id (mail-header-id header)
6468                   ref (gnus-parent-id (mail-header-references header))))
6469
6470           (when (setq header
6471                       (gnus-dependencies-add-header
6472                        header dependencies force-new))
6473             (push header headers))
6474           (goto-char (point-max))
6475           (widen))
6476         (nreverse headers)))))
6477
6478 ;; Goes through the xover lines and returns a list of vectors
6479 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6480                                                   force-new dependencies
6481                                                   group also-fetch-heads)
6482   "Parse the news overview data in the server buffer.
6483 Return a list of headers that match SEQUENCE (see
6484 `nntp-retrieve-headers')."
6485   ;; Get the Xref when the users reads the articles since most/some
6486   ;; NNTP servers do not include Xrefs when using XOVER.
6487   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6488   (let ((mail-parse-charset gnus-newsgroup-charset)
6489         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6490         (cur nntp-server-buffer)
6491         (dependencies (or dependencies gnus-newsgroup-dependencies))
6492         (allp (cond
6493                ((eq gnus-read-all-available-headers t)
6494                 t)
6495                ((and (stringp gnus-read-all-available-headers)
6496                      group)
6497                 (string-match gnus-read-all-available-headers group))
6498                (t
6499                 nil)))
6500         number headers header)
6501     (with-current-buffer nntp-server-buffer
6502       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6503       ;; Allow the user to mangle the headers before parsing them.
6504       (gnus-run-hooks 'gnus-parse-headers-hook)
6505       (goto-char (point-min))
6506       (gnus-parse-without-error
6507         (while (and (or sequence allp)
6508                     (not (eobp)))
6509           (setq number (read cur))
6510           (when (not allp)
6511             (while (and sequence
6512                         (< (car sequence) number))
6513               (setq sequence (cdr sequence))))
6514           (when (and (or allp
6515                          (and sequence
6516                               (eq number (car sequence))))
6517                      (progn
6518                        (setq sequence (cdr sequence))
6519                        (setq header (inline
6520                                       (gnus-nov-parse-line
6521                                        number dependencies force-new)))))
6522             (push header headers))
6523           (forward-line 1)))
6524       ;; A common bug in inn is that if you have posted an article and
6525       ;; then retrieves the active file, it will answer correctly --
6526       ;; the new article is included.  However, a NOV entry for the
6527       ;; article may not have been generated yet, so this may fail.
6528       ;; We work around this problem by retrieving the last few
6529       ;; headers using HEAD.
6530       (if (or (not also-fetch-heads)
6531               (not sequence))
6532           ;; We (probably) got all the headers.
6533           (nreverse headers)
6534         (let ((gnus-nov-is-evil t))
6535           (nconc
6536            (nreverse headers)
6537            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6538              (gnus-get-newsgroup-headers))))))))
6539
6540 (defun gnus-article-get-xrefs ()
6541   "Fill in the Xref value in `gnus-current-headers', if necessary.
6542 This is meant to be called in `gnus-article-internal-prepare-hook'."
6543   (let ((headers (with-current-buffer gnus-summary-buffer
6544                    gnus-current-headers)))
6545     (or (not gnus-use-cross-reference)
6546         (not headers)
6547         (and (mail-header-xref headers)
6548              (not (string= (mail-header-xref headers) "")))
6549         (let ((case-fold-search t)
6550               xref)
6551           (save-restriction
6552             (nnheader-narrow-to-headers)
6553             (goto-char (point-min))
6554             (when (or (and (not (eobp))
6555                            (eq (downcase (char-after)) ?x)
6556                            (looking-at "Xref:"))
6557                       (search-forward "\nXref:" nil t))
6558               (goto-char (1+ (match-end 0)))
6559               (setq xref (buffer-substring (point) (point-at-eol)))
6560               (mail-header-set-xref headers xref)))))))
6561
6562 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6563   "Find article ID and insert the summary line for that article.
6564 OLD-HEADER can either be a header or a line number to insert
6565 the subject line on.
6566 If USE-OLD-HEADER is non-nil, then OLD-HEADER should be a header,
6567 and OLD-HEADER will be used when the summary line is inserted,
6568 too, instead of trying to fetch new headers."
6569   (let* ((line (and (numberp old-header) old-header))
6570          (old-header (and (vectorp old-header) old-header))
6571          (header (cond ((and old-header use-old-header)
6572                         old-header)
6573                        ((and (numberp id)
6574                              (gnus-number-to-header id))
6575                         (gnus-number-to-header id))
6576                        (t
6577                         (gnus-read-header id))))
6578          (number (and (numberp id) id))
6579          d)
6580     (when header
6581       ;; Rebuild the thread that this article is part of and go to the
6582       ;; article we have fetched.
6583       (when (and (not gnus-show-threads)
6584                  old-header)
6585         (when (and number
6586                    (setq d (gnus-data-find (mail-header-number old-header))))
6587           (goto-char (gnus-data-pos d))
6588           (gnus-data-remove
6589            number
6590            (- (point-at-bol)
6591               (prog1
6592                   (1+ (point-at-eol))
6593                 (gnus-delete-line))))))
6594       ;; Remove list identifiers from subject.
6595       (let ((gnus-newsgroup-headers (list header)))
6596         (gnus-summary-remove-list-identifiers))
6597       (when old-header
6598         (mail-header-set-number header (mail-header-number old-header)))
6599       (setq gnus-newsgroup-sparse
6600             (delq (setq number (mail-header-number header))
6601                   gnus-newsgroup-sparse))
6602       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6603       (push number gnus-newsgroup-limit)
6604       (gnus-rebuild-thread (mail-header-id header) line)
6605       (gnus-summary-goto-subject number nil t))
6606     (when (and (numberp number)
6607                (> number 0))
6608       ;; We have to update the boundaries even if we can't fetch the
6609       ;; article if ID is a number -- so that the next `P' or `N'
6610       ;; command will fetch the previous (or next) article even
6611       ;; if the one we tried to fetch this time has been canceled.
6612       (when (> number gnus-newsgroup-end)
6613         (setq gnus-newsgroup-end number))
6614       (when (< number gnus-newsgroup-begin)
6615         (setq gnus-newsgroup-begin number))
6616       (setq gnus-newsgroup-unselected
6617             (delq number gnus-newsgroup-unselected)))
6618     ;; Report back a success?
6619     (and header (mail-header-number header))))
6620
6621 ;;; Process/prefix in the summary buffer
6622
6623 (defun gnus-summary-work-articles (n)
6624   "Return a list of articles to be worked upon.
6625 The prefix argument, the list of process marked articles, and the
6626 current article will be taken into consideration."
6627   (with-current-buffer gnus-summary-buffer
6628     (cond
6629      (n
6630       ;; A numerical prefix has been given.
6631       (setq n (prefix-numeric-value n))
6632       (let ((backward (< n 0))
6633             (n (abs (prefix-numeric-value n)))
6634             articles article)
6635         (save-excursion
6636           (while
6637               (and (> n 0)
6638                    (push (setq article (gnus-summary-article-number))
6639                          articles)
6640                    (if backward
6641                        (gnus-summary-find-prev nil article)
6642                      (gnus-summary-find-next nil article)))
6643             (decf n)))
6644         (nreverse articles)))
6645      ((and (gnus-region-active-p) (mark))
6646       (message "region active")
6647       ;; Work on the region between point and mark.
6648       (let ((max (max (point) (mark)))
6649             articles article)
6650         (save-excursion
6651           (goto-char (min (point) (mark)))
6652           (while
6653               (and
6654                (push (setq article (gnus-summary-article-number)) articles)
6655                (gnus-summary-find-next nil article)
6656                (< (point) max)))
6657           (nreverse articles))))
6658      (gnus-newsgroup-processable
6659       ;; There are process-marked articles present.
6660       ;; Save current state.
6661       (gnus-summary-save-process-mark)
6662       ;; Return the list.
6663       (reverse gnus-newsgroup-processable))
6664      (t
6665       ;; Just return the current article.
6666       (list (gnus-summary-article-number))))))
6667
6668 (defmacro gnus-summary-iterate (arg &rest forms)
6669   "Iterate over the process/prefixed articles and do FORMS.
6670 ARG is the interactive prefix given to the command.  FORMS will be
6671 executed with point over the summary line of the articles."
6672   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6673     `(let ((,articles (gnus-summary-work-articles ,arg)))
6674        (while ,articles
6675          (gnus-summary-goto-subject (car ,articles))
6676          ,@forms
6677          (pop ,articles)))))
6678
6679 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6680 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6681
6682 (defun gnus-summary-save-process-mark ()
6683   "Push the current set of process marked articles on the stack."
6684   (interactive)
6685   (push (copy-sequence gnus-newsgroup-processable)
6686         gnus-newsgroup-process-stack))
6687
6688 (defun gnus-summary-kill-process-mark ()
6689   "Push the current set of process marked articles on the stack and unmark."
6690   (interactive)
6691   (gnus-summary-save-process-mark)
6692   (gnus-summary-unmark-all-processable))
6693
6694 (defun gnus-summary-yank-process-mark ()
6695   "Pop the last process mark state off the stack and restore it."
6696   (interactive)
6697   (unless gnus-newsgroup-process-stack
6698     (error "Empty mark stack"))
6699   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6700
6701 (defun gnus-summary-process-mark-set (set)
6702   "Make SET into the current process marked articles."
6703   (gnus-summary-unmark-all-processable)
6704   (mapc 'gnus-summary-set-process-mark set))
6705
6706 ;;; Searching and stuff
6707
6708 (defun gnus-summary-search-group (&optional backward use-level)
6709   "Search for next unread newsgroup.
6710 If optional argument BACKWARD is non-nil, search backward instead."
6711   (with-current-buffer gnus-group-buffer
6712     (when (gnus-group-search-forward
6713            backward nil (if use-level (gnus-group-group-level) nil))
6714       (gnus-group-group-name))))
6715
6716 (defun gnus-summary-best-group (&optional exclude-group)
6717   "Find the name of the best unread group.
6718 If EXCLUDE-GROUP, do not go to this group."
6719   (with-current-buffer gnus-group-buffer
6720     (save-excursion
6721       (gnus-group-best-unread-group exclude-group))))
6722
6723 (defun gnus-summary-find-next (&optional unread article backward)
6724   (if backward
6725       (gnus-summary-find-prev unread article)
6726     (let* ((dummy (gnus-summary-article-intangible-p))
6727            (article (or article (gnus-summary-article-number)))
6728            (data (gnus-data-find-list article))
6729            result)
6730       (when (and (not dummy)
6731                  (or (not gnus-summary-check-current)
6732                      (not unread)
6733                      (not (gnus-data-unread-p (car data)))))
6734         (setq data (cdr data)))
6735       (when (setq result
6736                   (if unread
6737                       (progn
6738                         (while data
6739                           (unless (memq (gnus-data-number (car data))
6740                                         (cond
6741                                          ((eq gnus-auto-goto-ignores
6742                                               'always-undownloaded)
6743                                           gnus-newsgroup-undownloaded)
6744                                          (gnus-plugged
6745                                           nil)
6746                                          ((eq gnus-auto-goto-ignores
6747                                               'unfetched)
6748                                           gnus-newsgroup-unfetched)
6749                                          ((eq gnus-auto-goto-ignores
6750                                               'undownloaded)
6751                                           gnus-newsgroup-undownloaded)))
6752                             (when (gnus-data-unread-p (car data))
6753                               (setq result (car data)
6754                                     data nil)))
6755                           (setq data (cdr data)))
6756                         result)
6757                     (car data)))
6758         (goto-char (gnus-data-pos result))
6759         (gnus-data-number result)))))
6760
6761 (defun gnus-summary-find-prev (&optional unread article)
6762   (let* ((eobp (eobp))
6763          (article (or article (gnus-summary-article-number)))
6764          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6765          result)
6766     (when (and (not eobp)
6767                (or (not gnus-summary-check-current)
6768                    (not unread)
6769                    (not (gnus-data-unread-p (car data)))))
6770       (setq data (cdr data)))
6771     (when (setq result
6772                 (if unread
6773                     (progn
6774                       (while data
6775                         (unless (memq (gnus-data-number (car data))
6776                                       (cond
6777                                        ((eq gnus-auto-goto-ignores
6778                                             'always-undownloaded)
6779                                         gnus-newsgroup-undownloaded)
6780                                        (gnus-plugged
6781                                         nil)
6782                                        ((eq gnus-auto-goto-ignores
6783                                             'unfetched)
6784                                         gnus-newsgroup-unfetched)
6785                                        ((eq gnus-auto-goto-ignores
6786                                             'undownloaded)
6787                                         gnus-newsgroup-undownloaded)))
6788                           (when (gnus-data-unread-p (car data))
6789                             (setq result (car data)
6790                                   data nil)))
6791                         (setq data (cdr data)))
6792                       result)
6793                   (car data)))
6794       (goto-char (gnus-data-pos result))
6795       (gnus-data-number result))))
6796
6797 (defun gnus-summary-find-subject (subject &optional unread backward article)
6798   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6799          (article (or article (gnus-summary-article-number)))
6800          (articles (gnus-data-list backward))
6801          (arts (gnus-data-find-list article articles))
6802          result)
6803     (when (or (not gnus-summary-check-current)
6804               (not unread)
6805               (not (gnus-data-unread-p (car arts))))
6806       (setq arts (cdr arts)))
6807     (while arts
6808       (and (or (not unread)
6809                (gnus-data-unread-p (car arts)))
6810            (vectorp (gnus-data-header (car arts)))
6811            (gnus-subject-equal
6812             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6813            (setq result (car arts)
6814                  arts nil))
6815       (setq arts (cdr arts)))
6816     (and result
6817          (goto-char (gnus-data-pos result))
6818          (gnus-data-number result))))
6819
6820 (defun gnus-summary-search-forward (&optional unread subject backward)
6821   "Search forward for an article.
6822 If UNREAD, look for unread articles.  If SUBJECT, look for
6823 articles with that subject.  If BACKWARD, search backward instead."
6824   (cond (subject (gnus-summary-find-subject subject unread backward))
6825         (backward (gnus-summary-find-prev unread))
6826         (t (gnus-summary-find-next unread))))
6827
6828 (defun gnus-recenter (&optional n)
6829   "Center point in window and redisplay frame.
6830 Also do horizontal recentering."
6831   (interactive "P")
6832   (when (and gnus-auto-center-summary
6833              (not (eq gnus-auto-center-summary 'vertical)))
6834     (gnus-horizontal-recenter))
6835   (if (fboundp 'recenter-top-bottom)
6836       (recenter-top-bottom n)
6837     (recenter n)))
6838
6839 (put 'gnus-recenter 'isearch-scroll t)
6840
6841 (defun gnus-forward-line-ignore-invisible (n)
6842   "Move N lines forward (backward if N is negative).
6843 Like forward-line, but skip over (and don't count) invisible lines."
6844   (let (done)
6845     (while (and (> n 0) (not done))
6846       ;; If the following character is currently invisible,
6847       ;; skip all characters with that same `invisible' property value.
6848       (while (gnus-invisible-p (point))
6849         (goto-char (gnus-next-char-property-change (point))))
6850       (forward-line 1)
6851       (if (eobp)
6852           (setq done t)
6853         (setq n (1- n))))
6854     (while (and (< n 0) (not done))
6855       (forward-line -1)
6856       (if (bobp) (setq done t)
6857         (setq n (1+ n))
6858         (while (and (not (bobp)) (gnus-invisible-p (1- (point))))
6859           (goto-char (gnus-previous-char-property-change (point))))))))
6860
6861 (defun gnus-summary-recenter ()
6862   "Center point in the summary window.
6863 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6864 displayed, no centering will be performed."
6865   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6866   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6867   (interactive)
6868   ;; The user has to want it.
6869   (when gnus-auto-center-summary
6870     (let* ((top (cond ((< (window-height) 4) 0)
6871                       ((< (window-height) 7) 1)
6872                       (t (if (numberp gnus-auto-center-summary)
6873                              gnus-auto-center-summary
6874                            (/ (1- (window-height)) 2)))))
6875            (height (1- (window-height)))
6876            (bottom (save-excursion
6877                      (goto-char (point-max))
6878                      (gnus-forward-line-ignore-invisible (- height))
6879                      (point)))
6880            (window (get-buffer-window (current-buffer))))
6881       (when (get-buffer-window gnus-article-buffer)
6882         ;; Only do recentering when the article buffer is displayed,
6883         ;; Set the window start to either `bottom', which is the biggest
6884         ;; possible valid number, or the second line from the top,
6885         ;; whichever is the least.
6886         (let ((top-pos (save-excursion
6887                          (gnus-forward-line-ignore-invisible (- top))
6888                          (point))))
6889           (if (> bottom top-pos)
6890               ;; Keep the second line from the top visible
6891               (set-window-start window top-pos)
6892             ;; Try to keep the bottom line visible; if it's partially
6893             ;; obscured, either scroll one more line to make it fully
6894             ;; visible, or revert to using TOP-POS.
6895             (save-excursion
6896               (goto-char (point-max))
6897               (gnus-forward-line-ignore-invisible -1)
6898               (let ((last-line-start (point)))
6899                 (goto-char bottom)
6900                 (set-window-start window (point) t)
6901                 (when (not (pos-visible-in-window-p last-line-start window))
6902                   (gnus-forward-line-ignore-invisible 1)
6903                   (set-window-start window (min (point) top-pos) t)))))))
6904       ;; Do horizontal recentering while we're at it.
6905       (when (and (get-buffer-window (current-buffer) t)
6906                  (not (eq gnus-auto-center-summary 'vertical)))
6907         (let ((selected (selected-window)))
6908           (select-window (get-buffer-window (current-buffer) t))
6909           (gnus-summary-position-point)
6910           (gnus-horizontal-recenter)
6911           (select-window selected))))))
6912
6913 (defun gnus-summary-jump-to-group (newsgroup)
6914   "Move point to NEWSGROUP in group mode buffer."
6915   ;; Keep update point of group mode buffer if visible.
6916   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6917       (save-window-excursion
6918         ;; Take care of tree window mode.
6919         (when (get-buffer-window gnus-group-buffer)
6920           (pop-to-buffer gnus-group-buffer))
6921         (gnus-group-jump-to-group newsgroup))
6922     (save-excursion
6923       ;; Take care of tree window mode.
6924       (if (get-buffer-window gnus-group-buffer 0)
6925           (pop-to-buffer gnus-group-buffer)
6926         (set-buffer gnus-group-buffer))
6927       (gnus-group-jump-to-group newsgroup))))
6928
6929 ;; This function returns a list of article numbers based on the
6930 ;; difference between the ranges of read articles in this group and
6931 ;; the range of active articles.
6932 (defun gnus-list-of-unread-articles (group)
6933   (let* ((read (gnus-info-read (gnus-get-info group)))
6934          (active (or (gnus-active group) (gnus-activate-group group)))
6935          (last (or (cdr active)
6936                    (error "Group %s couldn't be activated " group)))
6937          (bottom (if gnus-newsgroup-maximum-articles
6938                      (max (car active)
6939                           (- last gnus-newsgroup-maximum-articles -1))
6940                    (car active)))
6941          first nlast unread)
6942     ;; If none are read, then all are unread.
6943     (if (not read)
6944         (setq first bottom)
6945       ;; If the range of read articles is a single range, then the
6946       ;; first unread article is the article after the last read
6947       ;; article.  Sounds logical, doesn't it?
6948       (if (and (not (listp (cdr read)))
6949                (or (< (car read) bottom)
6950                    (progn (setq read (list read))
6951                           nil)))
6952           (setq first (max bottom (1+ (cdr read))))
6953         ;; `read' is a list of ranges.
6954         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6955                                   (caar read)))
6956                   1)
6957           (setq first bottom))
6958         (while read
6959           (when first
6960             (while (< first nlast)
6961               (setq unread (cons first unread)
6962                     first (1+ first))))
6963           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6964           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6965           (setq read (cdr read)))))
6966     ;; And add the last unread articles.
6967     (while (<= first last)
6968       (setq unread (cons first unread)
6969             first (1+ first)))
6970     ;; Return the list of unread articles.
6971     (delq 0 (nreverse unread))))
6972
6973 (defun gnus-list-of-read-articles (group)
6974   "Return a list of unread, unticked and non-dormant articles."
6975   (let* ((info (gnus-get-info group))
6976          (marked (gnus-info-marks info))
6977          (active (gnus-active group)))
6978     (and info active
6979          (gnus-list-range-difference
6980           (gnus-list-range-difference
6981            (gnus-sorted-complement
6982             (gnus-uncompress-range
6983              (if gnus-newsgroup-maximum-articles
6984                  (cons (max (car active)
6985                             (- (cdr active)
6986                                gnus-newsgroup-maximum-articles
6987                                -1))
6988                        (cdr active))
6989                active))
6990             (gnus-list-of-unread-articles group))
6991            (cdr (assq 'dormant marked)))
6992           (cdr (assq 'tick marked))))))
6993
6994 ;; This function returns a sequence of article numbers based on the
6995 ;; difference between the ranges of read articles in this group and
6996 ;; the range of active articles.
6997 (defun gnus-sequence-of-unread-articles (group)
6998   (let* ((read (gnus-info-read (gnus-get-info group)))
6999          (active (or (gnus-active group) (gnus-activate-group group)))
7000          (last (cdr active))
7001          (bottom (if gnus-newsgroup-maximum-articles
7002                      (max (car active)
7003                           (- last gnus-newsgroup-maximum-articles -1))
7004                    (car active)))
7005          first nlast unread)
7006     ;; If none are read, then all are unread.
7007     (if (not read)
7008         (setq first bottom)
7009       ;; If the range of read articles is a single range, then the
7010       ;; first unread article is the article after the last read
7011       ;; article.  Sounds logical, doesn't it?
7012       (if (and (not (listp (cdr read)))
7013                (or (< (car read) bottom)
7014                    (progn (setq read (list read))
7015                           nil)))
7016           (setq first (max bottom (1+ (cdr read))))
7017         ;; `read' is a list of ranges.
7018         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
7019                                   (caar read)))
7020                   1)
7021           (setq first bottom))
7022         (while read
7023           (when first
7024             (push (cons first nlast) unread))
7025           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
7026           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
7027           (setq read (cdr read)))))
7028     ;; And add the last unread articles.
7029     (cond ((not (and first last))
7030            nil)
7031           ((< first last)
7032            (push (cons first last) unread))
7033           ((= first last)
7034            (push first unread)))
7035     ;; Return the sequence of unread articles.
7036     (delq 0 (nreverse unread))))
7037
7038 ;; Various summary commands
7039
7040 (defun gnus-summary-select-article-buffer ()
7041   "Reconfigure windows to show the article buffer.
7042 If `gnus-widen-article-window' is set, show only the article
7043 buffer."
7044   (interactive)
7045   (if (not (gnus-buffer-live-p gnus-article-buffer))
7046       (error "There is no article buffer for this summary buffer")
7047     (unless (get-buffer-window gnus-article-buffer)
7048       (gnus-summary-show-article))
7049     (gnus-configure-windows
7050      (if gnus-widen-article-window
7051          'only-article
7052        'article)
7053      t)
7054     (select-window (get-buffer-window gnus-article-buffer))))
7055
7056 (defun gnus-summary-universal-argument (arg)
7057   "Perform any operation on all articles that are process/prefixed."
7058   (interactive "P")
7059   (let ((articles (gnus-summary-work-articles arg))
7060         func article)
7061     (if (eq
7062          (setq
7063           func
7064           (key-binding
7065            (read-key-sequence
7066             (substitute-command-keys
7067              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
7068          'undefined)
7069         (gnus-error 1 "Undefined key")
7070       (save-excursion
7071         (while articles
7072           (gnus-summary-goto-subject (setq article (pop articles)))
7073           (let (gnus-newsgroup-processable)
7074             (command-execute func))
7075           (gnus-summary-remove-process-mark article)))))
7076   (gnus-summary-position-point))
7077
7078 (defun gnus-summary-toggle-truncation (&optional arg)
7079   "Toggle truncation of summary lines.
7080 With ARG, turn line truncation on if ARG is positive."
7081   (interactive "P")
7082   (setq truncate-lines
7083         (if (null arg) (not truncate-lines)
7084           (> (prefix-numeric-value arg) 0)))
7085   (redraw-display))
7086
7087 (defun gnus-summary-find-for-reselect ()
7088   "Return the number of an article to stay on across a reselect.
7089 The current article is considered, then following articles, then previous
7090 articles.  An article is sought which is not cancelled and isn't a temporary
7091 insertion from another group.  If there's no such then return a dummy 0."
7092   (let (found)
7093     (dolist (rev '(nil t))
7094       (unless found      ; don't demand the reverse list if we don't need it
7095         (let ((data (gnus-data-find-list
7096                      (gnus-summary-article-number) (gnus-data-list rev))))
7097           (while (and data (not found))
7098             (if (and (< 0 (gnus-data-number (car data)))
7099                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
7100                 (setq found (gnus-data-number (car data))))
7101             (setq data (cdr data))))))
7102     (or found 0)))
7103
7104 (defun gnus-summary-reselect-current-group (&optional all rescan)
7105   "Exit and then reselect the current newsgroup.
7106 The prefix argument ALL means to select all articles."
7107   (interactive "P")
7108   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
7109     (error "Ephemeral groups can't be reselected"))
7110   (let ((current-subject (gnus-summary-find-for-reselect))
7111         (group gnus-newsgroup-name))
7112     (setq gnus-newsgroup-begin nil)
7113     (gnus-summary-exit nil 'leave-hidden)
7114     ;; We have to adjust the point of group mode buffer because
7115     ;; point was moved to the next unread newsgroup by exiting.
7116     (gnus-summary-jump-to-group group)
7117     (when rescan
7118       (save-excursion
7119         (gnus-group-get-new-news-this-group 1)))
7120     (gnus-group-read-group all t)
7121     (gnus-summary-goto-subject current-subject nil t)))
7122
7123 (defun gnus-summary-rescan-group (&optional all)
7124   "Exit the newsgroup, ask for new articles, and select the newsgroup."
7125   (interactive "P")
7126   (let ((config gnus-current-window-configuration))
7127     (gnus-summary-reselect-current-group all t)
7128     (gnus-configure-windows config)
7129     (when (eq config 'article)
7130       (gnus-summary-select-article))))
7131
7132 (defun gnus-summary-update-info (&optional non-destructive)
7133   (save-excursion
7134     (let ((group gnus-newsgroup-name))
7135       (when group
7136         (when gnus-newsgroup-kill-headers
7137           (setq gnus-newsgroup-killed
7138                 (gnus-compress-sequence
7139                  (gnus-sorted-union
7140                   (gnus-list-range-intersection
7141                    gnus-newsgroup-unselected gnus-newsgroup-killed)
7142                   gnus-newsgroup-unreads)
7143                  t)))
7144         (unless (listp (cdr gnus-newsgroup-killed))
7145           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
7146         (let ((headers gnus-newsgroup-headers)
7147               (ephemeral-p (gnus-ephemeral-group-p group))
7148               info)
7149           (unless ephemeral-p
7150             (setq info (copy-sequence (gnus-get-info group))
7151                   info (delq (gnus-info-params info) info)))
7152           ;; Set the new ranges of read articles.
7153           (with-current-buffer gnus-group-buffer
7154             (gnus-undo-force-boundary))
7155           (gnus-update-read-articles
7156            group (gnus-sorted-union
7157                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
7158           ;; Set the current article marks.
7159           (let ((gnus-newsgroup-scored
7160                  (if (and (not gnus-save-score)
7161                           (not non-destructive))
7162                      nil
7163                    gnus-newsgroup-scored)))
7164             (save-excursion
7165               (gnus-update-marks)))
7166           ;; Do the cross-ref thing.
7167           (when gnus-use-cross-reference
7168             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
7169           ;; Do not switch windows but change the buffer to work.
7170           (set-buffer gnus-group-buffer)
7171           (unless ephemeral-p
7172             (gnus-group-update-group
7173              group nil
7174              (equal info
7175                     (setq info (copy-sequence (gnus-get-info group))
7176                           info (delq (gnus-info-params info) info))))))))))
7177
7178 (defun gnus-summary-save-newsrc (&optional force)
7179   "Save the current number of read/marked articles in the dribble buffer.
7180 The dribble buffer will then be saved.
7181 If FORCE (the prefix), also save the .newsrc file(s)."
7182   (interactive "P")
7183   (gnus-summary-update-info t)
7184   (if force
7185       (gnus-save-newsrc-file)
7186     (gnus-dribble-save)))
7187
7188 (declare-function gnus-cache-write-active "gnus-cache" (&optional force))
7189
7190 (defun gnus-summary-exit (&optional temporary leave-hidden)
7191   "Exit reading current newsgroup, and then return to group selection mode.
7192 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
7193   (interactive)
7194   (gnus-set-global-variables)
7195   (when (gnus-buffer-live-p gnus-article-buffer)
7196     (with-current-buffer gnus-article-buffer
7197       (mm-destroy-parts gnus-article-mime-handles)
7198       ;; Set it to nil for safety reason.
7199       (setq gnus-article-mime-handle-alist nil)
7200       (setq gnus-article-mime-handles nil)))
7201   (gnus-kill-save-kill-buffer)
7202   (gnus-async-halt-prefetch)
7203   (let* ((group gnus-newsgroup-name)
7204          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
7205          (gnus-group-is-exiting-p t)
7206          (article-buffer gnus-article-buffer)
7207          (mode major-mode)
7208          (group-point nil)
7209          (buf (current-buffer))
7210          ;; `gnus-single-article-buffer' is nil buffer-locally in
7211          ;; ephemeral group of which summary buffer will be killed,
7212          ;; but the global value may be non-nil.
7213          (single-article-buffer gnus-single-article-buffer))
7214     (unless quit-config
7215       ;; Do adaptive scoring, and possibly save score files.
7216       (when gnus-newsgroup-adaptive
7217         (gnus-score-adaptive))
7218       (when gnus-use-scoring
7219         (gnus-score-save)))
7220     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
7221     (when gnus-use-cache
7222       (gnus-cache-possibly-remove-articles)
7223       (gnus-cache-save-buffers))
7224     (gnus-async-prefetch-remove-group group)
7225     (when gnus-suppress-duplicates
7226       (gnus-dup-enter-articles))
7227     (when gnus-use-trees
7228       (gnus-tree-close group))
7229     (when gnus-use-cache
7230       (gnus-cache-write-active))
7231     ;; Remove entries for this group.
7232     (nnmail-purge-split-history (gnus-group-real-name group))
7233     ;; Make all changes in this group permanent.
7234     (unless quit-config
7235       (gnus-run-hooks 'gnus-exit-group-hook)
7236       (gnus-summary-update-info))
7237     (gnus-close-group group)
7238     ;; Make sure where we were, and go to next newsgroup.
7239     (set-buffer gnus-group-buffer)
7240     (unless quit-config
7241       (gnus-group-jump-to-group group))
7242     (gnus-run-hooks 'gnus-summary-exit-hook)
7243     (unless (or quit-config
7244                 (not gnus-summary-next-group-on-exit)
7245                 ;; If this group has disappeared from the summary
7246                 ;; buffer, don't skip forwards.
7247                 (not (string= group (gnus-group-group-name))))
7248       (gnus-group-next-unread-group 1))
7249     (setq group-point (point))
7250     (if temporary
7251         nil                             ;Nothing to do.
7252       (set-buffer buf)
7253       (if (not gnus-kill-summary-on-exit)
7254           (progn
7255             (gnus-deaden-summary)
7256             (setq mode nil))
7257         (when (get-buffer gnus-article-buffer)
7258           (bury-buffer gnus-article-buffer))
7259         ;; Return to group mode buffer.
7260         (when (eq mode 'gnus-summary-mode)
7261           (gnus-kill-buffer buf)))
7262
7263       (setq gnus-current-select-method gnus-select-method)
7264       (set-buffer gnus-group-buffer)
7265       (if quit-config
7266           (gnus-handle-ephemeral-exit quit-config)
7267         (goto-char group-point)
7268         ;; If gnus-group-buffer is already displayed, make sure we also move
7269         ;; the cursor in the window that displays it.
7270         (let ((win (get-buffer-window (current-buffer) 0)))
7271           (if win (set-window-point win (point))))
7272         (unless leave-hidden
7273           (gnus-configure-windows 'group 'force)))
7274
7275       ;; If we have several article buffers, we kill them at exit.
7276       (unless single-article-buffer
7277         (when (gnus-buffer-live-p article-buffer)
7278           (with-current-buffer article-buffer
7279             ;; Don't kill sticky article buffers
7280             (unless (eq major-mode 'gnus-sticky-article-mode)
7281               (gnus-kill-buffer article-buffer)
7282               (setq gnus-article-current nil))))
7283         (gnus-kill-buffer gnus-original-article-buffer))
7284
7285       ;; Clear the current group name.
7286       (unless quit-config
7287         (setq gnus-newsgroup-name nil)))))
7288
7289 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7290 (defun gnus-summary-exit-no-update (&optional no-questions)
7291   "Quit reading current newsgroup without updating read article info."
7292   (interactive)
7293   (let* ((group gnus-newsgroup-name)
7294          (gnus-group-is-exiting-p t)
7295          (gnus-group-is-exiting-without-update-p t)
7296          (quit-config (gnus-group-quit-config group)))
7297     (when (or no-questions
7298               gnus-expert-user
7299               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7300       (gnus-async-halt-prefetch)
7301       (run-hooks 'gnus-summary-prepare-exit-hook)
7302       (when (gnus-buffer-live-p gnus-article-buffer)
7303         (with-current-buffer gnus-article-buffer
7304           (gnus-article-stop-animations)
7305           (mm-destroy-parts gnus-article-mime-handles)
7306           ;; Set it to nil for safety reason.
7307           (setq gnus-article-mime-handle-alist nil)
7308           (setq gnus-article-mime-handles nil)))
7309       ;; If we have several article buffers, we kill them at exit.
7310       (unless gnus-single-article-buffer
7311         (gnus-kill-buffer gnus-article-buffer)
7312         (gnus-kill-buffer gnus-original-article-buffer)
7313         (setq gnus-article-current nil))
7314       ;; Return to the group buffer.
7315       (gnus-configure-windows 'group 'force)
7316       (if (not gnus-kill-summary-on-exit)
7317           (gnus-deaden-summary)
7318         (gnus-close-group group)
7319         (gnus-kill-buffer gnus-summary-buffer))
7320       (unless gnus-single-article-buffer
7321         (setq gnus-article-current nil))
7322       (when gnus-use-trees
7323         (gnus-tree-close group))
7324       (gnus-async-prefetch-remove-group group)
7325       (when (get-buffer gnus-article-buffer)
7326         (bury-buffer gnus-article-buffer))
7327       ;; Clear the current group name.
7328       (setq gnus-newsgroup-name nil)
7329       (unless (gnus-ephemeral-group-p group)
7330         (gnus-group-update-group group nil t))
7331       (when (equal (gnus-group-group-name) group)
7332         (gnus-group-next-unread-group 1))
7333       (when quit-config
7334         (gnus-handle-ephemeral-exit quit-config)))))
7335
7336 (defun gnus-handle-ephemeral-exit (quit-config)
7337   "Handle movement when leaving an ephemeral group.
7338 The state which existed when entering the ephemeral is reset."
7339   (if (not (buffer-name (car quit-config)))
7340       (gnus-configure-windows 'group 'force)
7341     (set-buffer (car quit-config))
7342     (unless (eq (cdr quit-config) 'group)
7343       (setq gnus-current-select-method
7344             (gnus-find-method-for-group gnus-newsgroup-name)))
7345     (cond ((eq major-mode 'gnus-summary-mode)
7346            (gnus-set-global-variables))
7347           ((eq major-mode 'gnus-article-mode)
7348            (save-current-buffer
7349              ;; The `gnus-summary-buffer' variable may point
7350              ;; to the old summary buffer when using a single
7351              ;; article buffer.
7352              (unless (gnus-buffer-live-p gnus-summary-buffer)
7353                (set-buffer gnus-group-buffer))
7354              (set-buffer gnus-summary-buffer)
7355              (gnus-set-global-variables))))
7356     (if (or (eq (cdr quit-config) 'article)
7357             (eq (cdr quit-config) 'pick))
7358         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7359             (gnus-configure-windows 'pick 'force)
7360           (gnus-configure-windows (cdr quit-config) 'force))
7361       (gnus-configure-windows (cdr quit-config) 'force))
7362     (when (eq major-mode 'gnus-summary-mode)
7363       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7364                                                      next-unread-noselect))
7365           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7366                                   'next-noselect)
7367                               (gnus-summary-next-subject 1 nil t))
7368                              ((eq gnus-auto-select-on-ephemeral-exit
7369                                   'next-unread-noselect)
7370                               (gnus-summary-next-subject 1 t t))))
7371             ;; Hide the article buffer which displays the article different
7372             ;; from the one that the cursor points to in the summary buffer.
7373             (gnus-configure-windows 'summary 'force))
7374         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7375                (gnus-summary-next-subject 1))
7376               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7377                (gnus-summary-next-subject 1 t))))
7378       (gnus-summary-recenter)
7379       (gnus-summary-position-point))))
7380
7381 ;;; Dead summaries.
7382
7383 (defvar gnus-dead-summary-mode-map
7384   (let ((map (make-keymap)))
7385     (suppress-keymap map)
7386     (substitute-key-definition 'undefined 'gnus-summary-wake-up-the-dead map)
7387     (dolist (key '("\C-d" "\r" "\177" [delete]))
7388       (define-key map key 'gnus-summary-wake-up-the-dead))
7389     (dolist (key '("q" "Q"))
7390       (define-key map key 'bury-buffer))
7391     map))
7392
7393 (define-minor-mode gnus-dead-summary-mode
7394   "Minor mode for Gnus summary buffers."
7395   :lighter " Dead" :keymap gnus-dead-summary-mode-map
7396   (unless (derived-mode-p 'gnus-summary-mode)
7397     (setq gnus-dead-summary-mode nil)))
7398
7399 (defun gnus-deaden-summary ()
7400   "Make the current summary buffer into a dead summary buffer."
7401   ;; Kill any previous dead summary buffer.
7402   (when (and gnus-dead-summary
7403              (buffer-name gnus-dead-summary))
7404     (with-current-buffer gnus-dead-summary
7405       (when gnus-dead-summary-mode
7406         (kill-buffer (current-buffer)))))
7407   ;; Make this the current dead summary.
7408   (setq gnus-dead-summary (current-buffer))
7409   (gnus-dead-summary-mode 1)
7410   (let ((name (buffer-name)))
7411     (when (string-match "Summary" name)
7412       (rename-buffer
7413        (concat (substring name 0 (match-beginning 0)) "Dead "
7414                (substring name (match-beginning 0)))
7415        t)
7416       (bury-buffer))))
7417
7418 (defun gnus-kill-or-deaden-summary (buffer)
7419   "Kill or deaden the summary BUFFER."
7420   (save-excursion
7421     (when (and (buffer-name buffer)
7422                (not gnus-single-article-buffer))
7423       (with-current-buffer buffer
7424         (gnus-kill-buffer gnus-article-buffer)
7425         (gnus-kill-buffer gnus-original-article-buffer)))
7426     (cond
7427      ;; Kill the buffer.
7428      (gnus-kill-summary-on-exit
7429       (when (and gnus-use-trees
7430                  (gnus-buffer-exists-p buffer))
7431         (with-current-buffer buffer
7432           (gnus-tree-close gnus-newsgroup-name)))
7433       (gnus-kill-buffer buffer))
7434      ;; Deaden the buffer.
7435      ((gnus-buffer-exists-p buffer)
7436       (with-current-buffer buffer
7437         (gnus-deaden-summary))))))
7438
7439 (defun gnus-summary-wake-up-the-dead (&rest args)
7440   "Wake up the dead summary buffer."
7441   (interactive)
7442   (gnus-dead-summary-mode -1)
7443   (let ((name (buffer-name)))
7444     (when (string-match "Dead " name)
7445       (rename-buffer
7446        (concat (substring name 0 (match-beginning 0))
7447                (substring name (match-end 0)))
7448        t)))
7449   (gnus-message 3 "This dead summary is now alive again"))
7450
7451 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7452 (defun gnus-summary-describe-group (&optional force)
7453   "Describe the current newsgroup."
7454   (interactive "P")
7455   (gnus-group-describe-group force gnus-newsgroup-name))
7456
7457 (defun gnus-summary-describe-briefly ()
7458   "Describe summary mode commands briefly."
7459   (interactive)
7460   (gnus-message 6 "%s" (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")))
7461
7462 ;; Walking around group mode buffer from summary mode.
7463
7464 (defun gnus-summary-next-group (&optional no-article target-group backward)
7465   "Exit current newsgroup and then select next unread newsgroup.
7466 If prefix argument NO-ARTICLE is non-nil, no article is selected
7467 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7468 previous group instead."
7469   (interactive "P")
7470   ;; Stop pre-fetching.
7471   (gnus-async-halt-prefetch)
7472   (let ((current-group gnus-newsgroup-name)
7473         (current-buffer (current-buffer))
7474         entered)
7475     ;; First we semi-exit this group to update Xrefs and all variables.
7476     ;; We can't do a real exit, because the window conf must remain
7477     ;; the same in case the user is prompted for info, and we don't
7478     ;; want the window conf to change before that...
7479     (gnus-summary-exit t)
7480     (while (not entered)
7481       ;; Then we find what group we are supposed to enter.
7482       (set-buffer gnus-group-buffer)
7483       (gnus-group-jump-to-group current-group)
7484       (setq target-group
7485             (or target-group
7486                 (if (eq gnus-keep-same-level 'best)
7487                     (gnus-summary-best-group gnus-newsgroup-name)
7488                   (gnus-summary-search-group backward gnus-keep-same-level))))
7489       (if (not target-group)
7490           ;; There are no further groups, so we return to the group
7491           ;; buffer.
7492           (progn
7493             (gnus-message 5 "Returning to the group buffer")
7494             (setq entered t)
7495             (when (gnus-buffer-live-p current-buffer)
7496               (set-buffer current-buffer)
7497               (gnus-summary-exit))
7498             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7499         ;; We try to enter the target group.
7500         (gnus-group-jump-to-group target-group)
7501         (let ((unreads (gnus-group-group-unread)))
7502           (if (and (or (eq t unreads)
7503                        (and unreads (not (zerop unreads))))
7504                    (gnus-summary-read-group
7505                     target-group nil no-article
7506                     (and (buffer-name current-buffer) current-buffer)
7507                     nil backward))
7508               (setq entered t)
7509             (setq current-group target-group
7510                   target-group nil)))))))
7511
7512 (defun gnus-summary-prev-group (&optional no-article)
7513   "Exit current newsgroup and then select previous unread newsgroup.
7514 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7515   (interactive "P")
7516   (gnus-summary-next-group no-article nil t))
7517
7518 ;; Walking around summary lines.
7519
7520 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7521   "Go to the first subject satisfying any non-nil constraint.
7522 If UNREAD is non-nil, the article should be unread.
7523 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7524 If UNSEEN is non-nil, the article should be unseen as well as unread.
7525 Returns the article selected or nil if there are no matching articles."
7526   (interactive "P")
7527   (cond
7528    ;; Empty summary.
7529    ((null gnus-newsgroup-data)
7530     (gnus-message 3 "No articles in the group")
7531     nil)
7532    ;; Pick the first article.
7533    ((not (or unread undownloaded unseen))
7534     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7535     (gnus-data-number (car gnus-newsgroup-data)))
7536    ;; Find the first unread article.
7537    (t
7538     (let ((data gnus-newsgroup-data))
7539       (while (and data
7540                   (let ((num (gnus-data-number (car data))))
7541                     (or (memq num gnus-newsgroup-unfetched)
7542                         (not (or (and unread
7543                                       (memq num gnus-newsgroup-unreads))
7544                                  (and undownloaded
7545                                       (memq num gnus-newsgroup-undownloaded))
7546                                  (and unseen
7547                                       (memq num gnus-newsgroup-unseen)
7548                                       (memq num gnus-newsgroup-unreads)))))))
7549         (setq data (cdr data)))
7550       (prog1
7551           (if data
7552               (progn
7553                 (goto-char (gnus-data-pos (car data)))
7554                 (gnus-data-number (car data)))
7555             (gnus-message 3 "No more%s articles"
7556                           (let* ((r (when unread " unread"))
7557                                  (d (when undownloaded " undownloaded"))
7558                                  (s (when unseen " unseen"))
7559                                  (l (delq nil (list r d s))))
7560                             (cond ((= 3 (length l))
7561                                    (concat r "," d ", or" s))
7562                                   ((= 2 (length l))
7563                                    (concat (car l) ", or" (cadr l)))
7564                                   ((= 1 (length l))
7565                                    (car l))
7566                                   (t
7567                                    ""))))
7568             nil
7569             )
7570         (gnus-summary-position-point))))))
7571
7572 (defun gnus-summary-next-subject (n &optional unread dont-display)
7573   "Go to next N'th summary line.
7574 If N is negative, go to the previous N'th subject line.
7575 If UNREAD is non-nil, only unread articles are selected.
7576 The difference between N and the actual number of steps taken is
7577 returned."
7578   (interactive "p")
7579   (let ((backward (< n 0))
7580         (n (abs n)))
7581     (while (and (> n 0)
7582                 (if backward
7583                     (gnus-summary-find-prev unread)
7584                   (gnus-summary-find-next unread)))
7585       (unless (zerop (setq n (1- n)))
7586         (gnus-summary-show-thread)))
7587     (when (/= 0 n)
7588       (gnus-message 7 "No more%s articles"
7589                     (if unread " unread" "")))
7590     (unless dont-display
7591       (gnus-summary-recenter)
7592       (gnus-summary-position-point))
7593     n))
7594
7595 (defun gnus-summary-next-unread-subject (n)
7596   "Go to next N'th unread summary line."
7597   (interactive "p")
7598   (gnus-summary-next-subject n t))
7599
7600 (defun gnus-summary-prev-subject (n &optional unread)
7601   "Go to previous N'th summary line.
7602 If optional argument UNREAD is non-nil, only unread article is selected."
7603   (interactive "p")
7604   (gnus-summary-next-subject (- n) unread))
7605
7606 (defun gnus-summary-prev-unread-subject (n)
7607   "Go to previous N'th unread summary line."
7608   (interactive "p")
7609   (gnus-summary-next-subject (- n) t))
7610
7611 (defun gnus-summary-goto-subjects (articles)
7612   "Insert the subject header for ARTICLES in the current buffer."
7613   (save-excursion
7614     (dolist (article articles)
7615       (gnus-summary-goto-subject article t)))
7616   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7617   (gnus-summary-position-point))
7618
7619 (defun gnus-summary-goto-subject (article &optional force silent)
7620   "Go to the subject line of ARTICLE.
7621 If FORCE, also allow jumping to articles not currently shown."
7622   (interactive "nArticle number: ")
7623   (unless (numberp article)
7624     (error "Article %s is not a number" article))
7625   (let ((b (point))
7626         (data (gnus-data-find article)))
7627     ;; We read in the article if we have to.
7628     (and (not data)
7629          force
7630          (gnus-summary-insert-subject
7631           article
7632           (if (or (numberp force) (vectorp force)) force)
7633           t)
7634          (setq data (gnus-data-find article)))
7635     (goto-char b)
7636     (if (not data)
7637         (progn
7638           (unless silent
7639             (gnus-message 3 "Can't find article %d" article))
7640           nil)
7641       (let ((pt (gnus-data-pos data)))
7642         (goto-char pt)
7643         (gnus-summary-set-article-display-arrow pt))
7644       (gnus-summary-position-point)
7645       article)))
7646
7647 ;; Walking around summary lines with displaying articles.
7648
7649 (defun gnus-summary-expand-window (&optional arg)
7650   "Make the summary buffer take up the entire Emacs frame.
7651 Given a prefix, will force an `article' buffer configuration."
7652   (interactive "P")
7653   (if arg
7654       (gnus-configure-windows 'article 'force)
7655     (gnus-configure-windows 'summary 'force)))
7656
7657 (defun gnus-summary-display-article (article &optional all-header)
7658   "Display ARTICLE in article buffer."
7659   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7660                (with-current-buffer gnus-article-buffer
7661                  (eq major-mode 'gnus-article-mode)))
7662     (gnus-article-setup-buffer))
7663   (gnus-set-global-variables)
7664   (with-current-buffer gnus-article-buffer
7665     (setq gnus-article-charset gnus-newsgroup-charset)
7666     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7667     (mm-enable-multibyte))
7668   (if (null article)
7669       nil
7670     (prog1
7671         (if gnus-summary-display-article-function
7672             (funcall gnus-summary-display-article-function article all-header)
7673           (gnus-article-prepare article all-header))
7674       (gnus-run-hooks 'gnus-select-article-hook)
7675       (when (and gnus-current-article
7676                  (not (zerop gnus-current-article)))
7677         (gnus-summary-goto-subject gnus-current-article))
7678       (gnus-summary-recenter)
7679       (when (and gnus-use-trees gnus-show-threads)
7680         (gnus-possibly-generate-tree article)
7681         (gnus-highlight-selected-tree article))
7682       ;; Successfully display article.
7683       (gnus-article-set-window-start
7684        (cdr (assq article gnus-newsgroup-bookmarks))))))
7685
7686 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7687   "Select the current article.
7688 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7689 non-nil, the article will be re-fetched even if it already present in
7690 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7691 be displayed."
7692   ;; Make sure we are in the summary buffer to work around bbdb bug.
7693   (unless (eq major-mode 'gnus-summary-mode)
7694     (set-buffer gnus-summary-buffer))
7695   (let ((article (or article (gnus-summary-article-number)))
7696         (all-headers (not (not all-headers))) ;Must be t or nil.
7697         gnus-summary-display-article-function)
7698     (and (not pseudo)
7699          (gnus-summary-article-pseudo-p article)
7700          (error "This is a pseudo-article"))
7701     (with-current-buffer gnus-summary-buffer
7702       (if (or (and gnus-single-article-buffer
7703                    (or (null gnus-current-article)
7704                        (null gnus-article-current)
7705                        (null (get-buffer gnus-article-buffer))
7706                        (not (eq article (cdr gnus-article-current)))
7707                        (not (equal (car gnus-article-current)
7708                                    gnus-newsgroup-name))
7709                        (not (get-buffer gnus-original-article-buffer))))
7710               (and (not gnus-single-article-buffer)
7711                    (or (null gnus-current-article)
7712                        (not (get-buffer gnus-original-article-buffer))
7713                        (not (eq gnus-current-article article))))
7714               force)
7715           ;; The requested article is different from the current article.
7716           (progn
7717             (gnus-summary-display-article article all-headers)
7718             (when (gnus-buffer-live-p gnus-article-buffer)
7719               (with-current-buffer gnus-article-buffer
7720                 (if (not gnus-article-decoded-p) ;; a local variable
7721                     (mm-disable-multibyte))))
7722             (gnus-article-set-window-start
7723              (cdr (assq article gnus-newsgroup-bookmarks)))
7724             article)
7725         'old))))
7726
7727 (defun gnus-summary-force-verify-and-decrypt ()
7728   "Display buttons for signed/encrypted parts and verify/decrypt them."
7729   (interactive)
7730   (let ((mm-verify-option 'known)
7731         (mm-decrypt-option 'known)
7732         (gnus-article-emulate-mime t)
7733         (gnus-buttonized-mime-types (append (list "multipart/signed"
7734                                                   "multipart/encrypted")
7735                                             gnus-buttonized-mime-types)))
7736     (gnus-summary-select-article nil 'force)))
7737
7738 (defun gnus-summary-set-current-mark (&optional current-mark)
7739   "Obsolete function."
7740   nil)
7741
7742 (defun gnus-summary-next-article (&optional unread subject backward push)
7743   "Select the next article.
7744 If UNREAD, only unread articles are selected.
7745 If SUBJECT, only articles with SUBJECT are selected.
7746 If BACKWARD, the previous article is selected instead of the next."
7747   (interactive "P")
7748   ;; Make sure we are in the summary buffer.
7749   (unless (eq major-mode 'gnus-summary-mode)
7750     (set-buffer gnus-summary-buffer))
7751   (cond
7752    ;; Is there such an article?
7753    ((and (gnus-summary-search-forward unread subject backward)
7754          (or (gnus-summary-display-article (gnus-summary-article-number))
7755              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7756     (gnus-summary-position-point))
7757    ;; If not, we try the first unread, if that is wanted.
7758    ((and subject
7759          gnus-auto-select-same
7760          (gnus-summary-first-unread-article))
7761     (gnus-summary-position-point)
7762     (gnus-message 6 "Wrapped"))
7763    ;; Try to get next/previous article not displayed in this group.
7764    ((and gnus-auto-extend-newsgroup
7765          (not unread) (not subject))
7766     (gnus-summary-goto-article
7767      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7768      nil (count-lines (point-min) (point))))
7769    ;; Go to next/previous group.
7770    (t
7771     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7772       (gnus-summary-jump-to-group gnus-newsgroup-name))
7773     (let ((cmd (if (featurep 'xemacs)
7774                    last-command-char
7775                  last-command-event))
7776           (point
7777            (with-current-buffer gnus-group-buffer
7778              (point)))
7779           (current-summary (current-buffer))
7780           (group
7781            (if (eq gnus-keep-same-level 'best)
7782                (gnus-summary-best-group gnus-newsgroup-name)
7783              (gnus-summary-search-group backward gnus-keep-same-level))))
7784       ;; Select next unread newsgroup automagically.
7785       (cond
7786        ((or (not gnus-auto-select-next)
7787             (not cmd))
7788         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7789        ((or (eq gnus-auto-select-next 'quietly)
7790             (and (eq gnus-auto-select-next 'slightly-quietly)
7791                  push)
7792             (and (eq gnus-auto-select-next 'almost-quietly)
7793                  (gnus-summary-last-article-p)))
7794         ;; Select quietly.
7795         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7796             (gnus-summary-exit)
7797           (gnus-message 7 "No more%s articles (%s)..."
7798                         (if unread " unread" "")
7799                         (if group (concat "selecting " group)
7800                           "exiting"))
7801           (gnus-summary-next-group nil group backward)))
7802        (t
7803         (when (gnus-key-press-event-p last-input-event)
7804           ;; Somehow or other, we may now have selected a different
7805           ;; window.  Make point go back to the summary buffer.
7806           (when (eq current-summary (current-buffer))
7807             ;; FIXME: This burps when get-buffer-window returns nil.
7808             (select-window (get-buffer-window current-summary 0)))
7809           (gnus-summary-walk-group-buffer
7810            gnus-newsgroup-name cmd unread backward point))))))))
7811
7812 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7813   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7814                       (?\C-p (gnus-group-prev-unread-group 1))))
7815         (cursor-in-echo-area t)
7816         keve key group ended prompt)
7817     (with-current-buffer gnus-group-buffer
7818       (goto-char start)
7819       (setq group
7820             (if (eq gnus-keep-same-level 'best)
7821                 (gnus-summary-best-group gnus-newsgroup-name)
7822               (gnus-summary-search-group backward gnus-keep-same-level))))
7823     (while (not ended)
7824       (setq prompt
7825             (format
7826              "No more%s articles%s " (if unread " unread" "")
7827              (if (and group
7828                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7829                  (format " (Type %s for %s [%s])"
7830                          (single-key-description cmd)
7831                          (gnus-group-decoded-name group)
7832                          (gnus-group-unread group))
7833                (format " (Type %s to exit %s)"
7834                        (single-key-description cmd)
7835                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7836       ;; Confirm auto selection.
7837       (setq key (car (setq keve (gnus-read-event-char prompt)))
7838             ended t)
7839       (cond
7840        ((assq key keystrokes)
7841         (let ((obuf (current-buffer)))
7842           (switch-to-buffer gnus-group-buffer)
7843           (when group
7844             (gnus-group-jump-to-group group))
7845           (eval (cadr (assq key keystrokes)))
7846           (setq group (gnus-group-group-name))
7847           (switch-to-buffer obuf))
7848         (setq ended nil))
7849        ((equal key cmd)
7850         (if (or (not group)
7851                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7852             (gnus-summary-exit)
7853           (gnus-summary-next-group nil group backward)))
7854        (t
7855         (push (cdr keve) unread-command-events))))))
7856
7857 (defun gnus-summary-next-unread-article ()
7858   "Select unread article after current one."
7859   (interactive)
7860   (gnus-summary-next-article
7861    (or (not (eq gnus-summary-goto-unread 'never))
7862        (gnus-summary-last-article-p (gnus-summary-article-number)))
7863    (and gnus-auto-select-same
7864         (gnus-summary-article-subject))))
7865
7866 (defun gnus-summary-prev-article (&optional unread subject)
7867   "Select the article before the current one.
7868 If UNREAD is non-nil, only unread articles are selected."
7869   (interactive "P")
7870   (gnus-summary-next-article unread subject t))
7871
7872 (defun gnus-summary-prev-unread-article ()
7873   "Select unread article before current one."
7874   (interactive)
7875   (gnus-summary-prev-article
7876    (or (not (eq gnus-summary-goto-unread 'never))
7877        (gnus-summary-first-article-p (gnus-summary-article-number)))
7878    (and gnus-auto-select-same
7879         (gnus-summary-article-subject))))
7880
7881 (defun gnus-summary-next-page (&optional lines circular stop)
7882   "Show next page of the selected article.
7883 If at the end of the current article, select the next article.
7884 LINES says how many lines should be scrolled up.
7885
7886 If CIRCULAR is non-nil, go to the start of the article instead of
7887 selecting the next article when reaching the end of the current
7888 article.
7889
7890 If STOP is non-nil, just stop when reaching the end of the message.
7891
7892 Also see the variable `gnus-article-skip-boring'."
7893   (interactive "P")
7894   (setq gnus-summary-buffer (current-buffer))
7895   (gnus-set-global-variables)
7896   (let ((article (gnus-summary-article-number))
7897         (article-window (get-buffer-window gnus-article-buffer t))
7898         endp)
7899     ;; If the buffer is empty, we have no article.
7900     (unless article
7901       (error "No article to select"))
7902     (gnus-configure-windows 'article)
7903     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7904         (if (and (eq gnus-summary-goto-unread 'never)
7905                  (not (gnus-summary-last-article-p article)))
7906             (gnus-summary-next-article)
7907           (gnus-summary-next-unread-article))
7908       (if (or (null gnus-current-article)
7909               (null gnus-article-current)
7910               (/= article (cdr gnus-article-current))
7911               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7912           ;; Selected subject is different from current article's.
7913           (gnus-summary-display-article article)
7914         (when article-window
7915           (gnus-eval-in-buffer-window gnus-article-buffer
7916             (setq endp (or (gnus-article-next-page lines)
7917                            (gnus-article-only-boring-p))))
7918           (when endp
7919             (cond ((or stop gnus-summary-stop-at-end-of-message)
7920                    (gnus-message 3 "End of message"))
7921                   (circular
7922                    (gnus-summary-beginning-of-article))
7923                   (lines
7924                    (gnus-message 3 "End of message"))
7925                   ((null lines)
7926                    (if (and (eq gnus-summary-goto-unread 'never)
7927                             (not (gnus-summary-last-article-p article)))
7928                        (gnus-summary-next-article)
7929                      (gnus-summary-next-unread-article))))))))
7930     (gnus-summary-recenter)
7931     (gnus-summary-position-point)))
7932
7933 (defun gnus-summary-prev-page (&optional lines move)
7934   "Show previous page of selected article.
7935 Argument LINES specifies lines to be scrolled down.
7936 If MOVE, move to the previous unread article if point is at
7937 the beginning of the buffer."
7938   (interactive "P")
7939   (let ((article (gnus-summary-article-number))
7940         (article-window (get-buffer-window gnus-article-buffer t))
7941         endp)
7942     (gnus-configure-windows 'article)
7943     (if (or (null gnus-current-article)
7944             (null gnus-article-current)
7945             (/= article (cdr gnus-article-current))
7946             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7947         ;; Selected subject is different from current article's.
7948         (gnus-summary-display-article article)
7949       (gnus-summary-recenter)
7950       (when article-window
7951         (gnus-eval-in-buffer-window gnus-article-buffer
7952           (setq endp (gnus-article-prev-page lines)))
7953         (when (and move endp)
7954           (cond (lines
7955                  (gnus-message 3 "Beginning of message"))
7956                 ((null lines)
7957                  (if (and (eq gnus-summary-goto-unread 'never)
7958                           (not (gnus-summary-first-article-p article)))
7959                      (gnus-summary-prev-article)
7960                    (gnus-summary-prev-unread-article))))))))
7961   (gnus-summary-position-point))
7962
7963 (defun gnus-summary-prev-page-or-article (&optional lines)
7964   "Show previous page of selected article.
7965 Argument LINES specifies lines to be scrolled down.
7966 If at the beginning of the article, go to the next article."
7967   (interactive "P")
7968   (gnus-summary-prev-page lines t))
7969
7970 (defun gnus-summary-scroll-up (lines)
7971   "Scroll up (or down) one line current article.
7972 Argument LINES specifies lines to be scrolled up (or down if negative).
7973 If no article is selected, then the current article will be selected first."
7974   (interactive "p")
7975   (gnus-configure-windows 'article)
7976   (gnus-summary-show-thread)
7977   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7978     (gnus-eval-in-buffer-window gnus-article-buffer
7979       (cond ((> lines 0)
7980              (when (gnus-article-next-page lines)
7981                (gnus-message 3 "End of message")))
7982             ((< lines 0)
7983              (gnus-article-prev-page (- lines))))))
7984   (gnus-summary-recenter)
7985   (gnus-summary-position-point))
7986
7987 (defun gnus-summary-scroll-down (lines)
7988   "Scroll down (or up) one line current article.
7989 Argument LINES specifies lines to be scrolled down (or up if negative).
7990 If no article is selected, then the current article will be selected first."
7991   (interactive "p")
7992   (gnus-summary-scroll-up (- lines)))
7993
7994 (defun gnus-summary-next-same-subject ()
7995   "Select next article which has the same subject as current one."
7996   (interactive)
7997   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7998
7999 (defun gnus-summary-prev-same-subject ()
8000   "Select previous article which has the same subject as current one."
8001   (interactive)
8002   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
8003
8004 (defun gnus-summary-next-unread-same-subject ()
8005   "Select next unread article which has the same subject as current one."
8006   (interactive)
8007   (gnus-summary-next-article t (gnus-summary-article-subject)))
8008
8009 (defun gnus-summary-prev-unread-same-subject ()
8010   "Select previous unread article which has the same subject as current one."
8011   (interactive)
8012   (gnus-summary-prev-article t (gnus-summary-article-subject)))
8013
8014 (defun gnus-summary-first-unread-article ()
8015   "Select the first unread article.
8016 Return nil if there are no unread articles."
8017   (interactive)
8018   (prog1
8019       (when (gnus-summary-first-subject t)
8020         (gnus-summary-show-thread)
8021         (gnus-summary-first-subject t)
8022         (gnus-summary-display-article (gnus-summary-article-number)))
8023     (gnus-summary-position-point)))
8024
8025 (defun gnus-summary-first-unread-subject ()
8026   "Place the point on the subject line of the first unread article.
8027 Return nil if there are no unread articles."
8028   (interactive)
8029   (prog1
8030       (when (gnus-summary-first-subject t)
8031         (gnus-summary-show-thread)
8032         (gnus-summary-first-subject t))
8033     (gnus-summary-position-point)))
8034
8035 (defun gnus-summary-first-unseen-subject ()
8036   "Place the point on the subject line of the first unseen article.
8037 Return nil if there are no unseen articles."
8038   (interactive)
8039   (prog1
8040       (when (gnus-summary-first-subject nil nil t)
8041         (gnus-summary-show-thread)
8042         (gnus-summary-first-subject nil nil t))
8043     (gnus-summary-position-point)))
8044
8045 (defun gnus-summary-first-unseen-or-unread-subject ()
8046   "Place the point on the subject line of the first unseen and unread article.
8047 If all article have been seen, on the subject line of the first unread
8048 article."
8049   (interactive)
8050   (prog1
8051       (unless (when (gnus-summary-first-subject nil nil t)
8052                 (gnus-summary-show-thread)
8053                 (gnus-summary-first-subject nil nil t))
8054         (when (gnus-summary-first-subject t)
8055           (gnus-summary-show-thread)
8056           (gnus-summary-first-subject t)))
8057     (gnus-summary-position-point)))
8058
8059 (defun gnus-summary-first-article ()
8060   "Select the first article.
8061 Return nil if there are no articles."
8062   (interactive)
8063   (prog1
8064       (when (gnus-summary-first-subject)
8065         (gnus-summary-show-thread)
8066         (gnus-summary-first-subject)
8067         (gnus-summary-display-article (gnus-summary-article-number)))
8068     (gnus-summary-position-point)))
8069
8070 (defun gnus-summary-best-unread-article (&optional arg)
8071   "Select the unread article with the highest score.
8072 If given a prefix argument, select the next unread article that has a
8073 score higher than the default score."
8074   (interactive "P")
8075   (let ((article (if arg
8076                      (gnus-summary-better-unread-subject)
8077                    (gnus-summary-best-unread-subject))))
8078     (if article
8079         (gnus-summary-goto-article article)
8080       (error "No unread articles"))))
8081
8082 (defun gnus-summary-best-unread-subject ()
8083   "Select the unread subject with the highest score."
8084   (interactive)
8085   (let ((best -1000000)
8086         (data gnus-newsgroup-data)
8087         article score)
8088     (while data
8089       (and (gnus-data-unread-p (car data))
8090            (> (setq score
8091                     (gnus-summary-article-score (gnus-data-number (car data))))
8092               best)
8093            (setq best score
8094                  article (gnus-data-number (car data))))
8095       (setq data (cdr data)))
8096     (when article
8097       (gnus-summary-goto-subject article))
8098     (gnus-summary-position-point)
8099     article))
8100
8101 (defun gnus-summary-better-unread-subject ()
8102   "Select the first unread subject that has a score over the default score."
8103   (interactive)
8104   (let ((data gnus-newsgroup-data)
8105         article score)
8106     (while (and (setq article (gnus-data-number (car data)))
8107                 (or (gnus-data-read-p (car data))
8108                     (not (> (gnus-summary-article-score article)
8109                             gnus-summary-default-score))))
8110       (setq data (cdr data)))
8111     (when article
8112       (gnus-summary-goto-subject article))
8113     (gnus-summary-position-point)
8114     article))
8115
8116 (defun gnus-summary-last-subject ()
8117   "Go to the last displayed subject line in the group."
8118   (let ((article (gnus-data-number (car (gnus-data-list t)))))
8119     (when article
8120       (gnus-summary-goto-subject article))))
8121
8122 (defun gnus-summary-goto-article (article &optional all-headers force)
8123   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
8124 If ALL-HEADERS is non-nil, no header lines are hidden.
8125 If FORCE, go to the article even if it isn't displayed.  If FORCE
8126 is a number, it is the line the article is to be displayed on."
8127   (interactive
8128    (list
8129     (gnus-completing-read
8130      "Article number or Message-ID"
8131      (mapcar 'int-to-string gnus-newsgroup-limit))
8132     current-prefix-arg
8133     t))
8134   (prog1
8135       (if (and (stringp article)
8136                (string-match "@\\|%40" article))
8137           (gnus-summary-refer-article article)
8138         (when (stringp article)
8139           (setq article (string-to-number article)))
8140         (if (gnus-summary-goto-subject article force)
8141             (gnus-summary-display-article article all-headers)
8142           (gnus-message 4 "Couldn't go to article %s" article) nil))
8143     (gnus-summary-position-point)))
8144
8145 (defun gnus-summary-goto-last-article ()
8146   "Go to the previously read article."
8147   (interactive)
8148   (prog1
8149       (when gnus-last-article
8150         (gnus-summary-goto-article gnus-last-article nil t))
8151     (gnus-summary-position-point)))
8152
8153 (defun gnus-summary-pop-article (number)
8154   "Pop one article off the history and go to the previous.
8155 NUMBER articles will be popped off."
8156   (interactive "p")
8157   (let (to)
8158     (setq gnus-newsgroup-history
8159           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
8160     (if to
8161         (gnus-summary-goto-article (car to) nil t)
8162       (error "Article history empty")))
8163   (gnus-summary-position-point))
8164
8165 ;; Summary commands and functions for limiting the summary buffer.
8166
8167 (defun gnus-summary-limit-to-articles (n)
8168   "Limit the summary buffer to the next N articles.
8169 If not given a prefix, use the process marked articles instead."
8170   (interactive "P")
8171   (prog1
8172       (let ((articles (gnus-summary-work-articles n)))
8173         (setq gnus-newsgroup-processable nil)
8174         (gnus-summary-limit articles))
8175     (gnus-summary-position-point)))
8176
8177 (defun gnus-summary-pop-limit (&optional total)
8178   "Restore the previous limit.
8179 If given a prefix, remove all limits."
8180   (interactive "P")
8181   (when total
8182     (setq gnus-newsgroup-limits
8183           (list (mapcar (lambda (h) (mail-header-number h))
8184                         gnus-newsgroup-headers))))
8185   (unless gnus-newsgroup-limits
8186     (error "No limit to pop"))
8187   (prog1
8188       (gnus-summary-limit nil 'pop)
8189     (gnus-summary-position-point)))
8190
8191 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
8192   "Limit the summary buffer to articles that have subjects that match a regexp.
8193 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
8194   (interactive
8195    (list (read-string (if current-prefix-arg
8196                           "Exclude subject (regexp): "
8197                         "Limit to subject (regexp): "))
8198          nil current-prefix-arg))
8199   (unless header
8200     (setq header "subject"))
8201   (when (not (equal "" subject))
8202     (prog1
8203         (let ((articles (gnus-summary-find-matching
8204                          (or header "subject") subject 'all nil nil
8205                          not-matching)))
8206           (unless articles
8207             (error "Found no matches for \"%s\"" subject))
8208           (gnus-summary-limit articles))
8209       (gnus-summary-position-point))))
8210
8211 (defun gnus-summary-limit-to-author (from &optional not-matching)
8212   "Limit the summary buffer to articles that have authors that match a regexp.
8213 If NOT-MATCHING, excluding articles that have authors that match a regexp."
8214   (interactive
8215    (list (read-string (if current-prefix-arg
8216                           "Exclude author (regexp): "
8217                         "Limit to author (regexp): "))
8218          current-prefix-arg))
8219   (gnus-summary-limit-to-subject from "from" not-matching))
8220
8221 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8222   "Limit the summary buffer to articles with the given RECIPIENT.
8223
8224 If NOT-MATCHING, exclude RECIPIENT.
8225
8226 To and Cc headers are checked.  You need to include them in
8227 `nnmail-extra-headers'."
8228   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8229   (interactive
8230    (list (read-string (format "%s recipient (regexp): "
8231                               (if current-prefix-arg "Exclude" "Limit to")))
8232          current-prefix-arg))
8233   (when (not (equal "" recipient))
8234     (prog1 (let* ((to
8235                    (if (memq 'To nnmail-extra-headers)
8236                        (gnus-summary-find-matching
8237                         (cons 'extra 'To) recipient 'all nil nil
8238                         not-matching)
8239                      (gnus-message
8240                       1 "`To' isn't present in `nnmail-extra-headers'")
8241                      (sit-for 1)
8242                      nil))
8243                   (cc
8244                    (if (memq 'Cc nnmail-extra-headers)
8245                        (gnus-summary-find-matching
8246                         (cons 'extra 'Cc) recipient 'all nil nil
8247                         not-matching)
8248                      (gnus-message
8249                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8250                      (sit-for 1)
8251                      nil))
8252                   (articles
8253                    (if not-matching
8254                        ;; We need the numbers that are in both lists:
8255                        (mapcar (lambda (a)
8256                                  (and (memq a to) a))
8257                                cc)
8258                      (nconc to cc))))
8259              (unless articles
8260                (error "Found no matches for \"%s\"" recipient))
8261              (gnus-summary-limit articles))
8262       (gnus-summary-position-point))))
8263
8264 (defun gnus-summary-limit-to-address (address &optional not-matching)
8265   "Limit the summary buffer to articles with the given ADDRESS.
8266
8267 If NOT-MATCHING, exclude ADDRESS.
8268
8269 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8270 in `nnmail-extra-headers'."
8271   (interactive
8272    (list (read-string (format "%s address (regexp): "
8273                               (if current-prefix-arg "Exclude" "Limit to")))
8274          current-prefix-arg))
8275   (when (not (equal "" address))
8276     (prog1 (let* ((to
8277                    (if (memq 'To nnmail-extra-headers)
8278                        (gnus-summary-find-matching
8279                         (cons 'extra 'To) address 'all nil nil
8280                         not-matching)
8281                      (gnus-message
8282                       1 "`To' isn't present in `nnmail-extra-headers'")
8283                      (sit-for 1)
8284                      t))
8285                   (cc
8286                    (if (memq 'Cc nnmail-extra-headers)
8287                        (gnus-summary-find-matching
8288                         (cons 'extra 'Cc) address 'all nil nil
8289                         not-matching)
8290                      (gnus-message
8291                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8292                      (sit-for 1)
8293                      t))
8294                   (from
8295                    (gnus-summary-find-matching "from" address
8296                                                'all nil nil not-matching))
8297                   (articles
8298                    (if not-matching
8299                        ;; We need the numbers that are in all lists:
8300                        (if (eq cc t)
8301                            (if (eq to t)
8302                                from
8303                              (mapcar (lambda (a) (car (memq a from))) to))
8304                          (if (eq to t)
8305                              (mapcar (lambda (a) (car (memq a from))) cc)
8306                            (mapcar (lambda (a) (car (memq a from)))
8307                                    (mapcar (lambda (a) (car (memq a to)))
8308                                            cc))))
8309                      (nconc (if (eq to t) nil to)
8310                             (if (eq cc t) nil cc)
8311                             from))))
8312              (unless articles
8313                (error "Found no matches for \"%s\"" address))
8314              (gnus-summary-limit articles))
8315       (gnus-summary-position-point))))
8316
8317 (defun gnus-summary-limit-strange-charsets-predicate (header)
8318   (when (fboundp 'char-charset)
8319     (let ((string (concat (mail-header-subject header)
8320                           (mail-header-from header)))
8321           charset found)
8322       (dotimes (i (1- (length string)))
8323         (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8324         (when (string-match "unicode\\|big\\|japanese" charset)
8325           (setq found t)))
8326       found)))
8327
8328 (defun gnus-summary-limit-to-predicate (predicate)
8329   "Limit to articles where PREDICATE returns non-nil.
8330 PREDICATE will be called with the header structures of the
8331 articles."
8332   (let ((articles nil)
8333         (case-fold-search t))
8334     (dolist (header gnus-newsgroup-headers)
8335       (when (funcall predicate header)
8336         (push (mail-header-number header) articles)))
8337     (gnus-summary-limit (nreverse articles))))
8338
8339 (defun gnus-summary-limit-to-age (age &optional younger-p)
8340   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8341 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8342 articles that are younger than AGE days."
8343   (interactive
8344    (let ((younger current-prefix-arg)
8345          (days-got nil)
8346          days)
8347      (while (not days-got)
8348        (setq days (if younger
8349                       (read-string "Limit to articles younger than (in days, older when negative): ")
8350                     (read-string
8351                      "Limit to articles older than (in days, younger when negative): ")))
8352        (when (> (length days) 0)
8353          (setq days (read days)))
8354        (if (numberp days)
8355            (progn
8356              (setq days-got t)
8357              (when (< days 0)
8358                (setq younger (not younger))
8359                (setq days (* days -1))))
8360          (message "Please enter a number.")
8361          (sleep-for 1)))
8362      (list days younger)))
8363   (prog1
8364       (let ((data gnus-newsgroup-data)
8365             (cutoff (days-to-time age))
8366             articles d date is-younger)
8367         (while (setq d (pop data))
8368           (when (and (vectorp (gnus-data-header d))
8369                      (setq date (mail-header-date (gnus-data-header d))))
8370             (setq is-younger (time-less-p
8371                               (time-since (gnus-date-get-time date))
8372                               cutoff))
8373             (when (if younger-p
8374                       is-younger
8375                     (not is-younger))
8376               (push (gnus-data-number d) articles))))
8377         (gnus-summary-limit (nreverse articles)))
8378     (gnus-summary-position-point)))
8379
8380 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8381   "Limit the summary buffer to articles that match an 'extra' header."
8382   (interactive
8383    (let ((header
8384           (intern
8385            (gnus-completing-read
8386             (if current-prefix-arg
8387                 "Exclude extra header"
8388               "Limit extra header")
8389             (mapcar 'symbol-name gnus-extra-headers)
8390             t nil nil
8391             (symbol-name (car gnus-extra-headers))))))
8392      (list header
8393            (read-string (format "%s header %s (regexp): "
8394                                 (if current-prefix-arg "Exclude" "Limit to")
8395                                 header))
8396            current-prefix-arg)))
8397   (when (not (equal "" regexp))
8398     (prog1
8399         (let ((articles (gnus-summary-find-matching
8400                          (cons 'extra header) regexp 'all nil nil
8401                          not-matching)))
8402           (unless articles
8403             (error "Found no matches for \"%s\"" regexp))
8404           (gnus-summary-limit articles))
8405       (gnus-summary-position-point))))
8406
8407 (defun gnus-summary-limit-to-display-predicate ()
8408   "Limit the summary buffer to the predicated in the `display' group parameter."
8409   (interactive)
8410   (unless gnus-newsgroup-display
8411     (error "There is no `display' group parameter"))
8412   (let (articles)
8413     (dolist (gnus-number gnus-newsgroup-articles)
8414       (when (funcall gnus-newsgroup-display)
8415         (push gnus-number articles)))
8416     (gnus-summary-limit articles))
8417   (gnus-summary-position-point))
8418
8419 (defun gnus-summary-limit-to-unread (&optional all)
8420   "Limit the summary buffer to articles that are not marked as read.
8421 If ALL is non-nil, limit strictly to unread articles."
8422   (interactive "P")
8423   (if all
8424       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8425     (gnus-summary-limit-to-marks
8426      ;; Concat all the marks that say that an article is read and have
8427      ;; those removed.
8428      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8429            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8430            gnus-low-score-mark gnus-expirable-mark
8431            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8432            gnus-duplicate-mark)
8433      'reverse)))
8434
8435 (defun gnus-summary-limit-to-headers (match &optional reverse)
8436   "Limit the summary buffer to articles that have headers that match MATCH.
8437 If REVERSE (the prefix), limit to articles that don't match."
8438   (interactive "sMatch headers (regexp): \nP")
8439   (gnus-summary-limit-to-bodies match reverse t))
8440
8441 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8442   "Limit the summary buffer to articles that have bodies that match MATCH.
8443 If REVERSE (the prefix), limit to articles that don't match."
8444   (interactive "sMatch body (regexp): \nP")
8445   (let ((articles nil)
8446         (gnus-select-article-hook nil)  ;Disable hook.
8447         (gnus-article-prepare-hook nil)
8448         (gnus-use-article-prefetch nil)
8449         (gnus-keep-backlog nil)
8450         (gnus-break-pages nil)
8451         (gnus-summary-display-arrow nil)
8452         (gnus-updated-mode-lines nil)
8453         (gnus-auto-center-summary nil)
8454         (gnus-display-mime-function nil))
8455     (dolist (data gnus-newsgroup-data)
8456       (let (gnus-mark-article-hook)
8457         (gnus-summary-select-article t t nil (gnus-data-number data)))
8458       (with-current-buffer gnus-article-buffer
8459         (article-goto-body)
8460         (let* ((case-fold-search t)
8461                (found (if headersp
8462                           (re-search-backward match nil t)
8463                         (re-search-forward match nil t))))
8464           (when (or (and found
8465                          (not reverse))
8466                     (and (not found)
8467                          reverse))
8468             (push (gnus-data-number data) articles)))))
8469     (if (not articles)
8470         (message "No messages matched")
8471       (gnus-summary-limit articles)))
8472   (gnus-summary-position-point))
8473
8474 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8475   "Limit the summary buffer to articles that aren't part on any thread.
8476 If THREADSP (the prefix), limit to articles that are in threads."
8477   (interactive "P")
8478   (let ((articles nil)
8479         thread-articles
8480         threads)
8481     (dolist (thread gnus-newsgroup-threads)
8482       (if (stringp (car thread))
8483           (dolist (thread (cdr thread))
8484             (push thread threads))
8485         (push thread threads)))
8486     (dolist (thread threads)
8487       (setq thread-articles (gnus-articles-in-thread thread))
8488       (when (or (and threadsp
8489                      (> (length thread-articles) 1))
8490                 (and (not threadsp)
8491                      (= (length thread-articles) 1)))
8492         (setq articles (nconc thread-articles articles))))
8493     (if (not articles)
8494         (message "No messages matched")
8495       (gnus-summary-limit articles))
8496     (gnus-summary-position-point)))
8497
8498 (defun gnus-summary-limit-to-replied (&optional unreplied)
8499   "Limit the summary buffer to replied articles.
8500 If UNREPLIED (the prefix), limit to unreplied articles."
8501   (interactive "P")
8502   (if unreplied
8503       (gnus-summary-limit
8504        (gnus-set-difference gnus-newsgroup-articles
8505         gnus-newsgroup-replied))
8506     (gnus-summary-limit gnus-newsgroup-replied))
8507   (gnus-summary-position-point))
8508
8509 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8510   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8511 If REVERSE, limit the summary buffer to articles that are marked
8512 with MARKS.  MARKS can either be a string of marks or a list of marks.
8513 Returns how many articles were removed."
8514   (interactive "sMarks: ")
8515   (gnus-summary-limit-to-marks marks t))
8516
8517 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8518   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8519 If REVERSE (the prefix), limit the summary buffer to articles that are
8520 not marked with MARKS.  MARKS can either be a string of marks or a
8521 list of marks.
8522 Returns how many articles were removed."
8523   (interactive "sMarks: \nP")
8524   (prog1
8525       (let ((data gnus-newsgroup-data)
8526             (marks (if (listp marks) marks
8527                      (append marks nil))) ; Transform to list.
8528             articles)
8529         (while data
8530           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8531                   (memq (gnus-data-mark (car data)) marks))
8532             (push (gnus-data-number (car data)) articles))
8533           (setq data (cdr data)))
8534         (gnus-summary-limit articles))
8535     (gnus-summary-position-point)))
8536
8537 (defun gnus-summary-limit-to-score (score)
8538   "Limit to articles with score at or above SCORE."
8539   (interactive "NLimit to articles with score of at least: ")
8540   (let ((data gnus-newsgroup-data)
8541         articles)
8542     (while data
8543       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8544                 score)
8545         (push (gnus-data-number (car data)) articles))
8546       (setq data (cdr data)))
8547     (prog1
8548         (gnus-summary-limit articles)
8549       (gnus-summary-position-point))))
8550
8551 (defun gnus-summary-limit-to-unseen ()
8552   "Limit to unseen articles."
8553   (interactive)
8554   (prog1
8555       (gnus-summary-limit gnus-newsgroup-unseen)
8556     (gnus-summary-position-point)))
8557
8558 (defun gnus-summary-limit-include-thread (id)
8559   "Display all the hidden articles that is in the thread with ID in it.
8560 When called interactively, ID is the Message-ID of the current
8561 article."
8562   (interactive (list (mail-header-id (gnus-summary-article-header))))
8563   (let ((articles (gnus-articles-in-thread
8564                    (gnus-id-to-thread (gnus-root-id id))))
8565         ;;we REALLY want the whole thread---this prevents cut-threads
8566         ;;from removing the thread we want to include.
8567         (gnus-fetch-old-headers nil)
8568         (gnus-build-sparse-threads nil))
8569     (prog1
8570         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8571       (gnus-summary-limit-include-matching-articles
8572        "subject"
8573        (regexp-quote (gnus-simplify-subject-re
8574                       (mail-header-subject (gnus-id-to-header id)))))
8575       (gnus-summary-position-point))))
8576
8577 (defun gnus-summary-limit-include-matching-articles (header regexp)
8578   "Display all the hidden articles that have HEADERs that match REGEXP."
8579   (interactive (list (read-string "Match on header: ")
8580                      (read-string "Regexp: ")))
8581   (let ((articles (gnus-find-matching-articles header regexp)))
8582     (prog1
8583         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8584       (gnus-summary-position-point))))
8585
8586 (defun gnus-summary-insert-dormant-articles ()
8587   "Insert all the dormant articles for this group into the current buffer."
8588   (interactive)
8589   (let ((gnus-verbose (max 6 gnus-verbose)))
8590     (if (not gnus-newsgroup-dormant)
8591         (gnus-message 3 "No dormant articles for this group")
8592       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8593
8594 (defun gnus-summary-insert-ticked-articles ()
8595   "Insert ticked articles for this group into the current buffer."
8596   (interactive)
8597   (let ((gnus-verbose (max 6 gnus-verbose)))
8598     (if (not gnus-newsgroup-marked)
8599         (gnus-message 3 "No ticked articles for this group")
8600       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8601
8602 (defun gnus-summary-limit-include-dormant ()
8603   "Display all the hidden articles that are marked as dormant.
8604 Note that this command only works on a subset of the articles currently
8605 fetched for this group."
8606   (interactive)
8607   (unless gnus-newsgroup-dormant
8608     (error "There are no dormant articles in this group"))
8609   (prog1
8610       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8611     (gnus-summary-position-point)))
8612
8613 (defun gnus-summary-include-articles (articles)
8614   "Fetch the headers for ARTICLES and then display the summary lines."
8615   (let ((gnus-inhibit-demon t)
8616         (gnus-agent nil)
8617         (gnus-read-all-available-headers t))
8618     (setq gnus-newsgroup-headers
8619           (gnus-merge
8620            'list gnus-newsgroup-headers
8621            (gnus-fetch-headers articles nil t)
8622            'gnus-article-sort-by-number))
8623     (gnus-summary-limit (append articles gnus-newsgroup-limit))))
8624
8625 (defun gnus-summary-limit-exclude-dormant ()
8626   "Hide all dormant articles."
8627   (interactive)
8628   (prog1
8629       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8630     (gnus-summary-position-point)))
8631
8632 (defun gnus-summary-limit-exclude-childless-dormant ()
8633   "Hide all dormant articles that have no children."
8634   (interactive)
8635   (let ((data (gnus-data-list t))
8636         articles d children)
8637     ;; Find all articles that are either not dormant or have
8638     ;; children.
8639     (while (setq d (pop data))
8640       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8641                 (and (setq children
8642                            (gnus-article-children (gnus-data-number d)))
8643                      (let (found)
8644                        (while children
8645                          (when (memq (car children) articles)
8646                            (setq children nil
8647                                  found t))
8648                          (pop children))
8649                        found)))
8650         (push (gnus-data-number d) articles)))
8651     ;; Do the limiting.
8652     (prog1
8653         (gnus-summary-limit articles)
8654       (gnus-summary-position-point))))
8655
8656 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8657   "Mark all unread excluded articles as read.
8658 If ALL, mark even excluded ticked and dormants as read."
8659   (interactive "P")
8660   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8661   (let ((articles (gnus-sorted-ndifference
8662                    (sort
8663                     (mapcar (lambda (h) (mail-header-number h))
8664                             gnus-newsgroup-headers)
8665                     '<)
8666                    gnus-newsgroup-limit))
8667         article)
8668     (setq gnus-newsgroup-unreads
8669           (gnus-sorted-intersection gnus-newsgroup-unreads
8670                                     gnus-newsgroup-limit))
8671     (if all
8672         (setq gnus-newsgroup-dormant nil
8673               gnus-newsgroup-marked nil
8674               gnus-newsgroup-reads
8675               (nconc
8676                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8677                gnus-newsgroup-reads))
8678       (while (setq article (pop articles))
8679         (unless (or (memq article gnus-newsgroup-dormant)
8680                     (memq article gnus-newsgroup-marked))
8681           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8682
8683 (defun gnus-summary-limit (articles &optional pop)
8684   (if pop
8685       ;; We pop the previous limit off the stack and use that.
8686       (setq articles (car gnus-newsgroup-limits)
8687             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8688     ;; We use the new limit, so we push the old limit on the stack.
8689     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8690   ;; Set the limit.
8691   (setq gnus-newsgroup-limit articles)
8692   (let ((total (length gnus-newsgroup-data))
8693         (data (gnus-data-find-list (gnus-summary-article-number)))
8694         (gnus-summary-mark-below nil)   ; Inhibit this.
8695         found)
8696     ;; This will do all the work of generating the new summary buffer
8697     ;; according to the new limit.
8698     (gnus-summary-prepare)
8699     ;; Hide any threads, possibly.
8700     (gnus-summary-maybe-hide-threads)
8701     ;; Try to return to the article you were at, or one in the
8702     ;; neighborhood.
8703     (when data
8704       ;; We try to find some article after the current one.
8705       (while data
8706         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8707           (setq data nil
8708                 found t))
8709         (setq data (cdr data))))
8710     (unless found
8711       ;; If there is no data, that means that we were after the last
8712       ;; article.  The same goes when we can't find any articles
8713       ;; after the current one.
8714       (goto-char (point-max))
8715       (gnus-summary-find-prev))
8716     (gnus-set-mode-line 'summary)
8717     ;; We return how many articles were removed from the summary
8718     ;; buffer as a result of the new limit.
8719     (- total (length gnus-newsgroup-data))))
8720
8721 (defsubst gnus-invisible-cut-children (threads)
8722   (let ((num 0))
8723     (while threads
8724       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8725         (incf num))
8726       (pop threads))
8727     (< num 2)))
8728
8729 (defsubst gnus-cut-thread (thread)
8730   "Go forwards in the thread until we find an article that we want to display."
8731   (when (or (eq gnus-fetch-old-headers 'some)
8732             (eq gnus-fetch-old-headers 'invisible)
8733             (numberp gnus-fetch-old-headers)
8734             (eq gnus-build-sparse-threads 'some)
8735             (eq gnus-build-sparse-threads 'more))
8736     ;; Deal with old-fetched headers and sparse threads.
8737     (while (and
8738             thread
8739             (or
8740              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8741              (gnus-summary-article-ancient-p
8742               (mail-header-number (car thread))))
8743             (if (or (<= (length (cdr thread)) 1)
8744                     (eq gnus-fetch-old-headers 'invisible))
8745                 (setq gnus-newsgroup-limit
8746                       (delq (mail-header-number (car thread))
8747                             gnus-newsgroup-limit)
8748                       thread (cadr thread))
8749               (when (gnus-invisible-cut-children (cdr thread))
8750                 (let ((th (cdr thread)))
8751                   (while th
8752                     (if (memq (mail-header-number (caar th))
8753                               gnus-newsgroup-limit)
8754                         (setq thread (car th)
8755                               th nil)
8756                       (setq th (cdr th))))))))))
8757   thread)
8758
8759 (defun gnus-cut-threads (threads)
8760   "Cut off all uninteresting articles from the beginning of THREADS."
8761   (when (or (eq gnus-fetch-old-headers 'some)
8762             (eq gnus-fetch-old-headers 'invisible)
8763             (numberp gnus-fetch-old-headers)
8764             (eq gnus-build-sparse-threads 'some)
8765             (eq gnus-build-sparse-threads 'more))
8766     (let ((th threads))
8767       (while th
8768         (setcar th (gnus-cut-thread (car th)))
8769         (setq th (cdr th)))))
8770   ;; Remove nixed out threads.
8771   (delq nil threads))
8772
8773 (defun gnus-summary-initial-limit (&optional show-if-empty)
8774   "Figure out what the initial limit is supposed to be on group entry.
8775 This entails weeding out unwanted dormants, low-scored articles,
8776 fetch-old-headers verbiage, and so on."
8777   ;; Most groups have nothing to remove.
8778   (unless (or gnus-inhibit-limiting
8779               (and (null gnus-newsgroup-dormant)
8780                    (eq gnus-newsgroup-display 'gnus-not-ignore)
8781                    (not (eq gnus-fetch-old-headers 'some))
8782                    (not (numberp gnus-fetch-old-headers))
8783                    (not (eq gnus-fetch-old-headers 'invisible))
8784                    (null gnus-summary-expunge-below)
8785                    (not (eq gnus-build-sparse-threads 'some))
8786                    (not (eq gnus-build-sparse-threads 'more))
8787                    (null gnus-thread-expunge-below)))
8788     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8789     (setq gnus-newsgroup-limit nil)
8790     (mapatoms
8791      (lambda (node)
8792        (unless (car (symbol-value node))
8793          ;; These threads have no parents -- they are roots.
8794          (let ((nodes (cdr (symbol-value node)))
8795                thread)
8796            (while nodes
8797              (if (and gnus-thread-expunge-below
8798                       (< (gnus-thread-total-score (car nodes))
8799                          gnus-thread-expunge-below))
8800                  (gnus-expunge-thread (pop nodes))
8801                (setq thread (pop nodes))
8802                (gnus-summary-limit-children thread))))))
8803      gnus-newsgroup-dependencies)
8804     ;; If this limitation resulted in an empty group, we might
8805     ;; pop the previous limit and use it instead.
8806     (when (and (not gnus-newsgroup-limit)
8807                show-if-empty)
8808       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8809     gnus-newsgroup-limit))
8810
8811 (defun gnus-summary-limit-children (thread)
8812   "Return 1 if this subthread is visible and 0 if it is not."
8813   ;; First we get the number of visible children to this thread.  This
8814   ;; is done by recursing down the thread using this function, so this
8815   ;; will really go down to a leaf article first, before slowly
8816   ;; working its way up towards the root.
8817   (when thread
8818     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8819            (children
8820            (if (cdr thread)
8821                (apply '+ (mapcar 'gnus-summary-limit-children
8822                                  (cdr thread)))
8823              0))
8824            (number (mail-header-number (car thread)))
8825            score)
8826       (if (and
8827            (not (memq number gnus-newsgroup-marked))
8828            (or
8829             ;; If this article is dormant and has absolutely no visible
8830             ;; children, then this article isn't visible.
8831             (and (memq number gnus-newsgroup-dormant)
8832                  (zerop children))
8833             ;; If this is "fetch-old-headered" and there is no
8834             ;; visible children, then we don't want this article.
8835             (and (or (eq gnus-fetch-old-headers 'some)
8836                      (numberp gnus-fetch-old-headers))
8837                  (gnus-summary-article-ancient-p number)
8838                  (zerop children))
8839             ;; If this is "fetch-old-headered" and `invisible', then
8840             ;; we don't want this article.
8841             (and (eq gnus-fetch-old-headers 'invisible)
8842                  (gnus-summary-article-ancient-p number))
8843             ;; If this is a sparsely inserted article with no children,
8844             ;; we don't want it.
8845             (and (eq gnus-build-sparse-threads 'some)
8846                  (gnus-summary-article-sparse-p number)
8847                  (zerop children))
8848             ;; If we use expunging, and this article is really
8849             ;; low-scored, then we don't want this article.
8850             (when (and gnus-summary-expunge-below
8851                        (< (setq score
8852                                 (or (cdr (assq number gnus-newsgroup-scored))
8853                                     gnus-summary-default-score))
8854                           gnus-summary-expunge-below))
8855               ;; We increase the expunge-tally here, but that has
8856               ;; nothing to do with the limits, really.
8857               (incf gnus-newsgroup-expunged-tally)
8858               ;; We also mark as read here, if that's wanted.
8859               (when (and gnus-summary-mark-below
8860                          (< score gnus-summary-mark-below))
8861                 (setq gnus-newsgroup-unreads
8862                       (delq number gnus-newsgroup-unreads))
8863                 (if gnus-newsgroup-auto-expire
8864                     (push number gnus-newsgroup-expirable)
8865                   (push (cons number gnus-low-score-mark)
8866                         gnus-newsgroup-reads)))
8867               t)
8868             ;; Do the `display' group parameter.
8869             (and gnus-newsgroup-display
8870                  (let ((gnus-number number))
8871                    (not (funcall gnus-newsgroup-display))))))
8872           ;; Nope, invisible article.
8873           0
8874         ;; Ok, this article is to be visible, so we add it to the limit
8875         ;; and return 1.
8876         (push number gnus-newsgroup-limit)
8877         1))))
8878
8879 (defun gnus-expunge-thread (thread)
8880   "Mark all articles in THREAD as read."
8881   (let* ((number (mail-header-number (car thread))))
8882     (incf gnus-newsgroup-expunged-tally)
8883     ;; We also mark as read here, if that's wanted.
8884     (setq gnus-newsgroup-unreads
8885           (delq number gnus-newsgroup-unreads))
8886     (if gnus-newsgroup-auto-expire
8887         (push number gnus-newsgroup-expirable)
8888       (push (cons number gnus-low-score-mark)
8889             gnus-newsgroup-reads)))
8890   ;; Go recursively through all subthreads.
8891   (mapcar 'gnus-expunge-thread (cdr thread)))
8892
8893 ;; Summary article oriented commands
8894
8895 (defun gnus-summary-refer-parent-article (n)
8896   "Refer parent article N times.
8897 If N is negative, go to ancestor -N instead.
8898 The difference between N and the number of articles fetched is returned."
8899   (interactive "p")
8900   (let ((skip 1)
8901         error header ref)
8902     (when (not (natnump n))
8903       (setq skip (abs n)
8904             n 1))
8905     (while (and (> n 0)
8906                 (not error))
8907       (setq header (gnus-summary-article-header))
8908       (if (and (eq (mail-header-number header)
8909                    (cdr gnus-article-current))
8910                (equal gnus-newsgroup-name
8911                       (car gnus-article-current)))
8912           ;; If we try to find the parent of the currently
8913           ;; displayed article, then we take a look at the actual
8914           ;; References header, since this is slightly more
8915           ;; reliable than the References field we got from the
8916           ;; server.
8917           (with-current-buffer gnus-original-article-buffer
8918             (nnheader-narrow-to-headers)
8919             (unless (setq ref (message-fetch-field "references"))
8920               (when (setq ref (message-fetch-field "in-reply-to"))
8921                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8922             (widen))
8923         (setq ref
8924               ;; It's not the current article, so we take a bet on
8925               ;; the value we got from the server.
8926               (mail-header-references header)))
8927       (if (and ref
8928                (not (equal ref "")))
8929           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8930             (gnus-message 1 "Couldn't find parent"))
8931         (gnus-message 1 "No references in article %d"
8932                       (gnus-summary-article-number))
8933         (setq error t))
8934       (decf n))
8935     (gnus-summary-position-point)
8936     n))
8937
8938 (defun gnus-summary-refer-references ()
8939   "Fetch all articles mentioned in the References header.
8940 Return the number of articles fetched."
8941   (interactive)
8942   (let ((ref (mail-header-references (gnus-summary-article-header)))
8943         (current (gnus-summary-article-number))
8944         (n 0))
8945     (if (or (not ref)
8946             (equal ref ""))
8947         (error "No References in the current article")
8948       ;; For each Message-ID in the References header...
8949       (while (string-match "<[^>]*>" ref)
8950         (incf n)
8951         ;; ... fetch that article.
8952         (gnus-summary-refer-article
8953          (prog1 (match-string 0 ref)
8954            (setq ref (substring ref (match-end 0))))))
8955       (gnus-summary-goto-subject current)
8956       (gnus-summary-position-point)
8957       n)))
8958
8959 (defun gnus-delete-duplicate-headers (headers)
8960   ;; First remove leading duplicates.
8961   (while (and (> (length headers) 1)
8962               (= (mail-header-number (car headers))
8963                  (mail-header-number (cadr headers))))
8964     (pop headers))
8965   ;; Then the rest.
8966   (let ((result headers))
8967     (while (> (length headers) 1)
8968       (if (= (mail-header-number (car headers))
8969              (mail-header-number (cadr headers)))
8970           (setcdr headers (cddr headers))
8971         (pop headers)))
8972     result))
8973
8974 (defun gnus-summary-refer-thread (&optional limit)
8975   "Fetch all articles in the current thread.
8976 If no backend-specific 'request-thread function is available
8977 fetch LIMIT (the numerical prefix) old headers. If LIMIT is nil
8978 fetch what's specified by the `gnus-refer-thread-limit'
8979 variable."
8980   (interactive "P")
8981   (gnus-warp-to-article)
8982   (let* ((header (gnus-summary-article-header))
8983          (id (mail-header-id header))
8984          (gnus-inhibit-demon t)
8985          (gnus-summary-ignore-duplicates t)
8986          (gnus-read-all-available-headers t)
8987          (limit (if limit (prefix-numeric-value limit)
8988                   gnus-refer-thread-limit))
8989          (new-headers
8990           (if (gnus-check-backend-function
8991                'request-thread gnus-newsgroup-name)
8992               (gnus-request-thread header gnus-newsgroup-name)
8993             (let* ((last (if (numberp limit)
8994                              (min (+ (mail-header-number header)
8995                                      limit)
8996                                   gnus-newsgroup-highest)
8997                            gnus-newsgroup-highest))
8998                    (subject (gnus-simplify-subject
8999                              (mail-header-subject header)))
9000                    (refs (split-string (or (mail-header-references header)
9001                                            "")))
9002                    (gnus-parse-headers-hook
9003                     (lambda () (goto-char (point-min))
9004                       (keep-lines
9005                        (regexp-opt (append refs (list id subject)))))))
9006               (gnus-fetch-headers (list last) (if (numberp limit)
9007                                                   (* 2 limit) limit) t)))))
9008     (dolist (header new-headers)
9009       (when (member (mail-header-number header) gnus-newsgroup-unselected)
9010         (push (mail-header-number header) gnus-newsgroup-unreads)
9011         (setq gnus-newsgroup-unselected
9012               (delete (mail-header-number header) gnus-newsgroup-unselected))))
9013     (setq gnus-newsgroup-headers
9014           (gnus-delete-duplicate-headers
9015            (gnus-merge
9016             'list gnus-newsgroup-headers new-headers
9017             'gnus-article-sort-by-number)))
9018     (gnus-summary-limit-include-thread id)))
9019
9020 (defun gnus-summary-refer-article (message-id)
9021   "Fetch an article specified by MESSAGE-ID."
9022   (interactive "sMessage-ID: ")
9023   (when (and (stringp message-id)
9024              (not (zerop (length message-id))))
9025     (setq message-id (gnus-replace-in-string message-id " " ""))
9026     ;; Construct the correct Message-ID if necessary.
9027     ;; Suggested by tale@pawl.rpi.edu.
9028     (unless (string-match "^<" message-id)
9029       (setq message-id (concat "<" message-id)))
9030     (unless (string-match ">$" message-id)
9031       (setq message-id (concat message-id ">")))
9032     ;; People often post MIDs from URLs, so unhex it:
9033     (unless (string-match "@" message-id)
9034       (setq message-id (gnus-url-unhex-string message-id)))
9035     (let* ((header (gnus-id-to-header message-id))
9036            (sparse (and header
9037                         (gnus-summary-article-sparse-p
9038                          (mail-header-number header))
9039                         (memq (mail-header-number header)
9040                               gnus-newsgroup-limit)))
9041            number)
9042       (cond
9043        ;; If the article is present in the buffer we just go to it.
9044        ((and header
9045              (or (not (gnus-summary-article-sparse-p
9046                        (mail-header-number header)))
9047                  sparse))
9048         (prog1
9049             (gnus-summary-goto-article
9050              (mail-header-number header) nil t)
9051           (when sparse
9052             (gnus-summary-update-article (mail-header-number header)))))
9053        (t
9054         ;; We fetch the article.
9055         (catch 'found
9056           (dolist (gnus-override-method (gnus-refer-article-methods))
9057             (when (and (gnus-check-server gnus-override-method)
9058                        ;; Fetch the header,
9059                        (setq number (gnus-summary-insert-subject message-id)))
9060               ;; and display the article.
9061               (gnus-summary-select-article nil nil nil number)
9062               (throw 'found t)))
9063           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
9064
9065 (defun gnus-refer-article-methods ()
9066   "Return a list of referable methods."
9067   (cond
9068    ;; No method, so we default to current and native.
9069    ((null gnus-refer-article-method)
9070     (list gnus-current-select-method gnus-select-method))
9071    ;; Current.
9072    ((eq 'current gnus-refer-article-method)
9073     (list gnus-current-select-method))
9074    ;; List of select methods.
9075    ((not (and (symbolp (car gnus-refer-article-method))
9076               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
9077     (let (out)
9078       (dolist (method gnus-refer-article-method)
9079         (push (if (eq 'current method)
9080                   gnus-current-select-method
9081                 (if (eq 'nnir (car method))
9082                     (list
9083                      'nnir
9084                      (or (cadr method)
9085                          (gnus-method-to-server gnus-current-select-method)))
9086                   method))
9087               out))
9088       (nreverse out)))
9089    ;; One single select method.
9090    (t
9091     (list gnus-refer-article-method))))
9092
9093 (defun gnus-summary-edit-parameters ()
9094   "Edit the group parameters of the current group."
9095   (interactive)
9096   (gnus-group-edit-group gnus-newsgroup-name 'params))
9097
9098 (defun gnus-summary-customize-parameters ()
9099   "Customize the group parameters of the current group."
9100   (interactive)
9101   (gnus-group-customize gnus-newsgroup-name))
9102
9103 (defun gnus-summary-enter-digest-group (&optional force)
9104   "Enter an nndoc group based on the current article.
9105 If FORCE, force a digest interpretation.  If not, try to guess
9106 what the document format is.
9107
9108 To control what happens when you exit the group, see the
9109 `gnus-auto-select-on-ephemeral-exit' variable."
9110   (interactive "P")
9111   (let ((conf gnus-current-window-configuration))
9112     (save-window-excursion
9113       (save-excursion
9114         (let (gnus-article-prepare-hook
9115               gnus-display-mime-function
9116               gnus-break-pages)
9117           (gnus-summary-select-article))))
9118     (setq gnus-current-window-configuration conf)
9119     (let* ((name (format "%s-%d"
9120                          (gnus-group-prefixed-name
9121                           gnus-newsgroup-name (list 'nndoc ""))
9122                          (with-current-buffer gnus-summary-buffer
9123                            gnus-current-article)))
9124            (ogroup gnus-newsgroup-name)
9125            (params (append (gnus-info-params (gnus-get-info ogroup))
9126                            (list (cons 'to-group ogroup))
9127                            (list (cons 'parent-group ogroup))
9128                            (list (cons 'save-article-group ogroup))))
9129            (case-fold-search t)
9130            (buf (current-buffer))
9131            dig to-address)
9132       (with-current-buffer gnus-original-article-buffer
9133         ;; Have the digest group inherit the main mail address of
9134         ;; the parent article.
9135         (when (setq to-address (or (gnus-fetch-field "reply-to")
9136                                    (gnus-fetch-field "from")))
9137           (setq params
9138                 (append
9139                  (list (cons 'to-address
9140                              (funcall gnus-decode-encoded-address-function
9141                                       to-address))))))
9142         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
9143         (insert-buffer-substring gnus-original-article-buffer)
9144         ;; Remove lines that may lead nndoc to misinterpret the
9145         ;; document type.
9146         (narrow-to-region
9147          (goto-char (point-min))
9148          (or (search-forward "\n\n" nil t) (point)))
9149         (goto-char (point-min))
9150         (delete-matching-lines "^Path:\\|^From ")
9151         (widen))
9152       (unwind-protect
9153           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
9154                     (gnus-newsgroup-ephemeral-ignored-charsets
9155                      gnus-newsgroup-ignored-charsets))
9156                 (gnus-group-read-ephemeral-group
9157                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
9158                               (nndoc-article-type
9159                                ,(if force 'mbox 'guess)))
9160                  t nil nil nil
9161                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
9162                                                         "ADAPT")))))
9163               ;; Make all postings to this group go to the parent group.
9164               (nconc (gnus-info-params (gnus-get-info name))
9165                      params)
9166             ;; Couldn't select this doc group.
9167             (switch-to-buffer buf)
9168             (gnus-set-global-variables)
9169             (gnus-configure-windows 'summary)
9170             (gnus-message 3 "Article couldn't be entered?"))
9171         (kill-buffer dig)))))
9172
9173 (defun gnus-summary-read-document (n)
9174   "Open a new group based on the current article(s).
9175 This will allow you to read digests and other similar
9176 documents as newsgroups.
9177 Obeys the standard process/prefix convention."
9178   (interactive "P")
9179   (let* ((ogroup gnus-newsgroup-name)
9180          (params (append (gnus-info-params (gnus-get-info ogroup))
9181                          (list (cons 'to-group ogroup))))
9182          group egroup groups vgroup)
9183     (dolist (article (gnus-summary-work-articles n))
9184       (setq group (format "%s-%d" gnus-newsgroup-name article))
9185       (gnus-summary-remove-process-mark article)
9186       (when (gnus-summary-display-article article)
9187         (save-excursion ;;What for?
9188           (with-temp-buffer
9189             (insert-buffer-substring gnus-original-article-buffer)
9190             ;; Remove some headers that may lead nndoc to make
9191             ;; the wrong guess.
9192             (message-narrow-to-head)
9193             (goto-char (point-min))
9194             (delete-matching-lines "^Path:\\|^From ")
9195             (widen)
9196             (if (setq egroup
9197                       (gnus-group-read-ephemeral-group
9198                        group `(nndoc ,group (nndoc-address ,(current-buffer))
9199                                      (nndoc-article-type guess))
9200                        t nil t))
9201                 (progn
9202                   ;; Make all postings to this group go to the parent group.
9203                   (nconc (gnus-info-params (gnus-get-info egroup))
9204                          params)
9205                   (push egroup groups))
9206               ;; Couldn't select this doc group.
9207               (gnus-error 3 "Article couldn't be entered"))))))
9208     ;; Now we have selected all the documents.
9209     (cond
9210      ((not groups)
9211       (error "None of the articles could be interpreted as documents"))
9212      ((gnus-group-read-ephemeral-group
9213        (setq vgroup (format
9214                      "nnvirtual:%s-%s" gnus-newsgroup-name
9215                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
9216        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
9217        t
9218        (cons (current-buffer) 'summary)))
9219      (t
9220       (error "Couldn't select virtual nndoc group")))))
9221
9222 (defun gnus-summary-widget-forward (arg)
9223   "Move point to the next field or button in the article.
9224 With optional ARG, move across that many fields."
9225   (interactive "p")
9226   (gnus-summary-select-article)
9227   (gnus-configure-windows 'article)
9228   (select-window (gnus-get-buffer-window gnus-article-buffer))
9229   (widget-forward arg))
9230
9231 (defun gnus-summary-isearch-article (&optional regexp-p)
9232   "Do incremental search forward on the current article.
9233 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
9234   (interactive "P")
9235   (gnus-summary-select-article)
9236   (gnus-configure-windows 'article)
9237   (gnus-eval-in-buffer-window gnus-article-buffer
9238     (save-restriction
9239       (widen)
9240       (isearch-forward regexp-p))))
9241
9242 (defun gnus-summary-repeat-search-article-forward ()
9243   "Repeat the previous search forwards."
9244   (interactive)
9245   (unless gnus-last-search-regexp
9246     (error "No previous search"))
9247   (gnus-summary-search-article-forward gnus-last-search-regexp))
9248
9249 (defun gnus-summary-repeat-search-article-backward ()
9250   "Repeat the previous search backwards."
9251   (interactive)
9252   (unless gnus-last-search-regexp
9253     (error "No previous search"))
9254   (gnus-summary-search-article-forward gnus-last-search-regexp t))
9255
9256 (defun gnus-summary-search-article-forward (regexp &optional backward)
9257   "Search for an article containing REGEXP forward.
9258 If BACKWARD, search backward instead."
9259   (interactive
9260    (list (read-string
9261           (format "Search article %s (regexp%s): "
9262                   (if current-prefix-arg "backward" "forward")
9263                   (if gnus-last-search-regexp
9264                       (concat ", default " gnus-last-search-regexp)
9265                     "")))
9266          current-prefix-arg))
9267   (if (string-equal regexp "")
9268       (setq regexp (or gnus-last-search-regexp ""))
9269     (setq gnus-last-search-regexp regexp)
9270     (setq gnus-article-before-search gnus-current-article))
9271   ;; Intentionally set gnus-last-article.
9272   (setq gnus-last-article gnus-article-before-search)
9273   (let ((gnus-last-article gnus-last-article))
9274     (if (gnus-summary-search-article regexp backward)
9275         (gnus-summary-show-thread)
9276       (signal 'search-failed (list regexp)))))
9277
9278 (defun gnus-summary-search-article-backward (regexp)
9279   "Search for an article containing REGEXP backward."
9280   (interactive
9281    (list (read-string
9282           (format "Search article backward (regexp%s): "
9283                   (if gnus-last-search-regexp
9284                       (concat ", default " gnus-last-search-regexp)
9285                     "")))))
9286   (gnus-summary-search-article-forward regexp 'backward))
9287
9288 (defun gnus-summary-search-article (regexp &optional backward)
9289   "Search for an article containing REGEXP.
9290 Optional argument BACKWARD means do search for backward.
9291 `gnus-select-article-hook' is not called during the search."
9292   ;; We have to require this here to make sure that the following
9293   ;; dynamic binding isn't shadowed by autoloading.
9294   (require 'gnus-async)
9295   (require 'gnus-art)
9296   (let ((gnus-select-article-hook nil)  ;Disable hook.
9297         (gnus-article-prepare-hook nil)
9298         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9299         (gnus-use-article-prefetch nil)
9300         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9301         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9302         (gnus-visual nil)
9303         (gnus-keep-backlog nil)
9304         (gnus-break-pages nil)
9305         (gnus-summary-display-arrow nil)
9306         (gnus-updated-mode-lines nil)
9307         (gnus-auto-center-summary nil)
9308         (sum (current-buffer))
9309         (gnus-display-mime-function nil)
9310         (found nil)
9311         point)
9312     (gnus-save-hidden-threads
9313       (gnus-summary-select-article)
9314       (set-buffer gnus-article-buffer)
9315       (goto-char (window-point (get-buffer-window (current-buffer))))
9316       (when backward
9317         (forward-line -1))
9318       (while (not found)
9319         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9320         (if (if backward
9321                 (re-search-backward regexp nil t)
9322               (re-search-forward regexp nil t))
9323             ;; We found the regexp.
9324             (progn
9325               (setq found 'found)
9326               (beginning-of-line)
9327               (set-window-start
9328                (get-buffer-window (current-buffer))
9329                (point))
9330               (forward-line 1)
9331               (set-window-point
9332                (get-buffer-window (current-buffer))
9333                (point))
9334               (set-buffer sum)
9335               (setq point (point)))
9336           ;; We didn't find it, so we go to the next article.
9337           (set-buffer sum)
9338           (setq found 'not)
9339           (while (eq found 'not)
9340             (if (not (if backward (gnus-summary-find-prev)
9341                        (gnus-summary-find-next)))
9342                 ;; No more articles.
9343                 (setq found t)
9344               ;; Select the next article and adjust point.
9345               (unless (gnus-summary-article-sparse-p
9346                        (gnus-summary-article-number))
9347                 (setq found nil)
9348                 (gnus-summary-select-article)
9349                 (set-buffer gnus-article-buffer)
9350                 (widen)
9351                 (goto-char (if backward (point-max) (point-min))))))))
9352       (gnus-message 7 ""))
9353     ;; Return whether we found the regexp.
9354     (when (eq found 'found)
9355       (goto-char point)
9356       (gnus-summary-show-thread)
9357       (gnus-summary-goto-subject gnus-current-article)
9358       (gnus-summary-position-point)
9359       t)))
9360
9361 (defun gnus-find-matching-articles (header regexp)
9362   "Return a list of all articles that match REGEXP on HEADER.
9363 This search includes all articles in the current group that Gnus has
9364 fetched headers for, whether they are displayed or not."
9365   (let ((articles nil)
9366         ;; Can't eta-reduce because it's a macro.
9367         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9368         (case-fold-search t))
9369     (dolist (header gnus-newsgroup-headers)
9370       (when (string-match regexp (funcall func header))
9371         (push (mail-header-number header) articles)))
9372     (nreverse articles)))
9373
9374 (defun gnus-summary-find-matching (header regexp &optional backward unread
9375                                           not-case-fold not-matching)
9376   "Return a list of all articles that match REGEXP on HEADER.
9377 The search stars on the current article and goes forwards unless
9378 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9379 If UNREAD is non-nil, only unread articles will
9380 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9381 in the comparisons. If NOT-MATCHING, return a list of all articles that
9382 not match REGEXP on HEADER."
9383   (let ((case-fold-search (not not-case-fold))
9384         articles d func)
9385     (if (consp header)
9386         (if (eq (car header) 'extra)
9387             (setq func
9388                   `(lambda (h)
9389                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9390                          "")))
9391           (error "%s is an invalid header" header))
9392       (unless (fboundp (intern (concat "mail-header-" header)))
9393         (error "%s is not a valid header" header))
9394       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9395     (dolist (d (if (eq backward 'all)
9396                    gnus-newsgroup-data
9397                  (gnus-data-find-list
9398                   (gnus-summary-article-number)
9399                   (gnus-data-list backward))))
9400       (when (and (or (not unread)       ; We want all articles...
9401                      (gnus-data-unread-p d)) ; Or just unreads.
9402                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9403                  (if not-matching
9404                      (not (string-match
9405                            regexp
9406                            (funcall func (gnus-data-header d))))
9407                    (string-match regexp
9408                                  (funcall func (gnus-data-header d)))))
9409         (push (gnus-data-number d) articles))) ; Success!
9410     (nreverse articles)))
9411
9412 (defun gnus-summary-execute-command (header regexp command &optional backward)
9413   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9414 If HEADER is an empty string (or nil), the match is done on the entire
9415 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9416   (interactive
9417    (list (let ((completion-ignore-case t))
9418            (gnus-completing-read
9419             "Header name"
9420             (mapcar 'symbol-name
9421                     (append
9422                      '(Number Subject From Lines Date
9423                        Message-ID Xref References Body)
9424                      gnus-extra-headers))
9425             'require-match))
9426          (read-string "Regexp: ")
9427          (read-key-sequence "Command: ")
9428          current-prefix-arg))
9429   (when (equal header "Body")
9430     (setq header ""))
9431   ;; Hidden thread subtrees must be searched as well.
9432   (gnus-summary-show-all-threads)
9433   ;; We don't want to change current point nor window configuration.
9434   (save-excursion
9435     (save-window-excursion
9436       (let (gnus-visual
9437             gnus-treat-strip-trailing-blank-lines
9438             gnus-treat-strip-leading-blank-lines
9439             gnus-treat-strip-multiple-blank-lines
9440             gnus-treat-hide-boring-headers
9441             gnus-treat-fold-newsgroups
9442             gnus-article-prepare-hook)
9443         (gnus-message 6 "Executing %s..." (key-description command))
9444         ;; We'd like to execute COMMAND interactively so as to give arguments.
9445         (gnus-execute header regexp
9446                       `(call-interactively ',(key-binding command))
9447                       backward)
9448         (gnus-message 6 "Executing %s...done" (key-description command))))))
9449
9450 (defun gnus-summary-beginning-of-article ()
9451   "Scroll the article back to the beginning."
9452   (interactive)
9453   (gnus-summary-select-article)
9454   (gnus-configure-windows 'article)
9455   (gnus-eval-in-buffer-window gnus-article-buffer
9456     (widen)
9457     (goto-char (point-min))
9458     (when gnus-break-pages
9459       (gnus-narrow-to-page))))
9460
9461 (defun gnus-summary-end-of-article ()
9462   "Scroll to the end of the article."
9463   (interactive)
9464   (gnus-summary-select-article)
9465   (gnus-configure-windows 'article)
9466   (gnus-eval-in-buffer-window gnus-article-buffer
9467     (widen)
9468     (goto-char (point-max))
9469     (recenter -3)
9470     (when gnus-break-pages
9471       (gnus-narrow-to-page))))
9472
9473 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9474   "Truncate to LEN and quote all \"(\"'s in STRING."
9475   (gnus-replace-in-string (if (and len (> (length string) len))
9476                               (substring string 0 len)
9477                             string)
9478                           "[()]" "\\\\\\&"))
9479
9480 (defun gnus-summary-print-article (&optional filename n)
9481   "Generate and print a PostScript image of the process-marked (mail) articles.
9482
9483 If used interactively, print the current article if none are
9484 process-marked.  With prefix arg, prompt the user for the name of the
9485 file to save in.
9486
9487 When used from Lisp, accept two optional args FILENAME and N.  N means
9488 to print the next N articles.  If N is negative, print the N previous
9489 articles.  If N is nil and articles have been marked with the process
9490 mark, print these instead.
9491
9492 If the optional first argument FILENAME is nil, send the image to the
9493 printer.  If FILENAME is a string, save the PostScript image in a file with
9494 that name.  If FILENAME is a number, prompt the user for the name of the file
9495 to save in."
9496   (interactive (list (ps-print-preprint current-prefix-arg)))
9497   (dolist (article (gnus-summary-work-articles n))
9498     (gnus-summary-select-article nil nil 'pseudo article)
9499     (gnus-eval-in-buffer-window gnus-article-buffer
9500       (gnus-print-buffer))
9501     (gnus-summary-remove-process-mark article))
9502   (ps-despool filename))
9503
9504 (defun gnus-print-buffer ()
9505   (let ((ps-left-header
9506          (list
9507           (concat "("
9508                   (gnus-summary-print-truncate-and-quote
9509                    (mail-header-subject gnus-current-headers)
9510                    66) ")")
9511           (concat "("
9512                   (gnus-summary-print-truncate-and-quote
9513                    (mail-header-from gnus-current-headers)
9514                    45) ")")))
9515         (ps-right-header
9516          (list
9517           "/pagenumberstring load"
9518           (concat "("
9519                   (mail-header-date gnus-current-headers) ")"))))
9520     (gnus-run-hooks 'gnus-ps-print-hook)
9521     (save-excursion
9522       (if ps-print-color-p
9523           (ps-spool-buffer-with-faces)
9524         (ps-spool-buffer)))))
9525
9526 (defun gnus-summary-show-complete-article ()
9527   "Show a complete version of the current article.
9528 This is only useful if you're looking at a partial version of the
9529 article currently."
9530   (interactive)
9531   (let ((gnus-keep-backlog nil)
9532         (gnus-use-cache nil)
9533         (gnus-agent nil)
9534         (variable (intern
9535                    (format "%s-fetch-partial-articles"
9536                            (car (gnus-find-method-for-group
9537                                  gnus-newsgroup-name)))
9538                    obarray))
9539         old-val)
9540     (unwind-protect
9541         (progn
9542           (setq old-val (symbol-value variable))
9543           (set variable nil)
9544           (gnus-flush-original-article-buffer)
9545           (gnus-summary-show-article))
9546       (set variable old-val))))
9547
9548 (defun gnus-summary-show-article (&optional arg)
9549   "Force redisplaying of the current article.
9550 If ARG (the prefix) is a number, show the article with the charset
9551 defined in `gnus-summary-show-article-charset-alist', or the charset
9552 input.
9553 If ARG (the prefix) is non-nil and not a number, show the article,
9554 but without running any of the article treatment functions
9555 article.  Normally, the keystroke is `C-u g'.  When using `C-u
9556 C-u g', show the raw article."
9557   (interactive "P")
9558   (cond
9559    ((numberp arg)
9560     (gnus-summary-show-article t)
9561     (let ((gnus-newsgroup-charset
9562            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9563                (mm-read-coding-system
9564                 "View as charset: " ;; actually it is coding system.
9565                 (with-current-buffer gnus-article-buffer
9566                   (mm-detect-coding-region (point) (point-max))))))
9567           (gnus-newsgroup-ignored-charsets 'gnus-all))
9568       (gnus-summary-select-article nil 'force)
9569       (let ((deps gnus-newsgroup-dependencies)
9570             head header lines)
9571         (with-current-buffer gnus-original-article-buffer
9572           (save-restriction
9573             (message-narrow-to-head)
9574             (setq head (buffer-string))
9575             (goto-char (point-min))
9576             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9577               (goto-char (point-max))
9578               (widen)
9579               (setq lines (1- (count-lines (point) (point-max))))))
9580           (with-temp-buffer
9581             (insert (format "211 %d Article retrieved.\n"
9582                             (cdr gnus-article-current)))
9583             (insert head)
9584             (if lines (insert (format "Lines: %d\n" lines)))
9585             (insert ".\n")
9586             (let ((nntp-server-buffer (current-buffer)))
9587               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9588         (gnus-data-set-header
9589          (gnus-data-find (cdr gnus-article-current))
9590          header)
9591         (gnus-summary-update-article-line
9592          (cdr gnus-article-current) header)
9593         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9594           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9595    ((not arg)
9596     ;; Select the article the normal way.
9597     (gnus-summary-select-article nil 'force))
9598    ((equal arg '(16))
9599     ;; C-u C-u g
9600     (let ((gnus-inhibit-article-treatments t))
9601       (gnus-summary-select-article nil 'force)))
9602    (t
9603     ;; We have to require this here to make sure that the following
9604     ;; dynamic binding isn't shadowed by autoloading.
9605     (require 'gnus-async)
9606     (require 'gnus-art)
9607     ;; Bind the article treatment functions to nil.
9608     (let ((gnus-have-all-headers t)
9609           gnus-article-prepare-hook
9610           gnus-article-decode-hook
9611           gnus-display-mime-function
9612           gnus-break-pages)
9613       ;; Destroy any MIME parts.
9614       (when (gnus-buffer-live-p gnus-article-buffer)
9615         (with-current-buffer gnus-article-buffer
9616           (gnus-article-stop-animations)
9617           (mm-destroy-parts gnus-article-mime-handles)
9618           ;; Set it to nil for safety reason.
9619           (setq gnus-article-mime-handle-alist nil)
9620           (setq gnus-article-mime-handles nil)))
9621       (gnus-summary-select-article nil 'force))))
9622   (gnus-summary-goto-subject gnus-current-article)
9623   (gnus-summary-position-point))
9624
9625 (defun gnus-summary-show-raw-article ()
9626   "Show the raw article without any article massaging functions being run."
9627   (interactive)
9628   (gnus-summary-show-article t))
9629
9630 (defun gnus-summary-verbose-headers (&optional arg)
9631   "Toggle permanent full header display.
9632 If ARG is a positive number, turn header display on.
9633 If ARG is a negative number, turn header display off."
9634   (interactive "P")
9635   (setq gnus-show-all-headers
9636         (cond ((or (not (numberp arg))
9637                    (zerop arg))
9638                (not gnus-show-all-headers))
9639               ((natnump arg)
9640                t)))
9641   (gnus-summary-show-article))
9642
9643 (defun gnus-summary-toggle-header (&optional arg)
9644   "Show the headers if they are hidden, or hide them if they are shown.
9645 If ARG is a positive number, show the entire header.
9646 If ARG is a negative number, hide the unwanted header lines."
9647   (interactive "P")
9648   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9649                      (get-buffer-window gnus-article-buffer t))))
9650     (with-current-buffer gnus-article-buffer
9651       (widen)
9652       (article-narrow-to-head)
9653       (let* ((inhibit-read-only t)
9654              (inhibit-point-motion-hooks t)
9655              (hidden (if (numberp arg)
9656                          (>= arg 0)
9657                        (or (not (looking-at "[^ \t\n]+:"))
9658                            (gnus-article-hidden-text-p 'headers))))
9659              s e)
9660         (delete-region (point-min) (point-max))
9661         (with-current-buffer gnus-original-article-buffer
9662           (goto-char (setq s (point-min)))
9663           (setq e (if (search-forward "\n\n" nil t)
9664                       (1- (point))
9665                     (point-max))))
9666         (insert-buffer-substring gnus-original-article-buffer s e)
9667         (run-hooks 'gnus-article-decode-hook)
9668         (if hidden
9669             (let ((gnus-treat-hide-headers nil)
9670                   (gnus-treat-hide-boring-headers nil))
9671               (gnus-delete-wash-type 'headers)
9672               (gnus-treat-article 'head))
9673           (gnus-treat-article 'head))
9674         (widen)
9675         (if window
9676             (set-window-start window (goto-char (point-min))))
9677         (if gnus-break-pages
9678             (gnus-narrow-to-page)
9679           (when (gnus-visual-p 'page-marker)
9680             (let ((inhibit-read-only t))
9681               (gnus-remove-text-with-property 'gnus-prev)
9682               (gnus-remove-text-with-property 'gnus-next))))
9683         (gnus-set-mode-line 'article)))))
9684
9685 (defun gnus-summary-show-all-headers ()
9686   "Make all header lines visible."
9687   (interactive)
9688   (gnus-summary-toggle-header 1))
9689
9690 (defun gnus-summary-caesar-message (&optional arg)
9691   "Caesar rotate the current article by 13.
9692 With a non-numerical prefix, also rotate headers.  A numerical
9693 prefix specifies how many places to rotate each letter forward."
9694   (interactive "P")
9695   (gnus-summary-select-article)
9696   (let ((mail-header-separator ""))
9697     (gnus-eval-in-buffer-window gnus-article-buffer
9698       (save-restriction
9699         (widen)
9700         (let ((start (window-start))
9701               (inhibit-read-only t))
9702           (if (equal arg '(4))
9703               (message-caesar-buffer-body nil t)
9704             (message-caesar-buffer-body arg))
9705           (set-window-start (get-buffer-window (current-buffer)) start)))))
9706   ;; Create buttons and stuff...
9707   (gnus-treat-article nil))
9708
9709 (declare-function idna-to-unicode "ext:idna" (str))
9710
9711 (defun gnus-summary-idna-message (&optional arg)
9712   "Decode IDNA encoded domain names in the current articles.
9713 IDNA encoded domain names looks like `xn--bar'.  If a string
9714 remain unencoded after running this function, it is likely an
9715 invalid IDNA string (`xn--bar' is invalid).
9716
9717 You must have GNU Libidn (URL `http://www.gnu.org/software/libidn/')
9718 installed for this command to work."
9719   (interactive "P")
9720   (if (not (and (condition-case nil (require 'idna)
9721                   (file-error))
9722                 (mm-coding-system-p 'utf-8)
9723                 (executable-find (symbol-value 'idna-program))))
9724       (gnus-message
9725        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9726     (gnus-summary-select-article)
9727     (let ((mail-header-separator ""))
9728       (gnus-eval-in-buffer-window gnus-article-buffer
9729         (save-restriction
9730           (widen)
9731           (let ((start (window-start))
9732                 buffer-read-only)
9733             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9734               (replace-match (idna-to-unicode (match-string 1))))
9735             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9736
9737 (defun gnus-summary-morse-message (&optional arg)
9738   "Morse decode the current article."
9739   (interactive "P")
9740   (gnus-summary-select-article)
9741   (let ((mail-header-separator ""))
9742     (gnus-eval-in-buffer-window gnus-article-buffer
9743       (save-excursion
9744         (save-restriction
9745           (widen)
9746           (let ((pos (window-start))
9747                 (inhibit-read-only t))
9748             (goto-char (point-min))
9749             (when (message-goto-body)
9750               (gnus-narrow-to-body))
9751             (goto-char (point-min))
9752             (while (search-forward "·" (point-max) t)
9753               (replace-match "."))
9754             (unmorse-region (point-min) (point-max))
9755             (widen)
9756             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9757
9758 (defun gnus-summary-stop-page-breaking ()
9759   "Stop page breaking in the current article."
9760   (interactive)
9761   (gnus-summary-select-article)
9762   (gnus-eval-in-buffer-window gnus-article-buffer
9763     (widen)
9764     (when (gnus-visual-p 'page-marker)
9765       (let ((inhibit-read-only t))
9766         (gnus-remove-text-with-property 'gnus-prev)
9767         (gnus-remove-text-with-property 'gnus-next))
9768       (setq gnus-page-broken nil))))
9769
9770 (defun gnus-summary-move-article (&optional n to-newsgroup
9771                                             select-method action)
9772   "Move the current article to a different newsgroup.
9773 If N is a positive number, move the N next articles.
9774 If N is a negative number, move the N previous articles.
9775 If N is nil and any articles have been marked with the process mark,
9776 move those articles instead.
9777 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9778 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9779 re-spool using this method.
9780
9781 When called interactively with TO-NEWSGROUP being nil, the value of
9782 the variable `gnus-move-split-methods' is used for finding a default
9783 for the target newsgroup.
9784
9785 For this function to work, both the current newsgroup and the
9786 newsgroup that you want to move to have to support the `request-move'
9787 and `request-accept' functions.
9788
9789 ACTION can be either `move' (the default), `crosspost' or `copy'."
9790   (interactive "P")
9791   (unless action
9792     (setq action 'move))
9793   ;; Check whether the source group supports the required functions.
9794   (cond ((and (eq action 'move)
9795               (not (gnus-check-backend-function
9796                     'request-move-article gnus-newsgroup-name)))
9797          (error "The current group does not support article moving"))
9798         ((and (eq action 'crosspost)
9799               (not (gnus-check-backend-function
9800                     'request-replace-article gnus-newsgroup-name)))
9801          (error "The current group does not support article editing")))
9802   (let ((articles (gnus-summary-work-articles n))
9803         (prefix (if (gnus-check-backend-function
9804                      'request-move-article gnus-newsgroup-name)
9805                     (funcall gnus-move-group-prefix-function
9806                              gnus-newsgroup-name)
9807                   ""))
9808         (names '((move "Move" "Moving")
9809                  (copy "Copy" "Copying")
9810                  (crosspost "Crosspost" "Crossposting")))
9811         (copy-buf (save-excursion
9812                     (nnheader-set-temp-buffer " *copy article*")))
9813         art-group to-method new-xref article to-groups
9814         articles-to-update-marks encoded)
9815     (unless (assq action names)
9816       (error "Unknown action %s" action))
9817     ;; Read the newsgroup name.
9818     (when (and (not to-newsgroup)
9819                (not select-method))
9820       (if (and gnus-move-split-methods
9821                (not
9822                 (and (memq gnus-current-article articles)
9823                      (gnus-buffer-live-p gnus-original-article-buffer))))
9824           ;; When `gnus-move-split-methods' is non-nil, we have to
9825           ;; select an article to give `gnus-read-move-group-name' an
9826           ;; opportunity to suggest an appropriate default.  However,
9827           ;; we needn't render or mark the article.
9828           (let ((gnus-display-mime-function nil)
9829                 (gnus-article-prepare-hook nil)
9830                 (gnus-mark-article-hook nil))
9831             (gnus-summary-select-article nil nil nil (car articles))))
9832       (setq to-newsgroup (gnus-read-move-group-name
9833                           (cadr (assq action names))
9834                           (symbol-value
9835                            (intern (format "gnus-current-%s-group" action)))
9836                           articles prefix)
9837             encoded to-newsgroup
9838             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9839       (set (intern (format "gnus-current-%s-group" action))
9840            (mm-decode-coding-string
9841             to-newsgroup
9842             (gnus-group-name-charset to-method to-newsgroup))))
9843     (unless to-method
9844       (setq to-method (or select-method
9845                           (gnus-server-to-method
9846                            (gnus-group-method to-newsgroup)))))
9847     (setq to-newsgroup
9848           (or encoded
9849               (and to-newsgroup
9850                    (mm-encode-coding-string
9851                     to-newsgroup
9852                     (gnus-group-name-charset to-method to-newsgroup)))))
9853     ;; Check the method we are to move this article to...
9854     (unless (gnus-check-backend-function
9855              'request-accept-article (car to-method))
9856       (error "%s does not support article copying" (car to-method)))
9857     (unless (gnus-check-server to-method)
9858       (error "Can't open server %s" (car to-method)))
9859     (gnus-message 6 "%s to %s: %s..."
9860                   (caddr (assq action names))
9861                   (or (car select-method)
9862                       (gnus-group-decoded-name to-newsgroup))
9863                   articles)
9864     (while articles
9865       (setq article (pop articles))
9866       ;; Set any marks that may have changed in the summary buffer.
9867       (when gnus-preserve-marks
9868         (gnus-summary-push-marks-to-backend article))
9869       (setq
9870        art-group
9871        (cond
9872         ;; Move the article.
9873         ((eq action 'move)
9874          ;; Remove this article from future suppression.
9875          (gnus-dup-unsuppress-article article)
9876          (let* ((from-method (gnus-find-method-for-group
9877                               gnus-newsgroup-name))
9878                 (to-method (or select-method
9879                                (gnus-find-method-for-group to-newsgroup)))
9880                 (move-is-internal (gnus-server-equal from-method to-method)))
9881            (gnus-request-move-article
9882             article                     ; Article to move
9883             gnus-newsgroup-name         ; From newsgroup
9884             (nth 1 (gnus-find-method-for-group
9885                     gnus-newsgroup-name)) ; Server
9886             (list 'gnus-request-accept-article
9887                   to-newsgroup (list 'quote select-method)
9888                   (not articles) t)     ; Accept form
9889             (not articles)              ; Only save nov last time
9890             (and move-is-internal
9891                  to-newsgroup           ; Not respooling
9892                                         ; Is this move internal?
9893                  (gnus-group-real-name to-newsgroup)))))
9894         ;; Copy the article.
9895         ((eq action 'copy)
9896          (with-current-buffer copy-buf
9897            (when (gnus-request-article-this-buffer article
9898                                                    gnus-newsgroup-name)
9899              (save-restriction
9900                (nnheader-narrow-to-headers)
9901                (dolist (hdr gnus-copy-article-ignored-headers)
9902                  (message-remove-header hdr t)))
9903              (gnus-request-accept-article
9904               to-newsgroup select-method (not articles) t))))
9905         ;; Crosspost the article.
9906         ((eq action 'crosspost)
9907          (let ((xref (message-tokenize-header
9908                       (mail-header-xref (gnus-summary-article-header
9909                                          article))
9910                       " ")))
9911            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9912                                   ":" (number-to-string article)))
9913            (unless xref
9914              (setq xref (list (system-name))))
9915            (setq new-xref
9916                  (concat
9917                   (mapconcat 'identity
9918                              (delete "Xref:" (delete new-xref xref))
9919                              " ")
9920                   " " new-xref))
9921            (with-current-buffer copy-buf
9922              ;; First put the article in the destination group.
9923              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9924              (when (consp (setq art-group
9925                                 (gnus-request-accept-article
9926                                  to-newsgroup select-method (not articles)
9927                                  t)))
9928                (setq new-xref (concat new-xref " " (car art-group)
9929                                       ":"
9930                                       (number-to-string (cdr art-group))))
9931                ;; Now we have the new Xrefs header, so we insert
9932                ;; it and replace the new article.
9933                (nnheader-replace-header "Xref" new-xref)
9934                (gnus-request-replace-article
9935                 (cdr art-group) to-newsgroup (current-buffer) t)
9936                art-group))))))
9937       (cond
9938        ((not art-group)
9939         (gnus-message 1 "Couldn't %s article %s: %s"
9940                       (cadr (assq action names)) article
9941                       (nnheader-get-report (car to-method))))
9942        ((eq art-group 'junk)
9943         (when (eq action 'move)
9944           (gnus-summary-mark-article article gnus-canceled-mark)
9945           (gnus-message 4 "Deleted article %s" article)
9946           ;; run the delete hook
9947           (run-hook-with-args 'gnus-summary-article-delete-hook
9948                               action
9949                               (gnus-data-header
9950                                (assoc article (gnus-data-list nil)))
9951                               gnus-newsgroup-name nil
9952                               select-method)))
9953        (t
9954         (let* ((pto-group (gnus-group-prefixed-name
9955                            (car art-group) to-method))
9956                (info (gnus-get-info pto-group))
9957                (to-group (gnus-info-group info))
9958                to-marks)
9959           ;; Update the group that has been moved to.
9960           (when (and info
9961                      (memq action '(move copy)))
9962             (unless (member to-group to-groups)
9963               (push to-group to-groups))
9964
9965             (when (and (not (memq article gnus-newsgroup-unreads))
9966                        (cdr art-group))
9967               (push 'read to-marks)
9968               (gnus-info-set-read
9969                info (gnus-add-to-range (gnus-info-read info)
9970                                        (list (cdr art-group)))))
9971
9972             ;; See whether the article is to be put in the cache.
9973             (let* ((expirable (gnus-group-auto-expirable-p to-group))
9974                    (marks (if expirable
9975                               gnus-article-mark-lists
9976                             (delete '(expirable . expire)
9977                                     (copy-sequence
9978                                      gnus-article-mark-lists))))
9979                    (to-article (cdr art-group)))
9980
9981               ;; Enter the article into the cache in the new group,
9982               ;; if that is required.
9983               (when (and to-article
9984                          gnus-use-cache)
9985                 (gnus-cache-possibly-enter-article
9986                  to-group to-article
9987                  (memq article gnus-newsgroup-marked)
9988                  (memq article gnus-newsgroup-dormant)
9989                  (memq article gnus-newsgroup-unreads)))
9990
9991               (when (and gnus-preserve-marks
9992                          to-article)
9993                 ;; Copy any marks over to the new group.
9994                 (when (and (equal to-group gnus-newsgroup-name)
9995                            (not (memq article gnus-newsgroup-unreads)))
9996                   ;; Mark this article as read in this group.
9997                   (push (cons to-article gnus-read-mark)
9998                         gnus-newsgroup-reads)
9999                   ;; Increase the active status of this group.
10000                   (setcdr (gnus-active to-group) to-article)
10001                   (setcdr gnus-newsgroup-active to-article))
10002
10003                 (while marks
10004                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
10005                     (when (memq article (symbol-value
10006                                          (intern (format "gnus-newsgroup-%s"
10007                                                          (caar marks)))))
10008                       (push (cdar marks) to-marks)
10009                       ;; If the other group is the same as this group,
10010                       ;; then we have to add the mark to the list.
10011                       (when (equal to-group gnus-newsgroup-name)
10012                         (set (intern (format "gnus-newsgroup-%s"
10013                                              (caar marks)))
10014                              (cons to-article
10015                                    (symbol-value
10016                                     (intern (format "gnus-newsgroup-%s"
10017                                                     (caar marks)))))))
10018                       ;; Copy the marks to other group.
10019                       (gnus-add-marked-articles
10020                        to-group (cdar marks) (list to-article) info)))
10021                   (setq marks (cdr marks)))
10022
10023                 (when (and expirable
10024                            gnus-mark-copied-or-moved-articles-as-expirable
10025                            (not (memq 'expire to-marks)))
10026                   ;; Mark this article as expirable.
10027                   (push 'expire to-marks)
10028                   (when (equal to-group gnus-newsgroup-name)
10029                     (push to-article gnus-newsgroup-expirable))
10030                   ;; Copy the expirable mark to other group.
10031                   (gnus-add-marked-articles
10032                    to-group 'expire (list to-article) info))
10033
10034                 (when to-marks
10035                   (gnus-request-set-mark
10036                    to-group (list (list (list to-article) 'add to-marks)))))
10037
10038               (gnus-dribble-enter
10039                (concat "(gnus-group-set-info '"
10040                        (gnus-prin1-to-string (gnus-get-info to-group))
10041                        ")")
10042                (concat "^(gnus-group-set-info '(\""
10043                        (regexp-quote to-group) "\""))))
10044
10045           ;; Update the Xref header in this article to point to
10046           ;; the new crossposted article we have just created.
10047           (when (eq action 'crosspost)
10048             (with-current-buffer copy-buf
10049               (gnus-request-article-this-buffer article gnus-newsgroup-name)
10050               (nnheader-replace-header "Xref" new-xref)
10051               (gnus-request-replace-article
10052                article gnus-newsgroup-name (current-buffer) t)))
10053
10054           ;; run the move/copy/crosspost/respool hook
10055           (run-hook-with-args 'gnus-summary-article-move-hook
10056                               action
10057                               (gnus-data-header
10058                                (assoc article (gnus-data-list nil)))
10059                               gnus-newsgroup-name
10060                               to-newsgroup
10061                               select-method))
10062
10063         ;;;!!!Why is this necessary?
10064         (set-buffer gnus-summary-buffer)
10065
10066         (when (eq action 'move)
10067           (save-excursion
10068             (gnus-summary-goto-subject article)
10069             (gnus-summary-mark-article article gnus-canceled-mark)))))
10070       (push article articles-to-update-marks))
10071
10072     (save-excursion
10073       (apply 'gnus-summary-remove-process-mark articles-to-update-marks))
10074     ;; Re-activate all groups that have been moved to.
10075     (with-current-buffer gnus-group-buffer
10076       (let ((gnus-group-marked to-groups))
10077         (gnus-group-get-new-news-this-group nil t)))
10078
10079     (gnus-kill-buffer copy-buf)
10080     (gnus-summary-position-point)
10081     (gnus-set-mode-line 'summary)))
10082
10083 (defun gnus-summary-push-marks-to-backend (article)
10084   (let ((set nil)
10085         (marks gnus-article-mark-lists))
10086     (unless (memq article gnus-newsgroup-unreads)
10087       (push 'read set))
10088     (while marks
10089       (when (and (eq (gnus-article-mark-to-type (cdar marks)) 'list)
10090                  (memq article (symbol-value
10091                                 (intern (format "gnus-newsgroup-%s"
10092                                                 (caar marks))))))
10093         (push (cdar marks) set))
10094       (pop marks))
10095     (gnus-request-set-mark gnus-newsgroup-name `(((,article) set ,set)))))
10096
10097 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
10098   "Copy the current article to some other group.
10099 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
10100 When called interactively, if TO-NEWSGROUP is nil, use the value of
10101 the variable `gnus-move-split-methods' for finding a default target
10102 newsgroup.
10103 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
10104 re-spool using this method."
10105   (interactive "P")
10106   (gnus-summary-move-article n to-newsgroup select-method 'copy))
10107
10108 (defun gnus-summary-crosspost-article (&optional n)
10109   "Crosspost the current article to some other group."
10110   (interactive "P")
10111   (gnus-summary-move-article n nil nil 'crosspost))
10112
10113 (defcustom gnus-summary-respool-default-method nil
10114   "Default method type for respooling an article.
10115 If nil, use to the current newsgroup method."
10116   :type 'symbol
10117   :group 'gnus-summary-mail)
10118
10119 (defun gnus-summary-respool-article (&optional n method)
10120   "Respool the current article.
10121 The article will be squeezed through the mail spooling process again,
10122 which means that it will be put in some mail newsgroup or other
10123 depending on `nnmail-split-methods'.
10124 If N is a positive number, respool the N next articles.
10125 If N is a negative number, respool the N previous articles.
10126 If N is nil and any articles have been marked with the process mark,
10127 respool those articles instead.
10128
10129 Respooling can be done both from mail groups and \"real\" newsgroups.
10130 In the former case, the articles in question will be moved from the
10131 current group into whatever groups they are destined to.  In the
10132 latter case, they will be copied into the relevant groups."
10133   (interactive
10134    (list current-prefix-arg
10135          (let* ((methods (mapcar #'car (gnus-methods-using 'respool)))
10136                 (methname
10137                  (symbol-name (or gnus-summary-respool-default-method
10138                                   (car (gnus-find-method-for-group
10139                                         gnus-newsgroup-name)))))
10140                 (method
10141                  (gnus-completing-read
10142                   "Backend to use when respooling"
10143                   methods t nil 'gnus-mail-method-history methname))
10144                 ms)
10145            (cond
10146             ((zerop (length (setq ms (gnus-servers-using-backend
10147                                       (intern method)))))
10148              (list (intern method) ""))
10149             ((= 1 (length ms))
10150              (car ms))
10151             (t
10152              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
10153                (cdr (assoc (gnus-completing-read "Server name" ms-alist t)
10154                            ms-alist))))))))
10155   (unless method
10156     (error "No method given for respooling"))
10157   (if (assoc (symbol-name
10158               (car (gnus-find-method-for-group gnus-newsgroup-name)))
10159              (gnus-methods-using 'respool))
10160       (gnus-summary-move-article n nil method)
10161     (gnus-summary-copy-article n nil method)))
10162
10163 (defun gnus-summary-import-article (file &optional edit)
10164   "Import an arbitrary file into a mail newsgroup."
10165   (interactive "fImport file: \nP")
10166   (let ((group gnus-newsgroup-name)
10167         (now (current-time))
10168         atts lines group-art)
10169     (unless (gnus-check-backend-function 'request-accept-article group)
10170       (error "%s does not support article importing" group))
10171     (or (file-readable-p file)
10172         (not (file-regular-p file))
10173         (error "Can't read %s" file))
10174     (with-current-buffer (gnus-get-buffer-create " *import file*")
10175       (erase-buffer)
10176       (nnheader-insert-file-contents file)
10177       (goto-char (point-min))
10178       (if (nnheader-article-p)
10179           (save-restriction
10180             (goto-char (point-min))
10181             (search-forward "\n\n" nil t)
10182             (narrow-to-region (point-min) (1- (point)))
10183             (goto-char (point-min))
10184             (unless (re-search-forward "^date:" nil t)
10185               (goto-char (point-max))
10186               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
10187        ;; This doesn't look like an article, so we fudge some headers.
10188         (setq atts (file-attributes file)
10189               lines (count-lines (point-min) (point-max)))
10190         (insert "From: " (read-string "From: ") "\n"
10191                 "Subject: " (read-string "Subject: ") "\n"
10192                 "Date: " (message-make-date (nth 5 atts)) "\n"
10193                 "Message-ID: " (message-make-message-id) "\n"
10194                 "Lines: " (int-to-string lines) "\n"
10195                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
10196       (setq group-art (gnus-request-accept-article group nil t))
10197       (kill-buffer (current-buffer)))
10198     (setq gnus-newsgroup-active (gnus-activate-group group))
10199     (forward-line 1)
10200     (gnus-summary-goto-article (cdr group-art) nil t)
10201     (when edit
10202       (gnus-summary-edit-article))))
10203
10204 (defun gnus-summary-create-article ()
10205   "Create an article in a mail newsgroup."
10206   (interactive)
10207   (let ((group gnus-newsgroup-name)
10208         (now (current-time))
10209         group-art)
10210     (unless (gnus-check-backend-function 'request-accept-article group)
10211       (error "%s does not support article importing" group))
10212     (with-current-buffer (gnus-get-buffer-create " *import file*")
10213       (erase-buffer)
10214       (goto-char (point-min))
10215       ;; This doesn't look like an article, so we fudge some headers.
10216       (insert "From: " (read-string "From: ") "\n"
10217               "Subject: " (read-string "Subject: ") "\n"
10218               "Date: " (message-make-date now) "\n"
10219               "Message-ID: " (message-make-message-id) "\n")
10220       (setq group-art (gnus-request-accept-article group nil t))
10221       (kill-buffer (current-buffer)))
10222     (setq gnus-newsgroup-active (gnus-activate-group group))
10223     (forward-line 1)
10224     (gnus-summary-goto-article (cdr group-art) nil t)
10225     (gnus-summary-edit-article)))
10226
10227 (defun gnus-summary-article-posted-p ()
10228   "Say whether the current (mail) article is available from news as well.
10229 This will be the case if the article has both been mailed and posted."
10230   (interactive)
10231   (let ((id (mail-header-references (gnus-summary-article-header)))
10232         (gnus-override-method (car (gnus-refer-article-methods))))
10233     (if (gnus-request-head id "")
10234         (gnus-message 2 "The current message was found on %s"
10235                       gnus-override-method)
10236       (gnus-message 2 "The current message couldn't be found on %s"
10237                     gnus-override-method)
10238       nil)))
10239
10240 (defun gnus-summary-expire-articles (&optional now)
10241   "Expire all articles that are marked as expirable in the current group."
10242   (interactive)
10243   (when (and (not gnus-group-is-exiting-without-update-p)
10244              (gnus-check-backend-function
10245               'request-expire-articles gnus-newsgroup-name))
10246     ;; This backend supports expiry.
10247     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
10248            (expirable (if total
10249                           (progn
10250                             ;; We need to update the info for
10251                             ;; this group for `gnus-list-of-read-articles'
10252                             ;; to give us the right answer.
10253                             (gnus-run-hooks 'gnus-exit-group-hook)
10254                             (gnus-summary-update-info)
10255                             (gnus-list-of-read-articles gnus-newsgroup-name))
10256                         (setq gnus-newsgroup-expirable
10257                               (sort gnus-newsgroup-expirable '<))))
10258            (expiry-wait (if now 'immediate
10259                           (gnus-group-find-parameter
10260                            gnus-newsgroup-name 'expiry-wait)))
10261            (nnmail-expiry-target
10262             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
10263                 nnmail-expiry-target))
10264            es)
10265       (when expirable
10266         ;; There are expirable articles in this group, so we run them
10267         ;; through the expiry process.
10268         (gnus-message 6 "Expiring articles...")
10269         (unless (gnus-check-group gnus-newsgroup-name)
10270           (error "Can't open server for %s" gnus-newsgroup-name))
10271         ;; The list of articles that weren't expired is returned.
10272         (save-excursion
10273           (if expiry-wait
10274               (let ((nnmail-expiry-wait-function nil)
10275                     (nnmail-expiry-wait expiry-wait))
10276                 (setq es (gnus-request-expire-articles
10277                           expirable gnus-newsgroup-name)))
10278             (setq es (gnus-request-expire-articles
10279                       expirable gnus-newsgroup-name)))
10280           (unless total
10281             (setq gnus-newsgroup-expirable es))
10282           ;; We go through the old list of expirable, and mark all
10283           ;; really expired articles as nonexistent.
10284           (unless (eq es expirable) ;If nothing was expired, we don't mark.
10285             (let ((gnus-use-cache nil))
10286               (dolist (article expirable)
10287                 (when (and (not (memq article es))
10288                            (gnus-data-find article))
10289                   (gnus-summary-mark-article article gnus-canceled-mark)
10290                   (run-hook-with-args 'gnus-summary-article-expire-hook
10291                                       'delete
10292                                       (gnus-data-header
10293                                        (assoc article (gnus-data-list nil)))
10294                                       gnus-newsgroup-name
10295                                       nil
10296                                       nil))))))
10297         (gnus-message 6 "Expiring articles...done")))))
10298
10299 (defun gnus-summary-expire-articles-now ()
10300   "Expunge all expirable articles in the current group.
10301 This means that *all* articles that are marked as expirable will be
10302 deleted forever, right now."
10303   (interactive)
10304   (or gnus-expert-user
10305       (gnus-yes-or-no-p
10306        "Are you really, really sure you want to delete all expirable messages? ")
10307       (error "Phew!"))
10308   (gnus-summary-expire-articles t))
10309
10310 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10311 (defun gnus-summary-delete-article (&optional n)
10312   "Delete the N next (mail) articles.
10313 This command actually deletes articles.  This is not a marking
10314 command.  The article will disappear forever from your life, never to
10315 return.
10316
10317 If N is negative, delete backwards.
10318 If N is nil and articles have been marked with the process mark,
10319 delete these instead.
10320
10321 If `gnus-novice-user' is non-nil you will be asked for
10322 confirmation before the articles are deleted."
10323   (interactive "P")
10324   (unless (gnus-check-backend-function 'request-expire-articles
10325                                        gnus-newsgroup-name)
10326     (error "The current newsgroup does not support article deletion"))
10327   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10328     (error "Couldn't open server"))
10329   ;; Compute the list of articles to delete.
10330   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10331         (nnmail-expiry-target 'delete)
10332         not-deleted)
10333     (if (and gnus-novice-user
10334              (not (gnus-yes-or-no-p
10335                    (format "Do you really want to delete %s forever? "
10336                            (if (> (length articles) 1)
10337                                (format "these %s articles" (length articles))
10338                              "this article")))))
10339         ()
10340       ;; Delete the articles.
10341       (setq not-deleted (gnus-request-expire-articles
10342                          articles gnus-newsgroup-name 'force))
10343       (save-excursion
10344         (while articles
10345           (gnus-summary-remove-process-mark (car articles))
10346           ;; The backend might not have been able to delete the article
10347           ;; after all.
10348           (unless (memq (car articles) not-deleted)
10349             (gnus-summary-mark-article (car articles) gnus-canceled-mark)
10350             (let* ((article (car articles))
10351                    (ghead  (gnus-data-header
10352                             (assoc article (gnus-data-list nil)))))
10353               (run-hook-with-args 'gnus-summary-article-delete-hook
10354                                   'delete ghead gnus-newsgroup-name nil
10355                                   nil)))
10356           (setq articles (cdr articles))))
10357       (when not-deleted
10358         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10359     (gnus-summary-position-point)
10360     (gnus-set-mode-line 'summary)
10361     not-deleted))
10362
10363 (defun gnus-summary-edit-article (&optional arg)
10364   "Edit the current article.
10365 This will have permanent effect only in mail groups.
10366 If ARG is nil, edit the decoded articles.
10367 If ARG is 1, edit the raw articles.
10368 If ARG is 2, edit the raw articles even in read-only groups.
10369 If ARG is 3, edit the articles with the current handles.
10370 Otherwise, allow editing of articles even in read-only
10371 groups."
10372   (interactive "P")
10373   (let (force raw current-handles)
10374     (cond
10375      ((null arg))
10376      ((eq arg 1)
10377       (setq raw t))
10378      ((eq arg 2)
10379       (setq raw t
10380             force t))
10381      ((eq arg 3)
10382       (setq current-handles
10383             (and (gnus-buffer-live-p gnus-article-buffer)
10384                  (with-current-buffer gnus-article-buffer
10385                    (prog1
10386                        gnus-article-mime-handles
10387                      (setq gnus-article-mime-handles nil))))))
10388      (t
10389       (setq force t)))
10390     (when (and raw (not force)
10391                (member gnus-newsgroup-name '("nndraft:delayed"
10392                                              "nndraft:drafts"
10393                                              "nndraft:queue")))
10394       (error "Can't edit the raw article in group %s"
10395              gnus-newsgroup-name))
10396     (with-current-buffer gnus-summary-buffer
10397       (let ((mail-parse-charset gnus-newsgroup-charset)
10398             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10399         (gnus-set-global-variables)
10400         (when (and (not force)
10401                    (gnus-group-read-only-p))
10402           (error "The current newsgroup does not support article editing"))
10403         (gnus-summary-show-article t)
10404         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10405           (with-current-buffer gnus-article-buffer
10406             (mm-enable-multibyte)))
10407         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10408             (setq raw t))
10409         (gnus-article-edit-article
10410          (if raw 'ignore
10411            `(lambda ()
10412               (let ((mbl mml-buffer-list))
10413                 (setq mml-buffer-list nil)
10414                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10415                   (mime-to-mml ,'current-handles))
10416                 (let ((mbl1 mml-buffer-list))
10417                   (setq mml-buffer-list mbl)
10418                   (set (make-local-variable 'mml-buffer-list) mbl1))
10419                 (gnus-make-local-hook 'kill-buffer-hook)
10420                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10421          `(lambda (no-highlight)
10422             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10423                   (message-options message-options)
10424                   (message-options-set-recipient)
10425                   (mail-parse-ignored-charsets
10426                    ',gnus-newsgroup-ignored-charsets)
10427                   (rfc2047-header-encoding-alist
10428                    ',(let ((charset (gnus-group-name-charset
10429                                      (gnus-find-method-for-group
10430                                       gnus-newsgroup-name)
10431                                      gnus-newsgroup-name)))
10432                        (append (list (cons "Newsgroups" charset)
10433                                      (cons "Followup-To" charset)
10434                                      (cons "Xref" charset))
10435                                rfc2047-header-encoding-alist))))
10436               ,(if (not raw) '(progn
10437                                 (mml-to-mime)
10438                                 (mml-destroy-buffers)
10439                                 (remove-hook 'kill-buffer-hook
10440                                              'mml-destroy-buffers t)
10441                                 (kill-local-variable 'mml-buffer-list)))
10442               (gnus-summary-edit-article-done
10443                ,(or (mail-header-references gnus-current-headers) "")
10444                ,(gnus-group-read-only-p)
10445                ,gnus-summary-buffer no-highlight))))))))
10446
10447 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10448
10449 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10450                                                  no-highlight)
10451   "Make edits to the current article permanent."
10452   (interactive)
10453   (save-excursion
10454     ;; The buffer restriction contains the entire article if it exists.
10455     (when (article-goto-body)
10456       (let ((lines (count-lines (point) (point-max)))
10457             (length (- (point-max) (point)))
10458             (case-fold-search t)
10459             (body (copy-marker (point))))
10460         (goto-char (point-min))
10461         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10462           (delete-region (match-beginning 1) (match-end 1))
10463           (insert (number-to-string length)))
10464         (goto-char (point-min))
10465         (when (re-search-forward
10466                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10467           (delete-region (match-beginning 1) (match-end 1))
10468           (insert (number-to-string length)))
10469         (goto-char (point-min))
10470         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10471           (delete-region (match-beginning 1) (match-end 1))
10472           (insert (number-to-string lines))))))
10473   ;; Replace the article.
10474   (let ((buf (current-buffer))
10475         (article (cdr gnus-article-current))
10476         replace-result)
10477     (with-temp-buffer
10478       (insert-buffer-substring buf)
10479       (if (and (not read-only)
10480                (not (setq replace-result
10481                           (gnus-request-replace-article
10482                            article (car gnus-article-current)
10483                            (current-buffer) t))))
10484           (error "Couldn't replace article")
10485         ;; If we got a number back, then that's the new article number
10486         ;; for this article.  Otherwise, the article number didn't change.
10487         (when (numberp replace-result)
10488           (with-current-buffer gnus-summary-buffer
10489             (setq gnus-newsgroup-limit (delq article gnus-newsgroup-limit))
10490             (gnus-summary-limit gnus-newsgroup-limit)
10491             (setq article replace-result)
10492             (gnus-summary-goto-subject article t)))
10493         ;; Update the summary buffer.
10494         (if (and references
10495                  (equal (message-tokenize-header references " ")
10496                         (message-tokenize-header
10497                          (or (message-fetch-field "references") "") " ")))
10498             ;; We only have to update this line.
10499             (save-excursion
10500               (save-restriction
10501                 (message-narrow-to-head)
10502                 (let ((head (buffer-substring-no-properties
10503                              (point-min) (point-max)))
10504                       header)
10505                   (with-temp-buffer
10506                     (insert (format "211 %d Article retrieved.\n" article))
10507                     (insert head)
10508                     (insert ".\n")
10509                     (let ((nntp-server-buffer (current-buffer)))
10510                       (setq header (car (gnus-get-newsgroup-headers nil t))))
10511                     (with-current-buffer gnus-summary-buffer
10512                       (gnus-data-set-header (gnus-data-find article) header)
10513                       (gnus-summary-update-article-line article header)
10514                       (if (gnus-summary-goto-subject article nil t)
10515                           (gnus-summary-update-secondary-mark article)))))))
10516           ;; Update threads.
10517           (set-buffer (or buffer gnus-summary-buffer))
10518           (gnus-summary-update-article article)
10519           (if (gnus-summary-goto-subject article nil t)
10520               (gnus-summary-update-secondary-mark article)))
10521         ;; Prettify the article buffer again.
10522         (unless no-highlight
10523           (with-current-buffer gnus-article-buffer
10524             ;;!!! Fix this -- article should be rehighlighted.
10525             ;;(gnus-run-hooks 'gnus-article-display-hook)
10526             (set-buffer gnus-original-article-buffer)
10527             (gnus-request-article
10528              article (car gnus-article-current) (current-buffer))))
10529         ;; Prettify the summary buffer line.
10530         (when (gnus-visual-p 'summary-highlight 'highlight)
10531           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10532
10533 (defun gnus-summary-edit-wash (key)
10534   "Perform editing command KEY in the article buffer."
10535   (interactive
10536    (list
10537     (progn
10538       (message "%s" (concat (this-command-keys) "- "))
10539       (read-char))))
10540   (message "")
10541   (gnus-summary-edit-article)
10542   (execute-kbd-macro (concat (this-command-keys) key))
10543   (gnus-article-edit-done))
10544
10545 ;;; Respooling
10546
10547 (defun gnus-summary-respool-query (&optional silent trace)
10548   "Query where the respool algorithm would put this article."
10549   (interactive)
10550   (let (gnus-mark-article-hook)
10551     (gnus-summary-select-article)
10552     (with-current-buffer gnus-original-article-buffer
10553       (let ((groups (nnmail-article-group 'identity trace)))
10554         (unless silent
10555           (if groups
10556               (message "This message would go to %s"
10557                        (mapconcat 'car groups ", "))
10558             (message "This message would go to no groups"))
10559           groups)))))
10560
10561 (defun gnus-summary-respool-trace ()
10562   "Trace where the respool algorithm would put this article.
10563 Display a buffer showing all fancy splitting patterns which matched."
10564   (interactive)
10565   (gnus-summary-respool-query nil t))
10566
10567 ;; Summary marking commands.
10568
10569 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10570   "Mark articles which has the same subject as read, and then select the next.
10571 If UNMARK is positive, remove any kind of mark.
10572 If UNMARK is negative, tick articles."
10573   (interactive "P")
10574   (when unmark
10575     (setq unmark (prefix-numeric-value unmark)))
10576   (let ((count
10577          (gnus-summary-mark-same-subject
10578           (gnus-summary-article-subject) unmark)))
10579     ;; Select next unread article.  If auto-select-same mode, should
10580     ;; select the first unread article.
10581     (gnus-summary-next-article t (and gnus-auto-select-same
10582                                       (gnus-summary-article-subject)))
10583     (gnus-message 7 "%d article%s marked as %s"
10584                   count (if (= count 1) " is" "s are")
10585                   (if unmark "unread" "read"))))
10586
10587 (defun gnus-summary-kill-same-subject (&optional unmark)
10588   "Mark articles which has the same subject as read.
10589 If UNMARK is positive, remove any kind of mark.
10590 If UNMARK is negative, tick articles."
10591   (interactive "P")
10592   (when unmark
10593     (setq unmark (prefix-numeric-value unmark)))
10594   (let ((count
10595          (gnus-summary-mark-same-subject
10596           (gnus-summary-article-subject) unmark)))
10597     ;; If marked as read, go to next unread subject.
10598     (when (null unmark)
10599       ;; Go to next unread subject.
10600       (gnus-summary-next-subject 1 t))
10601     (gnus-message 7 "%d articles are marked as %s"
10602                   count (if unmark "unread" "read"))))
10603
10604 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10605   "Mark articles with same SUBJECT as read, and return marked number.
10606 If optional argument UNMARK is positive, remove any kinds of marks.
10607 If optional argument UNMARK is negative, mark articles as unread instead."
10608   (let ((count 1))
10609     (save-excursion
10610       (cond
10611        ((null unmark)                   ; Mark as read.
10612         (while (and
10613                 (progn
10614                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10615                   (gnus-summary-show-thread) t)
10616                 (gnus-summary-find-subject subject))
10617           (setq count (1+ count))))
10618        ((> unmark 0)                    ; Tick.
10619         (while (and
10620                 (progn
10621                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10622                   (gnus-summary-show-thread) t)
10623                 (gnus-summary-find-subject subject))
10624           (setq count (1+ count))))
10625        (t                               ; Mark as unread.
10626         (while (and
10627                 (progn
10628                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10629                   (gnus-summary-show-thread) t)
10630                 (gnus-summary-find-subject subject))
10631           (setq count (1+ count)))))
10632       (gnus-set-mode-line 'summary)
10633       ;; Return the number of marked articles.
10634       count)))
10635
10636 (defun gnus-summary-mark-as-processable (n &optional unmark)
10637   "Set the process mark on the next N articles.
10638 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10639 the process mark instead.  The difference between N and the actual
10640 number of articles marked is returned."
10641   (interactive "P")
10642   (if (and (null n) (gnus-region-active-p))
10643       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10644     (setq n (prefix-numeric-value n))
10645     (let ((backward (< n 0))
10646           (n (abs n)))
10647       (while (and
10648               (> n 0)
10649               (if unmark
10650                   (gnus-summary-remove-process-mark
10651                    (gnus-summary-article-number))
10652                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10653               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10654         (setq n (1- n)))
10655       (when (/= 0 n)
10656         (gnus-message 7 "No more articles"))
10657       (gnus-summary-recenter)
10658       (gnus-summary-position-point)
10659       n)))
10660
10661 (defun gnus-summary-unmark-as-processable (n)
10662   "Remove the process mark from the next N articles.
10663 If N is negative, unmark backward instead.  The difference between N and
10664 the actual number of articles unmarked is returned."
10665   (interactive "P")
10666   (gnus-summary-mark-as-processable n t))
10667
10668 (defun gnus-summary-unmark-all-processable ()
10669   "Remove the process mark from all articles."
10670   (interactive)
10671   (save-excursion
10672     (while gnus-newsgroup-processable
10673       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10674   (gnus-summary-position-point))
10675
10676 (defun gnus-summary-add-mark (article type)
10677   "Mark ARTICLE with a mark of TYPE."
10678   (let ((vtype (car (assq type gnus-article-mark-lists)))
10679         var)
10680     (if (not vtype)
10681         (error "No such mark type: %s" type)
10682       (setq var (intern (format "gnus-newsgroup-%s" type)))
10683       (set var (cons article (symbol-value var)))
10684       (if (memq type '(processable cached replied forwarded recent saved))
10685           (gnus-summary-update-secondary-mark article)
10686         ;;; !!! This is bogus.  We should find out what primary
10687         ;;; !!! mark we want to set.
10688         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10689
10690 (defun gnus-summary-mark-as-expirable (n)
10691   "Mark N articles forward as expirable.
10692 If N is negative, mark backward instead.  The difference between N and
10693 the actual number of articles marked is returned."
10694   (interactive "p")
10695   (gnus-summary-mark-forward n gnus-expirable-mark))
10696
10697 (defun gnus-summary-mark-as-spam (n)
10698   "Mark N articles forward as spam.
10699 If N is negative, mark backward instead.  The difference between N and
10700 the actual number of articles marked is returned."
10701   (interactive "p")
10702   (gnus-summary-mark-forward n gnus-spam-mark))
10703
10704 (defun gnus-summary-mark-article-as-replied (article)
10705   "Mark ARTICLE as replied to and update the summary line.
10706 ARTICLE can also be a list of articles."
10707   (interactive (list (gnus-summary-article-number)))
10708   (let ((articles (if (listp article) article (list article))))
10709     (dolist (article articles)
10710       (unless (numberp article)
10711         (error "%s is not a number" article))
10712       (push article gnus-newsgroup-replied)
10713       (let ((inhibit-read-only t))
10714         (when (gnus-summary-goto-subject article nil t)
10715           (gnus-summary-update-secondary-mark article))))))
10716
10717 (defun gnus-summary-mark-article-as-forwarded (article)
10718   "Mark ARTICLE as forwarded and update the summary line.
10719 ARTICLE can also be a list of articles."
10720   (let ((articles (if (listp article) article (list article))))
10721     (dolist (article articles)
10722       (push article gnus-newsgroup-forwarded)
10723       (let ((inhibit-read-only t))
10724         (when (gnus-summary-goto-subject article nil t)
10725           (gnus-summary-update-secondary-mark article))))))
10726
10727 (defun gnus-summary-set-bookmark (article)
10728   "Set a bookmark in current article."
10729   (interactive (list (gnus-summary-article-number)))
10730   (when (or (not (get-buffer gnus-article-buffer))
10731             (not gnus-current-article)
10732             (not gnus-article-current)
10733             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10734     (error "No current article selected"))
10735   ;; Remove old bookmark, if one exists.
10736   (gnus-alist-pull article gnus-newsgroup-bookmarks)
10737   ;; Set the new bookmark, which is on the form
10738   ;; (article-number . line-number-in-body).
10739   (push
10740    (cons article
10741          (with-current-buffer gnus-article-buffer
10742            (count-lines
10743             (min (point)
10744                  (save-excursion
10745                    (article-goto-body)
10746                    (point)))
10747             (point))))
10748    gnus-newsgroup-bookmarks)
10749   (gnus-message 6 "A bookmark has been added to the current article."))
10750
10751 (defun gnus-summary-remove-bookmark (article)
10752   "Remove the bookmark from the current article."
10753   (interactive (list (gnus-summary-article-number)))
10754   ;; Remove old bookmark, if one exists.
10755   (if (not (assq article gnus-newsgroup-bookmarks))
10756       (gnus-message 6 "No bookmark in current article.")
10757     (gnus-alist-pull article gnus-newsgroup-bookmarks)
10758     (gnus-message 6 "Removed bookmark.")))
10759
10760 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10761 (defun gnus-summary-mark-as-dormant (n)
10762   "Mark N articles forward as dormant.
10763 If N is negative, mark backward instead.  The difference between N and
10764 the actual number of articles marked is returned."
10765   (interactive "p")
10766   (gnus-summary-mark-forward n gnus-dormant-mark))
10767
10768 (defun gnus-summary-set-process-mark (article)
10769   "Set the process mark on ARTICLE and update the summary line."
10770   (setq gnus-newsgroup-processable
10771         (cons article
10772               (delq article gnus-newsgroup-processable)))
10773   (when (gnus-summary-goto-subject article)
10774     (gnus-summary-show-thread)
10775     (gnus-summary-goto-subject article)
10776     (gnus-summary-update-secondary-mark article)))
10777
10778 (defun gnus-summary-remove-process-mark (&rest articles)
10779   "Remove the process mark from ARTICLES and update the summary line."
10780   (dolist (article articles)
10781     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10782     (when (gnus-summary-goto-subject article)
10783       (gnus-summary-show-thread)
10784       (gnus-summary-goto-subject article)
10785       (gnus-summary-update-secondary-mark article)))
10786   t)
10787
10788 (defun gnus-summary-set-saved-mark (article)
10789   "Set the process mark on ARTICLE and update the summary line."
10790   (push article gnus-newsgroup-saved)
10791   (when (gnus-summary-goto-subject article)
10792     (gnus-summary-update-secondary-mark article)))
10793
10794 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10795   "Mark N articles as read forwards.
10796 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10797 The difference between N and the actual number of articles marked is
10798 returned.
10799 If NO-EXPIRE, auto-expiry will be inhibited."
10800   (interactive "p")
10801   (gnus-summary-show-thread)
10802   (let ((backward (< n 0))
10803         (gnus-summary-goto-unread
10804          (and gnus-summary-goto-unread
10805               (not (eq gnus-summary-goto-unread 'never))
10806               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10807                                     gnus-ticked-mark gnus-dormant-mark)))))
10808         (n (abs n))
10809         (mark (or mark gnus-del-mark)))
10810     (while (and (> n 0)
10811                 (gnus-summary-mark-article nil mark no-expire)
10812                 (zerop (gnus-summary-next-subject
10813                         (if backward -1 1)
10814                         (and gnus-summary-goto-unread
10815                              (not (eq gnus-summary-goto-unread 'never)))
10816                         t)))
10817       (setq n (1- n)))
10818     (when (/= 0 n)
10819       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10820     (gnus-summary-recenter)
10821     (gnus-summary-position-point)
10822     (gnus-set-mode-line 'summary)
10823     n))
10824
10825 (defun gnus-summary-mark-article-as-read (mark)
10826   "Mark the current article quickly as read with MARK."
10827   (let ((article (gnus-summary-article-number)))
10828     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10829     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10830     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10831     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10832     (push (cons article mark) gnus-newsgroup-reads)
10833     ;; Possibly remove from cache, if that is used.
10834     (when gnus-use-cache
10835       (gnus-cache-enter-remove-article article))
10836     ;; Allow the backend to change the mark.
10837     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10838     ;; Check for auto-expiry.
10839     (when (and gnus-newsgroup-auto-expire
10840                (memq mark gnus-auto-expirable-marks))
10841       (setq mark gnus-expirable-mark)
10842       ;; Let the backend know about the mark change.
10843       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10844       (push article gnus-newsgroup-expirable))
10845     ;; Set the mark in the buffer.
10846     (gnus-summary-update-mark mark 'unread)
10847     t))
10848
10849 (defun gnus-summary-mark-article-as-unread (mark)
10850   "Mark the current article quickly as unread with MARK."
10851   (let* ((article (gnus-summary-article-number))
10852          (old-mark (gnus-summary-article-mark article)))
10853     ;; Allow the backend to change the mark.
10854     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10855     (if (eq mark old-mark)
10856         t
10857       (if (<= article 0)
10858           (progn
10859             (gnus-error 1 "Can't mark negative article numbers")
10860             nil)
10861         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10862         (setq gnus-newsgroup-spam-marked
10863               (delq article gnus-newsgroup-spam-marked))
10864         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10865         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10866         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10867         (cond ((= mark gnus-ticked-mark)
10868                (setq gnus-newsgroup-marked
10869                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10870                                               article)))
10871               ((= mark gnus-spam-mark)
10872                (setq gnus-newsgroup-spam-marked
10873                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10874                                               article)))
10875               ((= mark gnus-dormant-mark)
10876                (setq gnus-newsgroup-dormant
10877                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10878                                               article)))
10879               (t
10880                (setq gnus-newsgroup-unreads
10881                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10882                                               article))))
10883         (gnus-alist-pull article gnus-newsgroup-reads)
10884
10885         ;; See whether the article is to be put in the cache.
10886         (and gnus-use-cache
10887              (vectorp (gnus-summary-article-header article))
10888              (save-excursion
10889                (gnus-cache-possibly-enter-article
10890                 gnus-newsgroup-name article
10891                 (= mark gnus-ticked-mark)
10892                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10893
10894         ;; Fix the mark.
10895         (gnus-summary-update-mark mark 'unread)
10896         t))))
10897
10898 (defun gnus-summary-mark-article (&optional article mark no-expire)
10899   "Mark ARTICLE with MARK.  MARK can be any character.
10900 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10901 `??' (dormant) and `?E' (expirable).
10902 If MARK is nil, then the default character `?r' is used.
10903 If ARTICLE is nil, then the article on the current line will be
10904 marked.
10905 If NO-EXPIRE, auto-expiry will be inhibited."
10906   ;; The mark might be a string.
10907   (when (stringp mark)
10908     (setq mark (aref mark 0)))
10909   ;; If no mark is given, then we check auto-expiring.
10910   (when (null mark)
10911     (setq mark gnus-del-mark))
10912   (when (and (not no-expire)
10913              gnus-newsgroup-auto-expire
10914              (memq mark gnus-auto-expirable-marks))
10915     (setq mark gnus-expirable-mark))
10916   (let ((article (or article (gnus-summary-article-number)))
10917         (old-mark (gnus-summary-article-mark article)))
10918     ;; Allow the backend to change the mark.
10919     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10920     (if (eq mark old-mark)
10921         t
10922       (unless article
10923         (error "No article on current line"))
10924       (if (not (if (or (= mark gnus-unread-mark)
10925                        (= mark gnus-ticked-mark)
10926                        (= mark gnus-spam-mark)
10927                        (= mark gnus-dormant-mark))
10928                    (gnus-mark-article-as-unread article mark)
10929                  (gnus-mark-article-as-read article mark)))
10930           t
10931         ;; See whether the article is to be put in the cache.
10932         (and gnus-use-cache
10933              (not (= mark gnus-canceled-mark))
10934              (vectorp (gnus-summary-article-header article))
10935              (save-excursion
10936                (gnus-cache-possibly-enter-article
10937                 gnus-newsgroup-name article
10938                 (= mark gnus-ticked-mark)
10939                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10940
10941         (when (gnus-summary-goto-subject article nil t)
10942           (let ((inhibit-read-only t))
10943             (gnus-summary-show-thread)
10944             ;; Fix the mark.
10945             (gnus-summary-update-mark mark 'unread)
10946             t))))))
10947
10948 (defun gnus-summary-update-secondary-mark (article)
10949   "Update the secondary (read, process, cache) mark."
10950   (gnus-summary-update-mark
10951    (cond ((memq article gnus-newsgroup-processable)
10952           gnus-process-mark)
10953          ((memq article gnus-newsgroup-cached)
10954           gnus-cached-mark)
10955          ((memq article gnus-newsgroup-replied)
10956           gnus-replied-mark)
10957          ((memq article gnus-newsgroup-forwarded)
10958           gnus-forwarded-mark)
10959          ((memq article gnus-newsgroup-saved)
10960           gnus-saved-mark)
10961          ((memq article gnus-newsgroup-recent)
10962           gnus-recent-mark)
10963          ((memq article gnus-newsgroup-unseen)
10964           gnus-unseen-mark)
10965          (t gnus-no-mark))
10966    'replied)
10967   (when (gnus-visual-p 'summary-highlight 'highlight)
10968     (gnus-summary-highlight-line)
10969     (gnus-run-hooks 'gnus-summary-update-hook))
10970   t)
10971
10972 (defun gnus-summary-update-download-mark (article)
10973   "Update the download mark."
10974   (gnus-summary-update-mark
10975    (cond ((memq article gnus-newsgroup-undownloaded)
10976           gnus-undownloaded-mark)
10977          (gnus-newsgroup-agentized
10978           gnus-downloaded-mark)
10979          (t
10980           gnus-no-mark))
10981    'download)
10982   (gnus-summary-update-line t)
10983   t)
10984
10985 (defun gnus-summary-update-mark (mark type)
10986   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10987         (inhibit-read-only t))
10988     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10989     (when forward
10990       (when (looking-at "\r")
10991         (incf forward))
10992       (when (<= (+ forward (point)) (point-max))
10993         ;; Go to the right position on the line.
10994         (goto-char (+ forward (point)))
10995         ;; Replace the old mark with the new mark.
10996         (let ((to-insert
10997                (mm-subst-char-in-string
10998                 (char-after) mark
10999                 (buffer-substring (point) (1+ (point))))))
11000           (delete-region (point) (1+ (point)))
11001           (insert to-insert))
11002         ;; Optionally update the marks by some user rule.
11003         (when (eq type 'unread)
11004           (gnus-data-set-mark
11005            (gnus-data-find (gnus-summary-article-number)) mark)
11006           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
11007
11008 (defun gnus-mark-article-as-read (article &optional mark)
11009   "Enter ARTICLE in the pertinent lists and remove it from others."
11010   ;; Make the article expirable.
11011   (let ((mark (or mark gnus-del-mark)))
11012     (setq gnus-newsgroup-expirable
11013           (if (= mark gnus-expirable-mark)
11014               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
11015             (delq article gnus-newsgroup-expirable)))
11016     ;; Remove from unread and marked lists.
11017     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
11018     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
11019     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
11020     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
11021     (push (cons article mark) gnus-newsgroup-reads)
11022     ;; Possibly remove from cache, if that is used.
11023     (when gnus-use-cache
11024       (gnus-cache-enter-remove-article article))
11025     t))
11026
11027 (defun gnus-mark-article-as-unread (article &optional mark)
11028   "Enter ARTICLE in the pertinent lists and remove it from others."
11029   (let ((mark (or mark gnus-ticked-mark)))
11030     (if (<= article 0)
11031         (progn
11032           (gnus-error 1 "Can't mark negative article numbers")
11033           nil)
11034       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
11035             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
11036             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
11037             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
11038             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
11039
11040       ;; Unsuppress duplicates?
11041       (when gnus-suppress-duplicates
11042         (gnus-dup-unsuppress-article article))
11043
11044       (cond ((= mark gnus-ticked-mark)
11045              (setq gnus-newsgroup-marked
11046                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
11047             ((= mark gnus-spam-mark)
11048              (setq gnus-newsgroup-spam-marked
11049                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
11050                                             article)))
11051             ((= mark gnus-dormant-mark)
11052              (setq gnus-newsgroup-dormant
11053                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
11054             (t
11055              (setq gnus-newsgroup-unreads
11056                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
11057       (gnus-alist-pull article gnus-newsgroup-reads)
11058       t)))
11059
11060 (defun gnus-summary-tick-article-forward (n)
11061   "Tick N articles forwards.
11062 If N is negative, tick backwards instead.
11063 The difference between N and the number of articles ticked is returned."
11064   (interactive "p")
11065   (gnus-summary-mark-forward n gnus-ticked-mark))
11066
11067 (defun gnus-summary-tick-article-backward (n)
11068   "Tick N articles backwards.
11069 The difference between N and the number of articles ticked is returned."
11070   (interactive "p")
11071   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
11072
11073 (defun gnus-summary-tick-article (&optional article clear-mark)
11074   "Mark current article as unread.
11075 Optional 1st argument ARTICLE specifies article number to be marked as unread.
11076 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
11077   (interactive)
11078   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
11079                                        gnus-ticked-mark)))
11080
11081 (defun gnus-summary-mark-as-read-forward (n)
11082   "Mark N articles as read forwards.
11083 If N is negative, mark backwards instead.
11084 The difference between N and the actual number of articles marked is
11085 returned."
11086   (interactive "p")
11087   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
11088
11089 (defun gnus-summary-mark-as-read-backward (n)
11090   "Mark the N articles as read backwards.
11091 The difference between N and the actual number of articles marked is
11092 returned."
11093   (interactive "p")
11094   (gnus-summary-mark-forward
11095    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
11096
11097 (defun gnus-summary-mark-as-read (&optional article mark)
11098   "Mark current article as read.
11099 ARTICLE specifies the article to be marked as read.
11100 MARK specifies a string to be inserted at the beginning of the line."
11101   (gnus-summary-mark-article article mark))
11102
11103 (defun gnus-summary-clear-mark-forward (n)
11104   "Clear marks from N articles forward.
11105 If N is negative, clear backward instead.
11106 The difference between N and the number of marks cleared is returned."
11107   (interactive "p")
11108   (gnus-summary-mark-forward n gnus-unread-mark))
11109
11110 (defun gnus-summary-clear-mark-backward (n)
11111   "Clear marks from N articles backward.
11112 The difference between N and the number of marks cleared is returned."
11113   (interactive "p")
11114   (gnus-summary-mark-forward (- n) gnus-unread-mark))
11115
11116 (defun gnus-summary-mark-unread-as-read ()
11117   "Intended to be used by `gnus-mark-article-hook'."
11118   (when (memq gnus-current-article gnus-newsgroup-unreads)
11119     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
11120
11121 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
11122   "Intended to be used by `gnus-mark-article-hook'."
11123   (let ((mark (gnus-summary-article-mark)))
11124     (when (or (gnus-unread-mark-p mark)
11125               (gnus-read-mark-p mark))
11126       (gnus-summary-mark-article gnus-current-article
11127                                  (or new-mark gnus-read-mark)))))
11128
11129 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
11130   "Intended to be used by `gnus-mark-article-hook'."
11131   (let ((mark (gnus-summary-article-mark)))
11132     (when (or (gnus-unread-mark-p mark)
11133               (gnus-read-mark-p mark))
11134       (gnus-summary-mark-article (gnus-summary-article-number)
11135                                  (or new-mark gnus-read-mark)))))
11136
11137 (defun gnus-summary-mark-unread-as-ticked ()
11138   "Intended to be used by `gnus-mark-article-hook'."
11139   (when (memq gnus-current-article gnus-newsgroup-unreads)
11140     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
11141
11142 (defun gnus-summary-mark-region-as-read (point mark all)
11143   "Mark all unread articles between point and mark as read.
11144 If given a prefix, mark all articles between point and mark as read,
11145 even ticked and dormant ones."
11146   (interactive "r\nP")
11147   (save-excursion
11148     (let (article)
11149       (goto-char point)
11150       (beginning-of-line)
11151       (while (and
11152               (< (point) mark)
11153               (progn
11154                 (when (or all
11155                           (memq (setq article (gnus-summary-article-number))
11156                                 gnus-newsgroup-unreads))
11157                   (gnus-summary-mark-article article gnus-del-mark))
11158                 t)
11159               (gnus-summary-find-next))))))
11160
11161 (defun gnus-summary-mark-below (score mark)
11162   "Mark articles with score less than SCORE with MARK."
11163   (interactive "P\ncMark: ")
11164   (setq score (if score
11165                   (prefix-numeric-value score)
11166                 (or gnus-summary-default-score 0)))
11167   (with-current-buffer gnus-summary-buffer
11168     (goto-char (point-min))
11169     (while
11170         (progn
11171           (and (< (gnus-summary-article-score) score)
11172                (gnus-summary-mark-article nil mark))
11173           (gnus-summary-find-next)))))
11174
11175 (defun gnus-summary-kill-below (&optional score)
11176   "Mark articles with score below SCORE as read."
11177   (interactive "P")
11178   (gnus-summary-mark-below score gnus-killed-mark))
11179
11180 (defun gnus-summary-clear-above (&optional score)
11181   "Clear all marks from articles with score above SCORE."
11182   (interactive "P")
11183   (gnus-summary-mark-above score gnus-unread-mark))
11184
11185 (defun gnus-summary-tick-above (&optional score)
11186   "Tick all articles with score above SCORE."
11187   (interactive "P")
11188   (gnus-summary-mark-above score gnus-ticked-mark))
11189
11190 (defun gnus-summary-mark-above (score mark)
11191   "Mark articles with score over SCORE with MARK."
11192   (interactive "P\ncMark: ")
11193   (setq score (if score
11194                   (prefix-numeric-value score)
11195                 (or gnus-summary-default-score 0)))
11196   (with-current-buffer gnus-summary-buffer
11197     (goto-char (point-min))
11198     (while (and (progn
11199                   (when (> (gnus-summary-article-score) score)
11200                     (gnus-summary-mark-article nil mark))
11201                   t)
11202                 (gnus-summary-find-next)))))
11203
11204 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
11205 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
11206 (defun gnus-summary-limit-include-expunged (&optional no-error)
11207   "Display all the hidden articles that were expunged for low scores."
11208   (interactive)
11209   (let ((inhibit-read-only t))
11210     (let ((scored gnus-newsgroup-scored)
11211           headers h)
11212       (while scored
11213         (unless (gnus-summary-article-header (caar scored))
11214           (and (setq h (gnus-number-to-header (caar scored)))
11215                (< (cdar scored) gnus-summary-expunge-below)
11216                (push h headers)))
11217         (setq scored (cdr scored)))
11218       (if (not headers)
11219           (when (not no-error)
11220             (error "No expunged articles hidden"))
11221         (goto-char (point-min))
11222         (push gnus-newsgroup-limit gnus-newsgroup-limits)
11223         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
11224         (dolist (x headers)
11225           (push (mail-header-number x) gnus-newsgroup-limit))
11226         (gnus-summary-prepare-unthreaded (nreverse headers))
11227         (goto-char (point-min))
11228         (gnus-summary-position-point)
11229         t))))
11230
11231 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
11232   "Mark all unread articles in this newsgroup as read.
11233 If prefix argument ALL is non-nil, ticked and dormant articles will
11234 also be marked as read.
11235 If QUIETLY is non-nil, no questions will be asked.
11236
11237 If TO-HERE is non-nil, it should be a point in the buffer.  All
11238 articles before (after, if REVERSE is set) this point will be marked
11239 as read.
11240
11241 Note that this function will only catch up the unread article
11242 in the current summary buffer limitation.
11243
11244 The number of articles marked as read is returned."
11245   (interactive "P")
11246   (prog1
11247       (save-excursion
11248         (when (or quietly
11249                   (not gnus-interactive-catchup) ;Without confirmation?
11250                   gnus-expert-user
11251                   (gnus-y-or-n-p
11252                    (if all
11253                        "Mark absolutely all articles as read? "
11254                      "Mark all unread articles as read? ")))
11255           (if (and not-mark
11256                    (not gnus-newsgroup-adaptive)
11257                    (not gnus-newsgroup-auto-expire)
11258                    (not gnus-suppress-duplicates)
11259                    (or (not gnus-use-cache)
11260                        (eq gnus-use-cache 'passive)))
11261               (progn
11262                 (when all
11263                   (setq gnus-newsgroup-marked nil
11264                         gnus-newsgroup-spam-marked nil
11265                         gnus-newsgroup-dormant nil))
11266                 (setq gnus-newsgroup-unreads
11267                       (gnus-sorted-nunion
11268                        (gnus-sorted-intersection gnus-newsgroup-unreads
11269                                                  gnus-newsgroup-downloadable)
11270                        (gnus-sorted-difference gnus-newsgroup-unfetched
11271                                                gnus-newsgroup-cached))))
11272             ;; We actually mark all articles as canceled, which we
11273             ;; have to do when using auto-expiry or adaptive scoring.
11274             (gnus-summary-show-all-threads)
11275             (if (and to-here reverse)
11276                 (progn
11277                   (goto-char to-here)
11278                   (gnus-summary-mark-current-read-and-unread-as-read
11279                    gnus-catchup-mark)
11280                   (while (gnus-summary-find-next (not all))
11281                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
11282               (when (gnus-summary-first-subject (not all))
11283                 (while (and
11284                         (if to-here (< (point) to-here) t)
11285                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
11286                         (gnus-summary-find-next (not all))))))
11287             (gnus-set-mode-line 'summary))
11288           t))
11289     (gnus-summary-position-point)))
11290
11291 (defun gnus-summary-catchup-to-here (&optional all)
11292   "Mark all unticked articles before the current one as read.
11293 If ALL is non-nil, also mark ticked and dormant articles as read."
11294   (interactive "P")
11295   (save-excursion
11296     (gnus-save-hidden-threads
11297       (let ((beg (point)))
11298         ;; We check that there are unread articles.
11299         (when (or all (gnus-summary-find-prev))
11300           (gnus-summary-catchup all t beg)))))
11301   (gnus-summary-position-point))
11302
11303 (defun gnus-summary-catchup-from-here (&optional all)
11304   "Mark all unticked articles after (and including) the current one as read.
11305 If ALL is non-nil, also mark ticked and dormant articles as read."
11306   (interactive "P")
11307   (save-excursion
11308     (gnus-save-hidden-threads
11309       (let ((beg (point)))
11310         ;; We check that there are unread articles.
11311         (when (or all (gnus-summary-find-next))
11312           (gnus-summary-catchup all t beg nil t)))))
11313   (gnus-summary-position-point))
11314
11315 (defun gnus-summary-catchup-all (&optional quietly)
11316   "Mark all articles in this newsgroup as read.
11317 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11318 instead, which marks only unread articles as read."
11319   (interactive "P")
11320   (gnus-summary-catchup t quietly))
11321
11322 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11323   "Mark all unread articles in this group as read, then exit.
11324 If prefix argument ALL is non-nil, all articles are marked as read.
11325 If QUIETLY is non-nil, no questions will be asked."
11326   (interactive "P")
11327   (when (gnus-summary-catchup all quietly nil 'fast)
11328     ;; Select next newsgroup or exit.
11329     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11330              (eq gnus-auto-select-next 'quietly))
11331         (gnus-summary-next-group nil)
11332       (gnus-summary-exit))))
11333
11334 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11335   "Mark all articles in this newsgroup as read, and then exit.
11336 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11337 instead, which marks only unread articles as read."
11338   (interactive "P")
11339   (gnus-summary-catchup-and-exit t quietly))
11340
11341 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11342   "Mark all articles in this group as read and select the next group.
11343 If given a prefix, mark all articles, unread as well as ticked, as
11344 read."
11345   (interactive "P")
11346   (save-excursion
11347     (gnus-summary-catchup all))
11348   (gnus-summary-next-group))
11349
11350 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11351   "Mark all articles in this group as read and select the previous group.
11352 If given a prefix, mark all articles, unread as well as ticked, as
11353 read."
11354   (interactive "P")
11355   (save-excursion
11356     (gnus-summary-catchup all))
11357   (gnus-summary-next-group nil nil t))
11358
11359 ;;;
11360 ;;; with article
11361 ;;;
11362
11363 (defmacro gnus-with-article (article &rest forms)
11364   "Select ARTICLE and perform FORMS in the original article buffer.
11365 Then replace the article with the result."
11366   `(progn
11367      ;; We don't want the article to be marked as read.
11368      (let (gnus-mark-article-hook)
11369        (gnus-summary-select-article t t nil ,article))
11370      (set-buffer gnus-original-article-buffer)
11371      ,@forms
11372      (if (not (gnus-check-backend-function
11373                'request-replace-article (car gnus-article-current)))
11374          (gnus-message 5 "Read-only group; not replacing")
11375        (unless (gnus-request-replace-article
11376                 ,article (car gnus-article-current)
11377                 (current-buffer) t)
11378          (error "Couldn't replace article")))
11379      ;; The cache and backlog have to be flushed somewhat.
11380      (when gnus-keep-backlog
11381        (gnus-backlog-remove-article
11382         (car gnus-article-current) (cdr gnus-article-current)))
11383      (when gnus-use-cache
11384        (gnus-cache-update-article
11385         (car gnus-article-current) (cdr gnus-article-current)))))
11386
11387 (put 'gnus-with-article 'lisp-indent-function 1)
11388 (put 'gnus-with-article 'edebug-form-spec '(form body))
11389
11390 ;; Thread-based commands.
11391
11392 (defun gnus-summary-articles-in-thread (&optional article)
11393   "Return a list of all articles in the current thread.
11394 If ARTICLE is non-nil, return all articles in the thread that starts
11395 with that article."
11396   (let* ((article (or article (gnus-summary-article-number)))
11397          (data (gnus-data-find-list article))
11398          (top-level (gnus-data-level (car data)))
11399          (top-subject
11400           (cond ((null gnus-thread-operation-ignore-subject)
11401                  (gnus-simplify-subject-re
11402                   (mail-header-subject (gnus-data-header (car data)))))
11403                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11404                  (gnus-simplify-subject-fuzzy
11405                   (mail-header-subject (gnus-data-header (car data)))))
11406                 (t nil)))
11407          (end-point (save-excursion
11408                       (goto-char (gnus-data-pos (car data)))
11409                       (if (gnus-summary-go-to-next-thread)
11410                           (point) (point-max))))
11411          articles)
11412     (while (and data
11413                 (< (gnus-data-pos (car data)) end-point))
11414       (when (or (not top-subject)
11415                 (string= top-subject
11416                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11417                              (gnus-simplify-subject-fuzzy
11418                               (mail-header-subject
11419                                (gnus-data-header (car data))))
11420                            (gnus-simplify-subject-re
11421                             (mail-header-subject
11422                              (gnus-data-header (car data)))))))
11423         (push (gnus-data-number (car data)) articles))
11424       (unless (and (setq data (cdr data))
11425                    (> (gnus-data-level (car data)) top-level))
11426         (setq data nil)))
11427     ;; Return the list of articles.
11428     (nreverse articles)))
11429
11430 (defun gnus-summary-rethread-current ()
11431   "Rethread the thread the current article is part of."
11432   (interactive)
11433   (let* ((gnus-show-threads t)
11434          (article (gnus-summary-article-number))
11435          (id (mail-header-id (gnus-summary-article-header)))
11436          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11437     (unless id
11438       (error "No article on the current line"))
11439     (gnus-rebuild-thread id)
11440     (gnus-summary-goto-subject article)))
11441
11442 (defun gnus-summary-reparent-thread ()
11443   "Make the current article child of the marked (or previous) article.
11444
11445 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11446 is non-nil or the Subject: of both articles are the same."
11447   (interactive)
11448   (unless (not (gnus-group-read-only-p))
11449     (error "The current newsgroup does not support article editing"))
11450   (unless (<= (length gnus-newsgroup-processable) 1)
11451     (error "No more than one article may be marked"))
11452   (let ((child (gnus-summary-article-number))
11453         ;; First grab the marked article, otherwise one line up.
11454         (parent (if (not (null gnus-newsgroup-processable))
11455                     (car gnus-newsgroup-processable)
11456                   (save-excursion
11457                     (if (eq (forward-line -1) 0)
11458                         (gnus-summary-article-number)
11459                       (error "Beginning of summary buffer"))))))
11460     (gnus-summary-reparent-children parent (list child))))
11461
11462 (defun gnus-summary-reparent-children (parent children)
11463   "Make PARENT the parent of CHILDREN.
11464 When called interactively, PARENT is the current article and CHILDREN
11465 are the process-marked articles."
11466   (interactive
11467    (list (gnus-summary-article-number)
11468          (gnus-summary-work-articles nil)))
11469   (dolist (child children)
11470     (save-window-excursion
11471       (let ((gnus-article-buffer " *reparent*"))
11472         (unless (not (eq parent child))
11473           (error "An article may not be self-referential"))
11474         (let ((message-id (mail-header-id
11475                            (gnus-summary-article-header parent))))
11476           (unless (and message-id (not (equal message-id "")))
11477             (error "No message-id in desired parent"))
11478           (gnus-with-article child
11479             (save-restriction
11480               (goto-char (point-min))
11481               (message-narrow-to-head)
11482               (if (re-search-forward "^References: " nil t)
11483                   (progn
11484                     (re-search-forward "^[^ \t]" nil t)
11485                     (forward-line -1)
11486                     (end-of-line)
11487                     (insert " " message-id))
11488                 (insert "References: " message-id "\n"))))
11489           (set-buffer gnus-summary-buffer)
11490           (gnus-summary-unmark-all-processable)
11491           (gnus-summary-update-article child)
11492           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11493             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11494           (gnus-summary-rethread-current)
11495           (gnus-message 3 "Article %d is now the child of article %d"
11496                         child parent))))))
11497
11498 (defun gnus-summary-toggle-threads (&optional arg)
11499   "Toggle showing conversation threads.
11500 If ARG is positive number, turn showing conversation threads on."
11501   (interactive "P")
11502   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11503     (setq gnus-show-threads
11504           (if (null arg) (not gnus-show-threads)
11505             (> (prefix-numeric-value arg) 0)))
11506     (gnus-summary-prepare)
11507     (gnus-summary-goto-subject current)
11508     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11509     (gnus-summary-position-point)))
11510
11511 (eval-and-compile
11512   (if (fboundp 'remove-overlays)
11513       (defalias 'gnus-remove-overlays 'remove-overlays)
11514     (defun gnus-remove-overlays (beg end name val)
11515       "Clear BEG and END of overlays whose property NAME has value VAL.
11516 For compatibility with XEmacs."
11517       (dolist (ov (gnus-overlays-in beg end))
11518         (when (eq (gnus-overlay-get ov name) val)
11519           (gnus-delete-overlay ov))))))
11520
11521 (defun gnus-summary-show-all-threads ()
11522   "Show all threads."
11523   (interactive)
11524   (gnus-remove-overlays (point-min) (point-max) 'invisible 'gnus-sum)
11525   (gnus-summary-position-point))
11526
11527 (defsubst gnus-summary--inv (p)
11528   (and (eq (get-char-property p 'invisible) 'gnus-sum) p))
11529
11530 (defun gnus-summary-show-thread ()
11531   "Show thread subtrees.
11532 Returns nil if no thread was there to be shown."
11533   (interactive)
11534   (let* ((orig (point))
11535          (end (point-at-eol))
11536          (end (or (gnus-summary--inv end) (gnus-summary--inv (1- end))))
11537          ;; Leave point at bol
11538          (beg (progn (beginning-of-line) (if (bobp) (point) (1- (point)))))
11539          (eoi (when end
11540                 (if (fboundp 'next-single-char-property-change)
11541                     (or (next-single-char-property-change end 'invisible)
11542                         (point-max))
11543                   (while (progn
11544                            (end-of-line 2)
11545                            (and (not (eobp))
11546                                 (eq (get-char-property (point) 'invisible)
11547                                     'gnus-sum))))
11548                   (point)))))
11549     (when eoi
11550       (gnus-remove-overlays beg eoi 'invisible 'gnus-sum)
11551       (goto-char orig)
11552       (gnus-summary-position-point)
11553       eoi)))
11554
11555 (defun gnus-summary-maybe-hide-threads ()
11556   "If requested, hide the threads that should be hidden."
11557   (when (and gnus-show-threads
11558              gnus-thread-hide-subtree)
11559     (gnus-summary-hide-all-threads
11560      (if (or (consp gnus-thread-hide-subtree)
11561              (functionp gnus-thread-hide-subtree))
11562          (gnus-make-predicate gnus-thread-hide-subtree)
11563        nil))))
11564
11565 ;;; Hiding predicates.
11566
11567 (defun gnus-article-unread-p (header)
11568   (memq (mail-header-number header) gnus-newsgroup-unreads))
11569
11570 (defun gnus-article-unseen-p (header)
11571   (memq (mail-header-number header) gnus-newsgroup-unseen))
11572
11573 (defun gnus-map-articles (predicate articles)
11574   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11575   (apply 'gnus-or (mapcar predicate
11576                           (mapcar (lambda (number)
11577                                     (gnus-summary-article-header number))
11578                                   articles))))
11579
11580 (defun gnus-summary-hide-all-threads (&optional predicate)
11581   "Hide all thread subtrees.
11582 If PREDICATE is supplied, threads that satisfy this predicate
11583 will not be hidden."
11584   (interactive)
11585   (save-excursion
11586     (goto-char (point-min))
11587     (let ((end nil)
11588           (count 0))
11589       (while (not end)
11590         (incf count)
11591         (when (zerop (mod count 1000))
11592           (message "Hiding all threads... %d" count))
11593         (when (or (not predicate)
11594                   (gnus-map-articles
11595                    predicate (gnus-summary-article-children)))
11596             (gnus-summary-hide-thread))
11597         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11598   (gnus-summary-position-point))
11599
11600 (defun gnus-summary-hide-thread ()
11601   "Hide thread subtrees.
11602 If PREDICATE is supplied, threads that satisfy this predicate
11603 will not be hidden.
11604 Returns nil if no threads were there to be hidden."
11605   (interactive)
11606   (let ((start (point))
11607         (starteol (line-end-position))
11608         (article (gnus-summary-article-number)))
11609     (goto-char start)
11610     ;; Go forward until either the buffer ends or the subthread ends.
11611     (when (and (not (eobp))
11612                (or (zerop (gnus-summary-next-thread 1 t))
11613                    (goto-char (point-max))))
11614       (if (and (> (point) start)
11615                ;; FIXME: this should actually search for a non-invisible \n.
11616                (search-backward "\n" start t))
11617           (progn
11618             (when (> (point) starteol)
11619               (gnus-remove-overlays starteol (point) 'invisible 'gnus-sum)
11620               (let ((ol (gnus-make-overlay starteol (point) nil t nil)))
11621                 (gnus-overlay-put ol 'invisible 'gnus-sum)
11622                 (gnus-overlay-put ol 'evaporate t)))
11623             (gnus-summary-goto-subject article)
11624             (when (> start (point))
11625               (message "Hiding the thread moved us backwards, aborting!")
11626               (goto-char (point-max))))
11627         (goto-char start)
11628         nil))))
11629
11630 (defun gnus-summary-go-to-next-thread (&optional previous)
11631   "Go to the same level (or less) next thread.
11632 If PREVIOUS is non-nil, go to previous thread instead.
11633 Return the article number moved to, or nil if moving was impossible."
11634   (let ((level (gnus-summary-thread-level))
11635         (way (if previous -1 1))
11636         (beg (point)))
11637     (forward-line way)
11638     (while (and (not (eobp))
11639                 (< level (gnus-summary-thread-level)))
11640       (forward-line way))
11641     (if (eobp)
11642         (progn
11643           (goto-char beg)
11644           nil)
11645       (setq beg (point))
11646       (prog1
11647           (gnus-summary-article-number)
11648         (goto-char beg)))))
11649
11650 (defun gnus-summary-next-thread (n &optional silent)
11651   "Go to the same level next N'th thread.
11652 If N is negative, search backward instead.
11653 Returns the difference between N and the number of skips actually
11654 done.
11655
11656 If SILENT, don't output messages."
11657   (interactive "p")
11658   (let ((backward (< n 0))
11659         (n (abs n)))
11660     (while (and (> n 0)
11661                 (gnus-summary-go-to-next-thread backward))
11662       (decf n))
11663     (unless silent
11664       (gnus-summary-position-point))
11665     (when (and (not silent) (/= 0 n))
11666       (gnus-message 7 "No more threads"))
11667     n))
11668
11669 (defun gnus-summary-prev-thread (n)
11670   "Go to the same level previous N'th thread.
11671 Returns the difference between N and the number of skips actually
11672 done."
11673   (interactive "p")
11674   (gnus-summary-next-thread (- n)))
11675
11676 (defun gnus-summary-go-down-thread ()
11677   "Go down one level in the current thread."
11678   (let ((children (gnus-summary-article-children)))
11679     (when children
11680       (gnus-summary-goto-subject (car children)))))
11681
11682 (defun gnus-summary-go-up-thread ()
11683   "Go up one level in the current thread."
11684   (let ((parent (gnus-summary-article-parent)))
11685     (when parent
11686       (gnus-summary-goto-subject parent))))
11687
11688 (defun gnus-summary-down-thread (n)
11689   "Go down thread N steps.
11690 If N is negative, go up instead.
11691 Returns the difference between N and how many steps down that were
11692 taken."
11693   (interactive "p")
11694   (let ((up (< n 0))
11695         (n (abs n)))
11696     (while (and (> n 0)
11697                 (if up (gnus-summary-go-up-thread)
11698                   (gnus-summary-go-down-thread)))
11699       (setq n (1- n)))
11700     (gnus-summary-position-point)
11701     (when (/= 0 n)
11702       (gnus-message 7 "Can't go further"))
11703     n))
11704
11705 (defun gnus-summary-up-thread (n)
11706   "Go up thread N steps.
11707 If N is negative, go down instead.
11708 Returns the difference between N and how many steps down that were
11709 taken."
11710   (interactive "p")
11711   (gnus-summary-down-thread (- n)))
11712
11713 (defun gnus-summary-top-thread ()
11714   "Go to the top of the thread."
11715   (interactive)
11716   (while (gnus-summary-go-up-thread))
11717   (gnus-summary-article-number))
11718
11719 (defun gnus-summary-expire-thread ()
11720   "Mark articles under current thread as expired."
11721   (interactive)
11722   (gnus-summary-kill-thread 0))
11723
11724 (defun gnus-summary-kill-thread (&optional unmark)
11725   "Mark articles under current thread as read.
11726 If the prefix argument is positive, remove any kinds of marks.
11727 If the prefix argument is zero, mark thread as expired.
11728 If the prefix argument is negative, tick articles instead."
11729   (interactive "P")
11730   (when unmark
11731     (setq unmark (prefix-numeric-value unmark)))
11732   (let ((articles (gnus-summary-articles-in-thread))
11733         (hide (or (null unmark) (= unmark 0))))
11734     (save-excursion
11735       ;; Expand the thread.
11736       (gnus-summary-show-thread)
11737       ;; Mark all the articles.
11738       (while articles
11739         (gnus-summary-goto-subject (car articles))
11740         (cond ((null unmark)
11741                (gnus-summary-mark-article-as-read gnus-killed-mark))
11742               ((> unmark 0)
11743                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11744               ((= unmark 0)
11745                (gnus-summary-mark-article nil gnus-expirable-mark))
11746               (t
11747                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11748         (setq articles (cdr articles))))
11749     ;; Hide killed subtrees when hide is true.
11750     (and hide
11751          gnus-thread-hide-killed
11752          (gnus-summary-hide-thread))
11753     ;; If hide is t, go to next unread subject.
11754     (when hide
11755       ;; Go to next unread subject.
11756       (gnus-summary-next-subject 1 t)))
11757   (gnus-set-mode-line 'summary))
11758
11759 ;; Summary sorting commands
11760
11761 (defun gnus-summary-sort-by-number (&optional reverse)
11762   "Sort the summary buffer by article number.
11763 Argument REVERSE means reverse order."
11764   (interactive "P")
11765   (gnus-summary-sort 'number reverse))
11766
11767 (defun gnus-summary-sort-by-most-recent-number (&optional reverse)
11768   "Sort the summary buffer by most recent article number.
11769 Argument REVERSE means reverse order."
11770   (interactive "P")
11771   (gnus-summary-sort 'most-recent-number reverse))
11772
11773 (defun gnus-summary-sort-by-random (&optional reverse)
11774   "Randomize the order in the summary buffer.
11775 Argument REVERSE means to randomize in reverse order."
11776   (interactive "P")
11777   (gnus-summary-sort 'random reverse))
11778
11779 (defun gnus-summary-sort-by-author (&optional reverse)
11780   "Sort the summary buffer by author name alphabetically.
11781 If `case-fold-search' is non-nil, case of letters is ignored.
11782 Argument REVERSE means reverse order."
11783   (interactive "P")
11784   (gnus-summary-sort 'author reverse))
11785
11786 (defun gnus-summary-sort-by-recipient (&optional reverse)
11787   "Sort the summary buffer by recipient name alphabetically.
11788 If `case-fold-search' is non-nil, case of letters is ignored.
11789 Argument REVERSE means reverse order."
11790   (interactive "P")
11791   (gnus-summary-sort 'recipient reverse))
11792
11793 (defun gnus-summary-sort-by-subject (&optional reverse)
11794   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11795 If `case-fold-search' is non-nil, case of letters is ignored.
11796 Argument REVERSE means reverse order."
11797   (interactive "P")
11798   (gnus-summary-sort 'subject reverse))
11799
11800 (defun gnus-summary-sort-by-date (&optional reverse)
11801   "Sort the summary buffer by date.
11802 Argument REVERSE means reverse order."
11803   (interactive "P")
11804   (gnus-summary-sort 'date reverse))
11805
11806 (defun gnus-summary-sort-by-most-recent-date (&optional reverse)
11807   "Sort the summary buffer by most recent date.
11808 Argument REVERSE means reverse order."
11809   (interactive "P")
11810   (gnus-summary-sort 'most-recent-date reverse))
11811
11812 (defun gnus-summary-sort-by-score (&optional reverse)
11813   "Sort the summary buffer by score.
11814 Argument REVERSE means reverse order."
11815   (interactive "P")
11816   (gnus-summary-sort 'score reverse))
11817
11818 (defun gnus-summary-sort-by-lines (&optional reverse)
11819   "Sort the summary buffer by the number of lines.
11820 Argument REVERSE means reverse order."
11821   (interactive "P")
11822   (gnus-summary-sort 'lines reverse))
11823
11824 (defun gnus-summary-sort-by-chars (&optional reverse)
11825   "Sort the summary buffer by article length.
11826 Argument REVERSE means reverse order."
11827   (interactive "P")
11828   (gnus-summary-sort 'chars reverse))
11829
11830 (defun gnus-summary-sort-by-original (&optional reverse)
11831   "Sort the summary buffer using the default sorting method.
11832 Argument REVERSE means reverse order."
11833   (interactive "P")
11834   (let* ((inhibit-read-only t)
11835          (gnus-summary-prepare-hook nil))
11836     ;; We do the sorting by regenerating the threads.
11837     (gnus-summary-prepare)
11838     ;; Hide subthreads if needed.
11839     (gnus-summary-maybe-hide-threads)))
11840
11841 (defun gnus-summary-sort (predicate reverse)
11842   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11843   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11844          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11845          (gnus-thread-sort-functions
11846           (if (not reverse)
11847               thread
11848             `(lambda (t1 t2)
11849                (,thread t2 t1))))
11850          (gnus-sort-gathered-threads-function
11851           gnus-thread-sort-functions)
11852          (gnus-article-sort-functions
11853           (if (not reverse)
11854               article
11855             `(lambda (t1 t2)
11856                (,article t2 t1))))
11857          (inhibit-read-only t)
11858          (gnus-summary-prepare-hook nil))
11859     ;; We do the sorting by regenerating the threads.
11860     (gnus-summary-prepare)
11861     ;; Hide subthreads if needed.
11862     (gnus-summary-maybe-hide-threads)))
11863
11864 ;; Summary saving commands.
11865
11866 (defun gnus-summary-save-article (&optional n not-saved)
11867   "Save the current article using the default saver function.
11868 If N is a positive number, save the N next articles.
11869 If N is a negative number, save the N previous articles.
11870 If N is nil and any articles have been marked with the process mark,
11871 save those articles instead.
11872 The variable `gnus-default-article-saver' specifies the saver function.
11873
11874 If the optional second argument NOT-SAVED is non-nil, articles saved
11875 will not be marked as saved."
11876   (interactive "P")
11877   (require 'gnus-art)
11878   (let* ((articles (gnus-summary-work-articles n))
11879          (save-buffer (save-excursion
11880                         (nnheader-set-temp-buffer " *Gnus Save*")))
11881          (num (length articles))
11882          ;; Whether to save decoded articles or raw articles.
11883          (decode (when gnus-article-save-coding-system
11884                    (get gnus-default-article-saver :decode)))
11885          ;; When saving many articles in a single file, use the other
11886          ;; function to save articles other than the first one.
11887          (saver2 (get gnus-default-article-saver :function))
11888          (gnus-prompt-before-saving (if saver2
11889                                         t
11890                                       gnus-prompt-before-saving))
11891          (gnus-default-article-saver gnus-default-article-saver)
11892          header file)
11893     (dolist (article articles)
11894       (setq header (gnus-summary-article-header article))
11895       (if (not (vectorp header))
11896           ;; This is a pseudo-article.
11897           (if (assq 'name header)
11898               (gnus-copy-file (cdr (assq 'name header)))
11899             (gnus-message 1 "Article %d is unsaveable" article))
11900         ;; This is a real article.
11901         (save-window-excursion
11902           (gnus-summary-select-article decode decode nil article)
11903           (gnus-summary-goto-subject article))
11904         (with-current-buffer save-buffer
11905           (erase-buffer)
11906           (insert-buffer-substring (if decode
11907                                        gnus-article-buffer
11908                                      gnus-original-article-buffer)))
11909         (setq file (gnus-article-save save-buffer file num))
11910         (gnus-summary-remove-process-mark article)
11911         (unless not-saved
11912           (gnus-summary-set-saved-mark article)))
11913       (when saver2
11914         (setq gnus-default-article-saver saver2
11915               saver2 nil)))
11916     (gnus-kill-buffer save-buffer)
11917     (gnus-summary-position-point)
11918     (gnus-set-mode-line 'summary)
11919     n))
11920
11921 (defun gnus-summary-pipe-output (&optional n sym)
11922   "Pipe the current article to a subprocess.
11923 If N is a positive number, pipe the N next articles.
11924 If N is a negative number, pipe the N previous articles.
11925 If N is nil and any articles have been marked with the process mark,
11926 pipe those articles instead.
11927 The default command to which articles are piped is specified by the
11928 variable `gnus-summary-pipe-output-default-command'; if it is nil, you
11929 will be prompted for the command.
11930
11931 The properties `:decode' and `:headers' that are put to the function
11932 symbol `gnus-summary-save-in-pipe' control whether this function
11933 decodes articles and what headers to keep (see the doc string for the
11934 `gnus-default-article-saver' variable).  If SYM (the symbolic prefix)
11935 is neither omitted nor the symbol `r', force including all headers
11936 regardless of the `:headers' property.  If it is the symbol `r',
11937 articles that are not decoded and include all headers will be piped
11938 no matter what the properties `:decode' and `:headers' are."
11939   (interactive (gnus-interactive "P\ny"))
11940   (require 'gnus-art)
11941   (let* ((articles (gnus-summary-work-articles n))
11942          (result-buffer "*Shell Command Output*")
11943          (all-headers (not (memq sym '(nil r))))
11944          (gnus-save-all-headers (or all-headers gnus-save-all-headers))
11945          (raw (eq sym 'r))
11946          (headers (get 'gnus-summary-save-in-pipe :headers))
11947          command result)
11948     (unless (numberp (car articles))
11949       (error "No article to pipe"))
11950     (setq command (gnus-read-shell-command
11951                    (concat "Shell command on "
11952                            (if (cdr articles)
11953                                (format "these %d articles" (length articles))
11954                              "this article")
11955                            ": ")
11956                    gnus-summary-pipe-output-default-command))
11957     (when (string-equal command "")
11958       (error "A command is required"))
11959     (when all-headers
11960       (put 'gnus-summary-save-in-pipe :headers nil))
11961     (unwind-protect
11962         (while articles
11963           (gnus-summary-goto-subject (pop articles))
11964           (save-window-excursion (gnus-summary-save-in-pipe command raw))
11965           (when (and (get-buffer result-buffer)
11966                      (not (zerop (buffer-size (get-buffer result-buffer)))))
11967             (setq result (concat result (with-current-buffer result-buffer
11968                                           (buffer-string))))))
11969       (put 'gnus-summary-save-in-pipe :headers headers))
11970     (unless (zerop (length result))
11971       (if (with-current-buffer (get-buffer-create result-buffer)
11972             (erase-buffer)
11973             (insert result)
11974             (prog1
11975                 (and (= (count-lines (point-min) (point)) 1)
11976                      (progn
11977                        (end-of-line 0)
11978                        (<= (current-column)
11979                            (window-width (minibuffer-window)))))
11980               (goto-char (point-min))))
11981           (message "%s" (substring result 0 -1))
11982         (message nil)
11983         (gnus-configure-windows 'pipe)))))
11984
11985 (defun gnus-summary-save-article-mail (&optional arg)
11986   "Append the current article to a Unix mail box file.
11987 If N is a positive number, save the N next articles.
11988 If N is a negative number, save the N previous articles.
11989 If N is nil and any articles have been marked with the process mark,
11990 save those articles instead."
11991   (interactive "P")
11992   (require 'gnus-art)
11993   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11994     (gnus-summary-save-article arg)))
11995
11996 (defun gnus-summary-save-article-rmail (&optional arg)
11997   "Append the current article to an rmail file.
11998 If N is a positive number, save the N next articles.
11999 If N is a negative number, save the N previous articles.
12000 If N is nil and any articles have been marked with the process mark,
12001 save those articles instead."
12002   (interactive "P")
12003   (require 'gnus-art)
12004   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
12005     (gnus-summary-save-article arg)))
12006
12007 (defun gnus-summary-save-article-file (&optional arg)
12008   "Append the current article to a file.
12009 If N is a positive number, save the N next articles.
12010 If N is a negative number, save the N previous articles.
12011 If N is nil and any articles have been marked with the process mark,
12012 save those articles instead."
12013   (interactive "P")
12014   (require 'gnus-art)
12015   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
12016     (gnus-summary-save-article arg)))
12017
12018 (defun gnus-summary-write-article-file (&optional arg)
12019   "Write the current article to a file, deleting the previous file.
12020 If N is a positive number, save the N next articles.
12021 If N is a negative number, save the N previous articles.
12022 If N is nil and any articles have been marked with the process mark,
12023 save those articles instead."
12024   (interactive "P")
12025   (require 'gnus-art)
12026   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
12027     (gnus-summary-save-article arg)))
12028
12029 (defun gnus-summary-save-article-body-file (&optional arg)
12030   "Append the current article body to a file.
12031 If N is a positive number, save the N next articles.
12032 If N is a negative number, save the N previous articles.
12033 If N is nil and any articles have been marked with the process mark,
12034 save those articles instead."
12035   (interactive "P")
12036   (require 'gnus-art)
12037   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
12038     (gnus-summary-save-article arg)))
12039
12040 (defun gnus-summary-write-article-body-file (&optional arg)
12041   "Write the current article body to a file, deleting the previous file.
12042 If N is a positive number, save the N next articles.
12043 If N is a negative number, save the N previous articles.
12044 If N is nil and any articles have been marked with the process mark,
12045 save those articles instead."
12046   (interactive "P")
12047   (require 'gnus-art)
12048   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
12049     (gnus-summary-save-article arg)))
12050
12051 (defun gnus-summary-muttprint (&optional arg)
12052   "Print the current article using Muttprint.
12053 If N is a positive number, save the N next articles.
12054 If N is a negative number, save the N previous articles.
12055 If N is nil and any articles have been marked with the process mark,
12056 save those articles instead."
12057   (interactive "P")
12058   (require 'gnus-art)
12059   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
12060     (gnus-summary-save-article arg t)))
12061
12062 (defun gnus-summary-pipe-message (program)
12063   "Pipe the current article through PROGRAM."
12064   (interactive "sProgram: ")
12065   (gnus-summary-select-article)
12066   (let ((mail-header-separator ""))
12067     (gnus-eval-in-buffer-window gnus-article-buffer
12068       (save-restriction
12069         (widen)
12070         (let ((start (window-start))
12071               (inhibit-read-only t))
12072           (message-pipe-buffer-body program)
12073           (set-window-start (get-buffer-window (current-buffer)) start))))))
12074
12075 (defun gnus-get-split-value (methods)
12076   "Return a value based on the split METHODS."
12077   (let (split-name method result match)
12078     (when methods
12079       (with-current-buffer gnus-original-article-buffer
12080         (save-restriction
12081           (nnheader-narrow-to-headers)
12082           (while (and methods (not split-name))
12083             (goto-char (point-min))
12084             (setq method (pop methods))
12085             (setq match (car method))
12086             (when (cond
12087                    ((stringp match)
12088                     ;; Regular expression.
12089                     (ignore-errors
12090                       (re-search-forward match nil t)))
12091                    ((functionp match)
12092                     ;; Function.
12093                     (save-restriction
12094                       (widen)
12095                       (setq result (funcall match gnus-newsgroup-name))))
12096                    ((consp match)
12097                     ;; Form.
12098                     (save-restriction
12099                       (widen)
12100                       (setq result (eval match)))))
12101               (setq split-name (cdr method))
12102               (cond ((stringp result)
12103                      (push (expand-file-name
12104                             result gnus-article-save-directory)
12105                            split-name))
12106                     ((consp result)
12107                      (setq split-name (append result split-name)))))))))
12108     (nreverse split-name)))
12109
12110 (defun gnus-valid-move-group-p (group)
12111   (and (symbolp group)
12112        (boundp group)
12113        (symbol-name group)
12114        (symbol-value group)
12115        (gnus-get-function (gnus-find-method-for-group
12116                            (symbol-name group)) 'request-accept-article t)))
12117
12118 (defun gnus-read-move-group-name (prompt default articles prefix)
12119   "Read a group name."
12120   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
12121          (minibuffer-confirm-incomplete nil) ; XEmacs
12122          (prom
12123           (format "%s %s to"
12124                   prompt
12125                   (if (> (length articles) 1)
12126                       (format "these %d articles" (length articles))
12127                     "this article")))
12128          (to-newsgroup
12129           (cond
12130            ((null split-name)
12131             (gnus-group-completing-read
12132              prom
12133              (gnus-remove-if-not 'gnus-valid-move-group-p gnus-active-hashtb t)
12134              nil prefix nil default))
12135            ((= 1 (length split-name))
12136             (gnus-group-completing-read
12137              prom
12138              (gnus-remove-if-not 'gnus-valid-move-group-p gnus-active-hashtb t)
12139              nil prefix 'gnus-group-history (car split-name)))
12140            (t
12141             (gnus-completing-read
12142              prom (nreverse split-name) nil nil 'gnus-group-history))))
12143          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
12144          encoded)
12145     (when to-newsgroup
12146       (if (or (string= to-newsgroup "")
12147               (string= to-newsgroup prefix))
12148           (setq to-newsgroup default))
12149       (unless to-newsgroup
12150         (error "No group name entered"))
12151       (setq encoded (mm-encode-coding-string
12152                      to-newsgroup
12153                      (gnus-group-name-charset to-method to-newsgroup)))
12154       (or (gnus-active encoded)
12155           (gnus-activate-group encoded nil nil to-method)
12156           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
12157                                      to-newsgroup))
12158               (or (and (gnus-request-create-group encoded to-method)
12159                        (gnus-activate-group encoded nil nil to-method)
12160                        (gnus-subscribe-group encoded))
12161                   (error "Couldn't create group %s" to-newsgroup)))
12162           (error "No such group: %s" to-newsgroup))
12163       encoded)))
12164
12165 (defvar gnus-summary-save-parts-counter)
12166 (declare-function mm-uu-dissect "mm-uu" (&optional noheader mime-type))
12167
12168 (defun gnus-summary-save-parts (type dir n &optional reverse)
12169   "Save parts matching TYPE to DIR.
12170 If REVERSE, save parts that do not match TYPE."
12171   (interactive
12172    (list (read-string "Save parts of type: "
12173                       (or (car gnus-summary-save-parts-type-history)
12174                           gnus-summary-save-parts-default-mime)
12175                       'gnus-summary-save-parts-type-history)
12176          (setq gnus-summary-save-parts-last-directory
12177                (read-directory-name "Save to directory: "
12178                                     gnus-summary-save-parts-last-directory
12179                                     nil t))
12180          current-prefix-arg))
12181   (gnus-summary-iterate n
12182     (let ((gnus-display-mime-function nil)
12183           gnus-article-prepare-hook
12184           gnus-article-decode-hook
12185           gnus-display-mime-function
12186           gnus-break-pages
12187           (gnus-inhibit-treatment t))
12188       (gnus-summary-select-article))
12189     (with-current-buffer gnus-article-buffer
12190       (let ((handles (or gnus-article-mime-handles
12191                          (mm-dissect-buffer nil gnus-article-loose-mime)
12192                          (and gnus-article-emulate-mime
12193                               (mm-uu-dissect))))
12194             (gnus-summary-save-parts-counter 1))
12195         (when handles
12196           (gnus-summary-save-parts-1 type dir handles reverse)
12197           (unless gnus-article-mime-handles ;; Don't destroy this case.
12198             (mm-destroy-parts handles)))))))
12199
12200 (defun gnus-summary-save-parts-1 (type dir handle reverse)
12201   (if (stringp (car handle))
12202       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
12203               (cdr handle))
12204     (when (if reverse
12205               (not (string-match type (mm-handle-media-type handle)))
12206             (string-match type (mm-handle-media-type handle)))
12207       (let ((file (expand-file-name
12208                    (gnus-map-function
12209                     mm-file-name-rewrite-functions
12210                     (file-name-nondirectory
12211                      (or
12212                       (mm-handle-filename handle)
12213                       (format "%s.%d.%d" gnus-newsgroup-name
12214                               (cdr gnus-article-current)
12215                               gnus-summary-save-parts-counter))))
12216                    dir)))
12217         (incf gnus-summary-save-parts-counter)
12218         (unless (file-exists-p file)
12219           (mm-save-part-to-file handle file))))))
12220
12221 ;; Summary extract commands
12222
12223 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
12224   (let ((inhibit-read-only t)
12225         (article (gnus-summary-article-number))
12226         after-article b e)
12227     (unless (gnus-summary-goto-subject article)
12228       (error "No such article: %d" article))
12229     (gnus-summary-position-point)
12230     ;; If all commands are to be bunched up on one line, we collect
12231     ;; them here.
12232     (unless gnus-view-pseudos-separately
12233       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
12234             files action)
12235         (while ps
12236           (setq action (cdr (assq 'action (car ps))))
12237           (setq files (list (cdr (assq 'name (car ps)))))
12238           (while (and ps (cdr ps)
12239                       (string= (or action "1")
12240                                (or (cdr (assq 'action (cadr ps))) "2")))
12241             (push (cdr (assq 'name (cadr ps))) files)
12242             (setcdr ps (cddr ps)))
12243           (when files
12244             (when (not (string-match "%s" action))
12245               (push " " files))
12246             (push " " files)
12247             (when (assq 'execute (car ps))
12248               (setcdr (assq 'execute (car ps))
12249                       (funcall (if (string-match "%s" action)
12250                                    'format 'concat)
12251                                action
12252                                (mapconcat
12253                                 (lambda (f)
12254                                   (if (equal f " ")
12255                                       f
12256                                     (shell-quote-argument f)))
12257                                 files " ")))))
12258           (setq ps (cdr ps)))))
12259     (if (and gnus-view-pseudos (not not-view))
12260         (while pslist
12261           (when (assq 'execute (car pslist))
12262             (gnus-execute-command (cdr (assq 'execute (car pslist)))
12263                                   (eq gnus-view-pseudos 'not-confirm)))
12264           (setq pslist (cdr pslist)))
12265       (save-excursion
12266         (while pslist
12267           (setq after-article (or (cdr (assq 'article (car pslist)))
12268                                   (gnus-summary-article-number)))
12269           (gnus-summary-goto-subject after-article)
12270           (forward-line 1)
12271           (setq b (point))
12272           (insert "    " (file-name-nondirectory
12273                           (cdr (assq 'name (car pslist))))
12274                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
12275           (setq e (point))
12276           (forward-line -1)             ; back to `b'
12277           (gnus-add-text-properties
12278            b (1- e) (list 'gnus-number gnus-reffed-article-number
12279                           gnus-mouse-face-prop gnus-mouse-face))
12280           (gnus-data-enter
12281            after-article gnus-reffed-article-number
12282            gnus-unread-mark b (car pslist) 0 (- e b))
12283           (setq gnus-newsgroup-unreads
12284                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
12285                                          gnus-reffed-article-number))
12286           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
12287           (setq pslist (cdr pslist)))))))
12288
12289 (defun gnus-pseudos< (p1 p2)
12290   (let ((c1 (cdr (assq 'action p1)))
12291         (c2 (cdr (assq 'action p2))))
12292     (and c1 c2 (string< c1 c2))))
12293
12294 (defun gnus-request-pseudo-article (props)
12295   (cond ((assq 'execute props)
12296          (gnus-execute-command (cdr (assq 'execute props)))))
12297   (let ((gnus-current-article (gnus-summary-article-number)))
12298     (gnus-run-hooks 'gnus-mark-article-hook)))
12299
12300 (defun gnus-execute-command (command &optional automatic)
12301   (save-excursion
12302     (gnus-article-setup-buffer)
12303     (set-buffer gnus-article-buffer)
12304     (setq buffer-read-only nil)
12305     (let ((command (if automatic command
12306                      (read-string "Command: " (cons command 0)))))
12307       (erase-buffer)
12308       (insert "$ " command "\n\n")
12309       (if gnus-view-pseudo-asynchronously
12310           (start-process "gnus-execute" (current-buffer) shell-file-name
12311                          shell-command-switch command)
12312         (call-process shell-file-name nil t nil
12313                       shell-command-switch command)))))
12314
12315 ;; Summary kill commands.
12316
12317 (defun gnus-summary-edit-global-kill (article)
12318   "Edit the \"global\" kill file."
12319   (interactive (list (gnus-summary-article-number)))
12320   (gnus-group-edit-global-kill article))
12321
12322 (defun gnus-summary-edit-local-kill ()
12323   "Edit a local kill file applied to the current newsgroup."
12324   (interactive)
12325   (setq gnus-current-headers (gnus-summary-article-header))
12326   (gnus-group-edit-local-kill
12327    (gnus-summary-article-number) gnus-newsgroup-name))
12328
12329 ;;; Header reading.
12330
12331 (defun gnus-read-header (id &optional header)
12332   "Read the headers of article ID and enter them into the Gnus system."
12333   (let ((group gnus-newsgroup-name)
12334         (gnus-override-method
12335          (or
12336           gnus-override-method
12337           (and (gnus-news-group-p gnus-newsgroup-name)
12338                (car (gnus-refer-article-methods)))))
12339         where)
12340     ;; First we check to see whether the header in question is already
12341     ;; fetched.
12342     (if (stringp id)
12343         ;; This is a Message-ID.
12344         (setq header (or header (gnus-id-to-header id)))
12345       ;; This is an article number.
12346       (setq header (or header (gnus-summary-article-header id))))
12347     (if (and header
12348              (not (gnus-summary-article-sparse-p (mail-header-number header))))
12349         ;; We have found the header.
12350         header
12351       ;; We have to really fetch the header to this article.
12352       (with-current-buffer nntp-server-buffer
12353         (when (setq where (gnus-request-head id group))
12354           (nnheader-fold-continuation-lines)
12355           (goto-char (point-max))
12356           (insert ".\n")
12357           (goto-char (point-min))
12358           (insert "211 ")
12359           (princ (cond
12360                   ((numberp id) id)
12361                   ((cdr where) (cdr where))
12362                   (header (mail-header-number header))
12363                   (t gnus-reffed-article-number))
12364                  (current-buffer))
12365           (insert " Article retrieved.\n"))
12366         (if (or (not where)
12367                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
12368             ()                          ; Malformed head.
12369           (unless (gnus-summary-article-sparse-p (mail-header-number header))
12370             (when (and (stringp id)
12371                        (or
12372                         (not (string= (gnus-group-real-name group)
12373                                       (car where)))
12374                         (not (gnus-server-equal gnus-override-method
12375                                                 (gnus-group-method group)))))
12376               ;; If we fetched by Message-ID and the article came from
12377               ;; a different group (or server), we fudge some bogus
12378               ;; article numbers for this article.
12379               (mail-header-set-number header gnus-reffed-article-number))
12380             (with-current-buffer gnus-summary-buffer
12381               (decf gnus-reffed-article-number)
12382               (gnus-remove-header (mail-header-number header))
12383               (push header gnus-newsgroup-headers)
12384               (setq gnus-current-headers header)
12385               (push (mail-header-number header) gnus-newsgroup-limit)))
12386           header)))))
12387
12388 (defun gnus-remove-header (number)
12389   "Remove header NUMBER from `gnus-newsgroup-headers'."
12390   (if (and gnus-newsgroup-headers
12391            (= number (mail-header-number (car gnus-newsgroup-headers))))
12392       (pop gnus-newsgroup-headers)
12393     (let ((headers gnus-newsgroup-headers))
12394       (while (and (cdr headers)
12395                   (not (= number (mail-header-number (cadr headers)))))
12396         (pop headers))
12397       (when (cdr headers)
12398         (setcdr headers (cddr headers))))))
12399
12400 ;;;
12401 ;;; summary highlights
12402 ;;;
12403
12404 (defun gnus-highlight-selected-summary ()
12405   "Highlight selected article in summary buffer."
12406   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12407   (when gnus-summary-selected-face
12408     (save-excursion
12409       (let* ((beg (point-at-bol))
12410              (end (point-at-eol))
12411              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12412              (from (if (get-text-property beg gnus-mouse-face-prop)
12413                        beg
12414                      (or (next-single-property-change
12415                           beg gnus-mouse-face-prop nil end)
12416                          beg)))
12417              (to
12418               (if (= from end)
12419                   (- from 2)
12420                 (or (next-single-property-change
12421                      from gnus-mouse-face-prop nil end)
12422                     end))))
12423         ;; If no mouse-face prop on line we will have to = from = end,
12424         ;; so we highlight the entire line instead.
12425         (when (= (+ to 2) from)
12426           (setq from beg)
12427           (setq to end))
12428         (if gnus-newsgroup-selected-overlay
12429             ;; Move old overlay.
12430             (gnus-move-overlay
12431              gnus-newsgroup-selected-overlay from to (current-buffer))
12432           ;; Create new overlay.
12433           (gnus-overlay-put
12434            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12435            'face gnus-summary-selected-face))))))
12436
12437 (defvar gnus-summary-highlight-line-cached nil)
12438 (defvar gnus-summary-highlight-line-trigger nil)
12439
12440 (defun gnus-summary-highlight-line-0 ()
12441   (if (and (eq gnus-summary-highlight-line-trigger
12442                gnus-summary-highlight)
12443            gnus-summary-highlight-line-cached)
12444       gnus-summary-highlight-line-cached
12445     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12446           gnus-summary-highlight-line-cached
12447           (let* ((cond (list 'cond))
12448                  (c cond)
12449                  (list gnus-summary-highlight))
12450             (while list
12451               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12452                               nil))
12453               (setq c (cdr c)
12454                     list (cdr list)))
12455             (gnus-byte-compile (list 'lambda nil cond))))))
12456
12457 (defun gnus-summary-highlight-line ()
12458   "Highlight current line according to `gnus-summary-highlight'."
12459   (let* ((beg (point-at-bol))
12460          (article (or (gnus-summary-article-number) gnus-current-article))
12461          (score (or (cdr (assq article
12462                                gnus-newsgroup-scored))
12463                     gnus-summary-default-score 0))
12464          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12465          (inhibit-read-only t)
12466          (default gnus-summary-default-score)
12467          (default-high gnus-summary-default-high-score)
12468          (default-low gnus-summary-default-low-score)
12469          (uncached (and gnus-summary-use-undownloaded-faces
12470                         (memq article gnus-newsgroup-undownloaded)
12471                         (not (memq article gnus-newsgroup-cached)))))
12472     (let ((face (funcall (gnus-summary-highlight-line-0))))
12473       (unless (eq face (get-text-property beg 'face))
12474         (gnus-put-text-property-excluding-characters-with-faces
12475          beg (point-at-eol) 'face
12476          (setq face (if (boundp face) (symbol-value face) face)))
12477         (when gnus-summary-highlight-line-function
12478           (funcall gnus-summary-highlight-line-function article face))))))
12479
12480 (defun gnus-update-read-articles (group unread &optional compute)
12481   "Update the list of read articles in GROUP.
12482 UNREAD is a sorted list."
12483   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12484         (info (gnus-get-info group))
12485         (prev 1)
12486         read)
12487     (if (or (not info) (not active))
12488         ;; There is no info on this group if it was, in fact,
12489         ;; killed.  Gnus stores no information on killed groups, so
12490         ;; there's nothing to be done.
12491         ;; One could store the information somewhere temporarily,
12492         ;; perhaps...  Hmmm...
12493         ()
12494       ;; Remove any negative articles numbers.
12495       (while (and unread (< (car unread) 0))
12496         (setq unread (cdr unread)))
12497       ;; Remove any expired article numbers
12498       (while (and unread (< (car unread) (car active)))
12499         (setq unread (cdr unread)))
12500       ;; Compute the ranges of read articles by looking at the list of
12501       ;; unread articles.
12502       (while unread
12503         (when (/= (car unread) prev)
12504           (push (if (= prev (1- (car unread))) prev
12505                   (cons prev (1- (car unread))))
12506                 read))
12507         (setq prev (1+ (car unread)))
12508         (setq unread (cdr unread)))
12509       (when (<= prev (cdr active))
12510         (push (cons prev (cdr active)) read))
12511       (setq read (if (> (length read) 1) (nreverse read) read))
12512       (if compute
12513           read
12514         (save-excursion
12515           (let (setmarkundo)
12516             ;; Propagate the read marks to the backend.
12517             (when (and (or gnus-propagate-marks
12518                            (gnus-method-option-p
12519                             (gnus-find-method-for-group group)
12520                             'server-marks))
12521                        (gnus-check-backend-function 'request-set-mark group))
12522               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12523                     (add (gnus-remove-from-range read (gnus-info-read info))))
12524                 (when (or add del)
12525                   (unless (gnus-check-group group)
12526                     (error "Can't open server for %s" group))
12527                   (gnus-request-set-mark
12528                    group (delq nil (list (if add (list add 'add '(read)))
12529                                          (if del (list del 'del '(read))))))
12530                   (setq setmarkundo
12531                         `(gnus-request-set-mark
12532                           ,group
12533                           ',(delq nil (list
12534                                        (if del (list del 'add '(read)))
12535                                        (if add (list add 'del '(read))))))))))
12536             (set-buffer gnus-group-buffer)
12537             (gnus-undo-register
12538               `(progn
12539                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12540                  (gnus-info-set-read ',info ',(gnus-info-read info))
12541                  (gnus-get-unread-articles-in-group ',info
12542                                                     (gnus-active ,group))
12543                  (gnus-group-update-group ,group t)
12544                  ,setmarkundo))))
12545         ;; Enter this list into the group info.
12546         (gnus-info-set-read info read)
12547         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12548         (gnus-get-unread-articles-in-group info (gnus-active group))
12549         t))))
12550
12551 (defun gnus-offer-save-summaries ()
12552   "Offer to save all active summary buffers."
12553   (let (buffers)
12554     ;; Go through all buffers and find all summaries.
12555     (dolist (buffer (buffer-list))
12556       (when (and (setq buffer (buffer-name buffer))
12557                  (string-match "Summary" buffer)
12558                  (with-current-buffer buffer
12559                    ;; We check that this is, indeed, a summary buffer.
12560                    (and (eq major-mode 'gnus-summary-mode)
12561                         ;; Also make sure this isn't bogus.
12562                         gnus-newsgroup-prepared
12563                         ;; Also make sure that this isn't a
12564                         ;; dead summary buffer.
12565                         (not gnus-dead-summary-mode))))
12566         (push buffer buffers)))
12567     ;; Go through all these summary buffers and offer to save them.
12568     (when buffers
12569       (save-excursion
12570         (map-y-or-n-p
12571          "Update summary buffer %s? "
12572          (lambda (buf)
12573            (switch-to-buffer buf)
12574            (gnus-summary-exit))
12575          buffers)))))
12576
12577 (defun gnus-summary-setup-default-charset ()
12578   "Setup newsgroup default charset."
12579   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12580       (setq gnus-newsgroup-charset nil)
12581     (let* ((ignored-charsets
12582             (or gnus-newsgroup-ephemeral-ignored-charsets
12583                 (append
12584                  (and gnus-newsgroup-name
12585                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12586                  gnus-newsgroup-ignored-charsets))))
12587       (setq gnus-newsgroup-charset
12588             (or gnus-newsgroup-ephemeral-charset
12589                 (and gnus-newsgroup-name
12590                      (gnus-parameter-charset gnus-newsgroup-name))
12591                 gnus-default-charset))
12592       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12593            ignored-charsets))))
12594
12595 ;;;
12596 ;;; Mime Commands
12597 ;;;
12598
12599 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12600   "Display the current article buffer fully MIME-buttonized.
12601 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12602 treated as multipart/mixed."
12603   (interactive "P")
12604   (require 'gnus-art)
12605   (let ((gnus-unbuttonized-mime-types nil)
12606         (gnus-mime-display-multipart-as-mixed show-all-parts))
12607     (gnus-summary-show-article)))
12608
12609 (defun gnus-summary-repair-multipart (article)
12610   "Add a Content-Type header to a multipart article without one."
12611   (interactive (list (gnus-summary-article-number)))
12612   (gnus-with-article article
12613     (message-narrow-to-head)
12614     (message-remove-header "Mime-Version")
12615     (goto-char (point-max))
12616     (insert "Mime-Version: 1.0\n")
12617     (widen)
12618     (when (search-forward "\n--" nil t)
12619       (let ((separator (buffer-substring (point) (point-at-eol))))
12620         (message-narrow-to-head)
12621         (message-remove-header "Content-Type")
12622         (goto-char (point-max))
12623         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12624                         separator))
12625         (widen))))
12626   (let (gnus-mark-article-hook)
12627     (gnus-summary-select-article t t nil article)))
12628
12629 (defun gnus-summary-toggle-display-buttonized ()
12630   "Toggle the buttonizing of the article buffer."
12631   (interactive)
12632   (require 'gnus-art)
12633   (if (setq gnus-inhibit-mime-unbuttonizing
12634             (not gnus-inhibit-mime-unbuttonizing))
12635       (let ((gnus-unbuttonized-mime-types nil))
12636         (gnus-summary-show-article))
12637     (gnus-summary-show-article)))
12638
12639 ;;;
12640 ;;; Generic summary marking commands
12641 ;;;
12642
12643 (defvar gnus-summary-marking-alist
12644   '((read gnus-del-mark "d")
12645     (unread gnus-unread-mark "u")
12646     (ticked gnus-ticked-mark "!")
12647     (dormant gnus-dormant-mark "?")
12648     (expirable gnus-expirable-mark "e"))
12649   "An alist of names/marks/keystrokes.")
12650
12651 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12652 (defvar gnus-summary-mark-map)
12653
12654 (defun gnus-summary-make-all-marking-commands ()
12655   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12656   (dolist (elem gnus-summary-marking-alist)
12657     (apply 'gnus-summary-make-marking-command elem)))
12658
12659 (defun gnus-summary-make-marking-command (name mark keystroke)
12660   (let ((map (make-sparse-keymap)))
12661     (define-key gnus-summary-generic-mark-map keystroke map)
12662     (dolist (lway `((next "next" next nil "n")
12663                     (next-unread "next unread" next t "N")
12664                     (prev "previous" prev nil "p")
12665                     (prev-unread "previous unread" prev t "P")
12666                     (nomove "" nil nil ,keystroke)))
12667       (let ((func (gnus-summary-make-marking-command-1
12668                    mark (car lway) lway name)))
12669         (setq func (eval func))
12670         (define-key map (nth 4 lway) func)))))
12671
12672 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12673   `(defun ,(intern
12674             (format "gnus-summary-put-mark-as-%s%s"
12675                     name (if (eq way 'nomove)
12676                              ""
12677                            (concat "-" (symbol-name way)))))
12678      (n)
12679      ,(format
12680        "Mark the current article as %s%s.
12681 If N, the prefix, then repeat N times.
12682 If N is negative, move in reverse order.
12683 The difference between N and the actual number of articles marked is
12684 returned."
12685        name (cadr lway))
12686      (interactive "p")
12687      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12688
12689 (defun gnus-summary-generic-mark (n mark move unread)
12690   "Mark N articles with MARK."
12691   (unless (eq major-mode 'gnus-summary-mode)
12692     (error "This command can only be used in the summary buffer"))
12693   (gnus-summary-show-thread)
12694   (let ((nummove
12695          (cond
12696           ((eq move 'next) 1)
12697           ((eq move 'prev) -1)
12698           (t 0))))
12699     (if (zerop nummove)
12700         (setq n 1)
12701       (when (< n 0)
12702         (setq n (abs n)
12703               nummove (* -1 nummove))))
12704     (while (and (> n 0)
12705                 (gnus-summary-mark-article nil mark)
12706                 (zerop (gnus-summary-next-subject nummove unread t)))
12707       (setq n (1- n)))
12708     (when (/= 0 n)
12709       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12710     (gnus-summary-recenter)
12711     (gnus-summary-position-point)
12712     (gnus-set-mode-line 'summary)
12713     n))
12714
12715 (defun gnus-summary-insert-articles (articles)
12716   (when (setq articles
12717               (gnus-sorted-difference articles
12718                                       (mapcar (lambda (h)
12719                                                 (mail-header-number h))
12720                                               gnus-newsgroup-headers)))
12721     (setq gnus-newsgroup-headers
12722           (gnus-merge 'list
12723                       gnus-newsgroup-headers
12724                       (gnus-fetch-headers articles)
12725                       'gnus-article-sort-by-number))
12726     ;; Suppress duplicates?
12727     (when gnus-suppress-duplicates
12728       (gnus-dup-suppress-articles))
12729
12730     (if (and gnus-fetch-old-headers
12731              (eq gnus-headers-retrieved-by 'nov))
12732         ;; We might want to build some more threads first.
12733         (if (eq gnus-fetch-old-headers 'invisible)
12734             (gnus-build-all-threads)
12735           (gnus-build-old-threads))
12736       ;; Mark the inserted articles that are unread as unread.
12737       (setq gnus-newsgroup-unreads
12738             (gnus-sorted-nunion
12739              gnus-newsgroup-unreads
12740              (gnus-sorted-nintersection
12741               (gnus-list-of-unread-articles gnus-newsgroup-name)
12742               articles)))
12743       ;; Mark the inserted articles as selected so that the information
12744       ;; of the marks having been changed by a user may be updated when
12745       ;; exiting this group.  See `gnus-summary-update-info'.
12746       (dolist (art articles)
12747         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12748     ;; Let the Gnus agent mark articles as read.
12749     (when gnus-agent
12750       (gnus-agent-get-undownloaded-list))
12751     ;; Remove list identifiers from subject
12752     (gnus-summary-remove-list-identifiers)
12753     ;; First and last article in this newsgroup.
12754     (when gnus-newsgroup-headers
12755       (setq gnus-newsgroup-begin
12756             (mail-header-number (car gnus-newsgroup-headers))
12757             gnus-newsgroup-end
12758             (mail-header-number
12759              (gnus-last-element gnus-newsgroup-headers))))
12760     (when gnus-use-scoring
12761       (gnus-possibly-score-headers))))
12762
12763 (defun gnus-summary-insert-old-articles (&optional all)
12764   "Insert all old articles in this group.
12765 If ALL is non-nil, already read articles become readable.
12766 If ALL is a number, fetch this number of articles."
12767   (interactive "P")
12768   (prog1
12769       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12770             older len)
12771         (setq older
12772               ;; Some nntp servers lie about their active range.  When
12773               ;; this happens, the active range can be in the millions.
12774               ;; Use a compressed range to avoid creating a huge list.
12775               (gnus-range-difference (list gnus-newsgroup-active) old))
12776         (setq len (gnus-range-length older))
12777         (cond
12778          ((null older) nil)
12779          ((numberp all)
12780           (if (< all len)
12781               (let ((older-range (nreverse older)))
12782                 (setq older nil)
12783
12784                 (while (> all 0)
12785                   (let* ((r (pop older-range))
12786                          (min (if (numberp r) r (car r)))
12787                          (max (if (numberp r) r (cdr r))))
12788                     (while (and (<= min max)
12789                                 (> all 0))
12790                       (push max older)
12791                       (setq all (1- all)
12792                             max (1- max))))))
12793             (setq older (gnus-uncompress-range older))))
12794          (all
12795           (setq older (gnus-uncompress-range older)))
12796          (t
12797           (when (and (numberp gnus-large-newsgroup)
12798                    (> len gnus-large-newsgroup))
12799               (let* ((cursor-in-echo-area nil)
12800                      (initial (gnus-parameter-large-newsgroup-initial
12801                                gnus-newsgroup-name))
12802                      (input
12803                       (read-string
12804                        (format
12805                         "How many articles from %s (%s %d): "
12806                         (gnus-group-decoded-name gnus-newsgroup-name)
12807                         (if initial "max" "default")
12808                         len)
12809                        (if initial
12810                            (cons (number-to-string initial)
12811                                  0)))))
12812                 (unless (string-match "^[ \t]*$" input)
12813                   (setq all (string-to-number input))
12814                   (if (< all len)
12815                       (let ((older-range (nreverse older)))
12816                         (setq older nil)
12817
12818                         (while (> all 0)
12819                           (let* ((r (pop older-range))
12820                                  (min (if (numberp r) r (car r)))
12821                                  (max (if (numberp r) r (cdr r))))
12822                             (while (and (<= min max)
12823                                         (> all 0))
12824                               (push max older)
12825                               (setq all (1- all)
12826                                     max (1- max))))))))))
12827           (setq older (gnus-uncompress-range older))))
12828         (if (not older)
12829             (message "No old news.")
12830           (gnus-summary-insert-articles older)
12831           (gnus-summary-limit (gnus-sorted-nunion old older))))
12832     (gnus-summary-position-point)))
12833
12834 (defun gnus-summary-insert-new-articles ()
12835   "Insert all new articles in this group."
12836   (interactive)
12837   (prog1
12838       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12839             (old-high gnus-newsgroup-highest)
12840             (nnmail-fetched-sources (list t))
12841             i new)
12842         (setq gnus-newsgroup-active
12843               (gnus-copy-sequence
12844                (gnus-activate-group gnus-newsgroup-name 'scan)))
12845         (setq i (cdr gnus-newsgroup-active)
12846               gnus-newsgroup-highest i)
12847         (while (> i old-high)
12848           (push i new)
12849           (decf i))
12850         (if (not new)
12851             (message "No gnus is bad news")
12852           (gnus-summary-insert-articles new)
12853           (setq gnus-newsgroup-unreads
12854                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12855           (gnus-summary-limit (gnus-sorted-nunion old new))))
12856     (gnus-summary-position-point)))
12857
12858 ;;; Bookmark support for Gnus.
12859 (declare-function bookmark-make-record-default
12860                   "bookmark" (&optional no-file no-context posn))
12861 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
12862 (declare-function bookmark-default-handler "bookmark" (bmk))
12863 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
12864 (defvar bookmark-yank-point)
12865 (defvar bookmark-current-buffer)
12866
12867 (defun gnus-summary-bookmark-make-record ()
12868   "Make a bookmark entry for a Gnus summary buffer."
12869   (let (pos buf)
12870     (unless (and (derived-mode-p 'gnus-summary-mode) gnus-article-current)
12871       (save-restriction              ; FIXME is it necessary to widen?
12872         (widen) (setq pos (point))) ; Set position in gnus-article buffer.
12873       (setq buf "art") ; We are recording bookmark from article buffer.
12874       (setq bookmark-yank-point (point))
12875       (setq bookmark-current-buffer (current-buffer))
12876       (gnus-article-show-summary))      ; Go back in summary buffer.
12877     ;; We are now recording bookmark from summary buffer.
12878     (unless buf (setq buf "sum"))
12879     (let* ((subject (elt (gnus-summary-article-header) 1))
12880            (grp     (car gnus-article-current))
12881            (art     (cdr gnus-article-current))
12882            (head    (gnus-summary-article-header art))
12883            (id      (mail-header-id head)))
12884       `(,subject
12885         ,@(condition-case nil
12886               (bookmark-make-record-default 'no-file 'no-context pos)
12887             (wrong-number-of-arguments
12888              (bookmark-make-record-default 'point-only)))
12889         (location . ,(format "Gnus-%s %s:%d:%s" buf grp art id))
12890         (group . ,grp) (article . ,art)
12891         (message-id . ,id) (handler . gnus-summary-bookmark-jump)))))
12892
12893 ;;;###autoload
12894 (defun gnus-summary-bookmark-jump (bookmark)
12895   "Handler function for record returned by `gnus-summary-bookmark-make-record'.
12896 BOOKMARK is a bookmark name or a bookmark record."
12897   (let ((group    (bookmark-prop-get bookmark 'group))
12898         (article  (bookmark-prop-get bookmark 'article))
12899         (id       (bookmark-prop-get bookmark 'message-id))
12900         (buf      (car (split-string (bookmark-prop-get bookmark 'location)))))
12901     (gnus-fetch-group group (list article))
12902     (gnus-summary-insert-cached-articles)
12903     (gnus-summary-goto-article id nil 'force)
12904     ;; FIXME we have to wait article buffer is ready (only large buffer)
12905     ;; Is there a better solution to know that?
12906     ;; If we don't wait `bookmark-default-handler' will have no chance
12907     ;; to set position. However there is no error, just wrong pos.
12908     (sit-for 1)
12909     (when (string= buf "Gnus-art")
12910       (other-window 1))
12911     (bookmark-default-handler
12912      `(""
12913        (buffer . ,(current-buffer))
12914        . ,(bookmark-get-bookmark-record bookmark)))))
12915
12916 (gnus-summary-make-all-marking-commands)
12917
12918 (gnus-ems-redefine)
12919
12920 (provide 'gnus-sum)
12921
12922 (run-hooks 'gnus-sum-load-hook)
12923
12924 ;; Local Variables:
12925 ;; coding: iso-8859-1
12926 ;; End:
12927
12928 ;;; gnus-sum.el ends here