(gnus-summary-insert-new-articles): Protect against servers that are down.
[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-refer-thread-use-nnir nil
122   "*Use nnir to search an entire server when referring threads. A
123 nil value will only search for thread-related articles in the
124 current group."
125   :group 'gnus-thread
126   :type 'boolean)
127
128 (defcustom gnus-summary-make-false-root 'adopt
129   "*nil means that Gnus won't gather loose threads.
130 If the root of a thread has expired or been read in a previous
131 session, the information necessary to build a complete thread has been
132 lost.  Instead of having many small sub-threads from this original thread
133 scattered all over the summary buffer, Gnus can gather them.
134
135 If non-nil, Gnus will try to gather all loose sub-threads from an
136 original thread into one large thread.
137
138 If this variable is non-nil, it should be one of `none', `adopt',
139 `dummy' or `empty'.
140
141 If this variable is `none', Gnus will not make a false root, but just
142 present the sub-threads after another.
143 If this variable is `dummy', Gnus will create a dummy root that will
144 have all the sub-threads as children.
145 If this variable is `adopt', Gnus will make one of the \"children\"
146 the parent and mark all the step-children as such.
147 If this variable is `empty', the \"children\" are printed with empty
148 subject fields.  (Or rather, they will be printed with a string
149 given by the `gnus-summary-same-subject' variable.)"
150   :group 'gnus-thread
151   :type '(choice (const :tag "off" nil)
152                  (const none)
153                  (const dummy)
154                  (const adopt)
155                  (const empty)))
156
157 (defcustom gnus-summary-make-false-root-always nil
158   "Always make a false dummy root."
159   :version "22.1"
160   :group 'gnus-thread
161   :type 'boolean)
162
163 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
164   "*A regexp to match subjects to be excluded from loose thread gathering.
165 As loose thread gathering is done on subjects only, that means that
166 there can be many false gatherings performed.  By rooting out certain
167 common subjects, gathering might become saner."
168   :group 'gnus-thread
169   :type 'regexp)
170
171 (defcustom gnus-summary-gather-subject-limit nil
172   "*Maximum length of subject comparisons when gathering loose threads.
173 Use nil to compare full subjects.  Setting this variable to a low
174 number will help gather threads that have been corrupted by
175 newsreaders chopping off subject lines, but it might also mean that
176 unrelated articles that have subject that happen to begin with the
177 same few characters will be incorrectly gathered.
178
179 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
180 comparing subjects."
181   :group 'gnus-thread
182   :type '(choice (const :tag "off" nil)
183                  (const fuzzy)
184                  (sexp :menu-tag "on" t)))
185
186 (defcustom gnus-simplify-subject-functions nil
187   "List of functions taking a string argument that simplify subjects.
188 The functions are applied recursively.
189
190 Useful functions to put in this list include:
191 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
192 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
193   :group 'gnus-thread
194   :type '(repeat function))
195
196 (defcustom gnus-simplify-ignored-prefixes nil
197   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
198   :group 'gnus-thread
199   :type '(choice (const :tag "off" nil)
200                  regexp))
201
202 (defcustom gnus-build-sparse-threads nil
203   "*If non-nil, fill in the gaps in threads.
204 If `some', only fill in the gaps that are needed to tie loose threads
205 together.  If `more', fill in all leaf nodes that Gnus can find.  If
206 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
207   :group 'gnus-thread
208   :type '(choice (const :tag "off" nil)
209                  (const some)
210                  (const more)
211                  (sexp :menu-tag "all" t)))
212
213 (defcustom gnus-summary-thread-gathering-function
214   'gnus-gather-threads-by-subject
215   "*Function used for gathering loose threads.
216 There are two pre-defined functions: `gnus-gather-threads-by-subject',
217 which only takes Subjects into consideration; and
218 `gnus-gather-threads-by-references', which compared the References
219 headers of the articles to find matches."
220   :group 'gnus-thread
221   :type '(radio (function-item gnus-gather-threads-by-subject)
222                 (function-item gnus-gather-threads-by-references)
223                 (function :tag "other")))
224
225 (defcustom gnus-summary-same-subject ""
226   "*String indicating that the current article has the same subject as the previous.
227 This variable will only be used if the value of
228 `gnus-summary-make-false-root' is `empty'."
229   :group 'gnus-summary-format
230   :type 'string)
231
232 (defcustom gnus-summary-goto-unread nil
233   "*If t, many commands will go to the next unread article.
234 This applies to marking commands as well as other commands that
235 \"naturally\" select the next article, like, for instance, `SPC' at
236 the end of an article.
237
238 If nil, the marking commands do NOT go to the next unread article
239 \(they go to the next article instead).  If `never', commands that
240 usually go to the next unread article, will go to the next article,
241 whether it is read or not."
242   :version "24.1"
243   :group 'gnus-summary-marks
244   :link '(custom-manual "(gnus)Setting Marks")
245   :type '(choice (const :tag "off" nil)
246                  (const never)
247                  (sexp :menu-tag "on" t)))
248
249 (defcustom gnus-summary-default-score 0
250   "*Default article score level.
251 All scores generated by the score files will be added to this score.
252 If this variable is nil, scoring will be disabled."
253   :group 'gnus-score-default
254   :type '(choice (const :tag "disable")
255                  integer))
256
257 (defcustom gnus-summary-default-high-score 0
258   "*Default threshold for a high scored article.
259 An article will be highlighted as high scored if its score is greater
260 than this score."
261   :version "22.1"
262   :group 'gnus-score-default
263   :type 'integer)
264
265 (defcustom gnus-summary-default-low-score 0
266   "*Default threshold for a low scored article.
267 An article will be highlighted as low scored if its score is smaller
268 than this score."
269   :version "22.1"
270   :group 'gnus-score-default
271   :type 'integer)
272
273 (defcustom gnus-summary-zcore-fuzz 0
274   "*Fuzziness factor for the zcore in the summary buffer.
275 Articles with scores closer than this to `gnus-summary-default-score'
276 will not be marked."
277   :group 'gnus-summary-format
278   :type 'integer)
279
280 (defcustom gnus-simplify-subject-fuzzy-regexp nil
281   "*Strings to be removed when doing fuzzy matches.
282 This can either be a regular expression or list of regular expressions
283 that will be removed from subject strings if fuzzy subject
284 simplification is selected."
285   :group 'gnus-thread
286   :type '(repeat regexp))
287
288 (defcustom gnus-show-threads t
289   "*If non-nil, display threads in summary mode."
290   :group 'gnus-thread
291   :type 'boolean)
292
293 (defcustom gnus-thread-hide-subtree nil
294   "*If non-nil, hide all threads initially.
295 This can be a predicate specifier which says which threads to hide.
296 If threads are hidden, you have to run the command
297 `gnus-summary-show-thread' by hand or select an article."
298   :group 'gnus-thread
299   :type '(radio (sexp :format "Non-nil\n"
300                       :match (lambda (widget value)
301                                (not (or (consp value) (functionp value))))
302                       :value t)
303                 (const nil)
304                 (sexp :tag "Predicate specifier")))
305
306 (defcustom gnus-thread-hide-killed t
307   "*If non-nil, hide killed threads automatically."
308   :group 'gnus-thread
309   :type 'boolean)
310
311 (defcustom gnus-thread-ignore-subject t
312   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
313 If nil, articles that have different subjects from their parents will
314 start separate threads."
315   :group 'gnus-thread
316   :type 'boolean)
317
318 (defcustom gnus-thread-operation-ignore-subject t
319   "*If non-nil, subjects will be ignored when doing thread commands.
320 This affects commands like `gnus-summary-kill-thread' and
321 `gnus-summary-lower-thread'.
322
323 If this variable is nil, articles in the same thread with different
324 subjects will not be included in the operation in question.  If this
325 variable is `fuzzy', only articles that have subjects that are fuzzily
326 equal will be included."
327   :group 'gnus-thread
328   :type '(choice (const :tag "off" nil)
329                  (const fuzzy)
330                  (sexp :tag "on" t)))
331
332 (defcustom gnus-thread-indent-level 4
333   "*Number that says how much each sub-thread should be indented."
334   :group 'gnus-thread
335   :type 'integer)
336
337 (defcustom gnus-auto-extend-newsgroup t
338   "*If non-nil, extend newsgroup forward and backward when requested."
339   :group 'gnus-summary-choose
340   :type 'boolean)
341
342 (defcustom gnus-auto-select-first t
343   "If non-nil, select an article on group entry.
344 An article is selected automatically when entering a group
345 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
346 `gnus-summary-catchup-and-goto-next-group'.
347
348 Which article is selected is controlled by the variable
349 `gnus-auto-select-subject'.
350
351 If you want to prevent automatic selection of articles in some
352 newsgroups, set the variable to nil in `gnus-select-group-hook'."
353   ;; Commands include...
354   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
355   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
356   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
357   :group 'gnus-group-select
358   :type '(choice (const :tag "none" nil)
359                  (sexp :menu-tag "first" t)))
360
361 (defcustom gnus-auto-select-subject 'unseen-or-unread
362   "*Says what subject to place under point when entering a group.
363
364 This variable can either be the symbols `first' (place point on the
365 first subject), `unread' (place point on the subject line of the first
366 unread article), `best' (place point on the subject line of the
367 higest-scored article), `unseen' (place point on the subject line of
368 the first unseen article), `unseen-or-unread' (place point on the subject
369 line of the first unseen article or, if all articles have been seen, on the
370 subject line of the first unread article), or a function to be called to
371 place point on some subject line."
372   :version "24.1"
373   :group 'gnus-group-select
374   :type '(choice (const best)
375                  (const unread)
376                  (const first)
377                  (const unseen)
378                  (const unseen-or-unread)))
379
380 (defcustom gnus-auto-select-next t
381   "*If non-nil, offer to go to the next group from the end of the previous.
382 If the value is t and the next newsgroup is empty, Gnus will exit
383 summary mode and go back to group mode.  If the value is neither nil
384 nor t, Gnus will select the following unread newsgroup.  In
385 particular, if the value is the symbol `quietly', the next unread
386 newsgroup will be selected without any confirmation, and if it is
387 `almost-quietly', the next group will be selected without any
388 confirmation if you are located on the last article in the group.
389 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
390 will go to the next group without confirmation."
391   :group 'gnus-summary-maneuvering
392   :type '(choice (const :tag "off" nil)
393                  (const quietly)
394                  (const almost-quietly)
395                  (const slightly-quietly)
396                  (sexp :menu-tag "on" t)))
397
398 (defcustom gnus-auto-select-same nil
399   "*If non-nil, select the next article with the same subject.
400 If there are no more articles with the same subject, go to
401 the first unread article."
402   :group 'gnus-summary-maneuvering
403   :type 'boolean)
404
405 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
406   "What article should be selected after exiting an ephemeral group.
407 Valid values include:
408
409 `next'
410   Select the next article.
411 `next-unread'
412   Select the next unread article.
413 `next-noselect'
414   Move the cursor to the next article.  This is the default.
415 `next-unread-noselect'
416   Move the cursor to the next unread article.
417
418 If it has any other value or there is no next (unread) article, the
419 article selected before entering to the ephemeral group will appear."
420   :version "23.1" ;; No Gnus
421   :group 'gnus-summary-maneuvering
422   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
423                  (const next) (const next-unread)
424                  (const next-noselect) (const next-unread-noselect)
425                  (sexp :tag "other" :value nil)))
426
427 (defcustom gnus-auto-goto-ignores 'unfetched
428   "*Says how to handle unfetched articles when maneuvering.
429
430 This variable can either be the symbols nil (maneuver to any
431 article), `undownloaded' (maneuvering while unplugged ignores articles
432 that have not been fetched), `always-undownloaded' (maneuvering always
433 ignores articles that have not been fetched), `unfetched' (maneuvering
434 ignores articles whose headers have not been fetched).
435
436 NOTE: The list of unfetched articles will always be nil when plugged
437 and, when unplugged, a subset of the undownloaded article list."
438   :version "22.1"
439   :group 'gnus-summary-maneuvering
440   :type '(choice (const :tag "None" nil)
441                  (const :tag "Undownloaded when unplugged" undownloaded)
442                  (const :tag "Undownloaded" always-undownloaded)
443                  (const :tag "Unfetched" unfetched)))
444
445 (defcustom gnus-summary-check-current nil
446   "*If non-nil, consider the current article when moving.
447 The \"unread\" movement commands will stay on the same line if the
448 current article is unread."
449   :group 'gnus-summary-maneuvering
450   :type 'boolean)
451
452 (defcustom gnus-auto-center-summary 2
453   "*If non-nil, always center the current summary buffer.
454 In particular, if `vertical' do only vertical recentering.  If non-nil
455 and non-`vertical', do both horizontal and vertical recentering."
456   :group 'gnus-summary-maneuvering
457   :type '(choice (const :tag "none" nil)
458                  (const vertical)
459                  (integer :tag "height")
460                  (sexp :menu-tag "both" t)))
461
462 (defcustom gnus-auto-center-group t
463   "If non-nil, always center the group buffer."
464   :group 'gnus-summary-maneuvering
465   :type 'boolean)
466
467 (defcustom gnus-show-all-headers nil
468   "*If non-nil, don't hide any headers."
469   :group 'gnus-article-hiding
470   :group 'gnus-article-headers
471   :type 'boolean)
472
473 (defcustom gnus-summary-ignore-duplicates nil
474   "*If non-nil, ignore articles with identical Message-ID headers."
475   :group 'gnus-summary
476   :type 'boolean)
477
478 (defcustom gnus-single-article-buffer nil
479   "*If non-nil, display all articles in the same buffer.
480 If nil, each group will get its own article buffer."
481   :version "24.1"
482   :group 'gnus-article-various
483   :type 'boolean)
484
485 (defcustom gnus-widen-article-window nil
486   "If non-nil, selecting the article buffer will display only the article buffer."
487   :version "24.1"
488   :group 'gnus-article-various
489   :type 'boolean)
490
491 (defcustom gnus-break-pages t
492   "*If non-nil, do page breaking on articles.
493 The page delimiter is specified by the `gnus-page-delimiter'
494 variable."
495   :group 'gnus-article-various
496   :type 'boolean)
497
498 (defcustom gnus-move-split-methods nil
499   "*Variable used to suggest where articles are to be moved to.
500 It uses the same syntax as the `gnus-split-methods' variable.
501 However, whereas `gnus-split-methods' specifies file names as targets,
502 this variable specifies group names."
503   :group 'gnus-summary-mail
504   :type '(repeat (choice (list :value (fun) function)
505                          (cons :value ("" "") regexp (repeat string))
506                          (sexp :value nil))))
507
508 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
509   "Function used to compute default prefix for article move/copy/etc prompts.
510 The function should take one argument, a group name, and return a
511 string with the suggested prefix."
512   :group 'gnus-summary-mail
513   :type 'function)
514
515 ;; FIXME: Although the custom type is `character' for the following variables,
516 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
517
518 (defcustom gnus-unread-mark ?           ;Whitespace
519   "*Mark used for unread articles."
520   :group 'gnus-summary-marks
521   :type 'character)
522
523 (defcustom gnus-ticked-mark ?!
524   "*Mark used for ticked articles."
525   :group 'gnus-summary-marks
526   :type 'character)
527
528 (defcustom gnus-dormant-mark ??
529   "*Mark used for dormant articles."
530   :group 'gnus-summary-marks
531   :type 'character)
532
533 (defcustom gnus-del-mark ?r
534   "*Mark used for del'd articles."
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-read-mark ?R
539   "*Mark used for read articles."
540   :group 'gnus-summary-marks
541   :type 'character)
542
543 (defcustom gnus-expirable-mark ?E
544   "*Mark used for expirable articles."
545   :group 'gnus-summary-marks
546   :type 'character)
547
548 (defcustom gnus-killed-mark ?K
549   "*Mark used for killed articles."
550   :group 'gnus-summary-marks
551   :type 'character)
552
553 (defcustom gnus-spam-mark ?$
554   "*Mark used for spam articles."
555   :version "22.1"
556   :group 'gnus-summary-marks
557   :type 'character)
558
559 (defcustom gnus-kill-file-mark ?X
560   "*Mark used for articles killed by kill files."
561   :group 'gnus-summary-marks
562   :type 'character)
563
564 (defcustom gnus-low-score-mark ?Y
565   "*Mark used for articles with a low score."
566   :group 'gnus-summary-marks
567   :type 'character)
568
569 (defcustom gnus-catchup-mark ?C
570   "*Mark used for articles that are caught up."
571   :group 'gnus-summary-marks
572   :type 'character)
573
574 (defcustom gnus-replied-mark ?A
575   "*Mark used for articles that have been replied to."
576   :group 'gnus-summary-marks
577   :type 'character)
578
579 (defcustom gnus-forwarded-mark ?F
580   "*Mark used for articles that have been forwarded."
581   :version "22.1"
582   :group 'gnus-summary-marks
583   :type 'character)
584
585 (defcustom gnus-recent-mark ?N
586   "*Mark used for articles that are recent."
587   :version "22.1"
588   :group 'gnus-summary-marks
589   :type 'character)
590
591 (defcustom gnus-cached-mark ?*
592   "*Mark used for articles that are in the cache."
593   :group 'gnus-summary-marks
594   :type 'character)
595
596 (defcustom gnus-saved-mark ?S
597   "*Mark used for articles that have been saved."
598   :group 'gnus-summary-marks
599   :type 'character)
600
601 (defcustom gnus-unseen-mark ?.
602   "*Mark used for articles that haven't been seen."
603   :version "22.1"
604   :group 'gnus-summary-marks
605   :type 'character)
606
607 (defcustom gnus-no-mark ?               ;Whitespace
608   "*Mark used for articles that have no other secondary mark."
609   :version "22.1"
610   :group 'gnus-summary-marks
611   :type 'character)
612
613 (defcustom gnus-ancient-mark ?O
614   "*Mark used for ancient articles."
615   :group 'gnus-summary-marks
616   :type 'character)
617
618 (defcustom gnus-sparse-mark ?Q
619   "*Mark used for sparsely reffed articles."
620   :group 'gnus-summary-marks
621   :type 'character)
622
623 (defcustom gnus-canceled-mark ?G
624   "*Mark used for canceled articles."
625   :group 'gnus-summary-marks
626   :type 'character)
627
628 (defcustom gnus-duplicate-mark ?M
629   "*Mark used for duplicate articles."
630   :group 'gnus-summary-marks
631   :type 'character)
632
633 (defcustom gnus-undownloaded-mark ?-
634   "*Mark used for articles that weren't downloaded."
635   :version "22.1"
636   :group 'gnus-summary-marks
637   :type 'character)
638
639 (defcustom gnus-downloaded-mark ?+
640   "*Mark used for articles that were downloaded."
641   :group 'gnus-summary-marks
642   :type 'character)
643
644 (defcustom gnus-downloadable-mark ?%
645   "*Mark used for articles that are to be downloaded."
646   :group 'gnus-summary-marks
647   :type 'character)
648
649 (defcustom gnus-unsendable-mark ?=
650   "*Mark used for articles that won't be sent."
651   :group 'gnus-summary-marks
652   :type 'character)
653
654 (defcustom gnus-score-over-mark ?+
655   "*Score mark used for articles with high scores."
656   :group 'gnus-summary-marks
657   :type 'character)
658
659 (defcustom gnus-score-below-mark ?-
660   "*Score mark used for articles with low scores."
661   :group 'gnus-summary-marks
662   :type 'character)
663
664 (defcustom gnus-empty-thread-mark ?     ;Whitespace
665   "*There is no thread under the article."
666   :group 'gnus-summary-marks
667   :type 'character)
668
669 (defcustom gnus-not-empty-thread-mark ?=
670   "*There is a thread under the article."
671   :group 'gnus-summary-marks
672   :type 'character)
673
674 (defcustom gnus-view-pseudo-asynchronously nil
675   "*If non-nil, Gnus will view pseudo-articles asynchronously."
676   :group 'gnus-extract-view
677   :type 'boolean)
678
679 (defcustom gnus-auto-expirable-marks
680   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
681         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
682         gnus-duplicate-mark)
683   "*The list of marks converted into expiration if a group is auto-expirable."
684   :version "24.1"
685   :group 'gnus-summary
686   :type '(repeat character))
687
688 (defcustom gnus-inhibit-user-auto-expire t
689   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
690   :version "21.1"
691   :group 'gnus-summary
692   :type 'boolean)
693
694 (defcustom gnus-mark-copied-or-moved-articles-as-expirable nil
695   "If non-nil, mark articles copied or moved to auto-expire group as expirable.
696 If nil, the expirable marks will be unchanged except that the marks
697 will be removed when copying or moving articles to a group that has
698 not turned auto-expire on.  If non-nil, articles that have been read
699 will be marked as expirable when being copied or moved to a group in
700 which auto-expire is turned on."
701   :version "23.2"
702   :type 'boolean
703   :group 'gnus-summary-marks)
704
705 (defcustom gnus-view-pseudos nil
706   "*If `automatic', pseudo-articles will be viewed automatically.
707 If `not-confirm', pseudos will be viewed automatically, and the user
708 will not be asked to confirm the command."
709   :group 'gnus-extract-view
710   :type '(choice (const :tag "off" nil)
711                  (const automatic)
712                  (const not-confirm)))
713
714 (defcustom gnus-view-pseudos-separately t
715   "*If non-nil, one pseudo-article will be created for each file to be viewed.
716 If nil, all files that use the same viewing command will be given as a
717 list of parameters to that command."
718   :group 'gnus-extract-view
719   :type 'boolean)
720
721 (defcustom gnus-insert-pseudo-articles t
722   "*If non-nil, insert pseudo-articles when decoding articles."
723   :group 'gnus-extract-view
724   :type 'boolean)
725
726 (defcustom gnus-summary-dummy-line-format
727   "   %(:                             :%) %S\n"
728   "*The format specification for the dummy roots in the summary buffer.
729 It works along the same lines as a normal formatting string,
730 with some simple extensions.
731
732 %S  The subject
733
734 General format specifiers can also be used.
735 See `(gnus)Formatting Variables'."
736   :link '(custom-manual "(gnus)Formatting Variables")
737   :group 'gnus-threading
738   :type 'string)
739
740 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
741   "*The format specification for the summary mode line.
742 It works along the same lines as a normal formatting string,
743 with some simple extensions:
744
745 %G  Group name
746 %p  Unprefixed group name
747 %A  Current article number
748 %z  Current article score
749 %V  Gnus version
750 %U  Number of unread articles in the group
751 %e  Number of unselected articles in the group
752 %Z  A string with unread/unselected article counts
753 %g  Shortish group name
754 %S  Subject of the current article
755 %u  User-defined spec
756 %s  Current score file name
757 %d  Number of dormant articles
758 %r  Number of articles that have been marked as read in this session
759 %E  Number of articles expunged by the score files"
760   :group 'gnus-summary-format
761   :type 'string)
762
763 (defcustom gnus-list-identifiers nil
764   "Regexp that matches list identifiers to be removed from subject.
765 This can also be a list of regexps."
766   :version "21.1"
767   :group 'gnus-summary-format
768   :group 'gnus-article-hiding
769   :type '(choice (const :tag "none" nil)
770                  (regexp :value ".*")
771                  (repeat :value (".*") regexp)))
772
773 (defcustom gnus-summary-mark-below 0
774   "*Mark all articles with a score below this variable as read.
775 This variable is local to each summary buffer and usually set by the
776 score file."
777   :group 'gnus-score-default
778   :type 'integer)
779
780 (defun gnus-widget-reversible-match (widget value)
781   "Ignoring WIDGET, convert VALUE to internal form.
782 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
783   ;; (debug value)
784   (or (symbolp value)
785       (and (listp value)
786            (eq (length value) 2)
787            (eq (nth 0 value) 'not)
788            (symbolp (nth 1 value)))))
789
790 (defun gnus-widget-reversible-to-internal (widget value)
791   "Ignoring WIDGET, convert VALUE to internal form.
792 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
793 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
794   ;; (debug value)
795   (if (atom value)
796       (list value nil)
797     (list (nth 1 value) t)))
798
799 (defun gnus-widget-reversible-to-external (widget value)
800   "Ignoring WIDGET, convert VALUE to external form.
801 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
802 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
803   ;; (debug value)
804   (if (nth 1 value)
805       (list 'not (nth 0 value))
806     (nth 0 value)))
807
808 (define-widget 'gnus-widget-reversible 'group
809   "A `group' that convert values."
810   :match 'gnus-widget-reversible-match
811   :value-to-internal 'gnus-widget-reversible-to-internal
812   :value-to-external 'gnus-widget-reversible-to-external)
813
814 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
815   "*List of functions used for sorting articles in the summary buffer.
816
817 Each function takes two articles and returns non-nil if the first
818 article should be sorted before the other.  If you use more than one
819 function, the primary sort function should be the last.  You should
820 probably always include `gnus-article-sort-by-number' in the list of
821 sorting functions -- preferably first.  Also note that sorting by date
822 is often much slower than sorting by number, and the sorting order is
823 very similar.  (Sorting by date means sorting by the time the message
824 was sent, sorting by number means sorting by arrival time.)
825
826 Each item can also be a list `(not F)' where F is a function;
827 this reverses the sort order.
828
829 Ready-made functions include `gnus-article-sort-by-number',
830 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
831 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
832 and `gnus-article-sort-by-score'.
833
834 When threading is turned on, the variable `gnus-thread-sort-functions'
835 controls how articles are sorted."
836   :group 'gnus-summary-sort
837   :type '(repeat (gnus-widget-reversible
838                   (choice (function-item gnus-article-sort-by-number)
839                           (function-item gnus-article-sort-by-author)
840                           (function-item gnus-article-sort-by-subject)
841                           (function-item gnus-article-sort-by-date)
842                           (function-item gnus-article-sort-by-score)
843                           (function-item gnus-article-sort-by-random)
844                           (function :tag "other"))
845                   (boolean :tag "Reverse order"))))
846
847
848 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
849   "*List of functions used for sorting threads in the summary buffer.
850 By default, threads are sorted by article number.
851
852 Each function takes two threads and returns non-nil if the first
853 thread should be sorted before the other.  If you use more than one
854 function, the primary sort function should be the last.  You should
855 probably always include `gnus-thread-sort-by-number' in the list of
856 sorting functions -- preferably first.  Also note that sorting by date
857 is often much slower than sorting by number, and the sorting order is
858 very similar.  (Sorting by date means sorting by the time the message
859 was sent, sorting by number means sorting by arrival time.)
860
861 Each list item can also be a list `(not F)' where F is a
862 function; this specifies reversed sort order.
863
864 Ready-made functions include `gnus-thread-sort-by-number',
865 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
866 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
867 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
868 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
869 and `gnus-thread-sort-by-total-score' (see
870 `gnus-thread-score-function').
871
872 When threading is turned off, the variable
873 `gnus-article-sort-functions' controls how articles are sorted."
874   :group 'gnus-summary-sort
875   :type '(repeat
876           (gnus-widget-reversible
877            (choice (function-item gnus-thread-sort-by-number)
878                    (function-item gnus-thread-sort-by-author)
879                    (function-item gnus-thread-sort-by-recipient)
880                    (function-item gnus-thread-sort-by-subject)
881                    (function-item gnus-thread-sort-by-date)
882                    (function-item gnus-thread-sort-by-score)
883                    (function-item gnus-thread-sort-by-most-recent-number)
884                    (function-item gnus-thread-sort-by-most-recent-date)
885                    (function-item gnus-thread-sort-by-random)
886                    (function-item gnus-thread-sort-by-total-score)
887                    (function :tag "other"))
888            (boolean :tag "Reverse order"))))
889
890 (defcustom gnus-thread-score-function '+
891   "*Function used for calculating the total score of a thread.
892
893 The function is called with the scores of the article and each
894 subthread and should then return the score of the thread.
895
896 Some functions you can use are `+', `max', or `min'."
897   :group 'gnus-summary-sort
898   :type 'function)
899
900 (defcustom gnus-summary-expunge-below nil
901   "All articles that have a score less than this variable will be expunged.
902 This variable is local to the summary buffers."
903   :group 'gnus-score-default
904   :type '(choice (const :tag "off" nil)
905                  integer))
906
907 (defcustom gnus-thread-expunge-below nil
908   "All threads that have a total score less than this variable will be expunged.
909 See `gnus-thread-score-function' for en explanation of what a
910 \"thread score\" is.
911
912 This variable is local to the summary buffers."
913   :group 'gnus-threading
914   :group 'gnus-score-default
915   :type '(choice (const :tag "off" nil)
916                  integer))
917
918 (defcustom gnus-summary-mode-hook nil
919   "*A hook for Gnus summary mode.
920 This hook is run before any variables are set in the summary buffer."
921   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
922   :group 'gnus-summary-various
923   :type 'hook)
924
925 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
926 (when (featurep 'xemacs)
927   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
928   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
929   (add-hook 'gnus-summary-mode-hook
930             'gnus-xmas-switch-horizontal-scrollbar-off))
931
932 (defcustom gnus-summary-menu-hook nil
933   "*Hook run after the creation of the summary mode menu."
934   :group 'gnus-summary-visual
935   :type 'hook)
936
937 (defcustom gnus-summary-exit-hook nil
938   "*A hook called on exit from the summary buffer.
939 It will be called with point in the group buffer."
940   :group 'gnus-summary-exit
941   :type 'hook)
942
943 (defcustom gnus-summary-prepare-hook nil
944   "*A hook called after the summary buffer has been generated.
945 If you want to modify the summary buffer, you can use this hook."
946   :group 'gnus-summary-various
947   :type 'hook)
948
949 (defcustom gnus-summary-prepared-hook nil
950   "*A hook called as the last thing after the summary buffer has been generated."
951   :group 'gnus-summary-various
952   :type 'hook)
953
954 (defcustom gnus-summary-generate-hook nil
955   "*A hook run just before generating the summary buffer.
956 This hook is commonly used to customize threading variables and the
957 like."
958   :group 'gnus-summary-various
959   :type 'hook)
960
961 (defcustom gnus-select-group-hook nil
962   "*A hook called when a newsgroup is selected.
963
964 If you'd like to simplify subjects like the
965 `gnus-summary-next-same-subject' command does, you can use the
966 following hook:
967
968  (add-hook gnus-select-group-hook
969            (lambda ()
970              (mapcar (lambda (header)
971                        (mail-header-set-subject
972                         header
973                         (gnus-simplify-subject
974                          (mail-header-subject header) 're-only)))
975                      gnus-newsgroup-headers)))"
976   :group 'gnus-group-select
977   :type 'hook)
978
979 (defcustom gnus-select-article-hook nil
980   "*A hook called when an article is selected."
981   :group 'gnus-summary-choose
982   :options '(gnus-agent-fetch-selected-article)
983   :type 'hook)
984
985 (defcustom gnus-visual-mark-article-hook
986   (list 'gnus-highlight-selected-summary)
987   "*Hook run after selecting an article in the summary buffer.
988 It is meant to be used for highlighting the article in some way.  It
989 is not run if `gnus-visual' is nil."
990   :group 'gnus-summary-visual
991   :type 'hook)
992
993 (defcustom gnus-parse-headers-hook nil
994   "*A hook called before parsing the headers."
995   :group 'gnus-various
996   :type 'hook)
997
998 (defcustom gnus-exit-group-hook nil
999   "*A hook called when exiting summary mode.
1000 This hook is not called from the non-updating exit commands like `Q'."
1001   :group 'gnus-various
1002   :type 'hook)
1003
1004 (defcustom gnus-summary-update-hook nil
1005   "*A hook called when a summary line is changed.
1006 The hook will not be called if `gnus-visual' is nil.
1007
1008 The default function `gnus-summary-highlight-line' will
1009 highlight the line according to the `gnus-summary-highlight'
1010 variable."
1011   :group 'gnus-summary-visual
1012   :type 'hook)
1013
1014 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
1015   "*A hook called when an article is selected for the first time.
1016 The hook is intended to mark an article as read (or unread)
1017 automatically when it is selected."
1018   :group 'gnus-summary-choose
1019   :type 'hook)
1020
1021 (defcustom gnus-group-no-more-groups-hook nil
1022   "*A hook run when returning to group mode having no more (unread) groups."
1023   :group 'gnus-group-select
1024   :type 'hook)
1025
1026 (defcustom gnus-ps-print-hook nil
1027   "*A hook run before ps-printing something from Gnus."
1028   :group 'gnus-summary
1029   :type 'hook)
1030
1031 (defcustom gnus-summary-article-move-hook nil
1032   "*A hook called after an article is moved, copied, respooled, or crossposted."
1033   :version "22.1"
1034   :group 'gnus-summary
1035   :type 'hook)
1036
1037 (defcustom gnus-summary-article-delete-hook nil
1038   "*A hook called after an article is deleted."
1039   :version "22.1"
1040   :group 'gnus-summary
1041   :type 'hook)
1042
1043 (defcustom gnus-summary-article-expire-hook nil
1044   "*A hook called after an article is expired."
1045   :version "22.1"
1046   :group 'gnus-summary
1047   :type 'hook)
1048
1049 (defcustom gnus-summary-display-arrow
1050   (and (fboundp 'display-graphic-p)
1051        (display-graphic-p))
1052   "*If non-nil, display an arrow highlighting the current article."
1053   :version "22.1"
1054   :group 'gnus-summary
1055   :type 'boolean)
1056
1057 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1058   "Face used for highlighting the current article in the summary buffer."
1059   :group 'gnus-summary-visual
1060   :type 'face)
1061
1062 (defvar gnus-tmp-downloaded nil)
1063
1064 (defcustom gnus-summary-highlight
1065   '(((eq mark gnus-canceled-mark)
1066      . gnus-summary-cancelled)
1067     ((and uncached (> score default-high))
1068      . gnus-summary-high-undownloaded)
1069     ((and uncached (< score default-low))
1070      . gnus-summary-low-undownloaded)
1071     (uncached
1072      . gnus-summary-normal-undownloaded)
1073     ((and (> score default-high)
1074           (or (eq mark gnus-dormant-mark)
1075               (eq mark gnus-ticked-mark)))
1076      . gnus-summary-high-ticked)
1077     ((and (< score default-low)
1078           (or (eq mark gnus-dormant-mark)
1079               (eq mark gnus-ticked-mark)))
1080      . gnus-summary-low-ticked)
1081     ((or (eq mark gnus-dormant-mark)
1082          (eq mark gnus-ticked-mark))
1083      . gnus-summary-normal-ticked)
1084     ((and (> score default-high) (eq mark gnus-ancient-mark))
1085      . gnus-summary-high-ancient)
1086     ((and (< score default-low) (eq mark gnus-ancient-mark))
1087      . gnus-summary-low-ancient)
1088     ((eq mark gnus-ancient-mark)
1089      . gnus-summary-normal-ancient)
1090     ((and (> score default-high) (eq mark gnus-unread-mark))
1091      . gnus-summary-high-unread)
1092     ((and (< score default-low) (eq mark gnus-unread-mark))
1093      . gnus-summary-low-unread)
1094     ((eq mark gnus-unread-mark)
1095      . gnus-summary-normal-unread)
1096     ((> score default-high)
1097      . gnus-summary-high-read)
1098     ((< score default-low)
1099      . gnus-summary-low-read)
1100     (t
1101      . gnus-summary-normal-read))
1102   "*Controls the highlighting of summary buffer lines.
1103
1104 A list of (FORM . FACE) pairs.  When deciding how a particular
1105 summary line should be displayed, each form is evaluated.  The content
1106 of the face field after the first true form is used.  You can change
1107 how those summary lines are displayed, by editing the face field.
1108
1109 You can use the following variables in the FORM field.
1110
1111 score:        The article's score.
1112 default:      The default article score.
1113 default-high: The default score for high scored articles.
1114 default-low:  The default score for low scored articles.
1115 below:        The score below which articles are automatically marked as read.
1116 mark:         The article's mark.
1117 uncached:     Non-nil if the article is uncached."
1118   :group 'gnus-summary-visual
1119   :type '(repeat (cons (sexp :tag "Form" nil)
1120                        face)))
1121 (put 'gnus-summary-highlight 'risky-local-variable t)
1122
1123 (defcustom gnus-alter-header-function nil
1124   "Function called to allow alteration of article header structures.
1125 The function is called with one parameter, the article header vector,
1126 which it may alter in any way."
1127   :type '(choice (const :tag "None" nil)
1128                  function)
1129   :group 'gnus-summary)
1130
1131 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1132   "Function used to decode a string with encoded words.")
1133
1134 (defvar gnus-decode-encoded-address-function
1135   'mail-decode-encoded-address-string
1136   "Function used to decode addresses with encoded words.")
1137
1138 (defcustom gnus-extra-headers '(To Cc Keywords Gcc Newsgroups)
1139   "*Extra headers to parse."
1140   :version "24.1"                       ; added Cc Keywords Gcc
1141   :group 'gnus-summary
1142   :type '(repeat symbol))
1143
1144 (defcustom gnus-ignored-from-addresses
1145   (and user-mail-address
1146        (not (string= user-mail-address ""))
1147        (regexp-quote user-mail-address))
1148   "*From headers that may be suppressed in favor of To headers.
1149 This can be a regexp or a list of regexps."
1150   :version "21.1"
1151   :group 'gnus-summary
1152   :type '(choice regexp
1153                  (repeat :tag "Regexp List" regexp)))
1154
1155 (defsubst gnus-ignored-from-addresses ()
1156   (gmm-regexp-concat gnus-ignored-from-addresses))
1157
1158 (defcustom gnus-summary-to-prefix "-> "
1159   "*String prefixed to the To field in the summary line when
1160 using `gnus-ignored-from-addresses'."
1161   :version "22.1"
1162   :group 'gnus-summary
1163   :type 'string)
1164
1165 (defcustom gnus-summary-newsgroup-prefix "=> "
1166   "*String prefixed to the Newsgroup field in the summary
1167 line when using `gnus-ignored-from-addresses'."
1168   :version "22.1"
1169   :group 'gnus-summary
1170   :type 'string)
1171
1172 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1173   "List of charsets that should be ignored.
1174 When these charsets are used in the \"charset\" parameter, the
1175 default charset will be used instead."
1176   :version "21.1"
1177   :type '(repeat symbol)
1178   :group 'gnus-charset)
1179
1180 (defcustom gnus-newsgroup-maximum-articles nil
1181   "The maximum number of articles a newsgroup.
1182 If this is a number, old articles in a newsgroup exceeding this number
1183 are silently ignored.  If it is nil, no article is ignored.  Note that
1184 setting this variable to a number might prevent you from reading very
1185 old articles."
1186   :group 'gnus-group-select
1187   :version "22.2"
1188   :type '(choice (const :tag "No limit" nil)
1189                  integer))
1190
1191 (gnus-define-group-parameter
1192  ignored-charsets
1193  :type list
1194  :function-document
1195  "Return the ignored charsets of GROUP."
1196  :variable gnus-group-ignored-charsets-alist
1197  :variable-default
1198  '(("alt\\.chinese\\.text" iso-8859-1))
1199  :variable-document
1200  "Alist of regexps (to match group names) and charsets that should be ignored.
1201 When these charsets are used in the \"charset\" parameter, the
1202 default charset will be used instead."
1203  :variable-group gnus-charset
1204  :variable-type '(repeat (cons (regexp :tag "Group")
1205                                (repeat symbol)))
1206  :parameter-type '(choice :tag "Ignored charsets"
1207                           :value nil
1208                           (repeat (symbol)))
1209  :parameter-document       "\
1210 List of charsets that should be ignored.
1211
1212 When these charsets are used in the \"charset\" parameter, the
1213 default charset will be used instead.")
1214
1215 (defcustom gnus-group-highlight-words-alist nil
1216   "Alist of group regexps and highlight regexps.
1217 This variable uses the same syntax as `gnus-emphasis-alist'."
1218   :version "21.1"
1219   :type '(repeat (cons (regexp :tag "Group")
1220                        (repeat (list (regexp :tag "Highlight regexp")
1221                                      (number :tag "Group for entire word" 0)
1222                                      (number :tag "Group for displayed part" 0)
1223                                      (symbol :tag "Face"
1224                                              gnus-emphasis-highlight-words)))))
1225   :group 'gnus-summary-visual)
1226
1227 (defcustom gnus-summary-show-article-charset-alist
1228   nil
1229   "Alist of number and charset.
1230 The article will be shown with the charset corresponding to the
1231 numbered argument.
1232 For example: ((1 . cn-gb-2312) (2 . big5))."
1233   :version "21.1"
1234   :type '(repeat (cons (number :tag "Argument" 1)
1235                        (symbol :tag "Charset")))
1236   :group 'gnus-charset)
1237
1238 (defcustom gnus-preserve-marks t
1239   "Whether marks are preserved when moving, copying and respooling messages."
1240   :version "21.1"
1241   :type 'boolean
1242   :group 'gnus-summary-marks)
1243
1244 (defcustom gnus-propagate-marks nil
1245   "If non-nil, Gnus will store and retrieve marks from the backends.
1246 This means that marks will be stored both in .newsrc.eld and in
1247 the backend, and will slow operation down somewhat."
1248   :type 'boolean
1249   :group 'gnus-summary-marks)
1250
1251 (defcustom gnus-alter-articles-to-read-function nil
1252   "Function to be called to alter the list of articles to be selected."
1253   :type '(choice (const nil) function)
1254   :group 'gnus-summary)
1255
1256 (defcustom gnus-orphan-score nil
1257   "*All orphans get this score added.  Set in the score file."
1258   :group 'gnus-score-default
1259   :type '(choice (const nil)
1260                  integer))
1261
1262 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1263   "*A regexp to match MIME parts when saving multiple parts of a
1264 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1265 This regexp will be used by default when prompting the user for which
1266 type of files to save."
1267   :group 'gnus-summary
1268   :type 'regexp)
1269
1270 (defcustom gnus-read-all-available-headers nil
1271   "Whether Gnus should parse all headers made available to it.
1272 This is mostly relevant for slow back ends where the user may
1273 wish to widen the summary buffer to include all headers
1274 that were fetched."
1275   :version "22.1"
1276   :group 'gnus-summary
1277   :type '(choice boolean regexp))
1278
1279 (defcustom gnus-summary-pipe-output-default-command nil
1280   "Command (and optional arguments) used to pipe article to subprocess.
1281 This will be used as the default command if it is non-nil.  The value
1282 will be updated if you modify it when executing the command
1283 `gnus-summary-pipe-output' or the function `gnus-summary-save-in-pipe'."
1284   :version "23.1" ;; No Gnus
1285   :group 'gnus-summary
1286   :type '(radio (const :tag "None" nil) (string :tag "Command")))
1287
1288 (defcustom gnus-summary-muttprint-program "muttprint"
1289   "Command (and optional arguments) used to run Muttprint.
1290 The value will be updated if you modify it when executing the command
1291 `gnus-summary-muttprint'."
1292   :version "22.1"
1293   :group 'gnus-summary
1294   :type 'string)
1295
1296 (defcustom gnus-article-loose-mime t
1297   "If non-nil, don't require MIME-Version header.
1298 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1299 supply the MIME-Version header or deliberately strip it from the mail.
1300 If non-nil (the default), Gnus will treat some articles as MIME
1301 even if the MIME-Version header is missing."
1302   :version "22.1"
1303   :type 'boolean
1304   :group 'gnus-article-mime)
1305
1306 (defcustom gnus-article-emulate-mime t
1307   "If non-nil, use MIME emulation for uuencode and the like.
1308 This means that Gnus will search message bodies for text that look
1309 like uuencoded bits, yEncoded bits, and so on, and present that using
1310 the normal Gnus MIME machinery."
1311   :version "22.1"
1312   :type 'boolean
1313   :group 'gnus-article-mime)
1314
1315 ;;; Internal variables
1316
1317 (defvar gnus-summary-display-cache nil)
1318 (defvar gnus-article-mime-handles nil)
1319 (defvar gnus-article-decoded-p nil)
1320 (defvar gnus-article-charset nil)
1321 (defvar gnus-article-ignored-charsets nil)
1322 (defvar gnus-scores-exclude-files nil)
1323 (defvar gnus-page-broken nil)
1324
1325 (defvar gnus-original-article nil)
1326 (defvar gnus-article-internal-prepare-hook nil)
1327 (defvar gnus-newsgroup-process-stack nil)
1328
1329 (defvar gnus-thread-indent-array nil)
1330 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1331 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1332   "Function called to sort the articles within a thread after it has been gathered together.")
1333
1334 (defvar gnus-summary-save-parts-type-history nil)
1335 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1336
1337 ;; Avoid highlighting in kill files.
1338 (defvar gnus-summary-inhibit-highlight nil)
1339 (defvar gnus-newsgroup-selected-overlay nil)
1340 (defvar gnus-inhibit-limiting nil)
1341 (defvar gnus-newsgroup-adaptive-score-file nil)
1342 (defvar gnus-current-score-file nil)
1343 (defvar gnus-current-move-group nil)
1344 (defvar gnus-current-copy-group nil)
1345 (defvar gnus-current-crosspost-group nil)
1346 (defvar gnus-newsgroup-display nil)
1347
1348 (defvar gnus-newsgroup-dependencies nil)
1349 (defvar gnus-newsgroup-adaptive nil)
1350 (defvar gnus-summary-display-article-function nil)
1351 (defvar gnus-summary-highlight-line-function nil
1352   "Function called after highlighting a summary line.")
1353
1354 (defvar gnus-summary-line-format-alist
1355   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1356     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1357     (?s gnus-tmp-subject-or-nil ?s)
1358     (?n gnus-tmp-name ?s)
1359     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1360         ?s)
1361     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1362             gnus-tmp-from) ?s)
1363     (?F gnus-tmp-from ?s)
1364     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1365     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1366     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1367     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1368     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1369     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1370     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1371     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1372     (?L gnus-tmp-lines ?s)
1373     (?Z (or ,(gnus-macroexpand-all
1374               '(nnir-article-rsv (mail-header-number gnus-tmp-header)))
1375             0) ?d)
1376     (?G (or ,(gnus-macroexpand-all
1377               '(nnir-article-group (mail-header-number gnus-tmp-header)))
1378             "") ?s)
1379     (?g (or ,(gnus-macroexpand-all
1380               '(gnus-group-short-name
1381                 (nnir-article-group (mail-header-number gnus-tmp-header))))
1382             "") ?s)
1383     (?O gnus-tmp-downloaded ?c)
1384     (?I gnus-tmp-indentation ?s)
1385     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1386     (?R gnus-tmp-replied ?c)
1387     (?\[ gnus-tmp-opening-bracket ?c)
1388     (?\] gnus-tmp-closing-bracket ?c)
1389     (?\> (make-string gnus-tmp-level ? ) ?s)
1390     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1391     (?i gnus-tmp-score ?d)
1392     (?z gnus-tmp-score-char ?c)
1393     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1394     (?U gnus-tmp-unread ?c)
1395     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1396         ?s)
1397     (?t (gnus-summary-number-of-articles-in-thread
1398          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1399         ?d)
1400     (?e (gnus-summary-number-of-articles-in-thread
1401          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1402         ?c)
1403     (?u gnus-tmp-user-defined ?s)
1404     (?P (gnus-pick-line-number) ?d)
1405     (?B gnus-tmp-thread-tree-header-string ?s)
1406     (user-date (gnus-user-date
1407                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1408   "An alist of format specifications that can appear in summary lines.
1409 These are paired with what variables they correspond with, along with
1410 the type of the variable (string, integer, character, etc).")
1411
1412 (defvar gnus-summary-dummy-line-format-alist
1413   `((?S gnus-tmp-subject ?s)
1414     (?N gnus-tmp-number ?d)
1415     (?u gnus-tmp-user-defined ?s)))
1416
1417 (defvar gnus-summary-mode-line-format-alist
1418   `((?G gnus-tmp-group-name ?s)
1419     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1420     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1421     (?A gnus-tmp-article-number ?d)
1422     (?Z gnus-tmp-unread-and-unselected ?s)
1423     (?V gnus-version ?s)
1424     (?U gnus-tmp-unread-and-unticked ?d)
1425     (?S gnus-tmp-subject ?s)
1426     (?e gnus-tmp-unselected ?d)
1427     (?u gnus-tmp-user-defined ?s)
1428     (?d (length gnus-newsgroup-dormant) ?d)
1429     (?t (length gnus-newsgroup-marked) ?d)
1430     (?h (length gnus-newsgroup-spam-marked) ?d)
1431     (?r (length gnus-newsgroup-reads) ?d)
1432     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1433     (?E gnus-newsgroup-expunged-tally ?d)
1434     (?s (gnus-current-score-file-nondirectory) ?s)))
1435
1436 ;; This is here rather than in gnus-art for compilation reasons.
1437 (defvar gnus-article-mode-line-format-alist
1438   (nconc '((?w (gnus-article-wash-status) ?s)
1439            (?m (gnus-article-mime-part-status) ?s))
1440          gnus-summary-mode-line-format-alist))
1441
1442 (defvar gnus-last-search-regexp nil
1443   "Default regexp for article search command.")
1444
1445 (defvar gnus-last-shell-command nil
1446   "Default shell command on article.")
1447
1448 (defvar gnus-newsgroup-agentized nil
1449   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1450 (defvar gnus-newsgroup-begin nil)
1451 (defvar gnus-newsgroup-end nil)
1452 (defvar gnus-newsgroup-last-rmail nil)
1453 (defvar gnus-newsgroup-last-mail nil)
1454 (defvar gnus-newsgroup-last-folder nil)
1455 (defvar gnus-newsgroup-last-file nil)
1456 (defvar gnus-newsgroup-last-directory nil)
1457 (defvar gnus-newsgroup-auto-expire nil)
1458 (defvar gnus-newsgroup-active nil)
1459 (defvar gnus-newsgroup-highest nil)
1460
1461 (defvar gnus-newsgroup-data nil)
1462 (defvar gnus-newsgroup-data-reverse nil)
1463 (defvar gnus-newsgroup-limit nil)
1464 (defvar gnus-newsgroup-limits nil)
1465 (defvar gnus-summary-use-undownloaded-faces nil)
1466
1467 (defvar gnus-newsgroup-unreads nil
1468   "Sorted list of unread articles in the current newsgroup.")
1469
1470 (defvar gnus-newsgroup-unselected nil
1471   "Sorted list of unselected unread articles in the current newsgroup.")
1472
1473 (defvar gnus-newsgroup-reads nil
1474   "Alist of read articles and article marks in the current newsgroup.")
1475
1476 (defvar gnus-newsgroup-expunged-tally nil)
1477
1478 (defvar gnus-newsgroup-marked nil
1479   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1480
1481 (defvar gnus-newsgroup-spam-marked nil
1482   "List of ranges of articles that have been marked as spam.")
1483
1484 (defvar gnus-newsgroup-killed nil
1485   "List of ranges of articles that have been through the scoring process.")
1486
1487 (defvar gnus-newsgroup-cached nil
1488   "Sorted list of articles that come from the article cache.")
1489
1490 (defvar gnus-newsgroup-saved nil
1491   "List of articles that have been saved.")
1492
1493 (defvar gnus-newsgroup-kill-headers nil)
1494
1495 (defvar gnus-newsgroup-replied nil
1496   "List of articles that have been replied to in the current newsgroup.")
1497
1498 (defvar gnus-newsgroup-forwarded nil
1499   "List of articles that have been forwarded in the current newsgroup.")
1500
1501 (defvar gnus-newsgroup-recent nil
1502   "List of articles that have are recent in the current newsgroup.")
1503
1504 (defvar gnus-newsgroup-expirable nil
1505   "Sorted list of articles in the current newsgroup that can be expired.")
1506
1507 (defvar gnus-newsgroup-processable nil
1508   "List of articles in the current newsgroup that can be processed.")
1509
1510 (defvar gnus-newsgroup-downloadable nil
1511   "Sorted list of articles in the current newsgroup that can be processed.")
1512
1513 (defvar gnus-newsgroup-unfetched nil
1514   "Sorted list of articles in the current newsgroup whose headers have
1515 not been fetched into the agent.
1516
1517 This list will always be a subset of gnus-newsgroup-undownloaded.")
1518
1519 (defvar gnus-newsgroup-undownloaded nil
1520   "List of articles in the current newsgroup that haven't been downloaded.")
1521
1522 (defvar gnus-newsgroup-unsendable nil
1523   "List of articles in the current newsgroup that won't be sent.")
1524
1525 (defvar gnus-newsgroup-bookmarks nil
1526   "List of articles in the current newsgroup that have bookmarks.")
1527
1528 (defvar gnus-newsgroup-dormant nil
1529   "Sorted list of dormant articles in the current newsgroup.")
1530
1531 (defvar gnus-newsgroup-unseen nil
1532   "List of unseen articles in the current newsgroup.")
1533
1534 (defvar gnus-newsgroup-seen nil
1535   "Range of seen articles in the current newsgroup.")
1536
1537 (defvar gnus-newsgroup-articles nil
1538   "List of articles in the current newsgroup.")
1539
1540 (defvar gnus-newsgroup-scored nil
1541   "List of scored articles in the current newsgroup.")
1542
1543 (defvar gnus-newsgroup-headers nil
1544   "List of article headers in the current newsgroup.")
1545
1546 (defvar gnus-newsgroup-threads nil)
1547
1548 (defvar gnus-newsgroup-prepared nil
1549   "Whether the current group has been prepared properly.")
1550
1551 (defvar gnus-newsgroup-ancient nil
1552   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1553
1554 (defvar gnus-newsgroup-sparse nil)
1555
1556 (defvar gnus-current-article nil)
1557 (defvar gnus-article-current nil)
1558 (defvar gnus-current-headers nil)
1559 (defvar gnus-have-all-headers nil)
1560 (defvar gnus-last-article nil)
1561 (defvar gnus-newsgroup-history nil)
1562 (defvar gnus-newsgroup-charset nil)
1563 (defvar gnus-newsgroup-ephemeral-charset nil)
1564 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1565
1566 (defvar gnus-article-before-search nil)
1567
1568 (defvar gnus-summary-local-variables
1569   '(gnus-newsgroup-name
1570
1571     ;; Marks lists
1572     gnus-newsgroup-unreads
1573     gnus-newsgroup-unselected
1574     gnus-newsgroup-marked
1575     gnus-newsgroup-spam-marked
1576     gnus-newsgroup-reads
1577     gnus-newsgroup-saved
1578     gnus-newsgroup-replied
1579     gnus-newsgroup-forwarded
1580     gnus-newsgroup-recent
1581     gnus-newsgroup-expirable
1582     gnus-newsgroup-killed
1583     gnus-newsgroup-unseen
1584     gnus-newsgroup-seen
1585     gnus-newsgroup-cached
1586     gnus-newsgroup-downloadable
1587     gnus-newsgroup-undownloaded
1588     gnus-newsgroup-unsendable
1589
1590     gnus-newsgroup-begin gnus-newsgroup-end
1591     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1592     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1593     gnus-newsgroup-last-directory
1594     gnus-newsgroup-auto-expire
1595     gnus-newsgroup-processable
1596     gnus-newsgroup-unfetched
1597     gnus-newsgroup-articles
1598     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1599     gnus-newsgroup-headers gnus-newsgroup-threads
1600     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1601     gnus-current-article gnus-current-headers gnus-have-all-headers
1602     gnus-last-article gnus-article-internal-prepare-hook
1603     (gnus-summary-article-delete-hook . global)
1604     (gnus-summary-article-move-hook . global)
1605     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1606     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1607     gnus-thread-expunge-below
1608     gnus-score-alist gnus-current-score-file
1609     (gnus-summary-expunge-below . global)
1610     (gnus-summary-mark-below . global)
1611     (gnus-orphan-score . global)
1612     gnus-newsgroup-active gnus-scores-exclude-files
1613     gnus-newsgroup-highest
1614     gnus-newsgroup-history gnus-newsgroup-ancient
1615     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1616     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1617     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1618     (gnus-newsgroup-expunged-tally . 0)
1619     gnus-cache-removable-articles
1620     gnus-newsgroup-data gnus-newsgroup-data-reverse
1621     gnus-newsgroup-limit gnus-newsgroup-limits
1622     gnus-newsgroup-charset gnus-newsgroup-display
1623     gnus-summary-use-undownloaded-faces)
1624   "Variables that are buffer-local to the summary buffers.")
1625
1626 (defvar gnus-newsgroup-variables nil
1627   "A list of variables that have separate values in different newsgroups.
1628 A list of newsgroup (summary buffer) local variables, or cons of
1629 variables and their default expressions to be evalled (when the default
1630 values are not nil), that should be made global while the summary buffer
1631 is active.
1632
1633 Note: The default expressions will be evaluated (using function `eval')
1634 before assignment to the local variable rather than just assigned to it.
1635 If the default expression is the symbol `global', that symbol will not
1636 be evaluated but the global value of the local variable will be used
1637 instead.
1638
1639 These variables can be used to set variables in the group parameters
1640 while still allowing them to affect operations done in other buffers.
1641 For example:
1642
1643 \(setq gnus-newsgroup-variables
1644      '(message-use-followup-to
1645        (gnus-visible-headers .
1646          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1647 ")
1648
1649 (eval-when-compile
1650   ;; Bind features so that require will believe that gnus-sum has
1651   ;; already been loaded (avoids infinite recursion)
1652   (let ((features (cons 'gnus-sum features)))
1653     (require 'gnus-art)))
1654
1655 ;; MIME stuff.
1656
1657 (defvar gnus-decode-encoded-word-methods
1658   '(mail-decode-encoded-word-string)
1659   "List of methods used to decode encoded words.
1660
1661 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1662 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1663 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1664 whose names match REGEXP.
1665
1666 For example:
1667 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1668  mail-decode-encoded-word-string
1669  (\"chinese\" . rfc1843-decode-string))")
1670
1671 (defvar gnus-decode-encoded-word-methods-cache nil)
1672
1673 (defun gnus-multi-decode-encoded-word-string (string)
1674   "Apply the functions from `gnus-encoded-word-methods' that match."
1675   (unless (and gnus-decode-encoded-word-methods-cache
1676                (eq gnus-newsgroup-name
1677                    (car gnus-decode-encoded-word-methods-cache)))
1678     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1679     (dolist (method gnus-decode-encoded-word-methods)
1680       (if (symbolp method)
1681           (nconc gnus-decode-encoded-word-methods-cache (list method))
1682         (if (and gnus-newsgroup-name
1683                  (string-match (car method) gnus-newsgroup-name))
1684             (nconc gnus-decode-encoded-word-methods-cache
1685                    (list (cdr method)))))))
1686   (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1687     (setq string (funcall method string))))
1688
1689 ;; Subject simplification.
1690
1691 (defun gnus-simplify-whitespace (str)
1692   "Remove excessive whitespace from STR."
1693   ;; Multiple spaces.
1694   (while (string-match "[ \t][ \t]+" str)
1695     (setq str (concat (substring str 0 (match-beginning 0))
1696                         " "
1697                         (substring str (match-end 0)))))
1698   ;; Leading spaces.
1699   (when (string-match "^[ \t]+" str)
1700     (setq str (substring str (match-end 0))))
1701   ;; Trailing spaces.
1702   (when (string-match "[ \t]+$" str)
1703     (setq str (substring str 0 (match-beginning 0))))
1704   str)
1705
1706 (defun gnus-simplify-all-whitespace (str)
1707   "Remove all whitespace from STR."
1708   (while (string-match "[ \t\n]+" str)
1709     (setq str (replace-match "" nil nil str)))
1710   str)
1711
1712 (defsubst gnus-simplify-subject-re (subject)
1713   "Remove \"Re:\" from subject lines."
1714   (if (string-match message-subject-re-regexp subject)
1715       (substring subject (match-end 0))
1716     subject))
1717
1718 (defun gnus-simplify-subject (subject &optional re-only)
1719   "Remove `Re:' and words in parentheses.
1720 If RE-ONLY is non-nil, strip leading `Re:'s only."
1721   (let ((case-fold-search t))           ;Ignore case.
1722     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1723     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1724       (setq subject (substring subject (match-end 0))))
1725     ;; Remove uninteresting prefixes.
1726     (when (and (not re-only)
1727                gnus-simplify-ignored-prefixes
1728                (string-match gnus-simplify-ignored-prefixes subject))
1729       (setq subject (substring subject (match-end 0))))
1730     ;; Remove words in parentheses from end.
1731     (unless re-only
1732       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1733         (setq subject (substring subject 0 (match-beginning 0)))))
1734     ;; Return subject string.
1735     subject))
1736
1737 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1738 ;; all whitespace.
1739 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1740   (goto-char (point-min))
1741   (while (re-search-forward regexp nil t)
1742     (replace-match (or newtext ""))))
1743
1744 (defun gnus-simplify-buffer-fuzzy (regexp)
1745   "Simplify string in the buffer fuzzily.
1746 The string in the accessible portion of the current buffer is simplified.
1747 It is assumed to be a single-line subject.
1748 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1749 matter is removed.  Additional things can be deleted by setting
1750 `gnus-simplify-subject-fuzzy-regexp'."
1751   (let ((case-fold-search t)
1752         (modified-tick))
1753     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1754
1755     (while (not (eq modified-tick (buffer-modified-tick)))
1756       (setq modified-tick (buffer-modified-tick))
1757       (cond
1758        ((listp regexp)
1759         (mapc 'gnus-simplify-buffer-fuzzy-step regexp))
1760        (regexp
1761         (gnus-simplify-buffer-fuzzy-step regexp)))
1762       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1763       (gnus-simplify-buffer-fuzzy-step
1764        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1765       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1766
1767     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1768     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1769     (gnus-simplify-buffer-fuzzy-step " $")
1770     (gnus-simplify-buffer-fuzzy-step "^ +")))
1771
1772 (defun gnus-simplify-subject-fuzzy (subject)
1773   "Simplify a subject string fuzzily.
1774 See `gnus-simplify-buffer-fuzzy' for details."
1775   (save-excursion
1776     (let ((regexp gnus-simplify-subject-fuzzy-regexp))
1777       (gnus-set-work-buffer)
1778       (let ((case-fold-search t))
1779         ;; Remove uninteresting prefixes.
1780         (when (and gnus-simplify-ignored-prefixes
1781                    (string-match gnus-simplify-ignored-prefixes subject))
1782           (setq subject (substring subject (match-end 0))))
1783         (insert subject)
1784         (inline (gnus-simplify-buffer-fuzzy regexp))
1785         (buffer-string)))))
1786
1787 (defsubst gnus-simplify-subject-fully (subject)
1788   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1789   (cond
1790    (gnus-simplify-subject-functions
1791     (gnus-map-function gnus-simplify-subject-functions subject))
1792    ((null gnus-summary-gather-subject-limit)
1793     (gnus-simplify-subject-re subject))
1794    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1795     (gnus-simplify-subject-fuzzy subject))
1796    ((numberp gnus-summary-gather-subject-limit)
1797     (truncate-string-to-width (gnus-simplify-subject-re subject)
1798                               gnus-summary-gather-subject-limit))
1799    (t
1800     subject)))
1801
1802 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1803   "Check whether two subjects are equal.
1804 If optional argument SIMPLE-FIRST is t, first argument is already
1805 simplified."
1806   (cond
1807    ((null simple-first)
1808     (equal (gnus-simplify-subject-fully s1)
1809            (gnus-simplify-subject-fully s2)))
1810    (t
1811     (equal s1
1812            (gnus-simplify-subject-fully s2)))))
1813
1814 (defun gnus-summary-bubble-group ()
1815   "Increase the score of the current group.
1816 This is a handy function to add to `gnus-summary-exit-hook' to
1817 increase the score of each group you read."
1818   (gnus-group-add-score gnus-newsgroup-name))
1819
1820 \f
1821 ;;;
1822 ;;; Gnus summary mode
1823 ;;;
1824
1825 (put 'gnus-summary-mode 'mode-class 'special)
1826
1827 (defvar gnus-article-commands-menu)
1828
1829 ;; Non-orthogonal keys
1830
1831 (gnus-define-keys gnus-summary-mode-map
1832   " " gnus-summary-next-page
1833   "\177" gnus-summary-prev-page
1834   [delete] gnus-summary-prev-page
1835   [backspace] gnus-summary-prev-page
1836   "\r" gnus-summary-scroll-up
1837   "\M-\r" gnus-summary-scroll-down
1838   "n" gnus-summary-next-unread-article
1839   "p" gnus-summary-prev-unread-article
1840   "N" gnus-summary-next-article
1841   "P" gnus-summary-prev-article
1842   "\M-\C-n" gnus-summary-next-same-subject
1843   "\M-\C-p" gnus-summary-prev-same-subject
1844   "\M-n" gnus-summary-next-unread-subject
1845   "\M-p" gnus-summary-prev-unread-subject
1846   "." gnus-summary-first-unread-article
1847   "," gnus-summary-best-unread-article
1848   "\M-s" gnus-summary-search-article-forward
1849   "\M-r" gnus-summary-search-article-backward
1850   "\M-S" gnus-summary-repeat-search-article-forward
1851   "\M-R" gnus-summary-repeat-search-article-backward
1852   "<" gnus-summary-beginning-of-article
1853   ">" gnus-summary-end-of-article
1854   "j" gnus-summary-goto-article
1855   "^" gnus-summary-refer-parent-article
1856   "\M-^" gnus-summary-refer-article
1857   "u" gnus-summary-tick-article-forward
1858   "!" gnus-summary-tick-article-forward
1859   "U" gnus-summary-tick-article-backward
1860   "d" gnus-summary-mark-as-read-forward
1861   "D" gnus-summary-mark-as-read-backward
1862   "E" gnus-summary-mark-as-expirable
1863   "\M-u" gnus-summary-clear-mark-forward
1864   "\M-U" gnus-summary-clear-mark-backward
1865   "k" gnus-summary-kill-same-subject-and-select
1866   "\C-k" gnus-summary-kill-same-subject
1867   "\M-\C-k" gnus-summary-kill-thread
1868   "\M-\C-l" gnus-summary-lower-thread
1869   "e" gnus-summary-edit-article
1870   "#" gnus-summary-mark-as-processable
1871   "\M-#" gnus-summary-unmark-as-processable
1872   "\M-\C-t" gnus-summary-toggle-threads
1873   "\M-\C-s" gnus-summary-show-thread
1874   "\M-\C-h" gnus-summary-hide-thread
1875   "\M-\C-f" gnus-summary-next-thread
1876   "\M-\C-b" gnus-summary-prev-thread
1877   [(meta down)] gnus-summary-next-thread
1878   [(meta up)] gnus-summary-prev-thread
1879   "\M-\C-u" gnus-summary-up-thread
1880   "\M-\C-d" gnus-summary-down-thread
1881   "&" gnus-summary-execute-command
1882   "c" gnus-summary-catchup-and-exit
1883   "\C-w" gnus-summary-mark-region-as-read
1884   "\C-t" gnus-summary-toggle-truncation
1885   "?" gnus-summary-mark-as-dormant
1886   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1887   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1888   "\C-c\C-s\C-m\C-n" gnus-summary-sort-by-most-recent-number
1889   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1890   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1891   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1892   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1893   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1894   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1895   "\C-c\C-s\C-m\C-d" gnus-summary-sort-by-most-recent-date
1896   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1897   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1898   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1899   "=" gnus-summary-expand-window
1900   "\C-x\C-s" gnus-summary-reselect-current-group
1901   "\M-g" gnus-summary-rescan-group
1902   "\C-c\C-r" gnus-summary-caesar-message
1903   "f" gnus-summary-followup
1904   "F" gnus-summary-followup-with-original
1905   "C" gnus-summary-cancel-article
1906   "r" gnus-summary-reply
1907   "R" gnus-summary-reply-with-original
1908   "\C-c\C-f" gnus-summary-mail-forward
1909   "o" gnus-summary-save-article
1910   "\C-o" gnus-summary-save-article-mail
1911   "|" gnus-summary-pipe-output
1912   "\M-k" gnus-summary-edit-local-kill
1913   "\M-K" gnus-summary-edit-global-kill
1914   ;; "V" gnus-version
1915   "\C-c\C-d" gnus-summary-describe-group
1916   "q" gnus-summary-exit
1917   "Q" gnus-summary-exit-no-update
1918   "\C-c\C-i" gnus-info-find-node
1919   gnus-mouse-2 gnus-mouse-pick-article
1920   [follow-link] mouse-face
1921   "m" gnus-summary-mail-other-window
1922   "a" gnus-summary-post-news
1923   "x" gnus-summary-limit-to-unread
1924   "s" gnus-summary-isearch-article
1925   [tab] gnus-summary-widget-forward
1926   "t" gnus-summary-toggle-header
1927   "g" gnus-summary-show-article
1928   "l" gnus-summary-goto-last-article
1929   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1930   "\C-d" gnus-summary-enter-digest-group
1931   "\M-\C-d" gnus-summary-read-document
1932   "\M-\C-e" gnus-summary-edit-parameters
1933   "\M-\C-a" gnus-summary-customize-parameters
1934   "\C-c\C-b" gnus-bug
1935   "*" gnus-cache-enter-article
1936   "\M-*" gnus-cache-remove-article
1937   "\M-&" gnus-summary-universal-argument
1938   "\C-l" gnus-recenter
1939   "I" gnus-summary-increase-score
1940   "L" gnus-summary-lower-score
1941   "\M-i" gnus-symbolic-argument
1942   "h" gnus-summary-select-article-buffer
1943
1944   "b" gnus-article-view-part
1945   "\M-t" gnus-summary-toggle-display-buttonized
1946
1947   "V" gnus-summary-score-map
1948   "X" gnus-uu-extract-map
1949   "S" gnus-summary-send-map)
1950
1951 ;; Sort of orthogonal keymap
1952 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1953   "t" gnus-summary-tick-article-forward
1954   "!" gnus-summary-tick-article-forward
1955   "d" gnus-summary-mark-as-read-forward
1956   "r" gnus-summary-mark-as-read-forward
1957   "c" gnus-summary-clear-mark-forward
1958   " " gnus-summary-clear-mark-forward
1959   "e" gnus-summary-mark-as-expirable
1960   "x" gnus-summary-mark-as-expirable
1961   "?" gnus-summary-mark-as-dormant
1962   "b" gnus-summary-set-bookmark
1963   "B" gnus-summary-remove-bookmark
1964   "#" gnus-summary-mark-as-processable
1965   "\M-#" gnus-summary-unmark-as-processable
1966   "S" gnus-summary-limit-include-expunged
1967   "C" gnus-summary-catchup
1968   "H" gnus-summary-catchup-to-here
1969   "h" gnus-summary-catchup-from-here
1970   "\C-c" gnus-summary-catchup-all
1971   "k" gnus-summary-kill-same-subject-and-select
1972   "K" gnus-summary-kill-same-subject
1973   "P" gnus-uu-mark-map)
1974
1975 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1976   "c" gnus-summary-clear-above
1977   "u" gnus-summary-tick-above
1978   "m" gnus-summary-mark-above
1979   "k" gnus-summary-kill-below)
1980
1981 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1982   "/" gnus-summary-limit-to-subject
1983   "n" gnus-summary-limit-to-articles
1984   "b" gnus-summary-limit-to-bodies
1985   "h" gnus-summary-limit-to-headers
1986   "w" gnus-summary-pop-limit
1987   "s" gnus-summary-limit-to-subject
1988   "a" gnus-summary-limit-to-author
1989   "u" gnus-summary-limit-to-unread
1990   "m" gnus-summary-limit-to-marks
1991   "M" gnus-summary-limit-exclude-marks
1992   "v" gnus-summary-limit-to-score
1993   "*" gnus-summary-limit-include-cached
1994   "D" gnus-summary-limit-include-dormant
1995   "T" gnus-summary-limit-include-thread
1996   "d" gnus-summary-limit-exclude-dormant
1997   "t" gnus-summary-limit-to-age
1998   "." gnus-summary-limit-to-unseen
1999   "x" gnus-summary-limit-to-extra
2000   "p" gnus-summary-limit-to-display-predicate
2001   "E" gnus-summary-limit-include-expunged
2002   "c" gnus-summary-limit-exclude-childless-dormant
2003   "C" gnus-summary-limit-mark-excluded-as-read
2004   "o" gnus-summary-insert-old-articles
2005   "N" gnus-summary-insert-new-articles
2006   "S" gnus-summary-limit-to-singletons
2007   "r" gnus-summary-limit-to-replied
2008   "R" gnus-summary-limit-to-recipient
2009   "A" gnus-summary-limit-to-address)
2010
2011 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
2012   "n" gnus-summary-next-unread-article
2013   "p" gnus-summary-prev-unread-article
2014   "N" gnus-summary-next-article
2015   "P" gnus-summary-prev-article
2016   "\C-n" gnus-summary-next-same-subject
2017   "\C-p" gnus-summary-prev-same-subject
2018   "\M-n" gnus-summary-next-unread-subject
2019   "\M-p" gnus-summary-prev-unread-subject
2020   "f" gnus-summary-first-unread-article
2021   "b" gnus-summary-best-unread-article
2022   "j" gnus-summary-goto-article
2023   "g" gnus-summary-goto-subject
2024   "l" gnus-summary-goto-last-article
2025   "o" gnus-summary-pop-article)
2026
2027 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
2028   "k" gnus-summary-kill-thread
2029   "E" gnus-summary-expire-thread
2030   "l" gnus-summary-lower-thread
2031   "i" gnus-summary-raise-thread
2032   "T" gnus-summary-toggle-threads
2033   "t" gnus-summary-rethread-current
2034   "^" gnus-summary-reparent-thread
2035   "\M-^" gnus-summary-reparent-children
2036   "s" gnus-summary-show-thread
2037   "S" gnus-summary-show-all-threads
2038   "h" gnus-summary-hide-thread
2039   "H" gnus-summary-hide-all-threads
2040   "n" gnus-summary-next-thread
2041   "p" gnus-summary-prev-thread
2042   "u" gnus-summary-up-thread
2043   "o" gnus-summary-top-thread
2044   "d" gnus-summary-down-thread
2045   "#" gnus-uu-mark-thread
2046   "\M-#" gnus-uu-unmark-thread)
2047
2048 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
2049   "g" gnus-summary-prepare
2050   "c" gnus-summary-insert-cached-articles
2051   "d" gnus-summary-insert-dormant-articles
2052   "t" gnus-summary-insert-ticked-articles)
2053
2054 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
2055   "c" gnus-summary-catchup-and-exit
2056   "C" gnus-summary-catchup-all-and-exit
2057   "E" gnus-summary-exit-no-update
2058   "Q" gnus-summary-exit
2059   "Z" gnus-summary-exit
2060   "n" gnus-summary-catchup-and-goto-next-group
2061   "p" gnus-summary-catchup-and-goto-prev-group
2062   "R" gnus-summary-reselect-current-group
2063   "G" gnus-summary-rescan-group
2064   "N" gnus-summary-next-group
2065   "s" gnus-summary-save-newsrc
2066   "P" gnus-summary-prev-group)
2067
2068 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
2069   " " gnus-summary-next-page
2070   "n" gnus-summary-next-page
2071   "\177" gnus-summary-prev-page
2072   [delete] gnus-summary-prev-page
2073   "p" gnus-summary-prev-page
2074   "\r" gnus-summary-scroll-up
2075   "\M-\r" gnus-summary-scroll-down
2076   "<" gnus-summary-beginning-of-article
2077   ">" gnus-summary-end-of-article
2078   "b" gnus-summary-beginning-of-article
2079   "e" gnus-summary-end-of-article
2080   "^" gnus-summary-refer-parent-article
2081   "r" gnus-summary-refer-parent-article
2082   "C" gnus-summary-show-complete-article
2083   "D" gnus-summary-enter-digest-group
2084   "R" gnus-summary-refer-references
2085   "T" gnus-summary-refer-thread
2086   "W" gnus-warp-to-article
2087   "g" gnus-summary-show-article
2088   "s" gnus-summary-isearch-article
2089   [tab] gnus-summary-widget-forward
2090   "P" gnus-summary-print-article
2091   "S" gnus-sticky-article
2092   "M" gnus-mailing-list-insinuate
2093   "t" gnus-article-babel)
2094
2095 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2096   "b" gnus-article-add-buttons
2097   "B" gnus-article-add-buttons-to-head
2098   "o" gnus-article-treat-overstrike
2099   "e" gnus-article-emphasize
2100   "w" gnus-article-fill-cited-article
2101   "Q" gnus-article-fill-long-lines
2102   "L" gnus-article-toggle-truncate-lines
2103   "C" gnus-article-capitalize-sentences
2104   "c" gnus-article-remove-cr
2105   "q" gnus-article-de-quoted-unreadable
2106   "6" gnus-article-de-base64-unreadable
2107   "Z" gnus-article-decode-HZ
2108   "A" gnus-article-treat-ansi-sequences
2109   "h" gnus-article-wash-html
2110   "u" gnus-article-unsplit-urls
2111   "s" gnus-summary-force-verify-and-decrypt
2112   "f" gnus-article-display-x-face
2113   "l" gnus-summary-stop-page-breaking
2114   "r" gnus-summary-caesar-message
2115   "m" gnus-summary-morse-message
2116   "t" gnus-summary-toggle-header
2117   "g" gnus-treat-smiley
2118   "v" gnus-summary-verbose-headers
2119   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2120   "p" gnus-article-verify-x-pgp-sig
2121   "d" gnus-article-treat-dumbquotes
2122   "U" gnus-article-treat-non-ascii
2123   "i" gnus-summary-idna-message)
2124
2125 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2126   ;; mnemonic: deuglif*Y*
2127   "u" gnus-article-outlook-unwrap-lines
2128   "a" gnus-article-outlook-repair-attribution
2129   "c" gnus-article-outlook-rearrange-citation
2130   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2131
2132 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2133   "a" gnus-article-hide
2134   "h" gnus-article-hide-headers
2135   "b" gnus-article-hide-boring-headers
2136   "s" gnus-article-hide-signature
2137   "c" gnus-article-hide-citation
2138   "C" gnus-article-hide-citation-in-followups
2139   "l" gnus-article-hide-list-identifiers
2140   "B" gnus-article-strip-banner
2141   "P" gnus-article-hide-pem
2142   "\C-c" gnus-article-hide-citation-maybe)
2143
2144 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2145   "a" gnus-article-highlight
2146   "h" gnus-article-highlight-headers
2147   "c" gnus-article-highlight-citation
2148   "s" gnus-article-highlight-signature)
2149
2150 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2151   "f" gnus-article-treat-fold-headers
2152   "u" gnus-article-treat-unfold-headers
2153   "n" gnus-article-treat-fold-newsgroups)
2154
2155 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2156   "x" gnus-article-display-x-face
2157   "d" gnus-article-display-face
2158   "s" gnus-treat-smiley
2159   "D" gnus-article-remove-images
2160   "W" gnus-article-show-images
2161   "f" gnus-treat-from-picon
2162   "m" gnus-treat-mail-picon
2163   "n" gnus-treat-newsgroups-picon
2164   "g" gnus-treat-from-gravatar
2165   "h" gnus-treat-mail-gravatar)
2166
2167 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2168   "w" gnus-article-decode-mime-words
2169   "c" gnus-article-decode-charset
2170   "v" gnus-mime-view-all-parts
2171   "b" gnus-article-view-part)
2172
2173 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2174   "z" gnus-article-date-ut
2175   "u" gnus-article-date-ut
2176   "l" gnus-article-date-local
2177   "p" gnus-article-date-english
2178   "e" gnus-article-date-lapsed
2179   "o" gnus-article-date-original
2180   "i" gnus-article-date-iso8601
2181   "s" gnus-article-date-user)
2182
2183 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2184   "t" gnus-article-remove-trailing-blank-lines
2185   "l" gnus-article-strip-leading-blank-lines
2186   "m" gnus-article-strip-multiple-blank-lines
2187   "a" gnus-article-strip-blank-lines
2188   "A" gnus-article-strip-all-blank-lines
2189   "s" gnus-article-strip-leading-space
2190   "e" gnus-article-strip-trailing-space
2191   "w" gnus-article-remove-leading-whitespace)
2192
2193 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2194   "v" gnus-version
2195   "d" gnus-summary-describe-group
2196   "h" gnus-summary-describe-briefly
2197   "i" gnus-info-find-node)
2198
2199 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2200   "e" gnus-summary-expire-articles
2201   "\M-\C-e" gnus-summary-expire-articles-now
2202   "\177" gnus-summary-delete-article
2203   [delete] gnus-summary-delete-article
2204   [backspace] gnus-summary-delete-article
2205   "m" gnus-summary-move-article
2206   "r" gnus-summary-respool-article
2207   "w" gnus-summary-edit-article
2208   "c" gnus-summary-copy-article
2209   "B" gnus-summary-crosspost-article
2210   "q" gnus-summary-respool-query
2211   "t" gnus-summary-respool-trace
2212   "i" gnus-summary-import-article
2213   "I" gnus-summary-create-article
2214   "p" gnus-summary-article-posted-p)
2215
2216 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2217   "o" gnus-summary-save-article
2218   "m" gnus-summary-save-article-mail
2219   "F" gnus-summary-write-article-file
2220   "r" gnus-summary-save-article-rmail
2221   "f" gnus-summary-save-article-file
2222   "b" gnus-summary-save-article-body-file
2223   "B" gnus-summary-write-article-body-file
2224   "h" gnus-summary-save-article-folder
2225   "v" gnus-summary-save-article-vm
2226   "p" gnus-summary-pipe-output
2227   "P" gnus-summary-muttprint)
2228
2229 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2230   "b" gnus-summary-display-buttonized
2231   "m" gnus-summary-repair-multipart
2232   "v" gnus-article-view-part
2233   "o" gnus-article-save-part
2234   "O" gnus-article-save-part-and-strip
2235   "r" gnus-article-replace-part
2236   "d" gnus-article-delete-part
2237   "t" gnus-article-view-part-as-type
2238   "j" gnus-article-jump-to-part
2239   "c" gnus-article-copy-part
2240   "C" gnus-article-view-part-as-charset
2241   "e" gnus-article-view-part-externally
2242   "H" gnus-article-browse-html-article
2243   "E" gnus-article-encrypt-body
2244   "i" gnus-article-inline-part
2245   "|" gnus-article-pipe-part)
2246
2247 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2248   "p" gnus-summary-mark-as-processable
2249   "u" gnus-summary-unmark-as-processable
2250   "U" gnus-summary-unmark-all-processable
2251   "v" gnus-uu-mark-over
2252   "s" gnus-uu-mark-series
2253   "r" gnus-uu-mark-region
2254   "g" gnus-uu-unmark-region
2255   "R" gnus-uu-mark-by-regexp
2256   "G" gnus-uu-unmark-by-regexp
2257   "t" gnus-uu-mark-thread
2258   "T" gnus-uu-unmark-thread
2259   "a" gnus-uu-mark-all
2260   "b" gnus-uu-mark-buffer
2261   "S" gnus-uu-mark-sparse
2262   "k" gnus-summary-kill-process-mark
2263   "y" gnus-summary-yank-process-mark
2264   "w" gnus-summary-save-process-mark
2265   "i" gnus-uu-invert-processable)
2266
2267 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2268   ;;"x" gnus-uu-extract-any
2269   "m" gnus-summary-save-parts
2270   "u" gnus-uu-decode-uu
2271   "U" gnus-uu-decode-uu-and-save
2272   "s" gnus-uu-decode-unshar
2273   "S" gnus-uu-decode-unshar-and-save
2274   "o" gnus-uu-decode-save
2275   "O" gnus-uu-decode-save
2276   "b" gnus-uu-decode-binhex
2277   "B" gnus-uu-decode-binhex
2278   "Y" gnus-uu-decode-yenc
2279   "p" gnus-uu-decode-postscript
2280   "P" gnus-uu-decode-postscript-and-save)
2281
2282 (gnus-define-keys
2283     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2284   "u" gnus-uu-decode-uu-view
2285   "U" gnus-uu-decode-uu-and-save-view
2286   "s" gnus-uu-decode-unshar-view
2287   "S" gnus-uu-decode-unshar-and-save-view
2288   "o" gnus-uu-decode-save-view
2289   "O" gnus-uu-decode-save-view
2290   "b" gnus-uu-decode-binhex-view
2291   "B" gnus-uu-decode-binhex-view
2292   "p" gnus-uu-decode-postscript-view
2293   "P" gnus-uu-decode-postscript-and-save-view)
2294
2295 (defvar gnus-article-post-menu nil)
2296
2297 (defconst gnus-summary-menu-maxlen 20)
2298
2299 (defun gnus-summary-menu-split (menu)
2300   ;; If we have lots of elements, divide them into groups of 20
2301   ;; and make a pane (or submenu) for each one.
2302   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2303       (let ((menu menu) sublists next
2304             (i 1))
2305         (while menu
2306           ;; Pull off the next gnus-summary-menu-maxlen elements
2307           ;; and make them the next element of sublist.
2308           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2309           (if next
2310               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2311                       nil))
2312           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2313                                              (aref (car (last menu)) 0)) menu)
2314                                sublists))
2315           (setq i (1+ i))
2316           (setq menu next))
2317         (nreverse sublists))
2318     ;; Few elements--put them all in one pane.
2319     menu))
2320
2321 (defun gnus-summary-make-menu-bar ()
2322   (gnus-turn-off-edit-menu 'summary)
2323
2324   (unless (boundp 'gnus-summary-misc-menu)
2325
2326     (easy-menu-define
2327       gnus-summary-kill-menu gnus-summary-mode-map ""
2328       (cons
2329        "Score"
2330        (nconc
2331         (list
2332          ["Customize" gnus-score-customize t])
2333         (gnus-make-score-map 'increase)
2334         (gnus-make-score-map 'lower)
2335         '(("Mark"
2336            ["Kill below" gnus-summary-kill-below t]
2337            ["Mark above" gnus-summary-mark-above t]
2338            ["Tick above" gnus-summary-tick-above t]
2339            ["Clear above" gnus-summary-clear-above t])
2340           ["Current score" gnus-summary-current-score t]
2341           ["Set score" gnus-summary-set-score t]
2342           ["Switch current score file..." gnus-score-change-score-file t]
2343           ["Set mark below..." gnus-score-set-mark-below t]
2344           ["Set expunge below..." gnus-score-set-expunge-below t]
2345           ["Edit current score file" gnus-score-edit-current-scores t]
2346           ["Edit score file..." gnus-score-edit-file t]
2347           ["Trace score" gnus-score-find-trace t]
2348           ["Find words" gnus-score-find-favourite-words t]
2349           ["Rescore buffer" gnus-summary-rescore t]
2350           ["Increase score..." gnus-summary-increase-score t]
2351           ["Lower score..." gnus-summary-lower-score t]))))
2352
2353     ;; Define both the Article menu in the summary buffer and the
2354     ;; equivalent Commands menu in the article buffer here for
2355     ;; consistency.
2356     (let ((innards
2357            `(("Hide"
2358               ["All" gnus-article-hide t]
2359               ["Headers" gnus-article-hide-headers t]
2360               ["Signature" gnus-article-hide-signature t]
2361               ["Citation" gnus-article-hide-citation t]
2362               ["List identifiers" gnus-article-hide-list-identifiers t]
2363               ["Banner" gnus-article-strip-banner t]
2364               ["Boring headers" gnus-article-hide-boring-headers t])
2365              ("Highlight"
2366               ["All" gnus-article-highlight t]
2367               ["Headers" gnus-article-highlight-headers t]
2368               ["Signature" gnus-article-highlight-signature t]
2369               ["Citation" gnus-article-highlight-citation t])
2370              ("MIME"
2371               ["Words" gnus-article-decode-mime-words t]
2372               ["Charset" gnus-article-decode-charset t]
2373               ["QP" gnus-article-de-quoted-unreadable t]
2374               ["Base64" gnus-article-de-base64-unreadable t]
2375               ["View MIME buttons" gnus-summary-display-buttonized t]
2376               ["View all" gnus-mime-view-all-parts t]
2377               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2378               ["Encrypt body" gnus-article-encrypt-body
2379                :active (not (gnus-group-read-only-p))
2380                ,@(if (featurep 'xemacs) nil
2381                    '(:help "Encrypt the message body on disk"))]
2382               ["Extract all parts..." gnus-summary-save-parts t]
2383               ("Multipart"
2384                ["Repair multipart" gnus-summary-repair-multipart t]
2385                ["Pipe part..." gnus-article-pipe-part t]
2386                ["Inline part" gnus-article-inline-part t]
2387                ["View part as type..." gnus-article-view-part-as-type t]
2388                ["Encrypt body" gnus-article-encrypt-body
2389                 :active (not (gnus-group-read-only-p))
2390                ,@(if (featurep 'xemacs) nil
2391                    '(:help "Encrypt the message body on disk"))]
2392                ["View part externally" gnus-article-view-part-externally t]
2393                ["View HTML parts in browser" gnus-article-browse-html-article t]
2394                ["View part with charset..." gnus-article-view-part-as-charset t]
2395                ["Copy part" gnus-article-copy-part t]
2396                ["Save part..." gnus-article-save-part t]
2397                ["View part" gnus-article-view-part t]))
2398              ("Date"
2399               ["Local" gnus-article-date-local t]
2400               ["ISO8601" gnus-article-date-iso8601 t]
2401               ["UT" gnus-article-date-ut t]
2402               ["Original" gnus-article-date-original t]
2403               ["Lapsed" gnus-article-date-lapsed t]
2404               ["User-defined" gnus-article-date-user t])
2405              ("Display"
2406               ["Remove images" gnus-article-remove-images t]
2407               ["Toggle smiley" gnus-treat-smiley t]
2408               ["Show X-Face" gnus-article-display-x-face t]
2409               ["Show picons in From" gnus-treat-from-picon t]
2410               ["Show picons in mail headers" gnus-treat-mail-picon t]
2411               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2412               ["Show Gravatars in From" gnus-treat-from-gravatar t]
2413               ["Show Gravatars in mail headers" gnus-treat-mail-gravatar t]
2414               ("View as different encoding"
2415                ,@(gnus-summary-menu-split
2416                   (mapcar
2417                    (lambda (cs)
2418                      ;; Since easymenu under Emacs doesn't allow
2419                      ;; lambda forms for menu commands, we should
2420                      ;; provide intern'ed function symbols.
2421                      (let ((command (intern (format "\
2422 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2423                        (fset command
2424                              `(lambda ()
2425                                 (interactive)
2426                                 (let ((gnus-summary-show-article-charset-alist
2427                                        '((1 . ,cs))))
2428                                   (gnus-summary-show-article 1))))
2429                        `[,(symbol-name cs) ,command t]))
2430                    (sort (if (fboundp 'coding-system-list)
2431                              (coding-system-list)
2432                            (mapcar 'car mm-mime-mule-charset-alist))
2433                          'string<)))))
2434              ("Washing"
2435               ("Remove Blanks"
2436                ["Leading" gnus-article-strip-leading-blank-lines t]
2437                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2438                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2439                ["All of the above" gnus-article-strip-blank-lines t]
2440                ["All" gnus-article-strip-all-blank-lines t]
2441                ["Leading space" gnus-article-strip-leading-space t]
2442                ["Trailing space" gnus-article-strip-trailing-space t]
2443                ["Leading space in headers"
2444                 gnus-article-remove-leading-whitespace t])
2445               ["Overstrike" gnus-article-treat-overstrike t]
2446               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2447               ["Non-ASCII" gnus-article-treat-non-ascii t]
2448               ["Emphasis" gnus-article-emphasize t]
2449               ["Word wrap" gnus-article-fill-cited-article t]
2450               ["Fill long lines" gnus-article-fill-long-lines t]
2451               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2452               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2453               ["Remove CR" gnus-article-remove-cr t]
2454               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2455               ["Base64" gnus-article-de-base64-unreadable t]
2456               ["Rot 13" gnus-summary-caesar-message
2457                ,@(if (featurep 'xemacs) '(t)
2458                    '(:help "\"Caesar rotate\" article by 13"))]
2459               ["De-IDNA" gnus-summary-idna-message t]
2460               ["Morse decode" gnus-summary-morse-message t]
2461               ["Unix pipe..." gnus-summary-pipe-message t]
2462               ["Add buttons" gnus-article-add-buttons t]
2463               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2464               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2465               ["Verbose header" gnus-summary-verbose-headers t]
2466               ["Toggle header" gnus-summary-toggle-header t]
2467               ["Unfold headers" gnus-article-treat-unfold-headers t]
2468               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2469               ["Html" gnus-article-wash-html t]
2470               ["Unsplit URLs" gnus-article-unsplit-urls t]
2471               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2472               ["Decode HZ" gnus-article-decode-HZ t]
2473               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2474               ("(Outlook) Deuglify"
2475                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2476                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2477                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2478                ["Full (Outlook) deuglify"
2479                 gnus-article-outlook-deuglify-article t])
2480               )
2481              ("Output"
2482               ["Save in default format..." gnus-summary-save-article
2483                ,@(if (featurep 'xemacs) '(t)
2484                    '(:help "Save article using default method"))]
2485               ["Save in file..." gnus-summary-save-article-file
2486                ,@(if (featurep 'xemacs) '(t)
2487                    '(:help "Save article in file"))]
2488               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2489               ["Save in MH folder..." gnus-summary-save-article-folder t]
2490               ["Save in VM folder..." gnus-summary-save-article-vm t]
2491               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2492               ["Save body in file..." gnus-summary-save-article-body-file t]
2493               ["Pipe through a filter..." gnus-summary-pipe-output t]
2494               ["Print with Muttprint..." gnus-summary-muttprint t]
2495               ["Print" gnus-summary-print-article
2496                ,@(if (featurep 'xemacs) '(t)
2497                    '(:help "Generate and print a PostScript image"))])
2498              ("Copy, move,... (Backend)"
2499               ,@(if (featurep 'xemacs) nil
2500                   '(:help "Copying, moving, expiring articles..."))
2501               ["Respool article..." gnus-summary-respool-article t]
2502               ["Move article..." gnus-summary-move-article
2503                (gnus-check-backend-function
2504                 'request-move-article gnus-newsgroup-name)]
2505               ["Copy article..." gnus-summary-copy-article t]
2506               ["Crosspost article..." gnus-summary-crosspost-article
2507                (gnus-check-backend-function
2508                 'request-replace-article gnus-newsgroup-name)]
2509               ["Import file..." gnus-summary-import-article
2510                (gnus-check-backend-function
2511                 'request-accept-article gnus-newsgroup-name)]
2512               ["Create article..." gnus-summary-create-article
2513                (gnus-check-backend-function
2514                 'request-accept-article gnus-newsgroup-name)]
2515               ["Check if posted" gnus-summary-article-posted-p t]
2516               ["Edit article" gnus-summary-edit-article
2517                (not (gnus-group-read-only-p))]
2518               ["Delete article" gnus-summary-delete-article
2519                (gnus-check-backend-function
2520                 'request-expire-articles gnus-newsgroup-name)]
2521               ["Query respool" gnus-summary-respool-query t]
2522               ["Trace respool" gnus-summary-respool-trace t]
2523               ["Delete expirable articles" gnus-summary-expire-articles-now
2524                (gnus-check-backend-function
2525                 'request-expire-articles gnus-newsgroup-name)])
2526              ("Extract"
2527               ["Uudecode" gnus-uu-decode-uu
2528                ,@(if (featurep 'xemacs) '(t)
2529                    '(:help "Decode uuencoded article(s)"))]
2530               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2531               ["Unshar" gnus-uu-decode-unshar t]
2532               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2533               ["Save" gnus-uu-decode-save t]
2534               ["Binhex" gnus-uu-decode-binhex t]
2535               ["Postscript" gnus-uu-decode-postscript t]
2536               ["All MIME parts" gnus-summary-save-parts t])
2537              ("Cache"
2538               ["Enter article" gnus-cache-enter-article t]
2539               ["Remove article" gnus-cache-remove-article t])
2540              ["Translate" gnus-article-babel t]
2541              ["Select article buffer" gnus-summary-select-article-buffer t]
2542              ["Make article buffer sticky" gnus-sticky-article t]
2543              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2544              ["Isearch article..." gnus-summary-isearch-article t]
2545              ["Beginning of the article" gnus-summary-beginning-of-article t]
2546              ["End of the article" gnus-summary-end-of-article t]
2547              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2548              ["Fetch referenced articles" gnus-summary-refer-references t]
2549              ["Fetch current thread" gnus-summary-refer-thread t]
2550              ["Fetch article with id..." gnus-summary-refer-article t]
2551              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2552              ["Redisplay" gnus-summary-show-article t]
2553              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2554       (easy-menu-define
2555         gnus-summary-article-menu gnus-summary-mode-map ""
2556         (cons "Article" innards))
2557
2558       (if (not (keymapp gnus-summary-article-menu))
2559           (easy-menu-define
2560             gnus-article-commands-menu gnus-article-mode-map ""
2561             (cons "Commands" innards))
2562         ;; in Emacs, don't share menu.
2563         (setq gnus-article-commands-menu
2564               (copy-keymap gnus-summary-article-menu))
2565         (define-key gnus-article-mode-map [menu-bar commands]
2566           (cons "Commands" gnus-article-commands-menu))))
2567
2568     (easy-menu-define
2569       gnus-summary-thread-menu gnus-summary-mode-map ""
2570       '("Threads"
2571         ["Find all messages in thread" gnus-summary-refer-thread t]
2572         ["Toggle threading" gnus-summary-toggle-threads t]
2573         ["Hide threads" gnus-summary-hide-all-threads t]
2574         ["Show threads" gnus-summary-show-all-threads t]
2575         ["Hide thread" gnus-summary-hide-thread t]
2576         ["Show thread" gnus-summary-show-thread t]
2577         ["Go to next thread" gnus-summary-next-thread t]
2578         ["Go to previous thread" gnus-summary-prev-thread t]
2579         ["Go down thread" gnus-summary-down-thread t]
2580         ["Go up thread" gnus-summary-up-thread t]
2581         ["Top of thread" gnus-summary-top-thread t]
2582         ["Mark thread as read" gnus-summary-kill-thread t]
2583         ["Mark thread as expired" gnus-summary-expire-thread t]
2584         ["Lower thread score" gnus-summary-lower-thread t]
2585         ["Raise thread score" gnus-summary-raise-thread t]
2586         ["Rethread current" gnus-summary-rethread-current t]))
2587
2588     (easy-menu-define
2589       gnus-summary-post-menu gnus-summary-mode-map ""
2590       `("Post"
2591         ["Send a message (mail or news)" gnus-summary-post-news
2592          ,@(if (featurep 'xemacs) '(t)
2593              '(:help "Compose a new message (mail or news)"))]
2594         ["Followup" gnus-summary-followup
2595          ,@(if (featurep 'xemacs) '(t)
2596              '(:help "Post followup to this article"))]
2597         ["Followup and yank" gnus-summary-followup-with-original
2598          ,@(if (featurep 'xemacs) '(t)
2599              '(:help "Post followup to this article, quoting its contents"))]
2600         ["Supersede article" gnus-summary-supersede-article t]
2601         ["Cancel article" gnus-summary-cancel-article
2602          ,@(if (featurep 'xemacs) '(t)
2603              '(:help "Cancel an article you posted"))]
2604         ["Reply" gnus-summary-reply t]
2605         ["Reply and yank" gnus-summary-reply-with-original t]
2606         ["Wide reply" gnus-summary-wide-reply t]
2607         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2608          ,@(if (featurep 'xemacs) '(t)
2609              '(:help "Mail a reply, quoting this article"))]
2610         ["Very wide reply" gnus-summary-very-wide-reply t]
2611         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2612          ,@(if (featurep 'xemacs) '(t)
2613              '(:help "Mail a very wide reply, quoting this article"))]
2614         ["Mail forward" gnus-summary-mail-forward t]
2615         ["Post forward" gnus-summary-post-forward t]
2616         ["Digest and mail" gnus-uu-digest-mail-forward t]
2617         ["Digest and post" gnus-uu-digest-post-forward t]
2618         ["Resend message" gnus-summary-resend-message t]
2619         ["Resend message edit" gnus-summary-resend-message-edit t]
2620         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2621         ["Send a mail" gnus-summary-mail-other-window t]
2622         ["Create a local message" gnus-summary-news-other-window t]
2623         ["Uuencode and post" gnus-uu-post-news
2624          ,@(if (featurep 'xemacs) '(t)
2625              '(:help "Post a uuencoded article"))]
2626         ["Followup via news" gnus-summary-followup-to-mail t]
2627         ["Followup via news and yank"
2628          gnus-summary-followup-to-mail-with-original t]
2629         ["Strip signature on reply"
2630          (lambda ()
2631            (interactive)
2632            (if (not (memq message-cite-function
2633                           '(message-cite-original-without-signature
2634                             message-cite-original)))
2635                ;; Stupid workaround for XEmacs not honoring :visible.
2636                (message "Can't toggle this value of `message-cite-function'")
2637              (setq message-cite-function
2638                    (if (eq message-cite-function
2639                            'message-cite-original-without-signature)
2640                        'message-cite-original
2641                      'message-cite-original-without-signature))))
2642          ;; XEmacs barfs on :visible.
2643          ,@(if (featurep 'xemacs) nil
2644              '(:visible (memq message-cite-function
2645                               '(message-cite-original-without-signature
2646                                 message-cite-original))))
2647          :style toggle
2648          :selected (eq message-cite-function
2649                        'message-cite-original-without-signature)
2650          ,@(if (featurep 'xemacs) nil
2651              '(:help "Strip signature from cited article when replying."))]
2652         ;;("Draft"
2653         ;;["Send" gnus-summary-send-draft t]
2654         ;;["Send bounced" gnus-resend-bounced-mail t])
2655         ))
2656
2657     (cond
2658      ((not (keymapp gnus-summary-post-menu))
2659       (setq gnus-article-post-menu gnus-summary-post-menu))
2660      ((not gnus-article-post-menu)
2661       ;; Don't share post menu.
2662       (setq gnus-article-post-menu
2663             (copy-keymap gnus-summary-post-menu))))
2664     (define-key gnus-article-mode-map [menu-bar post]
2665       (cons "Post" gnus-article-post-menu))
2666
2667     (easy-menu-define
2668       gnus-summary-misc-menu gnus-summary-mode-map ""
2669       `("Gnus"
2670         ("Mark Read"
2671          ["Mark as read" gnus-summary-mark-as-read-forward t]
2672          ["Mark same subject and select"
2673           gnus-summary-kill-same-subject-and-select t]
2674          ["Mark same subject" gnus-summary-kill-same-subject t]
2675          ["Catchup" gnus-summary-catchup
2676           ,@(if (featurep 'xemacs) '(t)
2677               '(:help "Mark unread articles in this group as read"))]
2678          ["Catchup all" gnus-summary-catchup-all t]
2679          ["Catchup to here" gnus-summary-catchup-to-here t]
2680          ["Catchup from here" gnus-summary-catchup-from-here t]
2681          ["Catchup region" gnus-summary-mark-region-as-read
2682           (gnus-mark-active-p)]
2683          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2684         ("Mark Various"
2685          ["Tick" gnus-summary-tick-article-forward t]
2686          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2687          ["Remove marks" gnus-summary-clear-mark-forward t]
2688          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2689          ["Set bookmark" gnus-summary-set-bookmark t]
2690          ["Remove bookmark" gnus-summary-remove-bookmark t])
2691         ("Limit to"
2692          ["Marks..." gnus-summary-limit-to-marks t]
2693          ["Subject..." gnus-summary-limit-to-subject t]
2694          ["Author..." gnus-summary-limit-to-author t]
2695          ["Recipient..." gnus-summary-limit-to-recipient t]
2696          ["Address..." gnus-summary-limit-to-address t]
2697          ["Age..." gnus-summary-limit-to-age t]
2698          ["Extra..." gnus-summary-limit-to-extra t]
2699          ["Score..." gnus-summary-limit-to-score t]
2700          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2701          ["Unread" gnus-summary-limit-to-unread t]
2702          ["Unseen" gnus-summary-limit-to-unseen t]
2703          ["Singletons" gnus-summary-limit-to-singletons t]
2704          ["Replied" gnus-summary-limit-to-replied t]
2705          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2706          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2707          ["Pop limit" gnus-summary-pop-limit t]
2708          ["Show dormant" gnus-summary-limit-include-dormant t]
2709          ["Hide childless dormant"
2710           gnus-summary-limit-exclude-childless-dormant t]
2711          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2712          ["Hide marked" gnus-summary-limit-exclude-marks t]
2713          ["Show expunged" gnus-summary-limit-include-expunged t])
2714         ("Process Mark"
2715          ["Set mark" gnus-summary-mark-as-processable t]
2716          ["Remove mark" gnus-summary-unmark-as-processable t]
2717          ["Remove all marks" gnus-summary-unmark-all-processable t]
2718          ["Invert marks" gnus-uu-invert-processable t]
2719          ["Mark above" gnus-uu-mark-over t]
2720          ["Mark series" gnus-uu-mark-series t]
2721          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2722          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2723          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2724          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2725          ["Mark all" gnus-uu-mark-all t]
2726          ["Mark buffer" gnus-uu-mark-buffer t]
2727          ["Mark sparse" gnus-uu-mark-sparse t]
2728          ["Mark thread" gnus-uu-mark-thread t]
2729          ["Unmark thread" gnus-uu-unmark-thread t]
2730          ("Process Mark Sets"
2731           ["Kill" gnus-summary-kill-process-mark t]
2732           ["Yank" gnus-summary-yank-process-mark
2733            gnus-newsgroup-process-stack]
2734           ["Save" gnus-summary-save-process-mark t]
2735           ["Run command on marked..." gnus-summary-universal-argument t]))
2736         ("Registry Marks")
2737         ("Scroll article"
2738          ["Page forward" gnus-summary-next-page
2739           ,@(if (featurep 'xemacs) '(t)
2740               '(:help "Show next page of article"))]
2741          ["Page backward" gnus-summary-prev-page
2742           ,@(if (featurep 'xemacs) '(t)
2743               '(:help "Show previous page of article"))]
2744          ["Line forward" gnus-summary-scroll-up t])
2745         ("Move"
2746          ["Next unread article" gnus-summary-next-unread-article t]
2747          ["Previous unread article" gnus-summary-prev-unread-article t]
2748          ["Next article" gnus-summary-next-article t]
2749          ["Previous article" gnus-summary-prev-article t]
2750          ["Next unread subject" gnus-summary-next-unread-subject t]
2751          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2752          ["Next article same subject" gnus-summary-next-same-subject t]
2753          ["Previous article same subject" gnus-summary-prev-same-subject t]
2754          ["First unread article" gnus-summary-first-unread-article t]
2755          ["Best unread article" gnus-summary-best-unread-article t]
2756          ["Go to subject number..." gnus-summary-goto-subject t]
2757          ["Go to article number..." gnus-summary-goto-article t]
2758          ["Go to the last article" gnus-summary-goto-last-article t]
2759          ["Pop article off history" gnus-summary-pop-article t])
2760         ("Sort"
2761          ["Sort by number" gnus-summary-sort-by-number t]
2762          ["Sort by most recent number" gnus-summary-sort-by-most-recent-number t]
2763          ["Sort by author" gnus-summary-sort-by-author t]
2764          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2765          ["Sort by subject" gnus-summary-sort-by-subject t]
2766          ["Sort by date" gnus-summary-sort-by-date t]
2767          ["Sort by most recent date" gnus-summary-sort-by-most-recent-date t]
2768          ["Sort by score" gnus-summary-sort-by-score t]
2769          ["Sort by lines" gnus-summary-sort-by-lines t]
2770          ["Sort by characters" gnus-summary-sort-by-chars t]
2771          ["Randomize" gnus-summary-sort-by-random t]
2772          ["Original sort" gnus-summary-sort-by-original t])
2773         ("Help"
2774          ["Describe group" gnus-summary-describe-group t]
2775          ["Read manual" gnus-info-find-node t])
2776         ("Modes"
2777          ["Pick and read" gnus-pick-mode t]
2778          ["Binary" gnus-binary-mode t])
2779         ("Regeneration"
2780          ["Regenerate" gnus-summary-prepare t]
2781          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2782          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2783          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2784          ["Toggle threading" gnus-summary-toggle-threads t])
2785         ["See old articles" gnus-summary-insert-old-articles t]
2786         ["See new articles" gnus-summary-insert-new-articles t]
2787         ["Filter articles..." gnus-summary-execute-command t]
2788         ["Run command on articles..." gnus-summary-universal-argument t]
2789         ["Search articles forward..." gnus-summary-search-article-forward t]
2790         ["Search articles backward..." gnus-summary-search-article-backward t]
2791         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2792         ["Expand window" gnus-summary-expand-window t]
2793         ["Expire expirable articles" gnus-summary-expire-articles
2794          (gnus-check-backend-function
2795           'request-expire-articles gnus-newsgroup-name)]
2796         ["Edit local kill file" gnus-summary-edit-local-kill t]
2797         ["Edit main kill file" gnus-summary-edit-global-kill t]
2798         ["Edit group parameters" gnus-summary-edit-parameters t]
2799         ["Customize group parameters" gnus-summary-customize-parameters t]
2800         ["Send a bug report" gnus-bug t]
2801         ("Exit"
2802          ["Catchup and exit" gnus-summary-catchup-and-exit
2803           ,@(if (featurep 'xemacs) '(t)
2804               '(:help "Mark unread articles in this group as read, then exit"))]
2805          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2806          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2807          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2808          ["Exit group" gnus-summary-exit
2809           ,@(if (featurep 'xemacs) '(t)
2810               '(:help "Exit current group, return to group selection mode"))]
2811          ["Exit group without updating" gnus-summary-exit-no-update t]
2812          ["Exit and goto next group" gnus-summary-next-group t]
2813          ["Exit and goto prev group" gnus-summary-prev-group t]
2814          ["Reselect group" gnus-summary-reselect-current-group t]
2815          ["Rescan group" gnus-summary-rescan-group t]
2816          ["Update dribble" gnus-summary-save-newsrc t])))
2817
2818     (gnus-run-hooks 'gnus-summary-menu-hook)))
2819
2820 (defvar gnus-summary-tool-bar-map nil)
2821
2822 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2823 ;; affect _new_ message buffers.  We might add a function that walks thru all
2824 ;; summary-mode buffers and force the update.
2825 (defun gnus-summary-tool-bar-update (&optional symbol value)
2826   "Update summary mode toolbar.
2827 Setter function for custom variables."
2828   (setq-default gnus-summary-tool-bar-map nil)
2829   (when symbol
2830     ;; When used as ":set" function:
2831     (set-default symbol value))
2832   (when (gnus-buffer-live-p gnus-summary-buffer)
2833     (with-current-buffer gnus-summary-buffer
2834       (gnus-summary-make-tool-bar))))
2835
2836 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2837                                      'gnus-summary-tool-bar-gnome
2838                                    'gnus-summary-tool-bar-retro)
2839   "Specifies the Gnus summary tool bar.
2840
2841 It can be either a list or a symbol refering to a list.  See
2842 `gmm-tool-bar-from-list' for the format of the list.  The
2843 default key map is `gnus-summary-mode-map'.
2844
2845 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2846 `gnus-summary-tool-bar-retro'."
2847   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2848                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2849                  (repeat :tag "User defined list" gmm-tool-bar-item)
2850                  (symbol))
2851   :version "23.1" ;; No Gnus
2852   :initialize 'custom-initialize-default
2853   :set 'gnus-summary-tool-bar-update
2854   :group 'gnus-summary)
2855
2856 (defcustom gnus-summary-tool-bar-gnome
2857   '((gnus-summary-post-news "mail/compose" nil)
2858     (gnus-summary-insert-new-articles "mail/inbox" nil
2859                                       :visible (or (not gnus-agent)
2860                                                    gnus-plugged))
2861     (gnus-summary-reply-with-original "mail/reply")
2862     (gnus-summary-reply "mail/reply" nil :visible nil)
2863     (gnus-summary-followup-with-original "mail/reply-all")
2864     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2865     (gnus-summary-mail-forward "mail/forward")
2866     (gnus-summary-save-article "mail/save")
2867     (gnus-summary-search-article-forward "search" nil :visible nil)
2868     (gnus-summary-print-article "print")
2869     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2870     ;; Some new commands that may need more suitable icons:
2871     (gnus-summary-save-newsrc "save" nil :visible nil)
2872     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2873     (gnus-summary-prev-article "left-arrow")
2874     (gnus-summary-next-article "right-arrow")
2875     (gnus-summary-next-page "next-page")
2876     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2877     ;;
2878     ;; Maybe some sort-by-... could be added:
2879     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2880     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2881     (gnus-summary-mark-as-expirable
2882      "delete" nil
2883      :visible (gnus-check-backend-function 'request-expire-articles
2884                                            gnus-newsgroup-name))
2885     (gnus-summary-mark-as-spam
2886      "mail/spam" t
2887      :visible (and (fboundp 'spam-group-ham-contents-p)
2888                    (spam-group-ham-contents-p gnus-newsgroup-name))
2889      :help "Mark as spam")
2890     (gnus-summary-mark-as-read-forward
2891      "mail/not-spam" nil
2892      :visible (and (fboundp 'spam-group-spam-contents-p)
2893                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2894     ;;
2895     (gnus-summary-exit "exit")
2896     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2897     (gnus-info-find-node "help"))
2898   "List of functions for the summary tool bar (GNOME style).
2899
2900 See `gmm-tool-bar-from-list' for the format of the list."
2901   :type '(repeat gmm-tool-bar-item)
2902   :version "23.1" ;; No Gnus
2903   :initialize 'custom-initialize-default
2904   :set 'gnus-summary-tool-bar-update
2905   :group 'gnus-summary)
2906
2907 (defcustom gnus-summary-tool-bar-retro
2908   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2909     (gnus-summary-next-unread-article "gnus/next-ur")
2910     (gnus-summary-post-news "gnus/post")
2911     (gnus-summary-followup-with-original "gnus/fuwo")
2912     (gnus-summary-followup "gnus/followup")
2913     (gnus-summary-reply-with-original "gnus/reply-wo")
2914     (gnus-summary-reply "gnus/reply")
2915     (gnus-summary-caesar-message "gnus/rot13")
2916     (gnus-uu-decode-uu "gnus/uu-decode")
2917     (gnus-summary-save-article-file "gnus/save-aif")
2918     (gnus-summary-save-article "gnus/save-art")
2919     (gnus-uu-post-news "gnus/uu-post")
2920     (gnus-summary-catchup "gnus/catchup")
2921     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2922     (gnus-summary-exit "gnus/exit-summ")
2923     ;; Some new command that may need more suitable icons:
2924     (gnus-summary-print-article "gnus/print" nil :visible nil)
2925     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2926     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2927     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2928     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2929     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2930     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2931     ;;
2932     (gnus-info-find-node "gnus/help" nil :visible nil))
2933   "List of functions for the summary tool bar (retro look).
2934
2935 See `gmm-tool-bar-from-list' for the format of the list."
2936   :type '(repeat gmm-tool-bar-item)
2937   :version "23.1" ;; No Gnus
2938   :initialize 'custom-initialize-default
2939   :set 'gnus-summary-tool-bar-update
2940   :group 'gnus-summary)
2941
2942 (defcustom gnus-summary-tool-bar-zap-list t
2943   "List of icon items from the global tool bar.
2944 These items are not displayed in the Gnus summary mode tool bar.
2945
2946 See `gmm-tool-bar-from-list' for the format of the list."
2947   :type 'gmm-tool-bar-zap-list
2948   :version "23.1" ;; No Gnus
2949   :initialize 'custom-initialize-default
2950   :set 'gnus-summary-tool-bar-update
2951   :group 'gnus-summary)
2952
2953 (defvar image-load-path)
2954 (defvar tool-bar-map)
2955
2956 (defun gnus-summary-make-tool-bar (&optional force)
2957   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2958 When FORCE, rebuild the tool bar."
2959   (when (and (not (featurep 'xemacs))
2960              (boundp 'tool-bar-mode)
2961              tool-bar-mode
2962              (or (not gnus-summary-tool-bar-map) force))
2963     (let* ((load-path
2964             (gmm-image-load-path-for-library "gnus"
2965                                              "mail/save.xpm"
2966                                              nil t))
2967            (image-load-path (cons (car load-path)
2968                                   (when (boundp 'image-load-path)
2969                                     image-load-path)))
2970            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2971                                         gnus-summary-tool-bar-zap-list
2972                                         'gnus-summary-mode-map)))
2973       (when map
2974         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2975         ;; uses it's value.
2976         (setq gnus-summary-tool-bar-map map))))
2977   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2978
2979 (defun gnus-score-set-default (var value)
2980   "A version of set that updates the GNU Emacs menu-bar."
2981   (set var value)
2982   ;; It is the message that forces the active status to be updated.
2983   (message ""))
2984
2985 (defun gnus-make-score-map (type)
2986   "Make a summary score map of type TYPE."
2987   (if t
2988       nil
2989     (let ((headers '(("author" "from" string)
2990                      ("subject" "subject" string)
2991                      ("article body" "body" string)
2992                      ("article head" "head" string)
2993                      ("xref" "xref" string)
2994                      ("extra header" "extra" string)
2995                      ("lines" "lines" number)
2996                      ("followups to author" "followup" string)))
2997           (types '((number ("less than" <)
2998                            ("greater than" >)
2999                            ("equal" =))
3000                    (string ("substring" s)
3001                            ("exact string" e)
3002                            ("fuzzy string" f)
3003                            ("regexp" r))))
3004           (perms '(("temporary" (current-time-string))
3005                    ("permanent" nil)
3006                    ("immediate" now)))
3007           header)
3008       (list
3009        (apply
3010         'nconc
3011         (list
3012          (if (eq type 'lower)
3013              "Lower score"
3014            "Increase score"))
3015         (let (outh)
3016           (while headers
3017             (setq header (car headers))
3018             (setq outh
3019                   (cons
3020                    (apply
3021                     'nconc
3022                     (list (car header))
3023                     (let ((ts (cdr (assoc (nth 2 header) types)))
3024                           outt)
3025                       (while ts
3026                         (setq outt
3027                               (cons
3028                                (apply
3029                                 'nconc
3030                                 (list (caar ts))
3031                                 (let ((ps perms)
3032                                       outp)
3033                                   (while ps
3034                                     (setq outp
3035                                           (cons
3036                                            (vector
3037                                             (caar ps)
3038                                             (list
3039                                              'gnus-summary-score-entry
3040                                              (nth 1 header)
3041                                              (if (or (string= (nth 1 header)
3042                                                               "head")
3043                                                      (string= (nth 1 header)
3044                                                               "body"))
3045                                                  ""
3046                                                (list 'gnus-summary-header
3047                                                      (nth 1 header)))
3048                                              (list 'quote (nth 1 (car ts)))
3049                                              (list 'gnus-score-delta-default
3050                                                    nil)
3051                                              (nth 1 (car ps))
3052                                              t)
3053                                             t)
3054                                            outp))
3055                                     (setq ps (cdr ps)))
3056                                   (list (nreverse outp))))
3057                                outt))
3058                         (setq ts (cdr ts)))
3059                       (list (nreverse outt))))
3060                    outh))
3061             (setq headers (cdr headers)))
3062           (list (nreverse outh))))))))
3063
3064
3065 (declare-function turn-on-gnus-mailing-list-mode "gnus-ml" ())
3066 (defvar bookmark-make-record-function)
3067 \f
3068
3069 (defun gnus-summary-mode (&optional group)
3070   "Major mode for reading articles.
3071
3072 All normal editing commands are switched off.
3073 \\<gnus-summary-mode-map>
3074 Each line in this buffer represents one article.  To read an
3075 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
3076 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
3077 respectively.
3078
3079 You can also post articles and send mail from this buffer.  To
3080 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
3081 of an article, type `\\[gnus-summary-reply]'.
3082
3083 There are approx. one gazillion commands you can execute in this
3084 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
3085
3086 The following commands are available:
3087
3088 \\{gnus-summary-mode-map}"
3089   (interactive)
3090   (kill-all-local-variables)
3091   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
3092     (gnus-summary-make-local-variables))
3093   (gnus-summary-make-local-variables)
3094   (setq gnus-newsgroup-name group)
3095   (when (gnus-visual-p 'summary-menu 'menu)
3096     (gnus-summary-make-menu-bar)
3097     (gnus-summary-make-tool-bar))
3098   (gnus-make-thread-indent-array)
3099   (gnus-simplify-mode-line)
3100   (setq major-mode 'gnus-summary-mode)
3101   (setq mode-name "Summary")
3102   (use-local-map gnus-summary-mode-map)
3103   (buffer-disable-undo)
3104   (setq buffer-read-only t              ;Disable modification
3105         show-trailing-whitespace nil)
3106   (setq truncate-lines t)
3107   (add-to-invisibility-spec '(gnus-sum . t))
3108   (gnus-summary-set-display-table)
3109   (gnus-set-default-directory)
3110   (make-local-variable 'gnus-summary-line-format)
3111   (make-local-variable 'gnus-summary-line-format-spec)
3112   (make-local-variable 'gnus-summary-dummy-line-format)
3113   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3114   (make-local-variable 'gnus-summary-mark-positions)
3115   (gnus-make-local-hook 'pre-command-hook)
3116   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3117   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3118   (turn-on-gnus-mailing-list-mode)
3119   (mm-enable-multibyte)
3120   (set (make-local-variable 'bookmark-make-record-function)
3121        'gnus-summary-bookmark-make-record)
3122   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3123   (gnus-update-summary-mark-positions))
3124
3125 (defun gnus-summary-make-local-variables ()
3126   "Make all the local summary buffer variables."
3127   (let (global)
3128     (dolist (local gnus-summary-local-variables)
3129       (if (consp local)
3130           (progn
3131             (if (eq (cdr local) 'global)
3132                 ;; Copy the global value of the variable.
3133                 (setq global (symbol-value (car local)))
3134               ;; Use the value from the list.
3135               (setq global (eval (cdr local))))
3136             (set (make-local-variable (car local)) global))
3137         ;; Simple nil-valued local variable.
3138         (set (make-local-variable local) nil)))))
3139
3140 ;; Summary data functions.
3141
3142 (defmacro gnus-data-number (data)
3143   `(car ,data))
3144
3145 (defmacro gnus-data-set-number (data number)
3146   `(setcar ,data ,number))
3147
3148 (defmacro gnus-data-mark (data)
3149   `(nth 1 ,data))
3150
3151 (defmacro gnus-data-set-mark (data mark)
3152   `(setcar (nthcdr 1 ,data) ,mark))
3153
3154 (defmacro gnus-data-pos (data)
3155   `(nth 2 ,data))
3156
3157 (defmacro gnus-data-set-pos (data pos)
3158   `(setcar (nthcdr 2 ,data) ,pos))
3159
3160 (defmacro gnus-data-header (data)
3161   `(nth 3 ,data))
3162
3163 (defmacro gnus-data-set-header (data header)
3164   `(setf (nth 3 ,data) ,header))
3165
3166 (defmacro gnus-data-level (data)
3167   `(nth 4 ,data))
3168
3169 (defmacro gnus-data-unread-p (data)
3170   `(= (nth 1 ,data) gnus-unread-mark))
3171
3172 (defmacro gnus-data-read-p (data)
3173   `(/= (nth 1 ,data) gnus-unread-mark))
3174
3175 (defmacro gnus-data-pseudo-p (data)
3176   `(consp (nth 3 ,data)))
3177
3178 (defmacro gnus-data-find (number)
3179   `(assq ,number gnus-newsgroup-data))
3180
3181 (defmacro gnus-data-find-list (number &optional data)
3182   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3183      (memq (assq ,number bdata)
3184            bdata)))
3185
3186 (defmacro gnus-data-make (number mark pos header level)
3187   `(list ,number ,mark ,pos ,header ,level))
3188
3189 (defun gnus-data-enter (after-article number mark pos header level offset)
3190   (let ((data (gnus-data-find-list after-article)))
3191     (unless data
3192       (error "No such article: %d" after-article))
3193     (setcdr data (cons (gnus-data-make number mark pos header level)
3194                        (cdr data)))
3195     (setq gnus-newsgroup-data-reverse nil)
3196     (gnus-data-update-list (cddr data) offset)))
3197
3198 (defun gnus-data-enter-list (after-article list &optional offset)
3199   (when list
3200     (let ((data (and after-article (gnus-data-find-list after-article)))
3201           (ilist list))
3202       (if (not (or data
3203                    after-article))
3204           (let ((odata gnus-newsgroup-data))
3205             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3206             (when offset
3207               (gnus-data-update-list odata offset)))
3208         ;; Find the last element in the list to be spliced into the main
3209         ;; list.
3210         (setq list (last list))
3211         (if (not data)
3212             (progn
3213               (setcdr list gnus-newsgroup-data)
3214               (setq gnus-newsgroup-data ilist)
3215               (when offset
3216                 (gnus-data-update-list (cdr list) offset)))
3217           (setcdr list (cdr data))
3218           (setcdr data ilist)
3219           (when offset
3220             (gnus-data-update-list (cdr list) offset))))
3221       (setq gnus-newsgroup-data-reverse nil))))
3222
3223 (defun gnus-data-remove (article &optional offset)
3224   (let ((data gnus-newsgroup-data))
3225     (if (= (gnus-data-number (car data)) article)
3226         (progn
3227           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3228                 gnus-newsgroup-data-reverse nil)
3229           (when offset
3230             (gnus-data-update-list gnus-newsgroup-data offset)))
3231       (while (cdr data)
3232         (when (= (gnus-data-number (cadr data)) article)
3233           (setcdr data (cddr data))
3234           (when offset
3235             (gnus-data-update-list (cdr data) offset))
3236           (setq data nil
3237                 gnus-newsgroup-data-reverse nil))
3238         (setq data (cdr data))))))
3239
3240 (defmacro gnus-data-list (backward)
3241   `(if ,backward
3242        (or gnus-newsgroup-data-reverse
3243            (setq gnus-newsgroup-data-reverse
3244                  (reverse gnus-newsgroup-data)))
3245      gnus-newsgroup-data))
3246
3247 (defun gnus-data-update-list (data offset)
3248   "Add OFFSET to the POS of all data entries in DATA."
3249   (setq gnus-newsgroup-data-reverse nil)
3250   (while data
3251     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3252     (setq data (cdr data))))
3253
3254 (defun gnus-summary-article-pseudo-p (article)
3255   "Say whether this article is a pseudo article or not."
3256   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3257
3258 (defmacro gnus-summary-article-sparse-p (article)
3259   "Say whether this article is a sparse article or not."
3260   `(memq ,article gnus-newsgroup-sparse))
3261
3262 (defmacro gnus-summary-article-ancient-p (article)
3263   "Say whether this article is a sparse article or not."
3264   `(memq ,article gnus-newsgroup-ancient))
3265
3266 (defun gnus-article-parent-p (number)
3267   "Say whether this article is a parent or not."
3268   (let ((data (gnus-data-find-list number)))
3269     (and (cdr data)              ; There has to be an article after...
3270          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3271             (gnus-data-level (nth 1 data))))))
3272
3273 (defun gnus-article-children (number)
3274   "Return a list of all children to NUMBER."
3275   (let* ((data (gnus-data-find-list number))
3276          (level (gnus-data-level (car data)))
3277          children)
3278     (setq data (cdr data))
3279     (while (and data
3280                 (= (gnus-data-level (car data)) (1+ level)))
3281       (push (gnus-data-number (car data)) children)
3282       (setq data (cdr data)))
3283     children))
3284
3285 (defmacro gnus-summary-skip-intangible ()
3286   "If the current article is intangible, then jump to a different article."
3287   '(let ((to (get-text-property (point) 'gnus-intangible)))
3288      (and to (gnus-summary-goto-subject to))))
3289
3290 (defmacro gnus-summary-article-intangible-p ()
3291   "Say whether this article is intangible or not."
3292   '(get-text-property (point) 'gnus-intangible))
3293
3294 (defun gnus-article-read-p (article)
3295   "Say whether ARTICLE is read or not."
3296   (not (or (memq article gnus-newsgroup-marked)
3297            (memq article gnus-newsgroup-spam-marked)
3298            (memq article gnus-newsgroup-unreads)
3299            (memq article gnus-newsgroup-unselected)
3300            (memq article gnus-newsgroup-dormant))))
3301
3302 ;; Some summary mode macros.
3303
3304 (defmacro gnus-summary-article-number ()
3305   "The article number of the article on the current line.
3306 If there isn't an article number here, then we return the current
3307 article number."
3308   '(progn
3309      (gnus-summary-skip-intangible)
3310      (or (get-text-property (point) 'gnus-number)
3311          (gnus-summary-last-subject))))
3312
3313 (defmacro gnus-summary-article-header (&optional number)
3314   "Return the header of article NUMBER."
3315   `(gnus-data-header (gnus-data-find
3316                       ,(or number '(gnus-summary-article-number)))))
3317
3318 (defmacro gnus-summary-thread-level (&optional number)
3319   "Return the level of thread that starts with article NUMBER."
3320   `(if (and (eq gnus-summary-make-false-root 'dummy)
3321             (get-text-property (point) 'gnus-intangible))
3322        0
3323      (gnus-data-level (gnus-data-find
3324                        ,(or number '(gnus-summary-article-number))))))
3325
3326 (defmacro gnus-summary-article-mark (&optional number)
3327   "Return the mark of article NUMBER."
3328   `(gnus-data-mark (gnus-data-find
3329                     ,(or number '(gnus-summary-article-number)))))
3330
3331 (defmacro gnus-summary-article-pos (&optional number)
3332   "Return the position of the line of article NUMBER."
3333   `(gnus-data-pos (gnus-data-find
3334                    ,(or number '(gnus-summary-article-number)))))
3335
3336 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3337 (defmacro gnus-summary-article-subject (&optional number)
3338   "Return current subject string or nil if nothing."
3339   `(let ((headers
3340           ,(if number
3341                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3342              '(gnus-data-header (assq (gnus-summary-article-number)
3343                                       gnus-newsgroup-data)))))
3344      (and headers
3345           (vectorp headers)
3346           (mail-header-subject headers))))
3347
3348 (defmacro gnus-summary-article-score (&optional number)
3349   "Return current article score."
3350   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3351                   gnus-newsgroup-scored))
3352        gnus-summary-default-score 0))
3353
3354 (defun gnus-summary-article-children (&optional number)
3355   "Return a list of article numbers that are children of article NUMBER."
3356   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3357          (level (gnus-data-level (car data)))
3358          l children)
3359     (while (and (setq data (cdr data))
3360                 (> (setq l (gnus-data-level (car data))) level))
3361       (and (= (1+ level) l)
3362            (push (gnus-data-number (car data))
3363                  children)))
3364     (nreverse children)))
3365
3366 (defun gnus-summary-article-parent (&optional number)
3367   "Return the article number of the parent of article NUMBER."
3368   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3369                                     (gnus-data-list t)))
3370          (level (gnus-data-level (car data))))
3371     (if (zerop level)
3372         ()                              ; This is a root.
3373       ;; We search until we find an article with a level less than
3374       ;; this one.  That function has to be the parent.
3375       (while (and (setq data (cdr data))
3376                   (not (< (gnus-data-level (car data)) level))))
3377       (and data (gnus-data-number (car data))))))
3378
3379 (defun gnus-unread-mark-p (mark)
3380   "Say whether MARK is the unread mark."
3381   (= mark gnus-unread-mark))
3382
3383 (defun gnus-read-mark-p (mark)
3384   "Say whether MARK is one of the marks that mark as read.
3385 This is all marks except unread, ticked, dormant, and expirable."
3386   (not (or (= mark gnus-unread-mark)
3387            (= mark gnus-ticked-mark)
3388            (= mark gnus-spam-mark)
3389            (= mark gnus-dormant-mark)
3390            (= mark gnus-expirable-mark))))
3391
3392 (defmacro gnus-article-mark (number)
3393   "Return the MARK of article NUMBER.
3394 This macro should only be used when computing the mark the \"first\"
3395 time; i.e., when generating the summary lines.  After that,
3396 `gnus-summary-article-mark' should be used to examine the
3397 marks of articles."
3398   `(cond
3399     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3400     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3401     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3402     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3403     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3404     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3405     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3406     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3407            gnus-ancient-mark))))
3408
3409 ;; Saving hidden threads.
3410
3411 (defmacro gnus-save-hidden-threads (&rest forms)
3412   "Save hidden threads, eval FORMS, and restore the hidden threads."
3413   (let ((config (make-symbol "config")))
3414     `(let ((,config (gnus-hidden-threads-configuration)))
3415        (unwind-protect
3416            (save-excursion
3417              ,@forms)
3418          (gnus-restore-hidden-threads-configuration ,config)))))
3419 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3420 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3421
3422 (defun gnus-data-compute-positions ()
3423   "Compute the positions of all articles."
3424   (setq gnus-newsgroup-data-reverse nil)
3425   (let ((data gnus-newsgroup-data))
3426     (save-excursion
3427       (gnus-save-hidden-threads
3428         (gnus-summary-show-all-threads)
3429         (goto-char (point-min))
3430         (while data
3431           (while (get-text-property (point) 'gnus-intangible)
3432             (forward-line 1))
3433           (gnus-data-set-pos (car data) (+ (point) 3))
3434           (setq data (cdr data))
3435           (forward-line 1))))))
3436
3437 (defun gnus-hidden-threads-configuration ()
3438   "Return the current hidden threads configuration."
3439   (save-excursion
3440     (let (config)
3441       (goto-char (point-min))
3442       (while (not (eobp))
3443         (when (eq (get-char-property (point-at-eol) 'invisible) 'gnus-sum)
3444           (push (save-excursion (forward-line 0) (point)) config))
3445         (forward-line 1))
3446       config)))
3447
3448 (defun gnus-restore-hidden-threads-configuration (config)
3449   "Restore hidden threads configuration from CONFIG."
3450   (save-excursion
3451     (let (point (inhibit-read-only t))
3452       (while (setq point (pop config))
3453         (goto-char point)
3454         (gnus-summary-hide-thread)))))
3455
3456 ;; Various summary mode internalish functions.
3457
3458 (defun gnus-mouse-pick-article (e)
3459   (interactive "e")
3460   (mouse-set-point e)
3461   (gnus-summary-next-page nil t))
3462
3463 (defun gnus-summary-set-display-table ()
3464   "Change the display table.
3465 Odd characters have a tendency to mess
3466 up nicely formatted displays - we make all possible glyphs
3467 display only a single character."
3468
3469   ;; We start from the standard display table, if any.
3470   (let ((table (or (copy-sequence standard-display-table)
3471                    (make-display-table)))
3472         (i 32))
3473     ;; Nix out all the control chars...
3474     (while (>= (setq i (1- i)) 0)
3475       (gnus-put-display-table i [??] table))
3476    ;; ... but not newline and cr, of course.  (cr is necessary for the
3477     ;; selective display).
3478     (gnus-put-display-table ?\n nil table)
3479     (gnus-put-display-table ?\r nil table)
3480     ;; We keep TAB as well.
3481     (gnus-put-display-table ?\t nil table)
3482     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3483     ;; Emacs 23 (unicode), that are not set already.
3484     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3485                  160
3486                256)))
3487       (while (>= (setq i (1- i)) 127)
3488         ;; Only modify if the entry is nil.
3489         (unless (gnus-get-display-table i table)
3490           (gnus-put-display-table i [??] table))))
3491     (setq buffer-display-table table)))
3492
3493 (defun gnus-summary-set-article-display-arrow (pos)
3494   "Update the overlay arrow to point to line at position POS."
3495   (when gnus-summary-display-arrow
3496     (make-local-variable 'overlay-arrow-position)
3497     (make-local-variable 'overlay-arrow-string)
3498     (save-excursion
3499       (goto-char pos)
3500       (beginning-of-line)
3501       (unless overlay-arrow-position
3502         (setq overlay-arrow-position (make-marker)))
3503       (setq overlay-arrow-string "=>"
3504             overlay-arrow-position (set-marker overlay-arrow-position
3505                                                (point)
3506                                                (current-buffer))))))
3507
3508 (defun gnus-summary-setup-buffer (group)
3509   "Initialize summary buffer."
3510   (let ((buffer (gnus-summary-buffer-name group))
3511         (dead-name (concat "*Dead Summary "
3512                            (gnus-group-decoded-name group) "*")))
3513     ;; If a dead summary buffer exists, we kill it.
3514     (when (gnus-buffer-live-p dead-name)
3515       (gnus-kill-buffer dead-name))
3516     (if (get-buffer buffer)
3517         (progn
3518           (set-buffer buffer)
3519           (setq gnus-summary-buffer (current-buffer))
3520           (not gnus-newsgroup-prepared))
3521       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3522       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3523       (gnus-summary-mode group)
3524       (when (gnus-group-quit-config group)
3525         (set (make-local-variable 'gnus-single-article-buffer) nil))
3526       (make-local-variable 'gnus-article-buffer)
3527       (make-local-variable 'gnus-article-current)
3528       (make-local-variable 'gnus-original-article-buffer)
3529       (setq gnus-newsgroup-name group)
3530       ;; Set any local variables in the group parameters.
3531       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3532       t)))
3533
3534 (defun gnus-set-global-variables ()
3535   "Set the global equivalents of the buffer-local variables.
3536 They are set to the latest values they had.  These reflect the summary
3537 buffer that was in action when the last article was fetched."
3538   (when (eq major-mode 'gnus-summary-mode)
3539     (setq gnus-summary-buffer (current-buffer))
3540     (let ((name gnus-newsgroup-name)
3541           (marked gnus-newsgroup-marked)
3542           (spam gnus-newsgroup-spam-marked)
3543           (unread gnus-newsgroup-unreads)
3544           (headers gnus-current-headers)
3545           (data gnus-newsgroup-data)
3546           (summary gnus-summary-buffer)
3547           (article-buffer gnus-article-buffer)
3548           (original gnus-original-article-buffer)
3549           (gac gnus-article-current)
3550           (reffed gnus-reffed-article-number)
3551           (score-file gnus-current-score-file)
3552           (default-charset gnus-newsgroup-charset)
3553           vlist)
3554       (let ((locals gnus-newsgroup-variables))
3555         (while locals
3556           (if (consp (car locals))
3557               (push (eval (caar locals)) vlist)
3558             (push (eval (car locals)) vlist))
3559           (setq locals (cdr locals)))
3560         (setq vlist (nreverse vlist)))
3561       (with-current-buffer gnus-group-buffer
3562         (setq gnus-newsgroup-name name
3563               gnus-newsgroup-marked marked
3564               gnus-newsgroup-spam-marked spam
3565               gnus-newsgroup-unreads unread
3566               gnus-current-headers headers
3567               gnus-newsgroup-data data
3568               gnus-article-current gac
3569               gnus-summary-buffer summary
3570               gnus-article-buffer article-buffer
3571               gnus-original-article-buffer original
3572               gnus-reffed-article-number reffed
3573               gnus-current-score-file score-file
3574               gnus-newsgroup-charset default-charset)
3575         (let ((locals gnus-newsgroup-variables))
3576           (while locals
3577             (if (consp (car locals))
3578                 (set (caar locals) (pop vlist))
3579               (set (car locals) (pop vlist)))
3580             (setq locals (cdr locals))))
3581         ;; The article buffer also has local variables.
3582         (when (gnus-buffer-live-p gnus-article-buffer)
3583           (set-buffer gnus-article-buffer)
3584           (setq gnus-summary-buffer summary))))))
3585
3586 (defun gnus-summary-article-unread-p (article)
3587   "Say whether ARTICLE is unread or not."
3588   (memq article gnus-newsgroup-unreads))
3589
3590 (defun gnus-summary-first-article-p (&optional article)
3591   "Return whether ARTICLE is the first article in the buffer."
3592   (if (not (setq article (or article (gnus-summary-article-number))))
3593       nil
3594     (eq article (caar gnus-newsgroup-data))))
3595
3596 (defun gnus-summary-last-article-p (&optional article)
3597   "Return whether ARTICLE is the last article in the buffer."
3598   (if (not (setq article (or article (gnus-summary-article-number))))
3599       ;; All non-existent numbers are the last article.  :-)
3600       t
3601     (not (cdr (gnus-data-find-list article)))))
3602
3603 (defun gnus-make-thread-indent-array (&optional n)
3604   (when (or n
3605             (progn (setq n 200) nil)
3606             (null gnus-thread-indent-array)
3607             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3608     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3609           gnus-thread-indent-array-level gnus-thread-indent-level)
3610     (while (>= n 0)
3611       (aset gnus-thread-indent-array n
3612             (make-string (* n gnus-thread-indent-level) ? ))
3613       (setq n (1- n)))))
3614
3615 (defun gnus-update-summary-mark-positions ()
3616   "Compute where the summary marks are to go."
3617   (save-excursion
3618     (when (gnus-buffer-exists-p gnus-summary-buffer)
3619       (set-buffer gnus-summary-buffer))
3620     (let ((spec gnus-summary-line-format-spec)
3621           pos)
3622       (save-excursion
3623         (gnus-set-work-buffer)
3624         (let ((gnus-tmp-unread ?Z)
3625               (gnus-replied-mark ?Z)
3626               (gnus-score-below-mark ?Z)
3627               (gnus-score-over-mark ?Z)
3628               (gnus-undownloaded-mark ?Z)
3629               (gnus-summary-line-format-spec spec)
3630               (gnus-newsgroup-downloadable '(0))
3631               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3632               case-fold-search ignores)
3633           ;; Here, all marks are bound to Z.
3634           (gnus-summary-insert-line header
3635                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3636           (goto-char (point-min))
3637           ;; Memorize the positions of the same characters as dummy marks.
3638           (while (re-search-forward "[A-D]" nil t)
3639             (push (point) ignores))
3640           (erase-buffer)
3641           ;; We use A-D as dummy marks in order to know column positions
3642           ;; where marks should be inserted.
3643           (setq gnus-tmp-unread ?A
3644                 gnus-replied-mark ?B
3645                 gnus-score-below-mark ?C
3646                 gnus-score-over-mark ?C
3647                 gnus-undownloaded-mark ?D)
3648           (gnus-summary-insert-line header
3649                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3650           ;; Ignore characters which aren't dummy marks.
3651           (dolist (p ignores)
3652             (delete-region (goto-char (1- p)) p)
3653             (insert ?Z))
3654           (goto-char (point-min))
3655           (setq pos (list (cons 'unread
3656                                 (and (search-forward "A" nil t)
3657                                      (- (point) (point-min) 1)))))
3658           (goto-char (point-min))
3659           (push (cons 'replied (and (search-forward "B" nil t)
3660                                     (- (point) (point-min) 1)))
3661                 pos)
3662           (goto-char (point-min))
3663           (push (cons 'score (and (search-forward "C" nil t)
3664                                   (- (point) (point-min) 1)))
3665                 pos)
3666           (goto-char (point-min))
3667           (push (cons 'download (and (search-forward "D" nil t)
3668                                      (- (point) (point-min) 1)))
3669                 pos)))
3670       (setq gnus-summary-mark-positions pos))))
3671
3672 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3673   "Insert a dummy root in the summary buffer."
3674   (beginning-of-line)
3675   (gnus-add-text-properties
3676    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3677    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3678
3679 (defun gnus-summary-extract-address-component (from)
3680   (or (car (funcall gnus-extract-address-components from))
3681       from))
3682
3683 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3684   (let ((mail-parse-charset gnus-newsgroup-charset)
3685         (ignored-from-addresses (gnus-ignored-from-addresses))
3686         ; Is it really necessary to do this next part for each summary line?
3687         ; Luckily, doesn't seem to slow things down much.
3688         (mail-parse-ignored-charsets
3689          (with-current-buffer gnus-summary-buffer
3690            gnus-newsgroup-ignored-charsets)))
3691     (or
3692      (and ignored-from-addresses
3693           (string-match ignored-from-addresses gnus-tmp-from)
3694           (let ((extra-headers (mail-header-extra header))
3695                 to
3696                 newsgroups)
3697             (cond
3698              ((setq to (cdr (assq 'To extra-headers)))
3699               (concat gnus-summary-to-prefix
3700                       (inline
3701                         (gnus-summary-extract-address-component
3702                          (funcall gnus-decode-encoded-address-function to)))))
3703              ((setq newsgroups
3704                     (or
3705                      (cdr (assq 'Newsgroups extra-headers))
3706                      (and
3707                       (memq 'Newsgroups gnus-extra-headers)
3708                       (eq (car (gnus-find-method-for-group
3709                                 gnus-newsgroup-name)) 'nntp)
3710                       (gnus-group-real-name gnus-newsgroup-name))))
3711               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3712      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3713
3714 (defun gnus-summary-insert-line (gnus-tmp-header
3715                                  gnus-tmp-level gnus-tmp-current
3716                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3717                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3718                                  &optional gnus-tmp-dummy gnus-tmp-score
3719                                  gnus-tmp-process)
3720   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3721       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3722                                           gnus-tmp-level)))
3723   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3724          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3725          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3726          (gnus-tmp-score-char
3727           (if (or (null gnus-summary-default-score)
3728                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3729                       gnus-summary-zcore-fuzz))
3730               ?                         ;Whitespace
3731             (if (< gnus-tmp-score gnus-summary-default-score)
3732                 gnus-score-below-mark gnus-score-over-mark)))
3733          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3734          (gnus-tmp-replied
3735           (cond (gnus-tmp-process gnus-process-mark)
3736                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3737                  gnus-cached-mark)
3738                 (gnus-tmp-replied gnus-replied-mark)
3739                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3740                  gnus-forwarded-mark)
3741                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3742                  gnus-saved-mark)
3743                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3744                  gnus-recent-mark)
3745                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3746                  gnus-unseen-mark)
3747                 (t gnus-no-mark)))
3748          (gnus-tmp-downloaded
3749           (cond (undownloaded
3750                  gnus-undownloaded-mark)
3751                 (gnus-newsgroup-agentized
3752                  gnus-downloaded-mark)
3753                 (t
3754                  gnus-no-mark)))
3755          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3756          (gnus-tmp-name
3757           (cond
3758            ((string-match "<[^>]+> *$" gnus-tmp-from)
3759             (let ((beg (match-beginning 0)))
3760               (or (and (string-match "^\".+\"" gnus-tmp-from)
3761                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3762                   (substring gnus-tmp-from 0 beg))))
3763            ((string-match "(.+)" gnus-tmp-from)
3764             (substring gnus-tmp-from
3765                        (1+ (match-beginning 0)) (1- (match-end 0))))
3766            (t gnus-tmp-from)))
3767          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3768          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3769          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3770          (inhibit-read-only t))
3771     (when (string= gnus-tmp-name "")
3772       (setq gnus-tmp-name gnus-tmp-from))
3773     (unless (numberp gnus-tmp-lines)
3774       (setq gnus-tmp-lines -1))
3775     (if (= gnus-tmp-lines -1)
3776         (setq gnus-tmp-lines "?")
3777       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3778     (condition-case ()
3779         (gnus-put-text-property
3780          (point)
3781          (progn (eval gnus-summary-line-format-spec) (point))
3782          'gnus-number gnus-tmp-number)
3783       (error (gnus-message 5 "Error updating the summary line")))
3784     (when (gnus-visual-p 'summary-highlight 'highlight)
3785       (forward-line -1)
3786       (gnus-summary-highlight-line)
3787       (gnus-run-hooks 'gnus-summary-update-hook)
3788       (forward-line 1))))
3789
3790 (defun gnus-summary-update-line (&optional dont-update)
3791   "Update summary line after change."
3792   (when (and gnus-summary-default-score
3793              (not gnus-summary-inhibit-highlight))
3794     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3795            (article (gnus-summary-article-number))
3796            (score (gnus-summary-article-score article)))
3797       (unless dont-update
3798         (if (and gnus-summary-mark-below
3799                  (< (gnus-summary-article-score)
3800                     gnus-summary-mark-below))
3801             ;; This article has a low score, so we mark it as read.
3802             (when (memq article gnus-newsgroup-unreads)
3803               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3804           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3805             ;; This article was previously marked as read on account
3806             ;; of a low score, but now it has risen, so we mark it as
3807             ;; unread.
3808             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3809         (gnus-summary-update-mark
3810          (if (or (null gnus-summary-default-score)
3811                  (<= (abs (- score gnus-summary-default-score))
3812                      gnus-summary-zcore-fuzz))
3813              ?                          ;Whitespace
3814            (if (< score gnus-summary-default-score)
3815                gnus-score-below-mark gnus-score-over-mark))
3816          'score))
3817       ;; Do visual highlighting.
3818       (when (gnus-visual-p 'summary-highlight 'highlight)
3819         (gnus-summary-highlight-line)
3820         (gnus-run-hooks 'gnus-summary-update-hook)))))
3821
3822 (defvar gnus-tmp-new-adopts nil)
3823
3824 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3825   "Return the number of articles in THREAD.
3826 This may be 0 in some cases -- if none of the articles in
3827 the thread are to be displayed."
3828   (let* ((number
3829          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3830           (cond
3831            ((not (listp thread))
3832             1)
3833            ((and (consp thread) (cdr thread))
3834             (apply
3835              '+ 1 (mapcar
3836                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3837            ((null thread)
3838             1)
3839            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3840             1)
3841            (t 0))))
3842     (when (and level (zerop level) gnus-tmp-new-adopts)
3843       (incf number
3844             (apply '+ (mapcar
3845                        'gnus-summary-number-of-articles-in-thread
3846                        gnus-tmp-new-adopts))))
3847     (if char
3848         (if (> number 1) gnus-not-empty-thread-mark
3849           gnus-empty-thread-mark)
3850       number)))
3851
3852 (defsubst gnus-summary-line-message-size (head)
3853   "Return pretty-printed version of message size.
3854 This function is intended to be used in
3855 `gnus-summary-line-format-alist'."
3856   (let ((c (or (mail-header-chars head) -1)))
3857     (cond ((< c 0) "n/a")               ; chars not available
3858           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3859           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3860           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3861           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3862
3863 (defcustom gnus-user-date-format-alist
3864   '(((gnus-seconds-today) . "Today, %H:%M")
3865     ((+ 86400 (gnus-seconds-today)) . "Yesterday, %H:%M")
3866     (604800 . "%A %H:%M")               ; That's one week
3867     ((gnus-seconds-month) . "%A %d")
3868     ((gnus-seconds-year) . "%B %d")
3869     (t . "%b %d %Y"))                   ; This one is used when no other
3870                                         ; does match
3871   "Specifies date format depending on age of article.
3872 This is an alist of items (AGE . FORMAT).  AGE can be a number (of
3873 seconds) or a Lisp expression evaluating to a number.  When the age of
3874 the article is less than this number, then use `format-time-string'
3875 with the corresponding FORMAT for displaying the date of the article.
3876 If AGE is not a number or a Lisp expression evaluating to a
3877 non-number, then the corresponding FORMAT is used as a default value.
3878
3879 Note that the list is processed from the beginning, so it should be
3880 sorted by ascending AGE.  Also note that items following the first
3881 non-number AGE will be ignored.
3882
3883 You can use the functions `gnus-seconds-today', `gnus-seconds-month'
3884 and `gnus-seconds-year' in the AGE spec.  They return the number of
3885 seconds passed since the start of today, of this month, of this year,
3886 respectively."
3887   :version "24.1"
3888   :group 'gnus-summary-format
3889   :type '(alist :key-type sexp :value-type string))
3890
3891 (defun gnus-user-date (messy-date)
3892   "Format the messy-date according to `gnus-user-date-format-alist'.
3893 Returns \"  ?  \" if there's bad input or if another error occurs.
3894 Input should look like this: \"Sun, 14 Oct 2001 13:34:39 +0200\"."
3895   (condition-case ()
3896       (let* ((messy-date (gnus-float-time (gnus-date-get-time messy-date)))
3897              (now (gnus-float-time))
3898              ;;If we don't find something suitable we'll use this one
3899              (my-format "%b %d '%y"))
3900         (let* ((difference (- now messy-date))
3901                (templist gnus-user-date-format-alist)
3902                (top (eval (caar templist))))
3903           (while (if (numberp top) (< top difference) (not top))
3904             (progn
3905               (setq templist (cdr templist))
3906               (setq top (eval (caar templist)))))
3907           (if (stringp (cdr (car templist)))
3908               (setq my-format (cdr (car templist)))))
3909         (format-time-string (eval my-format) (seconds-to-time messy-date)))
3910     (error "  ?   ")))
3911
3912 (defun gnus-summary-set-local-parameters (group)
3913   "Go through the local params of GROUP and set all variable specs in that list."
3914   (let ((vars '(quit-config active)))   ; Ignore things that aren't
3915                                         ; really variables.
3916     (dolist (elem (gnus-group-find-parameter group))
3917       (and (consp elem)                 ; Has to be a cons.
3918            (consp (cdr elem))           ; The cdr has to be a list.
3919            (symbolp (car elem))         ; Has to be a symbol in there.
3920            (not (memq (car elem) vars))
3921            (ignore-errors
3922              (push (car elem) vars)
3923              ;; Variables like `gnus-show-threads' that are globally
3924              ;; bound, if used as group parameters, need to get to be
3925              ;; buffer-local, whereas just parameters like `gcc-self',
3926              ;; `timestamp', etc. should not be bound as variables.
3927              (if (boundp (car elem))
3928                  (set (make-local-variable (car elem)) (eval (nth 1 elem)))
3929                (eval (nth 1 elem))))))))
3930
3931 (defun gnus-summary-read-group (group &optional show-all no-article
3932                                       kill-buffer no-display backward
3933                                       select-articles)
3934   "Start reading news in newsgroup GROUP.
3935 If SHOW-ALL is non-nil, already read articles are also listed.
3936 If NO-ARTICLE is non-nil, no article is selected initially.
3937 If NO-DISPLAY, don't generate a summary buffer."
3938   (let (result)
3939     (while (and group
3940                 (null (setq result
3941                             (let ((gnus-auto-select-next nil))
3942                               (or (gnus-summary-read-group-1
3943                                    group show-all no-article
3944                                    kill-buffer no-display
3945                                    select-articles)
3946                                   (setq show-all nil
3947                                         select-articles nil)))))
3948                 (eq gnus-auto-select-next 'quietly))
3949       (set-buffer gnus-group-buffer)
3950       ;; The entry function called above goes to the next
3951       ;; group automatically, so we go two groups back
3952       ;; if we are searching for the previous group.
3953       (when backward
3954         (gnus-group-prev-unread-group 2))
3955       (if (not (equal group (gnus-group-group-name)))
3956           (setq group (gnus-group-group-name))
3957         (setq group nil)))
3958     result))
3959
3960 (defun gnus-summary-read-group-1 (group show-all no-article
3961                                         kill-buffer no-display
3962                                         &optional select-articles)
3963   ;; Killed foreign groups can't be entered.
3964   ;;  (when (and (not (gnus-group-native-p group))
3965   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3966   ;;    (error "Dead non-native groups can't be entered"))
3967   (gnus-message 5 "Retrieving newsgroup: %s..."
3968                 (gnus-group-decoded-name group))
3969   (let* ((new-group (gnus-summary-setup-buffer group))
3970          (quit-config (gnus-group-quit-config group))
3971          (did-select (and new-group (gnus-select-newsgroup
3972                                      group show-all select-articles))))
3973     (cond
3974      ;; This summary buffer exists already, so we just select it.
3975      ((not new-group)
3976       (gnus-set-global-variables)
3977       (when kill-buffer
3978         (gnus-kill-or-deaden-summary kill-buffer))
3979       (gnus-configure-windows 'summary 'force)
3980       (gnus-set-mode-line 'summary)
3981       (gnus-summary-position-point)
3982       (message "")
3983       t)
3984      ;; We couldn't select this group.
3985      ((null did-select)
3986       (when (and (eq major-mode 'gnus-summary-mode)
3987                  (not (equal (current-buffer) kill-buffer)))
3988         (kill-buffer (current-buffer))
3989         (if (not quit-config)
3990             (progn
3991               ;; Update the info -- marks might need to be removed,
3992               ;; for instance.
3993               (gnus-summary-update-info)
3994               (set-buffer gnus-group-buffer)
3995               (gnus-group-jump-to-group group)
3996               (gnus-group-next-unread-group 1))
3997           (gnus-handle-ephemeral-exit quit-config)))
3998       (if (null (gnus-list-of-unread-articles group))
3999           (gnus-message 3 "Group %s contains no messages" group)
4000         (gnus-message 3 "Can't select group"))
4001       nil)
4002      ;; The user did a `C-g' while prompting for number of articles,
4003      ;; so we exit this group.
4004      ((eq did-select 'quit)
4005       (and (eq major-mode 'gnus-summary-mode)
4006            (not (equal (current-buffer) kill-buffer))
4007            (kill-buffer (current-buffer)))
4008       (when kill-buffer
4009         (gnus-kill-or-deaden-summary kill-buffer))
4010       (if (not quit-config)
4011           (progn
4012             (set-buffer gnus-group-buffer)
4013             (gnus-group-jump-to-group group)
4014             (gnus-configure-windows 'group 'force))
4015         (gnus-handle-ephemeral-exit quit-config))
4016       ;; Finally signal the quit.
4017       (signal 'quit nil))
4018      ;; The group was successfully selected.
4019      (t
4020       (gnus-set-global-variables)
4021       ;; Save the active value in effect when the group was entered.
4022       (setq gnus-newsgroup-active
4023             (gnus-copy-sequence
4024              (gnus-active gnus-newsgroup-name)))
4025       (setq gnus-newsgroup-highest (cdr gnus-newsgroup-active))
4026       ;; You can change the summary buffer in some way with this hook.
4027       (gnus-run-hooks 'gnus-select-group-hook)
4028       (when (memq 'summary (gnus-update-format-specifications
4029                             nil 'summary 'summary-mode 'summary-dummy))
4030         ;; The format specification for the summary line was updated,
4031         ;; so we need to update the mark positions as well.
4032         (gnus-update-summary-mark-positions))
4033       ;; Do score processing.
4034       (when gnus-use-scoring
4035         (gnus-possibly-score-headers))
4036       ;; Check whether to fill in the gaps in the threads.
4037       (when gnus-build-sparse-threads
4038         (gnus-build-sparse-threads))
4039       ;; Find the initial limit.
4040       (if show-all
4041           (let ((gnus-newsgroup-dormant nil))
4042             (gnus-summary-initial-limit show-all))
4043         (gnus-summary-initial-limit show-all))
4044       ;; Generate the summary buffer.
4045       (unless no-display
4046         (gnus-summary-prepare))
4047       (when gnus-use-trees
4048         (gnus-tree-open group)
4049         (setq gnus-summary-highlight-line-function
4050               'gnus-tree-highlight-article))
4051       ;; If the summary buffer is empty, but there are some low-scored
4052       ;; articles or some excluded dormants, we include these in the
4053       ;; buffer.
4054       (when (and (zerop (buffer-size))
4055                  (not no-display))
4056         (cond (gnus-newsgroup-dormant
4057                (gnus-summary-limit-include-dormant))
4058               ((and gnus-newsgroup-scored show-all)
4059                (gnus-summary-limit-include-expunged t))))
4060       ;; Function `gnus-apply-kill-file' must be called in this hook.
4061       (gnus-run-hooks 'gnus-apply-kill-hook)
4062       (if (and (zerop (buffer-size))
4063                (not no-display))
4064           (progn
4065             ;; This newsgroup is empty.
4066             (gnus-summary-catchup-and-exit nil t)
4067             (gnus-message 6 "No unread news")
4068             (when kill-buffer
4069               (gnus-kill-or-deaden-summary kill-buffer))
4070             ;; Return nil from this function.
4071             nil)
4072         ;; Hide conversation thread subtrees.  We cannot do this in
4073         ;; gnus-summary-prepare-hook since kill processing may not
4074         ;; work with hidden articles.
4075         (gnus-summary-maybe-hide-threads)
4076         (gnus-configure-windows 'summary)
4077         (when kill-buffer
4078           (gnus-kill-or-deaden-summary kill-buffer))
4079         (gnus-summary-auto-select-subject)
4080         ;; Show first unread article if requested.
4081         (if (and (not no-article)
4082                  (not no-display)
4083                  gnus-newsgroup-unreads
4084                  gnus-auto-select-first)
4085             (progn
4086               (let ((art (gnus-summary-article-number)))
4087                 (unless (and (not gnus-plugged)
4088                              (or (memq art gnus-newsgroup-undownloaded)
4089                                  (memq art gnus-newsgroup-downloadable)))
4090                   (gnus-summary-goto-article art))))
4091           ;; Don't select any articles.
4092           (gnus-summary-position-point)
4093           (gnus-configure-windows 'summary 'force)
4094           (gnus-set-mode-line 'summary))
4095         (when (and gnus-auto-center-group
4096                    (get-buffer-window gnus-group-buffer t))
4097           ;; Gotta use windows, because recenter does weird stuff if
4098           ;; the current buffer ain't the displayed window.
4099           (let ((owin (selected-window)))
4100             (select-window (get-buffer-window gnus-group-buffer t))
4101             (when (gnus-group-goto-group group)
4102               (recenter))
4103             (select-window owin)))
4104         ;; Mark this buffer as "prepared".
4105         (setq gnus-newsgroup-prepared t)
4106         (gnus-run-hooks 'gnus-summary-prepared-hook)
4107         (unless (gnus-ephemeral-group-p group)
4108           (gnus-group-update-group group nil t))
4109         t)))))
4110
4111 (defun gnus-summary-auto-select-subject ()
4112   "Select the subject line on initial group entry."
4113   (goto-char (point-min))
4114   (cond
4115    ((eq gnus-auto-select-subject 'best)
4116     (gnus-summary-best-unread-subject))
4117    ((eq gnus-auto-select-subject 'unread)
4118     (gnus-summary-first-unread-subject))
4119    ((eq gnus-auto-select-subject 'unseen)
4120     (gnus-summary-first-unseen-subject))
4121    ((eq gnus-auto-select-subject 'unseen-or-unread)
4122     (gnus-summary-first-unseen-or-unread-subject))
4123    ((eq gnus-auto-select-subject 'first)
4124     ;; Do nothing.
4125     )
4126    ((functionp gnus-auto-select-subject)
4127     (funcall gnus-auto-select-subject))))
4128
4129 (defun gnus-summary-prepare ()
4130   "Generate the summary buffer."
4131   (interactive)
4132   (let ((inhibit-read-only t))
4133     (erase-buffer)
4134     (setq gnus-newsgroup-data nil
4135           gnus-newsgroup-data-reverse nil)
4136     (gnus-run-hooks 'gnus-summary-generate-hook)
4137     ;; Generate the buffer, either with threads or without.
4138     (when gnus-newsgroup-headers
4139       (gnus-summary-prepare-threads
4140        (if gnus-show-threads
4141            (gnus-sort-gathered-threads
4142             (funcall gnus-summary-thread-gathering-function
4143                      (gnus-sort-threads
4144                       (gnus-cut-threads (gnus-make-threads)))))
4145          ;; Unthreaded display.
4146          (gnus-sort-articles gnus-newsgroup-headers))))
4147     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4148     ;; Call hooks for modifying summary buffer.
4149     (goto-char (point-min))
4150     (gnus-run-hooks 'gnus-summary-prepare-hook)))
4151
4152 (defsubst gnus-general-simplify-subject (subject)
4153   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4154   (setq subject
4155         (cond
4156          ;; Truncate the subject.
4157          (gnus-simplify-subject-functions
4158           (gnus-map-function gnus-simplify-subject-functions subject))
4159          ((numberp gnus-summary-gather-subject-limit)
4160           (setq subject (gnus-simplify-subject-re subject))
4161           (if (> (length subject) gnus-summary-gather-subject-limit)
4162               (substring subject 0 gnus-summary-gather-subject-limit)
4163             subject))
4164          ;; Fuzzily simplify it.
4165          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4166           (gnus-simplify-subject-fuzzy subject))
4167          ;; Just remove the leading "Re:".
4168          (t
4169           (gnus-simplify-subject-re subject))))
4170
4171   (if (and gnus-summary-gather-exclude-subject
4172            (string-match gnus-summary-gather-exclude-subject subject))
4173       nil                         ; This article shouldn't be gathered
4174     subject))
4175
4176 (defun gnus-summary-simplify-subject-query ()
4177   "Query where the respool algorithm would put this article."
4178   (interactive)
4179   (gnus-summary-select-article)
4180   (message "%s" (gnus-general-simplify-subject (gnus-summary-article-subject))))
4181
4182 (defun gnus-gather-threads-by-subject (threads)
4183   "Gather threads by looking at Subject headers."
4184   (if (not gnus-summary-make-false-root)
4185       threads
4186     (let ((hashtb (gnus-make-hashtable 1024))
4187           (prev threads)
4188           (result threads)
4189           subject hthread whole-subject)
4190       (while threads
4191         (setq subject (gnus-general-simplify-subject
4192                        (setq whole-subject (mail-header-subject
4193                                             (caar threads)))))
4194         (when subject
4195           (if (setq hthread (gnus-gethash subject hashtb))
4196               (progn
4197                 ;; We enter a dummy root into the thread, if we
4198                 ;; haven't done that already.
4199                 (unless (stringp (caar hthread))
4200                   (setcar hthread (list whole-subject (car hthread))))
4201                 ;; We add this new gathered thread to this gathered
4202                 ;; thread.
4203                 (setcdr (car hthread)
4204                         (nconc (cdar hthread) (list (car threads))))
4205                 ;; Remove it from the list of threads.
4206                 (setcdr prev (cdr threads))
4207                 (setq threads prev))
4208             ;; Enter this thread into the hash table.
4209             (gnus-sethash subject
4210                           (if gnus-summary-make-false-root-always
4211                               (progn
4212                                 ;; If you want a dummy root above all
4213                                 ;; threads...
4214                                 (setcar threads (list whole-subject
4215                                                       (car threads)))
4216                                 threads)
4217                             threads)
4218                           hashtb)))
4219         (setq prev threads)
4220         (setq threads (cdr threads)))
4221       result)))
4222
4223 (defun gnus-gather-threads-by-references (threads)
4224   "Gather threads by looking at References headers."
4225   (let ((idhashtb (gnus-make-hashtable 1024))
4226         (thhashtb (gnus-make-hashtable 1024))
4227         (prev threads)
4228         (result threads)
4229         ids references id gthread gid entered ref)
4230     (while threads
4231       (when (setq references (mail-header-references (caar threads)))
4232         (setq id (mail-header-id (caar threads))
4233               ids (inline (gnus-split-references references))
4234               entered nil)
4235         (while (setq ref (pop ids))
4236           (setq ids (delete ref ids))
4237           (if (not (setq gid (gnus-gethash ref idhashtb)))
4238               (progn
4239                 (gnus-sethash ref id idhashtb)
4240                 (gnus-sethash id threads thhashtb))
4241             (setq gthread (gnus-gethash gid thhashtb))
4242             (unless entered
4243               ;; We enter a dummy root into the thread, if we
4244               ;; haven't done that already.
4245               (unless (stringp (caar gthread))
4246                 (setcar gthread (list (mail-header-subject (caar gthread))
4247                                       (car gthread))))
4248               ;; We add this new gathered thread to this gathered
4249               ;; thread.
4250               (setcdr (car gthread)
4251                       (nconc (cdar gthread) (list (car threads)))))
4252             ;; Add it into the thread hash table.
4253             (gnus-sethash id gthread thhashtb)
4254             (setq entered t)
4255             ;; Remove it from the list of threads.
4256             (setcdr prev (cdr threads))
4257             (setq threads prev))))
4258       (setq prev threads)
4259       (setq threads (cdr threads)))
4260     result))
4261
4262 (defun gnus-sort-gathered-threads (threads)
4263   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4264   (let ((result threads))
4265     (while threads
4266       (when (stringp (caar threads))
4267         (setcdr (car threads)
4268                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4269       (setq threads (cdr threads)))
4270     result))
4271
4272 (defun gnus-thread-loop-p (root thread)
4273   "Say whether ROOT is in THREAD."
4274   (let ((stack (list thread))
4275         (infloop 0)
4276         th)
4277     (while (setq thread (pop stack))
4278       (setq th (cdr thread))
4279       (while (and th
4280                   (not (eq (caar th) root)))
4281         (pop th))
4282       (if th
4283           ;; We have found a loop.
4284           (let (ref-dep)
4285             (setcdr thread (delq (car th) (cdr thread)))
4286             (if (boundp (setq ref-dep (intern "none"
4287                                               gnus-newsgroup-dependencies)))
4288                 (setcdr (symbol-value ref-dep)
4289                         (nconc (cdr (symbol-value ref-dep))
4290                                (list (car th))))
4291               (set ref-dep (list nil (car th))))
4292             (setq infloop 1
4293                   stack nil))
4294         ;; Push all the subthreads onto the stack.
4295         (push (cdr thread) stack)))
4296     infloop))
4297
4298 (defun gnus-make-threads ()
4299   "Go through the dependency hashtb and find the roots.  Return all threads."
4300   (let (threads)
4301     (while (catch 'infloop
4302              (mapatoms
4303               (lambda (refs)
4304                 ;; Deal with self-referencing References loops.
4305                 (when (and (car (symbol-value refs))
4306                            (not (zerop
4307                                  (apply
4308                                   '+
4309                                   (mapcar
4310                                    (lambda (thread)
4311                                      (gnus-thread-loop-p
4312                                       (car (symbol-value refs)) thread))
4313                                    (cdr (symbol-value refs)))))))
4314                   (setq threads nil)
4315                   (throw 'infloop t))
4316                 (unless (car (symbol-value refs))
4317                   ;; These threads do not refer back to any other
4318                   ;; articles, so they're roots.
4319                   (setq threads (append (cdr (symbol-value refs)) threads))))
4320               gnus-newsgroup-dependencies)))
4321     threads))
4322
4323 ;; Build the thread tree.
4324 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4325   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4326
4327 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4328 if it was already present.
4329
4330 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4331 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4332 Message-IDs will be renamed to a unique Message-ID before being
4333 entered.
4334
4335 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4336   (let* ((id (mail-header-id header))
4337          (id-dep (and id (intern id dependencies)))
4338          parent-id ref ref-dep ref-header replaced)
4339     ;; Enter this `header' in the `dependencies' table.
4340     (cond
4341      ((not id-dep)
4342       (setq header nil))
4343      ;; The first two cases do the normal part: enter a new `header'
4344      ;; in the `dependencies' table.
4345      ((not (boundp id-dep))
4346       (set id-dep (list header)))
4347      ((null (car (symbol-value id-dep)))
4348       (setcar (symbol-value id-dep) header))
4349
4350      ;; From here the `header' was already present in the
4351      ;; `dependencies' table.
4352      (force-new
4353       ;; Overrides an existing entry;
4354       ;; just set the header part of the entry.
4355       (setcar (symbol-value id-dep) header)
4356       (setq replaced t))
4357
4358      ;; Renames the existing `header' to a unique Message-ID.
4359      ((not gnus-summary-ignore-duplicates)
4360       ;; An article with this Message-ID has already been seen.
4361       ;; We rename the Message-ID.
4362       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4363            (list header))
4364       (mail-header-set-id header id))
4365
4366      ;; The last case ignores an existing entry, except it adds any
4367      ;; additional Xrefs (in case the two articles came from different
4368      ;; servers.
4369      ;; Also sets `header' to `nil' meaning that the `dependencies'
4370      ;; table was *not* modified.
4371      (t
4372       (mail-header-set-xref
4373        (car (symbol-value id-dep))
4374        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4375                    "")
4376                (or (mail-header-xref header) "")))
4377       (setq header nil)))
4378
4379     (when (and header (not replaced))
4380       ;; First check that we are not creating a References loop.
4381       (setq parent-id (gnus-parent-id (mail-header-references header)))
4382       (setq ref parent-id)
4383       (while (and ref
4384                   (setq ref-dep (intern-soft ref dependencies))
4385                   (boundp ref-dep)
4386                   (setq ref-header (car (symbol-value ref-dep))))
4387         (if (string= id ref)
4388             ;; Yuk!  This is a reference loop.  Make the article be a
4389             ;; root article.
4390             (progn
4391               (mail-header-set-references (car (symbol-value id-dep)) "none")
4392               (setq ref nil)
4393               (setq parent-id nil))
4394           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4395       (setq ref-dep (intern (or parent-id "none") dependencies))
4396       (if (boundp ref-dep)
4397           (setcdr (symbol-value ref-dep)
4398                   (nconc (cdr (symbol-value ref-dep))
4399                          (list (symbol-value id-dep))))
4400         (set ref-dep (list nil (symbol-value id-dep)))))
4401     header))
4402
4403 (defun gnus-extract-message-id-from-in-reply-to (string)
4404   (if (string-match "<[^>]+>" string)
4405       (substring string (match-beginning 0) (match-end 0))
4406     nil))
4407
4408 (defun gnus-build-sparse-threads ()
4409   (let ((headers gnus-newsgroup-headers)
4410         (mail-parse-charset gnus-newsgroup-charset)
4411         (gnus-summary-ignore-duplicates t)
4412         header references generation relations
4413         subject child end new-child date)
4414     ;; First we create an alist of generations/relations, where
4415     ;; generations is how much we trust the relation, and the relation
4416     ;; is parent/child.
4417     (gnus-message 7 "Making sparse threads...")
4418     (save-excursion
4419       (nnheader-set-temp-buffer " *gnus sparse threads*")
4420       (while (setq header (pop headers))
4421         (when (and (setq references (mail-header-references header))
4422                    (not (string= references "")))
4423           (insert references)
4424           (setq child (mail-header-id header)
4425                 subject (mail-header-subject header)
4426                 date (mail-header-date header)
4427                 generation 0)
4428           (while (search-backward ">" nil t)
4429             (setq end (1+ (point)))
4430             (when (search-backward "<" nil t)
4431               (setq new-child (buffer-substring (point) end))
4432               (push (list (incf generation)
4433                           child (setq child new-child)
4434                           subject date)
4435                     relations)))
4436           (when child
4437             (push (list (1+ generation) child nil subject) relations))
4438           (erase-buffer)))
4439       (kill-buffer (current-buffer)))
4440     ;; Sort over trustworthiness.
4441     (dolist (relation (sort relations 'car-less-than-car))
4442       (when (gnus-dependencies-add-header
4443              (make-full-mail-header
4444               gnus-reffed-article-number
4445               (nth 3 relation) "" (or (nth 4 relation) "")
4446               (nth 1 relation)
4447               (or (nth 2 relation) "") 0 0 "")
4448              gnus-newsgroup-dependencies nil)
4449         (push gnus-reffed-article-number gnus-newsgroup-limit)
4450         (push gnus-reffed-article-number gnus-newsgroup-sparse)
4451         (push (cons gnus-reffed-article-number gnus-sparse-mark)
4452               gnus-newsgroup-reads)
4453         (decf gnus-reffed-article-number)))
4454     (gnus-message 7 "Making sparse threads...done")))
4455
4456 (defun gnus-build-old-threads ()
4457   ;; Look at all the articles that refer back to old articles, and
4458   ;; fetch the headers for the articles that aren't there.  This will
4459   ;; build complete threads - if the roots haven't been expired by the
4460   ;; server, that is.
4461   (let ((mail-parse-charset gnus-newsgroup-charset)
4462         id heads)
4463     (mapatoms
4464      (lambda (refs)
4465        (when (not (car (symbol-value refs)))
4466          (setq heads (cdr (symbol-value refs)))
4467          (while heads
4468            (if (memq (mail-header-number (caar heads))
4469                      gnus-newsgroup-dormant)
4470                (setq heads (cdr heads))
4471              (setq id (symbol-name refs))
4472              (while (and (setq id (gnus-build-get-header id))
4473                          (not (car (gnus-id-to-thread id)))))
4474              (setq heads nil)))))
4475      gnus-newsgroup-dependencies)))
4476
4477 (defsubst gnus-remove-odd-characters (string)
4478   "Translate STRING into something that doesn't contain weird characters."
4479   (mm-subst-char-in-string
4480    ?\r ?\-
4481    (mm-subst-char-in-string ?\n ?\- string t) t))
4482
4483 ;; This function has to be called with point after the article number
4484 ;; on the beginning of the line.
4485 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4486   (let ((eol (point-at-eol))
4487         (buffer (current-buffer))
4488         header references in-reply-to)
4489
4490     ;; overview: [num subject from date id refs chars lines misc]
4491     (unwind-protect
4492         (let (x)
4493           (narrow-to-region (point) eol)
4494           (unless (eobp)
4495             (forward-char))
4496
4497           (setq header
4498                 (make-full-mail-header
4499                  number                 ; number
4500                  (condition-case ()     ; subject
4501                      (gnus-remove-odd-characters
4502                       (funcall gnus-decode-encoded-word-function
4503                                (setq x (nnheader-nov-field))))
4504                    (error x))
4505                  (condition-case ()     ; from
4506                      (gnus-remove-odd-characters
4507                       (funcall gnus-decode-encoded-address-function
4508                                (setq x (nnheader-nov-field))))
4509                    (error x))
4510                  (nnheader-nov-field)   ; date
4511                  (nnheader-nov-read-message-id number)  ; id
4512                  (setq references (nnheader-nov-field)) ; refs
4513                  (nnheader-nov-read-integer) ; chars
4514                  (nnheader-nov-read-integer) ; lines
4515                  (unless (eobp)
4516                    (if (looking-at "Xref: ")
4517                        (goto-char (match-end 0)))
4518                    (nnheader-nov-field)) ; Xref
4519                  (nnheader-nov-parse-extra)))) ; extra
4520
4521       (widen))
4522
4523     (when (and (string= references "")
4524                (setq in-reply-to (mail-header-extra header))
4525                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4526       (mail-header-set-references
4527        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4528
4529     (when gnus-alter-header-function
4530       (funcall gnus-alter-header-function header))
4531     (gnus-dependencies-add-header header dependencies force-new)))
4532
4533 (defun gnus-build-get-header (id)
4534   "Look through the buffer of NOV lines and find the header to ID.
4535 Enter this line into the dependencies hash table, and return
4536 the id of the parent article (if any)."
4537   (let ((deps gnus-newsgroup-dependencies)
4538         found header)
4539     (prog1
4540         (with-current-buffer nntp-server-buffer
4541           (let ((case-fold-search nil))
4542             (goto-char (point-min))
4543             (while (and (not found)
4544                         (search-forward id nil t))
4545               (beginning-of-line)
4546               (setq found (looking-at
4547                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4548                                    (regexp-quote id))))
4549               (or found (beginning-of-line 2)))
4550             (when found
4551               (beginning-of-line)
4552               (and
4553                (setq header (gnus-nov-parse-line
4554                              (read (current-buffer)) deps))
4555                (gnus-parent-id (mail-header-references header))))))
4556       (when header
4557         (let ((number (mail-header-number header)))
4558           (push number gnus-newsgroup-limit)
4559           (push header gnus-newsgroup-headers)
4560           (if (memq number gnus-newsgroup-unselected)
4561               (progn
4562                 (setq gnus-newsgroup-unreads
4563                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4564                                                number))
4565                 (setq gnus-newsgroup-unselected
4566                       (delq number gnus-newsgroup-unselected)))
4567             (push number gnus-newsgroup-ancient)))))))
4568
4569 (defun gnus-build-all-threads ()
4570   "Read all the headers."
4571   (let ((gnus-summary-ignore-duplicates t)
4572         (mail-parse-charset gnus-newsgroup-charset)
4573         (dependencies gnus-newsgroup-dependencies)
4574         header article)
4575     (with-current-buffer nntp-server-buffer
4576       (let ((case-fold-search nil))
4577         (goto-char (point-min))
4578         (while (not (eobp))
4579           (ignore-errors
4580             (setq article (read (current-buffer))
4581                   header (gnus-nov-parse-line article dependencies t)))
4582           (when header
4583             (with-current-buffer gnus-summary-buffer
4584               (push header gnus-newsgroup-headers)
4585               (if (memq (setq article (mail-header-number header))
4586                         gnus-newsgroup-unselected)
4587                   (progn
4588                     (setq gnus-newsgroup-unreads
4589                           (gnus-add-to-sorted-list
4590                            gnus-newsgroup-unreads article))
4591                     (setq gnus-newsgroup-unselected
4592                           (delq article gnus-newsgroup-unselected)))
4593                 (push article gnus-newsgroup-ancient)))
4594             (forward-line 1)))))))
4595
4596 (defun gnus-summary-update-article-line (article header)
4597   "Update the line for ARTICLE using HEADER."
4598   (let* ((id (mail-header-id header))
4599          (thread (gnus-id-to-thread id)))
4600     (unless thread
4601       (error "Article in no thread"))
4602     ;; Update the thread.
4603     (setcar thread header)
4604     (gnus-summary-goto-subject article)
4605     (let* ((datal (gnus-data-find-list article))
4606            (data (car datal))
4607            (inhibit-read-only t)
4608            (level (gnus-summary-thread-level)))
4609       (gnus-delete-line)
4610       (let ((inserted (- (point)
4611                          (progn
4612                            (gnus-summary-insert-line
4613                             header level nil
4614                             (memq article gnus-newsgroup-undownloaded)
4615                             (gnus-article-mark article)
4616                             (memq article gnus-newsgroup-replied)
4617                             (memq article gnus-newsgroup-expirable)
4618                             ;; Only insert the Subject string when it's different
4619                             ;; from the previous Subject string.
4620                             (if (and
4621                                  gnus-show-threads
4622                                  (gnus-subject-equal
4623                                   (condition-case ()
4624                                       (mail-header-subject
4625                                        (gnus-data-header
4626                                         (cadr
4627                                          (gnus-data-find-list
4628                                           article
4629                                           (gnus-data-list t)))))
4630                                     ;; Error on the side of excessive subjects.
4631                                     (error ""))
4632                                   (mail-header-subject header)))
4633                                 ""
4634                               (mail-header-subject header))
4635                             nil (cdr (assq article gnus-newsgroup-scored))
4636                             (memq article gnus-newsgroup-processable))
4637                            (point)))))
4638         (when (cdr datal)
4639           (gnus-data-update-list
4640            (cdr datal)
4641            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4642
4643 (defun gnus-summary-update-article (article &optional iheader)
4644   "Update ARTICLE in the summary buffer."
4645   (set-buffer gnus-summary-buffer)
4646   (let* ((header (gnus-summary-article-header article))
4647          (id (mail-header-id header))
4648          (data (gnus-data-find article))
4649          (thread (gnus-id-to-thread id))
4650          (references (mail-header-references header))
4651          (parent
4652           (gnus-id-to-thread
4653            (or (gnus-parent-id
4654                 (when (and references
4655                            (not (equal "" references)))
4656                   references))
4657                "none")))
4658          (inhibit-read-only t)
4659          (old (car thread)))
4660     (when thread
4661       (unless iheader
4662         (setcar thread nil)
4663         (when parent
4664           (delq thread parent)))
4665       (if (gnus-summary-insert-subject id header)
4666           ;; Set the (possibly) new article number in the data structure.
4667           (gnus-data-set-number data (gnus-id-to-article id))
4668         (setcar thread old)
4669         nil))))
4670
4671 (defun gnus-rebuild-thread (id &optional line)
4672   "Rebuild the thread containing ID.
4673 If LINE, insert the rebuilt thread starting on line LINE."
4674   (let ((inhibit-read-only t)
4675         old-pos current thread data)
4676     (if (not gnus-show-threads)
4677         (setq thread (list (car (gnus-id-to-thread id))))
4678       ;; Get the thread this article is part of.
4679       (setq thread (gnus-remove-thread id)))
4680     (setq old-pos (point-at-bol))
4681     (setq current (save-excursion
4682                     (and (re-search-backward "[\r\n]" nil t)
4683                          (gnus-summary-article-number))))
4684     ;; If this is a gathered thread, we have to go some re-gathering.
4685     (when (stringp (car thread))
4686       (let ((subject (car thread))
4687             roots thr)
4688         (setq thread (cdr thread))
4689         (while thread
4690           (unless (memq (setq thr (gnus-id-to-thread
4691                                    (gnus-root-id
4692                                     (mail-header-id (caar thread)))))
4693                         roots)
4694             (push thr roots))
4695           (setq thread (cdr thread)))
4696         ;; We now have all (unique) roots.
4697         (if (= (length roots) 1)
4698             ;; All the loose roots are now one solid root.
4699             (setq thread (car roots))
4700           (setq thread (cons subject (gnus-sort-threads roots))))))
4701     (let (threads)
4702       ;; We then insert this thread into the summary buffer.
4703       (when line
4704         (goto-char (point-min))
4705         (forward-line (1- line)))
4706       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4707         (if gnus-show-threads
4708             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4709           (gnus-summary-prepare-unthreaded thread))
4710         (setq data (nreverse gnus-newsgroup-data))
4711         (setq threads gnus-newsgroup-threads))
4712       ;; We splice the new data into the data structure.
4713       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4714       ;;!!! then we want to insert at the beginning of the buffer.
4715       ;;!!! That happens to be true with Gnus now, but that may
4716       ;;!!! change in the future.  Perhaps.
4717       (gnus-data-enter-list
4718        (if line nil current) data (- (point) old-pos))
4719       (setq gnus-newsgroup-threads
4720             (nconc threads gnus-newsgroup-threads))
4721       (gnus-data-compute-positions))))
4722
4723 (defun gnus-number-to-header (number)
4724   "Return the header for article NUMBER."
4725   (let ((headers gnus-newsgroup-headers))
4726     (while (and headers
4727                 (not (= number (mail-header-number (car headers)))))
4728       (pop headers))
4729     (when headers
4730       (car headers))))
4731
4732 (defun gnus-parent-headers (in-headers &optional generation)
4733   "Return the headers of the GENERATIONeth parent of HEADERS."
4734   (unless generation
4735     (setq generation 1))
4736   (let ((parent t)
4737         (headers in-headers)
4738         references)
4739     (while (and parent
4740                 (not (zerop generation))
4741                 (setq references (mail-header-references headers)))
4742       (setq headers (if (and references
4743                              (setq parent (gnus-parent-id references)))
4744                         (car (gnus-id-to-thread parent))
4745                       nil))
4746       (decf generation))
4747     (and (not (eq headers in-headers))
4748          headers)))
4749
4750 (defun gnus-id-to-thread (id)
4751   "Return the (sub-)thread where ID appears."
4752   (gnus-gethash id gnus-newsgroup-dependencies))
4753
4754 (defun gnus-id-to-article (id)
4755   "Return the article number of ID."
4756   (let ((thread (gnus-id-to-thread id)))
4757     (when (and thread
4758                (car thread))
4759       (mail-header-number (car thread)))))
4760
4761 (defun gnus-id-to-header (id)
4762   "Return the article headers of ID."
4763   (car (gnus-id-to-thread id)))
4764
4765 (defun gnus-article-displayed-root-p (article)
4766   "Say whether ARTICLE is a root(ish) article."
4767   (let ((level (gnus-summary-thread-level article))
4768         (refs (mail-header-references  (gnus-summary-article-header article)))
4769         particle)
4770     (cond
4771      ((null level) nil)
4772      ((zerop level) t)
4773      ((null refs) t)
4774      ((null (gnus-parent-id refs)) t)
4775      ((and (= 1 level)
4776            (null (setq particle (gnus-id-to-article
4777                                  (gnus-parent-id refs))))
4778            (null (gnus-summary-thread-level particle)))))))
4779
4780 (defun gnus-root-id (id)
4781   "Return the id of the root of the thread where ID appears."
4782   (let (last-id prev)
4783     (while (and id (setq prev (car (gnus-id-to-thread id))))
4784       (setq last-id id
4785             id (gnus-parent-id (mail-header-references prev))))
4786     last-id))
4787
4788 (defun gnus-articles-in-thread (thread)
4789   "Return the list of articles in THREAD."
4790   (cons (mail-header-number (car thread))
4791         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4792
4793 (defun gnus-remove-thread (id &optional dont-remove)
4794   "Remove the thread that has ID in it."
4795   (let (headers thread last-id)
4796     ;; First go up in this thread until we find the root.
4797     (setq last-id (gnus-root-id id)
4798           headers (message-flatten-list (gnus-id-to-thread last-id)))
4799     ;; We have now found the real root of this thread.  It might have
4800     ;; been gathered into some loose thread, so we have to search
4801     ;; through the threads to find the thread we wanted.
4802     (let ((threads gnus-newsgroup-threads)
4803           sub)
4804       (while threads
4805         (setq sub (car threads))
4806         (if (stringp (car sub))
4807             ;; This is a gathered thread, so we look at the roots
4808             ;; below it to find whether this article is in this
4809             ;; gathered root.
4810             (progn
4811               (setq sub (cdr sub))
4812               (while sub
4813                 (when (member (caar sub) headers)
4814                   (setq thread (car threads)
4815                         threads nil
4816                         sub nil))
4817                 (setq sub (cdr sub))))
4818           ;; It's an ordinary thread, so we check it.
4819           (when (eq (car sub) (car headers))
4820             (setq thread sub
4821                   threads nil)))
4822         (setq threads (cdr threads)))
4823       ;; If this article is in no thread, then it's a root.
4824       (if thread
4825           (unless dont-remove
4826             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4827         (setq thread (gnus-id-to-thread last-id)))
4828       (when thread
4829         (prog1
4830             thread                      ; We return this thread.
4831           (unless dont-remove
4832             (if (stringp (car thread))
4833                 (progn
4834                   ;; If we use dummy roots, then we have to remove the
4835                   ;; dummy root as well.
4836                   (when (eq gnus-summary-make-false-root 'dummy)
4837                     ;; We go to the dummy root by going to
4838                     ;; the first sub-"thread", and then one line up.
4839                     (gnus-summary-goto-article
4840                      (mail-header-number (caadr thread)))
4841                     (forward-line -1)
4842                     (gnus-delete-line)
4843                     (gnus-data-compute-positions))
4844                   (setq thread (cdr thread))
4845                   (while thread
4846                     (gnus-remove-thread-1 (car thread))
4847                     (setq thread (cdr thread))))
4848               (gnus-remove-thread-1 thread))))))))
4849
4850 (defun gnus-remove-thread-1 (thread)
4851   "Remove the thread THREAD recursively."
4852   (let ((number (mail-header-number (pop thread)))
4853         d)
4854     (setq thread (reverse thread))
4855     (while thread
4856       (gnus-remove-thread-1 (pop thread)))
4857     (when (setq d (gnus-data-find number))
4858       (goto-char (gnus-data-pos d))
4859       (gnus-summary-show-thread)
4860       (gnus-data-remove
4861        number
4862        (- (point-at-bol)
4863           (prog1
4864               (1+ (point-at-eol))
4865             (gnus-delete-line)))))))
4866
4867 (defun gnus-sort-threads-recursive (threads func)
4868   (sort (mapcar (lambda (thread)
4869                   (cons (car thread)
4870                         (and (cdr thread)
4871                              (gnus-sort-threads-recursive (cdr thread) func))))
4872                 threads) func))
4873
4874 (defun gnus-sort-threads-loop (threads func)
4875   (let* ((superthread (cons nil threads))
4876          (stack (list (cons superthread threads)))
4877          remaining-threads thread)
4878     (while stack
4879       (setq remaining-threads (cdr (car stack)))
4880       (if remaining-threads
4881           (progn (setq thread (car remaining-threads))
4882                  (setcdr (car stack) (cdr remaining-threads))
4883                  (if (cdr thread)
4884                      (push (cons thread (cdr thread)) stack)))
4885         (setq thread (caar stack))
4886         (setcdr thread (sort (cdr thread) func))
4887         (pop stack)))
4888     (cdr superthread)))
4889
4890 (defun gnus-sort-threads (threads)
4891   "Sort THREADS."
4892   (if (not gnus-thread-sort-functions)
4893       threads
4894     (gnus-message 8 "Sorting threads...")
4895     (prog1
4896         (condition-case nil
4897             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4898               (gnus-sort-threads-recursive
4899                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4900           ;; Even after binding max-lisp-eval-depth, the recursive
4901           ;; sorter might fail for very long threads.  In that case,
4902           ;; try using a (less well-tested) non-recursive sorter.
4903           (error (gnus-message 9 "Sorting threads with loop...")
4904                  (gnus-sort-threads-loop
4905                   threads (gnus-make-sort-function
4906                            gnus-thread-sort-functions))))
4907       (gnus-message 8 "Sorting threads...done"))))
4908
4909 (defun gnus-sort-articles (articles)
4910   "Sort ARTICLES."
4911   (when gnus-article-sort-functions
4912     (gnus-message 7 "Sorting articles...")
4913     (prog1
4914         (setq gnus-newsgroup-headers
4915               (sort articles (gnus-make-sort-function
4916                               gnus-article-sort-functions)))
4917       (gnus-message 7 "Sorting articles...done"))))
4918
4919 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4920 (defmacro gnus-thread-header (thread)
4921   "Return header of first article in THREAD.
4922 Note that THREAD must never, ever be anything else than a variable -
4923 using some other form will lead to serious barfage."
4924   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4925   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4926   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4927         (vector thread) 2))
4928
4929 (defsubst gnus-article-sort-by-number (h1 h2)
4930   "Sort articles by article number."
4931   (< (mail-header-number h1)
4932      (mail-header-number h2)))
4933
4934 (defun gnus-thread-sort-by-number (h1 h2)
4935   "Sort threads by root article number."
4936   (gnus-article-sort-by-number
4937    (gnus-thread-header h1) (gnus-thread-header h2)))
4938
4939 (defsubst gnus-article-sort-by-random (h1 h2)
4940   "Sort articles randomly."
4941   (zerop (random 2)))
4942
4943 (defun gnus-thread-sort-by-random (h1 h2)
4944   "Sort threads randomly."
4945   (gnus-article-sort-by-random
4946    (gnus-thread-header h1) (gnus-thread-header h2)))
4947
4948 (defsubst gnus-article-sort-by-lines (h1 h2)
4949   "Sort articles by article Lines header."
4950   (< (mail-header-lines h1)
4951      (mail-header-lines h2)))
4952
4953 (defun gnus-thread-sort-by-lines (h1 h2)
4954   "Sort threads by root article Lines header."
4955   (gnus-article-sort-by-lines
4956    (gnus-thread-header h1) (gnus-thread-header h2)))
4957
4958 (defsubst gnus-article-sort-by-chars (h1 h2)
4959   "Sort articles by octet length."
4960   (< (mail-header-chars h1)
4961      (mail-header-chars h2)))
4962
4963 (defun gnus-thread-sort-by-chars (h1 h2)
4964   "Sort threads by root article octet length."
4965   (gnus-article-sort-by-chars
4966    (gnus-thread-header h1) (gnus-thread-header h2)))
4967
4968 (defsubst gnus-article-sort-by-author (h1 h2)
4969   "Sort articles by root author."
4970   (gnus-string<
4971    (let ((extract (funcall
4972                    gnus-extract-address-components
4973                    (mail-header-from h1))))
4974      (or (car extract) (cadr extract) ""))
4975    (let ((extract (funcall
4976                    gnus-extract-address-components
4977                    (mail-header-from h2))))
4978      (or (car extract) (cadr extract) ""))))
4979
4980 (defun gnus-thread-sort-by-author (h1 h2)
4981   "Sort threads by root author."
4982   (gnus-article-sort-by-author
4983    (gnus-thread-header h1)  (gnus-thread-header h2)))
4984
4985 (defsubst gnus-article-sort-by-recipient (h1 h2)
4986   "Sort articles by recipient."
4987   (gnus-string<
4988    (let ((extract (funcall
4989                    gnus-extract-address-components
4990                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4991      (or (car extract) (cadr extract)))
4992    (let ((extract (funcall
4993                    gnus-extract-address-components
4994                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4995      (or (car extract) (cadr extract)))))
4996
4997 (defun gnus-thread-sort-by-recipient (h1 h2)
4998   "Sort threads by root recipient."
4999   (gnus-article-sort-by-recipient
5000    (gnus-thread-header h1) (gnus-thread-header h2)))
5001
5002 (defsubst gnus-article-sort-by-subject (h1 h2)
5003   "Sort articles by root subject."
5004   (gnus-string<
5005    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
5006    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
5007
5008 (defun gnus-thread-sort-by-subject (h1 h2)
5009   "Sort threads by root subject."
5010   (gnus-article-sort-by-subject
5011    (gnus-thread-header h1) (gnus-thread-header h2)))
5012
5013 (defsubst gnus-article-sort-by-date (h1 h2)
5014   "Sort articles by root article date."
5015   (time-less-p
5016    (gnus-date-get-time (mail-header-date h1))
5017    (gnus-date-get-time (mail-header-date h2))))
5018
5019 (defun gnus-thread-sort-by-date (h1 h2)
5020   "Sort threads by root article date."
5021   (gnus-article-sort-by-date
5022    (gnus-thread-header h1) (gnus-thread-header h2)))
5023
5024 (defsubst gnus-article-sort-by-score (h1 h2)
5025   "Sort articles by root article score.
5026 Unscored articles will be counted as having a score of zero."
5027   (> (or (cdr (assq (mail-header-number h1)
5028                     gnus-newsgroup-scored))
5029          gnus-summary-default-score 0)
5030      (or (cdr (assq (mail-header-number h2)
5031                     gnus-newsgroup-scored))
5032          gnus-summary-default-score 0)))
5033
5034 (defun gnus-thread-sort-by-score (h1 h2)
5035   "Sort threads by root article score."
5036   (gnus-article-sort-by-score
5037    (gnus-thread-header h1) (gnus-thread-header h2)))
5038
5039 (defun gnus-thread-sort-by-total-score (h1 h2)
5040   "Sort threads by the sum of all scores in the thread.
5041 Unscored articles will be counted as having a score of zero."
5042   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
5043
5044 (defun gnus-thread-total-score (thread)
5045   ;; This function find the total score of THREAD.
5046   (cond
5047    ((null thread)
5048     0)
5049    ((consp thread)
5050     (if (stringp (car thread))
5051         (apply gnus-thread-score-function 0
5052                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
5053       (gnus-thread-total-score-1 thread)))
5054    (t
5055     (gnus-thread-total-score-1 (list thread)))))
5056
5057 (defun gnus-article-sort-by-most-recent-number (h1 h2)
5058   "Sort articles by number."
5059   (gnus-article-sort-by-number h1 h2))
5060
5061 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
5062   "Sort threads such that the thread with the most recently arrived article comes first."
5063   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
5064
5065 (defun gnus-thread-highest-number (thread)
5066   "Return the highest article number in THREAD."
5067   (apply 'max (mapcar (lambda (header)
5068                         (mail-header-number header))
5069                       (message-flatten-list thread))))
5070
5071 (defun gnus-article-sort-by-most-recent-date (h1 h2)
5072   "Sort articles by number."
5073   (gnus-article-sort-by-date h1 h2))
5074
5075 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
5076   "Sort threads such that the thread with the most recently dated article comes first."
5077   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
5078
5079 ; Since this is called not only to sort the top-level threads, but
5080 ; also in recursive sorts to order the articles within a thread, each
5081 ; article will be processed many times.  Thus it speeds things up
5082 ; quite a bit to use gnus-date-get-time, which caches the time value.
5083 (defun gnus-thread-latest-date (thread)
5084   "Return the highest article date in THREAD."
5085   (apply 'max
5086          (mapcar (lambda (header) (gnus-float-time
5087                                    (gnus-date-get-time
5088                                     (mail-header-date header))))
5089                  (message-flatten-list thread))))
5090
5091 (defun gnus-thread-total-score-1 (root)
5092   ;; This function find the total score of the thread below ROOT.
5093   (setq root (car root))
5094   (apply gnus-thread-score-function
5095          (or (append
5096               (mapcar 'gnus-thread-total-score
5097                       (cdr (gnus-id-to-thread (mail-header-id root))))
5098               (when (> (mail-header-number root) 0)
5099                 (list (or (cdr (assq (mail-header-number root)
5100                                      gnus-newsgroup-scored))
5101                           gnus-summary-default-score 0))))
5102              (list gnus-summary-default-score)
5103              '(0))))
5104
5105 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
5106 (defvar gnus-tmp-prev-subject nil)
5107 (defvar gnus-tmp-false-parent nil)
5108 (defvar gnus-tmp-root-expunged nil)
5109 (defvar gnus-tmp-dummy-line nil)
5110
5111 (defun gnus-extra-header (type &optional header)
5112   "Return the extra header of TYPE."
5113   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
5114       ""))
5115
5116 (defvar gnus-tmp-thread-tree-header-string "")
5117
5118 (defcustom gnus-sum-thread-tree-root "> "
5119   "With %B spec, used for the 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-false-root "> "
5126   "With %B spec, used for a false root of a thread.
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-single-indent ""
5133   "With %B spec, used for a thread with just one message.
5134 If nil, use subject instead."
5135   :version "22.1"
5136   :type '(radio (const :format "%v  " nil) string)
5137   :group 'gnus-thread)
5138
5139 (defcustom gnus-sum-thread-tree-vertical "| "
5140   "With %B spec, used for drawing a vertical line."
5141   :version "22.1"
5142   :type 'string
5143   :group 'gnus-thread)
5144
5145 (defcustom gnus-sum-thread-tree-indent "  "
5146   "With %B spec, used for indenting."
5147   :version "22.1"
5148   :type 'string
5149   :group 'gnus-thread)
5150
5151 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5152   "With %B spec, used for a leaf with brothers."
5153   :version "22.1"
5154   :type 'string
5155   :group 'gnus-thread)
5156
5157 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5158   "With %B spec, used for a leaf without brothers."
5159   :version "22.1"
5160   :type 'string
5161   :group 'gnus-thread)
5162
5163 (defcustom gnus-summary-display-while-building nil
5164   "If non-nil, show and update the summary buffer as it's being built.
5165 If the value is t, update the buffer after every line is inserted.  If
5166 the value is an integer (N), update the display every N lines."
5167   :version "22.1"
5168   :group 'gnus-thread
5169   :type '(choice (const :tag "off" nil)
5170                  number
5171                  (const :tag "frequently" t)))
5172
5173 (defun gnus-summary-prepare-threads (threads)
5174   "Prepare summary buffer from THREADS and indentation LEVEL.
5175 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5176 or a straight list of headers."
5177   (gnus-message 7 "Generating summary...")
5178
5179   (setq gnus-newsgroup-threads threads)
5180   (beginning-of-line)
5181
5182   (let ((gnus-tmp-level 0)
5183         (default-score (or gnus-summary-default-score 0))
5184         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5185         (building-line-count gnus-summary-display-while-building)
5186         (building-count (integerp gnus-summary-display-while-building))
5187         thread number subject stack state gnus-tmp-gathered beg-match
5188         new-roots gnus-tmp-new-adopts thread-end simp-subject
5189         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5190         gnus-tmp-replied gnus-tmp-subject-or-nil
5191         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5192         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5193         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5194         tree-stack)
5195
5196     (setq gnus-tmp-prev-subject nil
5197           gnus-tmp-thread-tree-header-string "")
5198
5199     (if (vectorp (car threads))
5200         ;; If this is a straight (sic) list of headers, then a
5201         ;; threaded summary display isn't required, so we just create
5202         ;; an unthreaded one.
5203         (gnus-summary-prepare-unthreaded threads)
5204
5205       ;; Do the threaded display.
5206
5207       (if gnus-summary-display-while-building
5208           (switch-to-buffer (buffer-name)))
5209       (while (or threads stack gnus-tmp-new-adopts new-roots)
5210
5211         (if (and (= gnus-tmp-level 0)
5212                  (or (not stack)
5213                      (= (caar stack) 0))
5214                  (not gnus-tmp-false-parent)
5215                  (or gnus-tmp-new-adopts new-roots))
5216             (if gnus-tmp-new-adopts
5217                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5218                       thread (list (car gnus-tmp-new-adopts))
5219                       gnus-tmp-header (caar thread)
5220                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5221               (when new-roots
5222                 (setq thread (list (car new-roots))
5223                       gnus-tmp-header (caar thread)
5224                       new-roots (cdr new-roots))))
5225
5226           (if threads
5227               ;; If there are some threads, we do them before the
5228               ;; threads on the stack.
5229               (setq thread threads
5230                     gnus-tmp-header (caar thread))
5231             ;; There were no current threads, so we pop something off
5232             ;; the stack.
5233             (setq state (car stack)
5234                   gnus-tmp-level (car state)
5235                   tree-stack (cadr state)
5236                   thread (caddr state)
5237                   stack (cdr stack)
5238                   gnus-tmp-header (caar thread))))
5239
5240         (setq gnus-tmp-false-parent nil)
5241         (setq gnus-tmp-root-expunged nil)
5242         (setq thread-end nil)
5243
5244         (if (stringp gnus-tmp-header)
5245             ;; The header is a dummy root.
5246             (cond
5247              ((eq gnus-summary-make-false-root 'adopt)
5248               ;; We let the first article adopt the rest.
5249               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5250                                                (cddar thread)))
5251               (setq gnus-tmp-gathered
5252                     (nconc (mapcar
5253                             (lambda (h) (mail-header-number (car h)))
5254                             (cddar thread))
5255                            gnus-tmp-gathered))
5256               (setq thread (cons (list (caar thread)
5257                                        (cadar thread))
5258                                  (cdr thread)))
5259               (setq gnus-tmp-level -1
5260                     gnus-tmp-false-parent t))
5261              ((eq gnus-summary-make-false-root 'empty)
5262               ;; We print adopted articles with empty subject fields.
5263               (setq gnus-tmp-gathered
5264                     (nconc (mapcar
5265                             (lambda (h) (mail-header-number (car h)))
5266                             (cddar thread))
5267                            gnus-tmp-gathered))
5268               (setq gnus-tmp-level -1))
5269              ((eq gnus-summary-make-false-root 'dummy)
5270               ;; We remember that we probably want to output a dummy
5271               ;; root.
5272               (setq gnus-tmp-dummy-line gnus-tmp-header)
5273               (setq gnus-tmp-prev-subject gnus-tmp-header))
5274              (t
5275               ;; We do not make a root for the gathered
5276               ;; sub-threads at all.
5277               (setq gnus-tmp-level -1)))
5278
5279           (setq number (mail-header-number gnus-tmp-header)
5280                 subject (mail-header-subject gnus-tmp-header)
5281                 simp-subject (gnus-simplify-subject-fully subject))
5282
5283           (cond
5284            ;; If the thread has changed subject, we might want to make
5285            ;; this subthread into a root.
5286            ((and (null gnus-thread-ignore-subject)
5287                  (not (zerop gnus-tmp-level))
5288                  gnus-tmp-prev-subject
5289                  (not (string= gnus-tmp-prev-subject simp-subject)))
5290             (setq new-roots (nconc new-roots (list (car thread)))
5291                   thread-end t
5292                   gnus-tmp-header nil))
5293            ;; If the article lies outside the current limit,
5294            ;; then we do not display it.
5295            ((not (memq number gnus-newsgroup-limit))
5296             (setq gnus-tmp-gathered
5297                   (nconc (mapcar
5298                           (lambda (h) (mail-header-number (car h)))
5299                           (cdar thread))
5300                          gnus-tmp-gathered))
5301             (setq gnus-tmp-new-adopts (if (cdar thread)
5302                                           (append gnus-tmp-new-adopts
5303                                                   (cdar thread))
5304                                         gnus-tmp-new-adopts)
5305                   thread-end t
5306                   gnus-tmp-header nil)
5307             (when (zerop gnus-tmp-level)
5308               (setq gnus-tmp-root-expunged t)))
5309            ;; Perhaps this article is to be marked as read?
5310            ((and gnus-summary-mark-below
5311                  (< (or (cdr (assq number gnus-newsgroup-scored))
5312                         default-score)
5313                     gnus-summary-mark-below)
5314                  ;; Don't touch sparse articles.
5315                  (not (gnus-summary-article-sparse-p number))
5316                  (not (gnus-summary-article-ancient-p number)))
5317             (setq gnus-newsgroup-unreads
5318                   (delq number gnus-newsgroup-unreads))
5319             (if gnus-newsgroup-auto-expire
5320                 (setq gnus-newsgroup-expirable
5321                       (gnus-add-to-sorted-list
5322                        gnus-newsgroup-expirable number))
5323               (push (cons number gnus-low-score-mark)
5324                     gnus-newsgroup-reads))))
5325
5326           (when gnus-tmp-header
5327             ;; We may have an old dummy line to output before this
5328             ;; article.
5329             (when (and gnus-tmp-dummy-line
5330                        (gnus-subject-equal
5331                         gnus-tmp-dummy-line
5332                         (mail-header-subject gnus-tmp-header)))
5333               (gnus-summary-insert-dummy-line
5334                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5335               (setq gnus-tmp-dummy-line nil))
5336
5337             ;; Compute the mark.
5338             (setq gnus-tmp-unread (gnus-article-mark number))
5339
5340             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5341                                   gnus-tmp-header gnus-tmp-level)
5342                   gnus-newsgroup-data)
5343
5344             ;; Actually insert the line.
5345             (setq
5346              gnus-tmp-subject-or-nil
5347              (cond
5348               ((and gnus-thread-ignore-subject
5349                     gnus-tmp-prev-subject
5350                     (not (string= gnus-tmp-prev-subject simp-subject)))
5351                subject)
5352               ((zerop gnus-tmp-level)
5353                (if (and (eq gnus-summary-make-false-root 'empty)
5354                         (memq number gnus-tmp-gathered)
5355                         gnus-tmp-prev-subject
5356                         (string= gnus-tmp-prev-subject simp-subject))
5357                    gnus-summary-same-subject
5358                  subject))
5359               (t gnus-summary-same-subject)))
5360             (if (and (eq gnus-summary-make-false-root 'adopt)
5361                      (= gnus-tmp-level 1)
5362                      (memq number gnus-tmp-gathered))
5363                 (setq gnus-tmp-opening-bracket ?\<
5364                       gnus-tmp-closing-bracket ?\>)
5365               (setq gnus-tmp-opening-bracket ?\[
5366                     gnus-tmp-closing-bracket ?\]))
5367             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5368                 (gnus-make-thread-indent-array
5369                  (max (* 2 (length gnus-thread-indent-array))
5370                       gnus-tmp-level)))
5371             (setq
5372              gnus-tmp-indentation
5373              (aref gnus-thread-indent-array gnus-tmp-level)
5374              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5375              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5376                                 gnus-summary-default-score 0)
5377              gnus-tmp-score-char
5378              (if (or (null gnus-summary-default-score)
5379                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5380                          gnus-summary-zcore-fuzz))
5381                  ?                      ;Whitespace
5382                (if (< gnus-tmp-score gnus-summary-default-score)
5383                    gnus-score-below-mark gnus-score-over-mark))
5384              gnus-tmp-replied
5385              (cond ((memq number gnus-newsgroup-processable)
5386                     gnus-process-mark)
5387                    ((memq number gnus-newsgroup-cached)
5388                     gnus-cached-mark)
5389                    ((memq number gnus-newsgroup-replied)
5390                     gnus-replied-mark)
5391                    ((memq number gnus-newsgroup-forwarded)
5392                     gnus-forwarded-mark)
5393                    ((memq number gnus-newsgroup-saved)
5394                     gnus-saved-mark)
5395                    ((memq number gnus-newsgroup-recent)
5396                     gnus-recent-mark)
5397                    ((memq number gnus-newsgroup-unseen)
5398                     gnus-unseen-mark)
5399                    (t gnus-no-mark))
5400              gnus-tmp-downloaded
5401              (cond ((memq number gnus-newsgroup-undownloaded)
5402                     gnus-undownloaded-mark)
5403                    (gnus-newsgroup-agentized
5404                     gnus-downloaded-mark)
5405                    (t
5406                     gnus-no-mark))
5407              gnus-tmp-from (mail-header-from gnus-tmp-header)
5408              gnus-tmp-name
5409              (cond
5410               ((string-match "<[^>]+> *$" gnus-tmp-from)
5411                (setq beg-match (match-beginning 0))
5412                (or (and (string-match "^\".+\"" gnus-tmp-from)
5413                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5414                    (substring gnus-tmp-from 0 beg-match)))
5415               ((string-match "(.+)" gnus-tmp-from)
5416                (substring gnus-tmp-from
5417                           (1+ (match-beginning 0)) (1- (match-end 0))))
5418               (t gnus-tmp-from))
5419
5420              ;; Do the %B string
5421              gnus-tmp-thread-tree-header-string
5422              (cond
5423               ((not gnus-show-threads) "")
5424               ((zerop gnus-tmp-level)
5425                (cond ((cdar thread)
5426                       (or gnus-sum-thread-tree-root subject))
5427                      (gnus-tmp-new-adopts
5428                       (or gnus-sum-thread-tree-false-root subject))
5429                      (t
5430                       (or gnus-sum-thread-tree-single-indent subject))))
5431               (t
5432                (concat (apply 'concat
5433                               (mapcar (lambda (item)
5434                                         (if (= item 1)
5435                                             gnus-sum-thread-tree-vertical
5436                                           gnus-sum-thread-tree-indent))
5437                                       (cdr (reverse tree-stack))))
5438                        (if (nth 1 thread)
5439                            gnus-sum-thread-tree-leaf-with-other
5440                          gnus-sum-thread-tree-single-leaf)))))
5441             (when (string= gnus-tmp-name "")
5442               (setq gnus-tmp-name gnus-tmp-from))
5443             (unless (numberp gnus-tmp-lines)
5444               (setq gnus-tmp-lines -1))
5445             (if (= gnus-tmp-lines -1)
5446                 (setq gnus-tmp-lines "?")
5447               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5448             (gnus-put-text-property
5449              (point)
5450              (progn (eval gnus-summary-line-format-spec) (point))
5451              'gnus-number number)
5452             (when gnus-visual-p
5453               (forward-line -1)
5454               (gnus-summary-highlight-line)
5455               (when gnus-summary-update-hook
5456                 (gnus-run-hooks 'gnus-summary-update-hook))
5457               (forward-line 1))
5458
5459             (setq gnus-tmp-prev-subject simp-subject)))
5460
5461         (when (nth 1 thread)
5462           (push (list (max 0 gnus-tmp-level)
5463                       (copy-sequence tree-stack)
5464                       (nthcdr 1 thread))
5465                 stack))
5466         (push (if (nth 1 thread) 1 0) tree-stack)
5467         (incf gnus-tmp-level)
5468         (setq threads (if thread-end nil (cdar thread)))
5469         (if gnus-summary-display-while-building
5470             (if building-count
5471                 (progn
5472                   ;; use a set frequency
5473                   (setq building-line-count (1- building-line-count))
5474                   (when (= building-line-count 0)
5475                     (sit-for 0)
5476                     (setq building-line-count
5477                           gnus-summary-display-while-building)))
5478               ;; always
5479               (sit-for 0)))
5480         (unless threads
5481           (setq gnus-tmp-level 0)))))
5482   (gnus-message 7 "Generating summary...done"))
5483
5484 (defun gnus-summary-prepare-unthreaded (headers)
5485   "Generate an unthreaded summary buffer based on HEADERS."
5486   (let (header number mark)
5487
5488     (beginning-of-line)
5489
5490     (while headers
5491       ;; We may have to root out some bad articles...
5492       (when (memq (setq number (mail-header-number
5493                                 (setq header (pop headers))))
5494                   gnus-newsgroup-limit)
5495         ;; Mark article as read when it has a low score.
5496         (when (and gnus-summary-mark-below
5497                    (< (or (cdr (assq number gnus-newsgroup-scored))
5498                           gnus-summary-default-score 0)
5499                       gnus-summary-mark-below)
5500                    (not (gnus-summary-article-ancient-p number)))
5501           (setq gnus-newsgroup-unreads
5502                 (delq number gnus-newsgroup-unreads))
5503           (if gnus-newsgroup-auto-expire
5504               (push number gnus-newsgroup-expirable)
5505             (push (cons number gnus-low-score-mark)
5506                   gnus-newsgroup-reads)))
5507
5508         (setq mark (gnus-article-mark number))
5509         (push (gnus-data-make number mark (1+ (point)) header 0)
5510               gnus-newsgroup-data)
5511         (gnus-summary-insert-line
5512          header 0 number
5513          (memq number gnus-newsgroup-undownloaded)
5514          mark (memq number gnus-newsgroup-replied)
5515          (memq number gnus-newsgroup-expirable)
5516          (mail-header-subject header) nil
5517          (cdr (assq number gnus-newsgroup-scored))
5518          (memq number gnus-newsgroup-processable))))))
5519
5520 (defun gnus-group-get-list-identifiers (group)
5521   "Get list identifier regexp for GROUP."
5522   (or (gnus-parameter-list-identifier group)
5523       (if (consp gnus-list-identifiers)
5524           (mapconcat 'identity gnus-list-identifiers " *\\|")
5525         gnus-list-identifiers)))
5526
5527 (defun gnus-summary-remove-list-identifiers ()
5528   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5529   (let ((regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
5530         changed subject)
5531     (when regexp
5532       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5533       (dolist (header gnus-newsgroup-headers)
5534         (setq subject (mail-header-subject header)
5535               changed nil)
5536         (while (string-match regexp subject)
5537           (setq subject
5538                 (concat (substring subject 0 (match-beginning 1))
5539                         (substring subject (match-end 0)))
5540                 changed t))
5541         (when changed
5542           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5543             (setq subject
5544                   (concat (substring subject 0 (match-beginning 1))
5545                           (substring subject (match-end 1)))))
5546           (mail-header-set-subject header subject))))))
5547
5548 (defun gnus-fetch-headers (articles &optional limit force-new dependencies)
5549   "Fetch headers of ARTICLES."
5550   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5551     (gnus-message 5 "Fetching headers for %s..." name)
5552     (prog1
5553         (if (eq 'nov
5554                 (setq gnus-headers-retrieved-by
5555                       (gnus-retrieve-headers
5556                        articles gnus-newsgroup-name
5557                        (or limit
5558                            ;; We might want to fetch old headers, but
5559                            ;; not if there is only 1 article.
5560                            (and (or (and
5561                                      (not (eq gnus-fetch-old-headers 'some))
5562                                      (not (numberp gnus-fetch-old-headers)))
5563                                     (> (length articles) 1))
5564                                 gnus-fetch-old-headers)))))
5565             (gnus-get-newsgroup-headers-xover
5566              articles force-new dependencies gnus-newsgroup-name t)
5567           (gnus-get-newsgroup-headers dependencies force-new))
5568       (gnus-message 5 "Fetching headers for %s...done" name))))
5569
5570 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5571   "Select newsgroup GROUP.
5572 If READ-ALL is non-nil, all articles in the group are selected.
5573 If SELECT-ARTICLES, only select those articles from GROUP."
5574   (let* ((entry (gnus-group-entry group))
5575          ;;!!! Dirty hack; should be removed.
5576          (gnus-summary-ignore-duplicates
5577           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5578               t
5579             gnus-summary-ignore-duplicates))
5580          (info (nth 2 entry))
5581          charset articles fetched-articles cached)
5582
5583     (unless (gnus-check-server
5584              (set (make-local-variable 'gnus-current-select-method)
5585                   (gnus-find-method-for-group group)))
5586       (error "Couldn't open server"))
5587     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5588
5589     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5590         (gnus-activate-group group)     ; Or we can activate it...
5591         (progn                          ; Or we bug out.
5592           (when (equal major-mode 'gnus-summary-mode)
5593             (gnus-kill-buffer (current-buffer)))
5594           (error
5595            "Couldn't activate group %s: %s"
5596            (mm-decode-coding-string group charset)
5597            (mm-decode-coding-string (gnus-status-message group) charset))))
5598
5599     (unless (gnus-request-group group t)
5600       (when (equal major-mode 'gnus-summary-mode)
5601         (gnus-kill-buffer (current-buffer)))
5602       (error "Couldn't request group %s: %s"
5603              (mm-decode-coding-string group charset)
5604              (mm-decode-coding-string (gnus-status-message group) charset)))
5605
5606     (when (and gnus-agent
5607                (gnus-active group))
5608       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5609
5610       (setq gnus-summary-use-undownloaded-faces
5611             (gnus-agent-find-parameter
5612              group
5613              'agent-enable-undownloaded-faces)))
5614
5615     (setq gnus-newsgroup-name group
5616           gnus-newsgroup-unselected nil
5617           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5618
5619     (let ((display (gnus-group-find-parameter group 'display)))
5620       (setq gnus-newsgroup-display
5621             (cond
5622              ((not (zerop (or (car-safe read-all) 0)))
5623               ;; The user entered the group with C-u SPC/RET, let's show
5624               ;; all articles.
5625               'gnus-not-ignore)
5626              ((eq display 'all)
5627               'gnus-not-ignore)
5628              ((arrayp display)
5629               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5630              ((numberp display)
5631               ;; The following is probably the "correct" solution, but
5632               ;; it makes Gnus fetch all headers and then limit the
5633               ;; articles (which is slow), so instead we hack the
5634               ;; select-articles parameter instead. -- Simon Josefsson
5635               ;; <jas@kth.se>
5636               ;;
5637               ;; (gnus-byte-compile
5638               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5639               ;;                         display)))))
5640               (setq select-articles
5641                     (gnus-uncompress-range
5642                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5643                              (if (> tmp 0)
5644                                  tmp
5645                                1))
5646                            (cdr (gnus-active group)))))
5647               nil)
5648              (t
5649               nil))))
5650
5651     (gnus-summary-setup-default-charset)
5652
5653     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5654     (when (gnus-virtual-group-p group)
5655       (setq cached gnus-newsgroup-cached))
5656
5657     (setq gnus-newsgroup-unreads
5658           (gnus-sorted-ndifference
5659            (gnus-sorted-ndifference gnus-newsgroup-unreads
5660                                     gnus-newsgroup-marked)
5661            gnus-newsgroup-dormant))
5662
5663     (setq gnus-newsgroup-processable nil)
5664
5665     (gnus-update-read-articles group gnus-newsgroup-unreads t)
5666
5667     ;; Adjust and set lists of article marks.
5668     (when info
5669       (gnus-adjust-marked-articles info))
5670     (if (setq articles select-articles)
5671         (setq gnus-newsgroup-unselected
5672               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5673       (setq articles (gnus-articles-to-read group read-all)))
5674
5675     (cond
5676      ((null articles)
5677       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5678       'quit)
5679      ((eq articles 0) nil)
5680      (t
5681       ;; Init the dependencies hash table.
5682       (setq gnus-newsgroup-dependencies
5683             (gnus-make-hashtable (length articles)))
5684       (gnus-set-global-variables)
5685       ;; Retrieve the headers and read them in.
5686
5687       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5688
5689       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5690       (when cached
5691         (setq gnus-newsgroup-cached cached))
5692
5693       ;; Suppress duplicates?
5694       (when gnus-suppress-duplicates
5695         (gnus-dup-suppress-articles))
5696
5697       ;; Set the initial limit.
5698       (setq gnus-newsgroup-limit (copy-sequence articles))
5699       ;; Remove canceled articles from the list of unread articles.
5700       (setq fetched-articles
5701             (mapcar (lambda (headers) (mail-header-number headers))
5702                     gnus-newsgroup-headers))
5703       (setq gnus-newsgroup-articles fetched-articles)
5704       (setq gnus-newsgroup-unreads
5705             (gnus-sorted-nintersection
5706              gnus-newsgroup-unreads fetched-articles))
5707       (gnus-compute-unseen-list)
5708
5709       ;; Removed marked articles that do not exist.
5710       (gnus-update-missing-marks
5711        (gnus-sorted-difference articles fetched-articles))
5712       ;; We might want to build some more threads first.
5713       (when (and gnus-fetch-old-headers
5714                  (eq gnus-headers-retrieved-by 'nov))
5715         (if (eq gnus-fetch-old-headers 'invisible)
5716             (gnus-build-all-threads)
5717           (gnus-build-old-threads)))
5718       ;; Let the Gnus agent mark articles as read.
5719       (when gnus-agent
5720         (gnus-agent-get-undownloaded-list))
5721       ;; Remove list identifiers from subject
5722       (gnus-summary-remove-list-identifiers)
5723       ;; Check whether auto-expire is to be done in this group.
5724       (setq gnus-newsgroup-auto-expire
5725             (and (gnus-group-auto-expirable-p group)
5726                  (not (gnus-group-read-only-p group))))
5727       ;; Set up the article buffer now, if necessary.
5728       (unless (and gnus-single-article-buffer
5729                    (equal gnus-article-buffer "*Article*"))
5730         (gnus-article-setup-buffer))
5731       ;; First and last article in this newsgroup.
5732       (when gnus-newsgroup-headers
5733         (setq gnus-newsgroup-begin
5734               (mail-header-number (car gnus-newsgroup-headers))
5735               gnus-newsgroup-end
5736               (mail-header-number
5737                (gnus-last-element gnus-newsgroup-headers))))
5738       ;; GROUP is successfully selected.
5739       (or gnus-newsgroup-headers t)))))
5740
5741 (defun gnus-compute-unseen-list ()
5742   ;; The `seen' marks are treated specially.
5743   (if (not gnus-newsgroup-seen)
5744       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5745     (setq gnus-newsgroup-unseen
5746           (gnus-inverse-list-range-intersection
5747            gnus-newsgroup-articles gnus-newsgroup-seen))))
5748
5749 (declare-function gnus-get-predicate "gnus-agent" (predicate))
5750
5751 (defun gnus-summary-display-make-predicate (display)
5752   (require 'gnus-agent)
5753   (when (= (length display) 1)
5754     (setq display (car display)))
5755   (unless gnus-summary-display-cache
5756     (dolist (elem (append '((unread . unread)
5757                             (read . read)
5758                             (unseen . unseen))
5759                           gnus-article-mark-lists))
5760       (push (cons (cdr elem)
5761                   (gnus-byte-compile    ;Why bother?
5762                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5763             gnus-summary-display-cache)))
5764   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5765         (gnus-category-predicate-cache gnus-summary-display-cache))
5766     (gnus-get-predicate display)))
5767
5768 ;; Uses the dynamically bound `gnus-number' variable.
5769 (defvar gnus-number)
5770 (defun gnus-article-marked-p (type &optional article)
5771   (let ((article (or article gnus-number)))
5772     (cond
5773      ((eq type 'tick)
5774       (memq article gnus-newsgroup-marked))
5775      ((eq type 'spam)
5776       (memq article gnus-newsgroup-spam-marked))
5777      ((eq type 'unsend)
5778       (memq article gnus-newsgroup-unsendable))
5779      ((eq type 'undownload)
5780       (memq article gnus-newsgroup-undownloaded))
5781      ((eq type 'download)
5782       (memq article gnus-newsgroup-downloadable))
5783      ((eq type 'unread)
5784       (memq article gnus-newsgroup-unreads))
5785      ((eq type 'read)
5786       (memq article gnus-newsgroup-reads))
5787      ((eq type 'dormant)
5788       (memq article gnus-newsgroup-dormant) )
5789      ((eq type 'expire)
5790       (memq article gnus-newsgroup-expirable))
5791      ((eq type 'reply)
5792       (memq article gnus-newsgroup-replied))
5793      ((eq type 'killed)
5794       (memq article gnus-newsgroup-killed))
5795      ((eq type 'bookmark)
5796       (assq article gnus-newsgroup-bookmarks))
5797      ((eq type 'score)
5798       (assq article gnus-newsgroup-scored))
5799      ((eq type 'save)
5800       (memq article gnus-newsgroup-saved))
5801      ((eq type 'cache)
5802       (memq article gnus-newsgroup-cached))
5803      ((eq type 'forward)
5804       (memq article gnus-newsgroup-forwarded))
5805      ((eq type 'seen)
5806       (not (memq article gnus-newsgroup-unseen)))
5807      ((eq type 'recent)
5808       (memq article gnus-newsgroup-recent))
5809      (t t))))
5810
5811 (defun gnus-articles-to-read (group &optional read-all)
5812   "Find out what articles the user wants to read."
5813   (let* ((only-read-p t)
5814          (articles
5815           ;; Select all articles if `read-all' is non-nil, or if there
5816           ;; are no unread articles.
5817           (if (or read-all
5818                   (and (zerop (length gnus-newsgroup-marked))
5819                        (zerop (length gnus-newsgroup-unreads)))
5820                   ;; Fetch all if the predicate is non-nil.
5821                   gnus-newsgroup-display)
5822               ;; We want to select the headers for all the articles in
5823               ;; the group, so we select either all the active
5824               ;; articles in the group, or (if that's nil), the
5825               ;; articles in the cache.
5826               (or
5827                (if gnus-newsgroup-maximum-articles
5828                    (let ((active (gnus-active group)))
5829                      (gnus-uncompress-range
5830                       (cons (max (car active)
5831                                  (- (cdr active)
5832                                     gnus-newsgroup-maximum-articles
5833                                     -1))
5834                             (cdr active))))
5835                  (gnus-uncompress-range (gnus-active group)))
5836                (gnus-cache-articles-in-group group))
5837             ;; Select only the "normal" subset of articles.
5838             (setq only-read-p nil)
5839             (gnus-sorted-nunion
5840              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5841              gnus-newsgroup-unreads)))
5842          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5843          (scored (length scored-list))
5844          (number (length articles))
5845          (marked (+ (length gnus-newsgroup-marked)
5846                     (length gnus-newsgroup-dormant)))
5847          (select
5848           (cond
5849            ((numberp read-all)
5850             read-all)
5851            ((numberp gnus-newsgroup-display)
5852             gnus-newsgroup-display)
5853            (t
5854             (condition-case ()
5855                 (cond
5856                  ((and (or (<= scored marked) (= scored number))
5857                        (numberp gnus-large-newsgroup)
5858                        (> number gnus-large-newsgroup))
5859                   (let* ((cursor-in-echo-area nil)
5860                          (initial (gnus-parameter-large-newsgroup-initial
5861                                    gnus-newsgroup-name))
5862                          (default (if only-read-p
5863                                       (or initial gnus-large-newsgroup)
5864                                     number))
5865                          (input
5866                           (read-string
5867                            (if only-read-p
5868                                (format
5869                               "How many articles from %s (available %d, default %d): "
5870                               (gnus-group-decoded-name
5871                                (gnus-group-real-name gnus-newsgroup-name))
5872                               number default)
5873                              (format
5874                                 "How many articles from %s (%d available): "
5875                                 (gnus-group-decoded-name
5876                                  (gnus-group-real-name gnus-newsgroup-name))
5877                                 default))
5878                            nil
5879                            nil
5880                            (number-to-string default))))
5881                     (if (string-match "^[ \t]*$" input) number input)))
5882                  ((and (> scored marked) (< scored number)
5883                        (> (- scored number) 20))
5884                   (let ((input
5885                          (read-string
5886                           (format "%s %s (%d scored, %d total): "
5887                                   "How many articles from"
5888                                   (gnus-group-decoded-name
5889                                    (gnus-group-real-name gnus-newsgroup-name))
5890                                   scored number))))
5891                     (if (string-match "^[ \t]*$" input)
5892                         number input)))
5893                  (t number))
5894               (quit
5895                (message "Quit getting the articles to read")
5896                nil))))))
5897     (setq select (if (stringp select) (string-to-number select) select))
5898     (if (or (null select) (zerop select))
5899         select
5900       (if (and (not (zerop scored)) (<= (abs select) scored))
5901           (progn
5902             (setq articles (sort scored-list '<))
5903             (setq number (length articles)))
5904         (setq articles (copy-sequence articles)))
5905
5906       (when (< (abs select) number)
5907         (if (< select 0)
5908             ;; Select the N oldest articles.
5909             (setcdr (nthcdr (1- (abs select)) articles) nil)
5910           ;; Select the N most recent articles.
5911           (setq articles (nthcdr (- number select) articles))))
5912       (setq gnus-newsgroup-unselected
5913             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5914       (when gnus-alter-articles-to-read-function
5915         (setq articles
5916               (sort
5917                (funcall gnus-alter-articles-to-read-function
5918                         gnus-newsgroup-name articles)
5919                '<)))
5920       articles)))
5921
5922 (defun gnus-killed-articles (killed articles)
5923   (let (out)
5924     (while articles
5925       (when (inline (gnus-member-of-range (car articles) killed))
5926         (push (car articles) out))
5927       (setq articles (cdr articles)))
5928     out))
5929
5930 (defun gnus-uncompress-marks (marks)
5931   "Uncompress the mark ranges in MARKS."
5932   (let ((uncompressed '(score bookmark))
5933         out)
5934     (while marks
5935       (if (memq (caar marks) uncompressed)
5936           (push (car marks) out)
5937         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5938       (setq marks (cdr marks)))
5939     out))
5940
5941 (defun gnus-article-mark-to-type (mark)
5942   "Return the type of MARK."
5943   (or (cadr (assq mark gnus-article-special-mark-lists))
5944       'list))
5945
5946 (defun gnus-article-unpropagatable-p (mark)
5947   "Return whether MARK should be propagated to back end."
5948   (memq mark gnus-article-unpropagated-mark-lists))
5949
5950 (defun gnus-adjust-marked-articles (info)
5951   "Set all article lists and remove all marks that are no longer valid."
5952   (let* ((marked-lists (gnus-info-marks info))
5953          (active (gnus-active (gnus-info-group info)))
5954          (min (car active))
5955          (max (cdr active))
5956          (types gnus-article-mark-lists)
5957          marks var articles article mark mark-type
5958          bgn end)
5959     ;; Hack to avoid adjusting marks for imap.
5960     (when (eq (car (gnus-find-method-for-group (gnus-info-group info)))
5961               'nnimap)
5962       (setq min 1))
5963
5964     (dolist (marks marked-lists)
5965       (setq mark (car marks)
5966             mark-type (gnus-article-mark-to-type mark)
5967             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5968
5969       ;; We set the variable according to the type of the marks list,
5970       ;; and then adjust the marks to a subset of the active articles.
5971       (cond
5972        ;; Adjust "simple" lists - compressed yet unsorted
5973        ((eq mark-type 'list)
5974         ;; Simultaneously uncompress and clip to active range
5975         ;; See gnus-uncompress-range for a description of possible marks
5976         (let (l lh)
5977           (if (not (cadr marks))
5978               (set var nil)
5979             (setq articles (if (numberp (cddr marks))
5980                                (list (cdr marks))
5981                              (cdr marks))
5982                   lh (cons nil nil)
5983                   l lh)
5984
5985             (while (setq article (pop articles))
5986               (cond ((consp article)
5987                      (setq bgn (max (car article) min)
5988                            end (min (cdr article) max))
5989                      (while (<= bgn end)
5990                        (setq l (setcdr l (cons bgn nil))
5991                              bgn (1+ bgn))))
5992                     ((and (<= min article)
5993                           (>= max article))
5994                      (setq l (setcdr l (cons article nil))))))
5995             (set var (cdr lh)))))
5996        ;; Adjust assocs.
5997        ((eq mark-type 'tuple)
5998         (set var (setq articles (cdr marks)))
5999         (when (not (listp (cdr (symbol-value var))))
6000           (set var (list (symbol-value var))))
6001         (when (not (listp (cdr articles)))
6002           (setq articles (list articles)))
6003         (while articles
6004           (when (or (not (consp (setq article (pop articles))))
6005                     (< (car article) min)
6006                     (> (car article) max))
6007             (set var (delq article (symbol-value var))))))
6008        ;; Adjust ranges (sloppily).
6009        ((eq mark-type 'range)
6010         (cond
6011          ((eq mark 'seen)
6012           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
6013           ;; It should be (seen (NUM1 . NUM2)).
6014           (when (numberp (cddr marks))
6015             (setcdr marks (list (cdr marks))))
6016           (setq articles (cdr marks))
6017           (while (and articles
6018                       (or (and (consp (car articles))
6019                                (> min (cdar articles)))
6020                           (and (numberp (car articles))
6021                                (> min (car articles)))))
6022             (pop articles))
6023           (set var articles))))))))
6024
6025 (defun gnus-update-missing-marks (missing)
6026   "Go through the list of MISSING articles and remove them from the mark lists."
6027   (when missing
6028     (let (var m)
6029       ;; Go through all types.
6030       (dolist (elem gnus-article-mark-lists)
6031         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
6032           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
6033           (when (symbol-value var)
6034             ;; This list has articles.  So we delete all missing
6035             ;; articles from it.
6036             (setq m missing)
6037             (while m
6038               (set var (delq (pop m) (symbol-value var))))))))))
6039
6040 (defun gnus-update-marks ()
6041   "Enter the various lists of marked articles into the newsgroup info list."
6042   (let ((types gnus-article-mark-lists)
6043         (info (gnus-get-info gnus-newsgroup-name))
6044         type list newmarked symbol delta-marks)
6045     (when info
6046       ;; Add all marks lists to the list of marks lists.
6047       (while (setq type (pop types))
6048         (setq list (symbol-value
6049                     (setq symbol
6050                           (intern (format "gnus-newsgroup-%s" (car type))))))
6051
6052         (when list
6053           ;; Get rid of the entries of the articles that have the
6054           ;; default score.
6055           (when (and (eq (cdr type) 'score)
6056                      gnus-save-score
6057                      list)
6058             (let* ((arts list)
6059                    (prev (cons nil list))
6060                    (all prev))
6061               (while arts
6062                 (if (or (not (consp (car arts)))
6063                         (= (cdar arts) gnus-summary-default-score))
6064                     (setcdr prev (cdr arts))
6065                   (setq prev arts))
6066                 (setq arts (cdr arts)))
6067               (setq list (cdr all)))))
6068
6069         (when (eq (cdr type) 'seen)
6070           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
6071
6072         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
6073           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
6074
6075         (when (and (gnus-check-backend-function
6076                     'request-set-mark gnus-newsgroup-name)
6077                    (not (gnus-article-unpropagatable-p (cdr type))))
6078           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
6079                  ;; Don't do anything about marks for articles we
6080                  ;; didn't actually get any headers for.
6081                  (del
6082                   (gnus-list-range-intersection
6083                    gnus-newsgroup-articles
6084                    (gnus-remove-from-range (gnus-copy-sequence old) list)))
6085                  (add
6086                   (gnus-list-range-intersection
6087                    gnus-newsgroup-articles
6088                    (gnus-remove-from-range
6089                     (gnus-copy-sequence list) old))))
6090             (when add
6091               (push (list add 'add (list (cdr type))) delta-marks))
6092             (when del
6093               ;; Don't delete marks from outside the active range.
6094               ;; This shouldn't happen, but is a sanity check.
6095               (setq del (gnus-sorted-range-intersection
6096                          (gnus-active gnus-newsgroup-name) del))
6097               (push (list del 'del (list (cdr type))) delta-marks))))
6098
6099         (when list
6100           (push (cons (cdr type) list) newmarked)))
6101
6102       (when delta-marks
6103         (unless (gnus-check-group gnus-newsgroup-name)
6104           (error "Can't open server for %s" gnus-newsgroup-name))
6105         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
6106
6107       ;; Enter these new marks into the info of the group.
6108       (if (nthcdr 3 info)
6109           (setcar (nthcdr 3 info) newmarked)
6110         ;; Add the marks lists to the end of the info.
6111         (when newmarked
6112           (setcdr (nthcdr 2 info) (list newmarked))))
6113
6114       ;; Cut off the end of the info if there's nothing else there.
6115       (let ((i 5))
6116         (while (and (> i 2)
6117                     (not (nth i info)))
6118           (when (nthcdr (decf i) info)
6119             (setcdr (nthcdr i info) nil)))))))
6120
6121 (defun gnus-set-mode-line (where)
6122   "Set the mode line of the article or summary buffers.
6123 If WHERE is `summary', the summary mode line format will be used."
6124   ;; Is this mode line one we keep updated?
6125   (when (and (memq where gnus-updated-mode-lines)
6126              (symbol-value
6127               (intern (format "gnus-%s-mode-line-format-spec" where))))
6128     (let (mode-string)
6129       ;; We evaluate this in the summary buffer since these
6130       ;; variables are buffer-local to that buffer.
6131       (with-current-buffer gnus-summary-buffer
6132         ;; We bind all these variables that are used in the `eval' form
6133         ;; below.
6134         (let* ((mformat (symbol-value
6135                          (intern
6136                           (format "gnus-%s-mode-line-format-spec" where))))
6137                (gnus-tmp-group-name (gnus-mode-string-quote
6138                                      (gnus-group-decoded-name
6139                                       gnus-newsgroup-name)))
6140                (gnus-tmp-article-number (or gnus-current-article 0))
6141                (gnus-tmp-unread gnus-newsgroup-unreads)
6142                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
6143                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
6144                (gnus-tmp-unread-and-unselected
6145                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
6146                             (zerop gnus-tmp-unselected))
6147                        "")
6148                       ((zerop gnus-tmp-unselected)
6149                        (format "{%d more}" gnus-tmp-unread-and-unticked))
6150                       (t (format "{%d(+%d) more}"
6151                                  gnus-tmp-unread-and-unticked
6152                                  gnus-tmp-unselected))))
6153                (gnus-tmp-subject
6154                 (if (and gnus-current-headers
6155                          (vectorp gnus-current-headers))
6156                     (gnus-mode-string-quote
6157                      (mail-header-subject gnus-current-headers))
6158                   ""))
6159                bufname-length max-len
6160                gnus-tmp-header) ;; passed as argument to any user-format-funcs
6161           (setq mode-string (eval mformat))
6162           (setq bufname-length (if (string-match "%b" mode-string)
6163                                    (- (length
6164                                        (buffer-name
6165                                         (if (eq where 'summary)
6166                                             nil
6167                                           (get-buffer gnus-article-buffer))))
6168                                       2)
6169                                  0))
6170           (setq max-len (max 4 (if gnus-mode-non-string-length
6171                                    (- (window-width)
6172                                       gnus-mode-non-string-length
6173                                       bufname-length)
6174                                  (length mode-string))))
6175           ;; We might have to chop a bit of the string off...
6176           (when (> (length mode-string) max-len)
6177             (setq mode-string
6178                   (concat (truncate-string-to-width mode-string (- max-len 3))
6179                           "...")))))
6180       ;; Update the mode line.
6181       (setq mode-line-buffer-identification
6182             (gnus-mode-line-buffer-identification (list mode-string)))
6183       (set-buffer-modified-p t))))
6184
6185 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6186   "Go through the HEADERS list and add all Xrefs to a hash table.
6187 The resulting hash table is returned, or nil if no Xrefs were found."
6188   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
6189          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
6190          (xref-hashtb (gnus-make-hashtable))
6191          start group entry number xrefs header)
6192     (while headers
6193       (setq header (pop headers))
6194       (when (and (setq xrefs (mail-header-xref header))
6195                  (not (memq (setq number (mail-header-number header))
6196                             unreads)))
6197         (setq start 0)
6198         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6199           (setq start (match-end 0))
6200           (setq group (if prefix
6201                           (concat prefix (substring xrefs (match-beginning 1)
6202                                                     (match-end 1)))
6203                         (substring xrefs (match-beginning 1) (match-end 1))))
6204           (setq number
6205                 (string-to-number (substring xrefs (match-beginning 2)
6206                                           (match-end 2))))
6207           (if (setq entry (gnus-gethash group xref-hashtb))
6208               (setcdr entry (cons number (cdr entry)))
6209             (gnus-sethash group (cons number nil) xref-hashtb)))))
6210     (and start xref-hashtb)))
6211
6212 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6213   "Look through all the headers and mark the Xrefs as read."
6214   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6215         name info xref-hashtb idlist method nth4)
6216     (with-current-buffer gnus-group-buffer
6217       (when (setq xref-hashtb
6218                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6219         (mapatoms
6220          (lambda (group)
6221            (unless (string= from-newsgroup (setq name (symbol-name group)))
6222              (setq idlist (symbol-value group))
6223              ;; Dead groups are not updated.
6224              (and (prog1
6225                       (setq info (gnus-get-info name))
6226                     (when (stringp (setq nth4 (gnus-info-method info)))
6227                       (setq nth4 (gnus-server-to-method nth4))))
6228                   ;; Only do the xrefs if the group has the same
6229                   ;; select method as the group we have just read.
6230                   (or (gnus-methods-equal-p
6231                        nth4 (gnus-find-method-for-group from-newsgroup))
6232                       virtual
6233                       (equal nth4 (setq method (gnus-find-method-for-group
6234                                                 from-newsgroup)))
6235                       (and (equal (car nth4) (car method))
6236                            (equal (nth 1 nth4) (nth 1 method))))
6237                   gnus-use-cross-reference
6238                   (or (not (eq gnus-use-cross-reference t))
6239                       virtual
6240                       ;; Only do cross-references on subscribed
6241                       ;; groups, if that is what is wanted.
6242                       (<= (gnus-info-level info) gnus-level-subscribed))
6243                   (gnus-group-make-articles-read name idlist))))
6244          xref-hashtb)))))
6245
6246 (defun gnus-compute-read-articles (group articles)
6247   (let* ((entry (gnus-group-entry group))
6248          (info (nth 2 entry))
6249          (active (gnus-active group))
6250          ninfo)
6251     (when entry
6252       ;; First peel off all invalid article numbers.
6253       (when active
6254         (let ((ids articles)
6255               id first)
6256           (while (setq id (pop ids))
6257             (when (and first (> id (cdr active)))
6258               ;; We'll end up in this situation in one particular
6259               ;; obscure situation.  If you re-scan a group and get
6260               ;; a new article that is cross-posted to a different
6261               ;; group that has not been re-scanned, you might get
6262               ;; crossposted article that has a higher number than
6263               ;; Gnus believes possible.  So we re-activate this
6264               ;; group as well.  This might mean doing the
6265               ;; crossposting thingy will *increase* the number
6266               ;; of articles in some groups.  Tsk, tsk.
6267               (setq active (or (gnus-activate-group group) active)))
6268             (when (or (> id (cdr active))
6269                       (< id (car active)))
6270               (setq articles (delq id articles))))))
6271       ;; If the read list is nil, we init it.
6272       (if (and active
6273                (null (gnus-info-read info))
6274                (> (car active) 1))
6275           (setq ninfo (cons 1 (1- (car active))))
6276         (setq ninfo (gnus-info-read info)))
6277       ;; Then we add the read articles to the range.
6278       (gnus-add-to-range
6279        ninfo (setq articles (sort articles '<))))))
6280
6281 (defun gnus-group-make-articles-read (group articles)
6282   "Update the info of GROUP to say that ARTICLES are read."
6283   (let* ((num 0)
6284          (entry (gnus-group-entry group))
6285          (info (nth 2 entry))
6286          (active (gnus-active group))
6287          range)
6288     (if (not entry)
6289         ;; Group that Gnus doesn't know exists, but still allow the
6290         ;; backend to set marks.
6291         (gnus-request-set-mark
6292          group (list (list (gnus-compress-sequence (sort articles #'<))
6293                            'add '(read))))
6294       ;; Normal, subscribed groups.
6295       (setq range (gnus-compute-read-articles group articles))
6296       (with-current-buffer gnus-group-buffer
6297         (gnus-undo-register
6298           `(progn
6299              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6300              (gnus-info-set-read ',info ',(gnus-info-read info))
6301              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6302              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6303              (gnus-group-update-group ,group t))))
6304       ;; Add the read articles to the range.
6305       (gnus-info-set-read info range)
6306       (gnus-request-set-mark group (list (list range 'add '(read))))
6307       ;; Then we have to re-compute how many unread
6308       ;; articles there are in this group.
6309       (when active
6310         (cond
6311          ((not range)
6312           (setq num (- (1+ (cdr active)) (car active))))
6313          ((not (listp (cdr range)))
6314           (setq num (- (cdr active) (- (1+ (cdr range))
6315                                        (car range)))))
6316          (t
6317           (while range
6318             (if (numberp (car range))
6319                 (setq num (1+ num))
6320               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6321             (setq range (cdr range)))
6322           (setq num (- (cdr active) num))))
6323         ;; Update the number of unread articles.
6324         (setcar entry num)
6325         ;; Update the group buffer.
6326         (unless (gnus-ephemeral-group-p group)
6327           (gnus-group-update-group group t))))))
6328
6329 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6330   (let ((cur nntp-server-buffer)
6331         (dependencies
6332          (or dependencies
6333              (with-current-buffer gnus-summary-buffer
6334                gnus-newsgroup-dependencies)))
6335         headers id end ref number
6336         (mail-parse-charset gnus-newsgroup-charset)
6337         (mail-parse-ignored-charsets
6338          (save-current-buffer (condition-case nil
6339                                   (set-buffer gnus-summary-buffer)
6340                                 (error))
6341                               gnus-newsgroup-ignored-charsets)))
6342     (with-current-buffer nntp-server-buffer
6343       ;; Translate all TAB characters into SPACE characters.
6344       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6345       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6346       (ietf-drums-unfold-fws)
6347       (gnus-run-hooks 'gnus-parse-headers-hook)
6348       (let ((case-fold-search t)
6349             in-reply-to header p lines chars)
6350         (goto-char (point-min))
6351         ;; Search to the beginning of the next header.  Error messages
6352         ;; do not begin with 2 or 3.
6353         (while (re-search-forward "^[23][0-9]+ " nil t)
6354           (setq id nil
6355                 ref nil)
6356           ;; This implementation of this function, with nine
6357           ;; search-forwards instead of the one re-search-forward and
6358           ;; a case (which basically was the old function) is actually
6359           ;; about twice as fast, even though it looks messier.  You
6360           ;; can't have everything, I guess.  Speed and elegance
6361           ;; doesn't always go hand in hand.
6362           (setq
6363            header
6364            (vector
6365             ;; Number.
6366             (prog1
6367                 (setq number (read cur))
6368               (end-of-line)
6369               (setq p (point))
6370               (narrow-to-region (point)
6371                                 (or (and (search-forward "\n.\n" nil t)
6372                                          (- (point) 2))
6373                                     (point))))
6374             ;; Subject.
6375             (progn
6376               (goto-char p)
6377               (if (search-forward "\nsubject:" nil t)
6378                   (funcall gnus-decode-encoded-word-function
6379                            (nnheader-header-value))
6380                 "(none)"))
6381             ;; From.
6382             (progn
6383               (goto-char p)
6384               (if (search-forward "\nfrom:" nil t)
6385                   (funcall gnus-decode-encoded-address-function
6386                            (nnheader-header-value))
6387                 "(nobody)"))
6388             ;; Date.
6389             (progn
6390               (goto-char p)
6391               (if (search-forward "\ndate:" nil t)
6392                   (nnheader-header-value) ""))
6393             ;; Message-ID.
6394             (progn
6395               (goto-char p)
6396               (setq id (if (re-search-forward
6397                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6398                            ;; We do it this way to make sure the Message-ID
6399                            ;; is (somewhat) syntactically valid.
6400                            (buffer-substring (match-beginning 1)
6401                                              (match-end 1))
6402                          ;; If there was no message-id, we just fake one
6403                          ;; to make subsequent routines simpler.
6404                          (nnheader-generate-fake-message-id number))))
6405             ;; References.
6406             (progn
6407               (goto-char p)
6408               (if (search-forward "\nreferences:" nil t)
6409                   (progn
6410                     (setq end (point))
6411                     (prog1
6412                         (nnheader-header-value)
6413                       (setq ref
6414                             (buffer-substring
6415                              (progn
6416                                (end-of-line)
6417                                (search-backward ">" end t)
6418                                (1+ (point)))
6419                              (progn
6420                                (search-backward "<" end t)
6421                                (point))))))
6422                 ;; Get the references from the in-reply-to header if there
6423                 ;; were no references and the in-reply-to header looks
6424                 ;; promising.
6425                 (if (and (search-forward "\nin-reply-to:" nil t)
6426                          (setq in-reply-to (nnheader-header-value))
6427                          (string-match "<[^>]+>" in-reply-to))
6428                     (let (ref2)
6429                       (setq ref (substring in-reply-to (match-beginning 0)
6430                                            (match-end 0)))
6431                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6432                         (setq ref2 (substring in-reply-to (match-beginning 0)
6433                                               (match-end 0)))
6434                         (when (> (length ref2) (length ref))
6435                           (setq ref ref2)))
6436                       ref)
6437                   (setq ref nil))))
6438             ;; Chars.
6439             (progn
6440               (goto-char p)
6441               (if (search-forward "\nchars: " nil t)
6442                   (if (numberp (setq chars (ignore-errors (read cur))))
6443                       chars -1)
6444                 -1))
6445             ;; Lines.
6446             (progn
6447               (goto-char p)
6448               (if (search-forward "\nlines: " nil t)
6449                   (if (numberp (setq lines (ignore-errors (read cur))))
6450                       lines -1)
6451                 -1))
6452             ;; Xref.
6453             (progn
6454               (goto-char p)
6455               (and (search-forward "\nxref:" nil t)
6456                    (nnheader-header-value)))
6457             ;; Extra.
6458             (when gnus-extra-headers
6459               (let ((extra gnus-extra-headers)
6460                     out)
6461                 (while extra
6462                   (goto-char p)
6463                   (when (search-forward
6464                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6465                     (push (cons (car extra) (nnheader-header-value))
6466                           out))
6467                   (pop extra))
6468                 out))))
6469           (when (equal id ref)
6470             (setq ref nil))
6471
6472           (when gnus-alter-header-function
6473             (funcall gnus-alter-header-function header)
6474             (setq id (mail-header-id header)
6475                   ref (gnus-parent-id (mail-header-references header))))
6476
6477           (when (setq header
6478                       (gnus-dependencies-add-header
6479                        header dependencies force-new))
6480             (push header headers))
6481           (goto-char (point-max))
6482           (widen))
6483         (nreverse headers)))))
6484
6485 ;; Goes through the xover lines and returns a list of vectors
6486 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6487                                                   force-new dependencies
6488                                                   group also-fetch-heads)
6489   "Parse the news overview data in the server buffer.
6490 Return a list of headers that match SEQUENCE (see
6491 `nntp-retrieve-headers')."
6492   ;; Get the Xref when the users reads the articles since most/some
6493   ;; NNTP servers do not include Xrefs when using XOVER.
6494   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6495   (let ((mail-parse-charset gnus-newsgroup-charset)
6496         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6497         (cur nntp-server-buffer)
6498         (dependencies (or dependencies gnus-newsgroup-dependencies))
6499         (allp (cond
6500                ((eq gnus-read-all-available-headers t)
6501                 t)
6502                ((and (stringp gnus-read-all-available-headers)
6503                      group)
6504                 (string-match gnus-read-all-available-headers group))
6505                (t
6506                 nil)))
6507         number headers header)
6508     (with-current-buffer nntp-server-buffer
6509       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6510       ;; Allow the user to mangle the headers before parsing them.
6511       (gnus-run-hooks 'gnus-parse-headers-hook)
6512       (goto-char (point-min))
6513       (gnus-parse-without-error
6514         (while (and (or sequence allp)
6515                     (not (eobp)))
6516           (setq number (read cur))
6517           (when (not allp)
6518             (while (and sequence
6519                         (< (car sequence) number))
6520               (setq sequence (cdr sequence))))
6521           (when (and (or allp
6522                          (and sequence
6523                               (eq number (car sequence))))
6524                      (progn
6525                        (setq sequence (cdr sequence))
6526                        (setq header (inline
6527                                       (gnus-nov-parse-line
6528                                        number dependencies force-new)))))
6529             (push header headers))
6530           (forward-line 1)))
6531       ;; A common bug in inn is that if you have posted an article and
6532       ;; then retrieves the active file, it will answer correctly --
6533       ;; the new article is included.  However, a NOV entry for the
6534       ;; article may not have been generated yet, so this may fail.
6535       ;; We work around this problem by retrieving the last few
6536       ;; headers using HEAD.
6537       (if (or (not also-fetch-heads)
6538               (not sequence))
6539           ;; We (probably) got all the headers.
6540           (nreverse headers)
6541         (let ((gnus-nov-is-evil t))
6542           (nconc
6543            (nreverse headers)
6544            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6545              (gnus-get-newsgroup-headers))))))))
6546
6547 (defun gnus-article-get-xrefs ()
6548   "Fill in the Xref value in `gnus-current-headers', if necessary.
6549 This is meant to be called in `gnus-article-internal-prepare-hook'."
6550   (let ((headers (with-current-buffer gnus-summary-buffer
6551                    gnus-current-headers)))
6552     (or (not gnus-use-cross-reference)
6553         (not headers)
6554         (and (mail-header-xref headers)
6555              (not (string= (mail-header-xref headers) "")))
6556         (let ((case-fold-search t)
6557               xref)
6558           (save-restriction
6559             (nnheader-narrow-to-headers)
6560             (goto-char (point-min))
6561             (when (or (and (not (eobp))
6562                            (eq (downcase (char-after)) ?x)
6563                            (looking-at "Xref:"))
6564                       (search-forward "\nXref:" nil t))
6565               (goto-char (1+ (match-end 0)))
6566               (setq xref (buffer-substring (point) (point-at-eol)))
6567               (mail-header-set-xref headers xref)))))))
6568
6569 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6570   "Find article ID and insert the summary line for that article.
6571 OLD-HEADER can either be a header or a line number to insert
6572 the subject line on.
6573 If USE-OLD-HEADER is non-nil, then OLD-HEADER should be a header,
6574 and OLD-HEADER will be used when the summary line is inserted,
6575 too, instead of trying to fetch new headers."
6576   (let* ((line (and (numberp old-header) old-header))
6577          (old-header (and (vectorp old-header) old-header))
6578          (header (cond ((and old-header use-old-header)
6579                         old-header)
6580                        ((and (numberp id)
6581                              (gnus-number-to-header id))
6582                         (gnus-number-to-header id))
6583                        (t
6584                         (gnus-read-header id))))
6585          (number (and (numberp id) id))
6586          d)
6587     (when header
6588       ;; Rebuild the thread that this article is part of and go to the
6589       ;; article we have fetched.
6590       (when (and (not gnus-show-threads)
6591                  old-header)
6592         (when (and number
6593                    (setq d (gnus-data-find (mail-header-number old-header))))
6594           (goto-char (gnus-data-pos d))
6595           (gnus-data-remove
6596            number
6597            (- (point-at-bol)
6598               (prog1
6599                   (1+ (point-at-eol))
6600                 (gnus-delete-line))))))
6601       ;; Remove list identifiers from subject.
6602       (let ((gnus-newsgroup-headers (list header)))
6603         (gnus-summary-remove-list-identifiers))
6604       (when old-header
6605         (mail-header-set-number header (mail-header-number old-header)))
6606       (setq gnus-newsgroup-sparse
6607             (delq (setq number (mail-header-number header))
6608                   gnus-newsgroup-sparse))
6609       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6610       (push number gnus-newsgroup-limit)
6611       (gnus-rebuild-thread (mail-header-id header) line)
6612       (gnus-summary-goto-subject number nil t))
6613     (when (and (numberp number)
6614                (> number 0))
6615       ;; We have to update the boundaries even if we can't fetch the
6616       ;; article if ID is a number -- so that the next `P' or `N'
6617       ;; command will fetch the previous (or next) article even
6618       ;; if the one we tried to fetch this time has been canceled.
6619       (when (> number gnus-newsgroup-end)
6620         (setq gnus-newsgroup-end number))
6621       (when (< number gnus-newsgroup-begin)
6622         (setq gnus-newsgroup-begin number))
6623       (setq gnus-newsgroup-unselected
6624             (delq number gnus-newsgroup-unselected)))
6625     ;; Report back a success?
6626     (and header (mail-header-number header))))
6627
6628 ;;; Process/prefix in the summary buffer
6629
6630 (defun gnus-summary-work-articles (n)
6631   "Return a list of articles to be worked upon.
6632 The prefix argument, the list of process marked articles, and the
6633 current article will be taken into consideration."
6634   (with-current-buffer gnus-summary-buffer
6635     (cond
6636      (n
6637       ;; A numerical prefix has been given.
6638       (setq n (prefix-numeric-value n))
6639       (let ((backward (< n 0))
6640             (n (abs (prefix-numeric-value n)))
6641             articles article)
6642         (save-excursion
6643           (while
6644               (and (> n 0)
6645                    (push (setq article (gnus-summary-article-number))
6646                          articles)
6647                    (if backward
6648                        (gnus-summary-find-prev nil article)
6649                      (gnus-summary-find-next nil article)))
6650             (decf n)))
6651         (nreverse articles)))
6652      ((and (gnus-region-active-p) (mark))
6653       (message "region active")
6654       ;; Work on the region between point and mark.
6655       (let ((max (max (point) (mark)))
6656             articles article)
6657         (save-excursion
6658           (goto-char (min (point) (mark)))
6659           (while
6660               (and
6661                (push (setq article (gnus-summary-article-number)) articles)
6662                (gnus-summary-find-next nil article)
6663                (< (point) max)))
6664           (nreverse articles))))
6665      (gnus-newsgroup-processable
6666       ;; There are process-marked articles present.
6667       ;; Save current state.
6668       (gnus-summary-save-process-mark)
6669       ;; Return the list.
6670       (reverse gnus-newsgroup-processable))
6671      (t
6672       ;; Just return the current article.
6673       (list (gnus-summary-article-number))))))
6674
6675 (defmacro gnus-summary-iterate (arg &rest forms)
6676   "Iterate over the process/prefixed articles and do FORMS.
6677 ARG is the interactive prefix given to the command.  FORMS will be
6678 executed with point over the summary line of the articles."
6679   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6680     `(let ((,articles (gnus-summary-work-articles ,arg)))
6681        (while ,articles
6682          (gnus-summary-goto-subject (car ,articles))
6683          ,@forms
6684          (pop ,articles)))))
6685
6686 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6687 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6688
6689 (defun gnus-summary-save-process-mark ()
6690   "Push the current set of process marked articles on the stack."
6691   (interactive)
6692   (push (copy-sequence gnus-newsgroup-processable)
6693         gnus-newsgroup-process-stack))
6694
6695 (defun gnus-summary-kill-process-mark ()
6696   "Push the current set of process marked articles on the stack and unmark."
6697   (interactive)
6698   (gnus-summary-save-process-mark)
6699   (gnus-summary-unmark-all-processable))
6700
6701 (defun gnus-summary-yank-process-mark ()
6702   "Pop the last process mark state off the stack and restore it."
6703   (interactive)
6704   (unless gnus-newsgroup-process-stack
6705     (error "Empty mark stack"))
6706   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6707
6708 (defun gnus-summary-process-mark-set (set)
6709   "Make SET into the current process marked articles."
6710   (gnus-summary-unmark-all-processable)
6711   (mapc 'gnus-summary-set-process-mark set))
6712
6713 ;;; Searching and stuff
6714
6715 (defun gnus-summary-search-group (&optional backward use-level)
6716   "Search for next unread newsgroup.
6717 If optional argument BACKWARD is non-nil, search backward instead."
6718   (with-current-buffer gnus-group-buffer
6719     (when (gnus-group-search-forward
6720            backward nil (if use-level (gnus-group-group-level) nil))
6721       (gnus-group-group-name))))
6722
6723 (defun gnus-summary-best-group (&optional exclude-group)
6724   "Find the name of the best unread group.
6725 If EXCLUDE-GROUP, do not go to this group."
6726   (with-current-buffer gnus-group-buffer
6727     (save-excursion
6728       (gnus-group-best-unread-group exclude-group))))
6729
6730 (defun gnus-summary-find-next (&optional unread article backward)
6731   (if backward
6732       (gnus-summary-find-prev unread article)
6733     (let* ((dummy (gnus-summary-article-intangible-p))
6734            (article (or article (gnus-summary-article-number)))
6735            (data (gnus-data-find-list article))
6736            result)
6737       (when (and (not dummy)
6738                  (or (not gnus-summary-check-current)
6739                      (not unread)
6740                      (not (gnus-data-unread-p (car data)))))
6741         (setq data (cdr data)))
6742       (when (setq result
6743                   (if unread
6744                       (progn
6745                         (while data
6746                           (unless (memq (gnus-data-number (car data))
6747                                         (cond
6748                                          ((eq gnus-auto-goto-ignores
6749                                               'always-undownloaded)
6750                                           gnus-newsgroup-undownloaded)
6751                                          (gnus-plugged
6752                                           nil)
6753                                          ((eq gnus-auto-goto-ignores
6754                                               'unfetched)
6755                                           gnus-newsgroup-unfetched)
6756                                          ((eq gnus-auto-goto-ignores
6757                                               'undownloaded)
6758                                           gnus-newsgroup-undownloaded)))
6759                             (when (gnus-data-unread-p (car data))
6760                               (setq result (car data)
6761                                     data nil)))
6762                           (setq data (cdr data)))
6763                         result)
6764                     (car data)))
6765         (goto-char (gnus-data-pos result))
6766         (gnus-data-number result)))))
6767
6768 (defun gnus-summary-find-prev (&optional unread article)
6769   (let* ((eobp (eobp))
6770          (article (or article (gnus-summary-article-number)))
6771          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6772          result)
6773     (when (and (not eobp)
6774                (or (not gnus-summary-check-current)
6775                    (not unread)
6776                    (not (gnus-data-unread-p (car data)))))
6777       (setq data (cdr data)))
6778     (when (setq result
6779                 (if unread
6780                     (progn
6781                       (while data
6782                         (unless (memq (gnus-data-number (car data))
6783                                       (cond
6784                                        ((eq gnus-auto-goto-ignores
6785                                             'always-undownloaded)
6786                                         gnus-newsgroup-undownloaded)
6787                                        (gnus-plugged
6788                                         nil)
6789                                        ((eq gnus-auto-goto-ignores
6790                                             'unfetched)
6791                                         gnus-newsgroup-unfetched)
6792                                        ((eq gnus-auto-goto-ignores
6793                                             'undownloaded)
6794                                         gnus-newsgroup-undownloaded)))
6795                           (when (gnus-data-unread-p (car data))
6796                             (setq result (car data)
6797                                   data nil)))
6798                         (setq data (cdr data)))
6799                       result)
6800                   (car data)))
6801       (goto-char (gnus-data-pos result))
6802       (gnus-data-number result))))
6803
6804 (defun gnus-summary-find-subject (subject &optional unread backward article)
6805   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6806          (article (or article (gnus-summary-article-number)))
6807          (articles (gnus-data-list backward))
6808          (arts (gnus-data-find-list article articles))
6809          result)
6810     (when (or (not gnus-summary-check-current)
6811               (not unread)
6812               (not (gnus-data-unread-p (car arts))))
6813       (setq arts (cdr arts)))
6814     (while arts
6815       (and (or (not unread)
6816                (gnus-data-unread-p (car arts)))
6817            (vectorp (gnus-data-header (car arts)))
6818            (gnus-subject-equal
6819             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6820            (setq result (car arts)
6821                  arts nil))
6822       (setq arts (cdr arts)))
6823     (and result
6824          (goto-char (gnus-data-pos result))
6825          (gnus-data-number result))))
6826
6827 (defun gnus-summary-search-forward (&optional unread subject backward)
6828   "Search forward for an article.
6829 If UNREAD, look for unread articles.  If SUBJECT, look for
6830 articles with that subject.  If BACKWARD, search backward instead."
6831   (cond (subject (gnus-summary-find-subject subject unread backward))
6832         (backward (gnus-summary-find-prev unread))
6833         (t (gnus-summary-find-next unread))))
6834
6835 (defun gnus-recenter (&optional n)
6836   "Center point in window and redisplay frame.
6837 Also do horizontal recentering."
6838   (interactive "P")
6839   (when (and gnus-auto-center-summary
6840              (not (eq gnus-auto-center-summary 'vertical)))
6841     (gnus-horizontal-recenter))
6842   (if (fboundp 'recenter-top-bottom)
6843       (recenter-top-bottom n)
6844     (recenter n)))
6845
6846 (put 'gnus-recenter 'isearch-scroll t)
6847
6848 (defun gnus-forward-line-ignore-invisible (n)
6849   "Move N lines forward (backward if N is negative).
6850 Like forward-line, but skip over (and don't count) invisible lines."
6851   (let (done)
6852     (while (and (> n 0) (not done))
6853       ;; If the following character is currently invisible,
6854       ;; skip all characters with that same `invisible' property value.
6855       (while (gnus-invisible-p (point))
6856         (goto-char (gnus-next-char-property-change (point))))
6857       (forward-line 1)
6858       (if (eobp)
6859           (setq done t)
6860         (setq n (1- n))))
6861     (while (and (< n 0) (not done))
6862       (forward-line -1)
6863       (if (bobp) (setq done t)
6864         (setq n (1+ n))
6865         (while (and (not (bobp)) (gnus-invisible-p (1- (point))))
6866           (goto-char (gnus-previous-char-property-change (point))))))))
6867
6868 (defun gnus-summary-recenter ()
6869   "Center point in the summary window.
6870 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6871 displayed, no centering will be performed."
6872   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6873   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6874   (interactive)
6875   ;; The user has to want it.
6876   (when gnus-auto-center-summary
6877     (let* ((top (cond ((< (window-height) 4) 0)
6878                       ((< (window-height) 7) 1)
6879                       (t (if (numberp gnus-auto-center-summary)
6880                              gnus-auto-center-summary
6881                            (/ (1- (window-height)) 2)))))
6882            (height (1- (window-height)))
6883            (bottom (save-excursion
6884                      (goto-char (point-max))
6885                      (gnus-forward-line-ignore-invisible (- height))
6886                      (point)))
6887            (window (get-buffer-window (current-buffer))))
6888       (when (get-buffer-window gnus-article-buffer)
6889         ;; Only do recentering when the article buffer is displayed,
6890         ;; Set the window start to either `bottom', which is the biggest
6891         ;; possible valid number, or the second line from the top,
6892         ;; whichever is the least.
6893         (let ((top-pos (save-excursion
6894                          (gnus-forward-line-ignore-invisible (- top))
6895                          (point))))
6896           (if (> bottom top-pos)
6897               ;; Keep the second line from the top visible
6898               (set-window-start window top-pos)
6899             ;; Try to keep the bottom line visible; if it's partially
6900             ;; obscured, either scroll one more line to make it fully
6901             ;; visible, or revert to using TOP-POS.
6902             (save-excursion
6903               (goto-char (point-max))
6904               (gnus-forward-line-ignore-invisible -1)
6905               (let ((last-line-start (point)))
6906                 (goto-char bottom)
6907                 (set-window-start window (point) t)
6908                 (when (not (pos-visible-in-window-p last-line-start window))
6909                   (gnus-forward-line-ignore-invisible 1)
6910                   (set-window-start window (min (point) top-pos) t)))))))
6911       ;; Do horizontal recentering while we're at it.
6912       (when (and (get-buffer-window (current-buffer) t)
6913                  (not (eq gnus-auto-center-summary 'vertical)))
6914         (let ((selected (selected-window)))
6915           (select-window (get-buffer-window (current-buffer) t))
6916           (gnus-summary-position-point)
6917           (gnus-horizontal-recenter)
6918           (select-window selected))))))
6919
6920 (defun gnus-summary-jump-to-group (newsgroup)
6921   "Move point to NEWSGROUP in group mode buffer."
6922   ;; Keep update point of group mode buffer if visible.
6923   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6924       (save-window-excursion
6925         ;; Take care of tree window mode.
6926         (when (get-buffer-window gnus-group-buffer)
6927           (pop-to-buffer gnus-group-buffer))
6928         (gnus-group-jump-to-group newsgroup))
6929     (save-excursion
6930       ;; Take care of tree window mode.
6931       (if (get-buffer-window gnus-group-buffer 0)
6932           (pop-to-buffer gnus-group-buffer)
6933         (set-buffer gnus-group-buffer))
6934       (gnus-group-jump-to-group newsgroup))))
6935
6936 ;; This function returns a list of article numbers based on the
6937 ;; difference between the ranges of read articles in this group and
6938 ;; the range of active articles.
6939 (defun gnus-list-of-unread-articles (group)
6940   (let* ((read (gnus-info-read (gnus-get-info group)))
6941          (active (or (gnus-active group) (gnus-activate-group group)))
6942          (last (or (cdr active)
6943                    (error "Group %s couldn't be activated " group)))
6944          (bottom (if gnus-newsgroup-maximum-articles
6945                      (max (car active)
6946                           (- last gnus-newsgroup-maximum-articles -1))
6947                    (car active)))
6948          first nlast unread)
6949     ;; If none are read, then all are unread.
6950     (if (not read)
6951         (setq first bottom)
6952       ;; If the range of read articles is a single range, then the
6953       ;; first unread article is the article after the last read
6954       ;; article.  Sounds logical, doesn't it?
6955       (if (and (not (listp (cdr read)))
6956                (or (< (car read) bottom)
6957                    (progn (setq read (list read))
6958                           nil)))
6959           (setq first (max bottom (1+ (cdr read))))
6960         ;; `read' is a list of ranges.
6961         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6962                                   (caar read)))
6963                   1)
6964           (setq first bottom))
6965         (while read
6966           (when first
6967             (while (< first nlast)
6968               (setq unread (cons first unread)
6969                     first (1+ first))))
6970           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6971           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6972           (setq read (cdr read)))))
6973     ;; And add the last unread articles.
6974     (while (<= first last)
6975       (setq unread (cons first unread)
6976             first (1+ first)))
6977     ;; Return the list of unread articles.
6978     (delq 0 (nreverse unread))))
6979
6980 (defun gnus-list-of-read-articles (group)
6981   "Return a list of unread, unticked and non-dormant articles."
6982   (let* ((info (gnus-get-info group))
6983          (marked (gnus-info-marks info))
6984          (active (gnus-active group)))
6985     (and info active
6986          (gnus-list-range-difference
6987           (gnus-list-range-difference
6988            (gnus-sorted-complement
6989             (gnus-uncompress-range
6990              (if gnus-newsgroup-maximum-articles
6991                  (cons (max (car active)
6992                             (- (cdr active)
6993                                gnus-newsgroup-maximum-articles
6994                                -1))
6995                        (cdr active))
6996                active))
6997             (gnus-list-of-unread-articles group))
6998            (cdr (assq 'dormant marked)))
6999           (cdr (assq 'tick marked))))))
7000
7001 ;; This function returns a sequence of article numbers based on the
7002 ;; difference between the ranges of read articles in this group and
7003 ;; the range of active articles.
7004 (defun gnus-sequence-of-unread-articles (group)
7005   (let* ((read (gnus-info-read (gnus-get-info group)))
7006          (active (or (gnus-active group) (gnus-activate-group group)))
7007          (last (cdr active))
7008          (bottom (if gnus-newsgroup-maximum-articles
7009                      (max (car active)
7010                           (- last gnus-newsgroup-maximum-articles -1))
7011                    (car active)))
7012          first nlast unread)
7013     ;; If none are read, then all are unread.
7014     (if (not read)
7015         (setq first bottom)
7016       ;; If the range of read articles is a single range, then the
7017       ;; first unread article is the article after the last read
7018       ;; article.  Sounds logical, doesn't it?
7019       (if (and (not (listp (cdr read)))
7020                (or (< (car read) bottom)
7021                    (progn (setq read (list read))
7022                           nil)))
7023           (setq first (max bottom (1+ (cdr read))))
7024         ;; `read' is a list of ranges.
7025         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
7026                                   (caar read)))
7027                   1)
7028           (setq first bottom))
7029         (while read
7030           (when first
7031             (push (cons first nlast) unread))
7032           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
7033           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
7034           (setq read (cdr read)))))
7035     ;; And add the last unread articles.
7036     (cond ((not (and first last))
7037            nil)
7038           ((< first last)
7039            (push (cons first last) unread))
7040           ((= first last)
7041            (push first unread)))
7042     ;; Return the sequence of unread articles.
7043     (delq 0 (nreverse unread))))
7044
7045 ;; Various summary commands
7046
7047 (defun gnus-summary-select-article-buffer ()
7048   "Reconfigure windows to show the article buffer.
7049 If `gnus-widen-article-window' is set, show only the article
7050 buffer."
7051   (interactive)
7052   (if (not (gnus-buffer-live-p gnus-article-buffer))
7053       (error "There is no article buffer for this summary buffer")
7054     (unless (get-buffer-window gnus-article-buffer)
7055       (gnus-summary-show-article))
7056     (gnus-configure-windows
7057      (if gnus-widen-article-window
7058          'only-article
7059        'article)
7060      t)
7061     (select-window (get-buffer-window gnus-article-buffer))))
7062
7063 (defun gnus-summary-universal-argument (arg)
7064   "Perform any operation on all articles that are process/prefixed."
7065   (interactive "P")
7066   (let ((articles (gnus-summary-work-articles arg))
7067         func article)
7068     (if (eq
7069          (setq
7070           func
7071           (key-binding
7072            (read-key-sequence
7073             (substitute-command-keys
7074              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
7075          'undefined)
7076         (gnus-error 1 "Undefined key")
7077       (save-excursion
7078         (while articles
7079           (gnus-summary-goto-subject (setq article (pop articles)))
7080           (let (gnus-newsgroup-processable)
7081             (command-execute func))
7082           (gnus-summary-remove-process-mark article)))))
7083   (gnus-summary-position-point))
7084
7085 (defun gnus-summary-toggle-truncation (&optional arg)
7086   "Toggle truncation of summary lines.
7087 With ARG, turn line truncation on if ARG is positive."
7088   (interactive "P")
7089   (setq truncate-lines
7090         (if (null arg) (not truncate-lines)
7091           (> (prefix-numeric-value arg) 0)))
7092   (redraw-display))
7093
7094 (defun gnus-summary-find-for-reselect ()
7095   "Return the number of an article to stay on across a reselect.
7096 The current article is considered, then following articles, then previous
7097 articles.  An article is sought which is not cancelled and isn't a temporary
7098 insertion from another group.  If there's no such then return a dummy 0."
7099   (let (found)
7100     (dolist (rev '(nil t))
7101       (unless found      ; don't demand the reverse list if we don't need it
7102         (let ((data (gnus-data-find-list
7103                      (gnus-summary-article-number) (gnus-data-list rev))))
7104           (while (and data (not found))
7105             (if (and (< 0 (gnus-data-number (car data)))
7106                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
7107                 (setq found (gnus-data-number (car data))))
7108             (setq data (cdr data))))))
7109     (or found 0)))
7110
7111 (defun gnus-summary-reselect-current-group (&optional all rescan)
7112   "Exit and then reselect the current newsgroup.
7113 The prefix argument ALL means to select all articles."
7114   (interactive "P")
7115   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
7116     (error "Ephemeral groups can't be reselected"))
7117   (let ((current-subject (gnus-summary-find-for-reselect))
7118         (group gnus-newsgroup-name))
7119     (setq gnus-newsgroup-begin nil)
7120     (gnus-summary-exit nil 'leave-hidden)
7121     ;; We have to adjust the point of group mode buffer because
7122     ;; point was moved to the next unread newsgroup by exiting.
7123     (gnus-summary-jump-to-group group)
7124     (when rescan
7125       (save-excursion
7126         (gnus-group-get-new-news-this-group 1)))
7127     (gnus-group-read-group all t)
7128     (gnus-summary-goto-subject current-subject nil t)))
7129
7130 (defun gnus-summary-rescan-group (&optional all)
7131   "Exit the newsgroup, ask for new articles, and select the newsgroup."
7132   (interactive "P")
7133   (let ((config gnus-current-window-configuration))
7134     (gnus-summary-reselect-current-group all t)
7135     (gnus-configure-windows config)
7136     (when (eq config 'article)
7137       (gnus-summary-select-article))))
7138
7139 (defun gnus-summary-update-info (&optional non-destructive)
7140   (save-excursion
7141     (let ((group gnus-newsgroup-name))
7142       (when group
7143         (when gnus-newsgroup-kill-headers
7144           (setq gnus-newsgroup-killed
7145                 (gnus-compress-sequence
7146                  (gnus-sorted-union
7147                   (gnus-list-range-intersection
7148                    gnus-newsgroup-unselected gnus-newsgroup-killed)
7149                   gnus-newsgroup-unreads)
7150                  t)))
7151         (unless (listp (cdr gnus-newsgroup-killed))
7152           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
7153         (let ((headers gnus-newsgroup-headers)
7154               (ephemeral-p (gnus-ephemeral-group-p group))
7155               info)
7156           (unless ephemeral-p
7157             (setq info (copy-sequence (gnus-get-info group))
7158                   info (delq (gnus-info-params info) info)))
7159           ;; Set the new ranges of read articles.
7160           (with-current-buffer gnus-group-buffer
7161             (gnus-undo-force-boundary))
7162           (gnus-update-read-articles
7163            group (gnus-sorted-union
7164                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
7165           ;; Set the current article marks.
7166           (let ((gnus-newsgroup-scored
7167                  (if (and (not gnus-save-score)
7168                           (not non-destructive))
7169                      nil
7170                    gnus-newsgroup-scored)))
7171             (save-excursion
7172               (gnus-update-marks)))
7173           ;; Do the cross-ref thing.
7174           (when gnus-use-cross-reference
7175             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
7176           ;; Do not switch windows but change the buffer to work.
7177           (set-buffer gnus-group-buffer)
7178           (unless ephemeral-p
7179             (gnus-group-update-group
7180              group nil
7181              (equal info
7182                     (setq info (copy-sequence (gnus-get-info group))
7183                           info (delq (gnus-info-params info) info))))))))))
7184
7185 (defun gnus-summary-save-newsrc (&optional force)
7186   "Save the current number of read/marked articles in the dribble buffer.
7187 The dribble buffer will then be saved.
7188 If FORCE (the prefix), also save the .newsrc file(s)."
7189   (interactive "P")
7190   (gnus-summary-update-info t)
7191   (if force
7192       (gnus-save-newsrc-file)
7193     (gnus-dribble-save)))
7194
7195 (declare-function gnus-cache-write-active "gnus-cache" (&optional force))
7196
7197 (defun gnus-summary-exit (&optional temporary leave-hidden)
7198   "Exit reading current newsgroup, and then return to group selection mode.
7199 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
7200   (interactive)
7201   (gnus-set-global-variables)
7202   (when (gnus-buffer-live-p gnus-article-buffer)
7203     (with-current-buffer gnus-article-buffer
7204       (mm-destroy-parts gnus-article-mime-handles)
7205       ;; Set it to nil for safety reason.
7206       (setq gnus-article-mime-handle-alist nil)
7207       (setq gnus-article-mime-handles nil)))
7208   (gnus-kill-save-kill-buffer)
7209   (gnus-async-halt-prefetch)
7210   (let* ((group gnus-newsgroup-name)
7211          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
7212          (gnus-group-is-exiting-p t)
7213          (article-buffer gnus-article-buffer)
7214          (mode major-mode)
7215          (group-point nil)
7216          (buf (current-buffer))
7217          ;; `gnus-single-article-buffer' is nil buffer-locally in
7218          ;; ephemeral group of which summary buffer will be killed,
7219          ;; but the global value may be non-nil.
7220          (single-article-buffer gnus-single-article-buffer))
7221     (unless quit-config
7222       ;; Do adaptive scoring, and possibly save score files.
7223       (when gnus-newsgroup-adaptive
7224         (gnus-score-adaptive))
7225       (when gnus-use-scoring
7226         (gnus-score-save)))
7227     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
7228     (when gnus-use-cache
7229       (gnus-cache-possibly-remove-articles)
7230       (gnus-cache-save-buffers))
7231     (gnus-async-prefetch-remove-group group)
7232     (when gnus-suppress-duplicates
7233       (gnus-dup-enter-articles))
7234     (when gnus-use-trees
7235       (gnus-tree-close group))
7236     (when gnus-use-cache
7237       (gnus-cache-write-active))
7238     ;; Remove entries for this group.
7239     (nnmail-purge-split-history (gnus-group-real-name group))
7240     ;; Make all changes in this group permanent.
7241     (unless quit-config
7242       (gnus-run-hooks 'gnus-exit-group-hook)
7243       (gnus-summary-update-info))
7244     (gnus-close-group group)
7245     ;; Make sure where we were, and go to next newsgroup.
7246     (set-buffer gnus-group-buffer)
7247     (unless quit-config
7248       (gnus-group-jump-to-group group))
7249     (gnus-run-hooks 'gnus-summary-exit-hook)
7250     (unless (or quit-config
7251                 (not gnus-summary-next-group-on-exit)
7252                 ;; If this group has disappeared from the summary
7253                 ;; buffer, don't skip forwards.
7254                 (not (string= group (gnus-group-group-name))))
7255       (gnus-group-next-unread-group 1))
7256     (setq group-point (point))
7257     (if temporary
7258         nil                             ;Nothing to do.
7259       (set-buffer buf)
7260       (if (not gnus-kill-summary-on-exit)
7261           (progn
7262             (gnus-deaden-summary)
7263             (setq mode nil))
7264         (when (get-buffer gnus-article-buffer)
7265           (bury-buffer gnus-article-buffer))
7266         ;; Return to group mode buffer.
7267         (when (eq mode 'gnus-summary-mode)
7268           (gnus-kill-buffer buf)))
7269
7270       (setq gnus-current-select-method gnus-select-method)
7271       (set-buffer gnus-group-buffer)
7272       (if quit-config
7273           (gnus-handle-ephemeral-exit quit-config)
7274         (goto-char group-point)
7275         ;; If gnus-group-buffer is already displayed, make sure we also move
7276         ;; the cursor in the window that displays it.
7277         (let ((win (get-buffer-window (current-buffer) 0)))
7278           (if win (set-window-point win (point))))
7279         (unless leave-hidden
7280           (gnus-configure-windows 'group 'force)))
7281
7282       ;; If we have several article buffers, we kill them at exit.
7283       (unless single-article-buffer
7284         (when (gnus-buffer-live-p article-buffer)
7285           (with-current-buffer article-buffer
7286             ;; Don't kill sticky article buffers
7287             (unless (eq major-mode 'gnus-sticky-article-mode)
7288               (gnus-kill-buffer article-buffer)
7289               (setq gnus-article-current nil))))
7290         (gnus-kill-buffer gnus-original-article-buffer))
7291
7292       ;; Clear the current group name.
7293       (unless quit-config
7294         (setq gnus-newsgroup-name nil)))))
7295
7296 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7297 (defun gnus-summary-exit-no-update (&optional no-questions)
7298   "Quit reading current newsgroup without updating read article info."
7299   (interactive)
7300   (let* ((group gnus-newsgroup-name)
7301          (gnus-group-is-exiting-p t)
7302          (gnus-group-is-exiting-without-update-p t)
7303          (quit-config (gnus-group-quit-config group)))
7304     (when (or no-questions
7305               gnus-expert-user
7306               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7307       (gnus-async-halt-prefetch)
7308       (run-hooks 'gnus-summary-prepare-exit-hook)
7309       (when (gnus-buffer-live-p gnus-article-buffer)
7310         (with-current-buffer gnus-article-buffer
7311           (gnus-article-stop-animations)
7312           (mm-destroy-parts gnus-article-mime-handles)
7313           ;; Set it to nil for safety reason.
7314           (setq gnus-article-mime-handle-alist nil)
7315           (setq gnus-article-mime-handles nil)))
7316       ;; If we have several article buffers, we kill them at exit.
7317       (unless gnus-single-article-buffer
7318         (gnus-kill-buffer gnus-article-buffer)
7319         (gnus-kill-buffer gnus-original-article-buffer)
7320         (setq gnus-article-current nil))
7321       ;; Return to the group buffer.
7322       (gnus-configure-windows 'group 'force)
7323       (if (not gnus-kill-summary-on-exit)
7324           (gnus-deaden-summary)
7325         (gnus-close-group group)
7326         (gnus-kill-buffer gnus-summary-buffer))
7327       (unless gnus-single-article-buffer
7328         (setq gnus-article-current nil))
7329       (when gnus-use-trees
7330         (gnus-tree-close group))
7331       (gnus-async-prefetch-remove-group group)
7332       (when (get-buffer gnus-article-buffer)
7333         (bury-buffer gnus-article-buffer))
7334       ;; Clear the current group name.
7335       (setq gnus-newsgroup-name nil)
7336       (unless (gnus-ephemeral-group-p group)
7337         (gnus-group-update-group group nil t))
7338       (when (equal (gnus-group-group-name) group)
7339         (gnus-group-next-unread-group 1))
7340       (when quit-config
7341         (gnus-handle-ephemeral-exit quit-config)))))
7342
7343 (defun gnus-handle-ephemeral-exit (quit-config)
7344   "Handle movement when leaving an ephemeral group.
7345 The state which existed when entering the ephemeral is reset."
7346   (if (not (buffer-name (car quit-config)))
7347       (gnus-configure-windows 'group 'force)
7348     (set-buffer (car quit-config))
7349     (unless (eq (cdr quit-config) 'group)
7350       (setq gnus-current-select-method
7351             (gnus-find-method-for-group gnus-newsgroup-name)))
7352     (cond ((eq major-mode 'gnus-summary-mode)
7353            (gnus-set-global-variables))
7354           ((eq major-mode 'gnus-article-mode)
7355            (save-current-buffer
7356              ;; The `gnus-summary-buffer' variable may point
7357              ;; to the old summary buffer when using a single
7358              ;; article buffer.
7359              (unless (gnus-buffer-live-p gnus-summary-buffer)
7360                (set-buffer gnus-group-buffer))
7361              (set-buffer gnus-summary-buffer)
7362              (gnus-set-global-variables))))
7363     (if (or (eq (cdr quit-config) 'article)
7364             (eq (cdr quit-config) 'pick))
7365         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7366             (gnus-configure-windows 'pick 'force)
7367           (gnus-configure-windows (cdr quit-config) 'force))
7368       (gnus-configure-windows (cdr quit-config) 'force))
7369     (when (eq major-mode 'gnus-summary-mode)
7370       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7371                                                      next-unread-noselect))
7372           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7373                                   'next-noselect)
7374                               (gnus-summary-next-subject 1 nil t))
7375                              ((eq gnus-auto-select-on-ephemeral-exit
7376                                   'next-unread-noselect)
7377                               (gnus-summary-next-subject 1 t t))))
7378             ;; Hide the article buffer which displays the article different
7379             ;; from the one that the cursor points to in the summary buffer.
7380             (gnus-configure-windows 'summary 'force))
7381         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7382                (gnus-summary-next-subject 1))
7383               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7384                (gnus-summary-next-subject 1 t))))
7385       (gnus-summary-recenter)
7386       (gnus-summary-position-point))))
7387
7388 ;;; Dead summaries.
7389
7390 (defvar gnus-dead-summary-mode-map
7391   (let ((map (make-keymap)))
7392     (suppress-keymap map)
7393     (substitute-key-definition 'undefined 'gnus-summary-wake-up-the-dead map)
7394     (dolist (key '("\C-d" "\r" "\177" [delete]))
7395       (define-key map key 'gnus-summary-wake-up-the-dead))
7396     (dolist (key '("q" "Q"))
7397       (define-key map key 'bury-buffer))
7398     map))
7399
7400 (define-minor-mode gnus-dead-summary-mode
7401   "Minor mode for Gnus summary buffers."
7402   :lighter " Dead" :keymap gnus-dead-summary-mode-map
7403   (unless (derived-mode-p 'gnus-summary-mode)
7404     (setq gnus-dead-summary-mode nil)))
7405
7406 (defun gnus-deaden-summary ()
7407   "Make the current summary buffer into a dead summary buffer."
7408   ;; Kill any previous dead summary buffer.
7409   (when (and gnus-dead-summary
7410              (buffer-name gnus-dead-summary))
7411     (with-current-buffer gnus-dead-summary
7412       (when gnus-dead-summary-mode
7413         (kill-buffer (current-buffer)))))
7414   ;; Make this the current dead summary.
7415   (setq gnus-dead-summary (current-buffer))
7416   (gnus-dead-summary-mode 1)
7417   (let ((name (buffer-name)))
7418     (when (string-match "Summary" name)
7419       (rename-buffer
7420        (concat (substring name 0 (match-beginning 0)) "Dead "
7421                (substring name (match-beginning 0)))
7422        t)
7423       (bury-buffer))))
7424
7425 (defun gnus-kill-or-deaden-summary (buffer)
7426   "Kill or deaden the summary BUFFER."
7427   (save-excursion
7428     (when (and (buffer-name buffer)
7429                (not gnus-single-article-buffer))
7430       (with-current-buffer buffer
7431         (gnus-kill-buffer gnus-article-buffer)
7432         (gnus-kill-buffer gnus-original-article-buffer)))
7433     (cond
7434      ;; Kill the buffer.
7435      (gnus-kill-summary-on-exit
7436       (when (and gnus-use-trees
7437                  (gnus-buffer-exists-p buffer))
7438         (with-current-buffer buffer
7439           (gnus-tree-close gnus-newsgroup-name)))
7440       (gnus-kill-buffer buffer))
7441      ;; Deaden the buffer.
7442      ((gnus-buffer-exists-p buffer)
7443       (with-current-buffer buffer
7444         (gnus-deaden-summary))))))
7445
7446 (defun gnus-summary-wake-up-the-dead (&rest args)
7447   "Wake up the dead summary buffer."
7448   (interactive)
7449   (gnus-dead-summary-mode -1)
7450   (let ((name (buffer-name)))
7451     (when (string-match "Dead " name)
7452       (rename-buffer
7453        (concat (substring name 0 (match-beginning 0))
7454                (substring name (match-end 0)))
7455        t)))
7456   (gnus-message 3 "This dead summary is now alive again"))
7457
7458 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7459 (defun gnus-summary-describe-group (&optional force)
7460   "Describe the current newsgroup."
7461   (interactive "P")
7462   (gnus-group-describe-group force gnus-newsgroup-name))
7463
7464 (defun gnus-summary-describe-briefly ()
7465   "Describe summary mode commands briefly."
7466   (interactive)
7467   (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")))
7468
7469 ;; Walking around group mode buffer from summary mode.
7470
7471 (defun gnus-summary-next-group (&optional no-article target-group backward)
7472   "Exit current newsgroup and then select next unread newsgroup.
7473 If prefix argument NO-ARTICLE is non-nil, no article is selected
7474 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7475 previous group instead."
7476   (interactive "P")
7477   ;; Stop pre-fetching.
7478   (gnus-async-halt-prefetch)
7479   (let ((current-group gnus-newsgroup-name)
7480         (current-buffer (current-buffer))
7481         entered)
7482     ;; First we semi-exit this group to update Xrefs and all variables.
7483     ;; We can't do a real exit, because the window conf must remain
7484     ;; the same in case the user is prompted for info, and we don't
7485     ;; want the window conf to change before that...
7486     (gnus-summary-exit t)
7487     (while (not entered)
7488       ;; Then we find what group we are supposed to enter.
7489       (set-buffer gnus-group-buffer)
7490       (gnus-group-jump-to-group current-group)
7491       (setq target-group
7492             (or target-group
7493                 (if (eq gnus-keep-same-level 'best)
7494                     (gnus-summary-best-group gnus-newsgroup-name)
7495                   (gnus-summary-search-group backward gnus-keep-same-level))))
7496       (if (not target-group)
7497           ;; There are no further groups, so we return to the group
7498           ;; buffer.
7499           (progn
7500             (gnus-message 5 "Returning to the group buffer")
7501             (setq entered t)
7502             (when (gnus-buffer-live-p current-buffer)
7503               (set-buffer current-buffer)
7504               (gnus-summary-exit))
7505             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7506         ;; We try to enter the target group.
7507         (gnus-group-jump-to-group target-group)
7508         (let ((unreads (gnus-group-group-unread)))
7509           (if (and (or (eq t unreads)
7510                        (and unreads (not (zerop unreads))))
7511                    (gnus-summary-read-group
7512                     target-group nil no-article
7513                     (and (buffer-name current-buffer) current-buffer)
7514                     nil backward))
7515               (setq entered t)
7516             (setq current-group target-group
7517                   target-group nil)))))))
7518
7519 (defun gnus-summary-prev-group (&optional no-article)
7520   "Exit current newsgroup and then select previous unread newsgroup.
7521 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7522   (interactive "P")
7523   (gnus-summary-next-group no-article nil t))
7524
7525 ;; Walking around summary lines.
7526
7527 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7528   "Go to the first subject satisfying any non-nil constraint.
7529 If UNREAD is non-nil, the article should be unread.
7530 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7531 If UNSEEN is non-nil, the article should be unseen as well as unread.
7532 Returns the article selected or nil if there are no matching articles."
7533   (interactive "P")
7534   (cond
7535    ;; Empty summary.
7536    ((null gnus-newsgroup-data)
7537     (gnus-message 3 "No articles in the group")
7538     nil)
7539    ;; Pick the first article.
7540    ((not (or unread undownloaded unseen))
7541     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7542     (gnus-data-number (car gnus-newsgroup-data)))
7543    ;; Find the first unread article.
7544    (t
7545     (let ((data gnus-newsgroup-data))
7546       (while (and data
7547                   (let ((num (gnus-data-number (car data))))
7548                     (or (memq num gnus-newsgroup-unfetched)
7549                         (not (or (and unread
7550                                       (memq num gnus-newsgroup-unreads))
7551                                  (and undownloaded
7552                                       (memq num gnus-newsgroup-undownloaded))
7553                                  (and unseen
7554                                       (memq num gnus-newsgroup-unseen)
7555                                       (memq num gnus-newsgroup-unreads)))))))
7556         (setq data (cdr data)))
7557       (prog1
7558           (if data
7559               (progn
7560                 (goto-char (gnus-data-pos (car data)))
7561                 (gnus-data-number (car data)))
7562             (gnus-message 3 "No more%s articles"
7563                           (let* ((r (when unread " unread"))
7564                                  (d (when undownloaded " undownloaded"))
7565                                  (s (when unseen " unseen"))
7566                                  (l (delq nil (list r d s))))
7567                             (cond ((= 3 (length l))
7568                                    (concat r "," d ", or" s))
7569                                   ((= 2 (length l))
7570                                    (concat (car l) ", or" (cadr l)))
7571                                   ((= 1 (length l))
7572                                    (car l))
7573                                   (t
7574                                    ""))))
7575             nil
7576             )
7577         (gnus-summary-position-point))))))
7578
7579 (defun gnus-summary-next-subject (n &optional unread dont-display)
7580   "Go to next N'th summary line.
7581 If N is negative, go to the previous N'th subject line.
7582 If UNREAD is non-nil, only unread articles are selected.
7583 The difference between N and the actual number of steps taken is
7584 returned."
7585   (interactive "p")
7586   (let ((backward (< n 0))
7587         (n (abs n)))
7588     (while (and (> n 0)
7589                 (if backward
7590                     (gnus-summary-find-prev unread)
7591                   (gnus-summary-find-next unread)))
7592       (unless (zerop (setq n (1- n)))
7593         (gnus-summary-show-thread)))
7594     (when (/= 0 n)
7595       (gnus-message 7 "No more%s articles"
7596                     (if unread " unread" "")))
7597     (unless dont-display
7598       (gnus-summary-recenter)
7599       (gnus-summary-position-point))
7600     n))
7601
7602 (defun gnus-summary-next-unread-subject (n)
7603   "Go to next N'th unread summary line."
7604   (interactive "p")
7605   (gnus-summary-next-subject n t))
7606
7607 (defun gnus-summary-prev-subject (n &optional unread)
7608   "Go to previous N'th summary line.
7609 If optional argument UNREAD is non-nil, only unread article is selected."
7610   (interactive "p")
7611   (gnus-summary-next-subject (- n) unread))
7612
7613 (defun gnus-summary-prev-unread-subject (n)
7614   "Go to previous N'th unread summary line."
7615   (interactive "p")
7616   (gnus-summary-next-subject (- n) t))
7617
7618 (defun gnus-summary-goto-subjects (articles)
7619   "Insert the subject header for ARTICLES in the current buffer."
7620   (save-excursion
7621     (dolist (article articles)
7622       (gnus-summary-goto-subject article t)))
7623   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7624   (gnus-summary-position-point))
7625
7626 (defun gnus-summary-goto-subject (article &optional force silent)
7627   "Go to the subject line of ARTICLE.
7628 If FORCE, also allow jumping to articles not currently shown."
7629   (interactive "nArticle number: ")
7630   (unless (numberp article)
7631     (error "Article %s is not a number" article))
7632   (let ((b (point))
7633         (data (gnus-data-find article)))
7634     ;; We read in the article if we have to.
7635     (and (not data)
7636          force
7637          (gnus-summary-insert-subject
7638           article
7639           (if (or (numberp force) (vectorp force)) force)
7640           t)
7641          (setq data (gnus-data-find article)))
7642     (goto-char b)
7643     (if (not data)
7644         (progn
7645           (unless silent
7646             (gnus-message 3 "Can't find article %d" article))
7647           nil)
7648       (let ((pt (gnus-data-pos data)))
7649         (goto-char pt)
7650         (gnus-summary-set-article-display-arrow pt))
7651       (gnus-summary-position-point)
7652       article)))
7653
7654 ;; Walking around summary lines with displaying articles.
7655
7656 (defun gnus-summary-expand-window (&optional arg)
7657   "Make the summary buffer take up the entire Emacs frame.
7658 Given a prefix, will force an `article' buffer configuration."
7659   (interactive "P")
7660   (if arg
7661       (gnus-configure-windows 'article 'force)
7662     (gnus-configure-windows 'summary 'force)))
7663
7664 (defun gnus-summary-display-article (article &optional all-header)
7665   "Display ARTICLE in article buffer."
7666   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7667                (with-current-buffer gnus-article-buffer
7668                  (eq major-mode 'gnus-article-mode)))
7669     (gnus-article-setup-buffer))
7670   (gnus-set-global-variables)
7671   (with-current-buffer gnus-article-buffer
7672     (setq gnus-article-charset gnus-newsgroup-charset)
7673     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7674     (mm-enable-multibyte))
7675   (if (null article)
7676       nil
7677     (prog1
7678         (if gnus-summary-display-article-function
7679             (funcall gnus-summary-display-article-function article all-header)
7680           (gnus-article-prepare article all-header))
7681       (gnus-run-hooks 'gnus-select-article-hook)
7682       (when (and gnus-current-article
7683                  (not (zerop gnus-current-article)))
7684         (gnus-summary-goto-subject gnus-current-article))
7685       (gnus-summary-recenter)
7686       (when (and gnus-use-trees gnus-show-threads)
7687         (gnus-possibly-generate-tree article)
7688         (gnus-highlight-selected-tree article))
7689       ;; Successfully display article.
7690       (gnus-article-set-window-start
7691        (cdr (assq article gnus-newsgroup-bookmarks))))))
7692
7693 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7694   "Select the current article.
7695 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7696 non-nil, the article will be re-fetched even if it already present in
7697 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7698 be displayed."
7699   ;; Make sure we are in the summary buffer to work around bbdb bug.
7700   (unless (eq major-mode 'gnus-summary-mode)
7701     (set-buffer gnus-summary-buffer))
7702   (let ((article (or article (gnus-summary-article-number)))
7703         (all-headers (not (not all-headers))) ;Must be t or nil.
7704         gnus-summary-display-article-function)
7705     (and (not pseudo)
7706          (gnus-summary-article-pseudo-p article)
7707          (error "This is a pseudo-article"))
7708     (with-current-buffer gnus-summary-buffer
7709       (if (or (and gnus-single-article-buffer
7710                    (or (null gnus-current-article)
7711                        (null gnus-article-current)
7712                        (null (get-buffer gnus-article-buffer))
7713                        (not (eq article (cdr gnus-article-current)))
7714                        (not (equal (car gnus-article-current)
7715                                    gnus-newsgroup-name))
7716                        (not (get-buffer gnus-original-article-buffer))))
7717               (and (not gnus-single-article-buffer)
7718                    (or (null gnus-current-article)
7719                        (not (get-buffer gnus-original-article-buffer))
7720                        (not (eq gnus-current-article article))))
7721               force)
7722           ;; The requested article is different from the current article.
7723           (progn
7724             (gnus-summary-display-article article all-headers)
7725             (when (gnus-buffer-live-p gnus-article-buffer)
7726               (with-current-buffer gnus-article-buffer
7727                 (if (not gnus-article-decoded-p) ;; a local variable
7728                     (mm-disable-multibyte))))
7729             (gnus-article-set-window-start
7730              (cdr (assq article gnus-newsgroup-bookmarks)))
7731             article)
7732         'old))))
7733
7734 (defun gnus-summary-force-verify-and-decrypt ()
7735   "Display buttons for signed/encrypted parts and verify/decrypt them."
7736   (interactive)
7737   (let ((mm-verify-option 'known)
7738         (mm-decrypt-option 'known)
7739         (gnus-article-emulate-mime t)
7740         (gnus-buttonized-mime-types (append (list "multipart/signed"
7741                                                   "multipart/encrypted")
7742                                             gnus-buttonized-mime-types)))
7743     (gnus-summary-select-article nil 'force)))
7744
7745 (defun gnus-summary-set-current-mark (&optional current-mark)
7746   "Obsolete function."
7747   nil)
7748
7749 (defun gnus-summary-next-article (&optional unread subject backward push)
7750   "Select the next article.
7751 If UNREAD, only unread articles are selected.
7752 If SUBJECT, only articles with SUBJECT are selected.
7753 If BACKWARD, the previous article is selected instead of the next."
7754   (interactive "P")
7755   ;; Make sure we are in the summary buffer.
7756   (unless (eq major-mode 'gnus-summary-mode)
7757     (set-buffer gnus-summary-buffer))
7758   (cond
7759    ;; Is there such an article?
7760    ((and (gnus-summary-search-forward unread subject backward)
7761          (or (gnus-summary-display-article (gnus-summary-article-number))
7762              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7763     (gnus-summary-position-point))
7764    ;; If not, we try the first unread, if that is wanted.
7765    ((and subject
7766          gnus-auto-select-same
7767          (gnus-summary-first-unread-article))
7768     (gnus-summary-position-point)
7769     (gnus-message 6 "Wrapped"))
7770    ;; Try to get next/previous article not displayed in this group.
7771    ((and gnus-auto-extend-newsgroup
7772          (not unread) (not subject))
7773     (gnus-summary-goto-article
7774      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7775      nil (count-lines (point-min) (point))))
7776    ;; Go to next/previous group.
7777    (t
7778     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7779       (gnus-summary-jump-to-group gnus-newsgroup-name))
7780     (let ((cmd (if (featurep 'xemacs)
7781                    last-command-char
7782                  last-command-event))
7783           (point
7784            (with-current-buffer gnus-group-buffer
7785              (point)))
7786           (current-summary (current-buffer))
7787           (group
7788            (if (eq gnus-keep-same-level 'best)
7789                (gnus-summary-best-group gnus-newsgroup-name)
7790              (gnus-summary-search-group backward gnus-keep-same-level))))
7791       ;; Select next unread newsgroup automagically.
7792       (cond
7793        ((or (not gnus-auto-select-next)
7794             (not cmd))
7795         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7796        ((or (eq gnus-auto-select-next 'quietly)
7797             (and (eq gnus-auto-select-next 'slightly-quietly)
7798                  push)
7799             (and (eq gnus-auto-select-next 'almost-quietly)
7800                  (gnus-summary-last-article-p)))
7801         ;; Select quietly.
7802         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7803             (gnus-summary-exit)
7804           (gnus-message 7 "No more%s articles (%s)..."
7805                         (if unread " unread" "")
7806                         (if group (concat "selecting " group)
7807                           "exiting"))
7808           (gnus-summary-next-group nil group backward)))
7809        (t
7810         (when (gnus-key-press-event-p last-input-event)
7811           ;; Somehow or other, we may now have selected a different
7812           ;; window.  Make point go back to the summary buffer.
7813           (when (eq current-summary (current-buffer))
7814             ;; FIXME: This burps when get-buffer-window returns nil.
7815             (select-window (get-buffer-window current-summary 0)))
7816           (gnus-summary-walk-group-buffer
7817            gnus-newsgroup-name cmd unread backward point))))))))
7818
7819 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7820   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7821                       (?\C-p (gnus-group-prev-unread-group 1))))
7822         (cursor-in-echo-area t)
7823         keve key group ended prompt)
7824     (with-current-buffer gnus-group-buffer
7825       (goto-char start)
7826       (setq group
7827             (if (eq gnus-keep-same-level 'best)
7828                 (gnus-summary-best-group gnus-newsgroup-name)
7829               (gnus-summary-search-group backward gnus-keep-same-level))))
7830     (while (not ended)
7831       (setq prompt
7832             (format
7833              "No more%s articles%s " (if unread " unread" "")
7834              (if (and group
7835                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7836                  (format " (Type %s for %s [%s])"
7837                          (single-key-description cmd)
7838                          (gnus-group-decoded-name group)
7839                          (gnus-group-unread group))
7840                (format " (Type %s to exit %s)"
7841                        (single-key-description cmd)
7842                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7843       ;; Confirm auto selection.
7844       (setq key (car (setq keve (gnus-read-event-char prompt)))
7845             ended t)
7846       (cond
7847        ((assq key keystrokes)
7848         (let ((obuf (current-buffer)))
7849           (switch-to-buffer gnus-group-buffer)
7850           (when group
7851             (gnus-group-jump-to-group group))
7852           (eval (cadr (assq key keystrokes)))
7853           (setq group (gnus-group-group-name))
7854           (switch-to-buffer obuf))
7855         (setq ended nil))
7856        ((equal key cmd)
7857         (if (or (not group)
7858                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7859             (gnus-summary-exit)
7860           (gnus-summary-next-group nil group backward)))
7861        (t
7862         (push (cdr keve) unread-command-events))))))
7863
7864 (defun gnus-summary-next-unread-article ()
7865   "Select unread article after current one."
7866   (interactive)
7867   (gnus-summary-next-article
7868    (or (not (eq gnus-summary-goto-unread 'never))
7869        (gnus-summary-last-article-p (gnus-summary-article-number)))
7870    (and gnus-auto-select-same
7871         (gnus-summary-article-subject))))
7872
7873 (defun gnus-summary-prev-article (&optional unread subject)
7874   "Select the article before the current one.
7875 If UNREAD is non-nil, only unread articles are selected."
7876   (interactive "P")
7877   (gnus-summary-next-article unread subject t))
7878
7879 (defun gnus-summary-prev-unread-article ()
7880   "Select unread article before current one."
7881   (interactive)
7882   (gnus-summary-prev-article
7883    (or (not (eq gnus-summary-goto-unread 'never))
7884        (gnus-summary-first-article-p (gnus-summary-article-number)))
7885    (and gnus-auto-select-same
7886         (gnus-summary-article-subject))))
7887
7888 (defun gnus-summary-next-page (&optional lines circular stop)
7889   "Show next page of the selected article.
7890 If at the end of the current article, select the next article.
7891 LINES says how many lines should be scrolled up.
7892
7893 If CIRCULAR is non-nil, go to the start of the article instead of
7894 selecting the next article when reaching the end of the current
7895 article.
7896
7897 If STOP is non-nil, just stop when reaching the end of the message.
7898
7899 Also see the variable `gnus-article-skip-boring'."
7900   (interactive "P")
7901   (setq gnus-summary-buffer (current-buffer))
7902   (gnus-set-global-variables)
7903   (let ((article (gnus-summary-article-number))
7904         (article-window (get-buffer-window gnus-article-buffer t))
7905         endp)
7906     ;; If the buffer is empty, we have no article.
7907     (unless article
7908       (error "No article to select"))
7909     (gnus-configure-windows 'article)
7910     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7911         (if (and (eq gnus-summary-goto-unread 'never)
7912                  (not (gnus-summary-last-article-p article)))
7913             (gnus-summary-next-article)
7914           (gnus-summary-next-unread-article))
7915       (if (or (null gnus-current-article)
7916               (null gnus-article-current)
7917               (/= article (cdr gnus-article-current))
7918               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7919           ;; Selected subject is different from current article's.
7920           (gnus-summary-display-article article)
7921         (when article-window
7922           (gnus-eval-in-buffer-window gnus-article-buffer
7923             (setq endp (or (gnus-article-next-page lines)
7924                            (gnus-article-only-boring-p))))
7925           (when endp
7926             (cond ((or stop gnus-summary-stop-at-end-of-message)
7927                    (gnus-message 3 "End of message"))
7928                   (circular
7929                    (gnus-summary-beginning-of-article))
7930                   (lines
7931                    (gnus-message 3 "End of message"))
7932                   ((null lines)
7933                    (if (and (eq gnus-summary-goto-unread 'never)
7934                             (not (gnus-summary-last-article-p article)))
7935                        (gnus-summary-next-article)
7936                      (gnus-summary-next-unread-article))))))))
7937     (gnus-summary-recenter)
7938     (gnus-summary-position-point)))
7939
7940 (defun gnus-summary-prev-page (&optional lines move)
7941   "Show previous page of selected article.
7942 Argument LINES specifies lines to be scrolled down.
7943 If MOVE, move to the previous unread article if point is at
7944 the beginning of the buffer."
7945   (interactive "P")
7946   (let ((article (gnus-summary-article-number))
7947         (article-window (get-buffer-window gnus-article-buffer t))
7948         endp)
7949     (gnus-configure-windows 'article)
7950     (if (or (null gnus-current-article)
7951             (null gnus-article-current)
7952             (/= article (cdr gnus-article-current))
7953             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7954         ;; Selected subject is different from current article's.
7955         (gnus-summary-display-article article)
7956       (gnus-summary-recenter)
7957       (when article-window
7958         (gnus-eval-in-buffer-window gnus-article-buffer
7959           (setq endp (gnus-article-prev-page lines)))
7960         (when (and move endp)
7961           (cond (lines
7962                  (gnus-message 3 "Beginning of message"))
7963                 ((null lines)
7964                  (if (and (eq gnus-summary-goto-unread 'never)
7965                           (not (gnus-summary-first-article-p article)))
7966                      (gnus-summary-prev-article)
7967                    (gnus-summary-prev-unread-article))))))))
7968   (gnus-summary-position-point))
7969
7970 (defun gnus-summary-prev-page-or-article (&optional lines)
7971   "Show previous page of selected article.
7972 Argument LINES specifies lines to be scrolled down.
7973 If at the beginning of the article, go to the next article."
7974   (interactive "P")
7975   (gnus-summary-prev-page lines t))
7976
7977 (defun gnus-summary-scroll-up (lines)
7978   "Scroll up (or down) one line current article.
7979 Argument LINES specifies lines to be scrolled up (or down if negative).
7980 If no article is selected, then the current article will be selected first."
7981   (interactive "p")
7982   (gnus-configure-windows 'article)
7983   (gnus-summary-show-thread)
7984   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7985     (gnus-eval-in-buffer-window gnus-article-buffer
7986       (cond ((> lines 0)
7987              (when (gnus-article-next-page lines)
7988                (gnus-message 3 "End of message")))
7989             ((< lines 0)
7990              (gnus-article-prev-page (- lines))))))
7991   (gnus-summary-recenter)
7992   (gnus-summary-position-point))
7993
7994 (defun gnus-summary-scroll-down (lines)
7995   "Scroll down (or up) one line current article.
7996 Argument LINES specifies lines to be scrolled down (or up if negative).
7997 If no article is selected, then the current article will be selected first."
7998   (interactive "p")
7999   (gnus-summary-scroll-up (- lines)))
8000
8001 (defun gnus-summary-next-same-subject ()
8002   "Select next article which has the same subject as current one."
8003   (interactive)
8004   (gnus-summary-next-article nil (gnus-summary-article-subject)))
8005
8006 (defun gnus-summary-prev-same-subject ()
8007   "Select previous article which has the same subject as current one."
8008   (interactive)
8009   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
8010
8011 (defun gnus-summary-next-unread-same-subject ()
8012   "Select next unread article which has the same subject as current one."
8013   (interactive)
8014   (gnus-summary-next-article t (gnus-summary-article-subject)))
8015
8016 (defun gnus-summary-prev-unread-same-subject ()
8017   "Select previous unread article which has the same subject as current one."
8018   (interactive)
8019   (gnus-summary-prev-article t (gnus-summary-article-subject)))
8020
8021 (defun gnus-summary-first-unread-article ()
8022   "Select the first unread article.
8023 Return nil if there are no unread articles."
8024   (interactive)
8025   (prog1
8026       (when (gnus-summary-first-subject t)
8027         (gnus-summary-show-thread)
8028         (gnus-summary-first-subject t)
8029         (gnus-summary-display-article (gnus-summary-article-number)))
8030     (gnus-summary-position-point)))
8031
8032 (defun gnus-summary-first-unread-subject ()
8033   "Place the point on the subject line of the first unread article.
8034 Return nil if there are no unread articles."
8035   (interactive)
8036   (prog1
8037       (when (gnus-summary-first-subject t)
8038         (gnus-summary-show-thread)
8039         (gnus-summary-first-subject t))
8040     (gnus-summary-position-point)))
8041
8042 (defun gnus-summary-first-unseen-subject ()
8043   "Place the point on the subject line of the first unseen article.
8044 Return nil if there are no unseen articles."
8045   (interactive)
8046   (prog1
8047       (when (gnus-summary-first-subject nil nil t)
8048         (gnus-summary-show-thread)
8049         (gnus-summary-first-subject nil nil t))
8050     (gnus-summary-position-point)))
8051
8052 (defun gnus-summary-first-unseen-or-unread-subject ()
8053   "Place the point on the subject line of the first unseen and unread article.
8054 If all article have been seen, on the subject line of the first unread
8055 article."
8056   (interactive)
8057   (prog1
8058       (unless (when (gnus-summary-first-subject nil nil t)
8059                 (gnus-summary-show-thread)
8060                 (gnus-summary-first-subject nil nil t))
8061         (when (gnus-summary-first-subject t)
8062           (gnus-summary-show-thread)
8063           (gnus-summary-first-subject t)))
8064     (gnus-summary-position-point)))
8065
8066 (defun gnus-summary-first-article ()
8067   "Select the first article.
8068 Return nil if there are no articles."
8069   (interactive)
8070   (prog1
8071       (when (gnus-summary-first-subject)
8072         (gnus-summary-show-thread)
8073         (gnus-summary-first-subject)
8074         (gnus-summary-display-article (gnus-summary-article-number)))
8075     (gnus-summary-position-point)))
8076
8077 (defun gnus-summary-best-unread-article (&optional arg)
8078   "Select the unread article with the highest score.
8079 If given a prefix argument, select the next unread article that has a
8080 score higher than the default score."
8081   (interactive "P")
8082   (let ((article (if arg
8083                      (gnus-summary-better-unread-subject)
8084                    (gnus-summary-best-unread-subject))))
8085     (if article
8086         (gnus-summary-goto-article article)
8087       (error "No unread articles"))))
8088
8089 (defun gnus-summary-best-unread-subject ()
8090   "Select the unread subject with the highest score."
8091   (interactive)
8092   (let ((best -1000000)
8093         (data gnus-newsgroup-data)
8094         article score)
8095     (while data
8096       (and (gnus-data-unread-p (car data))
8097            (> (setq score
8098                     (gnus-summary-article-score (gnus-data-number (car data))))
8099               best)
8100            (setq best score
8101                  article (gnus-data-number (car data))))
8102       (setq data (cdr data)))
8103     (when article
8104       (gnus-summary-goto-subject article))
8105     (gnus-summary-position-point)
8106     article))
8107
8108 (defun gnus-summary-better-unread-subject ()
8109   "Select the first unread subject that has a score over the default score."
8110   (interactive)
8111   (let ((data gnus-newsgroup-data)
8112         article score)
8113     (while (and (setq article (gnus-data-number (car data)))
8114                 (or (gnus-data-read-p (car data))
8115                     (not (> (gnus-summary-article-score article)
8116                             gnus-summary-default-score))))
8117       (setq data (cdr data)))
8118     (when article
8119       (gnus-summary-goto-subject article))
8120     (gnus-summary-position-point)
8121     article))
8122
8123 (defun gnus-summary-last-subject ()
8124   "Go to the last displayed subject line in the group."
8125   (let ((article (gnus-data-number (car (gnus-data-list t)))))
8126     (when article
8127       (gnus-summary-goto-subject article))))
8128
8129 (defun gnus-summary-goto-article (article &optional all-headers force)
8130   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
8131 If ALL-HEADERS is non-nil, no header lines are hidden.
8132 If FORCE, go to the article even if it isn't displayed.  If FORCE
8133 is a number, it is the line the article is to be displayed on."
8134   (interactive
8135    (list
8136     (gnus-completing-read
8137      "Article number or Message-ID"
8138      (mapcar 'int-to-string gnus-newsgroup-limit))
8139     current-prefix-arg
8140     t))
8141   (prog1
8142       (if (and (stringp article)
8143                (string-match "@\\|%40" article))
8144           (gnus-summary-refer-article article)
8145         (when (stringp article)
8146           (setq article (string-to-number article)))
8147         (if (gnus-summary-goto-subject article force)
8148             (gnus-summary-display-article article all-headers)
8149           (gnus-message 4 "Couldn't go to article %s" article) nil))
8150     (gnus-summary-position-point)))
8151
8152 (defun gnus-summary-goto-last-article ()
8153   "Go to the previously read article."
8154   (interactive)
8155   (prog1
8156       (when gnus-last-article
8157         (gnus-summary-goto-article gnus-last-article nil t))
8158     (gnus-summary-position-point)))
8159
8160 (defun gnus-summary-pop-article (number)
8161   "Pop one article off the history and go to the previous.
8162 NUMBER articles will be popped off."
8163   (interactive "p")
8164   (let (to)
8165     (setq gnus-newsgroup-history
8166           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
8167     (if to
8168         (gnus-summary-goto-article (car to) nil t)
8169       (error "Article history empty")))
8170   (gnus-summary-position-point))
8171
8172 ;; Summary commands and functions for limiting the summary buffer.
8173
8174 (defun gnus-summary-limit-to-articles (n)
8175   "Limit the summary buffer to the next N articles.
8176 If not given a prefix, use the process marked articles instead."
8177   (interactive "P")
8178   (prog1
8179       (let ((articles (gnus-summary-work-articles n)))
8180         (setq gnus-newsgroup-processable nil)
8181         (gnus-summary-limit articles))
8182     (gnus-summary-position-point)))
8183
8184 (defun gnus-summary-pop-limit (&optional total)
8185   "Restore the previous limit.
8186 If given a prefix, remove all limits."
8187   (interactive "P")
8188   (when total
8189     (setq gnus-newsgroup-limits
8190           (list (mapcar (lambda (h) (mail-header-number h))
8191                         gnus-newsgroup-headers))))
8192   (unless gnus-newsgroup-limits
8193     (error "No limit to pop"))
8194   (prog1
8195       (gnus-summary-limit nil 'pop)
8196     (gnus-summary-position-point)))
8197
8198 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
8199   "Limit the summary buffer to articles that have subjects that match a regexp.
8200 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
8201   (interactive
8202    (list (read-string (if current-prefix-arg
8203                           "Exclude subject (regexp): "
8204                         "Limit to subject (regexp): "))
8205          nil current-prefix-arg))
8206   (unless header
8207     (setq header "subject"))
8208   (when (not (equal "" subject))
8209     (prog1
8210         (let ((articles (gnus-summary-find-matching
8211                          (or header "subject") subject 'all nil nil
8212                          not-matching)))
8213           (unless articles
8214             (error "Found no matches for \"%s\"" subject))
8215           (gnus-summary-limit articles))
8216       (gnus-summary-position-point))))
8217
8218 (defun gnus-summary-limit-to-author (from &optional not-matching)
8219   "Limit the summary buffer to articles that have authors that match a regexp.
8220 If NOT-MATCHING, excluding articles that have authors that match a regexp."
8221   (interactive
8222    (list (read-string (if current-prefix-arg
8223                           "Exclude author (regexp): "
8224                         "Limit to author (regexp): "))
8225          current-prefix-arg))
8226   (gnus-summary-limit-to-subject from "from" not-matching))
8227
8228 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8229   "Limit the summary buffer to articles with the given RECIPIENT.
8230
8231 If NOT-MATCHING, exclude RECIPIENT.
8232
8233 To and Cc headers are checked.  You need to include them in
8234 `nnmail-extra-headers'."
8235   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8236   (interactive
8237    (list (read-string (format "%s recipient (regexp): "
8238                               (if current-prefix-arg "Exclude" "Limit to")))
8239          current-prefix-arg))
8240   (when (not (equal "" recipient))
8241     (prog1 (let* ((to
8242                    (if (memq 'To nnmail-extra-headers)
8243                        (gnus-summary-find-matching
8244                         (cons 'extra 'To) recipient 'all nil nil
8245                         not-matching)
8246                      (gnus-message
8247                       1 "`To' isn't present in `nnmail-extra-headers'")
8248                      (sit-for 1)
8249                      nil))
8250                   (cc
8251                    (if (memq 'Cc nnmail-extra-headers)
8252                        (gnus-summary-find-matching
8253                         (cons 'extra 'Cc) recipient 'all nil nil
8254                         not-matching)
8255                      (gnus-message
8256                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8257                      (sit-for 1)
8258                      nil))
8259                   (articles
8260                    (if not-matching
8261                        ;; We need the numbers that are in both lists:
8262                        (mapcar (lambda (a)
8263                                  (and (memq a to) a))
8264                                cc)
8265                      (nconc to cc))))
8266              (unless articles
8267                (error "Found no matches for \"%s\"" recipient))
8268              (gnus-summary-limit articles))
8269       (gnus-summary-position-point))))
8270
8271 (defun gnus-summary-limit-to-address (address &optional not-matching)
8272   "Limit the summary buffer to articles with the given ADDRESS.
8273
8274 If NOT-MATCHING, exclude ADDRESS.
8275
8276 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8277 in `nnmail-extra-headers'."
8278   (interactive
8279    (list (read-string (format "%s address (regexp): "
8280                               (if current-prefix-arg "Exclude" "Limit to")))
8281          current-prefix-arg))
8282   (when (not (equal "" address))
8283     (prog1 (let* ((to
8284                    (if (memq 'To nnmail-extra-headers)
8285                        (gnus-summary-find-matching
8286                         (cons 'extra 'To) address 'all nil nil
8287                         not-matching)
8288                      (gnus-message
8289                       1 "`To' isn't present in `nnmail-extra-headers'")
8290                      (sit-for 1)
8291                      t))
8292                   (cc
8293                    (if (memq 'Cc nnmail-extra-headers)
8294                        (gnus-summary-find-matching
8295                         (cons 'extra 'Cc) address 'all nil nil
8296                         not-matching)
8297                      (gnus-message
8298                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8299                      (sit-for 1)
8300                      t))
8301                   (from
8302                    (gnus-summary-find-matching "from" address
8303                                                'all nil nil not-matching))
8304                   (articles
8305                    (if not-matching
8306                        ;; We need the numbers that are in all lists:
8307                        (if (eq cc t)
8308                            (if (eq to t)
8309                                from
8310                              (mapcar (lambda (a) (car (memq a from))) to))
8311                          (if (eq to t)
8312                              (mapcar (lambda (a) (car (memq a from))) cc)
8313                            (mapcar (lambda (a) (car (memq a from)))
8314                                    (mapcar (lambda (a) (car (memq a to)))
8315                                            cc))))
8316                      (nconc (if (eq to t) nil to)
8317                             (if (eq cc t) nil cc)
8318                             from))))
8319              (unless articles
8320                (error "Found no matches for \"%s\"" address))
8321              (gnus-summary-limit articles))
8322       (gnus-summary-position-point))))
8323
8324 (defun gnus-summary-limit-strange-charsets-predicate (header)
8325   (when (fboundp 'char-charset)
8326     (let ((string (concat (mail-header-subject header)
8327                           (mail-header-from header)))
8328           charset found)
8329       (dotimes (i (1- (length string)))
8330         (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8331         (when (string-match "unicode\\|big\\|japanese" charset)
8332           (setq found t)))
8333       found)))
8334
8335 (defun gnus-summary-limit-to-predicate (predicate)
8336   "Limit to articles where PREDICATE returns non-nil.
8337 PREDICATE will be called with the header structures of the
8338 articles."
8339   (let ((articles nil)
8340         (case-fold-search t))
8341     (dolist (header gnus-newsgroup-headers)
8342       (when (funcall predicate header)
8343         (push (mail-header-number header) articles)))
8344     (gnus-summary-limit (nreverse articles))))
8345
8346 (defun gnus-summary-limit-to-age (age &optional younger-p)
8347   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8348 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8349 articles that are younger than AGE days."
8350   (interactive
8351    (let ((younger current-prefix-arg)
8352          (days-got nil)
8353          days)
8354      (while (not days-got)
8355        (setq days (if younger
8356                       (read-string "Limit to articles younger than (in days, older when negative): ")
8357                     (read-string
8358                      "Limit to articles older than (in days, younger when negative): ")))
8359        (when (> (length days) 0)
8360          (setq days (read days)))
8361        (if (numberp days)
8362            (progn
8363              (setq days-got t)
8364              (when (< days 0)
8365                (setq younger (not younger))
8366                (setq days (* days -1))))
8367          (message "Please enter a number.")
8368          (sleep-for 1)))
8369      (list days younger)))
8370   (prog1
8371       (let ((data gnus-newsgroup-data)
8372             (cutoff (days-to-time age))
8373             articles d date is-younger)
8374         (while (setq d (pop data))
8375           (when (and (vectorp (gnus-data-header d))
8376                      (setq date (mail-header-date (gnus-data-header d))))
8377             (setq is-younger (time-less-p
8378                               (time-since (gnus-date-get-time date))
8379                               cutoff))
8380             (when (if younger-p
8381                       is-younger
8382                     (not is-younger))
8383               (push (gnus-data-number d) articles))))
8384         (gnus-summary-limit (nreverse articles)))
8385     (gnus-summary-position-point)))
8386
8387 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8388   "Limit the summary buffer to articles that match an 'extra' header."
8389   (interactive
8390    (let ((header
8391           (intern
8392            (gnus-completing-read
8393             (if current-prefix-arg
8394                 "Exclude extra header"
8395               "Limit extra header")
8396             (mapcar 'symbol-name gnus-extra-headers)
8397             t nil nil
8398             (symbol-name (car gnus-extra-headers))))))
8399      (list header
8400            (read-string (format "%s header %s (regexp): "
8401                                 (if current-prefix-arg "Exclude" "Limit to")
8402                                 header))
8403            current-prefix-arg)))
8404   (when (not (equal "" regexp))
8405     (prog1
8406         (let ((articles (gnus-summary-find-matching
8407                          (cons 'extra header) regexp 'all nil nil
8408                          not-matching)))
8409           (unless articles
8410             (error "Found no matches for \"%s\"" regexp))
8411           (gnus-summary-limit articles))
8412       (gnus-summary-position-point))))
8413
8414 (defun gnus-summary-limit-to-display-predicate ()
8415   "Limit the summary buffer to the predicated in the `display' group parameter."
8416   (interactive)
8417   (unless gnus-newsgroup-display
8418     (error "There is no `display' group parameter"))
8419   (let (articles)
8420     (dolist (gnus-number gnus-newsgroup-articles)
8421       (when (funcall gnus-newsgroup-display)
8422         (push gnus-number articles)))
8423     (gnus-summary-limit articles))
8424   (gnus-summary-position-point))
8425
8426 (defun gnus-summary-limit-to-unread (&optional all)
8427   "Limit the summary buffer to articles that are not marked as read.
8428 If ALL is non-nil, limit strictly to unread articles."
8429   (interactive "P")
8430   (if all
8431       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8432     (gnus-summary-limit-to-marks
8433      ;; Concat all the marks that say that an article is read and have
8434      ;; those removed.
8435      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8436            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8437            gnus-low-score-mark gnus-expirable-mark
8438            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8439            gnus-duplicate-mark)
8440      'reverse)))
8441
8442 (defun gnus-summary-limit-to-headers (match &optional reverse)
8443   "Limit the summary buffer to articles that have headers that match MATCH.
8444 If REVERSE (the prefix), limit to articles that don't match."
8445   (interactive "sMatch headers (regexp): \nP")
8446   (gnus-summary-limit-to-bodies match reverse t))
8447
8448 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8449   "Limit the summary buffer to articles that have bodies that match MATCH.
8450 If REVERSE (the prefix), limit to articles that don't match."
8451   (interactive "sMatch body (regexp): \nP")
8452   (let ((articles nil)
8453         (gnus-select-article-hook nil)  ;Disable hook.
8454         (gnus-article-prepare-hook nil)
8455         (gnus-use-article-prefetch nil)
8456         (gnus-keep-backlog nil)
8457         (gnus-break-pages nil)
8458         (gnus-summary-display-arrow nil)
8459         (gnus-updated-mode-lines nil)
8460         (gnus-auto-center-summary nil)
8461         (gnus-display-mime-function nil))
8462     (dolist (data gnus-newsgroup-data)
8463       (let (gnus-mark-article-hook)
8464         (gnus-summary-select-article t t nil (gnus-data-number data)))
8465       (with-current-buffer gnus-article-buffer
8466         (article-goto-body)
8467         (let* ((case-fold-search t)
8468                (found (if headersp
8469                           (re-search-backward match nil t)
8470                         (re-search-forward match nil t))))
8471           (when (or (and found
8472                          (not reverse))
8473                     (and (not found)
8474                          reverse))
8475             (push (gnus-data-number data) articles)))))
8476     (if (not articles)
8477         (message "No messages matched")
8478       (gnus-summary-limit articles)))
8479   (gnus-summary-position-point))
8480
8481 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8482   "Limit the summary buffer to articles that aren't part on any thread.
8483 If THREADSP (the prefix), limit to articles that are in threads."
8484   (interactive "P")
8485   (let ((articles nil)
8486         thread-articles
8487         threads)
8488     (dolist (thread gnus-newsgroup-threads)
8489       (if (stringp (car thread))
8490           (dolist (thread (cdr thread))
8491             (push thread threads))
8492         (push thread threads)))
8493     (dolist (thread threads)
8494       (setq thread-articles (gnus-articles-in-thread thread))
8495       (when (or (and threadsp
8496                      (> (length thread-articles) 1))
8497                 (and (not threadsp)
8498                      (= (length thread-articles) 1)))
8499         (setq articles (nconc thread-articles articles))))
8500     (if (not articles)
8501         (message "No messages matched")
8502       (gnus-summary-limit articles))
8503     (gnus-summary-position-point)))
8504
8505 (defun gnus-summary-limit-to-replied (&optional unreplied)
8506   "Limit the summary buffer to replied articles.
8507 If UNREPLIED (the prefix), limit to unreplied articles."
8508   (interactive "P")
8509   (if unreplied
8510       (gnus-summary-limit
8511        (gnus-set-difference gnus-newsgroup-articles
8512         gnus-newsgroup-replied))
8513     (gnus-summary-limit gnus-newsgroup-replied))
8514   (gnus-summary-position-point))
8515
8516 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8517   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8518 If REVERSE, limit the summary buffer to articles that are marked
8519 with MARKS.  MARKS can either be a string of marks or a list of marks.
8520 Returns how many articles were removed."
8521   (interactive "sMarks: ")
8522   (gnus-summary-limit-to-marks marks t))
8523
8524 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8525   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8526 If REVERSE (the prefix), limit the summary buffer to articles that are
8527 not marked with MARKS.  MARKS can either be a string of marks or a
8528 list of marks.
8529 Returns how many articles were removed."
8530   (interactive "sMarks: \nP")
8531   (prog1
8532       (let ((data gnus-newsgroup-data)
8533             (marks (if (listp marks) marks
8534                      (append marks nil))) ; Transform to list.
8535             articles)
8536         (while data
8537           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8538                   (memq (gnus-data-mark (car data)) marks))
8539             (push (gnus-data-number (car data)) articles))
8540           (setq data (cdr data)))
8541         (gnus-summary-limit articles))
8542     (gnus-summary-position-point)))
8543
8544 (defun gnus-summary-limit-to-score (score)
8545   "Limit to articles with score at or above SCORE."
8546   (interactive "NLimit to articles with score of at least: ")
8547   (let ((data gnus-newsgroup-data)
8548         articles)
8549     (while data
8550       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8551                 score)
8552         (push (gnus-data-number (car data)) articles))
8553       (setq data (cdr data)))
8554     (prog1
8555         (gnus-summary-limit articles)
8556       (gnus-summary-position-point))))
8557
8558 (defun gnus-summary-limit-to-unseen ()
8559   "Limit to unseen articles."
8560   (interactive)
8561   (prog1
8562       (gnus-summary-limit gnus-newsgroup-unseen)
8563     (gnus-summary-position-point)))
8564
8565 (defun gnus-summary-limit-include-thread (id)
8566   "Display all the hidden articles that is in the thread with ID in it.
8567 When called interactively, ID is the Message-ID of the current
8568 article."
8569   (interactive (list (mail-header-id (gnus-summary-article-header))))
8570   (let ((articles (gnus-articles-in-thread
8571                    (gnus-id-to-thread (gnus-root-id id))))
8572         ;;we REALLY want the whole thread---this prevents cut-threads
8573         ;;from removing the thread we want to include.
8574         (gnus-fetch-old-headers nil)
8575         (gnus-build-sparse-threads nil))
8576     (prog1
8577         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8578       (gnus-summary-limit-include-matching-articles
8579        "subject"
8580        (regexp-quote (gnus-simplify-subject-re
8581                       (mail-header-subject (gnus-id-to-header id)))))
8582       (gnus-summary-position-point))))
8583
8584 (defun gnus-summary-limit-include-matching-articles (header regexp)
8585   "Display all the hidden articles that have HEADERs that match REGEXP."
8586   (interactive (list (read-string "Match on header: ")
8587                      (read-string "Regexp: ")))
8588   (let ((articles (gnus-find-matching-articles header regexp)))
8589     (prog1
8590         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8591       (gnus-summary-position-point))))
8592
8593 (defun gnus-summary-insert-dormant-articles ()
8594   "Insert all the dormant articles for this group into the current buffer."
8595   (interactive)
8596   (let ((gnus-verbose (max 6 gnus-verbose)))
8597     (if (not gnus-newsgroup-dormant)
8598         (gnus-message 3 "No dormant articles for this group")
8599       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8600
8601 (defun gnus-summary-insert-ticked-articles ()
8602   "Insert ticked articles for this group into the current buffer."
8603   (interactive)
8604   (let ((gnus-verbose (max 6 gnus-verbose)))
8605     (if (not gnus-newsgroup-marked)
8606         (gnus-message 3 "No ticked articles for this group")
8607       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8608
8609 (defun gnus-summary-limit-include-dormant ()
8610   "Display all the hidden articles that are marked as dormant.
8611 Note that this command only works on a subset of the articles currently
8612 fetched for this group."
8613   (interactive)
8614   (unless gnus-newsgroup-dormant
8615     (error "There are no dormant articles in this group"))
8616   (prog1
8617       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8618     (gnus-summary-position-point)))
8619
8620 (defun gnus-summary-include-articles (articles)
8621   "Fetch the headers for ARTICLES and then display the summary lines."
8622   (let ((gnus-inhibit-demon t)
8623         (gnus-agent nil)
8624         (gnus-read-all-available-headers t))
8625     (setq gnus-newsgroup-headers
8626           (gnus-merge
8627            'list gnus-newsgroup-headers
8628            (gnus-fetch-headers articles nil t)
8629            'gnus-article-sort-by-number))
8630     (gnus-summary-limit (append articles gnus-newsgroup-limit))))
8631
8632 (defun gnus-summary-limit-exclude-dormant ()
8633   "Hide all dormant articles."
8634   (interactive)
8635   (prog1
8636       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8637     (gnus-summary-position-point)))
8638
8639 (defun gnus-summary-limit-exclude-childless-dormant ()
8640   "Hide all dormant articles that have no children."
8641   (interactive)
8642   (let ((data (gnus-data-list t))
8643         articles d children)
8644     ;; Find all articles that are either not dormant or have
8645     ;; children.
8646     (while (setq d (pop data))
8647       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8648                 (and (setq children
8649                            (gnus-article-children (gnus-data-number d)))
8650                      (let (found)
8651                        (while children
8652                          (when (memq (car children) articles)
8653                            (setq children nil
8654                                  found t))
8655                          (pop children))
8656                        found)))
8657         (push (gnus-data-number d) articles)))
8658     ;; Do the limiting.
8659     (prog1
8660         (gnus-summary-limit articles)
8661       (gnus-summary-position-point))))
8662
8663 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8664   "Mark all unread excluded articles as read.
8665 If ALL, mark even excluded ticked and dormants as read."
8666   (interactive "P")
8667   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8668   (let ((articles (gnus-sorted-ndifference
8669                    (sort
8670                     (mapcar (lambda (h) (mail-header-number h))
8671                             gnus-newsgroup-headers)
8672                     '<)
8673                    gnus-newsgroup-limit))
8674         article)
8675     (setq gnus-newsgroup-unreads
8676           (gnus-sorted-intersection gnus-newsgroup-unreads
8677                                     gnus-newsgroup-limit))
8678     (if all
8679         (setq gnus-newsgroup-dormant nil
8680               gnus-newsgroup-marked nil
8681               gnus-newsgroup-reads
8682               (nconc
8683                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8684                gnus-newsgroup-reads))
8685       (while (setq article (pop articles))
8686         (unless (or (memq article gnus-newsgroup-dormant)
8687                     (memq article gnus-newsgroup-marked))
8688           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8689
8690 (defun gnus-summary-limit (articles &optional pop)
8691   (if pop
8692       ;; We pop the previous limit off the stack and use that.
8693       (setq articles (car gnus-newsgroup-limits)
8694             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8695     ;; We use the new limit, so we push the old limit on the stack.
8696     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8697   ;; Set the limit.
8698   (setq gnus-newsgroup-limit articles)
8699   (let ((total (length gnus-newsgroup-data))
8700         (data (gnus-data-find-list (gnus-summary-article-number)))
8701         (gnus-summary-mark-below nil)   ; Inhibit this.
8702         found)
8703     ;; This will do all the work of generating the new summary buffer
8704     ;; according to the new limit.
8705     (gnus-summary-prepare)
8706     ;; Hide any threads, possibly.
8707     (gnus-summary-maybe-hide-threads)
8708     ;; Try to return to the article you were at, or one in the
8709     ;; neighborhood.
8710     (when data
8711       ;; We try to find some article after the current one.
8712       (while data
8713         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8714           (setq data nil
8715                 found t))
8716         (setq data (cdr data))))
8717     (unless found
8718       ;; If there is no data, that means that we were after the last
8719       ;; article.  The same goes when we can't find any articles
8720       ;; after the current one.
8721       (goto-char (point-max))
8722       (gnus-summary-find-prev))
8723     (gnus-set-mode-line 'summary)
8724     ;; We return how many articles were removed from the summary
8725     ;; buffer as a result of the new limit.
8726     (- total (length gnus-newsgroup-data))))
8727
8728 (defsubst gnus-invisible-cut-children (threads)
8729   (let ((num 0))
8730     (while threads
8731       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8732         (incf num))
8733       (pop threads))
8734     (< num 2)))
8735
8736 (defsubst gnus-cut-thread (thread)
8737   "Go forwards in the thread until we find an article that we want to display."
8738   (when (or (eq gnus-fetch-old-headers 'some)
8739             (eq gnus-fetch-old-headers 'invisible)
8740             (numberp gnus-fetch-old-headers)
8741             (eq gnus-build-sparse-threads 'some)
8742             (eq gnus-build-sparse-threads 'more))
8743     ;; Deal with old-fetched headers and sparse threads.
8744     (while (and
8745             thread
8746             (or
8747              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8748              (gnus-summary-article-ancient-p
8749               (mail-header-number (car thread))))
8750             (if (or (<= (length (cdr thread)) 1)
8751                     (eq gnus-fetch-old-headers 'invisible))
8752                 (setq gnus-newsgroup-limit
8753                       (delq (mail-header-number (car thread))
8754                             gnus-newsgroup-limit)
8755                       thread (cadr thread))
8756               (when (gnus-invisible-cut-children (cdr thread))
8757                 (let ((th (cdr thread)))
8758                   (while th
8759                     (if (memq (mail-header-number (caar th))
8760                               gnus-newsgroup-limit)
8761                         (setq thread (car th)
8762                               th nil)
8763                       (setq th (cdr th))))))))))
8764   thread)
8765
8766 (defun gnus-cut-threads (threads)
8767   "Cut off all uninteresting articles from the beginning of THREADS."
8768   (when (or (eq gnus-fetch-old-headers 'some)
8769             (eq gnus-fetch-old-headers 'invisible)
8770             (numberp gnus-fetch-old-headers)
8771             (eq gnus-build-sparse-threads 'some)
8772             (eq gnus-build-sparse-threads 'more))
8773     (let ((th threads))
8774       (while th
8775         (setcar th (gnus-cut-thread (car th)))
8776         (setq th (cdr th)))))
8777   ;; Remove nixed out threads.
8778   (delq nil threads))
8779
8780 (defun gnus-summary-initial-limit (&optional show-if-empty)
8781   "Figure out what the initial limit is supposed to be on group entry.
8782 This entails weeding out unwanted dormants, low-scored articles,
8783 fetch-old-headers verbiage, and so on."
8784   ;; Most groups have nothing to remove.
8785   (unless (or gnus-inhibit-limiting
8786               (and (null gnus-newsgroup-dormant)
8787                    (eq gnus-newsgroup-display 'gnus-not-ignore)
8788                    (not (eq gnus-fetch-old-headers 'some))
8789                    (not (numberp gnus-fetch-old-headers))
8790                    (not (eq gnus-fetch-old-headers 'invisible))
8791                    (null gnus-summary-expunge-below)
8792                    (not (eq gnus-build-sparse-threads 'some))
8793                    (not (eq gnus-build-sparse-threads 'more))
8794                    (null gnus-thread-expunge-below)))
8795     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8796     (setq gnus-newsgroup-limit nil)
8797     (mapatoms
8798      (lambda (node)
8799        (unless (car (symbol-value node))
8800          ;; These threads have no parents -- they are roots.
8801          (let ((nodes (cdr (symbol-value node)))
8802                thread)
8803            (while nodes
8804              (if (and gnus-thread-expunge-below
8805                       (< (gnus-thread-total-score (car nodes))
8806                          gnus-thread-expunge-below))
8807                  (gnus-expunge-thread (pop nodes))
8808                (setq thread (pop nodes))
8809                (gnus-summary-limit-children thread))))))
8810      gnus-newsgroup-dependencies)
8811     ;; If this limitation resulted in an empty group, we might
8812     ;; pop the previous limit and use it instead.
8813     (when (and (not gnus-newsgroup-limit)
8814                show-if-empty)
8815       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8816     gnus-newsgroup-limit))
8817
8818 (defun gnus-summary-limit-children (thread)
8819   "Return 1 if this subthread is visible and 0 if it is not."
8820   ;; First we get the number of visible children to this thread.  This
8821   ;; is done by recursing down the thread using this function, so this
8822   ;; will really go down to a leaf article first, before slowly
8823   ;; working its way up towards the root.
8824   (when thread
8825     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8826            (children
8827            (if (cdr thread)
8828                (apply '+ (mapcar 'gnus-summary-limit-children
8829                                  (cdr thread)))
8830              0))
8831            (number (mail-header-number (car thread)))
8832            score)
8833       (if (and
8834            (not (memq number gnus-newsgroup-marked))
8835            (or
8836             ;; If this article is dormant and has absolutely no visible
8837             ;; children, then this article isn't visible.
8838             (and (memq number gnus-newsgroup-dormant)
8839                  (zerop children))
8840             ;; If this is "fetch-old-headered" and there is no
8841             ;; visible children, then we don't want this article.
8842             (and (or (eq gnus-fetch-old-headers 'some)
8843                      (numberp gnus-fetch-old-headers))
8844                  (gnus-summary-article-ancient-p number)
8845                  (zerop children))
8846             ;; If this is "fetch-old-headered" and `invisible', then
8847             ;; we don't want this article.
8848             (and (eq gnus-fetch-old-headers 'invisible)
8849                  (gnus-summary-article-ancient-p number))
8850             ;; If this is a sparsely inserted article with no children,
8851             ;; we don't want it.
8852             (and (eq gnus-build-sparse-threads 'some)
8853                  (gnus-summary-article-sparse-p number)
8854                  (zerop children))
8855             ;; If we use expunging, and this article is really
8856             ;; low-scored, then we don't want this article.
8857             (when (and gnus-summary-expunge-below
8858                        (< (setq score
8859                                 (or (cdr (assq number gnus-newsgroup-scored))
8860                                     gnus-summary-default-score))
8861                           gnus-summary-expunge-below))
8862               ;; We increase the expunge-tally here, but that has
8863               ;; nothing to do with the limits, really.
8864               (incf gnus-newsgroup-expunged-tally)
8865               ;; We also mark as read here, if that's wanted.
8866               (when (and gnus-summary-mark-below
8867                          (< score gnus-summary-mark-below))
8868                 (setq gnus-newsgroup-unreads
8869                       (delq number gnus-newsgroup-unreads))
8870                 (if gnus-newsgroup-auto-expire
8871                     (push number gnus-newsgroup-expirable)
8872                   (push (cons number gnus-low-score-mark)
8873                         gnus-newsgroup-reads)))
8874               t)
8875             ;; Do the `display' group parameter.
8876             (and gnus-newsgroup-display
8877                  (let ((gnus-number number))
8878                    (not (funcall gnus-newsgroup-display))))))
8879           ;; Nope, invisible article.
8880           0
8881         ;; Ok, this article is to be visible, so we add it to the limit
8882         ;; and return 1.
8883         (push number gnus-newsgroup-limit)
8884         1))))
8885
8886 (defun gnus-expunge-thread (thread)
8887   "Mark all articles in THREAD as read."
8888   (let* ((number (mail-header-number (car thread))))
8889     (incf gnus-newsgroup-expunged-tally)
8890     ;; We also mark as read here, if that's wanted.
8891     (setq gnus-newsgroup-unreads
8892           (delq number gnus-newsgroup-unreads))
8893     (if gnus-newsgroup-auto-expire
8894         (push number gnus-newsgroup-expirable)
8895       (push (cons number gnus-low-score-mark)
8896             gnus-newsgroup-reads)))
8897   ;; Go recursively through all subthreads.
8898   (mapcar 'gnus-expunge-thread (cdr thread)))
8899
8900 ;; Summary article oriented commands
8901
8902 (defun gnus-summary-refer-parent-article (n)
8903   "Refer parent article N times.
8904 If N is negative, go to ancestor -N instead.
8905 The difference between N and the number of articles fetched is returned."
8906   (interactive "p")
8907   (let ((skip 1)
8908         error header ref)
8909     (when (not (natnump n))
8910       (setq skip (abs n)
8911             n 1))
8912     (while (and (> n 0)
8913                 (not error))
8914       (setq header (gnus-summary-article-header))
8915       (if (and (eq (mail-header-number header)
8916                    (cdr gnus-article-current))
8917                (equal gnus-newsgroup-name
8918                       (car gnus-article-current)))
8919           ;; If we try to find the parent of the currently
8920           ;; displayed article, then we take a look at the actual
8921           ;; References header, since this is slightly more
8922           ;; reliable than the References field we got from the
8923           ;; server.
8924           (with-current-buffer gnus-original-article-buffer
8925             (nnheader-narrow-to-headers)
8926             (unless (setq ref (message-fetch-field "references"))
8927               (when (setq ref (message-fetch-field "in-reply-to"))
8928                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8929             (widen))
8930         (setq ref
8931               ;; It's not the current article, so we take a bet on
8932               ;; the value we got from the server.
8933               (mail-header-references header)))
8934       (if (and ref
8935                (not (equal ref "")))
8936           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8937             (gnus-message 1 "Couldn't find parent"))
8938         (gnus-message 1 "No references in article %d"
8939                       (gnus-summary-article-number))
8940         (setq error t))
8941       (decf n))
8942     (gnus-summary-position-point)
8943     n))
8944
8945 (defun gnus-summary-refer-references ()
8946   "Fetch all articles mentioned in the References header.
8947 Return the number of articles fetched."
8948   (interactive)
8949   (let ((ref (mail-header-references (gnus-summary-article-header)))
8950         (current (gnus-summary-article-number))
8951         (n 0))
8952     (if (or (not ref)
8953             (equal ref ""))
8954         (error "No References in the current article")
8955       ;; For each Message-ID in the References header...
8956       (while (string-match "<[^>]*>" ref)
8957         (incf n)
8958         ;; ... fetch that article.
8959         (gnus-summary-refer-article
8960          (prog1 (match-string 0 ref)
8961            (setq ref (substring ref (match-end 0))))))
8962       (gnus-summary-goto-subject current)
8963       (gnus-summary-position-point)
8964       n)))
8965
8966 (defun gnus-delete-duplicate-headers (headers)
8967   ;; First remove leading duplicates.
8968   (while (and (> (length headers) 1)
8969               (= (mail-header-number (car headers))
8970                  (mail-header-number (cadr headers))))
8971     (pop headers))
8972   ;; Then the rest.
8973   (let ((result headers))
8974     (while (> (length headers) 1)
8975       (if (= (mail-header-number (car headers))
8976              (mail-header-number (cadr headers)))
8977           (setcdr headers (cddr headers))
8978         (pop headers)))
8979     result))
8980
8981 (defun gnus-summary-refer-thread (&optional limit)
8982   "Fetch all articles in the current thread. For backends that
8983 know how to search for threads (currently only 'nnimap) a
8984 non-numeric prefix arg will use nnir to search the entire
8985 server; without a prefix arg only the current group is
8986 searched. If the variable `gnus-refer-thread-use-nnir' is
8987 non-nil the prefix arg has the reverse meaning. If no
8988 backend-specific 'request-thread function is available fetch
8989 LIMIT (the numerical prefix) old headers. If LIMIT is
8990 non-numeric or nil fetch the number specified by the
8991 `gnus-refer-thread-limit' variable."
8992   (interactive "P")
8993   (gnus-warp-to-article)
8994   (let* ((header (gnus-summary-article-header))
8995          (id (mail-header-id header))
8996          (gnus-inhibit-demon t)
8997          (gnus-summary-ignore-duplicates t)
8998          (gnus-read-all-available-headers t)
8999          (gnus-refer-thread-use-nnir
9000           (if (and (not (null limit)) (listp limit))
9001               (not gnus-refer-thread-use-nnir) gnus-refer-thread-use-nnir))
9002          (new-headers
9003           (if (gnus-check-backend-function
9004                'request-thread gnus-newsgroup-name)
9005               (gnus-request-thread header gnus-newsgroup-name)
9006             (let* ((limit (if (numberp limit) (prefix-numeric-value limit)
9007                             gnus-refer-thread-limit))
9008                    (last (if (numberp limit)
9009                              (min (+ (mail-header-number header)
9010                                      limit)
9011                                   gnus-newsgroup-highest)
9012                            gnus-newsgroup-highest))
9013                    (subject (gnus-simplify-subject
9014                              (mail-header-subject header)))
9015                    (refs (split-string (or (mail-header-references header)
9016                                            "")))
9017                    (gnus-parse-headers-hook
9018                     (lambda () (goto-char (point-min))
9019                       (keep-lines
9020                        (regexp-opt (append refs (list id subject)))))))
9021               (gnus-fetch-headers (list last) (if (numberp limit)
9022                                                   (* 2 limit) limit) t)))))
9023     (when (listp new-headers)
9024       (dolist (header new-headers)
9025         (when (member (mail-header-number header) gnus-newsgroup-unselected)
9026           (push (mail-header-number header) gnus-newsgroup-unreads)
9027           (setq gnus-newsgroup-unselected
9028                 (delete (mail-header-number header)
9029                         gnus-newsgroup-unselected))))
9030       (setq gnus-newsgroup-headers
9031             (gnus-delete-duplicate-headers
9032              (gnus-merge
9033               'list gnus-newsgroup-headers new-headers
9034               'gnus-article-sort-by-number)))
9035       (gnus-summary-limit-include-thread id))))
9036
9037 (defun gnus-summary-refer-article (message-id)
9038   "Fetch an article specified by MESSAGE-ID."
9039   (interactive "sMessage-ID: ")
9040   (when (and (stringp message-id)
9041              (not (zerop (length message-id))))
9042     (setq message-id (gnus-replace-in-string message-id " " ""))
9043     ;; Construct the correct Message-ID if necessary.
9044     ;; Suggested by tale@pawl.rpi.edu.
9045     (unless (string-match "^<" message-id)
9046       (setq message-id (concat "<" message-id)))
9047     (unless (string-match ">$" message-id)
9048       (setq message-id (concat message-id ">")))
9049     ;; People often post MIDs from URLs, so unhex it:
9050     (unless (string-match "@" message-id)
9051       (setq message-id (gnus-url-unhex-string message-id)))
9052     (let* ((header (gnus-id-to-header message-id))
9053            (sparse (and header
9054                         (gnus-summary-article-sparse-p
9055                          (mail-header-number header))
9056                         (memq (mail-header-number header)
9057                               gnus-newsgroup-limit)))
9058            number)
9059       (cond
9060        ;; If the article is present in the buffer we just go to it.
9061        ((and header
9062              (or (not (gnus-summary-article-sparse-p
9063                        (mail-header-number header)))
9064                  sparse))
9065         (prog1
9066             (gnus-summary-goto-article
9067              (mail-header-number header) nil t)
9068           (when sparse
9069             (gnus-summary-update-article (mail-header-number header)))))
9070        (t
9071         ;; We fetch the article.
9072         (catch 'found
9073           (dolist (gnus-override-method (gnus-refer-article-methods))
9074             (when (and (gnus-check-server gnus-override-method)
9075                        ;; Fetch the header,
9076                        (setq number (gnus-summary-insert-subject message-id)))
9077               ;; and display the article.
9078               (gnus-summary-select-article nil nil nil number)
9079               (throw 'found t)))
9080           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
9081
9082 (defun gnus-refer-article-methods ()
9083   "Return a list of referable methods."
9084   (cond
9085    ;; No method, so we default to current and native.
9086    ((null gnus-refer-article-method)
9087     (list gnus-current-select-method gnus-select-method))
9088    ;; Current.
9089    ((eq 'current gnus-refer-article-method)
9090     (list gnus-current-select-method))
9091    ;; List of select methods.
9092    ((not (and (symbolp (car gnus-refer-article-method))
9093               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
9094     (let (out)
9095       (dolist (method gnus-refer-article-method)
9096         (push (if (eq 'current method)
9097                   gnus-current-select-method
9098                 (if (eq 'nnir (car method))
9099                     (list
9100                      'nnir
9101                      (or (cadr method)
9102                          (gnus-method-to-server gnus-current-select-method)))
9103                   method))
9104               out))
9105       (nreverse out)))
9106    ;; One single select method.
9107    (t
9108     (list gnus-refer-article-method))))
9109
9110 (defun gnus-summary-edit-parameters ()
9111   "Edit the group parameters of the current group."
9112   (interactive)
9113   (gnus-group-edit-group gnus-newsgroup-name 'params))
9114
9115 (defun gnus-summary-customize-parameters ()
9116   "Customize the group parameters of the current group."
9117   (interactive)
9118   (gnus-group-customize gnus-newsgroup-name))
9119
9120 (defun gnus-summary-enter-digest-group (&optional force)
9121   "Enter an nndoc group based on the current article.
9122 If FORCE, force a digest interpretation.  If not, try to guess
9123 what the document format is.
9124
9125 To control what happens when you exit the group, see the
9126 `gnus-auto-select-on-ephemeral-exit' variable."
9127   (interactive "P")
9128   (let ((conf gnus-current-window-configuration))
9129     (save-window-excursion
9130       (save-excursion
9131         (let (gnus-article-prepare-hook
9132               gnus-display-mime-function
9133               gnus-break-pages)
9134           (gnus-summary-select-article))))
9135     (setq gnus-current-window-configuration conf)
9136     (let* ((name (format "%s-%d"
9137                          (gnus-group-prefixed-name
9138                           gnus-newsgroup-name (list 'nndoc ""))
9139                          (with-current-buffer gnus-summary-buffer
9140                            gnus-current-article)))
9141            (ogroup gnus-newsgroup-name)
9142            (params (append (gnus-info-params (gnus-get-info ogroup))
9143                            (list (cons 'to-group ogroup))
9144                            (list (cons 'parent-group ogroup))
9145                            (list (cons 'save-article-group ogroup))))
9146            (case-fold-search t)
9147            (buf (current-buffer))
9148            dig to-address)
9149       (with-current-buffer gnus-original-article-buffer
9150         ;; Have the digest group inherit the main mail address of
9151         ;; the parent article.
9152         (when (setq to-address (or (gnus-fetch-field "reply-to")
9153                                    (gnus-fetch-field "from")))
9154           (setq params
9155                 (append
9156                  (list (cons 'to-address
9157                              (funcall gnus-decode-encoded-address-function
9158                                       to-address))))))
9159         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
9160         (insert-buffer-substring gnus-original-article-buffer)
9161         ;; Remove lines that may lead nndoc to misinterpret the
9162         ;; document type.
9163         (narrow-to-region
9164          (goto-char (point-min))
9165          (or (search-forward "\n\n" nil t) (point)))
9166         (goto-char (point-min))
9167         (delete-matching-lines "^Path:\\|^From ")
9168         (widen))
9169       (unwind-protect
9170           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
9171                     (gnus-newsgroup-ephemeral-ignored-charsets
9172                      gnus-newsgroup-ignored-charsets))
9173                 (gnus-group-read-ephemeral-group
9174                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
9175                               (nndoc-article-type
9176                                ,(if force 'mbox 'guess)))
9177                  t nil nil nil
9178                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
9179                                                         "ADAPT")))))
9180               ;; Make all postings to this group go to the parent group.
9181               (nconc (gnus-info-params (gnus-get-info name))
9182                      params)
9183             ;; Couldn't select this doc group.
9184             (switch-to-buffer buf)
9185             (gnus-set-global-variables)
9186             (gnus-configure-windows 'summary)
9187             (gnus-message 3 "Article couldn't be entered?"))
9188         (kill-buffer dig)))))
9189
9190 (defun gnus-summary-read-document (n)
9191   "Open a new group based on the current article(s).
9192 This will allow you to read digests and other similar
9193 documents as newsgroups.
9194 Obeys the standard process/prefix convention."
9195   (interactive "P")
9196   (let* ((ogroup gnus-newsgroup-name)
9197          (params (append (gnus-info-params (gnus-get-info ogroup))
9198                          (list (cons 'to-group ogroup))))
9199          group egroup groups vgroup)
9200     (dolist (article (gnus-summary-work-articles n))
9201       (setq group (format "%s-%d" gnus-newsgroup-name article))
9202       (gnus-summary-remove-process-mark article)
9203       (when (gnus-summary-display-article article)
9204         (save-excursion ;;What for?
9205           (with-temp-buffer
9206             (insert-buffer-substring gnus-original-article-buffer)
9207             ;; Remove some headers that may lead nndoc to make
9208             ;; the wrong guess.
9209             (message-narrow-to-head)
9210             (goto-char (point-min))
9211             (delete-matching-lines "^Path:\\|^From ")
9212             (widen)
9213             (if (setq egroup
9214                       (gnus-group-read-ephemeral-group
9215                        group `(nndoc ,group (nndoc-address ,(current-buffer))
9216                                      (nndoc-article-type guess))
9217                        t nil t))
9218                 (progn
9219                   ;; Make all postings to this group go to the parent group.
9220                   (nconc (gnus-info-params (gnus-get-info egroup))
9221                          params)
9222                   (push egroup groups))
9223               ;; Couldn't select this doc group.
9224               (gnus-error 3 "Article couldn't be entered"))))))
9225     ;; Now we have selected all the documents.
9226     (cond
9227      ((not groups)
9228       (error "None of the articles could be interpreted as documents"))
9229      ((gnus-group-read-ephemeral-group
9230        (setq vgroup (format
9231                      "nnvirtual:%s-%s" gnus-newsgroup-name
9232                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
9233        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
9234        t
9235        (cons (current-buffer) 'summary)))
9236      (t
9237       (error "Couldn't select virtual nndoc group")))))
9238
9239 (defun gnus-summary-widget-forward (arg)
9240   "Move point to the next field or button in the article.
9241 With optional ARG, move across that many fields."
9242   (interactive "p")
9243   (gnus-summary-select-article)
9244   (gnus-configure-windows 'article)
9245   (select-window (gnus-get-buffer-window gnus-article-buffer))
9246   (widget-forward arg))
9247
9248 (defun gnus-summary-isearch-article (&optional regexp-p)
9249   "Do incremental search forward on the current article.
9250 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
9251   (interactive "P")
9252   (gnus-summary-select-article)
9253   (gnus-configure-windows 'article)
9254   (gnus-eval-in-buffer-window gnus-article-buffer
9255     (save-restriction
9256       (widen)
9257       (isearch-forward regexp-p))))
9258
9259 (defun gnus-summary-repeat-search-article-forward ()
9260   "Repeat the previous search forwards."
9261   (interactive)
9262   (unless gnus-last-search-regexp
9263     (error "No previous search"))
9264   (gnus-summary-search-article-forward gnus-last-search-regexp))
9265
9266 (defun gnus-summary-repeat-search-article-backward ()
9267   "Repeat the previous search backwards."
9268   (interactive)
9269   (unless gnus-last-search-regexp
9270     (error "No previous search"))
9271   (gnus-summary-search-article-forward gnus-last-search-regexp t))
9272
9273 (defun gnus-summary-search-article-forward (regexp &optional backward)
9274   "Search for an article containing REGEXP forward.
9275 If BACKWARD, search backward instead."
9276   (interactive
9277    (list (read-string
9278           (format "Search article %s (regexp%s): "
9279                   (if current-prefix-arg "backward" "forward")
9280                   (if gnus-last-search-regexp
9281                       (concat ", default " gnus-last-search-regexp)
9282                     "")))
9283          current-prefix-arg))
9284   (if (string-equal regexp "")
9285       (setq regexp (or gnus-last-search-regexp ""))
9286     (setq gnus-last-search-regexp regexp)
9287     (setq gnus-article-before-search gnus-current-article))
9288   ;; Intentionally set gnus-last-article.
9289   (setq gnus-last-article gnus-article-before-search)
9290   (let ((gnus-last-article gnus-last-article))
9291     (if (gnus-summary-search-article regexp backward)
9292         (gnus-summary-show-thread)
9293       (signal 'search-failed (list regexp)))))
9294
9295 (defun gnus-summary-search-article-backward (regexp)
9296   "Search for an article containing REGEXP backward."
9297   (interactive
9298    (list (read-string
9299           (format "Search article backward (regexp%s): "
9300                   (if gnus-last-search-regexp
9301                       (concat ", default " gnus-last-search-regexp)
9302                     "")))))
9303   (gnus-summary-search-article-forward regexp 'backward))
9304
9305 (defun gnus-summary-search-article (regexp &optional backward)
9306   "Search for an article containing REGEXP.
9307 Optional argument BACKWARD means do search for backward.
9308 `gnus-select-article-hook' is not called during the search."
9309   ;; We have to require this here to make sure that the following
9310   ;; dynamic binding isn't shadowed by autoloading.
9311   (require 'gnus-async)
9312   (require 'gnus-art)
9313   (let ((gnus-select-article-hook nil)  ;Disable hook.
9314         (gnus-article-prepare-hook nil)
9315         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9316         (gnus-use-article-prefetch nil)
9317         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9318         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9319         (gnus-visual nil)
9320         (gnus-keep-backlog nil)
9321         (gnus-break-pages nil)
9322         (gnus-summary-display-arrow nil)
9323         (gnus-updated-mode-lines nil)
9324         (gnus-auto-center-summary nil)
9325         (sum (current-buffer))
9326         (gnus-display-mime-function nil)
9327         (found nil)
9328         point)
9329     (gnus-save-hidden-threads
9330       (gnus-summary-select-article)
9331       (set-buffer gnus-article-buffer)
9332       (goto-char (window-point (get-buffer-window (current-buffer))))
9333       (when backward
9334         (forward-line -1))
9335       (while (not found)
9336         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9337         (if (if backward
9338                 (re-search-backward regexp nil t)
9339               (re-search-forward regexp nil t))
9340             ;; We found the regexp.
9341             (progn
9342               (setq found 'found)
9343               (beginning-of-line)
9344               (set-window-start
9345                (get-buffer-window (current-buffer))
9346                (point))
9347               (forward-line 1)
9348               (set-window-point
9349                (get-buffer-window (current-buffer))
9350                (point))
9351               (set-buffer sum)
9352               (setq point (point)))
9353           ;; We didn't find it, so we go to the next article.
9354           (set-buffer sum)
9355           (setq found 'not)
9356           (while (eq found 'not)
9357             (if (not (if backward (gnus-summary-find-prev)
9358                        (gnus-summary-find-next)))
9359                 ;; No more articles.
9360                 (setq found t)
9361               ;; Select the next article and adjust point.
9362               (unless (gnus-summary-article-sparse-p
9363                        (gnus-summary-article-number))
9364                 (setq found nil)
9365                 (gnus-summary-select-article)
9366                 (set-buffer gnus-article-buffer)
9367                 (widen)
9368                 (goto-char (if backward (point-max) (point-min))))))))
9369       (gnus-message 7 ""))
9370     ;; Return whether we found the regexp.
9371     (when (eq found 'found)
9372       (goto-char point)
9373       (gnus-summary-show-thread)
9374       (gnus-summary-goto-subject gnus-current-article)
9375       (gnus-summary-position-point)
9376       t)))
9377
9378 (defun gnus-find-matching-articles (header regexp)
9379   "Return a list of all articles that match REGEXP on HEADER.
9380 This search includes all articles in the current group that Gnus has
9381 fetched headers for, whether they are displayed or not."
9382   (let ((articles nil)
9383         ;; Can't eta-reduce because it's a macro.
9384         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9385         (case-fold-search t))
9386     (dolist (header gnus-newsgroup-headers)
9387       (when (string-match regexp (funcall func header))
9388         (push (mail-header-number header) articles)))
9389     (nreverse articles)))
9390
9391 (defun gnus-summary-find-matching (header regexp &optional backward unread
9392                                           not-case-fold not-matching)
9393   "Return a list of all articles that match REGEXP on HEADER.
9394 The search stars on the current article and goes forwards unless
9395 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9396 If UNREAD is non-nil, only unread articles will
9397 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9398 in the comparisons. If NOT-MATCHING, return a list of all articles that
9399 not match REGEXP on HEADER."
9400   (let ((case-fold-search (not not-case-fold))
9401         articles d func)
9402     (if (consp header)
9403         (if (eq (car header) 'extra)
9404             (setq func
9405                   `(lambda (h)
9406                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9407                          "")))
9408           (error "%s is an invalid header" header))
9409       (unless (fboundp (intern (concat "mail-header-" header)))
9410         (error "%s is not a valid header" header))
9411       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9412     (dolist (d (if (eq backward 'all)
9413                    gnus-newsgroup-data
9414                  (gnus-data-find-list
9415                   (gnus-summary-article-number)
9416                   (gnus-data-list backward))))
9417       (when (and (or (not unread)       ; We want all articles...
9418                      (gnus-data-unread-p d)) ; Or just unreads.
9419                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9420                  (if not-matching
9421                      (not (string-match
9422                            regexp
9423                            (funcall func (gnus-data-header d))))
9424                    (string-match regexp
9425                                  (funcall func (gnus-data-header d)))))
9426         (push (gnus-data-number d) articles))) ; Success!
9427     (nreverse articles)))
9428
9429 (defun gnus-summary-execute-command (header regexp command &optional backward)
9430   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9431 If HEADER is an empty string (or nil), the match is done on the entire
9432 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9433   (interactive
9434    (list (let ((completion-ignore-case t))
9435            (gnus-completing-read
9436             "Header name"
9437             (mapcar 'symbol-name
9438                     (append
9439                      '(Number Subject From Lines Date
9440                        Message-ID Xref References Body)
9441                      gnus-extra-headers))
9442             'require-match))
9443          (read-string "Regexp: ")
9444          (read-key-sequence "Command: ")
9445          current-prefix-arg))
9446   (when (equal header "Body")
9447     (setq header ""))
9448   ;; Hidden thread subtrees must be searched as well.
9449   (gnus-summary-show-all-threads)
9450   ;; We don't want to change current point nor window configuration.
9451   (save-excursion
9452     (save-window-excursion
9453       (let (gnus-visual
9454             gnus-treat-strip-trailing-blank-lines
9455             gnus-treat-strip-leading-blank-lines
9456             gnus-treat-strip-multiple-blank-lines
9457             gnus-treat-hide-boring-headers
9458             gnus-treat-fold-newsgroups
9459             gnus-article-prepare-hook)
9460         (gnus-message 6 "Executing %s..." (key-description command))
9461         ;; We'd like to execute COMMAND interactively so as to give arguments.
9462         (gnus-execute header regexp
9463                       `(call-interactively ',(key-binding command))
9464                       backward)
9465         (gnus-message 6 "Executing %s...done" (key-description command))))))
9466
9467 (defun gnus-summary-beginning-of-article ()
9468   "Scroll the article back to the beginning."
9469   (interactive)
9470   (gnus-summary-select-article)
9471   (gnus-configure-windows 'article)
9472   (gnus-eval-in-buffer-window gnus-article-buffer
9473     (widen)
9474     (goto-char (point-min))
9475     (when gnus-break-pages
9476       (gnus-narrow-to-page))))
9477
9478 (defun gnus-summary-end-of-article ()
9479   "Scroll to the end of the article."
9480   (interactive)
9481   (gnus-summary-select-article)
9482   (gnus-configure-windows 'article)
9483   (gnus-eval-in-buffer-window gnus-article-buffer
9484     (widen)
9485     (goto-char (point-max))
9486     (recenter -3)
9487     (when gnus-break-pages
9488       (gnus-narrow-to-page))))
9489
9490 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9491   "Truncate to LEN and quote all \"(\"'s in STRING."
9492   (gnus-replace-in-string (if (and len (> (length string) len))
9493                               (substring string 0 len)
9494                             string)
9495                           "[()]" "\\\\\\&"))
9496
9497 (defun gnus-summary-print-article (&optional filename n)
9498   "Generate and print a PostScript image of the process-marked (mail) articles.
9499
9500 If used interactively, print the current article if none are
9501 process-marked.  With prefix arg, prompt the user for the name of the
9502 file to save in.
9503
9504 When used from Lisp, accept two optional args FILENAME and N.  N means
9505 to print the next N articles.  If N is negative, print the N previous
9506 articles.  If N is nil and articles have been marked with the process
9507 mark, print these instead.
9508
9509 If the optional first argument FILENAME is nil, send the image to the
9510 printer.  If FILENAME is a string, save the PostScript image in a file with
9511 that name.  If FILENAME is a number, prompt the user for the name of the file
9512 to save in."
9513   (interactive (list (ps-print-preprint current-prefix-arg)))
9514   (dolist (article (gnus-summary-work-articles n))
9515     (gnus-summary-select-article nil nil 'pseudo article)
9516     (gnus-eval-in-buffer-window gnus-article-buffer
9517       (gnus-print-buffer))
9518     (gnus-summary-remove-process-mark article))
9519   (ps-despool filename))
9520
9521 (defun gnus-print-buffer ()
9522   (let ((ps-left-header
9523          (list
9524           (concat "("
9525                   (gnus-summary-print-truncate-and-quote
9526                    (mail-header-subject gnus-current-headers)
9527                    66) ")")
9528           (concat "("
9529                   (gnus-summary-print-truncate-and-quote
9530                    (mail-header-from gnus-current-headers)
9531                    45) ")")))
9532         (ps-right-header
9533          (list
9534           "/pagenumberstring load"
9535           (concat "("
9536                   (mail-header-date gnus-current-headers) ")"))))
9537     (gnus-run-hooks 'gnus-ps-print-hook)
9538     (save-excursion
9539       (if ps-print-color-p
9540           (ps-spool-buffer-with-faces)
9541         (ps-spool-buffer)))))
9542
9543 (defun gnus-summary-show-complete-article ()
9544   "Show a complete version of the current article.
9545 This is only useful if you're looking at a partial version of the
9546 article currently."
9547   (interactive)
9548   (let ((gnus-keep-backlog nil)
9549         (gnus-use-cache nil)
9550         (gnus-agent nil)
9551         (variable (intern
9552                    (format "%s-fetch-partial-articles"
9553                            (car (gnus-find-method-for-group
9554                                  gnus-newsgroup-name)))
9555                    obarray))
9556         old-val)
9557     (unwind-protect
9558         (progn
9559           (setq old-val (symbol-value variable))
9560           (set variable nil)
9561           (gnus-flush-original-article-buffer)
9562           (gnus-summary-show-article))
9563       (set variable old-val))))
9564
9565 (defun gnus-summary-show-article (&optional arg)
9566   "Force redisplaying of the current article.
9567 If ARG (the prefix) is a number, show the article with the charset
9568 defined in `gnus-summary-show-article-charset-alist', or the charset
9569 input.
9570 If ARG (the prefix) is non-nil and not a number, show the article,
9571 but without running any of the article treatment functions
9572 article.  Normally, the keystroke is `C-u g'.  When using `C-u
9573 C-u g', show the raw article."
9574   (interactive "P")
9575   (cond
9576    ((numberp arg)
9577     (gnus-summary-show-article t)
9578     (let ((gnus-newsgroup-charset
9579            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9580                (mm-read-coding-system
9581                 "View as charset: " ;; actually it is coding system.
9582                 (with-current-buffer gnus-article-buffer
9583                   (mm-detect-coding-region (point) (point-max))))))
9584           (gnus-newsgroup-ignored-charsets 'gnus-all))
9585       (gnus-summary-select-article nil 'force)
9586       (let ((deps gnus-newsgroup-dependencies)
9587             head header lines)
9588         (with-current-buffer gnus-original-article-buffer
9589           (save-restriction
9590             (message-narrow-to-head)
9591             (setq head (buffer-string))
9592             (goto-char (point-min))
9593             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9594               (goto-char (point-max))
9595               (widen)
9596               (setq lines (1- (count-lines (point) (point-max))))))
9597           (with-temp-buffer
9598             (insert (format "211 %d Article retrieved.\n"
9599                             (cdr gnus-article-current)))
9600             (insert head)
9601             (if lines (insert (format "Lines: %d\n" lines)))
9602             (insert ".\n")
9603             (let ((nntp-server-buffer (current-buffer)))
9604               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9605         (gnus-data-set-header
9606          (gnus-data-find (cdr gnus-article-current))
9607          header)
9608         (gnus-summary-update-article-line
9609          (cdr gnus-article-current) header)
9610         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9611           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9612    ((not arg)
9613     ;; Select the article the normal way.
9614     (gnus-summary-select-article nil 'force))
9615    ((equal arg '(16))
9616     ;; C-u C-u g
9617     (let ((gnus-inhibit-article-treatments t))
9618       (gnus-summary-select-article nil 'force)))
9619    (t
9620     ;; We have to require this here to make sure that the following
9621     ;; dynamic binding isn't shadowed by autoloading.
9622     (require 'gnus-async)
9623     (require 'gnus-art)
9624     ;; Bind the article treatment functions to nil.
9625     (let ((gnus-have-all-headers t)
9626           gnus-article-prepare-hook
9627           gnus-article-decode-hook
9628           gnus-display-mime-function
9629           gnus-break-pages)
9630       ;; Destroy any MIME parts.
9631       (when (gnus-buffer-live-p gnus-article-buffer)
9632         (with-current-buffer gnus-article-buffer
9633           (gnus-article-stop-animations)
9634           (mm-destroy-parts gnus-article-mime-handles)
9635           ;; Set it to nil for safety reason.
9636           (setq gnus-article-mime-handle-alist nil)
9637           (setq gnus-article-mime-handles nil)))
9638       (gnus-summary-select-article nil 'force))))
9639   (gnus-summary-goto-subject gnus-current-article)
9640   (gnus-summary-position-point))
9641
9642 (defun gnus-summary-show-raw-article ()
9643   "Show the raw article without any article massaging functions being run."
9644   (interactive)
9645   (gnus-summary-show-article t))
9646
9647 (defun gnus-summary-verbose-headers (&optional arg)
9648   "Toggle permanent full header display.
9649 If ARG is a positive number, turn header display on.
9650 If ARG is a negative number, turn header display off."
9651   (interactive "P")
9652   (setq gnus-show-all-headers
9653         (cond ((or (not (numberp arg))
9654                    (zerop arg))
9655                (not gnus-show-all-headers))
9656               ((natnump arg)
9657                t)))
9658   (gnus-summary-show-article))
9659
9660 (defun gnus-summary-toggle-header (&optional arg)
9661   "Show the headers if they are hidden, or hide them if they are shown.
9662 If ARG is a positive number, show the entire header.
9663 If ARG is a negative number, hide the unwanted header lines."
9664   (interactive "P")
9665   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9666                      (get-buffer-window gnus-article-buffer t))))
9667     (with-current-buffer gnus-article-buffer
9668       (widen)
9669       (article-narrow-to-head)
9670       (let* ((inhibit-read-only t)
9671              (inhibit-point-motion-hooks t)
9672              (hidden (if (numberp arg)
9673                          (>= arg 0)
9674                        (or (not (looking-at "[^ \t\n]+:"))
9675                            (gnus-article-hidden-text-p 'headers))))
9676              s e)
9677         (delete-region (point-min) (point-max))
9678         (with-current-buffer gnus-original-article-buffer
9679           (goto-char (setq s (point-min)))
9680           (setq e (if (search-forward "\n\n" nil t)
9681                       (1- (point))
9682                     (point-max))))
9683         (insert-buffer-substring gnus-original-article-buffer s e)
9684         (run-hooks 'gnus-article-decode-hook)
9685         (if hidden
9686             (let ((gnus-treat-hide-headers nil)
9687                   (gnus-treat-hide-boring-headers nil))
9688               (gnus-delete-wash-type 'headers)
9689               (gnus-treat-article 'head))
9690           (gnus-treat-article 'head))
9691         (widen)
9692         (if window
9693             (set-window-start window (goto-char (point-min))))
9694         (if gnus-break-pages
9695             (gnus-narrow-to-page)
9696           (when (gnus-visual-p 'page-marker)
9697             (let ((inhibit-read-only t))
9698               (gnus-remove-text-with-property 'gnus-prev)
9699               (gnus-remove-text-with-property 'gnus-next))))
9700         (gnus-set-mode-line 'article)))))
9701
9702 (defun gnus-summary-show-all-headers ()
9703   "Make all header lines visible."
9704   (interactive)
9705   (gnus-summary-toggle-header 1))
9706
9707 (defun gnus-summary-caesar-message (&optional arg)
9708   "Caesar rotate the current article by 13.
9709 With a non-numerical prefix, also rotate headers.  A numerical
9710 prefix specifies how many places to rotate each letter forward."
9711   (interactive "P")
9712   (gnus-summary-select-article)
9713   (let ((mail-header-separator ""))
9714     (gnus-eval-in-buffer-window gnus-article-buffer
9715       (save-restriction
9716         (widen)
9717         (let ((start (window-start))
9718               (inhibit-read-only t))
9719           (if (equal arg '(4))
9720               (message-caesar-buffer-body nil t)
9721             (message-caesar-buffer-body arg))
9722           (set-window-start (get-buffer-window (current-buffer)) start)))))
9723   ;; Create buttons and stuff...
9724   (gnus-treat-article nil))
9725
9726 (declare-function idna-to-unicode "ext:idna" (str))
9727
9728 (defun gnus-summary-idna-message (&optional arg)
9729   "Decode IDNA encoded domain names in the current articles.
9730 IDNA encoded domain names looks like `xn--bar'.  If a string
9731 remain unencoded after running this function, it is likely an
9732 invalid IDNA string (`xn--bar' is invalid).
9733
9734 You must have GNU Libidn (URL `http://www.gnu.org/software/libidn/')
9735 installed for this command to work."
9736   (interactive "P")
9737   (if (not (and (condition-case nil (require 'idna)
9738                   (file-error))
9739                 (mm-coding-system-p 'utf-8)
9740                 (executable-find (symbol-value 'idna-program))))
9741       (gnus-message
9742        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9743     (gnus-summary-select-article)
9744     (let ((mail-header-separator ""))
9745       (gnus-eval-in-buffer-window gnus-article-buffer
9746         (save-restriction
9747           (widen)
9748           (let ((start (window-start))
9749                 buffer-read-only)
9750             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9751               (replace-match (idna-to-unicode (match-string 1))))
9752             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9753
9754 (defun gnus-summary-morse-message (&optional arg)
9755   "Morse decode the current article."
9756   (interactive "P")
9757   (gnus-summary-select-article)
9758   (let ((mail-header-separator ""))
9759     (gnus-eval-in-buffer-window gnus-article-buffer
9760       (save-excursion
9761         (save-restriction
9762           (widen)
9763           (let ((pos (window-start))
9764                 (inhibit-read-only t))
9765             (goto-char (point-min))
9766             (when (message-goto-body)
9767               (gnus-narrow-to-body))
9768             (goto-char (point-min))
9769             (while (search-forward "·" (point-max) t)
9770               (replace-match "."))
9771             (unmorse-region (point-min) (point-max))
9772             (widen)
9773             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9774
9775 (defun gnus-summary-stop-page-breaking ()
9776   "Stop page breaking in the current article."
9777   (interactive)
9778   (gnus-summary-select-article)
9779   (gnus-eval-in-buffer-window gnus-article-buffer
9780     (widen)
9781     (when (gnus-visual-p 'page-marker)
9782       (let ((inhibit-read-only t))
9783         (gnus-remove-text-with-property 'gnus-prev)
9784         (gnus-remove-text-with-property 'gnus-next))
9785       (setq gnus-page-broken nil))))
9786
9787 (defun gnus-summary-move-article (&optional n to-newsgroup
9788                                             select-method action)
9789   "Move the current article to a different newsgroup.
9790 If N is a positive number, move the N next articles.
9791 If N is a negative number, move the N previous articles.
9792 If N is nil and any articles have been marked with the process mark,
9793 move those articles instead.
9794 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9795 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9796 re-spool using this method.
9797
9798 When called interactively with TO-NEWSGROUP being nil, the value of
9799 the variable `gnus-move-split-methods' is used for finding a default
9800 for the target newsgroup.
9801
9802 For this function to work, both the current newsgroup and the
9803 newsgroup that you want to move to have to support the `request-move'
9804 and `request-accept' functions.
9805
9806 ACTION can be either `move' (the default), `crosspost' or `copy'."
9807   (interactive "P")
9808   (unless action
9809     (setq action 'move))
9810   ;; Check whether the source group supports the required functions.
9811   (cond ((and (eq action 'move)
9812               (not (gnus-check-backend-function
9813                     'request-move-article gnus-newsgroup-name)))
9814          (error "The current group does not support article moving"))
9815         ((and (eq action 'crosspost)
9816               (not (gnus-check-backend-function
9817                     'request-replace-article gnus-newsgroup-name)))
9818          (error "The current group does not support article editing")))
9819   (let ((articles (gnus-summary-work-articles n))
9820         (prefix (if (gnus-check-backend-function
9821                      'request-move-article gnus-newsgroup-name)
9822                     (funcall gnus-move-group-prefix-function
9823                              gnus-newsgroup-name)
9824                   ""))
9825         (names '((move "Move" "Moving")
9826                  (copy "Copy" "Copying")
9827                  (crosspost "Crosspost" "Crossposting")))
9828         (copy-buf (save-excursion
9829                     (nnheader-set-temp-buffer " *copy article*")))
9830         art-group to-method new-xref article to-groups
9831         articles-to-update-marks encoded)
9832     (unless (assq action names)
9833       (error "Unknown action %s" action))
9834     ;; Read the newsgroup name.
9835     (when (and (not to-newsgroup)
9836                (not select-method))
9837       (if (and gnus-move-split-methods
9838                (not
9839                 (and (memq gnus-current-article articles)
9840                      (gnus-buffer-live-p gnus-original-article-buffer))))
9841           ;; When `gnus-move-split-methods' is non-nil, we have to
9842           ;; select an article to give `gnus-read-move-group-name' an
9843           ;; opportunity to suggest an appropriate default.  However,
9844           ;; we needn't render or mark the article.
9845           (let ((gnus-display-mime-function nil)
9846                 (gnus-article-prepare-hook nil)
9847                 (gnus-mark-article-hook nil))
9848             (gnus-summary-select-article nil nil nil (car articles))))
9849       (setq to-newsgroup (gnus-read-move-group-name
9850                           (cadr (assq action names))
9851                           (symbol-value
9852                            (intern (format "gnus-current-%s-group" action)))
9853                           articles prefix)
9854             encoded to-newsgroup
9855             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9856       (set (intern (format "gnus-current-%s-group" action))
9857            (mm-decode-coding-string
9858             to-newsgroup
9859             (gnus-group-name-charset to-method to-newsgroup))))
9860     (unless to-method
9861       (setq to-method (or select-method
9862                           (gnus-server-to-method
9863                            (gnus-group-method to-newsgroup)))))
9864     (setq to-newsgroup
9865           (or encoded
9866               (and to-newsgroup
9867                    (mm-encode-coding-string
9868                     to-newsgroup
9869                     (gnus-group-name-charset to-method to-newsgroup)))))
9870     ;; Check the method we are to move this article to...
9871     (unless (gnus-check-backend-function
9872              'request-accept-article (car to-method))
9873       (error "%s does not support article copying" (car to-method)))
9874     (unless (gnus-check-server to-method)
9875       (error "Can't open server %s" (car to-method)))
9876     (gnus-message 6 "%s to %s: %s..."
9877                   (caddr (assq action names))
9878                   (or (car select-method)
9879                       (gnus-group-decoded-name to-newsgroup))
9880                   articles)
9881     (while articles
9882       (setq article (pop articles))
9883       ;; Set any marks that may have changed in the summary buffer.
9884       (when gnus-preserve-marks
9885         (gnus-summary-push-marks-to-backend article))
9886       (setq
9887        art-group
9888        (cond
9889         ;; Move the article.
9890         ((eq action 'move)
9891          ;; Remove this article from future suppression.
9892          (gnus-dup-unsuppress-article article)
9893          (let* ((from-method (gnus-find-method-for-group
9894                               gnus-newsgroup-name))
9895                 (to-method (or select-method
9896                                (gnus-find-method-for-group to-newsgroup)))
9897                 (move-is-internal (gnus-server-equal from-method to-method)))
9898            (gnus-request-move-article
9899             article                     ; Article to move
9900             gnus-newsgroup-name         ; From newsgroup
9901             (nth 1 (gnus-find-method-for-group
9902                     gnus-newsgroup-name)) ; Server
9903             (list 'gnus-request-accept-article
9904                   to-newsgroup (list 'quote select-method)
9905                   (not articles) t)     ; Accept form
9906             (not articles)              ; Only save nov last time
9907             (and move-is-internal
9908                  to-newsgroup           ; Not respooling
9909                                         ; Is this move internal?
9910                  (gnus-group-real-name to-newsgroup)))))
9911         ;; Copy the article.
9912         ((eq action 'copy)
9913          (with-current-buffer copy-buf
9914            (when (gnus-request-article-this-buffer article
9915                                                    gnus-newsgroup-name)
9916              (save-restriction
9917                (nnheader-narrow-to-headers)
9918                (dolist (hdr gnus-copy-article-ignored-headers)
9919                  (message-remove-header hdr t)))
9920              (gnus-request-accept-article
9921               to-newsgroup select-method (not articles) t))))
9922         ;; Crosspost the article.
9923         ((eq action 'crosspost)
9924          (let ((xref (message-tokenize-header
9925                       (mail-header-xref (gnus-summary-article-header
9926                                          article))
9927                       " ")))
9928            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9929                                   ":" (number-to-string article)))
9930            (unless xref
9931              (setq xref (list (system-name))))
9932            (setq new-xref
9933                  (concat
9934                   (mapconcat 'identity
9935                              (delete "Xref:" (delete new-xref xref))
9936                              " ")
9937                   " " new-xref))
9938            (with-current-buffer copy-buf
9939              ;; First put the article in the destination group.
9940              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9941              (when (consp (setq art-group
9942                                 (gnus-request-accept-article
9943                                  to-newsgroup select-method (not articles)
9944                                  t)))
9945                (setq new-xref (concat new-xref " " (car art-group)
9946                                       ":"
9947                                       (number-to-string (cdr art-group))))
9948                ;; Now we have the new Xrefs header, so we insert
9949                ;; it and replace the new article.
9950                (nnheader-replace-header "Xref" new-xref)
9951                (gnus-request-replace-article
9952                 (cdr art-group) to-newsgroup (current-buffer) t)
9953                art-group))))))
9954       (cond
9955        ((not art-group)
9956         (gnus-message 1 "Couldn't %s article %s: %s"
9957                       (cadr (assq action names)) article
9958                       (nnheader-get-report (car to-method))))
9959        ((eq art-group 'junk)
9960         (when (eq action 'move)
9961           (gnus-summary-mark-article article gnus-canceled-mark)
9962           (gnus-message 4 "Deleted article %s" article)
9963           ;; run the delete hook
9964           (run-hook-with-args 'gnus-summary-article-delete-hook
9965                               action
9966                               (gnus-data-header
9967                                (assoc article (gnus-data-list nil)))
9968                               gnus-newsgroup-name nil
9969                               select-method)))
9970        (t
9971         (let* ((pto-group (gnus-group-prefixed-name
9972                            (car art-group) to-method))
9973                (info (gnus-get-info pto-group))
9974                (to-group (gnus-info-group info))
9975                to-marks)
9976           ;; Update the group that has been moved to.
9977           (when (and info
9978                      (memq action '(move copy)))
9979             (unless (member to-group to-groups)
9980               (push to-group to-groups))
9981
9982             (when (and (not (memq article gnus-newsgroup-unreads))
9983                        (cdr art-group))
9984               (push 'read to-marks)
9985               (gnus-info-set-read
9986                info (gnus-add-to-range (gnus-info-read info)
9987                                        (list (cdr art-group)))))
9988
9989             ;; See whether the article is to be put in the cache.
9990             (let* ((expirable (gnus-group-auto-expirable-p to-group))
9991                    (marks (if expirable
9992                               gnus-article-mark-lists
9993                             (delete '(expirable . expire)
9994                                     (copy-sequence
9995                                      gnus-article-mark-lists))))
9996                    (to-article (cdr art-group)))
9997
9998               ;; Enter the article into the cache in the new group,
9999               ;; if that is required.
10000               (when (and to-article
10001                          gnus-use-cache)
10002                 (gnus-cache-possibly-enter-article
10003                  to-group to-article
10004                  (memq article gnus-newsgroup-marked)
10005                  (memq article gnus-newsgroup-dormant)
10006                  (memq article gnus-newsgroup-unreads)))
10007
10008               (when (and gnus-preserve-marks
10009                          to-article)
10010                 ;; Copy any marks over to the new group.
10011                 (when (and (equal to-group gnus-newsgroup-name)
10012                            (not (memq article gnus-newsgroup-unreads)))
10013                   ;; Mark this article as read in this group.
10014                   (push (cons to-article gnus-read-mark)
10015                         gnus-newsgroup-reads)
10016                   ;; Increase the active status of this group.
10017                   (setcdr (gnus-active to-group) to-article)
10018                   (setcdr gnus-newsgroup-active to-article))
10019
10020                 (while marks
10021                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
10022                     (when (memq article (symbol-value
10023                                          (intern (format "gnus-newsgroup-%s"
10024                                                          (caar marks)))))
10025                       (push (cdar marks) to-marks)
10026                       ;; If the other group is the same as this group,
10027                       ;; then we have to add the mark to the list.
10028                       (when (equal to-group gnus-newsgroup-name)
10029                         (set (intern (format "gnus-newsgroup-%s"
10030                                              (caar marks)))
10031                              (cons to-article
10032                                    (symbol-value
10033                                     (intern (format "gnus-newsgroup-%s"
10034                                                     (caar marks)))))))
10035                       ;; Copy the marks to other group.
10036                       (gnus-add-marked-articles
10037                        to-group (cdar marks) (list to-article) info)))
10038                   (setq marks (cdr marks)))
10039
10040                 (when (and expirable
10041                            gnus-mark-copied-or-moved-articles-as-expirable
10042                            (not (memq 'expire to-marks)))
10043                   ;; Mark this article as expirable.
10044                   (push 'expire to-marks)
10045                   (when (equal to-group gnus-newsgroup-name)
10046                     (push to-article gnus-newsgroup-expirable))
10047                   ;; Copy the expirable mark to other group.
10048                   (gnus-add-marked-articles
10049                    to-group 'expire (list to-article) info))
10050
10051                 (when to-marks
10052                   (gnus-request-set-mark
10053                    to-group (list (list (list to-article) 'add to-marks)))))
10054
10055               (gnus-dribble-enter
10056                (concat "(gnus-group-set-info '"
10057                        (gnus-prin1-to-string (gnus-get-info to-group))
10058                        ")")
10059                (concat "^(gnus-group-set-info '(\""
10060                        (regexp-quote to-group) "\""))))
10061
10062           ;; Update the Xref header in this article to point to
10063           ;; the new crossposted article we have just created.
10064           (when (eq action 'crosspost)
10065             (with-current-buffer copy-buf
10066               (gnus-request-article-this-buffer article gnus-newsgroup-name)
10067               (nnheader-replace-header "Xref" new-xref)
10068               (gnus-request-replace-article
10069                article gnus-newsgroup-name (current-buffer) t)))
10070
10071           ;; run the move/copy/crosspost/respool hook
10072           (run-hook-with-args 'gnus-summary-article-move-hook
10073                               action
10074                               (gnus-data-header
10075                                (assoc article (gnus-data-list nil)))
10076                               gnus-newsgroup-name
10077                               to-newsgroup
10078                               select-method))
10079
10080         ;;;!!!Why is this necessary?
10081         (set-buffer gnus-summary-buffer)
10082
10083         (when (eq action 'move)
10084           (save-excursion
10085             (gnus-summary-goto-subject article)
10086             (gnus-summary-mark-article article gnus-canceled-mark)))))
10087       (push article articles-to-update-marks))
10088
10089     (save-excursion
10090       (apply 'gnus-summary-remove-process-mark articles-to-update-marks))
10091     ;; Re-activate all groups that have been moved to.
10092     (with-current-buffer gnus-group-buffer
10093       (let ((gnus-group-marked to-groups))
10094         (gnus-group-get-new-news-this-group nil t)))
10095
10096     (gnus-kill-buffer copy-buf)
10097     (gnus-summary-position-point)
10098     (gnus-set-mode-line 'summary)))
10099
10100 (defun gnus-summary-push-marks-to-backend (article)
10101   (let ((set nil)
10102         (marks gnus-article-mark-lists))
10103     (unless (memq article gnus-newsgroup-unreads)
10104       (push 'read set))
10105     (while marks
10106       (when (and (eq (gnus-article-mark-to-type (cdar marks)) 'list)
10107                  (memq article (symbol-value
10108                                 (intern (format "gnus-newsgroup-%s"
10109                                                 (caar marks))))))
10110         (push (cdar marks) set))
10111       (pop marks))
10112     (gnus-request-set-mark gnus-newsgroup-name `(((,article) set ,set)))))
10113
10114 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
10115   "Copy the current article to some other group.
10116 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
10117 When called interactively, if TO-NEWSGROUP is nil, use the value of
10118 the variable `gnus-move-split-methods' for finding a default target
10119 newsgroup.
10120 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
10121 re-spool using this method."
10122   (interactive "P")
10123   (gnus-summary-move-article n to-newsgroup select-method 'copy))
10124
10125 (defun gnus-summary-crosspost-article (&optional n)
10126   "Crosspost the current article to some other group."
10127   (interactive "P")
10128   (gnus-summary-move-article n nil nil 'crosspost))
10129
10130 (defcustom gnus-summary-respool-default-method nil
10131   "Default method type for respooling an article.
10132 If nil, use to the current newsgroup method."
10133   :type 'symbol
10134   :group 'gnus-summary-mail)
10135
10136 (defun gnus-summary-respool-article (&optional n method)
10137   "Respool the current article.
10138 The article will be squeezed through the mail spooling process again,
10139 which means that it will be put in some mail newsgroup or other
10140 depending on `nnmail-split-methods'.
10141 If N is a positive number, respool the N next articles.
10142 If N is a negative number, respool the N previous articles.
10143 If N is nil and any articles have been marked with the process mark,
10144 respool those articles instead.
10145
10146 Respooling can be done both from mail groups and \"real\" newsgroups.
10147 In the former case, the articles in question will be moved from the
10148 current group into whatever groups they are destined to.  In the
10149 latter case, they will be copied into the relevant groups."
10150   (interactive
10151    (list current-prefix-arg
10152          (let* ((methods (mapcar #'car (gnus-methods-using 'respool)))
10153                 (methname
10154                  (symbol-name (or gnus-summary-respool-default-method
10155                                   (car (gnus-find-method-for-group
10156                                         gnus-newsgroup-name)))))
10157                 (method
10158                  (gnus-completing-read
10159                   "Backend to use when respooling"
10160                   methods t nil 'gnus-mail-method-history methname))
10161                 ms)
10162            (cond
10163             ((zerop (length (setq ms (gnus-servers-using-backend
10164                                       (intern method)))))
10165              (list (intern method) ""))
10166             ((= 1 (length ms))
10167              (car ms))
10168             (t
10169              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
10170                (cdr (assoc (gnus-completing-read "Server name" ms-alist t)
10171                            ms-alist))))))))
10172   (unless method
10173     (error "No method given for respooling"))
10174   (if (assoc (symbol-name
10175               (car (gnus-find-method-for-group gnus-newsgroup-name)))
10176              (gnus-methods-using 'respool))
10177       (gnus-summary-move-article n nil method)
10178     (gnus-summary-copy-article n nil method)))
10179
10180 (defun gnus-summary-import-article (file &optional edit)
10181   "Import an arbitrary file into a mail newsgroup."
10182   (interactive "fImport file: \nP")
10183   (let ((group gnus-newsgroup-name)
10184         (now (current-time))
10185         atts lines group-art)
10186     (unless (gnus-check-backend-function 'request-accept-article group)
10187       (error "%s does not support article importing" group))
10188     (or (file-readable-p file)
10189         (not (file-regular-p file))
10190         (error "Can't read %s" file))
10191     (with-current-buffer (gnus-get-buffer-create " *import file*")
10192       (erase-buffer)
10193       (nnheader-insert-file-contents file)
10194       (goto-char (point-min))
10195       (if (nnheader-article-p)
10196           (save-restriction
10197             (goto-char (point-min))
10198             (search-forward "\n\n" nil t)
10199             (narrow-to-region (point-min) (1- (point)))
10200             (goto-char (point-min))
10201             (unless (re-search-forward "^date:" nil t)
10202               (goto-char (point-max))
10203               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
10204        ;; This doesn't look like an article, so we fudge some headers.
10205         (setq atts (file-attributes file)
10206               lines (count-lines (point-min) (point-max)))
10207         (insert "From: " (read-string "From: ") "\n"
10208                 "Subject: " (read-string "Subject: ") "\n"
10209                 "Date: " (message-make-date (nth 5 atts)) "\n"
10210                 "Message-ID: " (message-make-message-id) "\n"
10211                 "Lines: " (int-to-string lines) "\n"
10212                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
10213       (setq group-art (gnus-request-accept-article group nil t))
10214       (kill-buffer (current-buffer)))
10215     (setq gnus-newsgroup-active (gnus-activate-group group))
10216     (forward-line 1)
10217     (gnus-summary-goto-article (cdr group-art) nil t)
10218     (when edit
10219       (gnus-summary-edit-article))))
10220
10221 (defun gnus-summary-create-article ()
10222   "Create an article in a mail newsgroup."
10223   (interactive)
10224   (let ((group gnus-newsgroup-name)
10225         (now (current-time))
10226         group-art)
10227     (unless (gnus-check-backend-function 'request-accept-article group)
10228       (error "%s does not support article importing" group))
10229     (with-current-buffer (gnus-get-buffer-create " *import file*")
10230       (erase-buffer)
10231       (goto-char (point-min))
10232       ;; This doesn't look like an article, so we fudge some headers.
10233       (insert "From: " (read-string "From: ") "\n"
10234               "Subject: " (read-string "Subject: ") "\n"
10235               "Date: " (message-make-date now) "\n"
10236               "Message-ID: " (message-make-message-id) "\n")
10237       (setq group-art (gnus-request-accept-article group nil t))
10238       (kill-buffer (current-buffer)))
10239     (setq gnus-newsgroup-active (gnus-activate-group group))
10240     (forward-line 1)
10241     (gnus-summary-goto-article (cdr group-art) nil t)
10242     (gnus-summary-edit-article)))
10243
10244 (defun gnus-summary-article-posted-p ()
10245   "Say whether the current (mail) article is available from news as well.
10246 This will be the case if the article has both been mailed and posted."
10247   (interactive)
10248   (let ((id (mail-header-references (gnus-summary-article-header)))
10249         (gnus-override-method (car (gnus-refer-article-methods))))
10250     (if (gnus-request-head id "")
10251         (gnus-message 2 "The current message was found on %s"
10252                       gnus-override-method)
10253       (gnus-message 2 "The current message couldn't be found on %s"
10254                     gnus-override-method)
10255       nil)))
10256
10257 (defun gnus-summary-expire-articles (&optional now)
10258   "Expire all articles that are marked as expirable in the current group."
10259   (interactive)
10260   (when (and (not gnus-group-is-exiting-without-update-p)
10261              (gnus-check-backend-function
10262               'request-expire-articles gnus-newsgroup-name))
10263     ;; This backend supports expiry.
10264     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
10265            (expirable (if total
10266                           (progn
10267                             ;; We need to update the info for
10268                             ;; this group for `gnus-list-of-read-articles'
10269                             ;; to give us the right answer.
10270                             (gnus-run-hooks 'gnus-exit-group-hook)
10271                             (gnus-summary-update-info)
10272                             (gnus-list-of-read-articles gnus-newsgroup-name))
10273                         (setq gnus-newsgroup-expirable
10274                               (sort gnus-newsgroup-expirable '<))))
10275            (expiry-wait (if now 'immediate
10276                           (gnus-group-find-parameter
10277                            gnus-newsgroup-name 'expiry-wait)))
10278            (nnmail-expiry-target
10279             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
10280                 nnmail-expiry-target))
10281            es)
10282       (when expirable
10283         ;; There are expirable articles in this group, so we run them
10284         ;; through the expiry process.
10285         (gnus-message 6 "Expiring articles...")
10286         (unless (gnus-check-group gnus-newsgroup-name)
10287           (error "Can't open server for %s" gnus-newsgroup-name))
10288         ;; The list of articles that weren't expired is returned.
10289         (save-excursion
10290           (if expiry-wait
10291               (let ((nnmail-expiry-wait-function nil)
10292                     (nnmail-expiry-wait expiry-wait))
10293                 (setq es (gnus-request-expire-articles
10294                           expirable gnus-newsgroup-name)))
10295             (setq es (gnus-request-expire-articles
10296                       expirable gnus-newsgroup-name)))
10297           (unless total
10298             (setq gnus-newsgroup-expirable es))
10299           ;; We go through the old list of expirable, and mark all
10300           ;; really expired articles as nonexistent.
10301           (unless (eq es expirable) ;If nothing was expired, we don't mark.
10302             (let ((gnus-use-cache nil))
10303               (dolist (article expirable)
10304                 (when (and (not (memq article es))
10305                            (gnus-data-find article))
10306                   (gnus-summary-mark-article article gnus-canceled-mark)
10307                   (run-hook-with-args 'gnus-summary-article-expire-hook
10308                                       'delete
10309                                       (gnus-data-header
10310                                        (assoc article (gnus-data-list nil)))
10311                                       gnus-newsgroup-name
10312                                       nil
10313                                       nil))))))
10314         (gnus-message 6 "Expiring articles...done")))))
10315
10316 (defun gnus-summary-expire-articles-now ()
10317   "Expunge all expirable articles in the current group.
10318 This means that *all* articles that are marked as expirable will be
10319 deleted forever, right now."
10320   (interactive)
10321   (or gnus-expert-user
10322       (gnus-yes-or-no-p
10323        "Are you really, really sure you want to delete all expirable messages? ")
10324       (error "Phew!"))
10325   (gnus-summary-expire-articles t))
10326
10327 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10328 (defun gnus-summary-delete-article (&optional n)
10329   "Delete the N next (mail) articles.
10330 This command actually deletes articles.  This is not a marking
10331 command.  The article will disappear forever from your life, never to
10332 return.
10333
10334 If N is negative, delete backwards.
10335 If N is nil and articles have been marked with the process mark,
10336 delete these instead.
10337
10338 If `gnus-novice-user' is non-nil you will be asked for
10339 confirmation before the articles are deleted."
10340   (interactive "P")
10341   (unless (gnus-check-backend-function 'request-expire-articles
10342                                        gnus-newsgroup-name)
10343     (error "The current newsgroup does not support article deletion"))
10344   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10345     (error "Couldn't open server"))
10346   ;; Compute the list of articles to delete.
10347   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10348         (nnmail-expiry-target 'delete)
10349         not-deleted)
10350     (if (and gnus-novice-user
10351              (not (gnus-yes-or-no-p
10352                    (format "Do you really want to delete %s forever? "
10353                            (if (> (length articles) 1)
10354                                (format "these %s articles" (length articles))
10355                              "this article")))))
10356         ()
10357       ;; Delete the articles.
10358       (setq not-deleted (gnus-request-expire-articles
10359                          articles gnus-newsgroup-name 'force))
10360       (save-excursion
10361         (while articles
10362           (gnus-summary-remove-process-mark (car articles))
10363           ;; The backend might not have been able to delete the article
10364           ;; after all.
10365           (unless (memq (car articles) not-deleted)
10366             (gnus-summary-mark-article (car articles) gnus-canceled-mark)
10367             (let* ((article (car articles))
10368                    (ghead  (gnus-data-header
10369                             (assoc article (gnus-data-list nil)))))
10370               (run-hook-with-args 'gnus-summary-article-delete-hook
10371                                   'delete ghead gnus-newsgroup-name nil
10372                                   nil)))
10373           (setq articles (cdr articles))))
10374       (when not-deleted
10375         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10376     (gnus-summary-position-point)
10377     (gnus-set-mode-line 'summary)
10378     not-deleted))
10379
10380 (defun gnus-summary-edit-article (&optional arg)
10381   "Edit the current article.
10382 This will have permanent effect only in mail groups.
10383 If ARG is nil, edit the decoded articles.
10384 If ARG is 1, edit the raw articles.
10385 If ARG is 2, edit the raw articles even in read-only groups.
10386 If ARG is 3, edit the articles with the current handles.
10387 Otherwise, allow editing of articles even in read-only
10388 groups."
10389   (interactive "P")
10390   (let (force raw current-handles)
10391     (cond
10392      ((null arg))
10393      ((eq arg 1)
10394       (setq raw t))
10395      ((eq arg 2)
10396       (setq raw t
10397             force t))
10398      ((eq arg 3)
10399       (setq current-handles
10400             (and (gnus-buffer-live-p gnus-article-buffer)
10401                  (with-current-buffer gnus-article-buffer
10402                    (prog1
10403                        gnus-article-mime-handles
10404                      (setq gnus-article-mime-handles nil))))))
10405      (t
10406       (setq force t)))
10407     (when (and raw (not force)
10408                (member gnus-newsgroup-name '("nndraft:delayed"
10409                                              "nndraft:drafts"
10410                                              "nndraft:queue")))
10411       (error "Can't edit the raw article in group %s"
10412              gnus-newsgroup-name))
10413     (with-current-buffer gnus-summary-buffer
10414       (let ((mail-parse-charset gnus-newsgroup-charset)
10415             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10416         (gnus-set-global-variables)
10417         (when (and (not force)
10418                    (gnus-group-read-only-p))
10419           (error "The current newsgroup does not support article editing"))
10420         (gnus-summary-show-article t)
10421         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10422           (with-current-buffer gnus-article-buffer
10423             (mm-enable-multibyte)))
10424         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10425             (setq raw t))
10426         (gnus-article-edit-article
10427          (if raw 'ignore
10428            `(lambda ()
10429               (let ((mbl mml-buffer-list))
10430                 (setq mml-buffer-list nil)
10431                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10432                   (mime-to-mml ,'current-handles))
10433                 (let ((mbl1 mml-buffer-list))
10434                   (setq mml-buffer-list mbl)
10435                   (set (make-local-variable 'mml-buffer-list) mbl1))
10436                 (gnus-make-local-hook 'kill-buffer-hook)
10437                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10438          `(lambda (no-highlight)
10439             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10440                   (message-options message-options)
10441                   (message-options-set-recipient)
10442                   (mail-parse-ignored-charsets
10443                    ',gnus-newsgroup-ignored-charsets)
10444                   (rfc2047-header-encoding-alist
10445                    ',(let ((charset (gnus-group-name-charset
10446                                      (gnus-find-method-for-group
10447                                       gnus-newsgroup-name)
10448                                      gnus-newsgroup-name)))
10449                        (append (list (cons "Newsgroups" charset)
10450                                      (cons "Followup-To" charset)
10451                                      (cons "Xref" charset))
10452                                rfc2047-header-encoding-alist))))
10453               ,(if (not raw) '(progn
10454                                 (mml-to-mime)
10455                                 (mml-destroy-buffers)
10456                                 (remove-hook 'kill-buffer-hook
10457                                              'mml-destroy-buffers t)
10458                                 (kill-local-variable 'mml-buffer-list)))
10459               (gnus-summary-edit-article-done
10460                ,(or (mail-header-references gnus-current-headers) "")
10461                ,(gnus-group-read-only-p)
10462                ,gnus-summary-buffer no-highlight))))))))
10463
10464 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10465
10466 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10467                                                  no-highlight)
10468   "Make edits to the current article permanent."
10469   (interactive)
10470   (save-excursion
10471     ;; The buffer restriction contains the entire article if it exists.
10472     (when (article-goto-body)
10473       (let ((lines (count-lines (point) (point-max)))
10474             (length (- (point-max) (point)))
10475             (case-fold-search t)
10476             (body (copy-marker (point))))
10477         (goto-char (point-min))
10478         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10479           (delete-region (match-beginning 1) (match-end 1))
10480           (insert (number-to-string length)))
10481         (goto-char (point-min))
10482         (when (re-search-forward
10483                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10484           (delete-region (match-beginning 1) (match-end 1))
10485           (insert (number-to-string length)))
10486         (goto-char (point-min))
10487         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10488           (delete-region (match-beginning 1) (match-end 1))
10489           (insert (number-to-string lines))))))
10490   ;; Replace the article.
10491   (let ((buf (current-buffer))
10492         (article (cdr gnus-article-current))
10493         replace-result)
10494     (with-temp-buffer
10495       (insert-buffer-substring buf)
10496       (if (and (not read-only)
10497                (not (setq replace-result
10498                           (gnus-request-replace-article
10499                            article (car gnus-article-current)
10500                            (current-buffer) t))))
10501           (error "Couldn't replace article")
10502         ;; If we got a number back, then that's the new article number
10503         ;; for this article.  Otherwise, the article number didn't change.
10504         (when (numberp replace-result)
10505           (with-current-buffer gnus-summary-buffer
10506             (setq gnus-newsgroup-limit (delq article gnus-newsgroup-limit))
10507             (gnus-summary-limit gnus-newsgroup-limit)
10508             (setq article replace-result)
10509             (gnus-summary-goto-subject article t)))
10510         ;; Update the summary buffer.
10511         (if (and references
10512                  (equal (message-tokenize-header references " ")
10513                         (message-tokenize-header
10514                          (or (message-fetch-field "references") "") " ")))
10515             ;; We only have to update this line.
10516             (save-excursion
10517               (save-restriction
10518                 (message-narrow-to-head)
10519                 (let ((head (buffer-substring-no-properties
10520                              (point-min) (point-max)))
10521                       header)
10522                   (with-temp-buffer
10523                     (insert (format "211 %d Article retrieved.\n" article))
10524                     (insert head)
10525                     (insert ".\n")
10526                     (let ((nntp-server-buffer (current-buffer)))
10527                       (setq header (car (gnus-get-newsgroup-headers nil t))))
10528                     (with-current-buffer gnus-summary-buffer
10529                       (gnus-data-set-header (gnus-data-find article) header)
10530                       (gnus-summary-update-article-line article header)
10531                       (if (gnus-summary-goto-subject article nil t)
10532                           (gnus-summary-update-secondary-mark article)))))))
10533           ;; Update threads.
10534           (set-buffer (or buffer gnus-summary-buffer))
10535           (gnus-summary-update-article article)
10536           (if (gnus-summary-goto-subject article nil t)
10537               (gnus-summary-update-secondary-mark article)))
10538         ;; Prettify the article buffer again.
10539         (unless no-highlight
10540           (with-current-buffer gnus-article-buffer
10541             ;;!!! Fix this -- article should be rehighlighted.
10542             ;;(gnus-run-hooks 'gnus-article-display-hook)
10543             (set-buffer gnus-original-article-buffer)
10544             (gnus-request-article
10545              article (car gnus-article-current) (current-buffer))))
10546         ;; Prettify the summary buffer line.
10547         (when (gnus-visual-p 'summary-highlight 'highlight)
10548           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10549
10550 (defun gnus-summary-edit-wash (key)
10551   "Perform editing command KEY in the article buffer."
10552   (interactive
10553    (list
10554     (progn
10555       (message "%s" (concat (this-command-keys) "- "))
10556       (read-char))))
10557   (message "")
10558   (gnus-summary-edit-article)
10559   (execute-kbd-macro (concat (this-command-keys) key))
10560   (gnus-article-edit-done))
10561
10562 ;;; Respooling
10563
10564 (defun gnus-summary-respool-query (&optional silent trace)
10565   "Query where the respool algorithm would put this article."
10566   (interactive)
10567   (let (gnus-mark-article-hook)
10568     (gnus-summary-select-article)
10569     (with-current-buffer gnus-original-article-buffer
10570       (let ((groups (nnmail-article-group 'identity trace)))
10571         (unless silent
10572           (if groups
10573               (message "This message would go to %s"
10574                        (mapconcat 'car groups ", "))
10575             (message "This message would go to no groups"))
10576           groups)))))
10577
10578 (defun gnus-summary-respool-trace ()
10579   "Trace where the respool algorithm would put this article.
10580 Display a buffer showing all fancy splitting patterns which matched."
10581   (interactive)
10582   (gnus-summary-respool-query nil t))
10583
10584 ;; Summary marking commands.
10585
10586 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10587   "Mark articles which has the same subject as read, and then select the next.
10588 If UNMARK is positive, remove any kind of mark.
10589 If UNMARK is negative, tick articles."
10590   (interactive "P")
10591   (when unmark
10592     (setq unmark (prefix-numeric-value unmark)))
10593   (let ((count
10594          (gnus-summary-mark-same-subject
10595           (gnus-summary-article-subject) unmark)))
10596     ;; Select next unread article.  If auto-select-same mode, should
10597     ;; select the first unread article.
10598     (gnus-summary-next-article t (and gnus-auto-select-same
10599                                       (gnus-summary-article-subject)))
10600     (gnus-message 7 "%d article%s marked as %s"
10601                   count (if (= count 1) " is" "s are")
10602                   (if unmark "unread" "read"))))
10603
10604 (defun gnus-summary-kill-same-subject (&optional unmark)
10605   "Mark articles which has the same subject as read.
10606 If UNMARK is positive, remove any kind of mark.
10607 If UNMARK is negative, tick articles."
10608   (interactive "P")
10609   (when unmark
10610     (setq unmark (prefix-numeric-value unmark)))
10611   (let ((count
10612          (gnus-summary-mark-same-subject
10613           (gnus-summary-article-subject) unmark)))
10614     ;; If marked as read, go to next unread subject.
10615     (when (null unmark)
10616       ;; Go to next unread subject.
10617       (gnus-summary-next-subject 1 t))
10618     (gnus-message 7 "%d articles are marked as %s"
10619                   count (if unmark "unread" "read"))))
10620
10621 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10622   "Mark articles with same SUBJECT as read, and return marked number.
10623 If optional argument UNMARK is positive, remove any kinds of marks.
10624 If optional argument UNMARK is negative, mark articles as unread instead."
10625   (let ((count 1))
10626     (save-excursion
10627       (cond
10628        ((null unmark)                   ; Mark as read.
10629         (while (and
10630                 (progn
10631                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10632                   (gnus-summary-show-thread) t)
10633                 (gnus-summary-find-subject subject))
10634           (setq count (1+ count))))
10635        ((> unmark 0)                    ; Tick.
10636         (while (and
10637                 (progn
10638                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10639                   (gnus-summary-show-thread) t)
10640                 (gnus-summary-find-subject subject))
10641           (setq count (1+ count))))
10642        (t                               ; Mark as unread.
10643         (while (and
10644                 (progn
10645                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10646                   (gnus-summary-show-thread) t)
10647                 (gnus-summary-find-subject subject))
10648           (setq count (1+ count)))))
10649       (gnus-set-mode-line 'summary)
10650       ;; Return the number of marked articles.
10651       count)))
10652
10653 (defun gnus-summary-mark-as-processable (n &optional unmark)
10654   "Set the process mark on the next N articles.
10655 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10656 the process mark instead.  The difference between N and the actual
10657 number of articles marked is returned."
10658   (interactive "P")
10659   (if (and (null n) (gnus-region-active-p))
10660       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10661     (setq n (prefix-numeric-value n))
10662     (let ((backward (< n 0))
10663           (n (abs n)))
10664       (while (and
10665               (> n 0)
10666               (if unmark
10667                   (gnus-summary-remove-process-mark
10668                    (gnus-summary-article-number))
10669                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10670               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10671         (setq n (1- n)))
10672       (when (/= 0 n)
10673         (gnus-message 7 "No more articles"))
10674       (gnus-summary-recenter)
10675       (gnus-summary-position-point)
10676       n)))
10677
10678 (defun gnus-summary-unmark-as-processable (n)
10679   "Remove the process mark from the next N articles.
10680 If N is negative, unmark backward instead.  The difference between N and
10681 the actual number of articles unmarked is returned."
10682   (interactive "P")
10683   (gnus-summary-mark-as-processable n t))
10684
10685 (defun gnus-summary-unmark-all-processable ()
10686   "Remove the process mark from all articles."
10687   (interactive)
10688   (save-excursion
10689     (while gnus-newsgroup-processable
10690       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10691   (gnus-summary-position-point))
10692
10693 (defun gnus-summary-add-mark (article type)
10694   "Mark ARTICLE with a mark of TYPE."
10695   (let ((vtype (car (assq type gnus-article-mark-lists)))
10696         var)
10697     (if (not vtype)
10698         (error "No such mark type: %s" type)
10699       (setq var (intern (format "gnus-newsgroup-%s" type)))
10700       (set var (cons article (symbol-value var)))
10701       (if (memq type '(processable cached replied forwarded recent saved))
10702           (gnus-summary-update-secondary-mark article)
10703         ;;; !!! This is bogus.  We should find out what primary
10704         ;;; !!! mark we want to set.
10705         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10706
10707 (defun gnus-summary-mark-as-expirable (n)
10708   "Mark N articles forward as expirable.
10709 If N is negative, mark backward instead.  The difference between N and
10710 the actual number of articles marked is returned."
10711   (interactive "p")
10712   (gnus-summary-mark-forward n gnus-expirable-mark))
10713
10714 (defun gnus-summary-mark-as-spam (n)
10715   "Mark N articles forward as spam.
10716 If N is negative, mark backward instead.  The difference between N and
10717 the actual number of articles marked is returned."
10718   (interactive "p")
10719   (gnus-summary-mark-forward n gnus-spam-mark))
10720
10721 (defun gnus-summary-mark-article-as-replied (article)
10722   "Mark ARTICLE as replied to and update the summary line.
10723 ARTICLE can also be a list of articles."
10724   (interactive (list (gnus-summary-article-number)))
10725   (let ((articles (if (listp article) article (list article))))
10726     (dolist (article articles)
10727       (unless (numberp article)
10728         (error "%s is not a number" article))
10729       (push article gnus-newsgroup-replied)
10730       (let ((inhibit-read-only t))
10731         (when (gnus-summary-goto-subject article nil t)
10732           (gnus-summary-update-secondary-mark article))))))
10733
10734 (defun gnus-summary-mark-article-as-forwarded (article)
10735   "Mark ARTICLE as forwarded and update the summary line.
10736 ARTICLE can also be a list of articles."
10737   (let ((articles (if (listp article) article (list article))))
10738     (dolist (article articles)
10739       (push article gnus-newsgroup-forwarded)
10740       (let ((inhibit-read-only t))
10741         (when (gnus-summary-goto-subject article nil t)
10742           (gnus-summary-update-secondary-mark article))))))
10743
10744 (defun gnus-summary-set-bookmark (article)
10745   "Set a bookmark in current article."
10746   (interactive (list (gnus-summary-article-number)))
10747   (when (or (not (get-buffer gnus-article-buffer))
10748             (not gnus-current-article)
10749             (not gnus-article-current)
10750             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10751     (error "No current article selected"))
10752   ;; Remove old bookmark, if one exists.
10753   (gnus-alist-pull article gnus-newsgroup-bookmarks)
10754   ;; Set the new bookmark, which is on the form
10755   ;; (article-number . line-number-in-body).
10756   (push
10757    (cons article
10758          (with-current-buffer gnus-article-buffer
10759            (count-lines
10760             (min (point)
10761                  (save-excursion
10762                    (article-goto-body)
10763                    (point)))
10764             (point))))
10765    gnus-newsgroup-bookmarks)
10766   (gnus-message 6 "A bookmark has been added to the current article."))
10767
10768 (defun gnus-summary-remove-bookmark (article)
10769   "Remove the bookmark from the current article."
10770   (interactive (list (gnus-summary-article-number)))
10771   ;; Remove old bookmark, if one exists.
10772   (if (not (assq article gnus-newsgroup-bookmarks))
10773       (gnus-message 6 "No bookmark in current article.")
10774     (gnus-alist-pull article gnus-newsgroup-bookmarks)
10775     (gnus-message 6 "Removed bookmark.")))
10776
10777 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10778 (defun gnus-summary-mark-as-dormant (n)
10779   "Mark N articles forward as dormant.
10780 If N is negative, mark backward instead.  The difference between N and
10781 the actual number of articles marked is returned."
10782   (interactive "p")
10783   (gnus-summary-mark-forward n gnus-dormant-mark))
10784
10785 (defun gnus-summary-set-process-mark (article)
10786   "Set the process mark on ARTICLE and update the summary line."
10787   (setq gnus-newsgroup-processable
10788         (cons article
10789               (delq article gnus-newsgroup-processable)))
10790   (when (gnus-summary-goto-subject article)
10791     (gnus-summary-show-thread)
10792     (gnus-summary-goto-subject article)
10793     (gnus-summary-update-secondary-mark article)))
10794
10795 (defun gnus-summary-remove-process-mark (&rest articles)
10796   "Remove the process mark from ARTICLES and update the summary line."
10797   (dolist (article articles)
10798     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10799     (when (gnus-summary-goto-subject article)
10800       (gnus-summary-show-thread)
10801       (gnus-summary-goto-subject article)
10802       (gnus-summary-update-secondary-mark article)))
10803   t)
10804
10805 (defun gnus-summary-set-saved-mark (article)
10806   "Set the process mark on ARTICLE and update the summary line."
10807   (push article gnus-newsgroup-saved)
10808   (when (gnus-summary-goto-subject article)
10809     (gnus-summary-update-secondary-mark article)))
10810
10811 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10812   "Mark N articles as read forwards.
10813 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10814 The difference between N and the actual number of articles marked is
10815 returned.
10816 If NO-EXPIRE, auto-expiry will be inhibited."
10817   (interactive "p")
10818   (gnus-summary-show-thread)
10819   (let ((backward (< n 0))
10820         (gnus-summary-goto-unread
10821          (and gnus-summary-goto-unread
10822               (not (eq gnus-summary-goto-unread 'never))
10823               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10824                                     gnus-ticked-mark gnus-dormant-mark)))))
10825         (n (abs n))
10826         (mark (or mark gnus-del-mark)))
10827     (while (and (> n 0)
10828                 (gnus-summary-mark-article nil mark no-expire)
10829                 (zerop (gnus-summary-next-subject
10830                         (if backward -1 1)
10831                         (and gnus-summary-goto-unread
10832                              (not (eq gnus-summary-goto-unread 'never)))
10833                         t)))
10834       (setq n (1- n)))
10835     (when (/= 0 n)
10836       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10837     (gnus-summary-recenter)
10838     (gnus-summary-position-point)
10839     (gnus-set-mode-line 'summary)
10840     n))
10841
10842 (defun gnus-summary-mark-article-as-read (mark)
10843   "Mark the current article quickly as read with MARK."
10844   (let ((article (gnus-summary-article-number)))
10845     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10846     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10847     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10848     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10849     (push (cons article mark) gnus-newsgroup-reads)
10850     ;; Possibly remove from cache, if that is used.
10851     (when gnus-use-cache
10852       (gnus-cache-enter-remove-article article))
10853     ;; Allow the backend to change the mark.
10854     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10855     ;; Check for auto-expiry.
10856     (when (and gnus-newsgroup-auto-expire
10857                (memq mark gnus-auto-expirable-marks))
10858       (setq mark gnus-expirable-mark)
10859       ;; Let the backend know about the mark change.
10860       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10861       (push article gnus-newsgroup-expirable))
10862     ;; Set the mark in the buffer.
10863     (gnus-summary-update-mark mark 'unread)
10864     t))
10865
10866 (defun gnus-summary-mark-article-as-unread (mark)
10867   "Mark the current article quickly as unread with MARK."
10868   (let* ((article (gnus-summary-article-number))
10869          (old-mark (gnus-summary-article-mark article)))
10870     ;; Allow the backend to change the mark.
10871     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10872     (if (eq mark old-mark)
10873         t
10874       (if (<= article 0)
10875           (progn
10876             (gnus-error 1 "Can't mark negative article numbers")
10877             nil)
10878         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10879         (setq gnus-newsgroup-spam-marked
10880               (delq article gnus-newsgroup-spam-marked))
10881         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10882         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10883         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10884         (cond ((= mark gnus-ticked-mark)
10885                (setq gnus-newsgroup-marked
10886                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10887                                               article)))
10888               ((= mark gnus-spam-mark)
10889                (setq gnus-newsgroup-spam-marked
10890                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10891                                               article)))
10892               ((= mark gnus-dormant-mark)
10893                (setq gnus-newsgroup-dormant
10894                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10895                                               article)))
10896               (t
10897                (setq gnus-newsgroup-unreads
10898                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10899                                               article))))
10900         (gnus-alist-pull article gnus-newsgroup-reads)
10901
10902         ;; See whether the article is to be put in the cache.
10903         (and gnus-use-cache
10904              (vectorp (gnus-summary-article-header article))
10905              (save-excursion
10906                (gnus-cache-possibly-enter-article
10907                 gnus-newsgroup-name article
10908                 (= mark gnus-ticked-mark)
10909                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10910
10911         ;; Fix the mark.
10912         (gnus-summary-update-mark mark 'unread)
10913         t))))
10914
10915 (defun gnus-summary-mark-article (&optional article mark no-expire)
10916   "Mark ARTICLE with MARK.  MARK can be any character.
10917 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10918 `??' (dormant) and `?E' (expirable).
10919 If MARK is nil, then the default character `?r' is used.
10920 If ARTICLE is nil, then the article on the current line will be
10921 marked.
10922 If NO-EXPIRE, auto-expiry will be inhibited."
10923   ;; The mark might be a string.
10924   (when (stringp mark)
10925     (setq mark (aref mark 0)))
10926   ;; If no mark is given, then we check auto-expiring.
10927   (when (null mark)
10928     (setq mark gnus-del-mark))
10929   (when (and (not no-expire)
10930              gnus-newsgroup-auto-expire
10931              (memq mark gnus-auto-expirable-marks))
10932     (setq mark gnus-expirable-mark))
10933   (let ((article (or article (gnus-summary-article-number)))
10934         (old-mark (gnus-summary-article-mark article)))
10935     ;; Allow the backend to change the mark.
10936     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10937     (if (eq mark old-mark)
10938         t
10939       (unless article
10940         (error "No article on current line"))
10941       (if (not (if (or (= mark gnus-unread-mark)
10942                        (= mark gnus-ticked-mark)
10943                        (= mark gnus-spam-mark)
10944                        (= mark gnus-dormant-mark))
10945                    (gnus-mark-article-as-unread article mark)
10946                  (gnus-mark-article-as-read article mark)))
10947           t
10948         ;; See whether the article is to be put in the cache.
10949         (and gnus-use-cache
10950              (not (= mark gnus-canceled-mark))
10951              (vectorp (gnus-summary-article-header article))
10952              (save-excursion
10953                (gnus-cache-possibly-enter-article
10954                 gnus-newsgroup-name article
10955                 (= mark gnus-ticked-mark)
10956                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10957
10958         (when (gnus-summary-goto-subject article nil t)
10959           (let ((inhibit-read-only t))
10960             (gnus-summary-show-thread)
10961             ;; Fix the mark.
10962             (gnus-summary-update-mark mark 'unread)
10963             t))))))
10964
10965 (defun gnus-summary-update-secondary-mark (article)
10966   "Update the secondary (read, process, cache) mark."
10967   (gnus-summary-update-mark
10968    (cond ((memq article gnus-newsgroup-processable)
10969           gnus-process-mark)
10970          ((memq article gnus-newsgroup-cached)
10971           gnus-cached-mark)
10972          ((memq article gnus-newsgroup-replied)
10973           gnus-replied-mark)
10974          ((memq article gnus-newsgroup-forwarded)
10975           gnus-forwarded-mark)
10976          ((memq article gnus-newsgroup-saved)
10977           gnus-saved-mark)
10978          ((memq article gnus-newsgroup-recent)
10979           gnus-recent-mark)
10980          ((memq article gnus-newsgroup-unseen)
10981           gnus-unseen-mark)
10982          (t gnus-no-mark))
10983    'replied)
10984   (when (gnus-visual-p 'summary-highlight 'highlight)
10985     (gnus-summary-highlight-line)
10986     (gnus-run-hooks 'gnus-summary-update-hook))
10987   t)
10988
10989 (defun gnus-summary-update-download-mark (article)
10990   "Update the download mark."
10991   (gnus-summary-update-mark
10992    (cond ((memq article gnus-newsgroup-undownloaded)
10993           gnus-undownloaded-mark)
10994          (gnus-newsgroup-agentized
10995           gnus-downloaded-mark)
10996          (t
10997           gnus-no-mark))
10998    'download)
10999   (gnus-summary-update-line t)
11000   t)
11001
11002 (defun gnus-summary-update-mark (mark type)
11003   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
11004         (inhibit-read-only t))
11005     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
11006     (when forward
11007       (when (looking-at "\r")
11008         (incf forward))
11009       (when (<= (+ forward (point)) (point-max))
11010         ;; Go to the right position on the line.
11011         (goto-char (+ forward (point)))
11012         ;; Replace the old mark with the new mark.
11013         (let ((to-insert
11014                (mm-subst-char-in-string
11015                 (char-after) mark
11016                 (buffer-substring (point) (1+ (point))))))
11017           (delete-region (point) (1+ (point)))
11018           (insert to-insert))
11019         ;; Optionally update the marks by some user rule.
11020         (when (eq type 'unread)
11021           (gnus-data-set-mark
11022            (gnus-data-find (gnus-summary-article-number)) mark)
11023           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
11024
11025 (defun gnus-mark-article-as-read (article &optional mark)
11026   "Enter ARTICLE in the pertinent lists and remove it from others."
11027   ;; Make the article expirable.
11028   (let ((mark (or mark gnus-del-mark)))
11029     (setq gnus-newsgroup-expirable
11030           (if (= mark gnus-expirable-mark)
11031               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
11032             (delq article gnus-newsgroup-expirable)))
11033     ;; Remove from unread and marked lists.
11034     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
11035     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
11036     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
11037     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
11038     (push (cons article mark) gnus-newsgroup-reads)
11039     ;; Possibly remove from cache, if that is used.
11040     (when gnus-use-cache
11041       (gnus-cache-enter-remove-article article))
11042     t))
11043
11044 (defun gnus-mark-article-as-unread (article &optional mark)
11045   "Enter ARTICLE in the pertinent lists and remove it from others."
11046   (let ((mark (or mark gnus-ticked-mark)))
11047     (if (<= article 0)
11048         (progn
11049           (gnus-error 1 "Can't mark negative article numbers")
11050           nil)
11051       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
11052             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
11053             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
11054             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
11055             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
11056
11057       ;; Unsuppress duplicates?
11058       (when gnus-suppress-duplicates
11059         (gnus-dup-unsuppress-article article))
11060
11061       (cond ((= mark gnus-ticked-mark)
11062              (setq gnus-newsgroup-marked
11063                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
11064             ((= mark gnus-spam-mark)
11065              (setq gnus-newsgroup-spam-marked
11066                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
11067                                             article)))
11068             ((= mark gnus-dormant-mark)
11069              (setq gnus-newsgroup-dormant
11070                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
11071             (t
11072              (setq gnus-newsgroup-unreads
11073                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
11074       (gnus-alist-pull article gnus-newsgroup-reads)
11075       t)))
11076
11077 (defun gnus-summary-tick-article-forward (n)
11078   "Tick N articles forwards.
11079 If N is negative, tick backwards instead.
11080 The difference between N and the number of articles ticked is returned."
11081   (interactive "p")
11082   (gnus-summary-mark-forward n gnus-ticked-mark))
11083
11084 (defun gnus-summary-tick-article-backward (n)
11085   "Tick N articles backwards.
11086 The difference between N and the number of articles ticked is returned."
11087   (interactive "p")
11088   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
11089
11090 (defun gnus-summary-tick-article (&optional article clear-mark)
11091   "Mark current article as unread.
11092 Optional 1st argument ARTICLE specifies article number to be marked as unread.
11093 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
11094   (interactive)
11095   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
11096                                        gnus-ticked-mark)))
11097
11098 (defun gnus-summary-mark-as-read-forward (n)
11099   "Mark N articles as read forwards.
11100 If N is negative, mark backwards instead.
11101 The difference between N and the actual number of articles marked is
11102 returned."
11103   (interactive "p")
11104   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
11105
11106 (defun gnus-summary-mark-as-read-backward (n)
11107   "Mark the N articles as read backwards.
11108 The difference between N and the actual number of articles marked is
11109 returned."
11110   (interactive "p")
11111   (gnus-summary-mark-forward
11112    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
11113
11114 (defun gnus-summary-mark-as-read (&optional article mark)
11115   "Mark current article as read.
11116 ARTICLE specifies the article to be marked as read.
11117 MARK specifies a string to be inserted at the beginning of the line."
11118   (gnus-summary-mark-article article mark))
11119
11120 (defun gnus-summary-clear-mark-forward (n)
11121   "Clear marks from N articles forward.
11122 If N is negative, clear backward instead.
11123 The difference between N and the number of marks cleared is returned."
11124   (interactive "p")
11125   (gnus-summary-mark-forward n gnus-unread-mark))
11126
11127 (defun gnus-summary-clear-mark-backward (n)
11128   "Clear marks from N articles backward.
11129 The difference between N and the number of marks cleared is returned."
11130   (interactive "p")
11131   (gnus-summary-mark-forward (- n) gnus-unread-mark))
11132
11133 (defun gnus-summary-mark-unread-as-read ()
11134   "Intended to be used by `gnus-mark-article-hook'."
11135   (when (memq gnus-current-article gnus-newsgroup-unreads)
11136     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
11137
11138 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
11139   "Intended to be used by `gnus-mark-article-hook'."
11140   (let ((mark (gnus-summary-article-mark)))
11141     (when (or (gnus-unread-mark-p mark)
11142               (gnus-read-mark-p mark))
11143       (gnus-summary-mark-article gnus-current-article
11144                                  (or new-mark gnus-read-mark)))))
11145
11146 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
11147   "Intended to be used by `gnus-mark-article-hook'."
11148   (let ((mark (gnus-summary-article-mark)))
11149     (when (or (gnus-unread-mark-p mark)
11150               (gnus-read-mark-p mark))
11151       (gnus-summary-mark-article (gnus-summary-article-number)
11152                                  (or new-mark gnus-read-mark)))))
11153
11154 (defun gnus-summary-mark-unread-as-ticked ()
11155   "Intended to be used by `gnus-mark-article-hook'."
11156   (when (memq gnus-current-article gnus-newsgroup-unreads)
11157     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
11158
11159 (defun gnus-summary-mark-region-as-read (point mark all)
11160   "Mark all unread articles between point and mark as read.
11161 If given a prefix, mark all articles between point and mark as read,
11162 even ticked and dormant ones."
11163   (interactive "r\nP")
11164   (save-excursion
11165     (let (article)
11166       (goto-char point)
11167       (beginning-of-line)
11168       (while (and
11169               (< (point) mark)
11170               (progn
11171                 (when (or all
11172                           (memq (setq article (gnus-summary-article-number))
11173                                 gnus-newsgroup-unreads))
11174                   (gnus-summary-mark-article article gnus-del-mark))
11175                 t)
11176               (gnus-summary-find-next))))))
11177
11178 (defun gnus-summary-mark-below (score mark)
11179   "Mark articles with score less than SCORE with MARK."
11180   (interactive "P\ncMark: ")
11181   (setq score (if score
11182                   (prefix-numeric-value score)
11183                 (or gnus-summary-default-score 0)))
11184   (with-current-buffer gnus-summary-buffer
11185     (goto-char (point-min))
11186     (while
11187         (progn
11188           (and (< (gnus-summary-article-score) score)
11189                (gnus-summary-mark-article nil mark))
11190           (gnus-summary-find-next)))))
11191
11192 (defun gnus-summary-kill-below (&optional score)
11193   "Mark articles with score below SCORE as read."
11194   (interactive "P")
11195   (gnus-summary-mark-below score gnus-killed-mark))
11196
11197 (defun gnus-summary-clear-above (&optional score)
11198   "Clear all marks from articles with score above SCORE."
11199   (interactive "P")
11200   (gnus-summary-mark-above score gnus-unread-mark))
11201
11202 (defun gnus-summary-tick-above (&optional score)
11203   "Tick all articles with score above SCORE."
11204   (interactive "P")
11205   (gnus-summary-mark-above score gnus-ticked-mark))
11206
11207 (defun gnus-summary-mark-above (score mark)
11208   "Mark articles with score over SCORE with MARK."
11209   (interactive "P\ncMark: ")
11210   (setq score (if score
11211                   (prefix-numeric-value score)
11212                 (or gnus-summary-default-score 0)))
11213   (with-current-buffer gnus-summary-buffer
11214     (goto-char (point-min))
11215     (while (and (progn
11216                   (when (> (gnus-summary-article-score) score)
11217                     (gnus-summary-mark-article nil mark))
11218                   t)
11219                 (gnus-summary-find-next)))))
11220
11221 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
11222 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
11223 (defun gnus-summary-limit-include-expunged (&optional no-error)
11224   "Display all the hidden articles that were expunged for low scores."
11225   (interactive)
11226   (let ((inhibit-read-only t))
11227     (let ((scored gnus-newsgroup-scored)
11228           headers h)
11229       (while scored
11230         (unless (gnus-summary-article-header (caar scored))
11231           (and (setq h (gnus-number-to-header (caar scored)))
11232                (< (cdar scored) gnus-summary-expunge-below)
11233                (push h headers)))
11234         (setq scored (cdr scored)))
11235       (if (not headers)
11236           (when (not no-error)
11237             (error "No expunged articles hidden"))
11238         (goto-char (point-min))
11239         (push gnus-newsgroup-limit gnus-newsgroup-limits)
11240         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
11241         (dolist (x headers)
11242           (push (mail-header-number x) gnus-newsgroup-limit))
11243         (gnus-summary-prepare-unthreaded (nreverse headers))
11244         (goto-char (point-min))
11245         (gnus-summary-position-point)
11246         t))))
11247
11248 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
11249   "Mark all unread articles in this newsgroup as read.
11250 If prefix argument ALL is non-nil, ticked and dormant articles will
11251 also be marked as read.
11252 If QUIETLY is non-nil, no questions will be asked.
11253
11254 If TO-HERE is non-nil, it should be a point in the buffer.  All
11255 articles before (after, if REVERSE is set) this point will be marked
11256 as read.
11257
11258 Note that this function will only catch up the unread article
11259 in the current summary buffer limitation.
11260
11261 The number of articles marked as read is returned."
11262   (interactive "P")
11263   (prog1
11264       (save-excursion
11265         (when (or quietly
11266                   (not gnus-interactive-catchup) ;Without confirmation?
11267                   gnus-expert-user
11268                   (gnus-y-or-n-p
11269                    (if all
11270                        "Mark absolutely all articles as read? "
11271                      "Mark all unread articles as read? ")))
11272           (if (and not-mark
11273                    (not gnus-newsgroup-adaptive)
11274                    (not gnus-newsgroup-auto-expire)
11275                    (not gnus-suppress-duplicates)
11276                    (or (not gnus-use-cache)
11277                        (eq gnus-use-cache 'passive)))
11278               (progn
11279                 (when all
11280                   (setq gnus-newsgroup-marked nil
11281                         gnus-newsgroup-spam-marked nil
11282                         gnus-newsgroup-dormant nil))
11283                 (setq gnus-newsgroup-unreads
11284                       (gnus-sorted-nunion
11285                        (gnus-sorted-intersection gnus-newsgroup-unreads
11286                                                  gnus-newsgroup-downloadable)
11287                        (gnus-sorted-difference gnus-newsgroup-unfetched
11288                                                gnus-newsgroup-cached))))
11289             ;; We actually mark all articles as canceled, which we
11290             ;; have to do when using auto-expiry or adaptive scoring.
11291             (gnus-summary-show-all-threads)
11292             (if (and to-here reverse)
11293                 (progn
11294                   (goto-char to-here)
11295                   (gnus-summary-mark-current-read-and-unread-as-read
11296                    gnus-catchup-mark)
11297                   (while (gnus-summary-find-next (not all))
11298                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
11299               (when (gnus-summary-first-subject (not all))
11300                 (while (and
11301                         (if to-here (< (point) to-here) t)
11302                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
11303                         (gnus-summary-find-next (not all))))))
11304             (gnus-set-mode-line 'summary))
11305           t))
11306     (gnus-summary-position-point)))
11307
11308 (defun gnus-summary-catchup-to-here (&optional all)
11309   "Mark all unticked articles before the current one as read.
11310 If ALL is non-nil, also mark ticked and dormant articles as read."
11311   (interactive "P")
11312   (save-excursion
11313     (gnus-save-hidden-threads
11314       (let ((beg (point)))
11315         ;; We check that there are unread articles.
11316         (when (or all (gnus-summary-find-prev))
11317           (gnus-summary-catchup all t beg)))))
11318   (gnus-summary-position-point))
11319
11320 (defun gnus-summary-catchup-from-here (&optional all)
11321   "Mark all unticked articles after (and including) the current one as read.
11322 If ALL is non-nil, also mark ticked and dormant articles as read."
11323   (interactive "P")
11324   (save-excursion
11325     (gnus-save-hidden-threads
11326       (let ((beg (point)))
11327         ;; We check that there are unread articles.
11328         (when (or all (gnus-summary-find-next))
11329           (gnus-summary-catchup all t beg nil t)))))
11330   (gnus-summary-position-point))
11331
11332 (defun gnus-summary-catchup-all (&optional quietly)
11333   "Mark all articles in this newsgroup as read.
11334 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11335 instead, which marks only unread articles as read."
11336   (interactive "P")
11337   (gnus-summary-catchup t quietly))
11338
11339 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11340   "Mark all unread articles in this group as read, then exit.
11341 If prefix argument ALL is non-nil, all articles are marked as read.
11342 If QUIETLY is non-nil, no questions will be asked."
11343   (interactive "P")
11344   (when (gnus-summary-catchup all quietly nil 'fast)
11345     ;; Select next newsgroup or exit.
11346     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11347              (eq gnus-auto-select-next 'quietly))
11348         (gnus-summary-next-group nil)
11349       (gnus-summary-exit))))
11350
11351 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11352   "Mark all articles in this newsgroup as read, and then exit.
11353 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11354 instead, which marks only unread articles as read."
11355   (interactive "P")
11356   (gnus-summary-catchup-and-exit t quietly))
11357
11358 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11359   "Mark all articles in this group as read and select the next group.
11360 If given a prefix, mark all articles, unread as well as ticked, as
11361 read."
11362   (interactive "P")
11363   (save-excursion
11364     (gnus-summary-catchup all))
11365   (gnus-summary-next-group))
11366
11367 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11368   "Mark all articles in this group as read and select the previous group.
11369 If given a prefix, mark all articles, unread as well as ticked, as
11370 read."
11371   (interactive "P")
11372   (save-excursion
11373     (gnus-summary-catchup all))
11374   (gnus-summary-next-group nil nil t))
11375
11376 ;;;
11377 ;;; with article
11378 ;;;
11379
11380 (defmacro gnus-with-article (article &rest forms)
11381   "Select ARTICLE and perform FORMS in the original article buffer.
11382 Then replace the article with the result."
11383   `(progn
11384      ;; We don't want the article to be marked as read.
11385      (let (gnus-mark-article-hook)
11386        (gnus-summary-select-article t t nil ,article))
11387      (set-buffer gnus-original-article-buffer)
11388      ,@forms
11389      (if (not (gnus-check-backend-function
11390                'request-replace-article (car gnus-article-current)))
11391          (gnus-message 5 "Read-only group; not replacing")
11392        (unless (gnus-request-replace-article
11393                 ,article (car gnus-article-current)
11394                 (current-buffer) t)
11395          (error "Couldn't replace article")))
11396      ;; The cache and backlog have to be flushed somewhat.
11397      (when gnus-keep-backlog
11398        (gnus-backlog-remove-article
11399         (car gnus-article-current) (cdr gnus-article-current)))
11400      (when gnus-use-cache
11401        (gnus-cache-update-article
11402         (car gnus-article-current) (cdr gnus-article-current)))))
11403
11404 (put 'gnus-with-article 'lisp-indent-function 1)
11405 (put 'gnus-with-article 'edebug-form-spec '(form body))
11406
11407 ;; Thread-based commands.
11408
11409 (defun gnus-summary-articles-in-thread (&optional article)
11410   "Return a list of all articles in the current thread.
11411 If ARTICLE is non-nil, return all articles in the thread that starts
11412 with that article."
11413   (let* ((article (or article (gnus-summary-article-number)))
11414          (data (gnus-data-find-list article))
11415          (top-level (gnus-data-level (car data)))
11416          (top-subject
11417           (cond ((null gnus-thread-operation-ignore-subject)
11418                  (gnus-simplify-subject-re
11419                   (mail-header-subject (gnus-data-header (car data)))))
11420                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11421                  (gnus-simplify-subject-fuzzy
11422                   (mail-header-subject (gnus-data-header (car data)))))
11423                 (t nil)))
11424          (end-point (save-excursion
11425                       (goto-char (gnus-data-pos (car data)))
11426                       (if (gnus-summary-go-to-next-thread)
11427                           (point) (point-max))))
11428          articles)
11429     (while (and data
11430                 (< (gnus-data-pos (car data)) end-point))
11431       (when (or (not top-subject)
11432                 (string= top-subject
11433                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11434                              (gnus-simplify-subject-fuzzy
11435                               (mail-header-subject
11436                                (gnus-data-header (car data))))
11437                            (gnus-simplify-subject-re
11438                             (mail-header-subject
11439                              (gnus-data-header (car data)))))))
11440         (push (gnus-data-number (car data)) articles))
11441       (unless (and (setq data (cdr data))
11442                    (> (gnus-data-level (car data)) top-level))
11443         (setq data nil)))
11444     ;; Return the list of articles.
11445     (nreverse articles)))
11446
11447 (defun gnus-summary-rethread-current ()
11448   "Rethread the thread the current article is part of."
11449   (interactive)
11450   (let* ((gnus-show-threads t)
11451          (article (gnus-summary-article-number))
11452          (id (mail-header-id (gnus-summary-article-header)))
11453          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11454     (unless id
11455       (error "No article on the current line"))
11456     (gnus-rebuild-thread id)
11457     (gnus-summary-goto-subject article)))
11458
11459 (defun gnus-summary-reparent-thread ()
11460   "Make the current article child of the marked (or previous) article.
11461
11462 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11463 is non-nil or the Subject: of both articles are the same."
11464   (interactive)
11465   (unless (not (gnus-group-read-only-p))
11466     (error "The current newsgroup does not support article editing"))
11467   (unless (<= (length gnus-newsgroup-processable) 1)
11468     (error "No more than one article may be marked"))
11469   (let ((child (gnus-summary-article-number))
11470         ;; First grab the marked article, otherwise one line up.
11471         (parent (if (not (null gnus-newsgroup-processable))
11472                     (car gnus-newsgroup-processable)
11473                   (save-excursion
11474                     (if (eq (forward-line -1) 0)
11475                         (gnus-summary-article-number)
11476                       (error "Beginning of summary buffer"))))))
11477     (gnus-summary-reparent-children parent (list child))))
11478
11479 (defun gnus-summary-reparent-children (parent children)
11480   "Make PARENT the parent of CHILDREN.
11481 When called interactively, PARENT is the current article and CHILDREN
11482 are the process-marked articles."
11483   (interactive
11484    (list (gnus-summary-article-number)
11485          (gnus-summary-work-articles nil)))
11486   (dolist (child children)
11487     (save-window-excursion
11488       (let ((gnus-article-buffer " *reparent*"))
11489         (unless (not (eq parent child))
11490           (error "An article may not be self-referential"))
11491         (let ((message-id (mail-header-id
11492                            (gnus-summary-article-header parent))))
11493           (unless (and message-id (not (equal message-id "")))
11494             (error "No message-id in desired parent"))
11495           (gnus-with-article child
11496             (save-restriction
11497               (goto-char (point-min))
11498               (message-narrow-to-head)
11499               (if (re-search-forward "^References: " nil t)
11500                   (progn
11501                     (re-search-forward "^[^ \t]" nil t)
11502                     (forward-line -1)
11503                     (end-of-line)
11504                     (insert " " message-id))
11505                 (insert "References: " message-id "\n"))))
11506           (set-buffer gnus-summary-buffer)
11507           (gnus-summary-unmark-all-processable)
11508           (gnus-summary-update-article child)
11509           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11510             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11511           (gnus-summary-rethread-current)
11512           (gnus-message 3 "Article %d is now the child of article %d"
11513                         child parent))))))
11514
11515 (defun gnus-summary-toggle-threads (&optional arg)
11516   "Toggle showing conversation threads.
11517 If ARG is positive number, turn showing conversation threads on."
11518   (interactive "P")
11519   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11520     (setq gnus-show-threads
11521           (if (null arg) (not gnus-show-threads)
11522             (> (prefix-numeric-value arg) 0)))
11523     (gnus-summary-prepare)
11524     (gnus-summary-goto-subject current)
11525     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11526     (gnus-summary-position-point)))
11527
11528 (eval-and-compile
11529   (if (fboundp 'remove-overlays)
11530       (defalias 'gnus-remove-overlays 'remove-overlays)
11531     (defun gnus-remove-overlays (beg end name val)
11532       "Clear BEG and END of overlays whose property NAME has value VAL.
11533 For compatibility with XEmacs."
11534       (dolist (ov (gnus-overlays-in beg end))
11535         (when (eq (gnus-overlay-get ov name) val)
11536           (gnus-delete-overlay ov))))))
11537
11538 (defun gnus-summary-show-all-threads ()
11539   "Show all threads."
11540   (interactive)
11541   (gnus-remove-overlays (point-min) (point-max) 'invisible 'gnus-sum)
11542   (gnus-summary-position-point))
11543
11544 (defsubst gnus-summary--inv (p)
11545   (and (eq (get-char-property p 'invisible) 'gnus-sum) p))
11546
11547 (defun gnus-summary-show-thread ()
11548   "Show thread subtrees.
11549 Returns nil if no thread was there to be shown."
11550   (interactive)
11551   (let* ((orig (point))
11552          (end (point-at-eol))
11553          (end (or (gnus-summary--inv end) (gnus-summary--inv (1- end))))
11554          ;; Leave point at bol
11555          (beg (progn (beginning-of-line) (if (bobp) (point) (1- (point)))))
11556          (eoi (when end
11557                 (if (fboundp 'next-single-char-property-change)
11558                     (or (next-single-char-property-change end 'invisible)
11559                         (point-max))
11560                   (while (progn
11561                            (end-of-line 2)
11562                            (and (not (eobp))
11563                                 (eq (get-char-property (point) 'invisible)
11564                                     'gnus-sum))))
11565                   (point)))))
11566     (when eoi
11567       (gnus-remove-overlays beg eoi 'invisible 'gnus-sum)
11568       (goto-char orig)
11569       (gnus-summary-position-point)
11570       eoi)))
11571
11572 (defun gnus-summary-maybe-hide-threads ()
11573   "If requested, hide the threads that should be hidden."
11574   (when (and gnus-show-threads
11575              gnus-thread-hide-subtree)
11576     (gnus-summary-hide-all-threads
11577      (if (or (consp gnus-thread-hide-subtree)
11578              (functionp gnus-thread-hide-subtree))
11579          (gnus-make-predicate gnus-thread-hide-subtree)
11580        nil))))
11581
11582 ;;; Hiding predicates.
11583
11584 (defun gnus-article-unread-p (header)
11585   (memq (mail-header-number header) gnus-newsgroup-unreads))
11586
11587 (defun gnus-article-unseen-p (header)
11588   (memq (mail-header-number header) gnus-newsgroup-unseen))
11589
11590 (defun gnus-map-articles (predicate articles)
11591   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11592   (apply 'gnus-or (mapcar predicate
11593                           (mapcar (lambda (number)
11594                                     (gnus-summary-article-header number))
11595                                   articles))))
11596
11597 (defun gnus-summary-hide-all-threads (&optional predicate)
11598   "Hide all thread subtrees.
11599 If PREDICATE is supplied, threads that satisfy this predicate
11600 will not be hidden."
11601   (interactive)
11602   (save-excursion
11603     (goto-char (point-min))
11604     (let ((end nil)
11605           (count 0))
11606       (while (not end)
11607         (incf count)
11608         (when (zerop (mod count 1000))
11609           (message "Hiding all threads... %d" count))
11610         (when (or (not predicate)
11611                   (gnus-map-articles
11612                    predicate (gnus-summary-article-children)))
11613             (gnus-summary-hide-thread))
11614         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11615   (gnus-summary-position-point))
11616
11617 (defun gnus-summary-hide-thread ()
11618   "Hide thread subtrees.
11619 If PREDICATE is supplied, threads that satisfy this predicate
11620 will not be hidden.
11621 Returns nil if no threads were there to be hidden."
11622   (interactive)
11623   (let ((start (point))
11624         (starteol (line-end-position))
11625         (article (gnus-summary-article-number)))
11626     (goto-char start)
11627     ;; Go forward until either the buffer ends or the subthread ends.
11628     (when (and (not (eobp))
11629                (or (zerop (gnus-summary-next-thread 1 t))
11630                    (goto-char (point-max))))
11631       (if (and (> (point) start)
11632                ;; FIXME: this should actually search for a non-invisible \n.
11633                (search-backward "\n" start t))
11634           (progn
11635             (when (> (point) starteol)
11636               (gnus-remove-overlays starteol (point) 'invisible 'gnus-sum)
11637               (let ((ol (gnus-make-overlay starteol (point) nil t nil)))
11638                 (gnus-overlay-put ol 'invisible 'gnus-sum)
11639                 (gnus-overlay-put ol 'evaporate t)))
11640             (gnus-summary-goto-subject article)
11641             (when (> start (point))
11642               (message "Hiding the thread moved us backwards, aborting!")
11643               (goto-char (point-max))))
11644         (goto-char start)
11645         nil))))
11646
11647 (defun gnus-summary-go-to-next-thread (&optional previous)
11648   "Go to the same level (or less) next thread.
11649 If PREVIOUS is non-nil, go to previous thread instead.
11650 Return the article number moved to, or nil if moving was impossible."
11651   (let ((level (gnus-summary-thread-level))
11652         (way (if previous -1 1))
11653         (beg (point)))
11654     (forward-line way)
11655     (while (and (not (eobp))
11656                 (< level (gnus-summary-thread-level)))
11657       (forward-line way))
11658     (if (eobp)
11659         (progn
11660           (goto-char beg)
11661           nil)
11662       (setq beg (point))
11663       (prog1
11664           (gnus-summary-article-number)
11665         (goto-char beg)))))
11666
11667 (defun gnus-summary-next-thread (n &optional silent)
11668   "Go to the same level next N'th thread.
11669 If N is negative, search backward instead.
11670 Returns the difference between N and the number of skips actually
11671 done.
11672
11673 If SILENT, don't output messages."
11674   (interactive "p")
11675   (let ((backward (< n 0))
11676         (n (abs n)))
11677     (while (and (> n 0)
11678                 (gnus-summary-go-to-next-thread backward))
11679       (decf n))
11680     (unless silent
11681       (gnus-summary-position-point))
11682     (when (and (not silent) (/= 0 n))
11683       (gnus-message 7 "No more threads"))
11684     n))
11685
11686 (defun gnus-summary-prev-thread (n)
11687   "Go to the same level previous N'th thread.
11688 Returns the difference between N and the number of skips actually
11689 done."
11690   (interactive "p")
11691   (gnus-summary-next-thread (- n)))
11692
11693 (defun gnus-summary-go-down-thread ()
11694   "Go down one level in the current thread."
11695   (let ((children (gnus-summary-article-children)))
11696     (when children
11697       (gnus-summary-goto-subject (car children)))))
11698
11699 (defun gnus-summary-go-up-thread ()
11700   "Go up one level in the current thread."
11701   (let ((parent (gnus-summary-article-parent)))
11702     (when parent
11703       (gnus-summary-goto-subject parent))))
11704
11705 (defun gnus-summary-down-thread (n)
11706   "Go down thread N steps.
11707 If N is negative, go up instead.
11708 Returns the difference between N and how many steps down that were
11709 taken."
11710   (interactive "p")
11711   (let ((up (< n 0))
11712         (n (abs n)))
11713     (while (and (> n 0)
11714                 (if up (gnus-summary-go-up-thread)
11715                   (gnus-summary-go-down-thread)))
11716       (setq n (1- n)))
11717     (gnus-summary-position-point)
11718     (when (/= 0 n)
11719       (gnus-message 7 "Can't go further"))
11720     n))
11721
11722 (defun gnus-summary-up-thread (n)
11723   "Go up thread N steps.
11724 If N is negative, go down instead.
11725 Returns the difference between N and how many steps down that were
11726 taken."
11727   (interactive "p")
11728   (gnus-summary-down-thread (- n)))
11729
11730 (defun gnus-summary-top-thread ()
11731   "Go to the top of the thread."
11732   (interactive)
11733   (while (gnus-summary-go-up-thread))
11734   (gnus-summary-article-number))
11735
11736 (defun gnus-summary-expire-thread ()
11737   "Mark articles under current thread as expired."
11738   (interactive)
11739   (gnus-summary-kill-thread 0))
11740
11741 (defun gnus-summary-kill-thread (&optional unmark)
11742   "Mark articles under current thread as read.
11743 If the prefix argument is positive, remove any kinds of marks.
11744 If the prefix argument is zero, mark thread as expired.
11745 If the prefix argument is negative, tick articles instead."
11746   (interactive "P")
11747   (when unmark
11748     (setq unmark (prefix-numeric-value unmark)))
11749   (let ((articles (gnus-summary-articles-in-thread))
11750         (hide (or (null unmark) (= unmark 0))))
11751     (save-excursion
11752       ;; Expand the thread.
11753       (gnus-summary-show-thread)
11754       ;; Mark all the articles.
11755       (while articles
11756         (gnus-summary-goto-subject (car articles))
11757         (cond ((null unmark)
11758                (gnus-summary-mark-article-as-read gnus-killed-mark))
11759               ((> unmark 0)
11760                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11761               ((= unmark 0)
11762                (gnus-summary-mark-article nil gnus-expirable-mark))
11763               (t
11764                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11765         (setq articles (cdr articles))))
11766     ;; Hide killed subtrees when hide is true.
11767     (and hide
11768          gnus-thread-hide-killed
11769          (gnus-summary-hide-thread))
11770     ;; If hide is t, go to next unread subject.
11771     (when hide
11772       ;; Go to next unread subject.
11773       (gnus-summary-next-subject 1 t)))
11774   (gnus-set-mode-line 'summary))
11775
11776 ;; Summary sorting commands
11777
11778 (defun gnus-summary-sort-by-number (&optional reverse)
11779   "Sort the summary buffer by article number.
11780 Argument REVERSE means reverse order."
11781   (interactive "P")
11782   (gnus-summary-sort 'number reverse))
11783
11784 (defun gnus-summary-sort-by-most-recent-number (&optional reverse)
11785   "Sort the summary buffer by most recent article number.
11786 Argument REVERSE means reverse order."
11787   (interactive "P")
11788   (gnus-summary-sort 'most-recent-number reverse))
11789
11790 (defun gnus-summary-sort-by-random (&optional reverse)
11791   "Randomize the order in the summary buffer.
11792 Argument REVERSE means to randomize in reverse order."
11793   (interactive "P")
11794   (gnus-summary-sort 'random reverse))
11795
11796 (defun gnus-summary-sort-by-author (&optional reverse)
11797   "Sort the summary buffer by author name alphabetically.
11798 If `case-fold-search' is non-nil, case of letters is ignored.
11799 Argument REVERSE means reverse order."
11800   (interactive "P")
11801   (gnus-summary-sort 'author reverse))
11802
11803 (defun gnus-summary-sort-by-recipient (&optional reverse)
11804   "Sort the summary buffer by recipient name alphabetically.
11805 If `case-fold-search' is non-nil, case of letters is ignored.
11806 Argument REVERSE means reverse order."
11807   (interactive "P")
11808   (gnus-summary-sort 'recipient reverse))
11809
11810 (defun gnus-summary-sort-by-subject (&optional reverse)
11811   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11812 If `case-fold-search' is non-nil, case of letters is ignored.
11813 Argument REVERSE means reverse order."
11814   (interactive "P")
11815   (gnus-summary-sort 'subject reverse))
11816
11817 (defun gnus-summary-sort-by-date (&optional reverse)
11818   "Sort the summary buffer by date.
11819 Argument REVERSE means reverse order."
11820   (interactive "P")
11821   (gnus-summary-sort 'date reverse))
11822
11823 (defun gnus-summary-sort-by-most-recent-date (&optional reverse)
11824   "Sort the summary buffer by most recent date.
11825 Argument REVERSE means reverse order."
11826   (interactive "P")
11827   (gnus-summary-sort 'most-recent-date reverse))
11828
11829 (defun gnus-summary-sort-by-score (&optional reverse)
11830   "Sort the summary buffer by score.
11831 Argument REVERSE means reverse order."
11832   (interactive "P")
11833   (gnus-summary-sort 'score reverse))
11834
11835 (defun gnus-summary-sort-by-lines (&optional reverse)
11836   "Sort the summary buffer by the number of lines.
11837 Argument REVERSE means reverse order."
11838   (interactive "P")
11839   (gnus-summary-sort 'lines reverse))
11840
11841 (defun gnus-summary-sort-by-chars (&optional reverse)
11842   "Sort the summary buffer by article length.
11843 Argument REVERSE means reverse order."
11844   (interactive "P")
11845   (gnus-summary-sort 'chars reverse))
11846
11847 (defun gnus-summary-sort-by-original (&optional reverse)
11848   "Sort the summary buffer using the default sorting method.
11849 Argument REVERSE means reverse order."
11850   (interactive "P")
11851   (let* ((inhibit-read-only t)
11852          (gnus-summary-prepare-hook nil))
11853     ;; We do the sorting by regenerating the threads.
11854     (gnus-summary-prepare)
11855     ;; Hide subthreads if needed.
11856     (gnus-summary-maybe-hide-threads)))
11857
11858 (defun gnus-summary-sort (predicate reverse)
11859   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11860   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11861          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11862          (gnus-thread-sort-functions
11863           (if (not reverse)
11864               thread
11865             `(lambda (t1 t2)
11866                (,thread t2 t1))))
11867          (gnus-sort-gathered-threads-function
11868           gnus-thread-sort-functions)
11869          (gnus-article-sort-functions
11870           (if (not reverse)
11871               article
11872             `(lambda (t1 t2)
11873                (,article t2 t1))))
11874          (inhibit-read-only t)
11875          (gnus-summary-prepare-hook nil))
11876     ;; We do the sorting by regenerating the threads.
11877     (gnus-summary-prepare)
11878     ;; Hide subthreads if needed.
11879     (gnus-summary-maybe-hide-threads)))
11880
11881 ;; Summary saving commands.
11882
11883 (defun gnus-summary-save-article (&optional n not-saved)
11884   "Save the current article using the default saver function.
11885 If N is a positive number, save the N next articles.
11886 If N is a negative number, save the N previous articles.
11887 If N is nil and any articles have been marked with the process mark,
11888 save those articles instead.
11889 The variable `gnus-default-article-saver' specifies the saver function.
11890
11891 If the optional second argument NOT-SAVED is non-nil, articles saved
11892 will not be marked as saved."
11893   (interactive "P")
11894   (require 'gnus-art)
11895   (let* ((articles (gnus-summary-work-articles n))
11896          (save-buffer (save-excursion
11897                         (nnheader-set-temp-buffer " *Gnus Save*")))
11898          (num (length articles))
11899          ;; Whether to save decoded articles or raw articles.
11900          (decode (when gnus-article-save-coding-system
11901                    (get gnus-default-article-saver :decode)))
11902          ;; When saving many articles in a single file, use the other
11903          ;; function to save articles other than the first one.
11904          (saver2 (get gnus-default-article-saver :function))
11905          (gnus-prompt-before-saving (if saver2
11906                                         t
11907                                       gnus-prompt-before-saving))
11908          (gnus-default-article-saver gnus-default-article-saver)
11909          header file)
11910     (dolist (article articles)
11911       (setq header (gnus-summary-article-header article))
11912       (if (not (vectorp header))
11913           ;; This is a pseudo-article.
11914           (if (assq 'name header)
11915               (gnus-copy-file (cdr (assq 'name header)))
11916             (gnus-message 1 "Article %d is unsaveable" article))
11917         ;; This is a real article.
11918         (save-window-excursion
11919           (gnus-summary-select-article decode decode nil article)
11920           (gnus-summary-goto-subject article))
11921         (with-current-buffer save-buffer
11922           (erase-buffer)
11923           (insert-buffer-substring (if decode
11924                                        gnus-article-buffer
11925                                      gnus-original-article-buffer)))
11926         (setq file (gnus-article-save save-buffer file num))
11927         (gnus-summary-remove-process-mark article)
11928         (unless not-saved
11929           (gnus-summary-set-saved-mark article)))
11930       (when saver2
11931         (setq gnus-default-article-saver saver2
11932               saver2 nil)))
11933     (gnus-kill-buffer save-buffer)
11934     (gnus-summary-position-point)
11935     (gnus-set-mode-line 'summary)
11936     n))
11937
11938 (defun gnus-summary-pipe-output (&optional n sym)
11939   "Pipe the current article to a subprocess.
11940 If N is a positive number, pipe the N next articles.
11941 If N is a negative number, pipe the N previous articles.
11942 If N is nil and any articles have been marked with the process mark,
11943 pipe those articles instead.
11944 The default command to which articles are piped is specified by the
11945 variable `gnus-summary-pipe-output-default-command'; if it is nil, you
11946 will be prompted for the command.
11947
11948 The properties `:decode' and `:headers' that are put to the function
11949 symbol `gnus-summary-save-in-pipe' control whether this function
11950 decodes articles and what headers to keep (see the doc string for the
11951 `gnus-default-article-saver' variable).  If SYM (the symbolic prefix)
11952 is neither omitted nor the symbol `r', force including all headers
11953 regardless of the `:headers' property.  If it is the symbol `r',
11954 articles that are not decoded and include all headers will be piped
11955 no matter what the properties `:decode' and `:headers' are."
11956   (interactive (gnus-interactive "P\ny"))
11957   (require 'gnus-art)
11958   (let* ((articles (gnus-summary-work-articles n))
11959          (result-buffer "*Shell Command Output*")
11960          (all-headers (not (memq sym '(nil r))))
11961          (gnus-save-all-headers (or all-headers gnus-save-all-headers))
11962          (raw (eq sym 'r))
11963          (headers (get 'gnus-summary-save-in-pipe :headers))
11964          command result)
11965     (unless (numberp (car articles))
11966       (error "No article to pipe"))
11967     (setq command (gnus-read-shell-command
11968                    (concat "Shell command on "
11969                            (if (cdr articles)
11970                                (format "these %d articles" (length articles))
11971                              "this article")
11972                            ": ")
11973                    gnus-summary-pipe-output-default-command))
11974     (when (string-equal command "")
11975       (error "A command is required"))
11976     (when all-headers
11977       (put 'gnus-summary-save-in-pipe :headers nil))
11978     (unwind-protect
11979         (while articles
11980           (gnus-summary-goto-subject (pop articles))
11981           (save-window-excursion (gnus-summary-save-in-pipe command raw))
11982           (when (and (get-buffer result-buffer)
11983                      (not (zerop (buffer-size (get-buffer result-buffer)))))
11984             (setq result (concat result (with-current-buffer result-buffer
11985                                           (buffer-string))))))
11986       (put 'gnus-summary-save-in-pipe :headers headers))
11987     (unless (zerop (length result))
11988       (if (with-current-buffer (get-buffer-create result-buffer)
11989             (erase-buffer)
11990             (insert result)
11991             (prog1
11992                 (and (= (count-lines (point-min) (point)) 1)
11993                      (progn
11994                        (end-of-line 0)
11995                        (<= (current-column)
11996                            (window-width (minibuffer-window)))))
11997               (goto-char (point-min))))
11998           (message "%s" (substring result 0 -1))
11999         (message nil)
12000         (gnus-configure-windows 'pipe)))))
12001
12002 (defun gnus-summary-save-article-mail (&optional arg)
12003   "Append the current article to a Unix mail box file.
12004 If N is a positive number, save the N next articles.
12005 If N is a negative number, save the N previous articles.
12006 If N is nil and any articles have been marked with the process mark,
12007 save those articles instead."
12008   (interactive "P")
12009   (require 'gnus-art)
12010   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
12011     (gnus-summary-save-article arg)))
12012
12013 (defun gnus-summary-save-article-rmail (&optional arg)
12014   "Append the current article to an rmail file.
12015 If N is a positive number, save the N next articles.
12016 If N is a negative number, save the N previous articles.
12017 If N is nil and any articles have been marked with the process mark,
12018 save those articles instead."
12019   (interactive "P")
12020   (require 'gnus-art)
12021   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
12022     (gnus-summary-save-article arg)))
12023
12024 (defun gnus-summary-save-article-file (&optional arg)
12025   "Append the current article to a file.
12026 If N is a positive number, save the N next articles.
12027 If N is a negative number, save the N previous articles.
12028 If N is nil and any articles have been marked with the process mark,
12029 save those articles instead."
12030   (interactive "P")
12031   (require 'gnus-art)
12032   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
12033     (gnus-summary-save-article arg)))
12034
12035 (defun gnus-summary-write-article-file (&optional arg)
12036   "Write the current article to a file, deleting the previous file.
12037 If N is a positive number, save the N next articles.
12038 If N is a negative number, save the N previous articles.
12039 If N is nil and any articles have been marked with the process mark,
12040 save those articles instead."
12041   (interactive "P")
12042   (require 'gnus-art)
12043   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
12044     (gnus-summary-save-article arg)))
12045
12046 (defun gnus-summary-save-article-body-file (&optional arg)
12047   "Append the current article body to a file.
12048 If N is a positive number, save the N next articles.
12049 If N is a negative number, save the N previous articles.
12050 If N is nil and any articles have been marked with the process mark,
12051 save those articles instead."
12052   (interactive "P")
12053   (require 'gnus-art)
12054   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
12055     (gnus-summary-save-article arg)))
12056
12057 (defun gnus-summary-write-article-body-file (&optional arg)
12058   "Write the current article body to a file, deleting the previous file.
12059 If N is a positive number, save the N next articles.
12060 If N is a negative number, save the N previous articles.
12061 If N is nil and any articles have been marked with the process mark,
12062 save those articles instead."
12063   (interactive "P")
12064   (require 'gnus-art)
12065   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
12066     (gnus-summary-save-article arg)))
12067
12068 (defun gnus-summary-muttprint (&optional arg)
12069   "Print the current article using Muttprint.
12070 If N is a positive number, save the N next articles.
12071 If N is a negative number, save the N previous articles.
12072 If N is nil and any articles have been marked with the process mark,
12073 save those articles instead."
12074   (interactive "P")
12075   (require 'gnus-art)
12076   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
12077     (gnus-summary-save-article arg t)))
12078
12079 (defun gnus-summary-pipe-message (program)
12080   "Pipe the current article through PROGRAM."
12081   (interactive "sProgram: ")
12082   (gnus-summary-select-article)
12083   (let ((mail-header-separator ""))
12084     (gnus-eval-in-buffer-window gnus-article-buffer
12085       (save-restriction
12086         (widen)
12087         (let ((start (window-start))
12088               (inhibit-read-only t))
12089           (message-pipe-buffer-body program)
12090           (set-window-start (get-buffer-window (current-buffer)) start))))))
12091
12092 (defun gnus-get-split-value (methods)
12093   "Return a value based on the split METHODS."
12094   (let (split-name method result match)
12095     (when methods
12096       (with-current-buffer gnus-original-article-buffer
12097         (save-restriction
12098           (nnheader-narrow-to-headers)
12099           (while (and methods (not split-name))
12100             (goto-char (point-min))
12101             (setq method (pop methods))
12102             (setq match (car method))
12103             (when (cond
12104                    ((stringp match)
12105                     ;; Regular expression.
12106                     (ignore-errors
12107                       (re-search-forward match nil t)))
12108                    ((functionp match)
12109                     ;; Function.
12110                     (save-restriction
12111                       (widen)
12112                       (setq result (funcall match gnus-newsgroup-name))))
12113                    ((consp match)
12114                     ;; Form.
12115                     (save-restriction
12116                       (widen)
12117                       (setq result (eval match)))))
12118               (setq split-name (cdr method))
12119               (cond ((stringp result)
12120                      (push (expand-file-name
12121                             result gnus-article-save-directory)
12122                            split-name))
12123                     ((consp result)
12124                      (setq split-name (append result split-name)))))))))
12125     (nreverse split-name)))
12126
12127 (defun gnus-valid-move-group-p (group)
12128   (and (symbolp group)
12129        (boundp group)
12130        (symbol-name group)
12131        (symbol-value group)
12132        (gnus-get-function (gnus-find-method-for-group
12133                            (symbol-name group)) 'request-accept-article t)))
12134
12135 (defun gnus-read-move-group-name (prompt default articles prefix)
12136   "Read a group name."
12137   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
12138          (minibuffer-confirm-incomplete nil) ; XEmacs
12139          (prom
12140           (format "%s %s to"
12141                   prompt
12142                   (if (> (length articles) 1)
12143                       (format "these %d articles" (length articles))
12144                     "this article")))
12145          (to-newsgroup
12146           (cond
12147            ((null split-name)
12148             (gnus-group-completing-read
12149              prom
12150              (gnus-remove-if-not 'gnus-valid-move-group-p gnus-active-hashtb t)
12151              nil prefix nil default))
12152            ((= 1 (length split-name))
12153             (gnus-group-completing-read
12154              prom
12155              (gnus-remove-if-not 'gnus-valid-move-group-p gnus-active-hashtb t)
12156              nil prefix 'gnus-group-history (car split-name)))
12157            (t
12158             (gnus-completing-read
12159              prom (nreverse split-name) nil nil 'gnus-group-history))))
12160          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
12161          encoded)
12162     (when to-newsgroup
12163       (if (or (string= to-newsgroup "")
12164               (string= to-newsgroup prefix))
12165           (setq to-newsgroup default))
12166       (unless to-newsgroup
12167         (error "No group name entered"))
12168       (setq encoded (mm-encode-coding-string
12169                      to-newsgroup
12170                      (gnus-group-name-charset to-method to-newsgroup)))
12171       (or (gnus-active encoded)
12172           (gnus-activate-group encoded nil nil to-method)
12173           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
12174                                      to-newsgroup))
12175               (or (and (gnus-request-create-group encoded to-method)
12176                        (gnus-activate-group encoded nil nil to-method)
12177                        (gnus-subscribe-group encoded))
12178                   (error "Couldn't create group %s" to-newsgroup)))
12179           (error "No such group: %s" to-newsgroup))
12180       encoded)))
12181
12182 (defvar gnus-summary-save-parts-counter)
12183 (declare-function mm-uu-dissect "mm-uu" (&optional noheader mime-type))
12184
12185 (defun gnus-summary-save-parts (type dir n &optional reverse)
12186   "Save parts matching TYPE to DIR.
12187 If REVERSE, save parts that do not match TYPE."
12188   (interactive
12189    (list (read-string "Save parts of type: "
12190                       (or (car gnus-summary-save-parts-type-history)
12191                           gnus-summary-save-parts-default-mime)
12192                       'gnus-summary-save-parts-type-history)
12193          (setq gnus-summary-save-parts-last-directory
12194                (read-directory-name "Save to directory: "
12195                                     gnus-summary-save-parts-last-directory
12196                                     nil t))
12197          current-prefix-arg))
12198   (gnus-summary-iterate n
12199     (let ((gnus-display-mime-function nil)
12200           gnus-article-prepare-hook
12201           gnus-article-decode-hook
12202           gnus-display-mime-function
12203           gnus-break-pages
12204           (gnus-inhibit-treatment t))
12205       (gnus-summary-select-article))
12206     (with-current-buffer gnus-article-buffer
12207       (let ((handles (or gnus-article-mime-handles
12208                          (mm-dissect-buffer nil gnus-article-loose-mime)
12209                          (and gnus-article-emulate-mime
12210                               (mm-uu-dissect))))
12211             (gnus-summary-save-parts-counter 1))
12212         (when handles
12213           (gnus-summary-save-parts-1 type dir handles reverse)
12214           (unless gnus-article-mime-handles ;; Don't destroy this case.
12215             (mm-destroy-parts handles)))))))
12216
12217 (defun gnus-summary-save-parts-1 (type dir handle reverse)
12218   (if (stringp (car handle))
12219       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
12220               (cdr handle))
12221     (when (if reverse
12222               (not (string-match type (mm-handle-media-type handle)))
12223             (string-match type (mm-handle-media-type handle)))
12224       (let ((file (expand-file-name
12225                    (gnus-map-function
12226                     mm-file-name-rewrite-functions
12227                     (file-name-nondirectory
12228                      (or
12229                       (mm-handle-filename handle)
12230                       (format "%s.%d.%d" gnus-newsgroup-name
12231                               (cdr gnus-article-current)
12232                               gnus-summary-save-parts-counter))))
12233                    dir)))
12234         (incf gnus-summary-save-parts-counter)
12235         (unless (file-exists-p file)
12236           (mm-save-part-to-file handle file))))))
12237
12238 ;; Summary extract commands
12239
12240 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
12241   (let ((inhibit-read-only t)
12242         (article (gnus-summary-article-number))
12243         after-article b e)
12244     (unless (gnus-summary-goto-subject article)
12245       (error "No such article: %d" article))
12246     (gnus-summary-position-point)
12247     ;; If all commands are to be bunched up on one line, we collect
12248     ;; them here.
12249     (unless gnus-view-pseudos-separately
12250       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
12251             files action)
12252         (while ps
12253           (setq action (cdr (assq 'action (car ps))))
12254           (setq files (list (cdr (assq 'name (car ps)))))
12255           (while (and ps (cdr ps)
12256                       (string= (or action "1")
12257                                (or (cdr (assq 'action (cadr ps))) "2")))
12258             (push (cdr (assq 'name (cadr ps))) files)
12259             (setcdr ps (cddr ps)))
12260           (when files
12261             (when (not (string-match "%s" action))
12262               (push " " files))
12263             (push " " files)
12264             (when (assq 'execute (car ps))
12265               (setcdr (assq 'execute (car ps))
12266                       (funcall (if (string-match "%s" action)
12267                                    'format 'concat)
12268                                action
12269                                (mapconcat
12270                                 (lambda (f)
12271                                   (if (equal f " ")
12272                                       f
12273                                     (shell-quote-argument f)))
12274                                 files " ")))))
12275           (setq ps (cdr ps)))))
12276     (if (and gnus-view-pseudos (not not-view))
12277         (while pslist
12278           (when (assq 'execute (car pslist))
12279             (gnus-execute-command (cdr (assq 'execute (car pslist)))
12280                                   (eq gnus-view-pseudos 'not-confirm)))
12281           (setq pslist (cdr pslist)))
12282       (save-excursion
12283         (while pslist
12284           (setq after-article (or (cdr (assq 'article (car pslist)))
12285                                   (gnus-summary-article-number)))
12286           (gnus-summary-goto-subject after-article)
12287           (forward-line 1)
12288           (setq b (point))
12289           (insert "    " (file-name-nondirectory
12290                           (cdr (assq 'name (car pslist))))
12291                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
12292           (setq e (point))
12293           (forward-line -1)             ; back to `b'
12294           (gnus-add-text-properties
12295            b (1- e) (list 'gnus-number gnus-reffed-article-number
12296                           gnus-mouse-face-prop gnus-mouse-face))
12297           (gnus-data-enter
12298            after-article gnus-reffed-article-number
12299            gnus-unread-mark b (car pslist) 0 (- e b))
12300           (setq gnus-newsgroup-unreads
12301                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
12302                                          gnus-reffed-article-number))
12303           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
12304           (setq pslist (cdr pslist)))))))
12305
12306 (defun gnus-pseudos< (p1 p2)
12307   (let ((c1 (cdr (assq 'action p1)))
12308         (c2 (cdr (assq 'action p2))))
12309     (and c1 c2 (string< c1 c2))))
12310
12311 (defun gnus-request-pseudo-article (props)
12312   (cond ((assq 'execute props)
12313          (gnus-execute-command (cdr (assq 'execute props)))))
12314   (let ((gnus-current-article (gnus-summary-article-number)))
12315     (gnus-run-hooks 'gnus-mark-article-hook)))
12316
12317 (defun gnus-execute-command (command &optional automatic)
12318   (save-excursion
12319     (gnus-article-setup-buffer)
12320     (set-buffer gnus-article-buffer)
12321     (setq buffer-read-only nil)
12322     (let ((command (if automatic command
12323                      (read-string "Command: " (cons command 0)))))
12324       (erase-buffer)
12325       (insert "$ " command "\n\n")
12326       (if gnus-view-pseudo-asynchronously
12327           (start-process "gnus-execute" (current-buffer) shell-file-name
12328                          shell-command-switch command)
12329         (call-process shell-file-name nil t nil
12330                       shell-command-switch command)))))
12331
12332 ;; Summary kill commands.
12333
12334 (defun gnus-summary-edit-global-kill (article)
12335   "Edit the \"global\" kill file."
12336   (interactive (list (gnus-summary-article-number)))
12337   (gnus-group-edit-global-kill article))
12338
12339 (defun gnus-summary-edit-local-kill ()
12340   "Edit a local kill file applied to the current newsgroup."
12341   (interactive)
12342   (setq gnus-current-headers (gnus-summary-article-header))
12343   (gnus-group-edit-local-kill
12344    (gnus-summary-article-number) gnus-newsgroup-name))
12345
12346 ;;; Header reading.
12347
12348 (defun gnus-read-header (id &optional header)
12349   "Read the headers of article ID and enter them into the Gnus system."
12350   (let ((group gnus-newsgroup-name)
12351         (gnus-override-method
12352          (or
12353           gnus-override-method
12354           (and (gnus-news-group-p gnus-newsgroup-name)
12355                (car (gnus-refer-article-methods)))))
12356         where)
12357     ;; First we check to see whether the header in question is already
12358     ;; fetched.
12359     (if (stringp id)
12360         ;; This is a Message-ID.
12361         (setq header (or header (gnus-id-to-header id)))
12362       ;; This is an article number.
12363       (setq header (or header (gnus-summary-article-header id))))
12364     (if (and header
12365              (not (gnus-summary-article-sparse-p (mail-header-number header))))
12366         ;; We have found the header.
12367         header
12368       ;; We have to really fetch the header to this article.
12369       (with-current-buffer nntp-server-buffer
12370         (when (setq where (gnus-request-head id group))
12371           (nnheader-fold-continuation-lines)
12372           (goto-char (point-max))
12373           (insert ".\n")
12374           (goto-char (point-min))
12375           (insert "211 ")
12376           (princ (cond
12377                   ((numberp id) id)
12378                   ((cdr where) (cdr where))
12379                   (header (mail-header-number header))
12380                   (t gnus-reffed-article-number))
12381                  (current-buffer))
12382           (insert " Article retrieved.\n"))
12383         (if (or (not where)
12384                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
12385             ()                          ; Malformed head.
12386           (unless (gnus-summary-article-sparse-p (mail-header-number header))
12387             (when (and (stringp id)
12388                        (or
12389                         (not (string= (gnus-group-real-name group)
12390                                       (car where)))
12391                         (not (gnus-server-equal gnus-override-method
12392                                                 (gnus-group-method group)))))
12393               ;; If we fetched by Message-ID and the article came from
12394               ;; a different group (or server), we fudge some bogus
12395               ;; article numbers for this article.
12396               (mail-header-set-number header gnus-reffed-article-number))
12397             (with-current-buffer gnus-summary-buffer
12398               (decf gnus-reffed-article-number)
12399               (gnus-remove-header (mail-header-number header))
12400               (push header gnus-newsgroup-headers)
12401               (setq gnus-current-headers header)
12402               (push (mail-header-number header) gnus-newsgroup-limit)))
12403           header)))))
12404
12405 (defun gnus-remove-header (number)
12406   "Remove header NUMBER from `gnus-newsgroup-headers'."
12407   (if (and gnus-newsgroup-headers
12408            (= number (mail-header-number (car gnus-newsgroup-headers))))
12409       (pop gnus-newsgroup-headers)
12410     (let ((headers gnus-newsgroup-headers))
12411       (while (and (cdr headers)
12412                   (not (= number (mail-header-number (cadr headers)))))
12413         (pop headers))
12414       (when (cdr headers)
12415         (setcdr headers (cddr headers))))))
12416
12417 ;;;
12418 ;;; summary highlights
12419 ;;;
12420
12421 (defun gnus-highlight-selected-summary ()
12422   "Highlight selected article in summary buffer."
12423   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12424   (when gnus-summary-selected-face
12425     (save-excursion
12426       (let* ((beg (point-at-bol))
12427              (end (point-at-eol))
12428              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12429              (from (if (get-text-property beg gnus-mouse-face-prop)
12430                        beg
12431                      (or (next-single-property-change
12432                           beg gnus-mouse-face-prop nil end)
12433                          beg)))
12434              (to
12435               (if (= from end)
12436                   (- from 2)
12437                 (or (next-single-property-change
12438                      from gnus-mouse-face-prop nil end)
12439                     end))))
12440         ;; If no mouse-face prop on line we will have to = from = end,
12441         ;; so we highlight the entire line instead.
12442         (when (= (+ to 2) from)
12443           (setq from beg)
12444           (setq to end))
12445         (if gnus-newsgroup-selected-overlay
12446             ;; Move old overlay.
12447             (gnus-move-overlay
12448              gnus-newsgroup-selected-overlay from to (current-buffer))
12449           ;; Create new overlay.
12450           (gnus-overlay-put
12451            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12452            'face gnus-summary-selected-face))))))
12453
12454 (defvar gnus-summary-highlight-line-cached nil)
12455 (defvar gnus-summary-highlight-line-trigger nil)
12456
12457 (defun gnus-summary-highlight-line-0 ()
12458   (if (and (eq gnus-summary-highlight-line-trigger
12459                gnus-summary-highlight)
12460            gnus-summary-highlight-line-cached)
12461       gnus-summary-highlight-line-cached
12462     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12463           gnus-summary-highlight-line-cached
12464           (let* ((cond (list 'cond))
12465                  (c cond)
12466                  (list gnus-summary-highlight))
12467             (while list
12468               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12469                               nil))
12470               (setq c (cdr c)
12471                     list (cdr list)))
12472             (gnus-byte-compile (list 'lambda nil cond))))))
12473
12474 (defun gnus-summary-highlight-line ()
12475   "Highlight current line according to `gnus-summary-highlight'."
12476   (let* ((beg (point-at-bol))
12477          (article (or (gnus-summary-article-number) gnus-current-article))
12478          (score (or (cdr (assq article
12479                                gnus-newsgroup-scored))
12480                     gnus-summary-default-score 0))
12481          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12482          (inhibit-read-only t)
12483          (default gnus-summary-default-score)
12484          (default-high gnus-summary-default-high-score)
12485          (default-low gnus-summary-default-low-score)
12486          (uncached (and gnus-summary-use-undownloaded-faces
12487                         (memq article gnus-newsgroup-undownloaded)
12488                         (not (memq article gnus-newsgroup-cached)))))
12489     (let ((face (funcall (gnus-summary-highlight-line-0))))
12490       (unless (eq face (get-text-property beg 'face))
12491         (gnus-put-text-property-excluding-characters-with-faces
12492          beg (point-at-eol) 'face
12493          (setq face (if (boundp face) (symbol-value face) face)))
12494         (when gnus-summary-highlight-line-function
12495           (funcall gnus-summary-highlight-line-function article face))))))
12496
12497 (defun gnus-update-read-articles (group unread &optional compute)
12498   "Update the list of read articles in GROUP.
12499 UNREAD is a sorted list."
12500   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12501         (info (gnus-get-info group))
12502         (prev 1)
12503         read)
12504     (if (or (not info) (not active))
12505         ;; There is no info on this group if it was, in fact,
12506         ;; killed.  Gnus stores no information on killed groups, so
12507         ;; there's nothing to be done.
12508         ;; One could store the information somewhere temporarily,
12509         ;; perhaps...  Hmmm...
12510         ()
12511       ;; Remove any negative articles numbers.
12512       (while (and unread (< (car unread) 0))
12513         (setq unread (cdr unread)))
12514       ;; Remove any expired article numbers
12515       (while (and unread (< (car unread) (car active)))
12516         (setq unread (cdr unread)))
12517       ;; Compute the ranges of read articles by looking at the list of
12518       ;; unread articles.
12519       (while unread
12520         (when (/= (car unread) prev)
12521           (push (if (= prev (1- (car unread))) prev
12522                   (cons prev (1- (car unread))))
12523                 read))
12524         (setq prev (1+ (car unread)))
12525         (setq unread (cdr unread)))
12526       (when (<= prev (cdr active))
12527         (push (cons prev (cdr active)) read))
12528       (setq read (if (> (length read) 1) (nreverse read) read))
12529       (if compute
12530           read
12531         (save-excursion
12532           (let (setmarkundo)
12533             ;; Propagate the read marks to the backend.
12534             (when (and (or gnus-propagate-marks
12535                            (gnus-method-option-p
12536                             (gnus-find-method-for-group group)
12537                             'server-marks))
12538                        (gnus-check-backend-function 'request-set-mark group))
12539               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12540                     (add (gnus-remove-from-range read (gnus-info-read info))))
12541                 (when (or add del)
12542                   (unless (gnus-check-group group)
12543                     (error "Can't open server for %s" group))
12544                   (gnus-request-set-mark
12545                    group (delq nil (list (if add (list add 'add '(read)))
12546                                          (if del (list del 'del '(read))))))
12547                   (setq setmarkundo
12548                         `(gnus-request-set-mark
12549                           ,group
12550                           ',(delq nil (list
12551                                        (if del (list del 'add '(read)))
12552                                        (if add (list add 'del '(read))))))))))
12553             (set-buffer gnus-group-buffer)
12554             (gnus-undo-register
12555               `(progn
12556                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12557                  (gnus-info-set-read ',info ',(gnus-info-read info))
12558                  (gnus-get-unread-articles-in-group ',info
12559                                                     (gnus-active ,group))
12560                  (gnus-group-update-group ,group t)
12561                  ,setmarkundo))))
12562         ;; Enter this list into the group info.
12563         (gnus-info-set-read info read)
12564         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12565         (gnus-get-unread-articles-in-group info (gnus-active group))
12566         t))))
12567
12568 (defun gnus-offer-save-summaries ()
12569   "Offer to save all active summary buffers."
12570   (let (buffers)
12571     ;; Go through all buffers and find all summaries.
12572     (dolist (buffer (buffer-list))
12573       (when (and (setq buffer (buffer-name buffer))
12574                  (string-match "Summary" buffer)
12575                  (with-current-buffer buffer
12576                    ;; We check that this is, indeed, a summary buffer.
12577                    (and (eq major-mode 'gnus-summary-mode)
12578                         ;; Also make sure this isn't bogus.
12579                         gnus-newsgroup-prepared
12580                         ;; Also make sure that this isn't a
12581                         ;; dead summary buffer.
12582                         (not gnus-dead-summary-mode))))
12583         (push buffer buffers)))
12584     ;; Go through all these summary buffers and offer to save them.
12585     (when buffers
12586       (save-excursion
12587         (map-y-or-n-p
12588          "Update summary buffer %s? "
12589          (lambda (buf)
12590            (switch-to-buffer buf)
12591            (gnus-summary-exit))
12592          buffers)))))
12593
12594 (defun gnus-summary-setup-default-charset ()
12595   "Setup newsgroup default charset."
12596   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12597       (setq gnus-newsgroup-charset nil)
12598     (let* ((ignored-charsets
12599             (or gnus-newsgroup-ephemeral-ignored-charsets
12600                 (append
12601                  (and gnus-newsgroup-name
12602                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12603                  gnus-newsgroup-ignored-charsets))))
12604       (setq gnus-newsgroup-charset
12605             (or gnus-newsgroup-ephemeral-charset
12606                 (and gnus-newsgroup-name
12607                      (gnus-parameter-charset gnus-newsgroup-name))
12608                 gnus-default-charset))
12609       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12610            ignored-charsets))))
12611
12612 ;;;
12613 ;;; Mime Commands
12614 ;;;
12615
12616 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12617   "Display the current article buffer fully MIME-buttonized.
12618 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12619 treated as multipart/mixed."
12620   (interactive "P")
12621   (require 'gnus-art)
12622   (let ((gnus-unbuttonized-mime-types nil)
12623         (gnus-mime-display-multipart-as-mixed show-all-parts))
12624     (gnus-summary-show-article)))
12625
12626 (defun gnus-summary-repair-multipart (article)
12627   "Add a Content-Type header to a multipart article without one."
12628   (interactive (list (gnus-summary-article-number)))
12629   (gnus-with-article article
12630     (message-narrow-to-head)
12631     (message-remove-header "Mime-Version")
12632     (goto-char (point-max))
12633     (insert "Mime-Version: 1.0\n")
12634     (widen)
12635     (when (search-forward "\n--" nil t)
12636       (let ((separator (buffer-substring (point) (point-at-eol))))
12637         (message-narrow-to-head)
12638         (message-remove-header "Content-Type")
12639         (goto-char (point-max))
12640         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12641                         separator))
12642         (widen))))
12643   (let (gnus-mark-article-hook)
12644     (gnus-summary-select-article t t nil article)))
12645
12646 (defun gnus-summary-toggle-display-buttonized ()
12647   "Toggle the buttonizing of the article buffer."
12648   (interactive)
12649   (require 'gnus-art)
12650   (if (setq gnus-inhibit-mime-unbuttonizing
12651             (not gnus-inhibit-mime-unbuttonizing))
12652       (let ((gnus-unbuttonized-mime-types nil))
12653         (gnus-summary-show-article))
12654     (gnus-summary-show-article)))
12655
12656 ;;;
12657 ;;; Generic summary marking commands
12658 ;;;
12659
12660 (defvar gnus-summary-marking-alist
12661   '((read gnus-del-mark "d")
12662     (unread gnus-unread-mark "u")
12663     (ticked gnus-ticked-mark "!")
12664     (dormant gnus-dormant-mark "?")
12665     (expirable gnus-expirable-mark "e"))
12666   "An alist of names/marks/keystrokes.")
12667
12668 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12669 (defvar gnus-summary-mark-map)
12670
12671 (defun gnus-summary-make-all-marking-commands ()
12672   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12673   (dolist (elem gnus-summary-marking-alist)
12674     (apply 'gnus-summary-make-marking-command elem)))
12675
12676 (defun gnus-summary-make-marking-command (name mark keystroke)
12677   (let ((map (make-sparse-keymap)))
12678     (define-key gnus-summary-generic-mark-map keystroke map)
12679     (dolist (lway `((next "next" next nil "n")
12680                     (next-unread "next unread" next t "N")
12681                     (prev "previous" prev nil "p")
12682                     (prev-unread "previous unread" prev t "P")
12683                     (nomove "" nil nil ,keystroke)))
12684       (let ((func (gnus-summary-make-marking-command-1
12685                    mark (car lway) lway name)))
12686         (setq func (eval func))
12687         (define-key map (nth 4 lway) func)))))
12688
12689 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12690   `(defun ,(intern
12691             (format "gnus-summary-put-mark-as-%s%s"
12692                     name (if (eq way 'nomove)
12693                              ""
12694                            (concat "-" (symbol-name way)))))
12695      (n)
12696      ,(format
12697        "Mark the current article as %s%s.
12698 If N, the prefix, then repeat N times.
12699 If N is negative, move in reverse order.
12700 The difference between N and the actual number of articles marked is
12701 returned."
12702        name (cadr lway))
12703      (interactive "p")
12704      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12705
12706 (defun gnus-summary-generic-mark (n mark move unread)
12707   "Mark N articles with MARK."
12708   (unless (eq major-mode 'gnus-summary-mode)
12709     (error "This command can only be used in the summary buffer"))
12710   (gnus-summary-show-thread)
12711   (let ((nummove
12712          (cond
12713           ((eq move 'next) 1)
12714           ((eq move 'prev) -1)
12715           (t 0))))
12716     (if (zerop nummove)
12717         (setq n 1)
12718       (when (< n 0)
12719         (setq n (abs n)
12720               nummove (* -1 nummove))))
12721     (while (and (> n 0)
12722                 (gnus-summary-mark-article nil mark)
12723                 (zerop (gnus-summary-next-subject nummove unread t)))
12724       (setq n (1- n)))
12725     (when (/= 0 n)
12726       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12727     (gnus-summary-recenter)
12728     (gnus-summary-position-point)
12729     (gnus-set-mode-line 'summary)
12730     n))
12731
12732 (defun gnus-summary-insert-articles (articles)
12733   (when (setq articles
12734               (gnus-sorted-difference articles
12735                                       (mapcar (lambda (h)
12736                                                 (mail-header-number h))
12737                                               gnus-newsgroup-headers)))
12738     (setq gnus-newsgroup-headers
12739           (gnus-merge 'list
12740                       gnus-newsgroup-headers
12741                       (gnus-fetch-headers articles)
12742                       'gnus-article-sort-by-number))
12743     ;; Suppress duplicates?
12744     (when gnus-suppress-duplicates
12745       (gnus-dup-suppress-articles))
12746
12747     (if (and gnus-fetch-old-headers
12748              (eq gnus-headers-retrieved-by 'nov))
12749         ;; We might want to build some more threads first.
12750         (if (eq gnus-fetch-old-headers 'invisible)
12751             (gnus-build-all-threads)
12752           (gnus-build-old-threads))
12753       ;; Mark the inserted articles that are unread as unread.
12754       (setq gnus-newsgroup-unreads
12755             (gnus-sorted-nunion
12756              gnus-newsgroup-unreads
12757              (gnus-sorted-nintersection
12758               (gnus-list-of-unread-articles gnus-newsgroup-name)
12759               articles)))
12760       ;; Mark the inserted articles as selected so that the information
12761       ;; of the marks having been changed by a user may be updated when
12762       ;; exiting this group.  See `gnus-summary-update-info'.
12763       (dolist (art articles)
12764         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12765     ;; Let the Gnus agent mark articles as read.
12766     (when gnus-agent
12767       (gnus-agent-get-undownloaded-list))
12768     ;; Remove list identifiers from subject
12769     (gnus-summary-remove-list-identifiers)
12770     ;; First and last article in this newsgroup.
12771     (when gnus-newsgroup-headers
12772       (setq gnus-newsgroup-begin
12773             (mail-header-number (car gnus-newsgroup-headers))
12774             gnus-newsgroup-end
12775             (mail-header-number
12776              (gnus-last-element gnus-newsgroup-headers))))
12777     (when gnus-use-scoring
12778       (gnus-possibly-score-headers))))
12779
12780 (defun gnus-summary-insert-old-articles (&optional all)
12781   "Insert all old articles in this group.
12782 If ALL is non-nil, already read articles become readable.
12783 If ALL is a number, fetch this number of articles."
12784   (interactive "P")
12785   (prog1
12786       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12787             older len)
12788         (setq older
12789               ;; Some nntp servers lie about their active range.  When
12790               ;; this happens, the active range can be in the millions.
12791               ;; Use a compressed range to avoid creating a huge list.
12792               (gnus-range-difference (list gnus-newsgroup-active) old))
12793         (setq len (gnus-range-length older))
12794         (cond
12795          ((null older) nil)
12796          ((numberp all)
12797           (if (< all len)
12798               (let ((older-range (nreverse older)))
12799                 (setq older nil)
12800
12801                 (while (> all 0)
12802                   (let* ((r (pop older-range))
12803                          (min (if (numberp r) r (car r)))
12804                          (max (if (numberp r) r (cdr r))))
12805                     (while (and (<= min max)
12806                                 (> all 0))
12807                       (push max older)
12808                       (setq all (1- all)
12809                             max (1- max))))))
12810             (setq older (gnus-uncompress-range older))))
12811          (all
12812           (setq older (gnus-uncompress-range older)))
12813          (t
12814           (when (and (numberp gnus-large-newsgroup)
12815                    (> len gnus-large-newsgroup))
12816               (let* ((cursor-in-echo-area nil)
12817                      (initial (gnus-parameter-large-newsgroup-initial
12818                                gnus-newsgroup-name))
12819                      (input
12820                       (read-string
12821                        (format
12822                         "How many articles from %s (%s %d): "
12823                         (gnus-group-decoded-name gnus-newsgroup-name)
12824                         (if initial "max" "default")
12825                         len)
12826                        (if initial
12827                            (cons (number-to-string initial)
12828                                  0)))))
12829                 (unless (string-match "^[ \t]*$" input)
12830                   (setq all (string-to-number input))
12831                   (if (< all len)
12832                       (let ((older-range (nreverse older)))
12833                         (setq older nil)
12834
12835                         (while (> all 0)
12836                           (let* ((r (pop older-range))
12837                                  (min (if (numberp r) r (car r)))
12838                                  (max (if (numberp r) r (cdr r))))
12839                             (while (and (<= min max)
12840                                         (> all 0))
12841                               (push max older)
12842                               (setq all (1- all)
12843                                     max (1- max))))))))))
12844           (setq older (gnus-uncompress-range older))))
12845         (if (not older)
12846             (message "No old news.")
12847           (gnus-summary-insert-articles older)
12848           (gnus-summary-limit (gnus-sorted-nunion old older))))
12849     (gnus-summary-position-point)))
12850
12851 (defun gnus-summary-insert-new-articles ()
12852   "Insert all new articles in this group."
12853   (interactive)
12854   (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12855         (old-high gnus-newsgroup-highest)
12856         (nnmail-fetched-sources (list t))
12857         (new-active (gnus-activate-group gnus-newsgroup-name 'scan))
12858         i new)
12859     (unless new-active
12860       (error "Couldn't fetch new data"))
12861     (setq gnus-newsgroup-active (gnus-copy-sequence new-active))
12862     (setq i (cdr gnus-newsgroup-active)
12863           gnus-newsgroup-highest i)
12864     (while (> i old-high)
12865       (push i new)
12866       (decf i))
12867     (if (not new)
12868         (message "No gnus is bad news")
12869       (gnus-summary-insert-articles new)
12870       (setq gnus-newsgroup-unreads
12871             (gnus-sorted-nunion gnus-newsgroup-unreads new))
12872       (gnus-summary-limit (gnus-sorted-nunion old new))))
12873   (gnus-summary-position-point))
12874
12875 ;;; Bookmark support for Gnus.
12876 (declare-function bookmark-make-record-default
12877                   "bookmark" (&optional no-file no-context posn))
12878 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
12879 (declare-function bookmark-default-handler "bookmark" (bmk))
12880 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
12881 (defvar bookmark-yank-point)
12882 (defvar bookmark-current-buffer)
12883
12884 (defun gnus-summary-bookmark-make-record ()
12885   "Make a bookmark entry for a Gnus summary buffer."
12886   (let (pos buf)
12887     (unless (and (derived-mode-p 'gnus-summary-mode) gnus-article-current)
12888       (save-restriction              ; FIXME is it necessary to widen?
12889         (widen) (setq pos (point))) ; Set position in gnus-article buffer.
12890       (setq buf "art") ; We are recording bookmark from article buffer.
12891       (setq bookmark-yank-point (point))
12892       (setq bookmark-current-buffer (current-buffer))
12893       (gnus-article-show-summary))      ; Go back in summary buffer.
12894     ;; We are now recording bookmark from summary buffer.
12895     (unless buf (setq buf "sum"))
12896     (let* ((subject (elt (gnus-summary-article-header) 1))
12897            (grp     (car gnus-article-current))
12898            (art     (cdr gnus-article-current))
12899            (head    (gnus-summary-article-header art))
12900            (id      (mail-header-id head)))
12901       `(,subject
12902         ,@(condition-case nil
12903               (bookmark-make-record-default 'no-file 'no-context pos)
12904             (wrong-number-of-arguments
12905              (bookmark-make-record-default 'point-only)))
12906         (location . ,(format "Gnus-%s %s:%d:%s" buf grp art id))
12907         (group . ,grp) (article . ,art)
12908         (message-id . ,id) (handler . gnus-summary-bookmark-jump)))))
12909
12910 ;;;###autoload
12911 (defun gnus-summary-bookmark-jump (bookmark)
12912   "Handler function for record returned by `gnus-summary-bookmark-make-record'.
12913 BOOKMARK is a bookmark name or a bookmark record."
12914   (let ((group    (bookmark-prop-get bookmark 'group))
12915         (article  (bookmark-prop-get bookmark 'article))
12916         (id       (bookmark-prop-get bookmark 'message-id))
12917         (buf      (car (split-string (bookmark-prop-get bookmark 'location)))))
12918     (gnus-fetch-group group (list article))
12919     (gnus-summary-insert-cached-articles)
12920     (gnus-summary-goto-article id nil 'force)
12921     ;; FIXME we have to wait article buffer is ready (only large buffer)
12922     ;; Is there a better solution to know that?
12923     ;; If we don't wait `bookmark-default-handler' will have no chance
12924     ;; to set position. However there is no error, just wrong pos.
12925     (sit-for 1)
12926     (when (string= buf "Gnus-art")
12927       (other-window 1))
12928     (bookmark-default-handler
12929      `(""
12930        (buffer . ,(current-buffer))
12931        . ,(bookmark-get-bookmark-record bookmark)))))
12932
12933 (gnus-summary-make-all-marking-commands)
12934
12935 (gnus-ems-redefine)
12936
12937 (provide 'gnus-sum)
12938
12939 (run-hooks 'gnus-sum-load-hook)
12940
12941 ;; Local Variables:
12942 ;; coding: iso-8859-1
12943 ;; End:
12944
12945 ;;; gnus-sum.el ends here